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

« back to all changes in this revision

Viewing changes to components/aggpas/scanline_boolean2.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
 
 scanline_boolean2 ;
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
 
 
20
 
 agg_ctrl ,
21
 
 agg_slider_ctrl ,
22
 
 agg_cbox_ctrl ,
23
 
 agg_rbox_ctrl ,
24
 
 
25
 
 agg_rendering_buffer ,
26
 
 agg_renderer_base ,
27
 
 agg_renderer_scanline ,
28
 
 agg_renderer_primitives ,
29
 
 agg_rasterizer_scanline_aa ,
30
 
 agg_scanline ,
31
 
 agg_scanline_u ,
32
 
 agg_scanline_p ,
33
 
 agg_scanline_bin ,
34
 
 agg_scanline_storage_aa ,
35
 
 agg_scanline_storage_bin ,
36
 
 agg_scanline_boolean_algebra ,
37
 
 agg_render_scanlines ,
38
 
 
39
 
 agg_math_stroke ,
40
 
 agg_path_storage ,
41
 
 agg_span_solid ,
42
 
 agg_conv_curve ,
43
 
 agg_conv_stroke ,
44
 
 agg_conv_transform ,
45
 
 agg_gsv_text ,
46
 
 agg_trans_affine ,
47
 
 agg_vertex_source ,
48
 
 
49
 
 make_gb_poly_ ,
50
 
 make_arrows_ ;
51
 
 
52
 
{$I agg_mode.inc }
53
 
 
54
 
const
55
 
 flip_y = true;
56
 
 
57
 
type
58
 
 spiral = object(vertex_source )
59
 
   m_x    ,
60
 
   m_y    ,
61
 
   m_r1   ,
62
 
   m_r2   ,
63
 
   m_step ,
64
 
 
65
 
   m_start_angle ,
66
 
 
67
 
   m_angle  ,
68
 
   m_curr_r ,
69
 
   m_da     ,
70
 
   m_dr     : double;
71
 
   m_start  : boolean;
72
 
 
73
 
   constructor Construct(x ,y ,r1 ,r2 ,step : double; start_angle : double = 0 );
74
 
 
75
 
   procedure rewind(path_id : unsigned ); virtual;
76
 
   function  vertex(x ,y : double_ptr ) : unsigned; virtual;
77
 
 
78
 
  end;
79
 
 
80
 
 the_application = object(platform_support )
81
 
   m_polygons      ,
82
 
   m_fill_rule     ,
83
 
   m_scanline_type ,
84
 
   m_operation     : rbox_ctrl;
85
 
 
86
 
   m_x ,
87
 
   m_y : double;
88
 
 
89
 
   constructor Construct(format_ : pix_format_e; flip_y_ : boolean );
90
 
   destructor  Destruct;
91
 
 
92
 
   procedure render_scanline_boolean(ras1 ,ras2 : rasterizer_scanline_ptr );
93
 
   function  render_sbool           (ras1 ,ras2 : rasterizer_scanline_ptr ) : unsigned;
94
 
 
95
 
   procedure on_init; virtual;
96
 
   procedure on_draw; virtual;
97
 
 
98
 
   procedure on_mouse_move       (x ,y : int; flags : unsigned ); virtual;
99
 
   procedure on_mouse_button_down(x ,y : int; flags : unsigned ); virtual;
100
 
 
101
 
   procedure on_key(x ,y : int; key ,flags : unsigned ); virtual;
102
 
 
103
 
  end;
104
 
 
105
 
{ CONSTRUCT }
106
 
constructor spiral.Construct;
107
 
begin
108
 
 m_x :=x;
109
 
 m_y :=y;
110
 
 m_r1:=r1;
111
 
 m_r2:=r2;
112
 
 
113
 
 m_step       :=step;
114
 
 m_start_angle:=start_angle;
115
 
 m_angle      :=start_angle;
116
 
 
117
 
 m_da:=deg2rad(4.0 );
118
 
 m_dr:=m_step / 90.0;
119
 
 
120
 
end;
121
 
 
122
 
{ REWIND }
123
 
procedure spiral.rewind;
124
 
begin
125
 
 m_angle :=m_start_angle;
126
 
 m_curr_r:=m_r1;
127
 
 m_start :=true;
128
 
 
129
 
end;
130
 
 
131
 
{ VERTEX }
132
 
function spiral.vertex;
133
 
begin
134
 
 if m_curr_r > m_r2 then
135
 
  begin
136
 
   result:=path_cmd_stop;
137
 
 
138
 
   exit;
139
 
 
140
 
  end;
141
 
 
142
 
 x^:=m_x + Cos(m_angle ) * m_curr_r;
143
 
 y^:=m_y + Sin(m_angle ) * m_curr_r;
144
 
 
145
 
 m_curr_r:=m_curr_r + m_dr;
146
 
 m_angle :=m_angle + m_da;
147
 
 
148
 
 if m_start then
149
 
  begin
150
 
   m_start:=false;
151
 
 
152
 
   result:=path_cmd_move_to;
153
 
 
154
 
  end
155
 
 else
156
 
  result:=path_cmd_line_to;
157
 
 
158
 
end;
159
 
 
160
 
{ COUNT_SPANS }
161
 
function count_spans(ras : rasterizer_scanline_ptr; sl : scanline_ptr ) : unsigned;
162
 
var
163
 
 n : unsigned;
164
 
 
165
 
begin
166
 
 n:=0;
167
 
 
168
 
 if ras.rewind_scanlines then
169
 
  begin
170
 
   sl.reset(ras._min_x ,ras._max_x );
171
 
 
172
 
   if sl.is_embedded then
173
 
    while ras.sweep_scanline_em(sl ) do
174
 
     inc(n ,sl.num_spans )
175
 
   else
176
 
    while ras.sweep_scanline(sl ) do
177
 
     inc(n ,sl.num_spans );
178
 
 
179
 
  end;
180
 
 
181
 
 result:=n;
182
 
 
183
 
end;
184
 
 
185
 
{ CONSTRUCT }
186
 
constructor the_application.Construct;
187
 
begin
188
 
 inherited Construct(format_ ,flip_y_ );
189
 
 
190
 
 m_polygons.Construct     (5.0   ,5.0 ,5.0 + 205.0   ,110.0 ,not flip_y_ );
191
 
 m_fill_rule.Construct    (200   ,5.0 ,200 + 105.0   ,50.0  ,not flip_y_ );
192
 
 m_scanline_type.Construct(300   ,5.0 ,300 + 115.0   ,70.0  ,not flip_y_ );
193
 
 m_operation.Construct    (535.0 ,5.0 ,535.0 + 115.0 ,145.0 ,not flip_y_ );
194
 
 
195
 
 m_operation.add_item ('None' );
196
 
 m_operation.add_item ('OR' );
197
 
 m_operation.add_item ('AND' );
198
 
 m_operation.add_item ('XOR Linear' );
199
 
 m_operation.add_item ('XOR Saddle' );
200
 
 m_operation.add_item ('A-B' );
201
 
 m_operation.add_item ('B-A' );
202
 
 m_operation.cur_item_(2 );
203
 
 
204
 
 add_ctrl(@m_operation );
205
 
 
206
 
 m_operation.no_transform;
207
 
 
208
 
 m_fill_rule.add_item ('Even-Odd' );
209
 
 m_fill_rule.add_item ('Non Zero' );
210
 
 m_fill_rule.cur_item_(1 );
211
 
 
212
 
 add_ctrl(@m_fill_rule );
213
 
 
214
 
 m_fill_rule.no_transform;
215
 
 
216
 
 m_scanline_type.add_item ('scanline_p' );
217
 
 m_scanline_type.add_item ('scanline_u' );
218
 
 m_scanline_type.add_item ('scanline_bin' );
219
 
 m_scanline_type.cur_item_(1 );
220
 
 
221
 
 add_ctrl(@m_scanline_type );
222
 
 
223
 
 m_scanline_type.no_transform;
224
 
 
225
 
 m_polygons.add_item ('Two Simple Paths' );
226
 
 m_polygons.add_item ('Closed Stroke' );
227
 
 m_polygons.add_item ('Great Britain and Arrows' );
228
 
 m_polygons.add_item ('Great Britain and Spiral' );
229
 
 m_polygons.add_item ('Spiral and Glyph' );
230
 
 m_polygons.cur_item_(3 );
231
 
 
232
 
 add_ctrl(@m_polygons );
233
 
 
234
 
 m_polygons.no_transform;
235
 
 
236
 
end;
237
 
 
238
 
{ DESTRUCT }
239
 
destructor the_application.Destruct;
240
 
begin
241
 
 inherited Destruct;
242
 
 
243
 
 m_polygons.Destruct;
244
 
 m_fill_rule.Destruct;
245
 
 m_scanline_type.Destruct;
246
 
 m_operation.Destruct;
247
 
 
248
 
end;
249
 
 
250
 
{ RENDER_SCANLINE_BOOLEAN }
251
 
procedure the_application.render_scanline_boolean;
252
 
var
253
 
 op : sbool_op_e;
254
 
 rb : renderer_base;
255
 
 
256
 
 buf : array[0..99 ] of char;
257
 
 
258
 
 pixf : pixel_formats;
259
 
 rgba : aggclr;
260
 
 
261
 
 t1 ,t2 : double;
262
 
 
263
 
 i : int;
264
 
 
265
 
 num_spans : unsigned;
266
 
 
267
 
 renp ,
268
 
 renu ,
269
 
 rent : renderer_scanline_aa_solid;
270
 
 renb : renderer_scanline_bin_solid;
271
 
 
272
 
 slt  ,
273
 
 slp  ,
274
 
 slp1 ,
275
 
 slp2 : scanline_p8;
276
 
 slu  ,
277
 
 slu1 ,
278
 
 slu2 : scanline_u8;
279
 
 slb  ,
280
 
 slb1 ,
281
 
 slb2 : scanline_bin;
282
 
 txt  : gsv_text;
283
 
 
284
 
 txt_stroke : conv_stroke;
285
 
 
286
 
 storage  ,
287
 
 storage1 ,
288
 
 storage2 : scanline_storage_aa8;
289
 
 
290
 
 storageb  ,
291
 
 storageb1 ,
292
 
 storageb2 : scanline_storage_bin;
293
 
 
294
 
begin
295
 
 if m_operation._cur_item > 0 then
296
 
  begin
297
 
   case m_operation._cur_item of
298
 
    1 : op:=sbool_or;
299
 
    2 : op:=sbool_and;
300
 
    3 : op:=sbool_xor;
301
 
    4 : op:=sbool_xor_saddle;
302
 
    5 : op:=sbool_a_minus_b;
303
 
    6 : op:=sbool_b_minus_a;
304
 
 
305
 
   end;
306
 
 
307
 
   pixfmt_bgr24(pixf ,rbuf_window );
308
 
   rb.Construct(@pixf );
309
 
 
310
 
   t1:=0.0;
311
 
   t2:=0.0;
312
 
 
313
 
   num_spans:=0;
314
 
 
315
 
  // Render Clipping
316
 
   case m_scanline_type._cur_item of
317
 
    0 :
318
 
     begin
319
 
      renp.Construct(@rb );
320
 
      slp.Construct;
321
 
      slp1.Construct;
322
 
      slp2.Construct;
323
 
 
324
 
      // The intermediate storage is used only to test the perfoprmance,
325
 
      // the short variant can be as follows:
326
 
      // ------------------------
327
 
      // rgba.ConstrDbl         (0.5 ,0.0 ,0 ,0.5 );
328
 
      // renp.color             (@rgba );
329
 
      // sbool_combine_shapes_aa(op ,ras1 ,ras2 ,@slp1 ,@slp2 ,@slp ,@renp );
330
 
 
331
 
      storage.Construct;
332
 
      storage1.Construct;
333
 
      storage2.Construct;
334
 
 
335
 
      render_scanlines(ras1 ,@slp ,@storage1 );
336
 
      render_scanlines(ras2 ,@slp ,@storage2 );
337
 
 
338
 
      start_timer;
339
 
 
340
 
      for i:=0 to 9 do
341
 
       sbool_combine_shapes_aa(op ,@storage1 ,@storage2 ,@slp1 ,@slp2 ,@slp ,@storage );
342
 
 
343
 
      t1:=elapsed_time / 10.0;
344
 
 
345
 
      start_timer;
346
 
 
347
 
      rgba.ConstrDbl  (0.5 ,0.0 ,0 ,0.5 );
348
 
      renp.color_     (@rgba );
349
 
      render_scanlines(@storage ,@slp ,@renp );
350
 
 
351
 
      t2:=elapsed_time;
352
 
 
353
 
      num_spans:=count_spans(@storage ,@slp );
354
 
 
355
 
      slp.Destruct;
356
 
      slp1.Destruct;
357
 
      slp2.Destruct;
358
 
 
359
 
      storage.Destruct;
360
 
      storage1.Destruct;
361
 
      storage2.Destruct;
362
 
 
363
 
     end;
364
 
 
365
 
    1 :
366
 
     begin
367
 
      renu.Construct(@rb );
368
 
 
369
 
      slu.Construct;
370
 
      slu1.Construct;
371
 
      slu2.Construct;
372
 
 
373
 
      {rgba.ConstrDbl         (0.5 ,0.0 ,0 ,0.5 );
374
 
      renu.color             (@rgba );
375
 
      sbool_combine_shapes_aa(op ,ras1 ,ras2 ,@slu1 ,@slu2 ,@slu ,@renu );}
376
 
 
377
 
      storage.Construct;
378
 
      storage1.Construct;
379
 
      storage2.Construct;
380
 
 
381
 
      render_scanlines(ras1 ,@slu ,@storage1 );
382
 
      render_scanlines(ras2 ,@slu ,@storage2 );
383
 
 
384
 
      start_timer;
385
 
 
386
 
      for i:=0 to 9 do
387
 
       sbool_combine_shapes_aa(op ,@storage1 ,@storage2 ,@slu1 ,@slu2 ,@slu ,@storage );
388
 
 
389
 
      t1:=elapsed_time / 10.0;
390
 
 
391
 
      start_timer;
392
 
 
393
 
      rgba.ConstrDbl  (0.5 ,0.0 ,0 ,0.5 );
394
 
      renu.color_     (@rgba );
395
 
      render_scanlines(@storage ,@slu ,@renu );
396
 
 
397
 
      t2:=elapsed_time;
398
 
 
399
 
      num_spans:=count_spans(@storage ,@slu );{}
400
 
 
401
 
      slu.Destruct;
402
 
      slu1.Destruct;
403
 
      slu2.Destruct;
404
 
 
405
 
      storage.Destruct;
406
 
      storage1.Destruct;
407
 
      storage2.Destruct;{}
408
 
 
409
 
     end;
410
 
 
411
 
    2 :
412
 
     begin
413
 
      renb.Construct(@rb );
414
 
 
415
 
      slb.Construct;
416
 
      slb1.Construct;
417
 
      slb2.Construct;
418
 
 
419
 
      storageb.Construct;
420
 
      storageb1.Construct;
421
 
      storageb2.Construct;
422
 
 
423
 
      render_scanlines(ras1 ,@slb ,@storageb1 );
424
 
      render_scanlines(ras2 ,@slb ,@storageb2 );
425
 
 
426
 
      start_timer;
427
 
 
428
 
      for i:=0 to 9 do
429
 
       sbool_combine_shapes_bin(op ,@storageb1 ,@storageb2 ,@slb1 ,@slb2 ,@slb ,@storageb );
430
 
 
431
 
      t1:=elapsed_time / 10.0;
432
 
 
433
 
      start_timer;
434
 
 
435
 
      rgba.ConstrDbl  ({0.5}1 ,0.0 ,0 {,0.5} );
436
 
      renb.color_     (@rgba );
437
 
      render_scanlines(@storageb ,@slb ,@renb );
438
 
 
439
 
      t2:=elapsed_time;
440
 
 
441
 
      num_spans:=count_spans(@storageb ,@slb );
442
 
 
443
 
      slb.Destruct;
444
 
      slb1.Destruct;
445
 
      slb2.Destruct;
446
 
 
447
 
      storageb.Destruct;
448
 
      storageb1.Destruct;
449
 
      storageb2.Destruct;
450
 
 
451
 
     end;
452
 
 
453
 
   end;
454
 
 
455
 
  // Render text
456
 
   sprintf(@buf[0 ]             ,'Combine=%.3fms'#13#13 ,t1 );
457
 
   sprintf(@buf[StrLen(@buf ) ] ,'Render=%.3fms'#13#13 ,t2 );
458
 
   sprintf(@buf[StrLen(@buf ) ] ,'num_spans=%d' ,num_spans );
459
 
 
460
 
   rent.Construct(@rb );
461
 
   slt.Construct;
462
 
   txt.Construct;
463
 
   txt_stroke.Construct(@txt );
464
 
   txt_stroke.width_   (1.0 );
465
 
   txt_stroke.line_cap_(round_cap );
466
 
   txt.size_           (8.0 );
467
 
   txt.start_point_    (420 ,40 );
468
 
   txt.text_           (@buf[0 ] );
469
 
 
470
 
   ras1.reset;
471
 
   ras1.add_path   (@txt_stroke );
472
 
   rgba.ConstrDbl  (0.0 ,0.0 ,0.0 );
473
 
   rent.color_     (@rgba );
474
 
   render_scanlines(ras1 ,@slt ,@rent );
475
 
 
476
 
   slt.Destruct;
477
 
   txt.Destruct;
478
 
   txt_stroke.Destruct;
479
 
 
480
 
  end;
481
 
 
482
 
end;
483
 
 
484
 
{ RENDER_SBOOL }
485
 
function the_application.render_sbool;
486
 
var
487
 
 pf  : pixel_formats;
488
 
 rb  : renderer_base;
489
 
 ren : renderer_scanline_aa_solid;
490
 
 sl  : scanline_p8;
491
 
 
492
 
 ps1 ,
493
 
 ps2 ,
494
 
 
495
 
 gb_poly ,
496
 
 arrows  ,
497
 
 glyph   : path_storage;
498
 
 
499
 
 rgba : aggclr;
500
 
 x ,y : double;
501
 
 
502
 
 mtx1 ,
503
 
 mtx2 ,
504
 
 mtx  : trans_affine;
505
 
 tat  : trans_affine_translation;
506
 
 tas  : trans_affine_scaling;
507
 
 
508
 
 stroke         ,
509
 
 stroke_gb_poly : conv_stroke;
510
 
 
511
 
 trans         ,
512
 
 trans_gb_poly ,
513
 
 trans_arrows  : conv_transform;
514
 
 
515
 
 curve : conv_curve;
516
 
 
517
 
 sp  : spiral;
518
 
 
519
 
begin
520
 
 pixfmt_bgr24(pf ,rbuf_window );
521
 
 
522
 
 rb.Construct (@pf );
523
 
 ren.Construct(@rb );
524
 
 
525
 
 sl.Construct;
526
 
 
527
 
 if m_fill_rule._cur_item <> 0 then
528
 
  ras1.filling_rule(fill_non_zero )
529
 
 else
530
 
  ras1.filling_rule(fill_even_odd );
531
 
 
532
 
 if m_fill_rule._cur_item <> 0 then
533
 
  ras2.filling_rule(fill_non_zero )
534
 
 else
535
 
  ras2.filling_rule(fill_even_odd );
536
 
 
537
 
 case m_polygons._cur_item of
538
 
  0 : // Two simple paths
539
 
   begin
540
 
    ps1.Construct;
541
 
    ps2.Construct;
542
 
 
543
 
    x:=m_x - _initial_width / 2 + 100;
544
 
    y:=m_y - _initial_height / 2 + 100;
545
 
 
546
 
    ps1.move_to(x + 140 ,y + 145 );
547
 
    ps1.line_to(x + 225 ,y + 44 );
548
 
    ps1.line_to(x + 296 ,y + 219 );
549
 
    ps1.close_polygon;
550
 
 
551
 
    ps1.line_to(x + 226 ,y + 289 );
552
 
    ps1.line_to(x + 82  ,y + 292 );
553
 
 
554
 
    ps1.move_to(x + 220 ,y + 222 );
555
 
    ps1.line_to(x + 363 ,y + 249 );
556
 
    ps1.line_to(x + 265 ,y + 331 );
557
 
 
558
 
    ps1.move_to(x + 242 ,y + 243 );
559
 
    ps1.line_to(x + 268 ,y + 309 );
560
 
    ps1.line_to(x + 325 ,y + 261 );
561
 
 
562
 
    ps1.move_to(x + 259 ,y + 259 );
563
 
    ps1.line_to(x + 273 ,y + 288 );
564
 
    ps1.line_to(x + 298 ,y + 266 );
565
 
 
566
 
    ps2.move_to(100 + 32  ,100 + 77 );
567
 
    ps2.line_to(100 + 473 ,100 + 263 );
568
 
    ps2.line_to(100 + 351 ,100 + 290 );
569
 
    ps2.line_to(100 + 354 ,100 + 374 );
570
 
 
571
 
    ras1.reset;
572
 
    ras1.add_path   (@ps1 );
573
 
    rgba.ConstrDbl  (0 ,0 ,0 ,{0.1}0.0 );
574
 
    ren.color_      (@rgba );
575
 
   { render_scanlines(ras1 ,@sl ,@ren ); }
576
 
 
577
 
    ras2.reset;
578
 
    ras2.add_path   (@ps2 );
579
 
    rgba.ConstrDbl  (0 ,0.6 ,0 ,{0.1}0.0 );
580
 
    ren.color_      (@rgba );
581
 
   { render_scanlines(ras2 ,@sl ,@ren ); }
582
 
 
583
 
    render_scanline_boolean(ras1 ,ras2 );
584
 
 
585
 
    ps1.Destruct;
586
 
    ps2.Destruct;
587
 
 
588
 
   end;
589
 
 
590
 
  1 : // Closed stroke
591
 
   begin
592
 
    ps1.Construct;
593
 
    ps2.Construct;
594
 
    stroke.Construct(@ps2 );
595
 
    stroke.width_   (15.0 );
596
 
 
597
 
    x:=m_x - _initial_width / 2 + 100;
598
 
    y:=m_y - _initial_height / 2 + 100;
599
 
 
600
 
    ps1.move_to(x + 140 ,y + 145 );
601
 
    ps1.line_to(x + 225 ,y + 44 );
602
 
    ps1.line_to(x + 296 ,y + 219 );
603
 
    ps1.close_polygon;
604
 
 
605
 
    ps1.line_to(x + 226 ,y + 289 );
606
 
    ps1.line_to(x + 82  ,y + 292 );
607
 
 
608
 
    ps1.move_to(x + 220 - 50 ,y + 222 );
609
 
    ps1.line_to(x + 265 - 50 ,y + 331 );
610
 
    ps1.line_to(x + 363 - 50 ,y + 249 );
611
 
    ps1.close_polygon(path_flags_ccw );
612
 
 
613
 
    ps2.move_to(100 + 32  ,100 + 77  );
614
 
    ps2.line_to(100 + 473 ,100 + 263 );
615
 
    ps2.line_to(100 + 351 ,100 + 290 );
616
 
    ps2.line_to(100 + 354 ,100 + 374 );
617
 
    ps2.close_polygon;
618
 
 
619
 
    ras1.reset;
620
 
    ras1.add_path   (@ps1 );
621
 
    rgba.ConstrDbl  (0 ,0 ,0 ,0.1 );
622
 
    ren.color_      (@rgba );
623
 
    render_scanlines(ras1 ,@sl ,@ren );
624
 
 
625
 
    ras2.reset;
626
 
    ras2.add_path   (@stroke );
627
 
    rgba.ConstrDbl  (0 ,0.6 ,0 ,0.1 );
628
 
    ren.color_      (@rgba );
629
 
    render_scanlines(ras2 ,@sl ,@ren );
630
 
 
631
 
    render_scanline_boolean(ras1 ,ras2 );
632
 
 
633
 
    ps1.Destruct;
634
 
    ps2.Destruct;
635
 
    stroke.Destruct;
636
 
 
637
 
   end;
638
 
 
639
 
  2 : // Great Britain and Arrows
640
 
   begin
641
 
    gb_poly.Construct;
642
 
    arrows.Construct;
643
 
 
644
 
    make_gb_poly(@gb_poly );
645
 
    make_arrows (@arrows );
646
 
 
647
 
    mtx1.Construct;
648
 
    mtx2.Construct;
649
 
    tat.Construct(-1150 ,-1150 );
650
 
    tas.Construct(2.0 );
651
 
    mtx1.multiply(@tat );
652
 
    mtx1.multiply(@tas );
653
 
 
654
 
    mtx2:=mtx1;
655
 
 
656
 
    tat.Construct(m_x - _initial_width / 2 ,m_y - _initial_height / 2 );
657
 
 
658
 
    mtx2.multiply(@tat );
659
 
 
660
 
    trans_gb_poly.Construct(@gb_poly ,@mtx1 );
661
 
    trans_arrows.Construct (@arrows  ,@mtx2 );
662
 
 
663
 
    ras2.add_path   (@trans_gb_poly );
664
 
    rgba.ConstrDbl  (0.5 ,0.5 ,0 ,0.1 );
665
 
    ren.color_      (@rgba );
666
 
    render_scanlines(ras2 ,@sl ,@ren );
667
 
 
668
 
    stroke_gb_poly.Construct(@trans_gb_poly );
669
 
    stroke_gb_poly.width_   (0.1);
670
 
    ras1.add_path           (@stroke_gb_poly );
671
 
    rgba.ConstrDbl          (0 ,0 ,0 );
672
 
    ren.color_              (@rgba );
673
 
    render_scanlines        (ras1 ,@sl ,@ren );
674
 
 
675
 
    ras2.add_path   (@trans_arrows );
676
 
    rgba.ConstrDbl  (0.0 ,0.5 ,0.5 ,0.1 );
677
 
    ren.color_      (@rgba );
678
 
    render_scanlines(ras2 ,@sl ,@ren );
679
 
 
680
 
    ras1.reset;
681
 
    ras1.add_path(@trans_gb_poly );
682
 
 
683
 
    render_scanline_boolean(ras1 ,ras2 );
684
 
 
685
 
    gb_poly.Destruct;
686
 
    arrows.Destruct;
687
 
    stroke_gb_poly.Destruct;
688
 
 
689
 
   end;
690
 
 
691
 
  3 : // Great Britain and a Spiral
692
 
   begin
693
 
    sp.Construct    (m_x ,m_y ,10 ,150 ,30 ,0.0 );
694
 
    stroke.Construct(@sp );
695
 
    stroke.width_   (15.0 );
696
 
 
697
 
    gb_poly.Construct;
698
 
    make_gb_poly(@gb_poly );
699
 
 
700
 
    mtx.Construct;
701
 
    tat.Construct(-1150 ,-1150 );
702
 
    tas.Construct(2.0 );
703
 
    mtx.multiply(@tat );
704
 
    mtx.multiply(@tas );
705
 
    mtx.multiply(_trans_affine_resizing );
706
 
 
707
 
    trans_gb_poly.Construct(@gb_poly ,@mtx );
708
 
 
709
 
    ras1.add_path   (@trans_gb_poly );
710
 
    rgba.ConstrDbl  (0.5 ,0.5 ,0 ,0.1 );
711
 
    ren.color_      (@rgba );
712
 
    render_scanlines(ras1 ,@sl ,@ren );
713
 
 
714
 
    stroke_gb_poly.Construct(@trans_gb_poly );
715
 
    stroke_gb_poly.width_   (0.1 );
716
 
    ras1.add_path           (@stroke_gb_poly );
717
 
    rgba.ConstrDbl          (0 ,0 ,0 );
718
 
    ren.color_              (@rgba );
719
 
    render_scanlines        (ras1 ,@sl ,@ren );
720
 
 
721
 
    ras2.reset;
722
 
    ras2.add_path   (@stroke );
723
 
    rgba.ConstrDbl  (0.0 ,0.5 ,0.5 ,0.1 );
724
 
    ren.color_      (@rgba );
725
 
    render_scanlines(ras2 ,@sl ,@ren );
726
 
 
727
 
    ras1.reset;
728
 
    ras1.add_path(@trans_gb_poly );
729
 
 
730
 
    render_scanline_boolean(ras1 ,ras2 );
731
 
 
732
 
    stroke.Destruct;
733
 
    gb_poly.Destruct;
734
 
    stroke_gb_poly.Destruct;
735
 
 
736
 
   end;
737
 
 
738
 
  4 : // Spiral and glyph
739
 
   begin
740
 
    sp.Construct    (m_x ,m_y ,10 ,150 ,30 ,0.0 );
741
 
    stroke.Construct(@sp );
742
 
    stroke.width_   (15.0 );
743
 
 
744
 
    glyph.Construct;
745
 
    glyph.move_to(28.47 ,6.45 );
746
 
    glyph.curve3 (21.58 ,1.12  ,19.82 ,0.29 );
747
 
    glyph.curve3 (17.19 ,-0.93 ,14.21 ,-0.93 );
748
 
    glyph.curve3 (9.57  ,-0.93 ,6.57  ,2.25 );
749
 
    glyph.curve3 (3.56  ,5.42  ,3.56  ,10.60 );
750
 
    glyph.curve3 (3.56  ,13.87 ,5.03  ,16.26 );
751
 
    glyph.curve3 (7.03  ,19.58 ,11.99 ,22.51 );
752
 
    glyph.curve3 (16.94 ,25.44 ,28.47 ,29.64 );
753
 
    glyph.line_to(28.47 ,31.40 );
754
 
    glyph.curve3 (28.47 ,38.09 ,26.34 ,40.58 );
755
 
    glyph.curve3 (24.22 ,43.07 ,20.17 ,43.07 );
756
 
    glyph.curve3 (17.09 ,43.07 ,15.28 ,41.41 );
757
 
    glyph.curve3 (13.43 ,39.75 ,13.43 ,37.60 );
758
 
    glyph.line_to(13.53 ,34.77 );
759
 
    glyph.curve3 (13.53 ,32.52 ,12.38 ,31.30 );
760
 
    glyph.curve3 (11.23 ,30.08 ,9.38  ,30.08 );
761
 
    glyph.curve3 (7.57  ,30.08 ,6.42  ,31.35 );
762
 
    glyph.curve3 (5.27  ,32.62 ,5.27  ,34.81 );
763
 
    glyph.curve3 (5.27  ,39.01 ,9.57  ,42.53 );
764
 
    glyph.curve3 (13.87 ,46.04 ,21.63 ,46.04 );
765
 
    glyph.curve3 (27.59 ,46.04 ,31.40 ,44.04 );
766
 
    glyph.curve3 (34.28 ,42.53 ,35.64 ,39.31 );
767
 
    glyph.curve3 (36.52 ,37.21 ,36.52 ,30.71 );
768
 
    glyph.line_to(36.52 ,15.53 );
769
 
    glyph.curve3 (36.52 ,9.13  ,36.77 ,7.69 );
770
 
    glyph.curve3 (37.01 ,6.25  ,37.57 ,5.76 );
771
 
    glyph.curve3 (38.13 ,5.27  ,38.87 ,5.27 );
772
 
    glyph.curve3 (39.65 ,5.27  ,40.23 ,5.62 );
773
 
    glyph.curve3 (41.26 ,6.25  ,44.19 ,9.18 );
774
 
    glyph.line_to(44.19 ,6.45 );
775
 
    glyph.curve3 (38.72 ,-0.88 ,33.74 ,-0.88 );
776
 
    glyph.curve3 (31.35 ,-0.88 ,29.93 ,0.78 );
777
 
    glyph.curve3 (28.52 ,2.44  ,28.47 ,6.45 );
778
 
    glyph.close_polygon;
779
 
 
780
 
    glyph.move_to(28.47 ,9.62 );
781
 
    glyph.line_to(28.47 ,26.66 );
782
 
    glyph.curve3 (21.09 ,23.73 ,18.95 ,22.51 );
783
 
    glyph.curve3 (15.09 ,20.36 ,13.43 ,18.02 );
784
 
    glyph.curve3 (11.77 ,15.67 ,11.77 ,12.89 );
785
 
    glyph.curve3 (11.77 ,9.38  ,13.87 ,7.06 );
786
 
    glyph.curve3 (15.97 ,4.74  ,18.70 ,4.74 );
787
 
    glyph.curve3 (22.41 ,4.74  ,28.47 ,9.62 );
788
 
    glyph.close_polygon;
789
 
 
790
 
    mtx.Construct;
791
 
    tas.Construct(4.0 );
792
 
    tat.Construct(220 ,200 );
793
 
    mtx.multiply(@tas );
794
 
    mtx.multiply(@tat );
795
 
 
796
 
    trans.Construct(@glyph ,@mtx );
797
 
    curve.Construct(@trans );
798
 
 
799
 
    ras1.reset;
800
 
    ras1.add_path   (@stroke );
801
 
    rgba.ConstrDbl  (0 ,0 ,0 ,0.1 );
802
 
    ren.color_      (@rgba );
803
 
    render_scanlines(ras1 ,@sl ,@ren );
804
 
 
805
 
    ras2.reset;
806
 
    ras2.add_path   (@curve );
807
 
    rgba.ConstrDbl  (0 ,0.6 ,0 ,0.1 );
808
 
    ren.color_      (@rgba );
809
 
    render_scanlines(ras2 ,@sl ,@ren );
810
 
 
811
 
    render_scanline_boolean(ras1 ,ras2 );
812
 
 
813
 
    stroke.Destruct;
814
 
    glyph.Destruct;
815
 
    curve.Destruct;
816
 
 
817
 
   end;
818
 
 
819
 
 end;
820
 
 
821
 
 sl.Destruct;
822
 
 
823
 
 result:=0;
824
 
 
825
 
end;
826
 
 
827
 
{ ON_INIT }
828
 
procedure the_application.on_init;
829
 
begin
830
 
 m_x:=_width / 2.0;
831
 
 m_y:=_height / 2.0;
832
 
 
833
 
end;
834
 
 
835
 
{ ON_DRAW }
836
 
procedure the_application.on_draw;
837
 
var
838
 
 pf : pixel_formats;
839
 
 
840
 
 rgba : aggclr;
841
 
 
842
 
 ren_base  : renderer_base;
843
 
 ren_solid : renderer_scanline_aa_solid;
844
 
 
845
 
 sl   : scanline_u8;
846
 
 ras  ,
847
 
 ras2 : rasterizer_scanline_aa;
848
 
 
849
 
begin
850
 
// Initialize structures
851
 
 pixfmt_bgr24(pf ,rbuf_window );
852
 
 
853
 
 ren_base.Construct (@pf );
854
 
 ren_solid.Construct(@ren_base );
855
 
 
856
 
 rgba.ConstrDbl(1 ,1 ,1 );
857
 
 ren_base.clear(@rgba );
858
 
 
859
 
 sl.Construct;
860
 
 ras.Construct;
861
 
 ras2.Construct;
862
 
 
863
 
// Render the controls
864
 
 render_ctrl(@ras ,@sl ,@ren_solid ,@m_polygons );
865
 
 render_ctrl(@ras ,@sl ,@ren_solid ,@m_fill_rule );
866
 
 render_ctrl(@ras ,@sl ,@ren_solid ,@m_scanline_type );
867
 
 render_ctrl(@ras ,@sl ,@ren_solid ,@m_operation );
868
 
 
869
 
// Render
870
 
 render_sbool(@ras ,@ras2 );
871
 
 
872
 
// Free AGG resources
873
 
 sl.Destruct;
874
 
 ras.Destruct;
875
 
 ras2.Destruct;
876
 
 
877
 
end;
878
 
 
879
 
{ ON_MOUSE_MOVE }
880
 
procedure the_application.on_mouse_move;
881
 
begin
882
 
 if flags and mouse_left <> 0 then
883
 
  begin
884
 
   m_x:=x;
885
 
   m_y:=y;
886
 
 
887
 
   force_redraw;
888
 
 
889
 
  end;
890
 
 
891
 
end;
892
 
 
893
 
{ ON_MOUSE_BUTTON_DOWN }
894
 
procedure the_application.on_mouse_button_down;
895
 
var
896
 
 buf : array[0..99 ] of char;
897
 
 
898
 
begin
899
 
 if flags and mouse_left <> 0 then
900
 
  begin
901
 
   m_x:=x;
902
 
   m_y:=y;
903
 
 
904
 
   force_redraw;
905
 
 
906
 
  end;
907
 
 
908
 
 if flags and mouse_right <> 0 then
909
 
  begin
910
 
   sprintf (@buf[0 ]             ,'%d ' ,x );
911
 
   sprintf (@buf[StrLen(@buf ) ] ,'%d'  ,y );
912
 
   message_(@buf[0 ] );
913
 
 
914
 
  end;
915
 
 
916
 
end;
917
 
 
918
 
{ ON_KEY }
919
 
procedure the_application.on_key;
920
 
begin
921
 
 if key = key_f1 then
922
 
  message_(
923
 
   'This is another example of using of the scanline boolean algebra. The example is '#13 +
924
 
   'similar to Demo gpc_test. Note that the cost of the boolean operation with Anti-Aliasing '#13 +
925
 
   'is comparable with rendering (the rasterization time is not included). Also note that '#13 +
926
 
   'there is a difference in timings between using of scanline_u and scanline_p. Most often '#13 +
927
 
   'scanline_u works faster, but it''s because of much less number of produced spans.'#13 +
928
 
   'Actually, when using the scanline_u the complexity of the algorithm becomes proportional '#13 +
929
 
   'to the area of the polygons, while in scanline_p it''s proportional to the perimeter. '#13 +
930
 
   'Of course, the binary variant works much faster than the Anti-Aliased one.' +
931
 
   #13#13'Note: F2 key saves current "screenshot" file in this demo''s directory.  ' );
932
 
 
933
 
end;
934
 
 
935
 
VAR
936
 
 app : the_application;
937
 
 
938
 
BEGIN
939
 
 app.Construct(pix_format_bgr24 ,flip_y );
940
 
 app.caption_ ('AGG Example. Scanline Boolean (F1-Help)' );
941
 
 
942
 
 if app.init(655 ,520 ,window_resize ) then
943
 
  app.run;
944
 
 
945
 
 app.Destruct;
946
 
 
947
 
END.
 
 
b'\\ No newline at end of file'