diff options
Diffstat (limited to '')
-rw-r--r-- | libraries/ecore/src/lib/ecore_win32/ecore_win32_cursor.c | 306 |
1 files changed, 306 insertions, 0 deletions
diff --git a/libraries/ecore/src/lib/ecore_win32/ecore_win32_cursor.c b/libraries/ecore/src/lib/ecore_win32/ecore_win32_cursor.c new file mode 100644 index 0000000..9a5a7eb --- /dev/null +++ b/libraries/ecore/src/lib/ecore_win32/ecore_win32_cursor.c | |||
@@ -0,0 +1,306 @@ | |||
1 | #ifdef HAVE_CONFIG_H | ||
2 | # include <config.h> | ||
3 | #endif | ||
4 | |||
5 | #define WIN32_LEAN_AND_MEAN | ||
6 | #include <windows.h> | ||
7 | #undef WIN32_LEAN_AND_MEAN | ||
8 | |||
9 | #include <Eina.h> | ||
10 | |||
11 | #include "Ecore_Win32.h" | ||
12 | #include "ecore_win32_private.h" | ||
13 | |||
14 | /*============================================================================* | ||
15 | * Local * | ||
16 | *============================================================================*/ | ||
17 | |||
18 | |||
19 | /*============================================================================* | ||
20 | * Global * | ||
21 | *============================================================================*/ | ||
22 | |||
23 | |||
24 | /*============================================================================* | ||
25 | * API * | ||
26 | *============================================================================*/ | ||
27 | |||
28 | /** | ||
29 | * @addtogroup Ecore_Win32_Group Ecore_Win32 library | ||
30 | * | ||
31 | * @{ | ||
32 | */ | ||
33 | |||
34 | /** | ||
35 | * @brief Create a new cursor. | ||
36 | * | ||
37 | * @param pixels_and The array of bytes containing the bit values for | ||
38 | * the AND mask of the cursor. | ||
39 | * @param pixels_xor The array of bytes containing the bit values for | ||
40 | * the XOR mask of the cursor. | ||
41 | * @param width The width of the cursor. | ||
42 | * @param height The height of the cursor. | ||
43 | * @param hot_x The horizontal position of the cursor's hot spot. | ||
44 | * @param hot_y The vertical position of the cursor's hot spot. | ||
45 | * @return A newly user-defined cursor. | ||
46 | * | ||
47 | * This function creates a new cursor of size @p width and @p | ||
48 | * height. They must be valid size. To determine the valid size of a | ||
49 | * cursor, useecore_win32_cursor_size_get(). @p pixels_and is an array | ||
50 | * of bytes (unsigned char) containing the bits of the cursor that | ||
51 | * will be visible. @p pixels_xor is similar but will allow the cursor | ||
52 | * to have a shape. Here is the truth table for the masks: | ||
53 | * | ||
54 | * <table border=1> | ||
55 | * <tr><td>AND mask</td><td>XOR mask</td><td>Display</td></tr> | ||
56 | * <tr><td>0</td> <td>0</td> <td>Black</td></tr> | ||
57 | * <tr><td>0</td> <td>1</td> <td>White</td></tr> | ||
58 | * <tr><td>1</td> <td>0</td> <td>Screen</td></tr> | ||
59 | * <tr><td>1</td> <td>1</td> <td>Reverse screen</td></tr> | ||
60 | * </table> | ||
61 | * | ||
62 | * @p hot_x and @p hot_y are the position of the hot spot of the | ||
63 | * cursor. If @p pixels_and or @p pixels_xor are @c NULL, the function | ||
64 | * returns NULL. If @p width or @p height does not match the valid | ||
65 | * size of a cursor, the function returns @c NULL. On success, the | ||
66 | * function creates a user-defined cursor, otherwise it returns | ||
67 | * @c NULL. | ||
68 | * | ||
69 | * Once the cursor is not used anymore, use ecore_win32_cursor_free() | ||
70 | * to free the ressources. | ||
71 | * | ||
72 | * Example of use: | ||
73 | * | ||
74 | * @code | ||
75 | * unsigned char pixels_and[] ={ | ||
76 | * 0xFF, 0xFC, 0x3F, 0xFF, // line 1 | ||
77 | * 0xFF, 0xC0, 0x1F, 0xFF, // line 2 | ||
78 | * 0xFF, 0x00, 0x3F, 0xFF, // line 3 | ||
79 | * 0xFE, 0x00, 0xFF, 0xFF, // line 4 | ||
80 | * | ||
81 | * 0xF7, 0x01, 0xFF, 0xFF, // line 5 | ||
82 | * 0xF0, 0x03, 0xFF, 0xFF, // line 6 | ||
83 | * 0xF0, 0x03, 0xFF, 0xFF, // line 7 | ||
84 | * 0xE0, 0x07, 0xFF, 0xFF, // line 8 | ||
85 | * | ||
86 | * 0xC0, 0x07, 0xFF, 0xFF, // line 9 | ||
87 | * 0xC0, 0x0F, 0xFF, 0xFF, // line 10 | ||
88 | * 0x80, 0x0F, 0xFF, 0xFF, // line 11 | ||
89 | * 0x80, 0x0F, 0xFF, 0xFF, // line 12 | ||
90 | * | ||
91 | * 0x80, 0x07, 0xFF, 0xFF, // line 13 | ||
92 | * 0x00, 0x07, 0xFF, 0xFF, // line 14 | ||
93 | * 0x00, 0x03, 0xFF, 0xFF, // line 15 | ||
94 | * 0x00, 0x00, 0xFF, 0xFF, // line 16 | ||
95 | * | ||
96 | * 0x00, 0x00, 0x7F, 0xFF, // line 17 | ||
97 | * 0x00, 0x00, 0x1F, 0xFF, // line 18 | ||
98 | * 0x00, 0x00, 0x0F, 0xFF, // line 19 | ||
99 | * 0x80, 0x00, 0x0F, 0xFF, // line 20 | ||
100 | * | ||
101 | * 0x80, 0x00, 0x07, 0xFF, // line 21 | ||
102 | * 0x80, 0x00, 0x07, 0xFF, // line 22 | ||
103 | * 0xC0, 0x00, 0x07, 0xFF, // line 23 | ||
104 | * 0xC0, 0x00, 0x0F, 0xFF, // line 24 | ||
105 | * | ||
106 | * 0xE0, 0x00, 0x0F, 0xFF, // line 25 | ||
107 | * 0xF0, 0x00, 0x1F, 0xFF, // line 26 | ||
108 | * 0xF0, 0x00, 0x1F, 0xFF, // line 27 | ||
109 | * 0xF8, 0x00, 0x3F, 0xFF, // line 28 | ||
110 | * | ||
111 | * 0xFE, 0x00, 0x7F, 0xFF, // line 29 | ||
112 | * 0xFF, 0x00, 0xFF, 0xFF, // line 30 | ||
113 | * 0xFF, 0xC3, 0xFF, 0xFF, // line 31 | ||
114 | * 0xFF, 0xFF, 0xFF, 0xFF // line 32 | ||
115 | * }; | ||
116 | * | ||
117 | * unsigned char pixels_xor[] = | ||
118 | * { | ||
119 | * 0x00, 0x00, 0x00, 0x00, // line 1 | ||
120 | * 0x00, 0x03, 0xC0, 0x00, // line 2 | ||
121 | * 0x00, 0x3F, 0x00, 0x00, // line 3 | ||
122 | * 0x00, 0xFE, 0x00, 0x00, // line 4 | ||
123 | * | ||
124 | * 0x0E, 0xFC, 0x00, 0x00, // line 5 | ||
125 | * 0x07, 0xF8, 0x00, 0x00, // line 6 | ||
126 | * 0x07, 0xF8, 0x00, 0x00, // line 7 | ||
127 | * 0x0F, 0xF0, 0x00, 0x00, // line 8 | ||
128 | * | ||
129 | * 0x1F, 0xF0, 0x00, 0x00, // line 9 | ||
130 | * 0x1F, 0xE0, 0x00, 0x00, // line 10 | ||
131 | * 0x3F, 0xE0, 0x00, 0x00, // line 11 | ||
132 | * 0x3F, 0xE0, 0x00, 0x00, // line 12 | ||
133 | * | ||
134 | * 0x3F, 0xF0, 0x00, 0x00, // line 13 | ||
135 | * 0x7F, 0xF0, 0x00, 0x00, // line 14 | ||
136 | * 0x7F, 0xF8, 0x00, 0x00, // line 15 | ||
137 | * 0x7F, 0xFC, 0x00, 0x00, // line 16 | ||
138 | * | ||
139 | * 0x7F, 0xFF, 0x00, 0x00, // line 17 | ||
140 | * 0x7F, 0xFF, 0x80, 0x00, // line 18 | ||
141 | * 0x7F, 0xFF, 0xE0, 0x00, // line 19 | ||
142 | * 0x3F, 0xFF, 0xE0, 0x00, // line 20 | ||
143 | * | ||
144 | * 0x3F, 0xC7, 0xF0, 0x00, // line 21 | ||
145 | * 0x3F, 0x83, 0xF0, 0x00, // line 22 | ||
146 | * 0x1F, 0x83, 0xF0, 0x00, // line 23 | ||
147 | * 0x1F, 0x83, 0xE0, 0x00, // line 24 | ||
148 | * | ||
149 | * 0x0F, 0xC7, 0xE0, 0x00, // line 25 | ||
150 | * 0x07, 0xFF, 0xC0, 0x00, // line 26 | ||
151 | * 0x07, 0xFF, 0xC0, 0x00, // line 27 | ||
152 | * 0x01, 0xFF, 0x80, 0x00, // line 28 | ||
153 | * | ||
154 | * 0x00, 0xFF, 0x00, 0x00, // line 29 | ||
155 | * 0x00, 0x3C, 0x00, 0x00, // line 30 | ||
156 | * 0x00, 0x00, 0x00, 0x00, // line 31 | ||
157 | * 0x00, 0x00, 0x00, 0x00 // line 32 | ||
158 | * }; | ||
159 | * | ||
160 | * Ecore_Win32_Cursor cursor = ecore_win32_cursor_new(pixels_and, pixels_xor, 32, 32, 19, 2); | ||
161 | * @endcode | ||
162 | */ | ||
163 | EAPI Ecore_Win32_Cursor * | ||
164 | ecore_win32_cursor_new(const void *pixels_and, | ||
165 | const void *pixels_xor, | ||
166 | int width, | ||
167 | int height, | ||
168 | int hot_x, | ||
169 | int hot_y) | ||
170 | { | ||
171 | Ecore_Win32_Cursor *cursor = NULL; | ||
172 | int cursor_width; | ||
173 | int cursor_height; | ||
174 | |||
175 | INF("creating cursor"); | ||
176 | |||
177 | if (!pixels_and || !pixels_xor) | ||
178 | return NULL; | ||
179 | |||
180 | cursor_width = GetSystemMetrics(SM_CXCURSOR); | ||
181 | cursor_height = GetSystemMetrics(SM_CYCURSOR); | ||
182 | |||
183 | if ((cursor_width != width) || | ||
184 | (cursor_height != height)) | ||
185 | return NULL; | ||
186 | |||
187 | if (!(cursor = CreateCursor(_ecore_win32_instance, | ||
188 | hot_x, hot_y, | ||
189 | width, height, | ||
190 | pixels_and, | ||
191 | pixels_xor))) | ||
192 | return NULL; | ||
193 | |||
194 | return cursor; | ||
195 | } | ||
196 | |||
197 | /** | ||
198 | * @brief Free the given cursor. | ||
199 | * | ||
200 | * @param cursor The cursor to free. | ||
201 | * | ||
202 | * This function free @p cursor. @p cursor must have been obtained | ||
203 | * with ecore_win32_cursor_new(). | ||
204 | */ | ||
205 | EAPI void | ||
206 | ecore_win32_cursor_free(Ecore_Win32_Cursor *cursor) | ||
207 | { | ||
208 | INF("destroying cursor"); | ||
209 | |||
210 | DestroyCursor(cursor); | ||
211 | } | ||
212 | |||
213 | /** | ||
214 | * @brief Create a cursor from a Windows ressource. | ||
215 | * | ||
216 | * @param shape The pre-defined shape of the cursor. | ||
217 | * @return The new cursor. | ||
218 | * | ||
219 | * This function returns a pre-defined cursor with a specified | ||
220 | * @p shape. This cursor does not need to be freed, as it is loaded | ||
221 | * from an existing resource. | ||
222 | */ | ||
223 | EAPI Ecore_Win32_Cursor * | ||
224 | ecore_win32_cursor_shaped_new(Ecore_Win32_Cursor_Shape shape) | ||
225 | { | ||
226 | Ecore_Win32_Cursor *cursor = NULL; | ||
227 | const char *cursor_name; | ||
228 | |||
229 | INF("geting shape cursor"); | ||
230 | |||
231 | switch (shape) | ||
232 | { | ||
233 | case ECORE_WIN32_CURSOR_SHAPE_APP_STARTING: | ||
234 | cursor_name = IDC_APPSTARTING; | ||
235 | break; | ||
236 | case ECORE_WIN32_CURSOR_SHAPE_ARROW: | ||
237 | cursor_name = IDC_ARROW; | ||
238 | break; | ||
239 | case ECORE_WIN32_CURSOR_SHAPE_CROSS: | ||
240 | cursor_name = IDC_CROSS; | ||
241 | break; | ||
242 | case ECORE_WIN32_CURSOR_SHAPE_HAND: | ||
243 | cursor_name = IDC_HAND; | ||
244 | break; | ||
245 | case ECORE_WIN32_CURSOR_SHAPE_HELP: | ||
246 | cursor_name = IDC_HELP; | ||
247 | break; | ||
248 | case ECORE_WIN32_CURSOR_SHAPE_I_BEAM: | ||
249 | cursor_name = IDC_IBEAM; | ||
250 | break; | ||
251 | case ECORE_WIN32_CURSOR_SHAPE_NO: | ||
252 | cursor_name = IDC_NO; | ||
253 | break; | ||
254 | case ECORE_WIN32_CURSOR_SHAPE_SIZE_ALL: | ||
255 | cursor_name = IDC_SIZEALL; | ||
256 | break; | ||
257 | case ECORE_WIN32_CURSOR_SHAPE_SIZE_NESW: | ||
258 | cursor_name = IDC_SIZENESW; | ||
259 | break; | ||
260 | case ECORE_WIN32_CURSOR_SHAPE_SIZE_NS: | ||
261 | cursor_name = IDC_SIZENS; | ||
262 | break; | ||
263 | case ECORE_WIN32_CURSOR_SHAPE_SIZE_NWSE: | ||
264 | cursor_name = IDC_SIZENWSE; | ||
265 | break; | ||
266 | case ECORE_WIN32_CURSOR_SHAPE_SIZE_WE: | ||
267 | cursor_name = IDC_SIZEWE; | ||
268 | break; | ||
269 | case ECORE_WIN32_CURSOR_SHAPE_UP_ARROW: | ||
270 | cursor_name = IDC_UPARROW; | ||
271 | break; | ||
272 | case ECORE_WIN32_CURSOR_SHAPE_WAIT: | ||
273 | cursor_name = IDC_WAIT; | ||
274 | break; | ||
275 | default: | ||
276 | return NULL; | ||
277 | } | ||
278 | |||
279 | if (!(cursor = LoadCursor(NULL, cursor_name))) | ||
280 | return NULL; | ||
281 | |||
282 | return cursor; | ||
283 | } | ||
284 | |||
285 | /** | ||
286 | * @brief Retrieve the size of a valid cursor. | ||
287 | * | ||
288 | * @param width The width of a valid cursor. | ||
289 | * @param height The height of a valid cursor. | ||
290 | * | ||
291 | * This function returns the size of a cursor that must be passed to | ||
292 | * ecore_win32_cursor_new(). @p width and @p height are buffers that | ||
293 | * will be filled with the correct size. They can be @c NULL. | ||
294 | */ | ||
295 | EAPI void | ||
296 | ecore_win32_cursor_size_get(int *width, int *height) | ||
297 | { | ||
298 | INF("geting size cursor"); | ||
299 | |||
300 | if (*width) *width = GetSystemMetrics(SM_CXCURSOR); | ||
301 | if (*height) *height = GetSystemMetrics(SM_CYCURSOR); | ||
302 | } | ||
303 | |||
304 | /** | ||
305 | * @} | ||
306 | */ | ||