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
22
agg_platform_support ,
27
agg_rasterizer_scanline_aa ,
32
agg_renderer_scanline ,
33
agg_render_scanlines ,
38
agg_trans_warp_magnifier ,
40
agg_conv_segmentator ,
43
{$I pixel_formats.inc }
50
g_rasterizer : rasterizer_scanline_aa;
51
g_scanline : scanline_p8;
53
g_path : path_storage;
54
g_colors : array[0..99 ] of aggclr;
55
g_path_idx : array[0..99 ] of unsigned;
59
g_x1 ,g_y1 ,g_x2 ,g_y2 ,
60
g_base_dx ,g_base_dy ,
62
g_skew_x ,g_skew_y : double;
67
the_application = object(platform_support )
69
m_radius_slider : slider_ctrl;
71
constructor Construct(format_ : pix_format_e; flip_y_ : boolean );
74
procedure on_init; virtual;
75
procedure on_draw; virtual;
77
procedure on_mouse_move (x ,y : int; flags : unsigned ); virtual;
78
procedure on_mouse_button_down(x ,y : int; flags : unsigned ); virtual;
80
procedure on_key(x ,y : int; key ,flags : unsigned ); virtual;
85
procedure _parse_lion_;
87
g_npaths:=parse_lion(@g_path ,@g_colors ,@g_path_idx );
89
bounding_rect(@g_path ,@g_path_idx ,0 ,g_npaths ,@g_x1 ,@g_y1 ,@g_x2 ,@g_y2 );
91
g_base_dx:=(g_x2 - g_x1 ) / 2.0;
92
g_base_dy:=(g_y2 - g_y1 ) / 2.0;
97
constructor the_application.Construct;
99
inherited Construct(format_ ,flip_y_ );
101
m_magn_slider.Construct (5 ,5 ,495 ,12 ,not flip_y_ );
102
m_radius_slider.Construct(5 ,20 ,495 ,27 ,not flip_y_ );
106
add_ctrl(@m_magn_slider );
108
m_magn_slider.no_transform;
109
m_magn_slider.range_(0.01 ,4.0 );
110
m_magn_slider.value_(3.0 );
111
m_magn_slider.label_('Scale=%3.2f' );
113
add_ctrl(@m_radius_slider );
115
m_radius_slider.no_transform;
116
m_radius_slider.range_(0.0 ,100.0 );
117
m_radius_slider.value_(70.0 );
118
m_radius_slider.label_('Radius=%3.2f' );
123
destructor the_application.Destruct;
127
m_magn_slider.Destruct;
128
m_radius_slider.Destruct;
133
procedure the_application.on_init;
141
procedure the_application.on_draw;
143
pixf : pixel_formats;
146
r : renderer_scanline_aa_solid;
150
lens : trans_warp_magnifier;
151
segm : conv_segmentator;
154
tat : trans_affine_translation;
155
tar : trans_affine_rotation;
158
trans_lens : conv_transform;
161
// Initialize structures
162
pixfmt(pixf ,rbuf_window );
164
rb.Construct(@pixf );
167
rgba.ConstrDbl(1 ,1 ,1 );
172
lens.center (g_x1 ,g_y1 );
173
lens.magnification(m_magn_slider._value );
174
lens.radius (m_radius_slider._value / m_magn_slider._value );
176
segm.Construct(@g_path );
179
tat.Construct(-g_base_dx ,-g_base_dy );
180
mtx.multiply (@tat );
182
tar.Construct(g_angle + pi );
183
mtx.multiply (@tar );
185
tat.Construct(_width / 2 ,_height / 2);
186
mtx.multiply (@tat );
188
trans_mtx.Construct (@segm ,@mtx );
189
trans_lens.Construct(@trans_mtx ,@lens );
191
render_all_paths(@g_rasterizer ,@g_scanline ,@r ,@trans_lens ,@g_colors ,@g_path_idx ,g_npaths );
193
// Render the controls
194
render_ctrl(@g_rasterizer ,@g_scanline ,@r ,@m_magn_slider );
195
render_ctrl(@g_rasterizer ,@g_scanline ,@r ,@m_radius_slider );
203
procedure the_application.on_mouse_move;
205
on_mouse_button_down(x ,y ,flags );
209
{ ON_MOUSE_BUTTON_DOWN }
210
procedure the_application.on_mouse_button_down;
212
if flags and mouse_left <> 0 then
221
if flags and mouse_right <> 0 then
233
procedure the_application.on_key;
237
'This example exhibits a non-linear transformer that "magnifies" vertices that fall '#13 +
238
'inside a circle and extends the rest (trans_warp_magnifier). Non-linear transformations '#13 +
239
'are tricky because straight lines become curves. To achieve the correct result we need '#13 +
240
'to divide long line segments into short ones. The example also demonstrates the use of '#13 +
241
'conv_segmentator that does this division job. The transformer can also shrink away '#13 +
242
'the image if the scaling value is less than 1.'#13#13 +
243
'How to play with:'#13#13 +
244
'Drag the center of the "lens" with the left mouse button and change the "Scale" and "Radius". '#13 +
245
'To watch for an amazing effect, set the scale to the minimum (0.01), decrease the radius '#13 +
246
'to about 1 and drag the "lens". You will see it behaves like a black hole consuming space '#13 +
247
'around it. Move the lens somewhere to the side of the window and change the radius. It looks '#13 +
248
'like changing the event horizon of the "black hole".' +
249
#13#13'Note: F2 key saves current "screenshot" file in this demo''s directory. ' );
254
app : the_application;
258
g_rasterizer.Construct;
259
g_scanline.Construct;
280
app.Construct(pix_format ,flip_y );
281
app.caption_ ('AGG Example. Lion (F1-Help)' );
283
if app.init(500 ,600 ,window_resize ) then
289
g_rasterizer.Destruct;
b'\\ No newline at end of file'