wxErlang

wxBrush.erl

  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
%          |¯|  |¯\ ) (  (` | | 
%\     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_wxbrush.html">wxBrush</a>.
%% @type wxBrush().  
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%   
%%   OVERVIEW
%%   ––––––––
%%   A brush is a drawing tool for filling in areas. It is used for painting 
%%   the background of rectangles, ellipses, etc. It has a colour and a style.
%%   
%%   On a monochrome display, wxWidgets shows all brushes as white 
%%   unless the colour is really 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 wxApp::OnInit or when required.
%%   
%%   An application may wish to create brushes with different characteristics 
%%   dynamically, and there is the consequent danger that a large number of 
%%   duplicate brushes will be created. Therefore an application may wish to 
%%   get a pointer to a brush by using the global list of brushes wxTheBrushList, 
%%   and calling the member function FindOrCreateBrush.
%%   
%%   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.  
%% 
%%   See Also:
%%   —————————
%%    wxBrushList, wxDC, wxDC::SetBrush
%%   
%%   
-module(wxBrush).
-include("wxe.hrl").
-export([
                   
                    new/0 ,
                    new/1 ,
                    new/2 ,
                    destroy/1 ,

                    getColour/1 ,
                    setColour/2 ,
                    setColour/4 ,

                    getStipple/1 ,
                    setStipple/2 ,

                    getStyle/1 ,
                    setStyle/2,                    


                    isHatch/1 ,

                    isOk/1 

                    ]).

%% inherited exports
-export([parent_class/1]).

-export_type([wxBrush/0]).
%% @hidden
parent_class(_Class) -> erlang:error({badtype, ?MODULE}).




-type wxBrush()  ::  wx:wx_object().




           %·%% NEW %%·%

%%   
%%    Default constructor. The brush will be uninitialised, and wxBrush:IsOk will return false.
%%   
%% Return Value:
%% See Also:
%%*%%*%%
          -spec new() -> wxBrush().

new() ->
  wxe_util:construct(?wxBrush_new_0,
               <<>>).


%%    
%%   Constructs a brush from a colour object and style.
%%
%%   Constructs a stippled brush using a bitmap.
%%
%%   If a stipple brush is created, the brush style will be set to wxSTIPPLE.
%%
%% Return Value:
%% See Also: wxBrushList, wxColour, wxColourDatabase
%%*%%*%%
          -spec new(Colour)           ->    wxBrush()
           when
           Colour :: wx:wx_colour();

                   (StippleBitmap)    ->    wxBrush()
           when
           StippleBitmap :: wxBitmap:wxBitmap().

new(Colour)
           when 
           tuple_size(Colour) =:= 3;
           tuple_size(Colour) =:= 4 ->

new(Colour, []);
new(#wx_ref{type=StippleBitmapT,ref=StippleBitmapRef}) ->
                             ?CLASS(StippleBitmapT,wxBitmap),
          wxe_util:construct(?wxBrush_new_1,
          <<StippleBitmapRef:32/?UI>>).


%%    
%%    Constructs a brush from a colour name and style.
%%
%%   Style — One of:
%%   
%%   wxTRANSPARENT         Transparent (no fill).
%%   wxSOLID               Solid.
%%   wxSTIPPLE             Uses a bitmap as a stipple.
%%   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. 
%%   
%% Return Value:
%% See Also: wxBrushList, wxColour, wxColourDatabase
%%*%%*%%
          -spec new(Colour, [Option]) -> wxBrush()
           when
           Colour :: wx:wx_colour(),
           Option  ::  {style, integer()}.

new(Colour, Options)
           when 
           tuple_size(Colour) =:= 3; 
           tuple_size(Colour) =:= 4,
           is_list(Options) ->

                   MOpts = fun({style, Style},  Acc) -> [<<1: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(?wxBrush_new_2,
                                     <<(wxe_util:colour_bin(Colour)):16/binary, BinOpt/binary>>).









           %·%% GET COLOUR %%·%

%%   
%%   Returns a reference to the brush colour.
%%   
%% Return Value:
%% See Also:
%%*%%*%%
          -spec getColour(This) -> wx:wx_colour4()
           when
           This :: wxBrush().

getColour(#wx_ref{type=ThisT,ref=ThisRef}) ->
                                            ?CLASS(ThisT,wxBrush),
                              wxe_util:call(?wxBrush_GetColour,
                              <<ThisRef:32/?UI>>).







           %·%% GET STIPPLE %%·%

%%   
%%   Gets a pointer to the stipple bitmap. 
%%   If the brush does not have a wxSTIPPLE style, 
%%   this bitmap may be non-NULL but uninitialised (wxBitmap:IsOk returns false).
%%   
%% Return Value:
%% See Also: wxBrush::SetStipple
%%*%%*%%
          -spec getStipple(This) -> wxBitmap:wxBitmap()
           when
           This :: wxBrush().

getStipple(#wx_ref{type=ThisT,ref=ThisRef}) ->
                                             ?CLASS(ThisT,wxBrush),
                               wxe_util:call(?wxBrush_GetStipple,
                               <<ThisRef:32/?UI>>).





           %·%% GET STYLE %%·%

%%   
%%   Returns the brush style, one of:
%%   
%%   wxTRANSPARENT             Transparent (no fill).
%%   wxSOLID                   Solid.
%%   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.
%%   wxSTIPPLE                 Stippled using a bitmap.
%%   wxSTIPPLE_MASK_OPAQUE     Stippled using a bitmap's mask. 
%%   
%% Return Value:
%% See Also: wxBrush::SetStyle, wxBrush::SetColour, wxBrush::SetStipple
%%*%%*%%
          -spec getStyle(This) -> integer()
           when
           This :: wxBrush().

getStyle(#wx_ref{type=ThisT,ref=ThisRef}) ->
                                           ?CLASS(ThisT,wxBrush),
                             wxe_util:call(?wxBrush_GetStyle,
                             <<ThisRef:32/?UI>>).







           %·%% IS HATCH %%·%

%%   
%%    Returns true if the style of the brush is any of hatched fills.
%%   
%% Return Value:
%% See Also:
%%*%%*%%
          -spec isHatch(This) -> boolean()
           when
           This :: wxBrush().

isHatch(#wx_ref{type=ThisT,ref=ThisRef}) ->
                                          ?CLASS(ThisT,wxBrush),
                            wxe_util:call(?wxBrush_IsHatch,
                            <<ThisRef:32/?UI>>).





           %·%% IS OK %%·%

%%   
%%   Returns true if the brush is initialised. 
%%   It will return false if the default constructor has been used (for example, 
%%   the brush is a member of a class, or NULL has been assigned to it).
%%   
%% Return Value:
%% See Also:
%%*%%*%%
          -spec isOk(This) -> boolean()
           when
           This :: wxBrush().

isOk(#wx_ref{type=ThisT,ref=ThisRef}) ->
                                       ?CLASS(ThisT,wxBrush),
                         wxe_util:call(?wxBrush_IsOk,
                         <<ThisRef:32/?UI>>).







           %·%% SET COLOUR %%·%

%%   
%%   Sets the brush colour using a reference to a colour object.
%%   
%% Return Value:
%% See Also:
%%*%%*%%
          -spec setColour(This, Col) -> ok
           when
           This ::      wxBrush(),
           Col  :: wx:wx_colour().

setColour(#wx_ref{type=ThisT,ref=ThisRef}, Col)
           when 
           tuple_size(Col) =:= 3; 
           tuple_size(Col) =:= 4 ->
                                  ?CLASS(ThisT,wxBrush),
                    wxe_util:cast(?wxBrush_SetColour_1,
                    <<ThisRef:32/?UI,(wxe_util:colour_bin(Col)):16/binary>>).


%%    
%%   Sets the brush colour using red, green and blue values.
%%
%% Return Value:
%% See Also: wxBrush::GetColour
%%*%%*%%
          -spec setColour(This, R, G, B) -> ok
           when
           This :: wxBrush(),
           R    :: integer(),
           G    :: integer(),
           B    :: integer().

setColour(#wx_ref{type=ThisT,ref=ThisRef}, R, G, B)
           when 
           is_integer(R),
           is_integer(G),
           is_integer(B) ->
                          ?CLASS(ThisT,wxBrush),
            wxe_util:cast(?wxBrush_SetColour_3,
            <<ThisRef:32/?UI,R:32/?UI,G:32/?UI,B:32/?UI>>).








           %·%% SET STIPPLE %%·%

%%   
%%   Sets the stipple bitmap.
%%   
%%   The style will be set to wxSTIPPLE, unless the bitmap has a mask 
%%   associated to it, in which case the style will be set to wxSTIPPLE_MASK_OPAQUE.
%%   
%%   If the wxSTIPPLE variant is used, the bitmap will be used to fill out 
%%   the area to be drawn. If the wxSTIPPLE_MASK_OPAQUE is used, the current 
%%   text foreground and text background determine what colours are used for 
%%   displaying and the bits in the mask (which is a mono-bitmap actually) 
%%   determine where to draw what.
%%   
%%   Note that under Windows 95, only 8x8 pixel large stipple bitmaps are 
%%   supported, Windows 98 and NT as well as GTK support arbitrary bitmaps.
%%
%% Return Value:
%% See Also:
%%*%%*%%
          -spec setStipple(This, Stipple) -> ok
           when
           This    ::           wxBrush(),
           Stipple :: wxBitmap:wxBitmap(). %% The bitmap to use for stippling.

setStipple(#wx_ref{type=ThisT,ref=ThisRef},
           #wx_ref{type=StippleT,ref=StippleRef}) ->
                                                   ?CLASS(ThisT,wxBrush),
                                                   ?CLASS(StippleT,wxBitmap),
                                     wxe_util:cast(?wxBrush_SetStipple,
                                     <<ThisRef:32/?UI,StippleRef:32/?UI>>).







           %·%% SET STYLE %%·%

%%   
%%   Sets the brush style.
%%   
%%   wxTRANSPARENT             Transparent (no fill).
%%   wxSOLID                   Solid.
%%   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.
%%   wxSTIPPLE                 Stippled using a bitmap.
%%   wxSTIPPLE_MASK_OPAQUE     Stippled using a bitmap's mask. 
%%
%% Return Value:
%% See Also:
%%*%%*%%
          -spec setStyle(This, Style) -> ok
           when
           This  :: wxBrush(),
           Style :: integer().

setStyle(#wx_ref{type=ThisT,ref=ThisRef}, Style)
           when 
           is_integer(Style) ->
                              ?CLASS(ThisT,wxBrush),
                wxe_util:cast(?wxBrush_SetStyle,
                <<ThisRef:32/?UI,Style:32/?UI>>).







           %·%% DESTROY %%·%

%%   
%%   
%% @doc Destroys this object, do not use object again
          -spec destroy(This :: wxBrush()) -> ok.

destroy(Obj=#wx_ref{type=Type}) ->
                                 ?CLASS(Type,wxBrush),
                wxe_util:destroy(?DESTROY_OBJECT,Obj),
                ok.