wxErlang

wxGraphicsRenderer.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
%       /¯_ |¯\  /\  |¯\ | |  | /¯   (`  |¯\ |_¯ |\ | |¯\ |_¯ |¯\ |_¯ |¯\ 
%\  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_wxgraphicsrenderer.html">wxGraphicsRenderer</a>.
%% @type wxGraphicsRenderer().  
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%   
%%   OVERVIEW
%%   ––––––––
%%   A wxGraphicsRenderer is the instance corresponding 
%%   to the rendering engine used. 
%%
%%   There may be multiple instances on a system, 
%%   if there are different rendering engines present, 
%%   but there is always one instance per engine, 
%%   eg there is ONE core graphics renderer instance on OSX. 
%%   
%%   This instance is pointed back to by all objects created by it 
%%   (wxGraphicsContext, wxGraphicsPath etc). 
%%   
%%   Therefore you can create ag additional instances of paths etc. 
%%   by calling GetRenderer() and then using the appropriate CreateXXX function.
%%   
%%   
%%   See Also:
%%   —————————
%%   
%%   
%%   
-module(wxGraphicsRenderer).
-include("wxe.hrl").
-export([createBrush/2,
         createContext/2,
         createFont/2,
         createFont/3,
         createLinearGradientBrush/7,
         createMatrix/1,
         createMatrix/2,
         createPath/1,
         createPen/2,
         createRadialGradientBrush/8,
         getDefaultRenderer/0]).


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

-export_type([wxGraphicsRenderer/0]).
-deprecated([createLinearGradientBrush/7,createRadialGradientBrush/8]).


%% @hidden
parent_class(_Class) -> erlang:error({badtype, ?MODULE}).

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




           %·%% GET DEFAULT RENDERER %%·%

%%   
%%    Returns the default renderer on this platform. 
%%    On OS X this is the Core Graphics (a.k.a. Quartz 2D) renderer, 
%%    on MSW the GDIPlus renderer, 
%%    and on GTK we currently default to the cairo renderer.
%%   
%% Return Value:
%% See Also:
%%*%%*%%
          -spec getDefaultRenderer() -> wxGraphicsRenderer().

getDefaultRenderer() ->
                         wxe_util:call(?wxGraphicsRenderer_GetDefaultRenderer,
                         <<>>).





           %·%% CREATE CONTEXT %%·%

%%   
%%    Creates a wxGraphicsContext from a wxWindowDC (eg a wxPaintDC).
%%     or
%%    Creates a wxGraphicsContext from a wxWindow.
%%
%% Return Value:
%% See Also:
%%*%%*%%
          -spec createContext(This, Dc) -> wxGraphicsContext:wxGraphicsContext()
           when
           This ::    wxGraphicsRenderer(), 
           Dc   :: wxWindowDC:wxWindowDC() 
                 |     wxWindow:wxWindow().

createContext(#wx_ref{type=ThisT,ref=ThisRef},
              #wx_ref{type=DcT,ref=DcRef})    ->
                                               ?CLASS(ThisT,wxGraphicsRenderer),
                                   DcOP = case ?CLASS_T(DcT,wxWindowDC) 
                                          of
                                            true ->
                                                   ?wxGraphicsRenderer_CreateContext_1_1;
                                            _ -> ?CLASS(DcT,wxWindow),
                                                   ?wxGraphicsRenderer_CreateContext_1_0
                                          end,
                                          wxe_util:call(DcOP,
                                          <<ThisRef:32/?UI,DcRef:32/?UI>>).





           %·%% CREATE PEN %%·%

%%   
%%    Creates a native pen from a wxPen.
%%   
%% Return Value:
%% See Also:
%%*%%*%%
          -spec createPen(This, Pen) -> wxGraphicsPen:wxGraphicsPen()
           when
           This :: wxGraphicsRenderer(), 
           Pen  ::        wxPen:wxPen().

createPen(#wx_ref{type=ThisT,ref=ThisRef},
          #wx_ref{type=PenT,ref=PenRef}) ->
                                          ?CLASS(ThisT,wxGraphicsRenderer),
                                          ?CLASS(PenT,wxPen),
                            wxe_util:call(?wxGraphicsRenderer_CreatePen,
                            <<ThisRef:32/?UI,PenRef:32/?UI>>).





           %·%% CREATE BRUSH %%·%

%%   
%%    Creates a native brush from a wxBrush.
%%   
%% Return Value:
%% See Also:
%%*%%*%%
          -spec createBrush(This, Brush) -> wxGraphicsBrush:wxGraphicsBrush()
           when
           This  :: wxGraphicsRenderer(), 
           Brush ::    wxBrush:wxBrush().

createBrush(#wx_ref{type=ThisT,ref=ThisRef},
            #wx_ref{type=BrushT,ref=BrushRef}) ->
                                                ?CLASS(ThisT,wxGraphicsRenderer),
                                                ?CLASS(BrushT,wxBrush),
                                  wxe_util:call(?wxGraphicsRenderer_CreateBrush,
                                  <<ThisRef:32/?UI,BrushRef:32/?UI>>).





           %·%% CREATE LINEAR GRADIENT BRUSH %%·%

%%   
%%    Creates a native brush, having a linear gradient, 
%%    starting at (x1,y1) with color c1 to (x2,y2) with color c2
%%   
%% Return Value:
%% See Also:
%%*%%*%%
          -spec createLinearGradientBrush(This, X1, Y1, X2, Y2, C1, C2) -> wxGraphicsBrush:wxGraphicsBrush()
           when
           This :: wxGraphicsRenderer(), 
           X1   ::             number(), 
           Y1   ::             number(), 
           X2   ::             number(), 
           Y2   ::             number(), 
           C1   ::       wx:wx_colour(), 
           C2   ::       wx:wx_colour().

createLinearGradientBrush(#wx_ref{type=ThisT,ref=ThisRef},X1,Y1,X2,Y2,C1,C2)
           when 
           is_number(X1),
           is_number(Y1),
           is_number(X2),
           is_number(Y2),
           tuple_size(C1) =:= 3;
           tuple_size(C1) =:= 4,
           tuple_size(C2) =:= 3;
           tuple_size(C2) =:= 4 ->
                                 ?CLASS(ThisT,wxGraphicsRenderer),
                   wxe_util:call(?wxGraphicsRenderer_CreateLinearGradientBrush,
                   <<ThisRef:32/?UI,0:32,X1:64/?F,Y1:64/?F,X2:64/?F,Y2:64/?F,(wxe_util:colour_bin(C1)):16/binary,
                                                                             (wxe_util:colour_bin(C2)):16/binary>>).






           %·%% CREATE RADIAL GRADIENT BRUSH %%·%

%%   
%%    Creates a native brush, having a radial gradient 
%%     originating at (xo,yc) with color oColour   & 
%%     ends on a circle around (xc,yc) with radius r and color cColour
%%   
%% Return Value:
%% See Also:
%%*%%*%%
          -spec createRadialGradientBrush(This, Xo, Yo, Xc, Yc, Radius, OColor, CColor) -> wxGraphicsBrush:wxGraphicsBrush()
           when
           This   :: wxGraphicsRenderer(), 
           Xo     ::             number(), 
           Yo     ::             number(), 
           Xc     ::             number(), 
           Yc     ::             number(), 
           Radius ::             number(), 
           OColor ::       wx:wx_colour(), 
           CColor ::       wx:wx_colour().

createRadialGradientBrush(#wx_ref{type=ThisT,ref=ThisRef},Xo,Yo,Xc,Yc,Radius,OColor,CColor)
           when 
           is_number(Xo),
           is_number(Yo),
           is_number(Xc),
           is_number(Yc),
           is_number(Radius),
           tuple_size(OColor) =:= 3; 
           tuple_size(OColor) =:= 4,
           tuple_size(CColor) =:= 3;
           tuple_size(CColor) =:= 4 ->
                                     ?CLASS(ThisT,wxGraphicsRenderer),
                       wxe_util:call(?wxGraphicsRenderer_CreateRadialGradientBrush,
                       <<ThisRef:32/?UI,0:32,Xo:64/?F,Yo:64/?F,Xc:64/?F,Yc:64/?F,Radius:64/?F,(wxe_util:colour_bin(OColor)):16/binary,
                                                                                              (wxe_util:colour_bin(CColor)):16/binary>>).





           %·%% CREATE FONT %%·%

%%   
%% See below...
%% @equiv createFont(This,Font, [])
          -spec createFont(This, Font) -> wxGraphicsFont:wxGraphicsFont()
           when
           This :: wxGraphicsRenderer(), 
           Font ::      wxFont:wxFont().

createFont(This,Font)
           when 
           is_record(This, wx_ref),
           is_record(Font, wx_ref)     -> createFont(This,Font, []).

%%
%%   Creates a native graphics font from a wxFont and a text colour.
%%    
%% Return Value:
%% See Also:
%%*%%*%%
          -spec createFont(This, Font, [Option]) -> wxGraphicsFont:wxGraphicsFont()
           when
           This    ::  wxGraphicsRenderer(), 
           Font    ::       wxFont:wxFont(),
           Option  ::  {col, wx:wx_colour()}.

createFont(#wx_ref{type=ThisT,ref=ThisRef},
           #wx_ref{type=FontT,ref=FontRef}, 
                                   Options)
           when 
           is_list(Options) ->
                             ?CLASS(ThisT,wxGraphicsRenderer),
                             ?CLASS(FontT,wxFont),
                   MOpts = fun({col, Col}, Acc) -> [<<1:32/?UI,(wxe_util:colour_bin(Col)):16/binary,0:32>>|Acc];
                                    (BadOpt, _) -> erlang:error({badoption, BadOpt})
            end,
                   BinOpt = list_to_binary(lists:foldl(MOpts, [<<0:32>>], Options)),
                                        wxe_util:call(?wxGraphicsRenderer_CreateFont,
                                        <<ThisRef:32/?UI,FontRef:32/?UI, BinOpt/binary>>).







           %·%% CREATE MATRIX %%·%

%%   
%% See below...
%% @equiv createMatrix(This, [])
          -spec createMatrix(This) -> wxGraphicsMatrix:wxGraphicsMatrix()
           when
           This :: wxGraphicsRenderer().

createMatrix(This)
           when 
           is_record(This, wx_ref) -> createMatrix(This, []).

%%
%%    Creates a native affine transformation matrix from the passed in values. 
%%
%%    The defaults result in an identity matrix.
%%    
%% Return Value:
%% See Also:
%%*%%*%%
          -spec createMatrix(This, [Option]) -> wxGraphicsMatrix:wxGraphicsMatrix()
           when
           This    :: wxGraphicsRenderer(),
           Option  :: {a,  number()}
                    | {b,  number()}
                    | {c,  number()}
                    | {d,  number()}
                    | {tx, number()}
                    | {ty, number()}.

createMatrix(#wx_ref{type=ThisT,ref=ThisRef}, Options)
           when 
           is_list(Options) ->
                             ?CLASS(ThisT,wxGraphicsRenderer),
                   MOpts = fun({a,   A}, Acc) -> [<<1:32/?UI,0:32,A:64/?F>>|Acc];
                              ({b,   B}, Acc) -> [<<2:32/?UI,0:32,B:64/?F>>|Acc];
                              ({c,   C}, Acc) -> [<<3:32/?UI,0:32,C:64/?F>>|Acc];
                              ({d,   D}, Acc) -> [<<4:32/?UI,0:32,D:64/?F>>|Acc];
                              ({tx, Tx}, Acc) -> [<<5:32/?UI,0:32,Tx:64/?F>>|Acc];
                              ({ty, Ty}, Acc) -> [<<6:32/?UI,0:32,Ty:64/?F>>|Acc];
                                  (BadOpt, _) -> erlang:error({badoption, BadOpt})
            end,
                   BinOpt = list_to_binary(lists:foldl(MOpts, [<<0:32>>], Options)),
                                        wxe_util:call(?wxGraphicsRenderer_CreateMatrix,
                                        <<ThisRef:32/?UI, 0:32,BinOpt/binary>>).





           %·%% CREATE PATH %%·%

%%   
%%    Creates a native graphics path which is initially empty.
%%   
%% Return Value:
%% See Also:
%%*%%*%%
          -spec createPath(This) -> wxGraphicsPath:wxGraphicsPath()
           when
           This :: wxGraphicsRenderer().
           
createPath(#wx_ref{type=ThisT,ref=ThisRef}) ->
                                             ?CLASS(ThisT,wxGraphicsRenderer),
                               wxe_util:call(?wxGraphicsRenderer_CreatePath,
                               <<ThisRef:32/?UI>>).