| 1 |
//---------------------------------------------------------------------------- |
| 2 |
// Anti-Grain Geometry - Version 2.4 |
| 3 |
// Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com) |
| 4 |
// |
| 5 |
// Permission to copy, use, modify, sell and distribute this software |
| 6 |
// is granted provided this copyright notice appears in all copies. |
| 7 |
// This software is provided "as is" without express or implied |
| 8 |
// warranty, and with no claim as to its suitability for any purpose. |
| 9 |
// |
| 10 |
//---------------------------------------------------------------------------- |
| 11 |
// Contact: [email protected] |
| 12 |
// [email protected] |
| 13 |
// http://www.antigrain.com |
| 14 |
//---------------------------------------------------------------------------- |
| 15 |
// |
| 16 |
// Function render_ctrl |
| 17 |
// |
| 18 |
//---------------------------------------------------------------------------- |
| 19 |
|
| 20 |
#ifndef AGG_CTRL_INCLUDED |
| 21 |
#define AGG_CTRL_INCLUDED |
| 22 |
|
| 23 |
#include "agg_trans_affine.h" |
| 24 |
#include "agg_renderer_scanline.h" |
| 25 |
|
| 26 |
namespace agg |
| 27 |
{ |
| 28 |
|
| 29 |
//--------------------------------------------------------------------ctrl |
| 30 |
class ctrl |
| 31 |
{ |
| 32 |
public: |
| 33 |
//-------------------------------------------------------------------- |
| 34 |
virtual ~ctrl() {} |
| 35 |
ctrl(double x1, double y1, double x2, double y2, bool flip_y) : |
| 36 |
m_x1(x1), m_y1(y1), m_x2(x2), m_y2(y2), |
| 37 |
m_flip_y(flip_y), |
| 38 |
m_mtx(0) |
| 39 |
{ |
| 40 |
} |
| 41 |
|
| 42 |
//-------------------------------------------------------------------- |
| 43 |
virtual bool in_rect(double x, double y) const = 0; |
| 44 |
virtual bool on_mouse_button_down(double x, double y) = 0; |
| 45 |
virtual bool on_mouse_button_up(double x, double y) = 0; |
| 46 |
virtual bool on_mouse_move(double x, double y, bool button_flag) = 0; |
| 47 |
virtual bool on_arrow_keys(bool left, bool right, bool down, bool up) = 0; |
| 48 |
|
| 49 |
//-------------------------------------------------------------------- |
| 50 |
void transform(const trans_affine& mtx) { m_mtx = &mtx; } |
| 51 |
void no_transform() { m_mtx = 0; } |
| 52 |
|
| 53 |
//-------------------------------------------------------------------- |
| 54 |
void transform_xy(double* x, double* y) const |
| 55 |
{ |
| 56 |
if(m_flip_y) *y = m_y1 + m_y2 - *y; |
| 57 |
if(m_mtx) m_mtx->transform(x, y); |
| 58 |
} |
| 59 |
|
| 60 |
//-------------------------------------------------------------------- |
| 61 |
void inverse_transform_xy(double* x, double* y) const |
| 62 |
{ |
| 63 |
if(m_mtx) m_mtx->inverse_transform(x, y); |
| 64 |
if(m_flip_y) *y = m_y1 + m_y2 - *y; |
| 65 |
} |
| 66 |
|
| 67 |
//-------------------------------------------------------------------- |
| 68 |
double scale() const { return m_mtx ? m_mtx->scale() : 1.0; } |
| 69 |
|
| 70 |
private: |
| 71 |
ctrl(const ctrl&); |
| 72 |
const ctrl& operator = (const ctrl&); |
| 73 |
|
| 74 |
protected: |
| 75 |
double m_x1; |
| 76 |
double m_y1; |
| 77 |
double m_x2; |
| 78 |
double m_y2; |
| 79 |
|
| 80 |
private: |
| 81 |
bool m_flip_y; |
| 82 |
const trans_affine* m_mtx; |
| 83 |
}; |
| 84 |
|
| 85 |
|
| 86 |
//-------------------------------------------------------------------- |
| 87 |
template<class Rasterizer, class Scanline, class Renderer, class Ctrl> |
| 88 |
void render_ctrl(Rasterizer& ras, Scanline& sl, Renderer& r, Ctrl& c) |
| 89 |
{ |
| 90 |
unsigned i; |
| 91 |
for(i = 0; i < c.num_paths(); i++) |
| 92 |
{ |
| 93 |
ras.reset(); |
| 94 |
ras.add_path(c, i); |
| 95 |
render_scanlines_aa_solid(ras, sl, r, c.color(i)); |
| 96 |
} |
| 97 |
} |
| 98 |
|
| 99 |
|
| 100 |
//-------------------------------------------------------------------- |
| 101 |
template<class Rasterizer, class Scanline, class Renderer, class Ctrl> |
| 102 |
void render_ctrl_rs(Rasterizer& ras, Scanline& sl, Renderer& r, Ctrl& c) |
| 103 |
{ |
| 104 |
unsigned i; |
| 105 |
for(i = 0; i < c.num_paths(); i++) |
| 106 |
{ |
| 107 |
ras.reset(); |
| 108 |
ras.add_path(c, i); |
| 109 |
r.color(c.color(i)); |
| 110 |
render_scanlines(ras, sl, r); |
| 111 |
} |
| 112 |
} |
| 113 |
|
| 114 |
|
| 115 |
} |
| 116 |
|
| 117 |
|
| 118 |
#endif |