Mercurial > molko
comparison libmlk-core/core/painter.h @ 243:71b3b7036de7
misc: lot of cleanups,
- prefix libraries with libmlk,
- move assets from source directories closes #2520,
- prefix header guards closes #2519
author | David Demelier <markand@malikania.fr> |
---|---|
date | Sat, 28 Nov 2020 22:37:30 +0100 |
parents | libcore/core/painter.h@789b23e01f52 |
children | c4da052c0def |
comparison
equal
deleted
inserted
replaced
242:4c24604efcab | 243:71b3b7036de7 |
---|---|
1 /* | |
2 * painter.h -- basic drawing routines | |
3 * | |
4 * Copyright (c) 2020 David Demelier <markand@malikania.fr> | |
5 * | |
6 * Permission to use, copy, modify, and/or distribute this software for any | |
7 * purpose with or without fee is hereby granted, provided that the above | |
8 * copyright notice and this permission notice appear in all copies. | |
9 * | |
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | |
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | |
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
17 */ | |
18 | |
19 #ifndef MOLKO_CORE_PAINTER_H | |
20 #define MOLKO_CORE_PAINTER_H | |
21 | |
22 /** | |
23 * \file painter.h | |
24 * \brief Basic drawing routines. | |
25 * \ingroup drawing | |
26 */ | |
27 | |
28 #include <stdbool.h> | |
29 | |
30 struct texture; | |
31 | |
32 /** | |
33 * Give the current texture being used for rendering, maybe NULL if the | |
34 * rendering is on root. | |
35 * | |
36 * \return Texture or NULL. | |
37 */ | |
38 struct texture * | |
39 painter_get_target(void); | |
40 | |
41 /** | |
42 * Set the rendering context to the given texture. | |
43 * | |
44 * Since this function change an internal global variable it is strongly | |
45 * encouraged to store a local backup of the current texture using \a | |
46 * painter_get_target and call this function with it afterwards. | |
47 * | |
48 * If texture is NULL, use default context aka the window. | |
49 * | |
50 * \param tex the texture | |
51 * \see \ref PAINTER_BEGIN | |
52 * \see \ref PAINTER_END | |
53 */ | |
54 void | |
55 painter_set_target(struct texture *tex); | |
56 | |
57 /** | |
58 * Get the current drawing color. | |
59 * | |
60 * \return the color in RRGGBBAA format | |
61 */ | |
62 unsigned long | |
63 painter_get_color(void); | |
64 | |
65 /** | |
66 * Set the rendering drawing color. | |
67 * | |
68 * \param color in RRGGBBAA format | |
69 */ | |
70 void | |
71 painter_set_color(unsigned long color); | |
72 | |
73 /** | |
74 * Draw a line. | |
75 * | |
76 * \param x1 first X coordinate | |
77 * \param y1 first Y coordinate | |
78 * \param x2 second X coordinate | |
79 * \param y2 second Y coordinate | |
80 */ | |
81 void | |
82 painter_draw_line(int x1, int y1, int x2, int y2); | |
83 | |
84 /** | |
85 * Draw a pixel point. | |
86 * | |
87 * \param x the X coordinate | |
88 * \param y the Y coordinate | |
89 */ | |
90 void | |
91 painter_draw_point(int x, int y); | |
92 | |
93 /** | |
94 * Draw a rectangle | |
95 * | |
96 * \param x the X coordinate | |
97 * \param y the Y coordinate | |
98 * \param w the rectangle width | |
99 * \param h the rectangle height | |
100 */ | |
101 void | |
102 painter_draw_rectangle(int x, int y, unsigned int w, unsigned int h); | |
103 | |
104 /** | |
105 * Draw a circle. | |
106 * | |
107 * \param x the X coordinate | |
108 * \param y the Y coordinate | |
109 * \param radius the radius size | |
110 */ | |
111 void | |
112 painter_draw_circle(int x, int y, int radius); | |
113 | |
114 /** | |
115 * Clear the window. | |
116 */ | |
117 void | |
118 painter_clear(void); | |
119 | |
120 /** | |
121 * Present the window, only call this function one time in the main loop. | |
122 */ | |
123 void | |
124 painter_present(void); | |
125 | |
126 /** | |
127 * Use this macro to start painting on the texture to store the current | |
128 * rendering context and put it back afterwards. | |
129 * | |
130 * \pre tex != NULL | |
131 * \param tex the texture to use | |
132 * \see \ref PAINTER_END | |
133 */ | |
134 #define PAINTER_BEGIN(tex ) \ | |
135 do { \ | |
136 struct texture *__current_texture__; \ | |
137 \ | |
138 __current_texture__ = painter_get_target(); \ | |
139 painter_set_target((tex)) | |
140 | |
141 /** | |
142 * Use this macro at the end of rendering into a given texture. | |
143 * | |
144 * \see \ref PAINTER_BEGIN | |
145 */ | |
146 #define PAINTER_END() \ | |
147 painter_set_target(__current_texture__); \ | |
148 } while (0) | |
149 | |
150 #endif /* !MOLKO_CORE_PAINTER_H */ |