1{mac_copy:spheres2.bmp} 2// 3// AggPas 2.4 RM3 Demo application 4// Note: Press F1 key on run to see more info about this demo 5// 6// Paths: src;src\ctrl;src\svg;src\util;src\platform\win;expat-wrap 7// 8program 9 Agg2DDemo ; 10 11uses 12 SysUtils , 13 agg_basics , 14 agg_platform_support , 15 file_utils_ , 16 agg_2D ; 17 18{$I agg_mode.inc } 19 20const 21 flip_y = true; 22 angle_step = 5; 23 gamma_step = 0.1; 24 25var 26 FONT_TIMES : AnsiString = 'Times New Roman'; 27 FONT_ARIAL : AnsiString = 'Arial'; 28 FONT_VERDA : AnsiString = 'Verdana'; 29 30type 31 the_application = object(platform_support ) 32 m_graphics , 33 m_timer : Agg2D; 34 m_angle , 35 m_gamma : double; 36 m_image : int; 37 m_gmText : AnsiString; 38 39 constructor Construct(format_ : pix_format_e; flip_y_ : boolean ); 40 destructor Destruct; 41 42 procedure on_init; virtual; 43 procedure on_draw; virtual; 44 45 procedure on_mouse_move(x ,y : int; flags : unsigned ); virtual; 46 47 procedure on_mouse_button_down(x ,y : int; flags : unsigned ); virtual; 48 procedure on_mouse_button_up (x ,y : int; flags : unsigned ); virtual; 49 50 procedure on_key(x ,y : int; key ,flags : unsigned ); virtual; 51 52 end; 53 54{ CONSTRUCT } 55constructor the_application.Construct; 56begin 57 inherited Construct(format_ ,flip_y_ ); 58 59 m_graphics.Construct; 60 m_timer.Construct; 61 62 m_angle:=0; 63 m_gamma:=1.4; 64 m_image:=6; 65 66 Str(m_gamma:0:2 ,m_gmText ); m_gmText:='Gamma: ' + m_gmText; 67 68end; 69 70{ DESTRUCT } 71destructor the_application.Destruct; 72begin 73 inherited Destruct; 74 75 m_graphics.Destruct; 76 m_timer.Destruct; 77 78 Finalize(m_gmText ); 79 80end; 81 82{ ON_INIT } 83procedure the_application.on_init; 84begin 85end; 86 87{ ON_DRAW } 88procedure the_application.on_draw; 89var 90 xb1 ,yb1 ,xb2 ,yb2 : double; 91 92 clr ,c1 ,c2 ,c3 : Color; 93 94 img : Image; 95 96 parl : array[0..5 ] of double; 97 poly : array[0..11 ] of double; 98 99 tm : double; 100 fps : int; 101 102 timer ,rate : AnsiString; 103 104begin 105 start_timer; 106 107 m_graphics.attach( 108 rbuf_window._buf , 109 rbuf_window._width , 110 rbuf_window._height , 111 rbuf_window._stride ); 112 113 m_graphics.clearAll(255 ,255 ,255 ); 114 115 //m_graphics.clearAll(0 ,0 ,0 ); 116 117 //m_graphics.blendMode(BlendSub ); 118 //m_graphics.blendMode(BlendAdd ); 119 120 m_graphics.antiAliasGamma(m_gamma ); 121 122// Set flipText(true) if you have the Y axis upside down. 123 m_graphics.flipText(not flip_y ); 124 125// ClipBox. 126 //m_graphics.clipBox(50 ,50 ,rbuf_window._width - 50 ,rbuf_window._height - 50 ); 127 128// Transfornations - Rotate around (300,300) to 5 degree 129 m_graphics.translate(-300 ,-300 ); 130 m_graphics.rotate (deg2Rad(m_angle ) ); 131 m_graphics.translate(300 ,300 ); 132 //m_graphics.skew (0.1 ,0.1 ); 133 134// Viewport - set 0,0,600,600 to the actual window size 135// preserving aspect ratio and placing the viewport in the center. 136// To ignore aspect ratio use Agg2D::Anisotropic 137// Note that the viewport just adds transformations to the current 138// affine matrix. So that, set the viewport *after* all transformations! 139 m_graphics.viewport( 140 0 ,0 ,600 ,600 , 141 0 ,0 ,_width ,_height , 142 //Anisotropic ); 143 XMidYMid ); 144 //XMinYMin ); 145 //XMidYMin ); 146 //XMaxYMin ); 147 //XMinYMid ); 148 //XMaxYMid ); 149 //XMinYMax ); 150 //XMidYMax ); 151 //XMaxYMax ); 152 153// Rounded Rect 154 m_graphics.lineColor(0 ,0 ,0 ); 155 m_graphics.noFill; 156 m_graphics.roundedRect(0.5 ,0.5 ,600 - 0.5 ,600 - 0.5 ,20.0 ); 157 158// Regular Text 159{ m_graphics.font(char_ptr(FONT_TIMES ) ,14.0 ,false ,false ); 160 m_graphics.fillColor(0 ,0 ,0 ); 161 m_graphics.noLine; 162 m_graphics.text(100 ,20 ,char_ptr(PChar('Regular Raster Text -- Fast, but can''t be rotated' ) ) );{} 163 164// Outlined Text 165 m_graphics.font(char_ptr(FONT_TIMES ) ,50.0 ,false ,false ,{RasterFontCache}VectorFontCache ); 166 m_graphics.lineColor(50 ,0 ,0 ); 167 m_graphics.fillColor(180 ,200 ,100 ); 168 m_graphics.lineWidth(1.0 ); 169 m_graphics.text(100.5 ,50.5 ,char_ptr(PChar('Outlined Text' ) ) ); 170 171// Gamma Text 172(* m_graphics.font(char_ptr(FONT_ARIAL ) ,38.0 ,true ,true ,VectorFontCache ); 173 174 c1.Construct (255 ,0 ,0 ,255 ); 175 c2.Construct (0 ,255 ,0 ,255 ); 176 m_graphics.fillLinearGradient(50 ,1 ,300 ,10 ,c1 ,c2 ); 177 178 m_graphics.noLine; 179 m_graphics.text(12.5 ,565.5 ,char_ptr(@m_gmText[1 ] ) ); 180 //m_graphics.rectangle(12.5 ,565.5 ,290 ,590 ); (**) 181 182// Text Alignment 183 m_graphics.lineColor(0 ,0 ,0 ); 184 m_graphics.line(250.5 - 150 ,150.5 ,250.5 + 150 ,150.5 ); 185 m_graphics.line(250.5 ,150.5 - 20 ,250.5 ,150.5 + 20 ); 186 m_graphics.line(250.5 - 150 ,200.5 ,250.5 + 150 ,200.5 ); 187 m_graphics.line(250.5 ,200.5 - 20 ,250.5 ,200.5 + 20 ); 188 m_graphics.line(250.5 - 150 ,250.5 ,250.5 + 150 ,250.5 ); 189 m_graphics.line(250.5 ,250.5 - 20 ,250.5 ,250.5 + 20 ); 190 m_graphics.line(250.5 - 150 ,300.5 ,250.5 + 150 ,300.5 ); 191 m_graphics.line(250.5 ,300.5 - 20 ,250.5 ,300.5 + 20 ); 192 m_graphics.line(250.5 - 150 ,350.5 ,250.5 + 150 ,350.5 ); 193 m_graphics.line(250.5 ,350.5 - 20 ,250.5 ,350.5 + 20 ); 194 m_graphics.line(250.5 - 150 ,400.5 ,250.5 + 150 ,400.5 ); 195 m_graphics.line(250.5 ,400.5 - 20 ,250.5 ,400.5 + 20 ); 196 m_graphics.line(250.5 - 150 ,450.5 ,250.5 + 150 ,450.5 ); 197 m_graphics.line(250.5 ,450.5 - 20 ,250.5 ,450.5 + 20 ); 198 m_graphics.line(250.5 - 150 ,500.5 ,250.5 + 150 ,500.5 ); 199 m_graphics.line(250.5 ,500.5 - 20 ,250.5 ,500.5 + 20 ); 200 m_graphics.line(250.5 - 150 ,550.5 ,250.5 + 150 ,550.5 ); 201 m_graphics.line(250.5 ,550.5 - 20 ,250.5 ,550.5 + 20 ); 202 203 m_graphics.fillColor(100 ,50 ,50 ); 204 m_graphics.noLine; 205 //m_graphics.textHints(false ); 206 m_graphics.font(char_ptr(FONT_TIMES ) ,40.0 ,false ,false ,VectorFontCache ); 207 208 m_graphics.textAlignment(AlignLeft ,AlignBottom ); 209 m_graphics.text(250.0 ,150.0 ,char_ptr(PChar('Left-Bottom' ) ) ,true ,0 ,0 ); 210 211 m_graphics.textAlignment(AlignCenter ,AlignBottom ); 212 m_graphics.text(250.0 ,200.0 ,char_ptr(PChar('Center-Bottom' ) ) ,true ,0 ,0 ); 213 214 m_graphics.textAlignment(AlignRight ,AlignBottom ); 215 m_graphics.text(250.0 ,250.0 ,char_ptr(PChar('Right-Bottom' ) ) ,true ,0 ,0 ); 216 217 m_graphics.textAlignment(AlignLeft ,AlignCenter ); 218 m_graphics.text(250.0 ,300.0 ,char_ptr(PChar('Left-Center' ) ) ,true ,0 ,0 ); 219 220 m_graphics.textAlignment(AlignCenter ,AlignCenter ); 221 m_graphics.text(250.0 ,350.0 ,char_ptr(PChar('Center-Center' ) ) ,true ,0 ,0 ); 222 223 m_graphics.textAlignment(AlignRight ,AlignCenter ); 224 m_graphics.text(250.0 ,400.0 ,char_ptr(PChar('Right-Center' ) ) ,true ,0 ,0 ); 225 226 m_graphics.textAlignment(AlignLeft ,AlignTop ); 227 m_graphics.text(250.0 ,450.0 ,char_ptr(PChar('Left-Top' ) ) ,true ,0 ,0 ); 228 229 m_graphics.textAlignment(AlignCenter ,AlignTop ); 230 m_graphics.text(250.0 ,500.0 ,char_ptr(PChar('Center-Top' ) ) ,true ,0 ,0 ); 231 232 m_graphics.textAlignment(AlignRight ,AlignTop ); 233 m_graphics.text(250.0 ,550.0 ,char_ptr(PChar('Right-Top' ) ) ,true ,0 ,0 ); 234 235// Gradients (Aqua Buttons) 236//======================================= 237 m_graphics.font(char_ptr(FONT_VERDA ) ,20.0 ,false ,false ,VectorFontCache ); 238 239 xb1:=400; 240 yb1:=80; 241 xb2:=xb1 + 150; 242 yb2:=yb1 + 36; 243 244 clr.Construct (0 ,50 ,180 ,180 ); 245 m_graphics.fillColor (clr ); 246 clr.Construct (0 ,0 ,80 ,255 ); 247 m_graphics.lineColor (clr ); 248 m_graphics.lineWidth (1.0); 249 m_graphics.roundedRect(xb1 ,yb1 ,xb2 ,yb2 ,12 ,18 ); 250 251 clr.Construct (0 ,0 ,0 ,0 ); 252 m_graphics.lineColor(clr ); 253 254 c1.Construct (100 ,200 ,255 ,255 ); 255 c2.Construct (255 ,255 ,255 ,0 ); 256 m_graphics.fillLinearGradient(xb1 ,yb1 ,xb1 ,yb1 + 30 ,c1 ,c2 ); 257 m_graphics.roundedRect (xb1 + 3 ,yb1 + 2.5 ,xb2 - 3 ,yb1 + 30 ,9 ,18 ,1 ,1 ); 258 259 clr.Construct (0 ,0 ,50 ,200 ); 260 m_graphics.fillColor(clr ); 261 m_graphics.noLine; 262 m_graphics.textAlignment(AlignCenter ,AlignCenter ); 263 m_graphics.text( 264 (xb1 + xb2 ) / 2.0 , 265 (yb1 + yb2 ) / 2.0 , 266 char_ptr(PChar('Aqua Button' ) ) , 267 true ,0.0 ,0.0 ); 268 269 c1.Construct(0 ,0 ,255 ,0 ); 270 c2.Construct(100 ,255 ,255 ,255 ); 271 m_graphics.fillLinearGradient(xb1 ,yb2 - 20 ,xb1 ,yb2 - 3 ,c1 ,c2 ); 272 m_graphics.roundedRect (xb1 + 3 ,yb2 - 20 ,xb2 - 3 ,yb2 - 2 ,1 ,1 ,9 ,18 ); 273 274// Aqua Button Pressed 275 xb1:=400; 276 yb1:=30; 277 xb2:=xb1 + 150; 278 yb2:=yb1 + 36; 279 280 clr.Construct (0 ,50 ,180 ,180 ); 281 m_graphics.fillColor (clr ); 282 clr.Construct (0 ,0 ,0 ,255 ); 283 m_graphics.lineColor (clr ); 284 m_graphics.lineWidth (2.0 ); 285 m_graphics.roundedRect(xb1 ,yb1 ,xb2 ,yb2 ,12 ,18 ); 286 287 clr.Construct (0 ,0 ,0 ,0 ); 288 m_graphics.lineColor(clr ); 289 290 c1.Construct (60 ,160 ,255 ,255 ); 291 c2.Construct (100 ,255 ,255 ,0 ); 292 m_graphics.fillLinearGradient(xb1 ,yb1 + 2 ,xb1 ,yb1 + 25 ,c1 ,c2 ); 293 m_graphics.roundedRect (xb1 + 3 ,yb1 + 2.5 ,xb2 - 3 ,yb1 + 30 ,9 ,18 ,1 ,1 ); 294 295 clr.Construct (0 ,0 ,50 ,255 ); 296 m_graphics.fillColor(clr ); 297 m_graphics.noLine; 298 m_graphics.textAlignment(AlignCenter ,AlignCenter ); 299 m_graphics.text( 300 (xb1 + xb2 ) / 2.0 , 301 (yb1 + yb2 ) / 2.0 , 302 char_ptr(PChar('Aqua Pressed' ) ) , 303 false ,0.0 ); 304 305 c1.Construct (0 ,180 ,255 ,0 ); 306 c2.Construct (0 ,200 ,255 ,255 ); 307 m_graphics.fillLinearGradient(xb1 ,yb2 - 25 ,xb1 ,yb2 - 5 ,c1 ,c2 ); 308 m_graphics.roundedRect (xb1 + 3 ,yb2 - 25 ,xb2 - 3 ,yb2 - 2 ,1 ,1 ,9 ,18 ); 309 310// Basic Shapes -- Ellipse 311//=========================================== 312 m_graphics.lineWidth(3.5 ); 313 m_graphics.lineColor(20 ,80 ,80 ); 314 m_graphics.fillColor(200 ,255 ,80 ,200 ); 315 m_graphics.ellipse (450 ,200 ,50 ,90 ); 316 317// Paths 318//=========================================== 319 m_graphics.resetPath; 320 m_graphics.fillColor (255 ,0 ,0 ,100 ); 321 m_graphics.lineColor (0 ,0 ,255 ,100 ); 322 m_graphics.lineWidth (2 ); 323 m_graphics.moveTo (300 / 2 ,200 / 2 ); 324 m_graphics.horLineRel(-150 / 2 ); 325 m_graphics.arcRel (150 / 2 ,150 / 2 ,0 ,true ,false ,150 / 2 ,-150 / 2 ); 326 m_graphics.closePolygon; 327 m_graphics.drawPath; 328 329 m_graphics.resetPath; 330 m_graphics.fillColor (255 ,255 ,0 ,100 ); 331 m_graphics.lineColor (0 ,0 ,255 ,100 ); 332 m_graphics.lineWidth (2 ); 333 m_graphics.moveTo (275 / 2 ,175 / 2 ); 334 m_graphics.verLineRel(-150 / 2 ); 335 m_graphics.arcRel (150 / 2 ,150 / 2 ,0 ,false ,false ,-150 / 2 ,150 / 2 ); 336 m_graphics.closePolygon; 337 m_graphics.drawPath; 338 339 m_graphics.resetPath; 340 m_graphics.noFill; 341 m_graphics.lineColor(127 ,0 ,0 ); 342 m_graphics.lineWidth(5 ); 343 m_graphics.moveTo (600 / 2 ,350 / 2 ); 344 m_graphics.lineRel (50 / 2 ,-25 / 2 ); 345 m_graphics.arcRel (25 / 2 ,25 / 2 ,deg2Rad(-30 ) ,false ,true ,50 / 2 ,-25 / 2 ); 346 m_graphics.lineRel (50 / 2 ,-25 / 2); 347 m_graphics.arcRel (25 / 2 ,50 / 2 ,deg2Rad(-30 ) ,false ,true ,50 / 2 ,-25 / 2 ); 348 m_graphics.lineRel (50 / 2 ,-25 / 2 ); 349 m_graphics.arcRel (25 / 2 ,75 / 2 ,deg2Rad(-30 ) ,false ,true ,50 / 2 ,-25 / 2 ); 350 m_graphics.lineRel (50 ,-25 ); 351 m_graphics.arcRel (25 / 2 ,100 / 2 ,deg2Rad(-30 ) ,false ,true ,50 / 2 ,-25 / 2 ); 352 m_graphics.lineRel (50 / 2 ,-25 / 2 ); 353 m_graphics.drawPath; 354 355// Master Alpha. From now on everything will be translucent 356//=========================================== 357 m_graphics.masterAlpha(0.85 ); 358 359// Image Transformations 360//=========================================== 361 img.Construct( 362 rbuf_img(0 )._buf , 363 rbuf_img(0 )._width , 364 rbuf_img(0 )._height , 365 rbuf_img(0 )._stride ); 366 367 m_graphics.imageFilter(Bilinear ); 368 369 //m_graphics.imageResample(NoResample ); 370 //m_graphics.imageResample(ResampleAlways ); 371 m_graphics.imageResample(ResampleOnZoomOut ); 372 373// Set the initial image blending operation as BlendDst, that actually 374// does nothing. 375//----------------- 376 m_graphics.imageBlendMode(BlendDst ); 377 378// Transform the whole image to the destination rectangle 379//----------------- 380 if m_image = 1 then 381 m_graphics.transformImage(@img ,450 ,200 ,595 ,350 );{1} 382 383// Transform the rectangular part of the image to the destination rectangle 384//----------------- 385 if m_image = 2 then 386 m_graphics.transformImage( 387 @img ,60 ,60 ,img.width - 60 ,img.height - 60 , 388 450 ,200 ,595 ,350 );{2} 389 390// Transform the whole image to the destination parallelogram 391//----------------- 392 if m_image = 3 then 393 begin 394 parl[0 ]:=450; 395 parl[1 ]:=200; 396 parl[2 ]:=595; 397 parl[3 ]:=220; 398 parl[4 ]:=575; 399 parl[5 ]:=350; 400 401 m_graphics.transformImage(@img ,@parl[0 ] );{3} 402 403 end; 404 405// Transform the rectangular part of the image to the destination parallelogram 406//----------------- 407 if m_image = 4 then 408 begin 409 parl[0 ]:=450; 410 parl[1 ]:=200; 411 parl[2 ]:=595; 412 parl[3 ]:=220; 413 parl[4 ]:=575; 414 parl[5 ]:=350; 415 416 m_graphics.transformImage(@img ,60 ,60 ,img.width - 60 ,img.height - 60 ,@parl[0 ] );{4} 417 418 end; 419 420// Transform image to the destination path. The scale is determined by a rectangle 421//----------------- 422 if m_image = 5 then 423 begin 424 m_graphics.resetPath; 425 m_graphics.moveTo (450 ,200 ); 426 m_graphics.cubicCurveTo (595 ,220 ,575 ,350 ,595 ,350 ); 427 m_graphics.lineTo (470 ,340 ); 428 m_graphics.transformImagePath(@img ,450 ,200 ,595 ,350 );{5} 429 430 end; 431 432// Transform image to the destination path. 433// The scale is determined by a rectangle 434//----------------- 435 if m_image = 6 then 436 begin 437 m_graphics.resetPath; 438 m_graphics.moveTo (450 ,200 ); 439 m_graphics.cubicCurveTo(595 ,220 ,575 ,350 ,595 ,350 ); 440 m_graphics.lineTo (470 ,340 ); 441 m_graphics.transformImagePath( 442 @img ,60 ,60 ,img.width - 60 ,img.height - 60 , 443 450 ,200 ,595 ,350 );{6} 444 445 end; 446 447// Transform image to the destination path. 448// The transformation is determined by a parallelogram 449 if m_image = 7 then 450 begin 451 m_graphics.resetPath; 452 m_graphics.moveTo (450 ,200 ); 453 m_graphics.cubicCurveTo(595 ,220 ,575 ,350 ,595 ,350 ); 454 m_graphics.lineTo (470 ,340 ); 455 456 parl[0 ]:=450; 457 parl[1 ]:=200; 458 parl[2 ]:=595; 459 parl[3 ]:=220; 460 parl[4 ]:=575; 461 parl[5 ]:=350; 462 463 m_graphics.transformImagePath(@img ,@parl[0 ] );{7} 464 465 end; 466 467// Transform the rectangular part of the image to the destination path. 468// The transformation is determined by a parallelogram 469 if m_image = 8 then 470 begin 471 m_graphics.resetPath; 472 m_graphics.moveTo (450 ,200 ); 473 m_graphics.cubicCurveTo(595 ,220 ,575 ,350 ,595 ,350 ); 474 m_graphics.lineTo (470 ,340 ); 475 476 parl[0 ]:=450; 477 parl[1 ]:=200; 478 parl[2 ]:=595; 479 parl[3 ]:=220; 480 parl[4 ]:=575; 481 parl[5 ]:=350; 482 483 m_graphics.transformImagePath(@img ,60 ,60 ,img.width - 60 ,img.height - 60 ,@parl[0 ] );{8} 484 485 end; 486 487// Free Image 488 img.Destruct; 489 490// Add/Sub/Contrast Blending Modes 491 m_graphics.noLine; 492 m_graphics.fillColor(70 ,70 ,0 ); 493 m_graphics.blendMode(BlendAdd ); 494 m_graphics.ellipse (500 ,280 ,20 ,40 ); 495 496 m_graphics.fillColor(255 ,255 ,255 ); 497 m_graphics.blendMode(BlendContrast ); 498 m_graphics.ellipse (500 + 40 ,280 ,20 ,40 ); 499 500// Radial gradient. 501 m_graphics.blendMode (BlendAlpha ); 502 c1.Construct (255 ,255 ,0 , 0); 503 c2.Construct (0 ,0 ,127 ); 504 c3.Construct (0 ,255 ,0 , 0); 505 m_graphics.fillRadialGradient(400 ,500 ,40 ,c1 ,c2 ,c3 ); 506 m_graphics.ellipse (400 ,500 ,40 ,40 ); 507 508// More ... 509(* m_graphics.masterAlpha(1 ); 510 511 //m_graphics.lineColor(50 ,60 ,70 ); 512 513 c1.Construct (255 ,0 ,0 ,255 ); 514 c2.Construct (0 ,255 ,0 ,255 ); 515 m_graphics.lineLinearGradient(0 ,0 ,500 ,0 ,c1 ,c2 );{} 516 517 m_graphics.fillColor(255 ,0 ,0 ); 518 m_graphics.lineJoin (JoinMiter ); 519 m_graphics.lineWidth(15 ); 520 m_graphics.triangle (10 ,10 ,100 ,20 ,50 ,150 ); 521 522 m_graphics.lineJoin (JoinRound ); 523 m_graphics.lineWidth(4 ); 524 m_graphics.noFill; 525 m_graphics.rectangle(55 ,540 ,135 ,495 ); 526 527 m_graphics.masterAlpha(0.5 ); 528 529 m_graphics.fillColor(255 ,127 ,65 ); 530 m_graphics.star (300 ,300 ,30 ,70 ,55 ,5 ); 531 m_graphics.arc (400 ,400 ,30 ,30 ,300 ,1150 ); 532 533 m_graphics.lineWidth(20 ); 534 m_graphics.lineCap (CapRound ); 535 m_graphics.curve (80 ,400 ,90 ,220 ,190 ,390 ); 536 m_graphics.curve (80 ,500 ,90 ,320 ,190 ,490 ,310 ,330 ); 537 538 poly[0 ]:=400; 539 poly[1 ]:=580; 540 541 poly[2 ]:=530; 542 poly[3 ]:=400; 543 544 poly[4 ]:=590; 545 poly[5 ]:=500; 546 547 poly[6 ]:=450; 548 poly[7 ]:=380; 549 550 poly[8 ]:=490; 551 poly[9 ]:=570; 552 553 poly[10 ]:=420; 554 poly[11 ]:=420; 555 556 m_graphics.fillEvenOdd(false ); 557 m_graphics.lineWidth (3 ); 558 m_graphics.polygon (@poly[0 ] ,6 ); 559 560 m_graphics.lineColor(221 ,160 ,221 ); 561 m_graphics.lineWidth(6 ); 562 m_graphics.polyline (@poly[0 ] ,6 ); (**) 563 564// TIMER DRAW 565// ---------- 566 tm:=elapsed_time; 567 568 m_timer.attach( 569 rbuf_window._buf , 570 rbuf_window._width , 571 rbuf_window._height , 572 rbuf_window._stride ); 573 574 m_timer.antiAliasGamma(1.4 ); 575 576 m_timer.flipText(not flip_y ); 577 m_timer.viewport( 578 0 ,0 ,600 ,600 , 579 0 ,0 ,_width ,_height , 580 //Anisotropic ); 581 XMidYMid ); 582 583 Str(tm:0:2 ,timer ); 584 585 timer:='Frame time: ' + timer + ' ms'; 586 587 fps:=Trunc(1000 / tm ); 588 589 Str(fps ,rate ); 590 591 timer:=timer + ' (' + rate + ' FPS)'; 592 593 m_timer.font(char_ptr(FONT_ARIAL ) ,15.0 ,true ,false ,VectorFontCache ); 594 m_timer.noLine; 595 m_timer.fillColor(255 ,0 ,0 ); 596 m_timer.text(350 ,8 ,char_ptr(@timer[1 ] ) ); 597 598end; 599 600{ ON_MOUSE_MOVE } 601procedure the_application.on_mouse_move; 602begin 603end; 604 605{ ON_MOUSE_BUTTON_DOWN } 606procedure the_application.on_mouse_button_down; 607begin 608end; 609 610{ ON_MOUSE_BUTTON_UP } 611procedure the_application.on_mouse_button_up; 612begin 613end; 614 615{ ON_KEY } 616procedure the_application.on_key; 617begin 618 if key = key_f1 then 619 message_( 620 '"Quick and dirty prototype" of 2D drawing API for AGG.'#13#13 + 621 'Written and published by Maxim Shemanarev (c) 2005 - 2006. '#13 + 622 'Ported to Object Pascal by Milan Marusinec (c) 2007.'#13#13 + 623 'How to play with:'#13#13 + 624 'Key Down - Rotate clockwise'#13 + 625 'Key Up - Rotate counterclockwise'#13 + 626 'Key Right - Next image transformation'#13 + 627 'Key Left - Previous image transformation'#13 + 628 'Key Plus - Increase gamma'#13 + 629 'Key Minus - Decrease gamma' ); 630 631 if key = key_down then 632 begin 633 m_angle:=m_angle - angle_step; 634 635 if m_angle < 0 then 636 m_angle:=360 - angle_step; 637 638 force_redraw; 639 640 end; 641 642 if key = key_up then 643 begin 644 m_angle:=m_angle + angle_step; 645 646 if m_angle > 360 then 647 m_angle:=angle_step; 648 649 force_redraw; 650 651 end; 652 653 if key = key_right then 654 begin 655 inc(m_image ); 656 657 if m_image > 8 then 658 m_image:=1; 659 660 force_redraw; 661 662 end; 663 664 if key = key_left then 665 begin 666 dec(m_image ); 667 668 if m_image < 1 then 669 m_image:=8; 670 671 force_redraw; 672 673 end; 674 675 if key = key_kp_plus then 676 begin 677 m_gamma:=m_gamma + gamma_step; 678 679 Str(m_gamma:0:2 ,m_gmText ); m_gmText:='Gamma: ' + m_gmText; 680 681 force_redraw; 682 683 end; 684 685 if key = key_kp_minus then 686 begin 687 m_gamma:=m_gamma - gamma_step; 688 689 Str(m_gamma:0:2 ,m_gmText ); m_gmText:='Gamma: ' + m_gmText; 690 691 force_redraw; 692 693 end; 694 695end; 696 697VAR 698 app : the_application; 699 buf : array [0..255 ] of char; 700 ext : string[10 ]; 701 702 img_name ,p ,n ,x : shortstring; 703 704BEGIN 705 if Agg2DUsesFreeType then 706 begin 707 FONT_TIMES:='times.ttf'; 708 FONT_ARIAL:='arial.ttf'; 709 FONT_VERDA:='verdana.ttf'; 710 711 end; 712 713 app.Construct(pix_format_bgra32 ,flip_y ); 714 app.caption_ ('Agg2DDemo (F1-Help)' ); 715 716 img_name:='spheres2'; 717 718{$IFDEF WIN32 } 719 if ParamCount > 0 then 720 begin 721 spread_name(ParamStr(1 ) ,p ,n ,x ); 722 723 img_name:=fold_name(p ,n ,'' ); 724 725 end; 726 727{$ENDIF } 728 729 if not app.load_img(0 ,img_name ) then 730 begin 731 img_name:=img_name + #0; 732 ext :=app._img_ext + #0; 733 734 if img_name = 'spheres2'#0 then 735 begin 736 sprintf(@buf[0 ] ,'File not found: %s' ,ptrcomp(@img_name[1 ] ) ); 737 sprintf(@buf[StrLen(@buf ) ] ,'%s. '#13'Download http://www.antigrain.com/' ,ptrcomp(@ext[1 ] ) ); 738 sprintf(@buf[StrLen(@buf ) ] ,'%s' ,ptrcomp(@img_name[1 ] ) ); 739 sprintf(@buf[StrLen(@buf ) ] ,'%s'#13'or copy it from another directory if available.' ,ptrcomp(@ext[1 ] ) ); 740 741 end 742 else 743 begin 744 sprintf(@buf[0 ] ,'File not found: %s' ,ptrcomp(@img_name[1 ] ) ); 745 sprintf(@buf[StrLen(@buf ) ] ,'%s' ,ptrcomp(@ext[1 ] ) ); 746 747 end; 748 749 app.message_(@buf[0 ] ); 750 751 end 752 else 753 if app.init(600 ,600 ,window_resize ) then 754 app.run; 755 756 app.Destruct; 757 758END.