~ubuntu-branches/ubuntu/saucy/lazarus/saucy

« back to all changes in this revision

Viewing changes to components/aggpas/alpha_mask3.dpr

  • Committer: Package Import Robot
  • Author(s): Paul Gevers, Abou Al Montacir, Bart Martens, Paul Gevers
  • Date: 2013-06-08 14:12:17 UTC
  • mfrom: (1.1.9)
  • Revision ID: package-import@ubuntu.com-20130608141217-7k0cy9id8ifcnutc
Tags: 1.0.8+dfsg-1
[ Abou Al Montacir ]
* New upstream major release and multiple maintenace release offering many
  fixes and new features marking a new milestone for the Lazarus development
  and its stability level.
  - The detailed list of changes can be found here:
    http://wiki.lazarus.freepascal.org/Lazarus_1.0_release_notes
    http://wiki.lazarus.freepascal.org/Lazarus_1.0_fixes_branch
* LCL changes:
  - LCL is now a normal package.
      + Platform independent parts of the LCL are now in the package LCLBase
      + LCL is automatically recompiled when switching the target platform,
        unless pre-compiled binaries for this target are already installed.
      + No impact on existing projects.
      + Linker options needed by LCL are no more added to projects that do
        not use the LCL package.
  - Minor changes in LCL basic classes behaviour
      + TCustomForm.Create raises an exception if a form resource is not
        found.
      + TNotebook and TPage: a new implementation of these classes was added.
      + TDBNavigator: It is now possible to have focusable buttons by setting
        Options = [navFocusableButtons] and TabStop = True, useful for
        accessibility and for devices with neither mouse nor touch screen.
      + Names of TControlBorderSpacing.GetSideSpace and GetSpace were swapped
        and are now consistent. GetSideSpace = Around + GetSpace.
      + TForm.WindowState=wsFullscreen was added
      + TCanvas.TextFitInfo was added to calculate how many characters will
        fit into a specified Width. Useful for word-wrapping calculations.
      + TControl.GetColorResolvingParent and
        TControl.GetRGBColorResolvingParent were added, simplifying the work
        to obtain the final color of the control while resolving clDefault
        and the ParentColor.
      + LCLIntf.GetTextExtentExPoint now has a good default implementation
        which works in any platform not providing a specific implementation.
        However, Widgetset specific implementation is better, when available.
      + TTabControl was reorganized. Now it has the correct class hierarchy
        and inherits from TCustomTabControl as it should.
  - New unit in the LCL:
      + lazdialogs.pas: adds non-native versions of various native dialogs,
        for example TLazOpenDialog, TLazSaveDialog, TLazSelectDirectoryDialog.
        It is used by widgetsets which either do not have a native dialog, or
        do not wish to use it because it is limited. These dialogs can also be
        used by user applications directly.
      + lazdeviceapis.pas: offers an interface to more hardware devices such
        as the accelerometer, GPS, etc. See LazDeviceAPIs
      + lazcanvas.pas: provides a TFPImageCanvas descendent implementing
        drawing in a LCL-compatible way, but 100% in Pascal.
      + lazregions.pas. LazRegions is a wholly Pascal implementation of
        regions for canvas clipping, event clipping, finding in which control
        of a region tree one an event should reach, for drawing polygons, etc.
      + customdrawncontrols.pas, customdrawndrawers.pas,
        customdrawn_common.pas, customdrawn_android.pas and
        customdrawn_winxp.pas: are the Lazarus Custom Drawn Controls -controls
        which imitate the standard LCL ones, but with the difference that they
        are non-native and support skinning.
  - New APIs added to the LCL to improve support of accessibility software
    such as screen readers.
* IDE changes:
  - Many improvments.
  - The detailed list of changes can be found here:
    http://wiki.lazarus.freepascal.org/New_IDE_features_since#v1.0_.282012-08-29.29
    http://wiki.lazarus.freepascal.org/Lazarus_1.0_release_notes#IDE_Changes
* Debugger / Editor changes:
  - Added pascal sources and breakpoints to the disassembler
  - Added threads dialog.
* Components changes:
  - TAChart: many fixes and new features
  - CodeTool: support Delphi style generics and new syntax extensions.
  - AggPas: removed to honor free licencing. (Closes: Bug#708695)
[Bart Martens]
* New debian/watch file fixing issues with upstream RC release.
[Abou Al Montacir]
* Avoid changing files in .pc hidden directory, these are used by quilt for
  internal purpose and could lead to surprises during build.
[Paul Gevers]
* Updated get-orig-source target and it compinion script orig-tar.sh so that they
  repack the source file, allowing bug 708695 to be fixed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//
2
 
// AggPas 2.4 RM3 Demo application
3
 
// Note: Press F1 key on run to see more info about this demo
4
 
//
5
 
// Paths: src;src\ctrl;src\svg;src\util;src\platform\win;expat-wrap
6
 
//
7
 
program
8
 
 alpha_mask3 ;
9
 
 
10
 
uses
11
 
 SysUtils ,
12
 
 
13
 
 agg_basics ,
14
 
 agg_platform_support ,
15
 
 
16
 
 agg_color ,
17
 
 agg_pixfmt ,
18
 
 agg_pixfmt_rgb ,
19
 
 agg_pixfmt_gray ,
20
 
 
21
 
 agg_ctrl ,
22
 
 agg_slider_ctrl ,
23
 
 agg_cbox_ctrl ,
24
 
 agg_rbox_ctrl ,
25
 
 
26
 
 agg_rendering_buffer ,
27
 
 agg_renderer_base ,
28
 
 agg_renderer_scanline ,
29
 
 agg_renderer_primitives ,
30
 
 agg_rasterizer_scanline_aa ,
31
 
 agg_scanline ,
32
 
 agg_scanline_p ,
33
 
 agg_render_scanlines ,
34
 
 
35
 
 agg_conv_curve ,
36
 
 agg_conv_stroke ,
37
 
 agg_conv_transform ,
38
 
 agg_gsv_text ,
39
 
 agg_pixfmt_amask_adaptor ,
40
 
 agg_alpha_mask_u8 ,
41
 
 agg_vertex_source ,
42
 
 agg_path_storage ,
43
 
 agg_trans_affine ,
44
 
 agg_math_stroke ,
45
 
 
46
 
 make_gb_poly_ ,
47
 
 make_arrows_ ;
48
 
 
49
 
{$I agg_mode.inc }
50
 
 
51
 
const
52
 
 flip_y = true;
53
 
 
54
 
type
55
 
 spiral = object(vertex_source )
56
 
   m_x    ,
57
 
   m_y    ,
58
 
   m_r1   ,
59
 
   m_r2   ,
60
 
   m_step ,
61
 
 
62
 
   m_start_angle ,
63
 
 
64
 
   m_angle  ,
65
 
   m_curr_r ,
66
 
   m_da     ,
67
 
   m_dr     : double;
68
 
   m_start  : boolean;
69
 
 
70
 
   constructor Construct(x ,y ,r1 ,r2 ,step : double; start_angle : double = 0 );
71
 
 
72
 
   procedure rewind(path_id : unsigned ); virtual;
73
 
   function  vertex(x ,y : double_ptr ) : unsigned; virtual;
74
 
 
75
 
  end;
76
 
 
77
 
 the_application = object(platform_support )
78
 
   m_polygons  ,
79
 
   m_operation : rbox_ctrl;
80
 
 
81
 
   m_alpha_buf       : int8u_ptr;
82
 
   m_alpha_aloc      : unsigned;
83
 
   m_alpha_mask_rbuf : rendering_buffer;
84
 
   m_alpha_mask      : amask_no_clip_gray8;
85
 
 
86
 
   m_ras : rasterizer_scanline_aa;
87
 
   m_sl  : scanline_p8;
88
 
 
89
 
   m_x ,
90
 
   m_y : double;
91
 
 
92
 
   constructor Construct(format_ : pix_format_e; flip_y_ : boolean );
93
 
   destructor  Destruct;
94
 
 
95
 
   procedure draw_text(x ,y : double; str : char_ptr );
96
 
 
97
 
   procedure generate_alpha_mask(vs : vertex_source_ptr );
98
 
   procedure perform_rendering  (vs : vertex_source_ptr );
99
 
 
100
 
   function  render : unsigned;
101
 
 
102
 
   procedure on_init; virtual;
103
 
   procedure on_draw; virtual;
104
 
 
105
 
   procedure on_mouse_move       (x ,y : int; flags : unsigned ); virtual;
106
 
   procedure on_mouse_button_down(x ,y : int; flags : unsigned ); virtual;
107
 
 
108
 
   procedure on_key(x ,y : int; key ,flags : unsigned ); virtual;
109
 
 
110
 
  end;
111
 
 
112
 
{ CONSTRUCT }
113
 
constructor spiral.Construct;
114
 
begin
115
 
 m_x :=x;
116
 
 m_y :=y;
117
 
 m_r1:=r1;
118
 
 m_r2:=r2;
119
 
 
120
 
 m_step       :=step;
121
 
 m_start_angle:=start_angle;
122
 
 m_angle      :=start_angle;
123
 
 
124
 
 m_da:=deg2rad(4.0 );
125
 
 m_dr:=m_step / 90.0;
126
 
 
127
 
end;
128
 
 
129
 
{ REWIND }
130
 
procedure spiral.rewind;
131
 
begin
132
 
 m_angle :=m_start_angle;
133
 
 m_curr_r:=m_r1;
134
 
 m_start :=true;
135
 
 
136
 
end;
137
 
 
138
 
{ VERTEX }
139
 
function spiral.vertex;
140
 
begin
141
 
 if m_curr_r > m_r2 then
142
 
  begin
143
 
   result:=path_cmd_stop;
144
 
 
145
 
   exit;
146
 
 
147
 
  end;
148
 
 
149
 
 x^:=m_x + Cos(m_angle ) * m_curr_r;
150
 
 y^:=m_y + Sin(m_angle ) * m_curr_r;
151
 
 
152
 
 m_curr_r:=m_curr_r + m_dr;
153
 
 m_angle :=m_angle + m_da;
154
 
 
155
 
 if m_start then
156
 
  begin
157
 
   m_start:=false;
158
 
 
159
 
   result:=path_cmd_move_to;
160
 
 
161
 
  end
162
 
 else
163
 
  result:=path_cmd_line_to;
164
 
 
165
 
end;
166
 
 
167
 
{ CONSTRUCT }
168
 
constructor the_application.Construct;
169
 
begin
170
 
 inherited Construct(format_ ,flip_y_ );
171
 
 
172
 
 m_polygons.Construct (5.0   ,5.0 ,5.0 + 205.0  ,110.0 ,not flip_y_ );
173
 
 m_operation.Construct(555.0 ,5.0 ,555.0 + 80.0 ,55.0  ,not flip_y_ );
174
 
 
175
 
 m_alpha_buf :=NIL;
176
 
 m_alpha_aloc:=0;
177
 
 
178
 
 m_alpha_mask_rbuf.Construct;
179
 
 m_alpha_mask.Construct(@m_alpha_mask_rbuf );
180
 
 
181
 
 m_ras.Construct;
182
 
 m_sl.Construct;
183
 
 
184
 
 m_x:=0;
185
 
 m_y:=0;
186
 
 
187
 
 m_operation.add_item ('AND' );
188
 
 m_operation.add_item ('SUB' );
189
 
 m_operation.cur_item_(0 );
190
 
 
191
 
 add_ctrl(@m_operation );
192
 
 
193
 
 m_operation.no_transform;
194
 
 
195
 
 m_polygons.add_item ('Two Simple Paths' );
196
 
 m_polygons.add_item ('Closed Stroke' );
197
 
 m_polygons.add_item ('Great Britain and Arrows' );
198
 
 m_polygons.add_item ('Great Britain and Spiral' );
199
 
 m_polygons.add_item ('Spiral and Glyph' );
200
 
 m_polygons.cur_item_(3 );
201
 
 
202
 
 add_ctrl(@m_polygons );
203
 
 
204
 
 m_polygons.no_transform;
205
 
 
206
 
end;
207
 
 
208
 
{ DESTRUCT }
209
 
destructor the_application.Destruct;
210
 
begin
211
 
 inherited Destruct;
212
 
 
213
 
 m_polygons.Destruct;
214
 
 m_operation.Destruct;
215
 
 
216
 
 m_alpha_mask_rbuf.Destruct;
217
 
 
218
 
 m_ras.Destruct;
219
 
 m_sl.Destruct;
220
 
 
221
 
 agg_freemem(pointer(m_alpha_buf ) ,m_alpha_aloc );
222
 
 
223
 
end;
224
 
 
225
 
{ DRAW_TEXT }
226
 
procedure the_application.draw_text;
227
 
var
228
 
 pf  : pixel_formats;
229
 
 rb  : renderer_base;
230
 
 ren : renderer_scanline_aa_solid;
231
 
 txt : gsv_text;
232
 
 
233
 
 txt_stroke : conv_stroke;
234
 
 
235
 
 rgba : aggclr;
236
 
 
237
 
begin
238
 
 pixfmt_bgr24(pf ,rbuf_window );
239
 
 
240
 
 rb.Construct (@pf );
241
 
 ren.Construct(@rb );
242
 
 
243
 
 txt.Construct;
244
 
 
245
 
 txt_stroke.Construct(@txt );
246
 
 txt_stroke.width_   (1.5 );
247
 
 txt_stroke.line_cap_(round_cap );
248
 
 
249
 
 txt.size_       (10.0 );
250
 
 txt.start_point_(x ,y );
251
 
 txt.text_       (PChar(str ) );
252
 
 
253
 
 m_ras.add_path  (@txt_stroke);
254
 
 rgba.ConstrDbl  (0.0 ,0.0 ,0.0 );
255
 
 ren.color_      (@rgba );
256
 
 render_scanlines(@m_ras ,@m_sl ,@ren );
257
 
 
258
 
 txt.Destruct;
259
 
 txt_stroke.Destruct;
260
 
 
261
 
end;
262
 
 
263
 
{ GENERATE_ALPHA_MASK }
264
 
procedure the_application.generate_alpha_mask;
265
 
var
266
 
 cx ,cy : unsigned;
267
 
 
268
 
 pixf : pixel_formats;
269
 
 gray : aggclr;
270
 
 
271
 
 rb  : renderer_base;
272
 
 ren : renderer_scanline_aa_solid;
273
 
 
274
 
 t1  : double;
275
 
 buf : array[0..99 ] of char;
276
 
 
277
 
begin
278
 
 cx:=trunc(_width );
279
 
 cy:=trunc(_height );
280
 
 
281
 
 agg_freemem(pointer(m_alpha_buf ) ,m_alpha_aloc );
282
 
 
283
 
 m_alpha_aloc:=cx * cy;
284
 
 
285
 
 agg_getmem(pointer(m_alpha_buf ) ,m_alpha_aloc );
286
 
 
287
 
 m_alpha_mask_rbuf.attach(m_alpha_buf ,cx ,cy ,cx );
288
 
 
289
 
 pixfmt_gray8(pixf ,@m_alpha_mask_rbuf );
290
 
 
291
 
 rb.Construct (@pixf );
292
 
 ren.Construct(@rb );
293
 
 
294
 
 start_timer;
295
 
 
296
 
 if m_operation._cur_item = 0 then
297
 
  begin
298
 
   gray.ConstrInt(0 );
299
 
   rb.clear      (@gray );
300
 
 
301
 
   gray.ConstrInt(255 );
302
 
   ren.color_    (@gray );
303
 
 
304
 
  end
305
 
 else
306
 
  begin
307
 
   gray.ConstrInt(255 );
308
 
   rb.clear      (@gray );
309
 
 
310
 
   gray.ConstrInt(0 );
311
 
   ren.color_    (@gray );
312
 
 
313
 
  end;
314
 
 
315
 
 m_ras.add_path  (vs );
316
 
 render_scanlines(@m_ras ,@m_sl ,@ren );
317
 
 
318
 
 t1:=elapsed_time;
319
 
 
320
 
 sprintf  (@buf[0 ] ,'Generate AlphaMask: %.3fms' ,t1 );
321
 
 draw_text(250 ,20 ,@buf[0 ] );
322
 
 
323
 
end;
324
 
 
325
 
{ PERFORM_RENDERING }
326
 
procedure the_application.perform_rendering;
327
 
var
328
 
 pixf  : pixel_formats;
329
 
 pixfa : pixfmt_amask_adaptor;
330
 
 rbase : renderer_base;
331
 
 
332
 
 ren  : renderer_scanline_aa_solid;
333
 
 rgba : aggclr;
334
 
 
335
 
 t1  : double;
336
 
 buf : array[0..99 ] of char;
337
 
 
338
 
begin
339
 
 pixfmt_bgr24(pixf ,rbuf_window );
340
 
 
341
 
 pixfa.Construct(@pixf ,@m_alpha_mask );
342
 
 rbase.Construct(@pixfa );
343
 
 ren.Construct  (@rbase );
344
 
 
345
 
 rgba.ConstrDbl(0.5 ,0.0 ,0 ,0.5 );
346
 
 ren.color_    (@rgba );
347
 
 
348
 
 start_timer;
349
 
 m_ras.reset;
350
 
 m_ras.add_path  (vs );
351
 
 render_scanlines(@m_ras ,@m_sl ,@ren );
352
 
 
353
 
 t1:=elapsed_time;
354
 
 
355
 
 sprintf  (@buf[0 ] ,'Render with AlphaMask: %.3fms' ,t1 );
356
 
 draw_text(250 ,5 ,@buf[0 ] );
357
 
 
358
 
 pixfa.Destruct;
359
 
 
360
 
end;
361
 
 
362
 
{ RENDER }
363
 
function the_application.render;
364
 
var
365
 
 pf : pixel_formats;
366
 
 rb : renderer_base;
367
 
 
368
 
 ren : renderer_scanline_aa_solid;
369
 
 ps1 ,
370
 
 ps2 ,
371
 
 
372
 
 gb_poly ,
373
 
 arrows  ,
374
 
 glyph   : path_storage;
375
 
 
376
 
 rgba : aggclr;
377
 
 x ,y : double;
378
 
 
379
 
 mtx1 ,
380
 
 mtx2 ,
381
 
 mtx  : trans_affine;
382
 
 tat  : trans_affine_translation;
383
 
 tas  : trans_affine_scaling;
384
 
 
385
 
 stroke         ,
386
 
 stroke_gb_poly : conv_stroke;
387
 
 
388
 
 trans         ,
389
 
 trans_gb_poly ,
390
 
 trans_arrows  : conv_transform;
391
 
 
392
 
 curve : conv_curve;
393
 
 
394
 
 sp : spiral;
395
 
 
396
 
begin
397
 
 pixfmt_bgr24(pf ,rbuf_window );
398
 
 
399
 
 rb.Construct (@pf );
400
 
 ren.Construct(@rb );
401
 
 
402
 
 case m_polygons._cur_item of
403
 
  0 : // Two simple paths
404
 
   begin
405
 
    ps1.Construct;
406
 
    ps2.Construct;
407
 
 
408
 
    x:=m_x - _initial_width / 2 + 100;
409
 
    y:=m_y - _initial_height / 2 + 100;
410
 
 
411
 
    ps1.move_to(x + 140 ,y + 145 );
412
 
    ps1.line_to(x + 225 ,y + 44 );
413
 
    ps1.line_to(x + 296 ,y + 219 );
414
 
    ps1.close_polygon;
415
 
 
416
 
    ps1.line_to(x + 226 ,y + 289 );
417
 
    ps1.line_to(x + 82  ,y + 292 );
418
 
 
419
 
    ps1.move_to(x + 220 ,y + 222 );
420
 
    ps1.line_to(x + 363 ,y + 249 );
421
 
    ps1.line_to(x + 265 ,y + 331 );
422
 
 
423
 
    ps1.move_to(x + 242 ,y + 243 );
424
 
    ps1.line_to(x + 268 ,y + 309 );
425
 
    ps1.line_to(x + 325 ,y + 261 );
426
 
 
427
 
    ps1.move_to(x + 259 ,y + 259 );
428
 
    ps1.line_to(x + 273 ,y + 288 );
429
 
    ps1.line_to(x + 298 ,y + 266 );
430
 
 
431
 
    ps2.move_to(100 + 32  ,100 + 77 );
432
 
    ps2.line_to(100 + 473 ,100 + 263 );
433
 
    ps2.line_to(100 + 351 ,100 + 290 );
434
 
    ps2.line_to(100 + 354 ,100 + 374 );
435
 
 
436
 
    m_ras.reset;
437
 
    m_ras.add_path  (@ps1 );
438
 
    rgba.ConstrDbl  (0 ,0 ,0 ,0.1 );
439
 
    ren.color_      (@rgba );
440
 
    render_scanlines(@m_ras ,@m_sl ,@ren );
441
 
 
442
 
    m_ras.reset;
443
 
    m_ras.add_path  (@ps2 );
444
 
    rgba.ConstrDbl  (0 ,0.6 ,0 ,0.1 );
445
 
    ren.color_      (@rgba );
446
 
    render_scanlines(@m_ras ,@m_sl ,@ren );
447
 
 
448
 
    generate_alpha_mask(@ps1 );
449
 
    perform_rendering  (@ps2 );
450
 
 
451
 
    ps1.Destruct;
452
 
    ps2.Destruct;
453
 
 
454
 
   end;
455
 
 
456
 
  1 : // Closed stroke
457
 
   begin
458
 
    ps1.Construct;
459
 
    ps2.Construct;
460
 
    stroke.Construct(@ps2 );
461
 
    stroke.width_   (10.0 );
462
 
 
463
 
    x:=m_x - _initial_width / 2 + 100;
464
 
    y:=m_y - _initial_height / 2 + 100;
465
 
 
466
 
    ps1.move_to(x + 140 ,y + 145 );
467
 
    ps1.line_to(x + 225 ,y + 44 );
468
 
    ps1.line_to(x + 296 ,y + 219 );
469
 
    ps1.close_polygon;
470
 
 
471
 
    ps1.line_to(x + 226 ,y + 289 );
472
 
    ps1.line_to(x + 82  ,y + 292 );
473
 
 
474
 
    ps1.move_to(x + 220 - 50 ,y + 222 );
475
 
    ps1.line_to(x + 265 - 50 ,y + 331 );
476
 
    ps1.line_to(x + 363 - 50 ,y + 249 );
477
 
    ps1.close_polygon(path_flags_ccw );
478
 
 
479
 
    ps2.move_to(100 + 32  ,100 + 77  );
480
 
    ps2.line_to(100 + 473 ,100 + 263 );
481
 
    ps2.line_to(100 + 351 ,100 + 290 );
482
 
    ps2.line_to(100 + 354 ,100 + 374 );
483
 
    ps2.close_polygon;
484
 
 
485
 
    m_ras.reset;
486
 
    m_ras.add_path  (@ps1 );
487
 
    rgba.ConstrDbl  (0 ,0 ,0 ,0.1 );
488
 
    ren.color_      (@rgba );
489
 
    render_scanlines(@m_ras ,@m_sl ,@ren );
490
 
 
491
 
    m_ras.reset;
492
 
    m_ras.add_path  (@stroke );
493
 
    rgba.ConstrDbl  (0 ,0.6 ,0 ,0.1 );
494
 
    ren.color_      (@rgba );
495
 
    render_scanlines(@m_ras ,@m_sl ,@ren );
496
 
 
497
 
    generate_alpha_mask(@ps1 );
498
 
    perform_rendering  (@stroke );
499
 
 
500
 
    ps1.Destruct;
501
 
    ps2.Destruct;
502
 
    stroke.Destruct;
503
 
 
504
 
   end;
505
 
 
506
 
  2 : // Great Britain and Arrows
507
 
   begin
508
 
    gb_poly.Construct;
509
 
    arrows.Construct;
510
 
 
511
 
    make_gb_poly(@gb_poly );
512
 
    make_arrows (@arrows );
513
 
 
514
 
    mtx1.Construct;
515
 
    mtx2.Construct;
516
 
    tat.Construct(-1150 ,-1150 );
517
 
    tas.Construct(2.0 );
518
 
    mtx1.multiply(@tat );
519
 
    mtx1.multiply(@tas );
520
 
 
521
 
    mtx2:=mtx1;
522
 
 
523
 
    tat.Construct(m_x - _initial_width / 2 ,m_y - _initial_height / 2 );
524
 
 
525
 
    mtx2.multiply(@tat );
526
 
 
527
 
    trans_gb_poly.Construct(@gb_poly ,@mtx1 );
528
 
    trans_arrows.Construct (@arrows  ,@mtx2 );
529
 
 
530
 
    m_ras.add_path  (@trans_gb_poly );
531
 
    rgba.ConstrDbl  (0.5 ,0.5 ,0 ,0.1 );
532
 
    ren.color_      (@rgba );
533
 
    render_scanlines(@m_ras ,@m_sl ,@ren );
534
 
 
535
 
    stroke_gb_poly.Construct(@trans_gb_poly );
536
 
    stroke_gb_poly.width_   (0.1);
537
 
    m_ras.add_path          (@stroke_gb_poly );
538
 
    rgba.ConstrDbl          (0 ,0 ,0 );
539
 
    ren.color_              (@rgba );
540
 
    render_scanlines        (@m_ras ,@m_sl ,@ren );
541
 
 
542
 
    m_ras.add_path  (@trans_arrows );
543
 
    rgba.ConstrDbl  (0.0 ,0.5 ,0.5 ,0.1 );
544
 
    ren.color_      (@rgba );
545
 
    render_scanlines(@m_ras ,@m_sl ,@ren );
546
 
 
547
 
    generate_alpha_mask(@trans_gb_poly );
548
 
    perform_rendering  (@trans_arrows );
549
 
 
550
 
    gb_poly.Destruct;
551
 
    arrows.Destruct;
552
 
    stroke_gb_poly.Destruct;
553
 
 
554
 
   end;
555
 
 
556
 
  3 : // Great Britain and a Spiral
557
 
   begin
558
 
    sp.Construct    (m_x ,m_y ,10 ,150 ,30 ,0.0 );
559
 
    stroke.Construct(@sp );
560
 
    stroke.width_   (15.0 );
561
 
 
562
 
    gb_poly.Construct;
563
 
    make_gb_poly(@gb_poly );
564
 
 
565
 
    mtx.Construct;
566
 
    tat.Construct(-1150 ,-1150 );
567
 
    tas.Construct(2.0 );
568
 
    mtx.multiply(@tat );
569
 
    mtx.multiply(@tas );
570
 
 
571
 
    trans_gb_poly.Construct(@gb_poly ,@mtx );
572
 
 
573
 
    m_ras.add_path  (@trans_gb_poly );
574
 
    rgba.ConstrDbl  (0.5 ,0.5 ,0 ,0.1 );
575
 
    ren.color_      (@rgba );
576
 
    render_scanlines(@m_ras ,@m_sl ,@ren );
577
 
 
578
 
    stroke_gb_poly.Construct(@trans_gb_poly );
579
 
    stroke_gb_poly.width_   (0.1 );
580
 
    m_ras.add_path          (@stroke_gb_poly );
581
 
    rgba.ConstrDbl          (0 ,0 ,0 );
582
 
    ren.color_              (@rgba );
583
 
    render_scanlines        (@m_ras ,@m_sl ,@ren );
584
 
 
585
 
    m_ras.add_path  (@stroke );
586
 
    rgba.ConstrDbl  (0.0 ,0.5 ,0.5 ,0.1 );
587
 
    ren.color_      (@rgba );
588
 
    render_scanlines(@m_ras ,@m_sl ,@ren );
589
 
 
590
 
    generate_alpha_mask(@trans_gb_poly );
591
 
    perform_rendering  (@stroke );
592
 
 
593
 
    stroke.Destruct;
594
 
    gb_poly.Destruct;
595
 
    stroke_gb_poly.Destruct;
596
 
 
597
 
   end;
598
 
 
599
 
  4 : // Spiral and glyph
600
 
   begin
601
 
    sp.Construct    (m_x ,m_y ,10 ,150 ,30 ,0.0 );
602
 
    stroke.Construct(@sp );
603
 
    stroke.width_   (15.0 );
604
 
 
605
 
    glyph.Construct;
606
 
    glyph.move_to(28.47 ,6.45 );
607
 
    glyph.curve3 (21.58 ,1.12  ,19.82 ,0.29 );
608
 
    glyph.curve3 (17.19 ,-0.93 ,14.21 ,-0.93 );
609
 
    glyph.curve3 (9.57  ,-0.93 ,6.57  ,2.25 );
610
 
    glyph.curve3 (3.56  ,5.42  ,3.56  ,10.60 );
611
 
    glyph.curve3 (3.56  ,13.87 ,5.03  ,16.26 );
612
 
    glyph.curve3 (7.03  ,19.58 ,11.99 ,22.51 );
613
 
    glyph.curve3 (16.94 ,25.44 ,28.47 ,29.64 );
614
 
    glyph.line_to(28.47 ,31.40 );
615
 
    glyph.curve3 (28.47 ,38.09 ,26.34 ,40.58 );
616
 
    glyph.curve3 (24.22 ,43.07 ,20.17 ,43.07 );
617
 
    glyph.curve3 (17.09 ,43.07 ,15.28 ,41.41 );
618
 
    glyph.curve3 (13.43 ,39.75 ,13.43 ,37.60 );
619
 
    glyph.line_to(13.53 ,34.77 );
620
 
    glyph.curve3 (13.53 ,32.52 ,12.38 ,31.30 );
621
 
    glyph.curve3 (11.23 ,30.08 ,9.38  ,30.08 );
622
 
    glyph.curve3 (7.57  ,30.08 ,6.42  ,31.35 );
623
 
    glyph.curve3 (5.27  ,32.62 ,5.27  ,34.81 );
624
 
    glyph.curve3 (5.27  ,39.01 ,9.57  ,42.53 );
625
 
    glyph.curve3 (13.87 ,46.04 ,21.63 ,46.04 );
626
 
    glyph.curve3 (27.59 ,46.04 ,31.40 ,44.04 );
627
 
    glyph.curve3 (34.28 ,42.53 ,35.64 ,39.31 );
628
 
    glyph.curve3 (36.52 ,37.21 ,36.52 ,30.71 );
629
 
    glyph.line_to(36.52 ,15.53 );
630
 
    glyph.curve3 (36.52 ,9.13  ,36.77 ,7.69 );
631
 
    glyph.curve3 (37.01 ,6.25  ,37.57 ,5.76 );
632
 
    glyph.curve3 (38.13 ,5.27  ,38.87 ,5.27 );
633
 
    glyph.curve3 (39.65 ,5.27  ,40.23 ,5.62 );
634
 
    glyph.curve3 (41.26 ,6.25  ,44.19 ,9.18 );
635
 
    glyph.line_to(44.19 ,6.45 );
636
 
    glyph.curve3 (38.72 ,-0.88 ,33.74 ,-0.88 );
637
 
    glyph.curve3 (31.35 ,-0.88 ,29.93 ,0.78 );
638
 
    glyph.curve3 (28.52 ,2.44  ,28.47 ,6.45 );
639
 
    glyph.close_polygon;
640
 
 
641
 
    glyph.move_to(28.47 ,9.62 );
642
 
    glyph.line_to(28.47 ,26.66 );
643
 
    glyph.curve3 (21.09 ,23.73 ,18.95 ,22.51 );
644
 
    glyph.curve3 (15.09 ,20.36 ,13.43 ,18.02 );
645
 
    glyph.curve3 (11.77 ,15.67 ,11.77 ,12.89 );
646
 
    glyph.curve3 (11.77 ,9.38  ,13.87 ,7.06 );
647
 
    glyph.curve3 (15.97 ,4.74  ,18.70 ,4.74 );
648
 
    glyph.curve3 (22.41 ,4.74  ,28.47 ,9.62 );
649
 
    glyph.close_polygon;
650
 
 
651
 
    mtx.Construct;
652
 
    tas.Construct(4.0 );
653
 
    tat.Construct(220 ,200 );
654
 
    mtx.multiply(@tas );
655
 
    mtx.multiply(@tat );
656
 
 
657
 
    trans.Construct(@glyph ,@mtx );
658
 
    curve.Construct(@trans );
659
 
 
660
 
    m_ras.reset;
661
 
    m_ras.add_path  (@stroke );
662
 
    rgba.ConstrDbl  (0 ,0 ,0 ,0.1 );
663
 
    ren.color_      (@rgba );
664
 
    render_scanlines(@m_ras ,@m_sl ,@ren );
665
 
 
666
 
    m_ras.reset;
667
 
    m_ras.add_path  (@curve );
668
 
    rgba.ConstrDbl  (0 ,0.6 ,0 ,0.1 );
669
 
    ren.color_      (@rgba );
670
 
    render_scanlines(@m_ras ,@m_sl ,@ren );
671
 
 
672
 
    generate_alpha_mask(@stroke );
673
 
    perform_rendering  (@curve );
674
 
 
675
 
    stroke.Destruct;
676
 
    glyph.Destruct;
677
 
    curve.Destruct;
678
 
 
679
 
   end;
680
 
 
681
 
 end;
682
 
 
683
 
end;
684
 
 
685
 
{ ON_INIT }
686
 
procedure the_application.on_init;
687
 
begin
688
 
 m_x:=_width / 2.0;
689
 
 m_y:=_height / 2.0;
690
 
 
691
 
end;
692
 
 
693
 
{ ON_DRAW }
694
 
procedure the_application.on_draw;
695
 
var
696
 
 pf : pixel_formats;
697
 
 
698
 
 rgba : aggclr;
699
 
 
700
 
 ren_base  : renderer_base;
701
 
 ren_solid : renderer_scanline_aa_solid;
702
 
 
703
 
begin
704
 
// Initialize structures
705
 
 pixfmt_bgr24(pf ,rbuf_window );
706
 
 
707
 
 ren_base.Construct (@pf );
708
 
 ren_solid.Construct(@ren_base );
709
 
 
710
 
 rgba.ConstrDbl(1 ,1 ,1 );
711
 
 ren_base.clear(@rgba );
712
 
 
713
 
// Render
714
 
 render;
715
 
 
716
 
// Render the controls
717
 
 render_ctrl(@m_ras ,@m_sl ,@ren_solid ,@m_polygons );
718
 
 render_ctrl(@m_ras ,@m_sl ,@ren_solid ,@m_operation );
719
 
 
720
 
end;
721
 
 
722
 
{ ON_MOUSE_MOVE }
723
 
procedure the_application.on_mouse_move;
724
 
begin
725
 
 if flags and mouse_left <> 0 then
726
 
  begin
727
 
   m_x:=x;
728
 
   m_y:=y;
729
 
 
730
 
   force_redraw;
731
 
 
732
 
  end;
733
 
 
734
 
end;
735
 
 
736
 
{ ON_MOUSE_BUTTON_DOWN }
737
 
procedure the_application.on_mouse_button_down;
738
 
var
739
 
 buf : array[0..99 ] of char;
740
 
 
741
 
begin
742
 
 if flags and mouse_left <> 0 then
743
 
  begin
744
 
   m_x:=x;
745
 
   m_y:=y;
746
 
 
747
 
   force_redraw;
748
 
 
749
 
  end;
750
 
 
751
 
 if flags and mouse_right <> 0 then
752
 
  begin
753
 
   sprintf (@buf[0 ]             ,'%d ' ,x );
754
 
   sprintf (@buf[StrLen(@buf ) ] ,'%d'  ,y );
755
 
   message_(@buf[0 ] );
756
 
 
757
 
  end;
758
 
 
759
 
end;
760
 
 
761
 
{ ON_KEY }
762
 
procedure the_application.on_key;
763
 
begin
764
 
 if key = key_f1 then
765
 
  message_(
766
 
   'Yet another example of alpha-masking. It simulates arbitrary polygon clipping '#13 +
767
 
   'similar to "gpc_test". Alpha-Masking allows you to perform only the Intersection '#13 +
768
 
   '(AND) and Difference (SUB) operations, but works much faster that conv_gpc. '#13 +
769
 
   'Actually, there''re different complexities and different dependencies. '#13 +
770
 
   'The performance of conv_gpc depends on the number of vertices, while'#13 +
771
 
   'Alpha-Masking depends on the area of the rendered polygons. Still, with typical '#13 +
772
 
   'screen resolutions, Alpha-Masking works much faster than General Polygon Clipper. '#13 +
773
 
   'Compare the timings between "alpha_mask3" and "gpc_test"".'#13#13 +
774
 
   'How to play with:'#13#13 +
775
 
   'Use the left mouse button to move the upper shape around.'#13 +
776
 
   'Use the right mouse button to display a message with current coordinates.' +
777
 
   #13#13'Note: F2 key saves current "screenshot" file in this demo''s directory.  ' );
778
 
 
779
 
end;
780
 
 
781
 
VAR
782
 
 app : the_application;
783
 
 
784
 
BEGIN
785
 
 app.Construct(pix_format_bgr24 ,flip_y );
786
 
 app.caption_ ('AGG Example. Alpha-Mask as a Polygon Clipper (F1-Help)' );
787
 
 
788
 
 if app.init(640 ,520 ,window_resize ) then
789
 
  app.run;
790
 
 
791
 
 app.Destruct;
792
 
 
793
 
END.
 
 
b'\\ No newline at end of file'