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
15
agg_platform_support ,
20
agg_rendering_buffer ,
21
agg_rasterizer_scanline_aa ,
27
agg_renderer_scanline ,
33
agg_span_interpolator_linear ,
34
agg_rasterizer_outline_aa ,
35
agg_rendering_buffer_dynarow ,
40
agg_render_scanlines ,
50
g_rasterizer : rasterizer_scanline_aa;
52
g_scanline : scanline_u8;
54
g_path : path_storage;
56
g_npaths : unsigned = 0;
63
g_base_dx : double = 0;
64
g_base_dy : double = 0;
66
g_scale : double = 1.0;
68
g_skew_x : double = 0;
69
g_skew_y : double = 0;
73
g_cx ,g_cy ,g_dx ,g_dy ,g_radius : array[0..999 ] of double;
75
g_color1 ,g_color2 ,g_color3 : array[0..999 ] of aggclr;
77
g_gradients : array[0..999 ] of pod_auto_array;
81
g_center : double = 0;
85
g_cache : array[0..999 ] of rendering_buffer_dynarow_ptr;
88
gradient_tricolor = object(array_base )
96
constructor Construct(c1 ,c2 ,c3 : aggclr );
98
function size : unsigned; virtual;
99
function array_operator(i : unsigned ) : pointer; virtual;
101
procedure colors(c1 ,c2 ,c3 : aggclr );
105
the_application = object(platform_support )
108
m_speed : slider_ctrl;
114
m_first_time : boolean;
117
m_speed_value : double;
120
constructor Construct(format_ : pix_format_e; flip_y_ : boolean );
123
procedure on_init; virtual;
124
procedure on_draw; virtual;
126
procedure on_mouse_button_down(x ,y : int; flags : unsigned ); virtual;
127
procedure on_mouse_move (x ,y : int; flags : unsigned ); virtual;
129
procedure on_key(x ,y : int; key ,flags : unsigned ); virtual;
130
procedure on_idle; virtual;
131
procedure on_ctrl_change; virtual;
136
constructor gradient_tricolor.Construct(c1 ,c2 ,c3 : aggclr );
145
function gradient_tricolor.size : unsigned;
152
function gradient_tricolor.array_operator(i : unsigned ) : pointer;
158
m_rc.r:=int8u((((m_c2.r - m_c1.r ) * int(i ) ) + (m_c1.r shl 8 ) ) shr 8 );
159
m_rc.g:=int8u((((m_c2.g - m_c1.g ) * int(i ) ) + (m_c1.g shl 8 ) ) shr 8 );
160
m_rc.b:=int8u((((m_c2.b - m_c1.b ) * int(i ) ) + (m_c1.b shl 8 ) ) shr 8 );
161
m_rc.a:=int8u((((m_c2.a - m_c1.a ) * int(i ) ) + (m_c1.a shl 8 ) ) shr 8 );
168
m_rc.r:=int8u((((m_c3.r - m_c2.r ) * int(i ) ) + (m_c2.r shl 8 ) ) shr 8 );
169
m_rc.g:=int8u((((m_c3.g - m_c2.g ) * int(i ) ) + (m_c2.g shl 8 ) ) shr 8 );
170
m_rc.b:=int8u((((m_c3.b - m_c2.b ) * int(i ) ) + (m_c2.b shl 8 ) ) shr 8 );
171
m_rc.a:=int8u((((m_c3.a - m_c2.a ) * int(i ) ) + (m_c2.a shl 8 ) ) shr 8 );
180
procedure gradient_tricolor.colors(c1 ,c2 ,c3 : aggclr );
189
constructor the_application.Construct;
195
inherited Construct(format_ ,flip_y_ );
197
m_particles.Construct(5 ,5 ,300 ,12 ,not flip_y_ );
198
m_speed.Construct (5 ,5 + 15 ,300 ,12 + 15 ,not flip_y_ );
199
m_use_cache.Construct(320 ,5 ,'Use Bitmap Cache' ,not flip_y_ );
200
m_run.Construct (320 ,5 + 15 ,'Start the Universe!' ,not flip_y_ );
203
m_use_cache_flag:=false;
211
g_gradients[i ].Construct(256 ,sizeof(aggclr ) );
217
add_ctrl(@m_particles );
219
m_particles.range_(10 ,1000 );
220
m_particles.value_(200 );
221
m_particles.label_('Number of Particles=%.0f' );
222
m_particles.no_transform;
224
m_particles_value:=m_particles._value;
228
m_speed.range_(0.025 ,2.0 );
229
m_speed.value_(1.0 );
230
m_speed.label_('Dark Energy=%.3f' );
231
m_speed.no_transform;
233
m_speed_value:=m_speed._value;
236
add_ctrl(@m_use_cache );
238
c.ConstrDbl (1 ,1 ,1 );
239
m_use_cache.text_color_ (@c );
240
c.ConstrDbl (1 ,1 ,1 );
241
m_use_cache.inactive_color_(@c );
242
c.ConstrDbl (0.8 ,0 ,0 );
243
m_use_cache.active_color_ (@c );
245
m_use_cache.no_transform;
249
c.ConstrDbl (1 ,1 ,1 );
250
m_run.text_color_ (@c );
251
c.ConstrDbl (1 ,1 ,1 );
252
m_run.inactive_color_(@c );
253
c.ConstrDbl (0.8 ,0 ,0 );
254
m_run.active_color_ (@c );
257
m_run.status_(true );
262
destructor the_application.Destruct;
269
m_particles.Destruct;
271
m_use_cache.Destruct;
278
if g_cache[i ] <> NIL then
279
dispose(g_cache[i ] ,Destruct );
281
g_gradients[i ].Destruct;
290
procedure render_particle(ren : renderer_base_ptr; i : unsigned; x ,y : double );
293
grf : gradient_circle;
298
rg : renderer_scanline_aa;
300
inter : span_interpolator_linear;
304
tas : trans_affine_scaling;
305
tat : trans_affine_translation;
312
inter.Construct(@grm );
313
sg.Construct (@sa ,@inter ,@grf ,@g_gradients[i ] ,0 ,10 );
314
rg.Construct (ren ,@sg );
319
tas.Construct(r / 10.0 );
320
grm.multiply (@tas );
321
tat.Construct(x ,y );
322
grm.multiply (@tat );
325
ell.init(x ,y ,r ,r ,32 );
327
g_rasterizer.add_path(@ell );
329
render_scanlines(@g_rasterizer ,@g_scanline ,@rg );
337
procedure the_application.on_init;
339
n ,i ,j ,d : unsigned;
343
divisor ,angle ,speed ,k : double;
345
grc : gradient_tricolor;
347
gr : pod_auto_array_ptr;
349
pixf : pixel_formats;
353
n:=Trunc(m_particles._value );
357
if m_use_cache._status then
368
g_cx[i ]:=_width / 2 {$IFDEF DISORDER } + rand mod 10 - 5 {$ENDIF };
369
g_cy[i ]:=_height / 2 {$IFDEF DISORDER } + rand mod 10 - 5 {$ENDIF };
372
if rand and 1 <> 0 then
373
g_dx[i ]:=(rand mod 5000 + 1000 ) / divisor
375
g_dx[i ]:=-(rand mod 5000 + 1000 ) / divisor;
379
if rand and 1 <> 0 then
383
angle:=(rand mod 10000 ) / 10000.0 * (2.0 / 8.0 ) * pi;
385
angle:=angle + 2.0 * pi * da / 4.0 + (pi / 10.0 );
388
angle:=(rand mod 10000 ) / 10000.0 * 2.0 * pi;
392
speed:=((rand mod 10000 ) mod 5000 + 1000.0 ) / divisor;
394
g_dx[i ]:=Cos(angle ) * speed;
395
g_dy[i ]:=Sin(angle ) * speed;
399
g_radius[i ]:=(rand mod 30 + 15 ) * k;
401
g_color1[i ].ConstrInt(rand and $FF ,rand and $FF ,rand and $FF ,0 );
402
g_color2[i ].ConstrInt(rand and $FF ,rand and $FF ,rand and $FF ,255 );
404
component:=rand mod 3;
406
if component = 0 then
409
if component = 1 then
412
if component = 2 then
416
g_color1[i ] :=g_color2[i ];
421
g_color3[i ].ConstrInt(rand and $FF ,rand and $FF ,rand and $FF ,0 );
423
grc.Construct(g_color1[i ] ,g_color2[i ] ,g_color3[i ] );
425
gr:=@g_gradients[i ];
431
grc.array_operator(j )^ ,
432
gr.array_operator(j )^ ,
447
if m_use_cache._status then
453
if g_cache[i ] <> NIL then
454
dispose(g_cache[i ] ,Destruct );
466
d:=Trunc(g_radius[i ] ) * 2;
468
new(g_cache[i ] ,Construct(d ,d ,d * 4 ) );
470
pixfmt_alpha_blend_rgba(pixf ,g_cache[i ] ,bgra_order );
472
ren.Construct(@pixf );
474
render_particle(@ren ,i ,d / 2 ,d / 2 );
485
procedure the_application.on_draw;
489
width ,height ,x ,y : int;
491
pf ,pf_pre ,pixf : pixel_formats;
493
r ,r_pre : renderer_base;
495
rs : renderer_scanline_aa_solid;
502
buf : array[0..63 ] of char;
508
width :=rbuf_window._width;
509
height:=rbuf_window._height;
511
// Initialize structures
512
pixfmt_bgra32(pf ,rbuf_window );
517
g_rasterizer.clip_box(0 ,0 ,width ,height );
519
rgba.ConstrDbl(0 ,0 ,0 );
523
if m_run._status then
527
n:=Trunc(m_particles._value );
529
if m_use_cache._status then
531
pixfmt_bgra32_pre(pf_pre ,rbuf_window );
532
r_pre.Construct (@pf_pre );
538
if g_cache[i ] <> NIL then
540
pixfmt_alpha_blend_rgba(pixf ,g_cache[i ] ,bgra_order );
542
x:=Trunc(g_cx[i ] - g_radius[i ] ) + 1;
543
y:=Trunc(g_cy[i ] - g_radius[i ] ) + 1;
545
r_pre.blend_from(@pixf ,0 ,x ,y ,255 );
560
render_particle(@r ,i ,g_cx[i ] ,g_cy[i ] );
576
sprintf(@buf[0 ] ,'%6.1f fps' ,1000.0 / tm );
578
t.start_point_(10.0 ,35.0 );
581
g_rasterizer.add_path(@pt );
583
rgba.ConstrDbl(1 ,1 ,1 );
586
render_scanlines(@g_rasterizer ,@g_scanline ,@rs );
593
// Render the controls
594
render_ctrl(@g_rasterizer ,@g_scanline ,@rs ,@m_particles );
595
render_ctrl(@g_rasterizer ,@g_scanline ,@rs ,@m_speed );
596
render_ctrl(@g_rasterizer ,@g_scanline ,@rs ,@m_use_cache );
597
render_ctrl(@g_rasterizer ,@g_scanline ,@rs ,@m_run );
601
{ ON_MOUSE_BUTTON_DOWN }
602
procedure the_application.on_mouse_button_down;
604
if (flags and mouse_left <> 0 ) or
605
(flags and mouse_right <> 0 ) then
611
procedure the_application.on_mouse_move;
613
on_mouse_button_down(x ,y ,flags );
618
procedure the_application.on_key;
622
'Demonstration of using the bitmap cache.'#13#13 +
623
'Cached bitmaps are descended from AGG renderer_base '#13 +
624
'and on_draw method just alpha blended to the scene.' );
629
procedure the_application.on_idle;
633
x1 ,y1 ,x2 ,y2 ,dx ,dy ,cx ,cy ,max_dist ,d : double;
636
n:=Trunc(m_particles._value );
642
dx:=Cos(g_angle ) * g_center;
643
dy:=Sin(g_angle ) * g_center;
645
cy:=dy + _height / 2;
647
max_dist:=Sqrt(_width * _width / 2 + _height * _height / 2 );
649
g_angle :=g_angle + 5.0 * pi / 180.0;
650
g_center:=g_center + g_dc;
652
if g_center > max_dist / 2 then
654
g_center:=max_dist / 2;
659
if g_center < 10.0 then
670
g_cx[i ]:=g_cx[i ] + g_dx[i ] * m_speed._value;
671
g_cy[i ]:=g_cy[i ] + g_dy[i ] * m_speed._value;
673
d:=calc_distance(g_cx[i ] ,g_cy[i ] ,cx ,cy );
684
if g_cx[i ] < x1 then
691
if g_cx[i ] > x2 then
698
if g_cy[i ] < y1 then
705
if g_cy[i ] > y2 then
713
if g_cx[i ] < x1 then
720
if g_cx[i ] > x2 then
727
if g_cy[i ] < y1 then
734
if g_cy[i ] > y2 then
753
procedure the_application.on_ctrl_change;
755
stop ,over : boolean;
758
if m_run_flag <> m_run._status then
760
wait_mode_(not m_run._status );
762
m_run_flag:=m_run._status;
778
if m_use_cache._status <> m_use_cache_flag then
780
m_use_cache_flag:=m_use_cache._status;
787
if m_particles._value <> m_particles_value then
789
m_particles_value:=m_particles._value;
796
if m_speed._value <> m_speed_value then
798
m_speed_value:=m_speed._value;
808
m_run.status_(false );
820
app : the_application;
823
app.Construct(pix_format_bgra32 ,flip_y );
824
app.caption_ ('Renesis project -- Particles demo. (F1-Help)' );
826
g_scanline.Construct;
827
g_rasterizer.Construct;
830
if app.init(600 ,500 ,window_resize ) then
832
app.wait_mode_(false );
837
g_rasterizer.Destruct;
b'\\ No newline at end of file'