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
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548 | % |¯\ |_¯ |\ |
%\ 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_wxpen.html">wxPen</a>.
%% @type wxPen().
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%% OVERVIEW
%% ––––––––
%% A pen is a drawing tool for drawing outlines.
%% It is used for drawing lines and painting the outline
%% of rectangles, ellipses, etc.
%% It has a colour, a width and a style.
%%
%%
%% On a monochrome display, wxWidgets shows all non-white pens as black.
%%
%% Do not initialize objects on the stack before the program commences,
%% since other required structures may not have been set up yet.
%% Instead, define global pointers to objects and create
%% them in OnInit or when required.
%%
%% An application may wish to dynamically create pens with different
%% characteristics, and there is the consequent danger that a
%% large number of duplicate pens will be created.
%% Therefore an application may wish to get a pointer
%% to a pen by using the global list of pens wxThePenList,
%% and calling the member function FindOrCreatePen.
%% See the entry for wxPenList.
%%
%% This class uses reference counting and copy-on-write internally
%% so that assignments between two instances of this class are very cheap.
%% You can therefore use actual objects instead of pointers without efficiency problems.
%% If an instance of this class is changed it will create its own data
%% internally so that other instances, which previously shared the
%% data using the reference counting, are not affected.
%%
%%
%% PREDEFINED OBJECTS
%%
%% Objects:
%%
%% wxNullPen
%%
%% Pointers:
%% wxRED_PEN
%% wxCYAN_PEN
%% wxGREEN_PEN
%% wxBLACK_PEN
%% wxWHITE_PEN
%% wxTRANSPARENT_PEN
%% wxBLACK_DASHED_PEN
%% wxGREY_PEN
%% wxMEDIUM_GREY_PEN
%% wxLIGHT_GREY_PEN
%%
%%
%% See Also:
%% —————————
%% wxPenList, wxDC, wxDC::SetPen
%%
%%
-module(wxPen).
-include("wxe.hrl").
-export([
%% Con/De - structors
new/0 ,
new/1 ,
new/2 ,
destroy/1 ,
%% Get/Sets
getCap/1 ,
setCap/2 ,
getColour/1 ,
setColour/2 ,
setColour/4 ,
getJoin/1 ,
setJoin/2 ,
getStyle/1 ,
setStyle/2 ,
getWidth/1 ,
setWidth/2 ,
%% Other
isOk/1
]).
%% inherited exports
-export([parent_class/1]).
-export_type([wxPen/0]).
%% @hidden
parent_class(_Class) -> erlang:error({badtype, ?MODULE}).
-type wxPen() :: wx:wx_object().
%·%% NEW / 0 %%·%
%%
%% Default constructor.
%% The pen will be uninitialised, and wxPen:IsOk will return false.
%%
%% Return Value:
%% See Also:
%%*%%*%%
-spec new() -> wxPen().
new() ->
wxe_util:construct(?wxPen_new_0,
<<>>).
%·%% NEW / 1 %%·%
%% @equiv new(Colour, [])
-spec new(Colour) -> wxPen()
when
Colour :: wx:wx_colour().
new(Colour)
when
tuple_size(Colour) =:= 3;
tuple_size(Colour) =:= 4 -> new(Colour, []).
%% NOTICE - Color it a Tuple
%% {R,G,B} or {R,G,B,A}
%·%% NEW / 2 %%·%
%%
%% Constructs a pen from a colour object, pen width and style.
%%
%% Different versions of Windows and different versions of other platforms
%% support very different subsets of the styles above - there is no similarity
%% even between Windows95 and Windows98 - so handle with care.
%%
%% If the named colour form is used, an appropriate wxColour structure
%% is found in the colour database.
%%
%% Return Value:
%% See Also: wxPen::SetStyle, wxPen::SetColour, wxPen::SetWidth, wxPen::SetStipple
%%*%%*%%
-spec new(Colour, [Option]) -> wxPen()
when
Colour :: wx:wx_colour(),
Option :: {width, integer()} %% Pen width. Under Windows,
%% the pen width cannot be greater than 1 if
%% the style is wxDOT, wxLONG_DASH, wxSHORT_DASH,
%% wxDOT_DASH, or wxUSER_DASH.
| {style, integer()}.
%% The style may be one of the following:
%%
%% wxSOLID Solid style.
%% wxTRANSPARENT No pen is used.
%% wxDOT Dotted style.
%% wxLONG_DASH Long dashed style.
%% wxSHORT_DASH Short dashed style.
%% wxDOT_DASH Dot and dash style.
%% wxSTIPPLE Use the stipple bitmap.
%% wxUSER_DASH Use the user dashes: see wxPen::SetDashes.
%% wxBDIAGONAL_HATCH Backward diagonal hatch.
%% wxCROSSDIAG_HATCH Cross-diagonal hatch.
%% wxFDIAGONAL_HATCH Forward diagonal hatch.
%% wxCROSS_HATCH Cross hatch.
%% wxHORIZONTAL_HATCH Horizontal hatch.
%% wxVERTICAL_HATCH Vertical hatch.
new(Colour, Options)
when
tuple_size(Colour) =:= 3;
tuple_size(Colour) =:= 4,
is_list(Options) ->
MOpts = fun({width, Width}, Acc) -> [<<1:32/?UI,Width:32/?UI>>|Acc];
({style, Style}, Acc) -> [<<2:32/?UI,Style:32/?UI>>|Acc];
(BadOpt, _) -> erlang:error({badoption, BadOpt})
end,
BinOpt = list_to_binary(lists:foldl(MOpts, [<<0:32>>], Options)),
wxe_util:construct(?wxPen_new_2,
<<(wxe_util:colour_bin(Colour)):16/binary, BinOpt/binary>>).
%·%% GET CAP %%·%
%%
%% Returns the pen cap style,
%% which may be one of wxCAP_ROUND,
%% wxCAP_PROJECTING and
%% wxCAP_BUTT.
%%
%% The default is wxCAP_ROUND.
%%
%% Return Value:
%% See Also: wxPen::SetCap
%%*%%*%%
-spec getCap(This) -> integer()
when
This :: wxPen().
getCap(#wx_ref{type=ThisT,ref=ThisRef}) ->
?CLASS(ThisT,wxPen),
wxe_util:call(?wxPen_GetCap,
<<ThisRef:32/?UI>>).
%·%% GET COLOUR %%·%
%%
%% Returns a reference to the pen colour.
%%
%% Return Value:
%% See Also: wxPen::SetColour
%%*%%*%%
-spec getColour(This) -> wx:wx_colour4()
when
This :: wxPen().
getColour(#wx_ref{type=ThisT,ref=ThisRef}) ->
?CLASS(ThisT,wxPen),
wxe_util:call(?wxPen_GetColour,
<<ThisRef:32/?UI>>).
%·%% GET JOIN %%·%
%%
%% Returns the pen join style, which may be one of wxJOIN_BEVEL,
%% wxJOIN_ROUND and
%% wxJOIN_MITER.
%% The default is wxJOIN_ROUND.
%%
%% Return Value:
%% See Also:
%%*%%*%%
-spec getJoin(This) -> integer()
when
This :: wxPen().
getJoin(#wx_ref{type=ThisT,ref=ThisRef}) ->
?CLASS(ThisT,wxPen),
wxe_util:call(?wxPen_GetJoin,
<<ThisRef:32/?UI>>).
%·%% GET STYLE %%·%
%%
%% Returns the pen style.
%%
%% Return Value:
%% See Also: wxPen::wxPen, wxPen::SetStyle
%%*%%*%%
-spec getStyle(This) -> integer()
when
This :: wxPen().
getStyle(#wx_ref{type=ThisT,ref=ThisRef}) ->
?CLASS(ThisT,wxPen),
wxe_util:call(?wxPen_GetStyle,
<<ThisRef:32/?UI>>).
%·%% GET WIDTH %%·%
%%
%% Returns the pen width.
%%
%% Return Value:
%% See Also: wxPen::SetWidth
%%*%%*%%
-spec getWidth(This) -> integer()
when
This :: wxPen().
getWidth(#wx_ref{type=ThisT,ref=ThisRef}) ->
?CLASS(ThisT,wxPen),
wxe_util:call(?wxPen_GetWidth,
<<ThisRef:32/?UI>>).
%·%% IS OK %%·%
%%
%% Returns true if the pen is initialised.
%%
%% Return Value:
%% See Also:
%%*%%*%%
-spec isOk(This) -> boolean()
when
This :: wxPen().
isOk(#wx_ref{type=ThisT,ref=ThisRef}) ->
?CLASS(ThisT,wxPen),
wxe_util:call(?wxPen_IsOk,
<<ThisRef:32/?UI>>).
%·%% SET CAP %%·%
%%
%% Sets the pen cap style,
%% which may be one of wxCAP_ROUND,
%% wxCAP_PROJECTING and
%% wxCAP_BUTT.
%%
%% The default is wxCAP_ROUND.
%%
%%
%% Return Value:
%% See Also: wxPen::GetCap
%%*%%*%%
-spec setCap(This, CapStyle) -> ok
when
This :: wxPen(),
CapStyle :: wx:wx_enum(). %%<br /> CapStyle = integer
setCap(#wx_ref{type=ThisT,ref=ThisRef}, CapStyle)
when
is_integer(CapStyle) ->
?CLASS(ThisT,wxPen),
wxe_util:cast(?wxPen_SetCap,
<<ThisRef:32/?UI,CapStyle:32/?UI>>).
%·%% SET COLOUR / 2 %%·%
%%
%% The pen's colour is changed to the given colour.
%%
%% Return Value:
%% See Also: wxPen::GetColour
%%*%%*%%
-spec setColour(This, Colour) -> ok
when
This :: wxPen(),
Colour :: wx:wx_colour().
setColour(#wx_ref{type=ThisT,ref=ThisRef}, Colour)
when
tuple_size(Colour) =:= 3;
tuple_size(Colour) =:= 4 ->
?CLASS(ThisT,wxPen),
wxe_util:cast(?wxPen_SetColour_1,
<<ThisRef:32/?UI,(wxe_util:colour_bin(Colour)):16/binary>>).
%·%% SET COLOUR / 4 %%·%
%%
%% The pen's colour is changed to the given colour.
%%
%% Return Value:
%% See Also: wxPen::GetColour
%%*%%*%%
-spec setColour(This, Red, Green, Blue) -> ok
when
This :: wxPen(),
Red :: integer(),
Green :: integer(),
Blue :: integer().
setColour(#wx_ref{type=ThisT,ref=ThisRef}, Red, Green, Blue)
when
is_integer(Red),
is_integer(Green),
is_integer(Blue) ->
?CLASS(ThisT,wxPen),
wxe_util:cast(?wxPen_SetColour_3,
<<ThisRef:32/?UI,Red:32/?UI,Green:32/?UI,Blue:32/?UI>>).
%·%% SET JOIN %%·%
%%
%% Returns the pen join style, which may be one of wxJOIN_BEVEL,
%% wxJOIN_ROUND and
%% wxJOIN_MITER.
%% The default is wxJOIN_ROUND.
%%
%% Return Value:
%% See Also:
%%*%%*%%
-spec setJoin(This, JoinStyle) -> ok
when
This :: wxPen(),
JoinStyle :: wx:wx_enum(). %% JoinStyle = integer
setJoin(#wx_ref{type=ThisT,ref=ThisRef}, JoinStyle)
when
is_integer(JoinStyle) ->
?CLASS(ThisT,wxPen),
wxe_util:cast(?wxPen_SetJoin,
<<ThisRef:32/?UI,JoinStyle:32/?UI>>).
%·%% SET STYLE %%·%
%%
%% Set the pen style.
%%
%% Return Value:
%% See Also: wxPen::wxPen
%%*%%*%%
-spec setStyle(This, Style) -> ok
when
This :: wxPen(),
Style :: integer().
setStyle(#wx_ref{type=ThisT,ref=ThisRef}, Style)
when
is_integer(Style) ->
?CLASS(ThisT,wxPen),
wxe_util:cast(?wxPen_SetStyle,
<<ThisRef:32/?UI,Style:32/?UI>>).
%·%% SET WIDTH %%·%
%%
%% Sets the pen width.
%%
%% Return Value:
%% See Also: wxPen::GetWidth
%%*%%*%%
-spec setWidth(This, Width) -> ok
when
This :: wxPen(),
Width :: integer().
setWidth(#wx_ref{type=ThisT,ref=ThisRef}, Width)
when
is_integer(Width) ->
?CLASS(ThisT,wxPen),
wxe_util:cast(?wxPen_SetWidth,
<<ThisRef:32/?UI,Width:32/?UI>>).
%·%% DESTROY %%·%
%% Destructor. See reference-counted object destruction for more info.
%%
%% Although all remaining pens are deleted when the application exits,
%% the application should try to clean up all pens itself.
%% This is because wxWidgets cannot know if a pointer to the
%% pen object is stored in an application data structure,
%% and there is a risk of double deletion.
%%
%% @doc Destroys this object, do not use object again
-spec destroy(This :: wxPen()) -> ok.
destroy(Obj=#wx_ref{type=Type}) ->
?CLASS(Type,wxPen),
wxe_util:destroy(?DESTROY_OBJECT,Obj),
ok.
|