~ubuntu-branches/ubuntu/lucid/agg/lucid-proposed

« back to all changes in this revision

Viewing changes to examples/gradients.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Rene Engelhard
  • Date: 2005-11-29 02:02:41 UTC
  • Revision ID: james.westby@ubuntu.com-20051129020241-pmlxls0x6j2qv3nm
Tags: upstream-2.3
ImportĀ upstreamĀ versionĀ 2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <stdio.h>
 
2
#include <stdlib.h>
 
3
#include "agg_rendering_buffer.h"
 
4
#include "agg_rasterizer_scanline_aa.h"
 
5
#include "agg_scanline_u.h"
 
6
#include "agg_scanline_p.h"
 
7
#include "agg_conv_transform.h"
 
8
#include "agg_color_rgba.h"
 
9
#include "agg_color_gray.h"
 
10
#include "agg_span_gradient.h"
 
11
#include "agg_span_interpolator_linear.h"
 
12
#include "agg_renderer_scanline.h"
 
13
#include "ctrl/agg_rbox_ctrl.h"
 
14
#include "ctrl/agg_spline_ctrl.h"
 
15
#include "ctrl/agg_gamma_ctrl.h"
 
16
#include "platform/agg_platform_support.h"
 
17
 
 
18
 
 
19
//#define AGG_GRAY16
 
20
#define AGG_BGR24
 
21
//#define AGG_RGB24
 
22
//#define AGG_RGB_AAA
 
23
//#define AGG_RGBA32 
 
24
//#define AGG_ARGB32 
 
25
//#define AGG_ABGR32
 
26
//#define AGG_RGB565
 
27
//#define AGG_RGB555
 
28
#include "pixel_formats.h"
 
29
 
 
30
enum flip_y_e { flip_y = true };
 
31
 
 
32
const double center_x = 350;
 
33
const double center_y = 280;
 
34
 
 
35
 
 
36
 
 
37
 
 
38
class gradient_polymorphic_wrapper_base
 
39
{
 
40
public:
 
41
    virtual int calculate(int x, int y, int) const = 0;
 
42
};
 
43
 
 
44
template<class GradientF> 
 
45
class gradient_polymorphic_wrapper : public gradient_polymorphic_wrapper_base
 
46
{
 
47
public:
 
48
    gradient_polymorphic_wrapper() : m_adaptor(m_gradient) {}
 
49
 
 
50
    virtual int calculate(int x, int y, int d) const
 
51
    {
 
52
        return m_adaptor.calculate(x, y, d);
 
53
    }
 
54
    GradientF m_gradient;
 
55
    agg::gradient_reflect_adaptor<GradientF> m_adaptor;
 
56
};
 
57
 
 
58
 
 
59
 
 
60
struct color_function_profile
 
61
{
 
62
    color_function_profile() {}
 
63
    color_function_profile(const color_type* colors, const agg::int8u* profile) :
 
64
        m_colors(colors), m_profile(profile) {}
 
65
 
 
66
    static unsigned size() { return 256; }
 
67
    const color_type& operator [] (unsigned v) const
 
68
    { 
 
69
        return m_colors[m_profile[v]]; 
 
70
    }
 
71
 
 
72
    const color_type* m_colors;
 
73
    const agg::int8u* m_profile;
 
74
};
 
75
 
 
76
 
 
77
class the_application : public agg::platform_support
 
78
{
 
79
    agg::gamma_ctrl<agg::rgba8>  m_profile;
 
80
    agg::spline_ctrl<agg::rgba8> m_spline_r;
 
81
    agg::spline_ctrl<agg::rgba8> m_spline_g;
 
82
    agg::spline_ctrl<agg::rgba8> m_spline_b;
 
83
    agg::spline_ctrl<agg::rgba8> m_spline_a;
 
84
    agg::rbox_ctrl<agg::rgba8>   m_rbox;
 
85
 
 
86
    double m_pdx;
 
87
    double m_pdy;
 
88
    double m_center_x;
 
89
    double m_center_y;
 
90
    double m_scale;
 
91
    double m_prev_scale;
 
92
    double m_angle;
 
93
    double m_prev_angle;
 
94
    double m_scale_x;
 
95
    double m_prev_scale_x;
 
96
    double m_scale_y;
 
97
    double m_prev_scale_y;
 
98
    bool m_mouse_move;
 
99
 
 
100
public:
 
101
    virtual ~the_application()
 
102
    {
 
103
        FILE* fd = fopen(full_file_name("settings.dat"), "w");
 
104
        fprintf(fd, "%f\n", m_center_x);
 
105
        fprintf(fd, "%f\n", m_center_y);
 
106
        fprintf(fd, "%f\n", m_scale);
 
107
        fprintf(fd, "%f\n", m_angle);
 
108
        fprintf(fd, "%f\n", m_spline_r.x(0));
 
109
        fprintf(fd, "%f\n", m_spline_r.y(0));
 
110
        fprintf(fd, "%f\n", m_spline_r.x(1));
 
111
        fprintf(fd, "%f\n", m_spline_r.y(1));
 
112
        fprintf(fd, "%f\n", m_spline_r.x(2));
 
113
        fprintf(fd, "%f\n", m_spline_r.y(2));
 
114
        fprintf(fd, "%f\n", m_spline_r.x(3));
 
115
        fprintf(fd, "%f\n", m_spline_r.y(3));
 
116
        fprintf(fd, "%f\n", m_spline_r.x(4));
 
117
        fprintf(fd, "%f\n", m_spline_r.y(4));
 
118
        fprintf(fd, "%f\n", m_spline_r.x(5));
 
119
        fprintf(fd, "%f\n", m_spline_r.y(5));
 
120
        fprintf(fd, "%f\n", m_spline_g.x(0));
 
121
        fprintf(fd, "%f\n", m_spline_g.y(0));
 
122
        fprintf(fd, "%f\n", m_spline_g.x(1));
 
123
        fprintf(fd, "%f\n", m_spline_g.y(1));
 
124
        fprintf(fd, "%f\n", m_spline_g.x(2));
 
125
        fprintf(fd, "%f\n", m_spline_g.y(2));
 
126
        fprintf(fd, "%f\n", m_spline_g.x(3));
 
127
        fprintf(fd, "%f\n", m_spline_g.y(3));
 
128
        fprintf(fd, "%f\n", m_spline_g.x(4));
 
129
        fprintf(fd, "%f\n", m_spline_g.y(4));
 
130
        fprintf(fd, "%f\n", m_spline_g.x(5));
 
131
        fprintf(fd, "%f\n", m_spline_g.y(5));
 
132
        fprintf(fd, "%f\n", m_spline_b.x(0));
 
133
        fprintf(fd, "%f\n", m_spline_b.y(0));
 
134
        fprintf(fd, "%f\n", m_spline_b.x(1));
 
135
        fprintf(fd, "%f\n", m_spline_b.y(1));
 
136
        fprintf(fd, "%f\n", m_spline_b.x(2));
 
137
        fprintf(fd, "%f\n", m_spline_b.y(2));
 
138
        fprintf(fd, "%f\n", m_spline_b.x(3));
 
139
        fprintf(fd, "%f\n", m_spline_b.y(3));
 
140
        fprintf(fd, "%f\n", m_spline_b.x(4));
 
141
        fprintf(fd, "%f\n", m_spline_b.y(4));
 
142
        fprintf(fd, "%f\n", m_spline_b.x(5));
 
143
        fprintf(fd, "%f\n", m_spline_b.y(5));
 
144
        fprintf(fd, "%f\n", m_spline_a.x(0));
 
145
        fprintf(fd, "%f\n", m_spline_a.y(0));
 
146
        fprintf(fd, "%f\n", m_spline_a.x(1));
 
147
        fprintf(fd, "%f\n", m_spline_a.y(1));
 
148
        fprintf(fd, "%f\n", m_spline_a.x(2));
 
149
        fprintf(fd, "%f\n", m_spline_a.y(2));
 
150
        fprintf(fd, "%f\n", m_spline_a.x(3));
 
151
        fprintf(fd, "%f\n", m_spline_a.y(3));
 
152
        fprintf(fd, "%f\n", m_spline_a.x(4));
 
153
        fprintf(fd, "%f\n", m_spline_a.y(4));
 
154
        fprintf(fd, "%f\n", m_spline_a.x(5));
 
155
        fprintf(fd, "%f\n", m_spline_a.y(5));
 
156
        double x1,y1,x2,y2;
 
157
        m_profile.values(&x1, &y1, &x2, &y2);
 
158
        fprintf(fd, "%f\n", x1);
 
159
        fprintf(fd, "%f\n", y1);
 
160
        fprintf(fd, "%f\n", x2);
 
161
        fprintf(fd, "%f\n", y2);
 
162
        fclose(fd);
 
163
    }
 
164
 
 
165
    the_application(agg::pix_format_e format, bool flip_y) :
 
166
        agg::platform_support(format, flip_y),
 
167
        m_profile(10.0, 10.0, 200.0, 170.0-5.0,    !flip_y),
 
168
        m_spline_r(210, 10,     210+250, 5+40,  6, !flip_y),
 
169
        m_spline_g(210, 10+40,  210+250, 5+80,  6, !flip_y),
 
170
        m_spline_b(210, 10+80,  210+250, 5+120, 6, !flip_y),
 
171
        m_spline_a(210, 10+120, 210+250, 5+160, 6, !flip_y),
 
172
        m_rbox(10.0, 180.0, 200.0, 300.0, !flip_y),
 
173
 
 
174
        m_pdx(0.0),
 
175
        m_pdy(0.0),
 
176
        m_center_x(center_x),
 
177
        m_center_y(center_y),
 
178
        m_scale(1.0),
 
179
        m_prev_scale(1.0),
 
180
        m_angle(0.0),
 
181
        m_prev_angle(0.0),
 
182
        m_scale_x(1.0),
 
183
        m_prev_scale_x(1.0),
 
184
        m_scale_y(1.0),
 
185
        m_prev_scale_y(1.0),
 
186
        m_mouse_move(false)
 
187
    {
 
188
        add_ctrl(m_profile);
 
189
        add_ctrl(m_spline_r);
 
190
        add_ctrl(m_spline_g);
 
191
        add_ctrl(m_spline_b);
 
192
        add_ctrl(m_spline_a);
 
193
        add_ctrl(m_rbox);
 
194
 
 
195
        m_profile.border_width(2.0, 2.0);
 
196
 
 
197
        m_spline_r.background_color(agg::rgba(1.0, 0.8, 0.8));
 
198
        m_spline_g.background_color(agg::rgba(0.8, 1.0, 0.8));
 
199
        m_spline_b.background_color(agg::rgba(0.8, 0.8, 1.0));
 
200
        m_spline_a.background_color(agg::rgba(1.0, 1.0, 1.0));
 
201
 
 
202
        m_spline_r.border_width(1.0, 2.0);
 
203
        m_spline_g.border_width(1.0, 2.0);
 
204
        m_spline_b.border_width(1.0, 2.0);
 
205
        m_spline_a.border_width(1.0, 2.0);
 
206
        m_rbox.border_width(2.0, 2.0);
 
207
 
 
208
        m_spline_r.point(0, 0.0,     1.0);
 
209
        m_spline_r.point(1, 1.0/5.0, 1.0 - 1.0/5.0);
 
210
        m_spline_r.point(2, 2.0/5.0, 1.0 - 2.0/5.0);
 
211
        m_spline_r.point(3, 3.0/5.0, 1.0 - 3.0/5.0);
 
212
        m_spline_r.point(4, 4.0/5.0, 1.0 - 4.0/5.0);
 
213
        m_spline_r.point(5, 1.0,     0.0);
 
214
        m_spline_r.update_spline();
 
215
 
 
216
        m_spline_g.point(0, 0.0,     1.0);
 
217
        m_spline_g.point(1, 1.0/5.0, 1.0 - 1.0/5.0);
 
218
        m_spline_g.point(2, 2.0/5.0, 1.0 - 2.0/5.0);
 
219
        m_spline_g.point(3, 3.0/5.0, 1.0 - 3.0/5.0);
 
220
        m_spline_g.point(4, 4.0/5.0, 1.0 - 4.0/5.0);
 
221
        m_spline_g.point(5, 1.0,     0.0);
 
222
        m_spline_g.update_spline();
 
223
 
 
224
        m_spline_b.point(0, 0.0,     1.0);
 
225
        m_spline_b.point(1, 1.0/5.0, 1.0 - 1.0/5.0);
 
226
        m_spline_b.point(2, 2.0/5.0, 1.0 - 2.0/5.0);
 
227
        m_spline_b.point(3, 3.0/5.0, 1.0 - 3.0/5.0);
 
228
        m_spline_b.point(4, 4.0/5.0, 1.0 - 4.0/5.0);
 
229
        m_spline_b.point(5, 1.0,     0.0);
 
230
        m_spline_b.update_spline();
 
231
 
 
232
        m_spline_a.point(0, 0.0,     1.0);
 
233
        m_spline_a.point(1, 1.0/5.0, 1.0);
 
234
        m_spline_a.point(2, 2.0/5.0, 1.0);
 
235
        m_spline_a.point(3, 3.0/5.0, 1.0);
 
236
        m_spline_a.point(4, 4.0/5.0, 1.0);
 
237
        m_spline_a.point(5, 1.0,     1.0);
 
238
        m_spline_a.update_spline();
 
239
 
 
240
        m_rbox.add_item("Circular");
 
241
        m_rbox.add_item("Diamond");
 
242
        m_rbox.add_item("Linear");
 
243
        m_rbox.add_item("XY");
 
244
        m_rbox.add_item("sqrt(XY)");
 
245
        m_rbox.add_item("Conic");
 
246
        m_rbox.cur_item(0);
 
247
 
 
248
        FILE* fd = fopen(full_file_name("settings.dat"), "r");
 
249
        if(fd)
 
250
        {
 
251
            float x;
 
252
            float y;
 
253
            float x2;
 
254
            float y2;
 
255
            float t;
 
256
 
 
257
            fscanf(fd, "%f\n", &t); m_center_x = t;
 
258
            fscanf(fd, "%f\n", &t); m_center_y = t;
 
259
            fscanf(fd, "%f\n", &t); m_scale = t;
 
260
            fscanf(fd, "%f\n", &t); m_angle = t;
 
261
            fscanf(fd, "%f\n", &x);
 
262
            fscanf(fd, "%f\n", &y); m_spline_r.point(0, x, y);
 
263
            fscanf(fd, "%f\n", &x);
 
264
            fscanf(fd, "%f\n", &y); m_spline_r.point(1, x, y);
 
265
            fscanf(fd, "%f\n", &x);
 
266
            fscanf(fd, "%f\n", &y); m_spline_r.point(2, x, y);
 
267
            fscanf(fd, "%f\n", &x);
 
268
            fscanf(fd, "%f\n", &y); m_spline_r.point(3, x, y);
 
269
            fscanf(fd, "%f\n", &x);
 
270
            fscanf(fd, "%f\n", &y); m_spline_r.point(4, x, y);
 
271
            fscanf(fd, "%f\n", &x);
 
272
            fscanf(fd, "%f\n", &y); m_spline_r.point(5, x, y);
 
273
            fscanf(fd, "%f\n", &x);
 
274
            fscanf(fd, "%f\n", &y); m_spline_g.point(0, x, y);
 
275
            fscanf(fd, "%f\n", &x);
 
276
            fscanf(fd, "%f\n", &y); m_spline_g.point(1, x, y);
 
277
            fscanf(fd, "%f\n", &x);
 
278
            fscanf(fd, "%f\n", &y); m_spline_g.point(2, x, y);
 
279
            fscanf(fd, "%f\n", &x);
 
280
            fscanf(fd, "%f\n", &y); m_spline_g.point(3, x, y);
 
281
            fscanf(fd, "%f\n", &x);
 
282
            fscanf(fd, "%f\n", &y); m_spline_g.point(4, x, y);
 
283
            fscanf(fd, "%f\n", &x);
 
284
            fscanf(fd, "%f\n", &y); m_spline_g.point(5, x, y);
 
285
            fscanf(fd, "%f\n", &x);
 
286
            fscanf(fd, "%f\n", &y); m_spline_b.point(0, x, y);
 
287
            fscanf(fd, "%f\n", &x);
 
288
            fscanf(fd, "%f\n", &y); m_spline_b.point(1, x, y);
 
289
            fscanf(fd, "%f\n", &x);
 
290
            fscanf(fd, "%f\n", &y); m_spline_b.point(2, x, y);
 
291
            fscanf(fd, "%f\n", &x);
 
292
            fscanf(fd, "%f\n", &y); m_spline_b.point(3, x, y);
 
293
            fscanf(fd, "%f\n", &x);
 
294
            fscanf(fd, "%f\n", &y); m_spline_b.point(4, x, y);
 
295
            fscanf(fd, "%f\n", &x);
 
296
            fscanf(fd, "%f\n", &y); m_spline_b.point(5, x, y);
 
297
            fscanf(fd, "%f\n", &x);
 
298
            fscanf(fd, "%f\n", &y); m_spline_a.point(0, x, y);
 
299
            fscanf(fd, "%f\n", &x);
 
300
            fscanf(fd, "%f\n", &y); m_spline_a.point(1, x, y);
 
301
            fscanf(fd, "%f\n", &x);
 
302
            fscanf(fd, "%f\n", &y); m_spline_a.point(2, x, y);
 
303
            fscanf(fd, "%f\n", &x);
 
304
            fscanf(fd, "%f\n", &y); m_spline_a.point(3, x, y);
 
305
            fscanf(fd, "%f\n", &x);
 
306
            fscanf(fd, "%f\n", &y); m_spline_a.point(4, x, y);
 
307
            fscanf(fd, "%f\n", &x);
 
308
            fscanf(fd, "%f\n", &y); m_spline_a.point(5, x, y);
 
309
            m_spline_r.update_spline();
 
310
            m_spline_g.update_spline();
 
311
            m_spline_b.update_spline();
 
312
            m_spline_a.update_spline();
 
313
            fscanf(fd, "%f\n", &x);
 
314
            fscanf(fd, "%f\n", &y);
 
315
            fscanf(fd, "%f\n", &x2);
 
316
            fscanf(fd, "%f\n", &y2);
 
317
            m_profile.values(x, y, x2, y2);
 
318
            fclose(fd);
 
319
        }
 
320
 
 
321
    }
 
322
 
 
323
 
 
324
    virtual void on_draw()
 
325
    {
 
326
        agg::rasterizer_scanline_aa<> pf;
 
327
 
 
328
        typedef agg::renderer_base<pixfmt> renderer_base;
 
329
        typedef agg::renderer_scanline_aa_solid<renderer_base> renderer_solid;
 
330
        agg::scanline_u8 sl;
 
331
            
 
332
 
 
333
        pixfmt pixf(rbuf_window());
 
334
        renderer_base rb(pixf);
 
335
        renderer_solid r(rb);
 
336
        rb.clear(agg::rgba(0, 0, 0));
 
337
      
 
338
        m_profile.text_size(8.0);
 
339
 
 
340
        agg::render_ctrl(pf, sl, r, m_profile);
 
341
        agg::render_ctrl(pf, sl, r, m_spline_r);
 
342
        agg::render_ctrl(pf, sl, r, m_spline_g);
 
343
        agg::render_ctrl(pf, sl, r, m_spline_b);
 
344
        agg::render_ctrl(pf, sl, r, m_spline_a);
 
345
        agg::render_ctrl(pf, sl, r, m_rbox);
 
346
 
 
347
        double ini_scale = 1.0;
 
348
 
 
349
        agg::trans_affine mtx1;
 
350
        mtx1 *= agg::trans_affine_scaling(ini_scale, ini_scale);
 
351
        mtx1 *= agg::trans_affine_rotation(agg::deg2rad(0.0));
 
352
        mtx1 *= agg::trans_affine_translation(center_x, center_y);
 
353
        mtx1 *= trans_affine_resizing();
 
354
 
 
355
        agg::ellipse e1;
 
356
        e1.init(0.0, 0.0, 110.0, 110.0, 64);
 
357
 
 
358
        agg::trans_affine mtx_g1;
 
359
        mtx_g1 *= agg::trans_affine_scaling(ini_scale, ini_scale);
 
360
        mtx_g1 *= agg::trans_affine_scaling(m_scale, m_scale);
 
361
        mtx_g1 *= agg::trans_affine_scaling(m_scale_x, m_scale_y);
 
362
        mtx_g1 *= agg::trans_affine_rotation(m_angle);
 
363
        mtx_g1 *= agg::trans_affine_translation(m_center_x, m_center_y);
 
364
        mtx_g1 *= trans_affine_resizing();
 
365
        mtx_g1.invert();
 
366
 
 
367
 
 
368
        color_type color_profile[256]; // color_type is defined in pixel_formats.h
 
369
        int i;
 
370
        for(i = 0; i < 256; i++)
 
371
        {
 
372
            color_profile[i] = color_type(agg::rgba(m_spline_r.spline()[i], 
 
373
                                                    m_spline_g.spline()[i],
 
374
                                                    m_spline_b.spline()[i],
 
375
                                                    m_spline_a.spline()[i]));
 
376
        }
 
377
 
 
378
        agg::conv_transform<agg::ellipse, agg::trans_affine> t1(e1, mtx1);
 
379
 
 
380
        gradient_polymorphic_wrapper<agg::gradient_radial>       gr_circle;
 
381
        gradient_polymorphic_wrapper<agg::gradient_diamond>      gr_diamond;
 
382
        gradient_polymorphic_wrapper<agg::gradient_x>            gr_x;
 
383
        gradient_polymorphic_wrapper<agg::gradient_xy>           gr_xy;
 
384
        gradient_polymorphic_wrapper<agg::gradient_sqrt_xy>      gr_sqrt_xy;
 
385
        gradient_polymorphic_wrapper<agg::gradient_conic>        gr_conic;
 
386
 
 
387
        gradient_polymorphic_wrapper_base* gr_ptr = &gr_circle;
 
388
 
 
389
//        gr_circle.m_gradient.init(150, 80, 80);
 
390
 
 
391
        switch(m_rbox.cur_item())
 
392
        {
 
393
            case 1: gr_ptr = &gr_diamond; break;
 
394
            case 2: gr_ptr = &gr_x;       break;
 
395
            case 3: gr_ptr = &gr_xy;      break;
 
396
            case 4: gr_ptr = &gr_sqrt_xy; break;
 
397
            case 5: gr_ptr = &gr_conic;   break;
 
398
        }
 
399
 
 
400
        typedef agg::span_interpolator_linear<> interpolator_type;
 
401
        typedef agg::span_gradient<color_type, 
 
402
                                   interpolator_type,
 
403
                                   gradient_polymorphic_wrapper_base,
 
404
                                   color_function_profile> gradient_span_gen;
 
405
        typedef agg::span_allocator<gradient_span_gen::color_type> gradient_span_alloc;
 
406
        typedef agg::renderer_scanline_aa<renderer_base, gradient_span_gen> renderer_gradient;
 
407
        
 
408
        gradient_span_alloc    span_alloc;
 
409
        color_function_profile colors(color_profile, m_profile.gamma());
 
410
        interpolator_type      inter(mtx_g1);
 
411
        gradient_span_gen      span_gen(span_alloc, inter, *gr_ptr, colors, 0, 150);
 
412
        renderer_gradient      r1(rb, span_gen);
 
413
 
 
414
        pf.add_path(t1);
 
415
        agg::render_scanlines(pf, sl, r1);
 
416
 
 
417
 
 
418
    }
 
419
 
 
420
 
 
421
    virtual void on_mouse_move(int x, int y, unsigned flags)
 
422
    {
 
423
        if(m_mouse_move)
 
424
        {
 
425
            double x2 = x;
 
426
            double y2 = y;
 
427
            trans_affine_resizing().inverse_transform(&x2, &y2);
 
428
 
 
429
            if(flags & agg::kbd_ctrl)
 
430
            {
 
431
                double dx = x2 - m_center_x;
 
432
                double dy = y2 - m_center_y;
 
433
                m_scale_x = m_prev_scale_x * dx / m_pdx;
 
434
                m_scale_y = m_prev_scale_y * dy / m_pdy;
 
435
                force_redraw();
 
436
            }
 
437
            else
 
438
            {
 
439
                if(flags & agg::mouse_left)
 
440
                {
 
441
                    m_center_x = x2 + m_pdx;
 
442
                    m_center_y = y2 + m_pdy;
 
443
                    force_redraw();
 
444
                }
 
445
 
 
446
                if(flags & agg::mouse_right)
 
447
                {
 
448
                    double dx = x2 - m_center_x;
 
449
                    double dy = y2 - m_center_y;
 
450
                    m_scale = m_prev_scale * 
 
451
                              sqrt(dx * dx + dy * dy) / 
 
452
                              sqrt(m_pdx * m_pdx + m_pdy * m_pdy);
 
453
 
 
454
                    m_angle = m_prev_angle + atan2(dy, dx) - atan2(m_pdy, m_pdx);
 
455
                    force_redraw();
 
456
                }
 
457
            }
 
458
        }
 
459
    }
 
460
 
 
461
 
 
462
    virtual void on_mouse_button_down(int x, int y, unsigned flags)
 
463
    {
 
464
        m_mouse_move = true;
 
465
        double x2 = x;
 
466
        double y2 = y;
 
467
        trans_affine_resizing().inverse_transform(&x2, &y2);
 
468
 
 
469
        m_pdx = m_center_x - x2;
 
470
        m_pdy = m_center_y - y2;
 
471
        m_prev_scale = m_scale;
 
472
        m_prev_angle = m_angle + agg::pi;
 
473
        m_prev_scale_x = m_scale_x;
 
474
        m_prev_scale_y = m_scale_y;
 
475
        force_redraw();
 
476
    }
 
477
 
 
478
 
 
479
    virtual void on_mouse_button_up(int x, int y, unsigned flags)
 
480
    {
 
481
        m_mouse_move = false;
 
482
    }
 
483
 
 
484
 
 
485
    virtual void on_key(int x, int y, unsigned key, unsigned flags) 
 
486
    {
 
487
        if(key == agg::key_f1)
 
488
        {
 
489
            FILE* fd = fopen(full_file_name("colors.dat"), "w");
 
490
            int i;
 
491
            for(i = 0; i < 256; i++)
 
492
            {
 
493
                color_type c = agg::rgba(m_spline_r.spline()[i], 
 
494
                                         m_spline_g.spline()[i],
 
495
                                         m_spline_b.spline()[i],
 
496
                                         m_spline_a.spline()[i]);
 
497
                fprintf(fd, "    %3d, %3d, %3d, %3d,\n", c.r, c.g, c.b, c.a);
 
498
            }
 
499
            fclose(fd);
 
500
 
 
501
            fd = fopen(full_file_name("profile.dat"), "w");
 
502
            for(i = 0; i < 256; i++)
 
503
            {
 
504
                fprintf(fd, "%3d, ", unsigned(m_profile.gamma()[i]));
 
505
                if((i & 0xF) == 0xF) fprintf(fd, "\n");
 
506
            }
 
507
            fclose(fd);
 
508
        }
 
509
 
 
510
 
 
511
    }
 
512
 
 
513
};
 
514
 
 
515
 
 
516
 
 
517
int agg_main(int argc, char* argv[])
 
518
{
 
519
    //#ifdef _WIN32
 
520
    //    FILE* fd = fopen("stdout.txt", "w"); fclose(fd);
 
521
    //#endif
 
522
    //AGG_WATCHDOGGY(wd1, false);
 
523
 
 
524
    the_application app(pix_format, flip_y);
 
525
    app.caption("AGG gradients with Mach bands compensation");
 
526
 
 
527
    if(app.init(512, 400, agg::window_resize | agg::window_hw_buffer))
 
528
    {
 
529
        return app.run();
 
530
    }
 
531
    return 1;
 
532
}
 
533
 
 
534