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

« back to all changes in this revision

Viewing changes to components/aggpas/gpc_test.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
 
{target:win}
2
 
//
3
 
// AggPas 2.4 RM3 Demo application
4
 
// Note: Press F1 key on run to see more info about this demo
5
 
//
6
 
// Paths: src;src\ctrl;src\svg;src\util;src\platform\win;expat-wrap
7
 
//
8
 
program
9
 
 gpc_test ;
10
 
 
11
 
uses
12
 
 SysUtils ,
13
 
 
14
 
 agg_basics ,
15
 
 agg_platform_support ,
16
 
 
17
 
 agg_color ,
18
 
 agg_pixfmt ,
19
 
 agg_pixfmt_rgb ,
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_u ,
33
 
 agg_scanline_p ,
34
 
 agg_render_scanlines ,
35
 
 
36
 
 agg_math_stroke ,
37
 
 agg_path_storage ,
38
 
 agg_span_solid ,
39
 
 agg_conv_curve ,
40
 
 agg_conv_stroke ,
41
 
 agg_conv_transform ,
42
 
 agg_conv_clip_polygon ,
43
 
 agg_conv_gpc ,
44
 
 agg_gsv_text ,
45
 
 agg_trans_affine ,
46
 
 agg_vertex_source ,
47
 
 
48
 
 make_gb_poly_ ,
49
 
 make_arrows_ ;
50
 
 
51
 
{$I agg_mode.inc }
52
 
 
53
 
const
54
 
 flip_y = true;
55
 
 
56
 
type
57
 
 spiral = object(vertex_source )
58
 
   m_x    ,
59
 
   m_y    ,
60
 
   m_r1   ,
61
 
   m_r2   ,
62
 
   m_step ,
63
 
 
64
 
   m_start_angle ,
65
 
 
66
 
   m_angle  ,
67
 
   m_curr_r ,
68
 
   m_da     ,
69
 
   m_dr     : double;
70
 
   m_start  : boolean;
71
 
 
72
 
   constructor Construct(x ,y ,r1 ,r2 ,step : double; start_angle : double = 0 );
73
 
 
74
 
   procedure rewind(path_id : unsigned ); virtual;
75
 
   function  vertex(x ,y : double_ptr ) : unsigned; virtual;
76
 
 
77
 
  end;
78
 
 
79
 
 conv_poly_counter = object(vertex_source )
80
 
   m_src : vertex_source_ptr;
81
 
 
82
 
   m_contours ,
83
 
   m_points   : unsigned;
84
 
 
85
 
   constructor Construct(src : vertex_source_ptr );
86
 
 
87
 
   procedure rewind(path_id : unsigned ); virtual;
88
 
   function  vertex(x ,y : double_ptr ) : unsigned; virtual;
89
 
 
90
 
  end;
91
 
 
92
 
 the_application = object(platform_support )
93
 
   m_polygons  ,
94
 
   m_operation : rbox_ctrl;
95
 
 
96
 
   m_x ,
97
 
   m_y : double;
98
 
 
99
 
   constructor Construct(format_ : pix_format_e; flip_y_ : boolean );
100
 
   destructor  Destruct;
101
 
 
102
 
   procedure perform_rendering(
103
 
              sl  : scanline_ptr;
104
 
              ras : rasterizer_scanline_ptr;
105
 
              ren : renderer_scanline_ptr;
106
 
              gpc : conv_gpc_ptr );
107
 
 
108
 
   function  render_gpc(sl : scanline_ptr; ras : rasterizer_scanline_ptr ) : unsigned;
109
 
 
110
 
   procedure on_init; virtual;
111
 
   procedure on_draw; virtual;
112
 
 
113
 
   procedure on_mouse_move       (x ,y : int; flags : unsigned ); virtual;
114
 
   procedure on_mouse_button_down(x ,y : int; flags : unsigned ); virtual;
115
 
 
116
 
   procedure on_key(x ,y : int; key ,flags : unsigned ); virtual;
117
 
 
118
 
   procedure stress_test;
119
 
 
120
 
  end;
121
 
 
122
 
{ CONSTRUCT }
123
 
constructor spiral.Construct;
124
 
begin
125
 
 m_x :=x;
126
 
 m_y :=y;
127
 
 m_r1:=r1;
128
 
 m_r2:=r2;
129
 
 
130
 
 m_step       :=step;
131
 
 m_start_angle:=start_angle;
132
 
 m_angle      :=start_angle;
133
 
 
134
 
 m_da:=deg2rad(4.0 );
135
 
 m_dr:=m_step / 90.0;
136
 
 
137
 
end;
138
 
 
139
 
{ REWIND }
140
 
procedure spiral.rewind;
141
 
begin
142
 
 m_angle :=m_start_angle;
143
 
 m_curr_r:=m_r1;
144
 
 m_start :=true;
145
 
 
146
 
end;
147
 
 
148
 
{ VERTEX }
149
 
function spiral.vertex;
150
 
begin
151
 
 if m_curr_r > m_r2 then
152
 
  begin
153
 
   result:=path_cmd_stop;
154
 
 
155
 
   exit;
156
 
 
157
 
  end;
158
 
 
159
 
 x^:=m_x + Cos(m_angle ) * m_curr_r;
160
 
 y^:=m_y + Sin(m_angle ) * m_curr_r;
161
 
 
162
 
 m_curr_r:=m_curr_r + m_dr;
163
 
 m_angle :=m_angle + m_da;
164
 
 
165
 
 if m_start then
166
 
  begin
167
 
   m_start:=false;
168
 
 
169
 
   result:=path_cmd_move_to;
170
 
 
171
 
  end
172
 
 else
173
 
  result:=path_cmd_line_to;
174
 
 
175
 
end;
176
 
 
177
 
{ CONSTRUCT }
178
 
constructor conv_poly_counter.Construct;
179
 
begin
180
 
 m_src:=src;
181
 
 
182
 
 m_contours:=0;
183
 
 m_points  :=0;
184
 
 
185
 
end;
186
 
 
187
 
{ REWIND }
188
 
procedure conv_poly_counter.rewind;
189
 
begin
190
 
 m_contours:=0;
191
 
 m_points  :=0;
192
 
 
193
 
 m_src.rewind(path_id );
194
 
 
195
 
end;
196
 
 
197
 
{ VERTEX }
198
 
function conv_poly_counter.vertex;
199
 
var
200
 
 cmd : unsigned;
201
 
 
202
 
begin
203
 
 cmd:=m_src.vertex(x ,y );
204
 
 
205
 
 if is_vertex(cmd ) then
206
 
  inc(m_points );
207
 
 
208
 
 if is_move_to(cmd ) then
209
 
  inc(m_contours );
210
 
 
211
 
 result:=cmd;
212
 
 
213
 
end;
214
 
 
215
 
{ CONSTRUCT }
216
 
constructor the_application.Construct;
217
 
begin
218
 
 inherited Construct(format_ ,flip_y_ );
219
 
 
220
 
 m_polygons.Construct (5.0   ,5.0 ,5.0 + 205.0  ,110.0 ,not flip_y_ );
221
 
 m_operation.Construct(555.0 ,5.0 ,555.0 + 80.0 ,130.0 ,not flip_y_ );
222
 
 
223
 
 m_operation.add_item ('None' );
224
 
 m_operation.add_item ('OR' );
225
 
 m_operation.add_item ('AND' );
226
 
 m_operation.add_item ('XOR' );
227
 
 m_operation.add_item ('A-B' );
228
 
 m_operation.add_item ('B-A' );
229
 
 m_operation.cur_item_(2 );
230
 
 
231
 
 add_ctrl(@m_operation );
232
 
 
233
 
 m_polygons.add_item ('Two Simple Paths' );
234
 
 m_polygons.add_item ('Closed Stroke' );
235
 
 m_polygons.add_item ('Great Britain and Arrows' );
236
 
 m_polygons.add_item ('Great Britain and Spiral' );
237
 
 m_polygons.add_item ('Spiral and Glyph' );
238
 
 m_polygons.cur_item_(3 );
239
 
 
240
 
 add_ctrl(@m_polygons );
241
 
 
242
 
end;
243
 
 
244
 
{ DESTRUCT }
245
 
destructor the_application.Destruct;
246
 
begin
247
 
 inherited Destruct;
248
 
 
249
 
 m_polygons.Destruct;
250
 
 m_operation.Destruct;
251
 
 
252
 
end;
253
 
 
254
 
{ PERFORM_RENDERING }
255
 
procedure the_application.perform_rendering;
256
 
var
257
 
 counter : conv_poly_counter;
258
 
 
259
 
 t1 ,t2 ,x ,y : double;
260
 
 
261
 
 cmd : unsigned;
262
 
 buf : array[0..99 ] of char;
263
 
 
264
 
 rgba : aggclr;
265
 
 txt  : gsv_text;
266
 
 
267
 
 txt_stroke : conv_stroke;
268
 
 
269
 
begin
270
 
 if m_operation._cur_item > 0 then
271
 
  begin
272
 
  // Render clipped polygon
273
 
   ras.reset;
274
 
 
275
 
   case m_operation._cur_item of
276
 
    1: gpc.operation(gpc_or );
277
 
    2: gpc.operation(gpc_and );
278
 
    3: gpc.operation(gpc_xor );
279
 
    4: gpc.operation(gpc_a_minus_b );
280
 
    5: gpc.operation(gpc_b_minus_a );
281
 
 
282
 
   end;
283
 
 
284
 
   counter.Construct(gpc );
285
 
 
286
 
   start_timer;
287
 
   counter.rewind(0 );
288
 
 
289
 
   t1:=elapsed_time;
290
 
 
291
 
   ras.reset;
292
 
   start_timer;
293
 
 
294
 
   cmd:=counter.vertex(@x ,@y );
295
 
 
296
 
   while not is_stop(cmd ) do
297
 
    begin
298
 
     ras.add_vertex(x ,y ,cmd );
299
 
 
300
 
     cmd:=counter.vertex(@x ,@y );
301
 
 
302
 
    end;
303
 
 
304
 
   rgba.ConstrDbl  (0.5 ,0.0 ,0 ,0.5 );
305
 
   ren.color_      (@rgba );
306
 
   render_scanlines(ras ,sl ,ren );
307
 
 
308
 
   t2:=elapsed_time;
309
 
 
310
 
  // Render information text
311
 
   sprintf(@buf[0 ]             ,'Contours: %d   ' ,counter.m_contours );
312
 
   sprintf(@buf[StrLen(@buf ) ] ,'Points: %d' ,counter.m_points );
313
 
 
314
 
   txt.Construct;
315
 
   txt_stroke.Construct(@txt );
316
 
 
317
 
   txt_stroke.width_   (1.5 );
318
 
   txt_stroke.line_cap_(round_cap );
319
 
   txt.size_           (10.0 );
320
 
   txt.start_point_    (250 ,5 );
321
 
   txt.text_           (@buf[0 ] );
322
 
 
323
 
   ras.add_path    (@txt_stroke );
324
 
   rgba.ConstrDbl  (0.0 ,0.0 ,0.0 );
325
 
   ren.color_      (@rgba );
326
 
   render_scanlines(ras ,sl ,ren );
327
 
 
328
 
   sprintf(@buf[0 ]            ,'GPC=%.3fms ' ,t1 );
329
 
   sprintf(@buf[StrLen(buf ) ] ,'Render=%.3fms' ,t2 );
330
 
 
331
 
   txt.start_point_(250 ,20 );
332
 
   txt.text_       (@buf[0 ] );
333
 
 
334
 
   ras.add_path    (@txt_stroke );
335
 
   rgba.ConstrDbl  (0.0 ,0.0 ,0.0 );
336
 
   ren.color_      (@rgba );
337
 
   render_scanlines(ras ,sl ,ren );
338
 
 
339
 
  // Free
340
 
   txt.Destruct;
341
 
   txt_stroke.Destruct;
342
 
 
343
 
  end;
344
 
 
345
 
end;
346
 
 
347
 
{ RENDER_GPC }
348
 
function the_application.render_gpc;
349
 
var
350
 
 pf : pixel_formats;
351
 
 rb : renderer_base;
352
 
 
353
 
 ren : renderer_scanline_aa_solid;
354
 
 ps1 ,
355
 
 ps2 ,
356
 
 
357
 
 gb_poly ,
358
 
 arrows  ,
359
 
 glyph   : path_storage;
360
 
 
361
 
 rgba : aggclr;
362
 
 x ,y : double;
363
 
 
364
 
 mtx1 ,
365
 
 mtx2 ,
366
 
 mtx  : trans_affine;
367
 
 tat  : trans_affine_translation;
368
 
 tas  : trans_affine_scaling;
369
 
 
370
 
 stroke         ,
371
 
 stroke_gb_poly : conv_stroke;
372
 
 
373
 
 trans         ,
374
 
 trans_gb_poly ,
375
 
 trans_arrows  : conv_transform;
376
 
 
377
 
 curve : conv_curve;
378
 
 
379
 
 sp  : spiral;
380
 
 gpc : conv_gpc;
381
 
 
382
 
begin
383
 
 pixfmt_bgr24(pf ,rbuf_window );
384
 
 
385
 
 rb.Construct (@pf );
386
 
 ren.Construct(@rb );
387
 
 
388
 
 case m_polygons._cur_item of
389
 
  0 : // Two simple paths
390
 
   begin
391
 
    ps1.Construct;
392
 
    ps2.Construct;
393
 
 
394
 
    gpc.Construct(@ps1 ,@ps2 );
395
 
 
396
 
    x:=m_x - _initial_width / 2 + 100;
397
 
    y:=m_y - _initial_height / 2 + 100;
398
 
 
399
 
    ps1.move_to(x + 140 ,y + 145 );
400
 
    ps1.line_to(x + 225 ,y + 44 );
401
 
    ps1.line_to(x + 296 ,y + 219 );
402
 
    ps1.close_polygon;
403
 
 
404
 
    ps1.line_to(x + 226 ,y + 289 );
405
 
    ps1.line_to(x + 82  ,y + 292 );
406
 
 
407
 
    ps1.move_to(x + 220 ,y + 222 );
408
 
    ps1.line_to(x + 363 ,y + 249 );
409
 
    ps1.line_to(x + 265 ,y + 331 );
410
 
 
411
 
    ps1.move_to(x + 242 ,y + 243 );
412
 
    ps1.line_to(x + 268 ,y + 309 );
413
 
    ps1.line_to(x + 325 ,y + 261 );
414
 
 
415
 
    ps1.move_to(x + 259 ,y + 259 );
416
 
    ps1.line_to(x + 273 ,y + 288 );
417
 
    ps1.line_to(x + 298 ,y + 266 );
418
 
 
419
 
    ps2.move_to(100 + 32  ,100 + 77 );
420
 
    ps2.line_to(100 + 473 ,100 + 263 );
421
 
    ps2.line_to(100 + 351 ,100 + 290 );
422
 
    ps2.line_to(100 + 354 ,100 + 374 );
423
 
 
424
 
    ras.reset;
425
 
    ras.add_path    (@ps1 );
426
 
    rgba.ConstrDbl  (0 ,0 ,0 ,0.1 );
427
 
    ren.color_      (@rgba );
428
 
    render_scanlines(ras ,sl ,@ren );
429
 
 
430
 
    ras.reset;
431
 
    ras.add_path    (@ps2 );
432
 
    rgba.ConstrDbl  (0 ,0.6 ,0 ,0.1 );
433
 
    ren.color_      (@rgba );
434
 
    render_scanlines(ras ,sl ,@ren );
435
 
 
436
 
    perform_rendering(sl ,ras ,@ren ,@gpc );
437
 
 
438
 
    ps1.Destruct;
439
 
    ps2.Destruct;
440
 
    gpc.Destruct;
441
 
 
442
 
   end;
443
 
 
444
 
  1 : // Closed stroke
445
 
   begin
446
 
    ps1.Construct;
447
 
    ps2.Construct;
448
 
    stroke.Construct(@ps2 );
449
 
    stroke.width_   (10.0 );
450
 
 
451
 
    gpc.Construct(@ps1 ,@stroke );
452
 
 
453
 
    x:=m_x - _initial_width / 2 + 100;
454
 
    y:=m_y - _initial_height / 2 + 100;
455
 
 
456
 
    ps1.move_to(x + 140 ,y + 145 );
457
 
    ps1.line_to(x + 225 ,y + 44 );
458
 
    ps1.line_to(x + 296 ,y + 219 );
459
 
    ps1.close_polygon;
460
 
 
461
 
    ps1.line_to(x + 226 ,y + 289 );
462
 
    ps1.line_to(x + 82  ,y + 292 );
463
 
 
464
 
    ps1.move_to(x + 220 - 50 ,y + 222 );
465
 
    ps1.line_to(x + 265 - 50 ,y + 331 );
466
 
    ps1.line_to(x + 363 - 50 ,y + 249 );
467
 
    ps1.close_polygon(path_flags_ccw );
468
 
 
469
 
    ps2.move_to(100 + 32  ,100 + 77  );
470
 
    ps2.line_to(100 + 473 ,100 + 263 );
471
 
    ps2.line_to(100 + 351 ,100 + 290 );
472
 
    ps2.line_to(100 + 354 ,100 + 374 );
473
 
    ps2.close_polygon;
474
 
 
475
 
    ras.reset;
476
 
    ras.add_path    (@ps1 );
477
 
    rgba.ConstrDbl  (0 ,0 ,0 ,0.1 );
478
 
    ren.color_      (@rgba );
479
 
    render_scanlines(ras ,sl ,@ren );
480
 
 
481
 
    ras.reset;
482
 
    ras.add_path    (@stroke );
483
 
    rgba.ConstrDbl  (0 ,0.6 ,0 ,0.1 );
484
 
    ren.color_      (@rgba );
485
 
    render_scanlines(ras ,sl ,@ren );
486
 
 
487
 
    perform_rendering(sl ,ras ,@ren ,@gpc );
488
 
 
489
 
    ps1.Destruct;
490
 
    ps2.Destruct;
491
 
    stroke.Destruct;
492
 
    gpc.Destruct;
493
 
 
494
 
   end;
495
 
 
496
 
  2 : // Great Britain and Arrows
497
 
   begin
498
 
    gb_poly.Construct;
499
 
    arrows.Construct;
500
 
 
501
 
    make_gb_poly(@gb_poly );
502
 
    make_arrows (@arrows );
503
 
 
504
 
    mtx1.Construct;
505
 
    mtx2.Construct;
506
 
    tat.Construct(-1150 ,-1150 );
507
 
    tas.Construct(2.0 );
508
 
    mtx1.multiply(@tat );
509
 
    mtx1.multiply(@tas );
510
 
 
511
 
    mtx2:=mtx1;
512
 
 
513
 
    tat.Construct(m_x - _initial_width / 2 ,m_y - _initial_height / 2 );
514
 
 
515
 
    mtx2.multiply(@tat );
516
 
 
517
 
    trans_gb_poly.Construct(@gb_poly ,@mtx1 );
518
 
    trans_arrows.Construct (@arrows  ,@mtx2 );
519
 
 
520
 
    gpc.Construct(@trans_gb_poly ,@trans_arrows );
521
 
 
522
 
    ras.add_path    (@trans_gb_poly );
523
 
    rgba.ConstrDbl  (0.5 ,0.5 ,0 ,0.1 );
524
 
    ren.color_      (@rgba );
525
 
    render_scanlines(ras ,sl ,@ren );
526
 
 
527
 
    stroke_gb_poly.Construct(@trans_gb_poly );
528
 
    stroke_gb_poly.width_   (0.1);
529
 
    ras.add_path            (@stroke_gb_poly );
530
 
    rgba.ConstrDbl          (0 ,0 ,0 );
531
 
    ren.color_              (@rgba );
532
 
    render_scanlines        (ras ,sl ,@ren );
533
 
 
534
 
    ras.add_path    (@trans_arrows );
535
 
    rgba.ConstrDbl  (0.0 ,0.5 ,0.5 ,0.1 );
536
 
    ren.color_      (@rgba );
537
 
    render_scanlines(ras ,sl ,@ren );
538
 
 
539
 
    perform_rendering(sl ,ras ,@ren ,@gpc );
540
 
 
541
 
    gb_poly.Destruct;
542
 
    arrows.Destruct;
543
 
    stroke_gb_poly.Destruct;
544
 
    gpc.Destruct;
545
 
 
546
 
   end;
547
 
 
548
 
  3 : // Great Britain and a Spiral
549
 
   begin
550
 
    sp.Construct    (m_x ,m_y ,10 ,150 ,30 ,0.0 );
551
 
    stroke.Construct(@sp );
552
 
    stroke.width_   (15.0 );
553
 
 
554
 
    gb_poly.Construct;
555
 
    make_gb_poly(@gb_poly );
556
 
 
557
 
    mtx.Construct;
558
 
    tat.Construct(-1150 ,-1150 );
559
 
    tas.Construct(2.0 );
560
 
    mtx.multiply(@tat );
561
 
    mtx.multiply(@tas );
562
 
 
563
 
    trans_gb_poly.Construct(@gb_poly ,@mtx );
564
 
 
565
 
    gpc.Construct(@trans_gb_poly ,@stroke );
566
 
 
567
 
    ras.add_path    (@trans_gb_poly );
568
 
    rgba.ConstrDbl  (0.5 ,0.5 ,0 ,0.1 );
569
 
    ren.color_      (@rgba );
570
 
    render_scanlines(ras ,sl ,@ren );
571
 
 
572
 
    stroke_gb_poly.Construct(@trans_gb_poly );
573
 
    stroke_gb_poly.width_   (0.1 );
574
 
    ras.add_path            (@stroke_gb_poly );
575
 
    rgba.ConstrDbl          (0 ,0 ,0 );
576
 
    ren.color_              (@rgba );
577
 
    render_scanlines        (ras ,sl ,@ren );
578
 
 
579
 
    ras.add_path    (@stroke );
580
 
    rgba.ConstrDbl  (0.0 ,0.5 ,0.5 ,0.1 );
581
 
    ren.color_      (@rgba );
582
 
    render_scanlines(ras ,sl ,@ren );
583
 
 
584
 
    perform_rendering(sl ,ras ,@ren ,@gpc );
585
 
 
586
 
    stroke.Destruct;
587
 
    gb_poly.Destruct;
588
 
    stroke_gb_poly.Destruct;
589
 
    gpc.Destruct;
590
 
 
591
 
   end;
592
 
 
593
 
  4 : // Spiral and glyph
594
 
   begin
595
 
    sp.Construct    (m_x ,m_y ,10 ,150 ,30 ,0.0 );
596
 
    stroke.Construct(@sp );
597
 
    stroke.width_   (15.0 );
598
 
 
599
 
    glyph.Construct;
600
 
    glyph.move_to(28.47 ,6.45 );
601
 
    glyph.curve3 (21.58 ,1.12  ,19.82 ,0.29 );
602
 
    glyph.curve3 (17.19 ,-0.93 ,14.21 ,-0.93 );
603
 
    glyph.curve3 (9.57  ,-0.93 ,6.57  ,2.25 );
604
 
    glyph.curve3 (3.56  ,5.42  ,3.56  ,10.60 );
605
 
    glyph.curve3 (3.56  ,13.87 ,5.03  ,16.26 );
606
 
    glyph.curve3 (7.03  ,19.58 ,11.99 ,22.51 );
607
 
    glyph.curve3 (16.94 ,25.44 ,28.47 ,29.64 );
608
 
    glyph.line_to(28.47 ,31.40 );
609
 
    glyph.curve3 (28.47 ,38.09 ,26.34 ,40.58 );
610
 
    glyph.curve3 (24.22 ,43.07 ,20.17 ,43.07 );
611
 
    glyph.curve3 (17.09 ,43.07 ,15.28 ,41.41 );
612
 
    glyph.curve3 (13.43 ,39.75 ,13.43 ,37.60 );
613
 
    glyph.line_to(13.53 ,34.77 );
614
 
    glyph.curve3 (13.53 ,32.52 ,12.38 ,31.30 );
615
 
    glyph.curve3 (11.23 ,30.08 ,9.38  ,30.08 );
616
 
    glyph.curve3 (7.57  ,30.08 ,6.42  ,31.35 );
617
 
    glyph.curve3 (5.27  ,32.62 ,5.27  ,34.81 );
618
 
    glyph.curve3 (5.27  ,39.01 ,9.57  ,42.53 );
619
 
    glyph.curve3 (13.87 ,46.04 ,21.63 ,46.04 );
620
 
    glyph.curve3 (27.59 ,46.04 ,31.40 ,44.04 );
621
 
    glyph.curve3 (34.28 ,42.53 ,35.64 ,39.31 );
622
 
    glyph.curve3 (36.52 ,37.21 ,36.52 ,30.71 );
623
 
    glyph.line_to(36.52 ,15.53 );
624
 
    glyph.curve3 (36.52 ,9.13  ,36.77 ,7.69 );
625
 
    glyph.curve3 (37.01 ,6.25  ,37.57 ,5.76 );
626
 
    glyph.curve3 (38.13 ,5.27  ,38.87 ,5.27 );
627
 
    glyph.curve3 (39.65 ,5.27  ,40.23 ,5.62 );
628
 
    glyph.curve3 (41.26 ,6.25  ,44.19 ,9.18 );
629
 
    glyph.line_to(44.19 ,6.45 );
630
 
    glyph.curve3 (38.72 ,-0.88 ,33.74 ,-0.88 );
631
 
    glyph.curve3 (31.35 ,-0.88 ,29.93 ,0.78 );
632
 
    glyph.curve3 (28.52 ,2.44  ,28.47 ,6.45 );
633
 
    glyph.close_polygon;
634
 
 
635
 
    glyph.move_to(28.47 ,9.62 );
636
 
    glyph.line_to(28.47 ,26.66 );
637
 
    glyph.curve3 (21.09 ,23.73 ,18.95 ,22.51 );
638
 
    glyph.curve3 (15.09 ,20.36 ,13.43 ,18.02 );
639
 
    glyph.curve3 (11.77 ,15.67 ,11.77 ,12.89 );
640
 
    glyph.curve3 (11.77 ,9.38  ,13.87 ,7.06 );
641
 
    glyph.curve3 (15.97 ,4.74  ,18.70 ,4.74 );
642
 
    glyph.curve3 (22.41 ,4.74  ,28.47 ,9.62 );
643
 
    glyph.close_polygon;
644
 
 
645
 
    mtx.Construct;
646
 
    tas.Construct(4.0 );
647
 
    tat.Construct(220 ,200 );
648
 
    mtx.multiply(@tas );
649
 
    mtx.multiply(@tat );
650
 
 
651
 
    trans.Construct(@glyph ,@mtx );
652
 
    curve.Construct(@trans );
653
 
 
654
 
    gpc.Construct(@stroke ,@curve );
655
 
 
656
 
    ras.reset;
657
 
    ras.add_path    (@stroke );
658
 
    rgba.ConstrDbl  (0 ,0 ,0 ,0.1 );
659
 
    ren.color_      (@rgba );
660
 
    render_scanlines(ras ,sl ,@ren );
661
 
 
662
 
    ras.reset;
663
 
    ras.add_path    (@curve );
664
 
    rgba.ConstrDbl  (0 ,0.6 ,0 ,0.1 );
665
 
    ren.color_      (@rgba );
666
 
    render_scanlines(ras ,sl ,@ren );
667
 
 
668
 
    perform_rendering(sl ,ras ,@ren ,@gpc );
669
 
 
670
 
    stroke.Destruct;
671
 
    glyph.Destruct;
672
 
    curve.Destruct;
673
 
    gpc.Destruct;
674
 
    
675
 
   end;
676
 
 
677
 
 end;
678
 
 
679
 
 result:=0;
680
 
 
681
 
end;
682
 
 
683
 
{ ON_INIT }
684
 
procedure the_application.on_init;
685
 
begin
686
 
 m_x:=_width / 2.0;
687
 
 m_y:=_height / 2.0;
688
 
 
689
 
end;
690
 
 
691
 
{ ON_DRAW }
692
 
procedure the_application.on_draw;
693
 
var
694
 
 pf : pixel_formats;
695
 
 
696
 
 rgba : aggclr;
697
 
 
698
 
 ren_base  : renderer_base;
699
 
 ren_solid : renderer_scanline_aa_solid;
700
 
 
701
 
 sl  : scanline_u8;
702
 
 ras : rasterizer_scanline_aa;
703
 
 
704
 
begin
705
 
// Initialize structures
706
 
 pixfmt_bgr24(pf ,rbuf_window );
707
 
 
708
 
 ren_base.Construct (@pf );
709
 
 ren_solid.Construct(@ren_base );
710
 
 
711
 
 rgba.ConstrDbl(1 ,1 ,1 );
712
 
 ren_base.clear(@rgba );
713
 
 
714
 
 sl.Construct;
715
 
 ras.Construct;
716
 
 
717
 
// Render
718
 
 render_gpc(@sl ,@ras );
719
 
 
720
 
// Render the controls
721
 
 render_ctrl(@ras ,@sl ,@ren_solid ,@m_polygons );
722
 
 render_ctrl(@ras ,@sl ,@ren_solid ,@m_operation );
723
 
 
724
 
// Free AGG resources
725
 
 sl.Destruct;
726
 
 ras.Destruct;
727
 
 
728
 
end;
729
 
 
730
 
{ ON_MOUSE_MOVE }
731
 
procedure the_application.on_mouse_move;
732
 
begin
733
 
 if flags and mouse_left <> 0 then
734
 
  begin
735
 
   m_x:=x;
736
 
   m_y:=y;
737
 
 
738
 
   force_redraw;
739
 
 
740
 
  end;
741
 
 
742
 
end;
743
 
 
744
 
{ ON_MOUSE_BUTTON_DOWN }
745
 
procedure the_application.on_mouse_button_down;
746
 
var
747
 
 buf : array[0..99 ] of char;
748
 
 
749
 
begin
750
 
 if flags and mouse_left <> 0 then
751
 
  begin
752
 
   m_x:=x;
753
 
   m_y:=y;
754
 
 
755
 
   force_redraw;
756
 
 
757
 
  end;
758
 
 
759
 
 if flags and mouse_right <> 0 then
760
 
  begin
761
 
   sprintf (@buf[0 ]             ,'%d ' ,x );
762
 
   sprintf (@buf[StrLen(@buf ) ] ,'%d'  ,y );
763
 
   message_(@buf[0 ] );
764
 
 
765
 
  end;
766
 
 
767
 
end;
768
 
 
769
 
{ ON_KEY }
770
 
procedure the_application.on_key;
771
 
begin
772
 
 case key of
773
 
  byte('t' ) ,
774
 
  byte('T' ) :
775
 
   stress_test;
776
 
 
777
 
 end;
778
 
 
779
 
 if key = key_f1 then
780
 
  message_(
781
 
   'General Polygon Clipper by Alan Murta is the most reliable implementation of the '#13 +
782
 
   'polygon boolean algebra. It implements Bala R. Vatti''s algorithm of arbitrary '#13 +
783
 
   'polygon clipping and allows you to calculate the Union, Intersection, Difference, '#13 +
784
 
   'and Exclusive OR between two poly-polygons (i.e., polygonal areas consisted of '#13 +
785
 
   'several contours). AGG has a simple wrapper class that can be used in the coordinate '#13 +
786
 
   'conversion pipeline. The implementation by Alan Murta has restrictions of using it '#13 +
787
 
   'in commercial software, so that, please contact the author to settle the legal issues. '#13 +
788
 
   'The example demonstrates the use of GPC. Note, that all operations are done in the '#13 +
789
 
   'vectorial representation of the contours before rendering.'#13#13 +
790
 
   'How to play with:'#13#13 +
791
 
   'You can drag one polygon with the left mouse button pressed.'#13 +
792
 
   'Press the "T" key to perform the random polygon clipping stress testing.'#13 +
793
 
   '(may take some time)' +
794
 
   #13#13'Note: F2 key saves current "screenshot" file in this demo''s directory.  ' );
795
 
 
796
 
end;
797
 
 
798
 
{ STRESS_TEST }
799
 
// Stress-test.
800
 
// Works quite well on random polygons, no crashes, no memory leaks!
801
 
// Sometimes takes long to produce the result
802
 
procedure the_application.stress_test;
803
 
 
804
 
{ random }
805
 
function random(min ,max : double ) : double;
806
 
var
807
 
 r : int;
808
 
 
809
 
begin
810
 
 r:=(System.Random($7fff ) shl 15 ) or System.Random($7fff );
811
 
 
812
 
 result:=$FFFFFFF + 1;
813
 
 result:=((r and $FFFFFFF) / result ) * (max - min ) + min;
814
 
 
815
 
end;
816
 
 
817
 
var
818
 
 sl  : scanline_u8;
819
 
 ras : rasterizer_scanline_aa;
820
 
 
821
 
 pf : pixel_formats;
822
 
 
823
 
 ren_base  : renderer_base;
824
 
 ren_solid : renderer_scanline_aa_solid;
825
 
 
826
 
 ps1 ,ps2 : path_storage;
827
 
 
828
 
 gpc  : conv_gpc;
829
 
 rgba : aggclr;
830
 
 
831
 
 i ,num_poly1 ,num_poly2 ,j ,k ,np ,op: unsigned;
832
 
 
833
 
 buf : array[0..99 ] of char;
834
 
 txt : gsv_text;
835
 
 
836
 
 txt_stroke : conv_stroke;
837
 
 
838
 
begin
839
 
 sl.Construct;
840
 
 ras.Construct;
841
 
 
842
 
 pixfmt_bgr24(pf ,rbuf_window );
843
 
 
844
 
 ren_base.Construct (@pf );
845
 
 ren_solid.Construct(@ren_base );
846
 
 
847
 
 ps1.Construct;
848
 
 ps2.Construct;
849
 
 gpc.Construct(@ps1 ,@ps2 );
850
 
 
851
 
 txt.Construct;
852
 
 txt_stroke.Construct(@txt );
853
 
 
854
 
 txt_stroke.width_   (1.5 );
855
 
 txt_stroke.line_cap_(round_cap );
856
 
 txt.size_           (10.0 );
857
 
 txt.start_point_    (5 ,5 );
858
 
 
859
 
 for i:=0 to 999 do
860
 
  begin
861
 
   rgba.ConstrDbl(1 ,1 ,1 );
862
 
   ren_base.clear(@rgba );
863
 
 
864
 
   num_poly1:=System.Random($7fff ) mod 10 + 1;
865
 
   num_poly2:=System.Random($7fff ) mod 10 + 1;
866
 
 
867
 
   ps1.remove_all;
868
 
   ps2.remove_all;
869
 
 
870
 
   for j:=0 to num_poly1 - 1 do
871
 
    begin
872
 
     ps1.move_to(random(0 ,_width ) ,random(0 ,_height ) );
873
 
 
874
 
     np:=System.Random($7fff ) mod 20 + 2;
875
 
 
876
 
     for k:=0 to np - 1 do
877
 
      ps1.line_to(random(0 ,_width ) ,random(0 ,_height ) );
878
 
 
879
 
    end;
880
 
 
881
 
   for j:=0 to num_poly2 - 1 do
882
 
    begin
883
 
     ps2.move_to(random(0 ,_width ) ,random(0 ,_height ) );
884
 
 
885
 
     np:=System.Random($7fff ) mod 20 + 2;
886
 
 
887
 
     for k:=0 to np - 1 do
888
 
      ps2.line_to(random(0 ,_width ) ,random(0 ,_height ) );
889
 
 
890
 
    end;
891
 
 
892
 
   op:=System.Random($7fff ) mod 5;
893
 
 
894
 
   case op of
895
 
    0 :
896
 
     gpc.operation(gpc_or );
897
 
 
898
 
    1 :
899
 
     gpc.operation(gpc_and );
900
 
 
901
 
    2 :
902
 
     gpc.operation(gpc_xor );
903
 
 
904
 
    3 :
905
 
     gpc.operation(gpc_a_minus_b );
906
 
 
907
 
    else
908
 
     gpc.operation(gpc_b_minus_a );
909
 
 
910
 
   end;
911
 
 
912
 
  // Clipping result
913
 
   ras.add_path    (@gpc );
914
 
   rgba.ConstrDbl  (0.5 ,0.0 ,0 ,0.5 );
915
 
   ren_solid.color_(@rgba );
916
 
   render_scanlines(@ras ,@sl ,@ren_solid );
917
 
 
918
 
  // Counter display
919
 
   sprintf  (@buf[0 ] ,'%d / 1000' ,i + 1 );
920
 
   txt.text_(@buf[0 ] );
921
 
 
922
 
   txt.start_point_(5 ,5 );
923
 
 
924
 
   ras.add_path    (@txt_stroke );
925
 
   rgba.ConstrDbl  (0.0 ,0.0 ,0.0 );
926
 
   ren_solid.color_(@rgba );
927
 
   render_scanlines(@ras ,@sl ,@ren_solid );
928
 
 
929
 
  // Refresh
930
 
   update_window;
931
 
 
932
 
  end;
933
 
 
934
 
 message_('Done' );
935
 
 
936
 
 ps1.Destruct;
937
 
 ps2.Destruct;
938
 
 gpc.Destruct;
939
 
 
940
 
 sl.Destruct;
941
 
 ras.Destruct;
942
 
 
943
 
 txt.Destruct;
944
 
 txt_stroke.Destruct;
945
 
 
946
 
 force_redraw;
947
 
 
948
 
end;
949
 
 
950
 
VAR
951
 
 app : the_application;
952
 
 
953
 
BEGIN
954
 
 app.Construct(pix_format_bgr24 ,flip_y );
955
 
 app.caption_ ('AGG Example. General Polygon Clipping - GPC (F1-Help)' );
956
 
 
957
 
 if app.init(640 ,520 ,window_resize ) then
958
 
  app.run;
959
 
 
960
 
 app.Destruct;
961
 
 
962
 
END.
 
 
b'\\ No newline at end of file'