Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

distortions.cpp

Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <stdlib.h>
00003 #include <math.h>
00004 #include "agg_rendering_buffer.h"
00005 #include "agg_rasterizer_scanline_aa.h"
00006 #include "agg_ellipse.h"
00007 #include "agg_trans_affine.h"
00008 #include "agg_conv_transform.h"
00009 #include "agg_pixfmt_rgb.h"
00010 #include "agg_span_allocator.h"
00011 #include "agg_span_image_filter_rgb.h"
00012 #include "agg_scanline_u.h"
00013 #include "agg_renderer_scanline.h"
00014 #include "agg_span_interpolator_linear.h"
00015 #include "agg_span_interpolator_adaptor.h"
00016 #include "agg_span_gradient.h"
00017 #include "agg_image_accessors.h"
00018 #include "ctrl/agg_slider_ctrl.h"
00019 #include "ctrl/agg_rbox_ctrl.h"
00020 #include "platform/agg_platform_support.h"
00021 
00022 
00023 enum flip_y_e { flip_y = true };
00024 
00025 
00026 static agg::int8u g_gradient_colors[] = 
00027 {
00028     255, 255, 255, 255,
00029     255, 255, 254, 255,
00030     255, 255, 254, 255,
00031     255, 255, 254, 255,
00032     255, 255, 253, 255,
00033     255, 255, 253, 255,
00034     255, 255, 252, 255,
00035     255, 255, 251, 255,
00036     255, 255, 250, 255,
00037     255, 255, 248, 255,
00038     255, 255, 246, 255,
00039     255, 255, 244, 255,
00040     255, 255, 241, 255,
00041     255, 255, 238, 255,
00042     255, 255, 235, 255,
00043     255, 255, 231, 255,
00044     255, 255, 227, 255,
00045     255, 255, 222, 255,
00046     255, 255, 217, 255,
00047     255, 255, 211, 255,
00048     255, 255, 206, 255,
00049     255, 255, 200, 255,
00050     255, 254, 194, 255,
00051     255, 253, 188, 255,
00052     255, 252, 182, 255,
00053     255, 250, 176, 255,
00054     255, 249, 170, 255,
00055     255, 247, 164, 255,
00056     255, 246, 158, 255,
00057     255, 244, 152, 255,
00058     254, 242, 146, 255,
00059     254, 240, 141, 255,
00060     254, 238, 136, 255,
00061     254, 236, 131, 255,
00062     253, 234, 126, 255,
00063     253, 232, 121, 255,
00064     253, 229, 116, 255,
00065     252, 227, 112, 255,
00066     252, 224, 108, 255,
00067     251, 222, 104, 255,
00068     251, 219, 100, 255,
00069     251, 216,  96, 255,
00070     250, 214,  93, 255,
00071     250, 211,  89, 255,
00072     249, 208,  86, 255,
00073     249, 205,  83, 255,
00074     248, 202,  80, 255,
00075     247, 199,  77, 255,
00076     247, 196,  74, 255,
00077     246, 193,  72, 255,
00078     246, 190,  69, 255,
00079     245, 187,  67, 255,
00080     244, 183,  64, 255,
00081     244, 180,  62, 255,
00082     243, 177,  60, 255,
00083     242, 174,  58, 255,
00084     242, 170,  56, 255,
00085     241, 167,  54, 255,
00086     240, 164,  52, 255,
00087     239, 161,  51, 255,
00088     239, 157,  49, 255,
00089     238, 154,  47, 255,
00090     237, 151,  46, 255,
00091     236, 147,  44, 255,
00092     235, 144,  43, 255,
00093     235, 141,  41, 255,
00094     234, 138,  40, 255,
00095     233, 134,  39, 255,
00096     232, 131,  37, 255,
00097     231, 128,  36, 255,
00098     230, 125,  35, 255,
00099     229, 122,  34, 255,
00100     228, 119,  33, 255,
00101     227, 116,  31, 255,
00102     226, 113,  30, 255,
00103     225, 110,  29, 255,
00104     224, 107,  28, 255,
00105     223, 104,  27, 255,
00106     222, 101,  26, 255,
00107     221,  99,  25, 255,
00108     220,  96,  24, 255,
00109     219,  93,  23, 255,
00110     218,  91,  22, 255,
00111     217,  88,  21, 255,
00112     216,  86,  20, 255,
00113     215,  83,  19, 255,
00114     214,  81,  18, 255,
00115     213,  79,  17, 255,
00116     212,  77,  17, 255,
00117     211,  74,  16, 255,
00118     210,  72,  15, 255,
00119     209,  70,  14, 255,
00120     207,  68,  13, 255,
00121     206,  66,  13, 255,
00122     205,  64,  12, 255,
00123     204,  62,  11, 255,
00124     203,  60,  10, 255,
00125     202,  58,  10, 255,
00126     201,  56,   9, 255,
00127     199,  55,   9, 255,
00128     198,  53,   8, 255,
00129     197,  51,   7, 255,
00130     196,  50,   7, 255,
00131     195,  48,   6, 255,
00132     193,  46,   6, 255,
00133     192,  45,   5, 255,
00134     191,  43,   5, 255,
00135     190,  42,   4, 255,
00136     188,  41,   4, 255,
00137     187,  39,   3, 255,
00138     186,  38,   3, 255,
00139     185,  37,   2, 255,
00140     183,  35,   2, 255,
00141     182,  34,   1, 255,
00142     181,  33,   1, 255,
00143     179,  32,   1, 255,
00144     178,  30,   0, 255,
00145     177,  29,   0, 255,
00146     175,  28,   0, 255,
00147     174,  27,   0, 255,
00148     173,  26,   0, 255,
00149     171,  25,   0, 255,
00150     170,  24,   0, 255,
00151     168,  23,   0, 255,
00152     167,  22,   0, 255,
00153     165,  21,   0, 255,
00154     164,  21,   0, 255,
00155     163,  20,   0, 255,
00156     161,  19,   0, 255,
00157     160,  18,   0, 255,
00158     158,  17,   0, 255,
00159     156,  17,   0, 255,
00160     155,  16,   0, 255,
00161     153,  15,   0, 255,
00162     152,  14,   0, 255,
00163     150,  14,   0, 255,
00164     149,  13,   0, 255,
00165     147,  12,   0, 255,
00166     145,  12,   0, 255,
00167     144,  11,   0, 255,
00168     142,  11,   0, 255,
00169     140,  10,   0, 255,
00170     139,  10,   0, 255,
00171     137,   9,   0, 255,
00172     135,   9,   0, 255,
00173     134,   8,   0, 255,
00174     132,   8,   0, 255,
00175     130,   7,   0, 255,
00176     128,   7,   0, 255,
00177     126,   6,   0, 255,
00178     125,   6,   0, 255,
00179     123,   5,   0, 255,
00180     121,   5,   0, 255,
00181     119,   4,   0, 255,
00182     117,   4,   0, 255,
00183     115,   4,   0, 255,
00184     113,   3,   0, 255,
00185     111,   3,   0, 255,
00186     109,   2,   0, 255,
00187     107,   2,   0, 255,
00188     105,   2,   0, 255,
00189     103,   1,   0, 255,
00190     101,   1,   0, 255,
00191      99,   1,   0, 255,
00192      97,   0,   0, 255,
00193      95,   0,   0, 255,
00194      93,   0,   0, 255,
00195      91,   0,   0, 255,
00196      90,   0,   0, 255,
00197      88,   0,   0, 255,
00198      86,   0,   0, 255,
00199      84,   0,   0, 255,
00200      82,   0,   0, 255,
00201      80,   0,   0, 255,
00202      78,   0,   0, 255,
00203      77,   0,   0, 255,
00204      75,   0,   0, 255,
00205      73,   0,   0, 255,
00206      72,   0,   0, 255,
00207      70,   0,   0, 255,
00208      68,   0,   0, 255,
00209      67,   0,   0, 255,
00210      65,   0,   0, 255,
00211      64,   0,   0, 255,
00212      63,   0,   0, 255,
00213      61,   0,   0, 255,
00214      60,   0,   0, 255,
00215      59,   0,   0, 255,
00216      58,   0,   0, 255,
00217      57,   0,   0, 255,
00218      56,   0,   0, 255,
00219      55,   0,   0, 255,
00220      54,   0,   0, 255,
00221      53,   0,   0, 255,
00222      53,   0,   0, 255,
00223      52,   0,   0, 255,
00224      52,   0,   0, 255,
00225      51,   0,   0, 255,
00226      51,   0,   0, 255,
00227      51,   0,   0, 255,
00228      50,   0,   0, 255,
00229      50,   0,   0, 255,
00230      51,   0,   0, 255,
00231      51,   0,   0, 255,
00232      51,   0,   0, 255,
00233      51,   0,   0, 255,
00234      52,   0,   0, 255,
00235      52,   0,   0, 255,
00236      53,   0,   0, 255,
00237      54,   1,   0, 255,
00238      55,   2,   0, 255,
00239      56,   3,   0, 255,
00240      57,   4,   0, 255,
00241      58,   5,   0, 255,
00242      59,   6,   0, 255,
00243      60,   7,   0, 255,
00244      62,   8,   0, 255,
00245      63,   9,   0, 255,
00246      64,  11,   0, 255,
00247      66,  12,   0, 255,
00248      68,  13,   0, 255,
00249      69,  14,   0, 255,
00250      71,  16,   0, 255,
00251      73,  17,   0, 255,
00252      75,  18,   0, 255,
00253      77,  20,   0, 255,
00254      79,  21,   0, 255,
00255      81,  23,   0, 255,
00256      83,  24,   0, 255,
00257      85,  26,   0, 255,
00258      87,  28,   0, 255,
00259      90,  29,   0, 255,
00260      92,  31,   0, 255,
00261      94,  33,   0, 255,
00262      97,  34,   0, 255,
00263      99,  36,   0, 255,
00264     102,  38,   0, 255,
00265     104,  40,   0, 255,
00266     107,  41,   0, 255,
00267     109,  43,   0, 255,
00268     112,  45,   0, 255,
00269     115,  47,   0, 255,
00270     117,  49,   0, 255,
00271     120,  51,   0, 255,
00272     123,  52,   0, 255,
00273     126,  54,   0, 255,
00274     128,  56,   0, 255,
00275     131,  58,   0, 255,
00276     134,  60,   0, 255,
00277     137,  62,   0, 255,
00278     140,  64,   0, 255,
00279     143,  66,   0, 255,
00280     145,  68,   0, 255,
00281     148,  70,   0, 255,
00282     151,  72,   0, 255,
00283     154,  74,   0, 255
00284 };
00285 
00286 
00287 
00288 class periodic_distortion
00289 {
00290 public:
00291     periodic_distortion() :
00292         m_cx(0.0),
00293         m_cy(0.0),
00294         m_period(0.5),
00295         m_amplitude(0.5),
00296         m_phase(0.0)
00297     {}
00298 
00299     void center(double x, double y) { m_cx = x; m_cy = y; }
00300     void period(double v)           { m_period = v; }
00301     void amplitude(double v)        { m_amplitude = 1.0 / v; }
00302     void phase(double v)            { m_phase = v; }
00303 
00304     virtual void calculate(int* x, int* y) const = 0;
00305 
00306 protected:
00307     double m_cx;
00308     double m_cy;
00309     double m_period;
00310     double m_amplitude;
00311     double m_phase;
00312 };
00313 
00314 
00315 
00316 inline void calculate_wave(int* x, int* y, 
00317                            double cx, double cy, 
00318                            double period, double amplitude, double phase)
00319 {
00320     double xd = double(*x) / agg::image_subpixel_scale - cx;
00321     double yd = double(*y) / agg::image_subpixel_scale - cy;
00322     double d = sqrt(xd*xd + yd*yd);
00323     if(d > 1)
00324     {
00325         double a = cos(d / (16.0 * period) - phase) * (1.0 / (amplitude * d)) + 1.0; 
00326         *x = int((xd * a + cx) * agg::image_subpixel_scale);
00327         *y = int((yd * a + cy) * agg::image_subpixel_scale);
00328     }
00329 }
00330 
00331 
00332 
00333 inline void calculate_swirl(int* x, int* y,
00334                             double cx, double cy, 
00335                             double amplitude, double phase)
00336 {
00337     double xd = double(*x) / agg::image_subpixel_scale - cx;
00338     double yd = double(*y) / agg::image_subpixel_scale - cy;
00339     double a = double(100.0 - sqrt(xd * xd + yd * yd)) / 100.0 * (0.1 / -amplitude);
00340     double sa = sin(a - phase/25.0);
00341     double ca = cos(a - phase/25.0);
00342     *x = int((xd * ca - yd * sa + cx) * agg::image_subpixel_scale);
00343     *y = int((xd * sa + yd * ca + cy) * agg::image_subpixel_scale);
00344 }
00345 
00346 
00347 
00348 
00349 
00350 class distortion_wave : public periodic_distortion
00351 {
00352     virtual void calculate(int* x, int* y) const
00353     {
00354         calculate_wave(x, y, m_cx, m_cy, m_period, m_amplitude, m_phase);
00355     }
00356 };
00357 
00358 class distortion_swirl : public periodic_distortion
00359 {
00360     virtual void calculate(int* x, int* y) const
00361     {
00362         calculate_swirl(x, y, m_cx, m_cy, m_amplitude, m_phase);
00363     }
00364 };
00365 
00366 class distortion_swirl_wave : public periodic_distortion
00367 {
00368     virtual void calculate(int* x, int* y) const
00369     {
00370         calculate_swirl(x, y, m_cx, m_cy, m_amplitude, m_phase);
00371         calculate_wave(x, y, m_cx, m_cy, m_period, m_amplitude, m_phase);
00372     }
00373 };
00374 
00375 
00376 class distortion_wave_swirl : public periodic_distortion
00377 {
00378     virtual void calculate(int* x, int* y) const
00379     {
00380         calculate_wave(x, y, m_cx, m_cy, m_period, m_amplitude, m_phase);
00381         calculate_swirl(x, y, m_cx, m_cy, m_amplitude, m_phase);
00382     }
00383 };
00384 
00385 
00386 
00387 
00388 
00389 
00390 
00391 
00392 
00393 
00394 class the_application : public agg::platform_support
00395 {
00396     agg::slider_ctrl<agg::rgba8> m_angle;
00397     agg::slider_ctrl<agg::rgba8> m_scale;
00398     agg::slider_ctrl<agg::rgba8> m_amplitude;
00399     agg::slider_ctrl<agg::rgba8> m_period;
00400     agg::rbox_ctrl<agg::rgba8>   m_distortion;
00401 
00402     double m_center_x;
00403     double m_center_y;
00404     double m_phase;
00405 
00406     typedef agg::pod_auto_array<agg::rgba8, 256> color_array_type;
00407     color_array_type m_gradient_colors;
00408 
00409 public:
00410     the_application(agg::pix_format_e format, bool flip_y) :
00411         agg::platform_support(format, flip_y),
00412         m_angle     (5,      5,    150,     12,    !flip_y),
00413         m_scale     (5,      5+15, 150,     12+15, !flip_y),
00414         m_period    (5+170,  5,    150+170, 12,    !flip_y),
00415         m_amplitude (5+170,  5+15, 150+170, 12+15, !flip_y),
00416         m_distortion(480,    5,    600,     90,    !flip_y),
00417 
00418         m_center_x(0.0),
00419         m_center_y(0.0),
00420         m_phase(0.0)
00421     {
00422         add_ctrl(m_angle);
00423         add_ctrl(m_scale);
00424         add_ctrl(m_amplitude);
00425         add_ctrl(m_period);
00426         add_ctrl(m_distortion);
00427         m_angle.label("Angle=%3.2f");
00428         m_scale.label("Scale=%3.2f");
00429         m_angle.range(-180.0, 180.0);
00430         m_angle.value(20.0);
00431         m_scale.range(0.1, 5.0);
00432         m_scale.value(1.0);
00433 
00434         m_amplitude.label("Amplitude=%3.2f");
00435         m_period.label("Period=%3.2f");
00436         m_amplitude.range(0.1, 40.0);
00437         m_period.range(0.1, 2.0);
00438         m_amplitude.value(10.0);
00439         m_period.value(1.0);
00440 
00441         m_distortion.add_item("Wave");
00442         m_distortion.add_item("Swirl");
00443         m_distortion.add_item("Wave-Swirl");
00444         m_distortion.add_item("Swirl-Wave");
00445         m_distortion.cur_item(0);
00446 
00447         unsigned i;
00448         const agg::int8u* p = g_gradient_colors;
00449         for(i = 0; i < 256; i++)
00450         {
00451             m_gradient_colors[i] = agg::rgba8(p[0], p[1], p[2], p[3]);
00452             p += 4;
00453         }
00454     }
00455 
00456     virtual ~the_application()
00457     {
00458     }
00459 
00460     virtual void on_init()
00461     {
00462         m_center_x = rbuf_img(0).width() / 2.0 + 10;
00463         m_center_y = rbuf_img(0).height() / 2.0 + 10 + 40;
00464     }
00465 
00466     virtual void on_draw()
00467     {
00468         double img_width = rbuf_img(0).width();
00469         double img_height = rbuf_img(0).height();
00470     
00471         typedef agg::pixfmt_bgr24 pixfmt; 
00472         typedef agg::renderer_base<pixfmt> renderer_base;
00473 
00474         pixfmt pixf(rbuf_window());
00475         pixfmt img_pixf(rbuf_img(0));
00476 
00477         renderer_base rb(pixf);
00478 
00479         rb.clear(agg::rgba(1.0, 1.0, 1.0));
00480 
00481         agg::trans_affine src_mtx;
00482         src_mtx *= agg::trans_affine_translation(-img_width/2, -img_height/2);
00483         src_mtx *= agg::trans_affine_rotation(m_angle.value() * agg::pi / 180.0);
00484         src_mtx *= agg::trans_affine_translation(img_width/2 + 10, img_height/2 + 10 + 40);
00485         src_mtx *= trans_affine_resizing();
00486 
00487         agg::trans_affine img_mtx;
00488         img_mtx *= agg::trans_affine_translation(-img_width/2, -img_height/2);
00489         img_mtx *= agg::trans_affine_rotation(m_angle.value() * agg::pi / 180.0);
00490         img_mtx *= agg::trans_affine_scaling(m_scale.value());
00491         img_mtx *= agg::trans_affine_translation(img_width/2 + 10, img_height/2 + 10 + 40);
00492         img_mtx *= trans_affine_resizing();
00493         img_mtx.invert();
00494 
00495 
00496         typedef agg::span_allocator<agg::rgba8> span_alloc_type;
00497 
00498         span_alloc_type sa;
00499         
00500         typedef agg::span_interpolator_adaptor<agg::span_interpolator_linear<>, 
00501                                                periodic_distortion> interpolator_type;
00502 
00503         periodic_distortion*  dist = 0;
00504         distortion_wave       dist_wave;
00505         distortion_swirl      dist_swirl;
00506         distortion_wave_swirl dist_wave_swirl;
00507         distortion_swirl_wave dist_swirl_wave;
00508 
00509         switch(m_distortion.cur_item())
00510         {
00511             case 0: dist = &dist_wave;       break;
00512             case 1: dist = &dist_swirl;      break;
00513             case 2: dist = &dist_wave_swirl; break;
00514             case 3: dist = &dist_swirl_wave; break;
00515         }
00516 
00517         dist->period(m_period.value());
00518         dist->amplitude(m_amplitude.value());
00519         dist->phase(m_phase);
00520         double cx = m_center_x;
00521         double cy = m_center_y;
00522         img_mtx.transform(&cx, &cy);
00523         dist->center(cx, cy);
00524 
00525         interpolator_type interpolator(img_mtx, *dist);
00526 
00527         typedef agg::image_accessor_clip<pixfmt> img_source_type;
00528         img_source_type img_src(img_pixf, agg::rgba(1,1,1));
00529 
00530 /*
00531         // Version without filtering (nearest neighbor)
00532         //------------------------------------------
00533         typedef agg::span_image_filter_rgb_nn<img_source_type,
00534                                               interpolator_type> span_gen_type;
00535         span_gen_type sg(img_src, interpolator);
00536         //------------------------------------------
00537 */
00538 
00539         // Version with "hardcoded" bilinear filter and without 
00540         // image_accessor (direct filter, the old variant)
00541         //------------------------------------------
00542         typedef agg::span_image_filter_rgb_bilinear_clip<pixfmt,
00543                                                          interpolator_type> span_gen_type;
00544         span_gen_type sg(img_pixf, agg::rgba(1,1,1), interpolator);
00545         //------------------------------------------
00546 
00547 /*
00548         // Version with arbitrary 2x2 filter
00549         //------------------------------------------
00550         typedef agg::span_image_filter_rgb_2x2<img_source_type,
00551                                                interpolator_type> span_gen_type;
00552         agg::image_filter<agg::image_filter_kaiser> filter;
00553         span_gen_type sg(img_src, interpolator, filter);
00554         //------------------------------------------
00555 */
00556 /*
00557         // Version with arbitrary filter
00558         //------------------------------------------
00559         typedef agg::span_image_filter_rgb<img_source_type,
00560                                            interpolator_type> span_gen_type;
00561         agg::image_filter<agg::image_filter_spline36> filter;
00562         span_gen_type sg(img_src, interpolator, filter);
00563         //------------------------------------------
00564 */
00565 
00566 
00567         agg::rasterizer_scanline_aa<> ras;
00568         agg::scanline_u8 sl;
00569         double r = img_width;
00570         if(img_height < r) r = img_height;
00571         agg::ellipse ell(img_width  / 2.0, 
00572                          img_height / 2.0, 
00573                          r / 2.0 - 20.0, 
00574                          r / 2.0 - 20.0, 200);
00575 
00576 
00577         agg::conv_transform<agg::ellipse> tr(ell, src_mtx);
00578 
00579         ras.add_path(tr);
00580         agg::render_scanlines_aa(ras, sl, rb, sa, sg);
00581 
00582         src_mtx *= ~trans_affine_resizing();
00583         src_mtx *= agg::trans_affine_translation(img_width - img_width/10, 0.0);
00584         src_mtx *= trans_affine_resizing();
00585 
00586         ras.add_path(tr);
00587         agg::render_scanlines_aa_solid(ras, sl, rb, agg::rgba8(0,0,0));
00588 
00589         typedef agg::span_gradient<agg::rgba8, 
00590                                    interpolator_type,
00591                                    agg::gradient_circle,
00592                                    color_array_type> gradient_span_gen;
00593 
00594         agg::gradient_circle gradient_function;
00595 
00596         color_array_type gradient_colors(m_gradient_colors);
00597         gradient_span_gen span_gradient(interpolator, 
00598                                         gradient_function, 
00599                                         gradient_colors, 
00600                                         0, 180);
00601 
00602         agg::trans_affine gr1_mtx;
00603         gr1_mtx *= agg::trans_affine_translation(-img_width/2, -img_height/2);
00604         gr1_mtx *= agg::trans_affine_scaling(0.8);
00605         gr1_mtx *= agg::trans_affine_rotation(m_angle.value() * agg::pi / 180.0);
00606         gr1_mtx *= agg::trans_affine_translation(img_width - img_width/10 + img_width/2 + 10, 
00607                                                  img_height/2 + 10 + 40);
00608         gr1_mtx *= trans_affine_resizing();
00609 
00610         agg::trans_affine gr2_mtx;
00611         gr2_mtx *= agg::trans_affine_rotation(m_angle.value() * agg::pi / 180.0);
00612         gr2_mtx *= agg::trans_affine_scaling(m_scale.value());
00613         gr2_mtx *= agg::trans_affine_translation(img_width - img_width/10 + img_width/2 + 10 + 50, 
00614                                                  img_height/2 + 10 + 40 + 50);
00615         gr2_mtx *= trans_affine_resizing();
00616         gr2_mtx.invert();
00617 
00618         cx = m_center_x + img_width - img_width/10;
00619         cy = m_center_y;
00620         gr2_mtx.transform(&cx, &cy);
00621         dist->center(cx, cy);
00622 
00623         interpolator.transformer(gr2_mtx);
00624 
00625         agg::conv_transform<agg::ellipse> tr2(ell, gr1_mtx);
00626 
00627         ras.add_path(tr2);
00628         agg::render_scanlines_aa(ras, sl, rb, sa, span_gradient);
00629 
00630         agg::render_ctrl(ras, sl, rb, m_angle);
00631         agg::render_ctrl(ras, sl, rb, m_scale);
00632         agg::render_ctrl(ras, sl, rb, m_amplitude);
00633         agg::render_ctrl(ras, sl, rb, m_period);
00634         agg::render_ctrl(ras, sl, rb, m_distortion);
00635     }
00636 
00637 
00638     
00639     virtual void on_mouse_button_down(int x, int y, unsigned flags)
00640     {
00641         if(flags)
00642         {
00643             m_center_x = x;
00644             m_center_y = y;
00645             force_redraw();
00646         }
00647     }
00648 
00649 
00650 
00651     virtual void on_mouse_move(int x, int y, unsigned flags)
00652     {
00653         if(flags & 1)
00654         {
00655             m_center_x = x;
00656             m_center_y = y;
00657             force_redraw();
00658         }
00659     }
00660 
00661     virtual void on_idle()
00662     {
00663         m_phase += 15.0 * agg::pi / 180.0;
00664         if(m_phase > agg::pi * 200.0) m_phase -= agg::pi * 200.0;
00665         force_redraw();
00666     }
00667 
00668 
00669 };
00670 
00671 
00672 
00673 
00674 
00675 int agg_main(int argc, char* argv[])
00676 {
00677     the_application app(agg::pix_format_bgr24, flip_y);
00678     app.caption("Image and Gradient Distortions");
00679 
00680     const char* img_name = "spheres";
00681     if(argc >= 2) img_name = argv[1];
00682     if(!app.load_img(0, img_name)) 
00683     {
00684         char buf[256];
00685         if(strcmp(img_name, "spheres") == 0)
00686         {
00687             sprintf(buf, "File not found: %s%s. Download http://www.antigrain.com/%s%s\n"
00688                          "or copy it from another directory if available.",
00689                     img_name, app.img_ext(), img_name, app.img_ext());
00690         }
00691         else
00692         {
00693             sprintf(buf, "File not found: %s%s", img_name, app.img_ext());
00694         }
00695         app.message(buf);
00696         return 1;
00697     }
00698 
00699     if(app.init(app.rbuf_img(0).width() + 300, app.rbuf_img(0).height() + 40 + 20, agg::window_resize))
00700     {
00701         app.wait_mode(false);
00702         return app.run();
00703     }
00704     return 0;
00705 }
00706 
00707 

© sourcejam.com 2005-2008