2
// AggPas 2.4 RM3 Demo application
3
// Note: Press F1 key on run to see more info about this demo
5
// Paths: src;src\ctrl;src\svg;src\util;src\platform\win;expat-wrap
24
agg_platform_support ,
30
agg_rasterizer_scanline_aa ,
31
agg_rasterizer_outline_aa ,
36
agg_renderer_scanline ,
37
agg_renderer_outline_aa ,
38
agg_render_scanlines ,
48
{$I pixel_formats.inc }
55
g_rasterizer : rasterizer_scanline_aa;
56
g_scanline : scanline_p8;
58
g_path : path_storage;
59
g_colors : array[0..99 ] of aggclr;
60
g_path_idx : array[0..99 ] of unsigned;
64
g_x1 ,g_y1 ,g_x2 ,g_y2 ,
65
g_base_dx ,g_base_dy ,
67
g_skew_x ,g_skew_y : double;
72
the_application = object(platform_support )
73
m_width_slider : slider_ctrl;
74
m_scanline : cbox_ctrl;
76
constructor Construct(format_ : pix_format_e; flip_y_ : boolean );
79
procedure on_draw; virtual;
81
procedure transform(width_ ,height_ ,x ,y : double );
83
procedure on_mouse_move (x ,y : int; flags : unsigned ); virtual;
84
procedure on_mouse_button_down(x ,y : int; flags : unsigned ); virtual;
86
procedure on_key(x ,y : int; key ,flags : unsigned ); virtual;
91
procedure _parse_lion_;
93
g_npaths:=parse_lion(@g_path ,@g_colors ,@g_path_idx );
95
bounding_rect(@g_path ,@g_path_idx ,0 ,g_npaths ,@g_x1 ,@g_y1 ,@g_x2 ,@g_y2 );
97
g_base_dx:=(g_x2 - g_x1 ) / 2.0;
98
g_base_dy:=(g_y2 - g_y1 ) / 2.0;
103
constructor the_application.Construct;
105
inherited Construct(format_ ,flip_y_ );
107
m_width_slider.Construct(5 ,5 ,150 ,12 ,not flip_y_ );
108
m_scanline.Construct (160 ,5 ,'Use Scanline Rasterizer' ,not flip_y_ );
112
add_ctrl(@m_width_slider );
114
m_width_slider.no_transform;
115
m_width_slider.range_(0.0 ,4.0 );
116
m_width_slider.value_(1.0 );
117
m_width_slider.label_('Width %3.2f' );
119
add_ctrl(@m_scanline );
121
m_scanline.no_transform;
126
destructor the_application.Destruct;
130
m_width_slider.Destruct;
136
procedure the_application.on_draw;
138
width_ ,height_ : int;
142
pixf : pixel_formats;
145
r : renderer_scanline_aa_solid;
150
tat : trans_affine_translation;
151
tas : trans_affine_scaling;
152
tar : trans_affine_rotation;
153
taw : trans_affine_skewing;
155
stroke : conv_stroke;
156
trans : conv_transform;
158
gm_no : vertex_source;
159
profile : line_profile_aa;
161
ren : renderer_outline_aa;
162
ras : rasterizer_outline_aa;
165
width_ :=rbuf_window._width;
166
height_:=rbuf_window._height;
168
// Initialize structures
169
pixfmt(pixf ,rbuf_window );
171
rb.Construct(@pixf );
174
rgba.ConstrDbl(1 ,1 ,1 );
180
tat.Construct(-g_base_dx ,-g_base_dy );
181
mtx.multiply (@tat );
183
tas.Construct(g_scale ,g_scale );
184
mtx.multiply (@tas );
186
tar.Construct(g_angle + pi );
187
mtx.multiply (@tar );
189
taw.Construct(g_skew_x / 1000.0 ,g_skew_y / 1000.0 );
190
mtx.multiply (@taw );
192
tat.Construct(width_ / 2 ,height_ / 2 );
193
mtx.multiply (@tat );
196
if m_scanline._status then
198
stroke.Construct(@g_path );
199
stroke.width_ (m_width_slider._value );
200
trans.Construct (@stroke ,@mtx );
202
render_all_paths(@g_rasterizer ,@g_scanline ,@r ,@trans ,@g_colors ,@g_path_idx ,g_npaths );
209
w:=m_width_slider._value * mtx.scale;
212
profile.Construct(w ,@gm_no );
214
ren.Construct (@rb ,@profile );
215
ras.Construct (@ren );
216
trans.Construct(@g_path ,@mtx );
218
ras.render_all_paths(@trans ,@g_colors ,@g_path_idx ,g_npaths );
225
// Render the control
226
render_ctrl(@g_rasterizer ,@g_scanline ,@r ,@m_width_slider );
227
render_ctrl(@g_rasterizer ,@g_scanline ,@r ,@m_scanline );
232
procedure the_application.transform;
234
x:=x - (width_ / 2 );
235
y:=y - (height_ / 2 );
237
g_angle:=ArcTan2(y ,x );
238
g_scale:=Sqrt (y * y + x * x ) / 100.0;
243
procedure the_application.on_mouse_move;
245
on_mouse_button_down(x ,y ,flags );
249
{ ON_MOUSE_BUTTON_DOWN }
250
procedure the_application.on_mouse_button_down;
252
width_ ,height_ : int;
255
if flags and mouse_left <> 0 then
257
width_ :=rbuf_window._width;
258
height_:=rbuf_window._height;
260
transform(width_ ,height_ ,x ,y );
265
if flags and mouse_right <> 0 then
277
procedure the_application.on_key;
281
'The example demonstrates my new algorithm of drawing Anti-Aliased lines. '#13 +
282
'The algorithm works about 2.5 times faster than the scanline rasterizer '#13 +
283
'but has some restrictions, particularly, line joins can be only of the '#13 +
284
'"miter" type, and when so called miter limit is exceded, they are not as '#13 +
285
'accurate as generated by the stroke converter (conv_stroke).'#13#13 +
286
'How to play with:'#13#13 +
287
'To see the difference, maximize the window and try to rotate and scale '#13 +
288
'the "lion" with and without using the scanline rasterizer (a checkbox '#13 +
289
'at the bottom). The difference in performance is obvious.' +
290
#13#13'Note: F2 key saves current "screenshot" file in this demo''s directory. ' );
295
app : the_application;
299
g_rasterizer.Construct;
300
g_scanline.Construct;
321
app.Construct(pix_format ,flip_y );
322
app.caption_ ('AGG Example. Lion (F1-Help)' );
324
if app.init(512 ,512 ,window_resize ) then
330
g_rasterizer.Destruct;
b'\\ No newline at end of file'