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
14
agg_platform_support ,
20
agg_rendering_buffer ,
22
agg_renderer_scanline ,
23
agg_rasterizer_scanline_aa ,
27
agg_render_scanlines ,
43
g_path : path_storage;
44
g_colors : array[0..99 ] of aggclr;
45
g_path_idx : array[0..99 ] of unsigned;
49
g_x1 ,g_y1 ,g_x2 ,g_y2 ,
50
g_base_dx ,g_base_dy ,
52
g_skew_x ,g_skew_y : double;
56
g_alpha_mask_rbuf : rendering_buffer;
57
g_alpha_mask : alpha_mask_gray8;
58
g_rasterizer : rasterizer_scanline_aa;
61
the_application = object(platform_support )
62
m_alpha_size : unsigned;
63
m_alpha_buf : char_ptr;
64
m_alpha_rbuf : rendering_buffer;
66
constructor Construct(format_ : pix_format_e; flip_y_ : boolean );
69
procedure generate_alpha_mask(cx ,cy : int );
71
procedure on_resize(sx ,sy : int ); virtual;
72
procedure on_draw; virtual;
74
procedure transform(width_ ,height_ ,x ,y : double );
76
procedure on_mouse_move (x ,y : int; flags : unsigned ); virtual;
77
procedure on_mouse_button_down(x ,y : int; flags : unsigned ); virtual;
79
procedure on_key(x ,y : int; key ,flags : unsigned ); virtual;
84
procedure _parse_lion_;
86
g_npaths:=parse_lion(@g_path ,@g_colors ,@g_path_idx );
88
bounding_rect(@g_path ,@g_path_idx ,0 ,g_npaths ,@g_x1 ,@g_y1 ,@g_x2 ,@g_y2 );
90
g_base_dx:=(g_x2 - g_x1 ) / 2.0;
91
g_base_dy:=(g_y2 - g_y1 ) / 2.0;
96
constructor the_application.Construct;
98
inherited Construct(format_ ,flip_y_ );
108
destructor the_application.Destruct;
112
agg_freemem(pointer(m_alpha_buf ) ,m_alpha_size );
116
{ GENERATE_ALPHA_MASK }
117
procedure the_application.generate_alpha_mask;
119
pixf : pixel_formats;
123
r : renderer_scanline_aa_solid;
131
agg_freemem(pointer(m_alpha_buf ) ,m_alpha_size );
133
m_alpha_size:=cx * cy;
135
agg_getmem(pointer(m_alpha_buf ) ,m_alpha_size );
137
g_alpha_mask_rbuf.attach(int8u_ptr(m_alpha_buf ) ,cx ,cy ,cx );
139
pixfmt_gray8(pixf ,@g_alpha_mask_rbuf );
140
rb.Construct(@pixf );
152
Random($7fff ) mod cx ,
153
Random($7fff ) mod cy ,
154
Random($7fff ) mod 100 + 20 ,
155
Random($7fff ) mod 100 + 20 ,100 );
157
g_rasterizer.add_path(@ell );
159
rgba.ConstrInt(Random($7fff ) and $FF ,Random($7fff ) and $FF );
162
render_scanlines(@g_rasterizer ,@sl ,@r );
171
procedure the_application.on_resize;
173
generate_alpha_mask(sx ,sy );
178
procedure the_application.on_draw;
180
width_ ,height_ : int;
182
pixf : pixel_formats;
185
r : renderer_scanline_aa_solid;
189
trans : conv_transform;
192
tat : trans_affine_translation;
193
tas : trans_affine_scaling;
194
tar : trans_affine_rotation;
195
taw : trans_affine_skewing;
198
width_ :=rbuf_window._width;
199
height_:=rbuf_window._height;
201
// Initialize structures
202
pixfmt_bgr24(pixf ,rbuf_window );
204
rb.Construct(@pixf );
206
sl.Construct(@g_alpha_mask );
208
rgba.ConstrInt(255 ,255 ,255 );
214
tat.Construct(-g_base_dx ,-g_base_dy );
215
mtx.multiply (@tat );
217
tas.Construct(g_scale ,g_scale );
218
mtx.multiply (@tas );
220
tar.Construct(g_angle + pi );
221
mtx.multiply (@tar );
223
taw.Construct(g_skew_x / 1000.0 ,g_skew_y / 1000.0 );
224
mtx.multiply (@taw );
226
tat.Construct(width_ / 2 ,height_ / 2 );
227
mtx.multiply (@tat );
229
// This code renders the lion
230
trans.Construct(@g_path ,@mtx );
232
render_all_paths(@g_rasterizer ,@sl ,@r ,@trans ,@g_colors ,@g_path_idx ,g_npaths );
234
// Free AGG resources
240
procedure the_application.transform;
245
g_angle:=ArcTan2(y ,x );
246
g_scale:=Sqrt(y * y + x * x ) / 100.0;
251
procedure the_application.on_mouse_move;
253
on_mouse_button_down(x ,y ,flags );
257
{ ON_MOUSE_BUTTON_DOWN }
258
procedure the_application.on_mouse_button_down;
260
width_ ,height_ : int;
263
if flags and mouse_left <> 0 then
265
width_ :=rbuf_window._width;
266
height_:=rbuf_window._height;
268
transform(width_ ,height_ ,x ,y );
274
if flags and mouse_right <> 0 then
286
procedure the_application.on_key;
290
'Alpha-mask is a simple method of clipping and masking polygons to a number'#13 +
291
'of other arbitrary polygons. Alpha mask is a buffer that is mixed to the '#13 +
292
'scanline container and controls the Anti-Aliasing values in it. It''s not the '#13 +
293
'perfect mechanism of clipping, but it allows you not only to clip the polygons, '#13 +
294
'but also to change the opacity in certain areas, i.e., the clipping can be '#13 +
295
'translucent. '#13#13 +
296
'How to play with:'#13#13 +
297
'Press and drag the left mouse button to scale and rotate the lion.'#13 +
298
'Resize the window to generate new alpha-mask.'#13 +
299
'Use the right mouse button to skew the lion.' +
300
#13#13'Note: F2 key saves current "screenshot" file in this demo''s directory. ' );
305
app : the_application;
328
g_alpha_mask_rbuf.Construct;
329
g_alpha_mask.Construct(@g_alpha_mask_rbuf );
330
g_rasterizer.Construct;
333
app.Construct(pix_format_bgr24 ,flip_y );
334
app.caption_ ('AGG Example. Lion with Alpha-Masking (F1-Help)' );
336
if app.init(512 ,400 ,window_resize ) then
343
g_alpha_mask_rbuf.Destruct;
344
g_rasterizer.Destruct;
b'\\ No newline at end of file'