1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371 | % /¯ ) ( |¯\ (` /¯\ |¯\
%\ W X \_, \_/ |¯\ \_) \_/ |¯\ . E R L
%%
%%
%% Copyright Ericsson AB 2008-2013. All Rights Reserved.
%%
%%
%% Whitespace Beautified by ScriptCulture © 2018
%% Sit Back · Feet Up · Learn wxErlang
%% For use as a reference only
%% www.scriptculture.com
%% Not check-summed
%% wx 1.8
%%
%% Licensed under the Apache License,
%% Version 2.0 (the "License"); you may
%% not use this file except in compliance
%% with the License. You may obtain a copy
%% of the License at:
%%
%% http://www.apache.org/licenses/LICENSE-2.0
%%
%% Unless required by
%% applicable law or agreed to in writing, software
%% distributed under the License is distributed
%% on an "AS IS" BASIS, WITHOUT WARRANTIES
%% OR CONDITIONS OF ANY KIND, either
%% express or implied. See the
%% License for the specific
%% language governing
%% permissions and
%% limitations
%% under the
%% License.
%%%%%%%
%%%%
%%%%%
%% @doc See external documentation: <a href="http://www.wxwidgets.org/manuals/2.8.12/wx_wxcursor.html">wxCursor</a>.
%% <p>This class is derived (and can use functions) from:
%% <br />{@link wxBitmap}
%% </p>
%% @type wxCursor().
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%% OVERVIEW
%% ––––––––
%% A cursor is a small bitmap usually used for denoting where
%% the mouse pointer is, with a picture that might indicate
%% the interpretation of a mouse click.
%% As with icons, cursors in X and MS Windows
%% are created in a different manner.
%% Therefore, separate cursors will be
%% created for the different environments.
%% Platform-specific methods for creating a
%% wxCursor object are catered for, and this is an
%% occasion where conditional compilation will probably
%% be required (see wxIcon for an example).
%%
%% A single cursor object may be used in many windows (any subwindow type).
%% The wxWidgets convention is to set the cursor for a window, as in X,
%% rather than to set it globally as in MS Windows,
%% although a global ::wxSetCursor is also available for MS Windows use.
%%
%%
%% — EXAMPLE AT BOTTOM —
%%
%%
%% PREDEFINED OBJECTS
%% ——————————————————
%% Objects:
%% wxNullCursor
%%
%% Pointers:
%% wxSTANDARD_CURSOR
%% wxHOURGLASS_CURSOR
%% wxCROSS_CURSOR
%%
%% See Also:
%% —————————
%% wxBitmap,
%% wxIcon,
%% wxWindow::SetCursor,
%% ::wxSetCursor
%%
%%
-module(wxCursor).
-include("wxe.hrl").
-export([destroy/1,new/0,new/1,new/3,new/4,ok/1]).
%% inherited exports
-export([convertToImage/1,copyFromIcon/2,getDepth/1,getHeight/1,getMask/1,getPalette/1,
getSubBitmap/2,getWidth/1,loadFile/2,loadFile/3,parent_class/1,saveFile/3,
saveFile/4,setDepth/2,setHeight/2,setMask/2,setPalette/2,setWidth/2]).
-export_type([wxCursor/0]).
-deprecated([new/3,new/4]).
%% @hidden
parent_class(wxBitmap) -> true;
parent_class(_Class) -> erlang:error({badtype, ?MODULE}).
-type wxCursor() :: wx:wx_object().
%·%% NEW %%·%
%%
%%
%%
%% Return Value:
%% See Also:
%%*%%*%%
-spec new() -> wxCursor().
new() ->
wxe_util:construct(?wxCursor_new_0,
<<>>).
%·%% NEW / 1 %%·%
%%
%% 1. CursorID
%% Constructs a cursor using a cursor identifier.
%%
%% 2. IMAGE!
%% Constructs a cursor from a wxImage.
%% If the cursor is monochrome on the current platform,
%% colors with the RGB elements all greater than 127 will be foreground,
%% colors less than this will be background.
%% The mask (if any) will be used to specify the transparent area.
%%
%% In wxMSW the foreground will be white and the background black.
%% If the cursor is larger than 32x32 it is resized.
%%
%% In wxGTK, colour cursors and alpha channel are supported
%% (starting from GTK+ 2.2). Otherwise the two most
%% frequent colors will be used for foreground and background.
%% In any case, the cursor will be displayed at the size of the image.
%%
%% In wxMac, if the cursor is larger than 16x16 it is resized and
%% currently only shown as black/white (mask respected).
%%
%% Return Value:
%% See Also:
%%*%%*%%
%% <br /> Also:<br />
%% new(Image) -> wxCursor() when<br />
%% Image :: wxImage:wxImage().<br />
%%
-spec new(CursorId) -> wxCursor()
when
CursorId :: integer();
(Image) -> wxCursor()
when
Image :: wxImage:wxImage().
new(CursorId)
when
is_integer(CursorId) ->
wxe_util:construct(?wxCursor_new_1_0,
<<CursorId:32/?UI>>);
new(#wx_ref{type=ImageT,ref=ImageRef}) ->
?CLASS(ImageT,wxImage),
wxe_util:construct(?wxCursor_new_1_1,
<<ImageRef:32/?UI>>).
%% See below...
%% @equiv new(Bits,Width,Height, [])
-spec new(Bits, Width, Height) -> wxCursor()
when
Bits :: binary(), % An array of bits.
Width :: integer(), % Cursor width.
Height :: integer(). % Cursor height.
new(Bits,Width,Height)
when
is_binary(Bits),
is_integer(Width),
is_integer(Height) -> new(Bits,Width,Height, []).
%%
%% Constructs a cursor by passing an array of bits (Motif and GTK+ only).
%% maskBits is used only under Motif and GTK+.
%% The parameters fg and bg are only present on GTK+,
%% and force the cursor to use particular background and foreground colours.
%%
%% If either hotSpotX or hotSpotY is -1,
%% the hotspot will be the centre of the cursor image (Motif only).
%%
%% Return Value:
%% See Also:
%%*%%*%%
-spec new(Bits, Width, Height, [Option]) -> wxCursor()
when
Bits :: binary(), % An array of bits.
Width :: integer(), % Cursor width.
Height :: integer(), % Cursor height.
Option :: {hotSpotX, integer()} % Hotspot x coordinate.
| {hotSpotY, integer()}. % Hotspot y coordinate.
new(Bits, Width, Height, Options)
when
is_binary(Bits),
is_integer(Width),
is_integer(Height),
is_list(Options) ->
wxe_util:send_bin(Bits),
MOpts = fun({hotSpotX, HotSpotX}, Acc) -> [<<1:32/?UI,HotSpotX:32/?UI>>|Acc];
({hotSpotY, HotSpotY}, Acc) -> [<<2:32/?UI,HotSpotY:32/?UI>>|Acc];
(BadOpt, _) -> erlang:error({badoption, BadOpt})
end,
BinOpt = list_to_binary(lists:foldl(MOpts, [<<0:32>>], Options)),
wxe_util:construct(?wxCursor_new_4,
<<Width:32/?UI,Height:32/?UI, BinOpt/binary>>).
%·%% OK %%·%
%%
%% Returns true if cursor data is present.
%%
%% Return Value:
%% See Also:
%%*%%*%%
-spec ok(This) -> boolean()
when
This :: wxCursor().
ok(#wx_ref{type=ThisT,ref=ThisRef}) ->
?CLASS(ThisT,wxCursor),
wxe_util:call(?wxCursor_Ok,
<<ThisRef:32/?UI>>).
%·%% DESTROY %%·%
%%
%% Destroys the cursor.
%% See reference-counted object destruction for more info.
%%
%% A cursor can be reused for more than one window,
%% and does not get destroyed when the window is destroyed.
%% wxWidgets destroys all cursors on application exit,
%% although it is best to clean them up explicitly.
%%
%% @doc Destroys this object, do not use object again
-spec destroy(This :: wxCursor()) -> ok.
destroy(Obj=#wx_ref{type=Type}) ->
?CLASS(Type,wxCursor),
wxe_util:destroy(?DESTROY_OBJECT,Obj),
ok.
%% EXAMPLE
%% ———————
%% The following is an example of creating a cursor from 32x32 bitmap data
%% (down_bits) and a mask (down_mask) where 1 is black and 0
%% is white for the bits, and 1 is opaque and 0 is transparent for the mask.
%% It works on Windows and GTK+.
%%
%% static char down_bits[] = { 255, 255, 255, 255, 31,
%% 255, 255, 255, 31, 255, 255, 255, 31, 255, 255, 255,
%% 31, 255, 255, 255, 31, 255, 255, 255, 31, 255, 255,
%% 255, 31, 255, 255, 255, 31, 255, 255, 255, 25, 243,
%% 255, 255, 19, 249, 255, 255, 7, 252, 255, 255, 15, 254,
%% 255, 255, 31, 255, 255, 255, 191, 255, 255, 255, 255,
%% 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
%% 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
%% 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
%% 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
%% 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
%% 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
%% 255 };
%%
%% static char down_mask[] = { 240, 1, 0, 0, 240, 1,
%% 0, 0, 240, 1, 0, 0, 240, 1, 0, 0, 240, 1, 0, 0, 240, 1,
%% 0, 0, 240, 1, 0, 0, 240, 1, 0, 0, 255, 31, 0, 0, 255,
%% 31, 0, 0, 254, 15, 0, 0, 252, 7, 0, 0, 248, 3, 0, 0,
%% 240, 1, 0, 0, 224, 0, 0, 0, 64, 0, 0, 0, 0, 0, 0, 0, 0,
%% 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
%% 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
%% 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
%% 0, 0, 0, 0, 0 };
%%
%% #ifdef __WXMSW__
%% wxBitmap down_bitmap(down_bits, 32, 32);
%% wxBitmap down_mask_bitmap(down_mask, 32, 32);
%%
%% down_bitmap.SetMask(new wxMask(down_mask_bitmap));
%% wxImage down_image = down_bitmap.ConvertToImage();
%% down_image.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_X, 6);
%% down_image.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_Y, 14);
%% wxCursor down_cursor = wxCursor(down_image);
%% #else
%% wxCursor down_cursor = wxCursor(down_bits, 32, 32,
%% 6, 14, down_mask, wxWHITE, wxBLACK);
%% #endif
%% From wxBitmap
%% @hidden
setWidth(This,Width) -> wxBitmap:setWidth(This,Width).
%% @hidden
setPalette(This,Palette) -> wxBitmap:setPalette(This,Palette).
%% @hidden
setMask(This,Mask) -> wxBitmap:setMask(This,Mask).
%% @hidden
setHeight(This,Height) -> wxBitmap:setHeight(This,Height).
%% @hidden
setDepth(This,Depth) -> wxBitmap:setDepth(This,Depth).
%% @hidden
saveFile(This,Name,Type, Options) -> wxBitmap:saveFile(This,Name,Type, Options).
%% @hidden
saveFile(This,Name,Type) -> wxBitmap:saveFile(This,Name,Type).
%% @hidden
loadFile(This,Name, Options) -> wxBitmap:loadFile(This,Name, Options).
%% @hidden
loadFile(This,Name) -> wxBitmap:loadFile(This,Name).
%% @hidden
getSubBitmap(This,Rect) -> wxBitmap:getSubBitmap(This,Rect).
%% @hidden
getWidth(This) -> wxBitmap:getWidth(This).
%% @hidden
getMask(This) -> wxBitmap:getMask(This).
%% @hidden
getPalette(This) -> wxBitmap:getPalette(This).
%% @hidden
getHeight(This) -> wxBitmap:getHeight(This).
%% @hidden
getDepth(This) -> wxBitmap:getDepth(This).
%% @hidden
copyFromIcon(This,Icon) -> wxBitmap:copyFromIcon(This,Icon).
%% @hidden
convertToImage(This) -> wxBitmap:convertToImage(This).
|