00001 #include <stdlib.h>
00002 #include <ctype.h>
00003 #include <stdio.h>
00004 #include "agg_basics.h"
00005 #include "agg_rendering_buffer.h"
00006 #include "agg_rasterizer_scanline_aa.h"
00007 #include "agg_scanline_p.h"
00008 #include "agg_renderer_scanline.h"
00009 #include "agg_path_storage.h"
00010 #include "agg_conv_transform.h"
00011 #include "agg_bounding_rect.h"
00012 #include "ctrl/agg_slider_ctrl.h"
00013 #include "platform/agg_platform_support.h"
00014
00015
00016
00017
00018
00019 #define AGG_BGRA32
00020
00021
00022
00023
00024
00025 #include "pixel_formats.h"
00026
00027 enum flip_y_e { flip_y = true };
00028
00029 agg::rasterizer_scanline_aa<> g_rasterizer;
00030 agg::scanline_p8 g_scanline;
00031 agg::path_storage g_path;
00032 agg::rgba8 g_colors[100];
00033 unsigned g_path_idx[100];
00034 unsigned g_npaths = 0;
00035 double g_x1 = 0;
00036 double g_y1 = 0;
00037 double g_x2 = 0;
00038 double g_y2 = 0;
00039 double g_base_dx = 0;
00040 double g_base_dy = 0;
00041 double g_angle = 0;
00042 double g_scale = 1.0;
00043 double g_skew_x = 0;
00044 double g_skew_y = 0;
00045 int g_nclick = 0;
00046
00047 unsigned parse_lion(agg::path_storage& ps, agg::rgba8* colors, unsigned* path_idx);
00048 void parse_lion()
00049 {
00050 g_npaths = parse_lion(g_path, g_colors, g_path_idx);
00051 agg::pod_array_adaptor<unsigned> path_idx(g_path_idx, 100);
00052 agg::bounding_rect(g_path, path_idx, 0, g_npaths, &g_x1, &g_y1, &g_x2, &g_y2);
00053 g_base_dx = (g_x2 - g_x1) / 2.0;
00054 g_base_dy = (g_y2 - g_y1) / 2.0;
00055 }
00056
00057
00058
00059 class the_application : public agg::platform_support
00060 {
00061 agg::slider_ctrl<agg::rgba8> m_alpha_slider;
00062
00063 public:
00064 typedef agg::renderer_base<pixfmt> renderer_base;
00065 typedef agg::renderer_scanline_aa_solid<renderer_base> renderer_solid;
00066
00067 the_application(agg::pix_format_e format, bool flip_y) :
00068 agg::platform_support(format, flip_y),
00069 m_alpha_slider(5, 5, 512-5, 12, !flip_y)
00070 {
00071 parse_lion();
00072 add_ctrl(m_alpha_slider);
00073 m_alpha_slider.no_transform();
00074 m_alpha_slider.label("Alpha%3.3f");
00075 m_alpha_slider.value(0.1);
00076 }
00077
00078 virtual void on_resize(int cx, int cy)
00079 {
00080 pixfmt pf(rbuf_window());
00081 renderer_base r(pf);
00082 r.clear(agg::rgba(1, 1, 1));
00083 }
00084
00085 virtual void on_draw()
00086 {
00087 int width = rbuf_window().width();
00088 int height = rbuf_window().height();
00089
00090 unsigned i;
00091 for(i = 0; i < g_npaths; i++)
00092 {
00093 g_colors[i].a = agg::int8u(m_alpha_slider.value() * 255);
00094 }
00095
00096 pixfmt pixf(rbuf_window());
00097 renderer_base rb(pixf);
00098 renderer_solid r(rb);
00099
00100 agg::trans_affine mtx;
00101 mtx *= agg::trans_affine_translation(-g_base_dx, -g_base_dy);
00102 mtx *= agg::trans_affine_scaling(g_scale, g_scale);
00103 mtx *= agg::trans_affine_rotation(g_angle + agg::pi);
00104 mtx *= agg::trans_affine_skewing(g_skew_x/1000.0, g_skew_y/1000.0);
00105 mtx *= agg::trans_affine_translation(width/2, height/2);
00106
00107
00108 agg::conv_transform<agg::path_storage, agg::trans_affine> trans(g_path, mtx);
00109 agg::render_all_paths(g_rasterizer, g_scanline, r, trans, g_colors, g_path_idx, g_npaths);
00110
00111
00112 agg::render_ctrl(g_rasterizer, g_scanline, rb, m_alpha_slider);
00113 }
00114
00115
00116 void transform(double width, double height, double x, double y)
00117 {
00118 x -= width / 2;
00119 y -= height / 2;
00120 g_angle = atan2(y, x);
00121 g_scale = sqrt(y * y + x * x) / 100.0;
00122 }
00123
00124
00125 virtual void on_mouse_button_down(int x, int y, unsigned flags)
00126 {
00127 if(flags & agg::mouse_left)
00128 {
00129 int width = rbuf_window().width();
00130 int height = rbuf_window().height();
00131 transform(width, height, x, y);
00132 force_redraw();
00133 }
00134
00135 if(flags & agg::mouse_right)
00136 {
00137 g_skew_x = x;
00138 g_skew_y = y;
00139 force_redraw();
00140 }
00141 }
00142
00143
00144 virtual void on_mouse_move(int x, int y, unsigned flags)
00145 {
00146 on_mouse_button_down(x, y, flags);
00147 }
00148
00149 };
00150
00151
00152
00153
00154
00155
00156 int agg_main(int argc, char* argv[])
00157 {
00158 the_application app(pix_format, flip_y);
00159 app.caption("AGG Example. Lion");
00160
00161 if(app.init(512, 400, agg::window_resize))
00162 {
00163 return app.run();
00164 }
00165 return 1;
00166 }
00167
00168
00169
00170
00171
00172