3
// AggPas 2.4 RM3 Demo application
4
// Note: Press F1 key on run to see more info about this demo
6
// Paths: src;src\ctrl;src\svg;src\util;src\platform\win;expat-wrap
16
agg_platform_support ,
25
agg_rendering_buffer ,
27
agg_renderer_scanline ,
28
agg_rasterizer_scanline_aa ,
31
agg_render_scanlines ,
39
agg_svg_path_renderer ,
41
file_utils_, AggPasLCL ;
43
{$I src/agg_mode.inc }
49
the_application = object(platform_support )
50
m_path : path_renderer;
55
m_rotate : slider_ctrl;
67
m_drag_flag : boolean;
69
constructor Construct(format_ : pix_format_e; flip_y_ : boolean );
72
procedure parse_svg(fname : shortstring );
74
procedure on_resize(sx ,sy : int ); virtual;
75
procedure on_draw; virtual;
77
procedure on_mouse_move(x ,y : int; flags : unsigned ); virtual;
79
procedure on_mouse_button_down(x ,y : int; flags : unsigned ); virtual;
80
procedure on_mouse_button_up (x ,y : int; flags : unsigned ); virtual;
82
procedure on_key(x ,y : int; key ,flags : unsigned ); virtual;
87
constructor the_application.Construct;
89
inherited Construct(format_ ,flip_y_ );
93
m_expand.Construct(5 ,5 ,256 - 5 ,11 ,not flip_y_ );
94
m_gamma.Construct (5 ,5 + 15 ,256 - 5 ,11 + 15 ,not flip_y_ );
95
m_scale.Construct (256 + 5 ,5 ,512 - 5 ,11 ,not flip_y_ );
96
m_rotate.Construct(256 + 5 ,5 + 15 ,512 - 5 ,11 + 15 ,not flip_y_ );
110
add_ctrl(@m_expand );
113
add_ctrl(@m_rotate );
115
m_expand.label_('Expand=%3.2f' );
116
m_expand.range_(-1 ,1.2 );
117
m_expand.value_(0.0 );
119
m_gamma.label_('Gamma=%3.2f' );
120
m_gamma.range_(0.0 ,3.0 );
121
m_gamma.value_(1.0 );
123
m_scale.label_('Scale=%3.2f' );
124
m_scale.range_(0.2 ,10.0 );
125
m_scale.value_(1.0 );
127
m_rotate.label_('Rotate=%3.2f' );
128
m_rotate.range_(-180.0 ,180.0 );
129
m_rotate.value_(0.0 );
134
destructor the_application.Destruct;
148
procedure the_application.parse_svg;
153
p.Construct(@m_path );
164
m_path.arrange_orientations;
165
m_path.bounding_rect(@m_min_x ,@m_min_y ,@m_max_x ,@m_max_y );
167
caption_(StrPas(PChar(p.title ) ) + ' (F1-Help)' );
174
procedure the_application.on_resize;
179
procedure the_application.on_draw;
181
pixf : pixel_formats;
184
ren : renderer_scanline_aa_solid;
185
ras : rasterizer_scanline_aa;
193
tat : trans_affine_translation;
194
tas : trans_affine_scaling;
195
tar : trans_affine_rotation;
199
vertex_count : unsigned;
201
buf : array[0..127 ] of char;
206
// Initialize structures
207
pixfmt_bgra32(pixf ,rbuf_window );
209
rb.Construct (@pixf );
212
rgba.ConstrDbl(1 ,1 ,1 );
220
gmpw.Construct(m_gamma._value );
223
tat.Construct((m_min_x + m_max_x ) * -0.5 ,(m_min_y + m_max_y ) * -0.5 );
224
mtx.multiply (@tat );
226
tas.Construct(m_scale._value );
227
mtx.multiply (@tas );
229
tar.Construct(deg2rad(m_rotate._value ) );
230
mtx.multiply (@tar );
232
tat.Construct((m_min_x + m_max_x ) * 0.5 + m_x ,(m_min_y + m_max_y ) * 0.5 + m_y + 30 );
233
mtx.multiply (@tat );
235
m_path.expand(m_expand._value );
239
m_path.render(@ras ,@sl ,@ren ,@mtx ,rb._clip_box ,1.0 );
243
vertex_count:=m_path.vertex_count;
245
// Render the controls
249
render_ctrl(@ras ,@sl ,@ren ,@m_expand );
250
render_ctrl(@ras ,@sl ,@ren ,@m_gamma );
251
render_ctrl(@ras ,@sl ,@ren ,@m_scale );
252
render_ctrl(@ras ,@sl ,@ren ,@m_rotate );
262
sprintf(@buf[0 ] ,'Vertices=%d ' ,vertex_count );
263
sprintf(@buf[StrLen(@buf[0 ] ) ] ,'Time=%.3f ms' ,tm );
265
t.start_point_(10.0 ,40.0 );
269
rgba.ConstrDbl (0 ,0 ,0 );
271
render_scanlines(@ras ,@sl ,@ren );
273
// Free AGG resources
283
procedure the_application.on_mouse_move;
299
{ ON_MOUSE_BUTTON_DOWN }
300
procedure the_application.on_mouse_button_down;
309
{ ON_MOUSE_BUTTON_UP }
310
procedure the_application.on_mouse_button_up;
317
procedure the_application.on_key;
320
tat : trans_affine_translation;
321
tas : trans_affine_scaling;
322
tar : trans_affine_rotation;
324
m : array[0..5 ] of double;
325
buf : array[0..127 ] of char;
329
if key = byte(' ' ) then
333
tat.Construct((m_min_x + m_max_x ) * -0.5 ,(m_min_y + m_max_y ) * -0.5 );
334
mtx.multiply (@tat );
336
tas.Construct(m_scale._value );
337
mtx.multiply (@tas );
339
tar.Construct(deg2rad(m_rotate._value ) );
340
mtx.multiply (@tar );
342
tat.Construct((m_min_x + m_max_x ) * 0.5 ,(m_min_y + m_max_y ) * 0.5 );
343
mtx.multiply (@tat );
345
tat.Construct(m_x ,m_y );
346
mtx.multiply (@tat );
350
sprintf(@buf[0 ] ,'%3.3f, ' ,m[0 ] );
351
sprintf(@buf[StrLen(@buf[0 ] ) ] ,'%3.3f, ' ,m[1 ] );
352
sprintf(@buf[StrLen(@buf[0 ] ) ] ,'%3.3f, ' ,m[2 ] );
353
sprintf(@buf[StrLen(@buf[0 ] ) ] ,'%3.3f, ' ,m[3 ] );
354
sprintf(@buf[StrLen(@buf[0 ] ) ] ,'%3.3f, ' ,m[4 ] );
355
sprintf(@buf[StrLen(@buf[0 ] ) ] ,'%3.3f' ,m[5 ] );
360
AssignFile(fd ,'transform.txt' );
362
writeln (fd ,PChar(@buf[0 ] ) );
369
'The SVG viewer is just another example of using Anti-Grain Geometry. The viewer '#13 +
370
'supports absolute minimum of the SVG specification, it basically can be used as '#13 +
371
'a simple example of AGG plus SVG. But of course, its functionality can be extended. '#13 +
372
'The main point of the viewer is high quality and high performance. The Anti-Aliasing '#13 +
373
'algorithm produces 256 levels of transparency. Actually, AGG computes the exact '#13 +
374
'coverage of the outline on each pixel cell.'#13#13 +
376
'Besides, the viewer has a very nice feature that I haven''t seen in any other ones. '#13 +
377
'It''s eliminating of the "problem of adjacent edges". It appears when rendering '#13 +
378
'adjacent polygons with anti-aliasing and looks like thin "web" upon the image. '#13 +
379
'Strictly speaking, it''s possible to get rid of it completely only when the polygons '#13 +
380
'are fully opaque. When they are translucent, the effect will appear anyway. However, '#13 +
381
'it''s possible to reduce the effect so that it becomes almost invisible.'#13#13 +
382
'How to play with:'#13#13 +
383
'Use mouse to move the drawing around. Change size & rotation with top controls.'#13 +
384
'Press the spacebar key to display and save the current transformation matrix.' );
389
app : the_application;
397
app.Construct(pix_format_bgra32 ,flip_y );
399
fname:=app.file_source('svg' ,'tiger.svg' );
401
if param_count > 0 then
406
if api_open_file(af ,fname ) then
410
app.message_('Usage: svg_test <svg_file>' );
419
app.parse_svg(fname );
421
if app.init(512 ,600 ,window_resize ) then
425
on e:svg_exception do
427
app.message_(PChar(e._msg ) );
433
app.message_('Unknown exception' );