00001 #include <stdlib.h>
00002 #include <ctype.h>
00003 #include <stdio.h>
00004 #include "agg_rendering_buffer.h"
00005 #include "agg_rasterizer_scanline_aa.h"
00006 #include "agg_scanline_p.h"
00007 #include "agg_renderer_scanline.h"
00008 #include "agg_conv_bspline.h"
00009 #include "ctrl/agg_cbox_ctrl.h"
00010 #include "ctrl/agg_slider_ctrl.h"
00011 #include "platform/agg_platform_support.h"
00012 #include "interactive_polygon.h"
00013
00014 #define AGG_BGR24
00015
00016
00017
00018
00019
00020
00021
00022 #include "pixel_formats.h"
00023
00024 enum flip_y_e { flip_y = true };
00025
00026
00027
00028
00029
00030
00031 class the_application : public agg::platform_support
00032 {
00033 public:
00034 typedef agg::renderer_base<pixfmt> renderer_base;
00035 typedef agg::scanline_p8 scanline_type;
00036
00037 agg::interactive_polygon m_poly;
00038 agg::slider_ctrl<agg::rgba8> m_num_points;
00039 agg::cbox_ctrl<agg::rgba8> m_close;
00040 int m_flip;
00041
00042 the_application(agg::pix_format_e format, bool flip_y) :
00043 agg::platform_support(format, flip_y),
00044 m_poly(6, 5.0),
00045 m_num_points(5.0, 5.0, 340.0, 12.0, !flip_y),
00046 m_close (350, 5.0, "Close", !flip_y),
00047 m_flip(0)
00048 {
00049 add_ctrl(m_close);
00050 m_num_points.range(1.0, 40.0);
00051 m_num_points.value(20.0);
00052 m_num_points.label("Number of intermediate Points = %.3f");
00053 add_ctrl(m_num_points);
00054 }
00055
00056
00057 virtual void on_init()
00058 {
00059 if(m_flip)
00060 {
00061 m_poly.xn(0) = 100;
00062 m_poly.yn(0) = height() - 100;
00063 m_poly.xn(1) = width() - 100;
00064 m_poly.yn(1) = height() - 100;
00065 m_poly.xn(2) = width() - 100;
00066 m_poly.yn(2) = 100;
00067 m_poly.xn(3) = 100;
00068 m_poly.yn(3) = 100;
00069 }
00070 else
00071 {
00072 m_poly.xn(0) = 100;
00073 m_poly.yn(0) = 100;
00074 m_poly.xn(1) = width() - 100;
00075 m_poly.yn(1) = 100;
00076 m_poly.xn(2) = width() - 100;
00077 m_poly.yn(2) = height() - 100;
00078 m_poly.xn(3) = 100;
00079 m_poly.yn(3) = height() - 100;
00080 }
00081 m_poly.xn(4) = width() / 2;
00082 m_poly.yn(4) = height() / 2;
00083 m_poly.xn(5) = width() / 2;
00084 m_poly.yn(5) = height() / 3;
00085
00086 }
00087
00088
00089
00090
00091 virtual void on_draw()
00092 {
00093 pixfmt pixf(rbuf_window());
00094 renderer_base rb(pixf);
00095 rb.clear(agg::rgba(1, 1, 1));
00096
00097 scanline_type sl;
00098 agg::rasterizer_scanline_aa<> ras;
00099
00100 agg::simple_polygon_vertex_source path(m_poly.polygon(),
00101 m_poly.num_points(),
00102 false,
00103 m_close.status());
00104
00105 typedef agg::conv_bspline<agg::simple_polygon_vertex_source> conv_bspline_type;
00106 conv_bspline_type bspline(path);
00107 bspline.interpolation_step(1.0 / m_num_points.value());
00108
00109 typedef agg::conv_stroke<conv_bspline_type> conv_stroke_type;
00110 conv_stroke_type stroke(bspline);
00111
00112 stroke.width(2.0);
00113
00114 ras.add_path(stroke);
00115 agg::render_scanlines_aa_solid(ras, sl, rb, agg::rgba(0, 0, 0));
00116
00117
00118
00119
00120 ras.add_path(m_poly);
00121 agg::render_scanlines_aa_solid(ras, sl, rb, agg::rgba(0, 0.3, 0.5, 0.6));
00122
00123 agg::render_ctrl(ras, sl, rb, m_close);
00124 agg::render_ctrl(ras, sl, rb, m_num_points);
00125
00126
00127 }
00128
00129
00130
00131 virtual void on_mouse_button_down(int x, int y, unsigned flags)
00132 {
00133 if(flags & agg::mouse_left)
00134 {
00135 if(m_poly.on_mouse_button_down(x, y))
00136 {
00137 force_redraw();
00138 }
00139 }
00140 }
00141
00142
00143 virtual void on_mouse_move(int x, int y, unsigned flags)
00144 {
00145 if(flags & agg::mouse_left)
00146 {
00147 if(m_poly.on_mouse_move(x, y))
00148 {
00149 force_redraw();
00150 }
00151 }
00152 if((flags & agg::mouse_left) == 0)
00153 {
00154 on_mouse_button_up(x, y, flags);
00155 }
00156 }
00157
00158
00159 virtual void on_mouse_button_up(int x, int y, unsigned flags)
00160 {
00161 if(m_poly.on_mouse_button_up(x, y))
00162 {
00163 force_redraw();
00164 }
00165 }
00166
00167
00168 virtual void on_key(int x, int y, unsigned key, unsigned flags)
00169 {
00170 if(key == ' ')
00171 {
00172 m_flip ^= 1;
00173 on_init();
00174 force_redraw();
00175 }
00176 }
00177
00178 };
00179
00180
00181
00182
00183
00184
00185 int agg_main(int argc, char* argv[])
00186 {
00187 the_application app(pix_format, flip_y);
00188 app.caption("AGG Example. BSpline Interpolator");
00189
00190 if(app.init(600, 600, agg::window_resize))
00191 {
00192 return app.run();
00193 }
00194 return 1;
00195 }
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205