summaryrefslogtreecommitdiff
path: root/core/src/fxge/agg/agg23/agg_renderer_base.h
blob: bd1b203b9a73e44fb140e72284bc98a901444012 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163

//----------------------------------------------------------------------------
// Anti-Grain Geometry - Version 2.3
// Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
//
// Permission to copy, use, modify, sell and distribute this software
// is granted provided this copyright notice appears in all copies.
// This software is provided "as is" without express or implied
// warranty, and with no claim as to its suitability for any purpose.
//
//----------------------------------------------------------------------------
// Contact: mcseem@antigrain.com
//          mcseemagg@yahoo.com
//          http://www.antigrain.com
//----------------------------------------------------------------------------
//
// class renderer_base
//
//----------------------------------------------------------------------------
#ifndef AGG_RENDERER_BASE_INCLUDED
#define AGG_RENDERER_BASE_INCLUDED
#include "agg_basics.h"
#include "agg_rendering_buffer.h"
namespace agg
{
template<class PixelFormat> class renderer_base 
{
public:
    typedef PixelFormat pixfmt_type;
    typedef typename pixfmt_type::color_type color_type;
    typedef typename pixfmt_type::row_data row_data;
    typedef typename pixfmt_type::span_data span_data;
    renderer_base() : m_ren(0), m_clip_box(1, 1, 0, 0) {}
    renderer_base(pixfmt_type& ren) :
        m_ren(&ren),
        m_clip_box(0, 0, ren.width() - 1, ren.height() - 1)
    {}
    void attach(pixfmt_type& ren)
    {
        m_ren = &ren;
        m_clip_box = rect(0, 0, ren.width() - 1, ren.height() - 1);
    }
    const pixfmt_type& ren() const
    {
        return *m_ren;
    }
    pixfmt_type& ren()
    {
        return *m_ren;
    }
    unsigned width()  const
    {
        return m_ren->width();
    }
    unsigned height() const
    {
        return m_ren->height();
    }
    void first_clip_box() {}
    bool next_clip_box()
    {
        return false;
    }
    const rect& clip_box() const
    {
        return m_clip_box;
    }
    int         xmin()     const
    {
        return m_clip_box.x1;
    }
    int         ymin()     const
    {
        return m_clip_box.y1;
    }
    int         xmax()     const
    {
        return m_clip_box.x2;
    }
    int         ymax()     const
    {
        return m_clip_box.y2;
    }
    const rect& bounding_clip_box() const
    {
        return m_clip_box;
    }
    int         bounding_xmin()     const
    {
        return m_clip_box.x1;
    }
    int         bounding_ymin()     const
    {
        return m_clip_box.y1;
    }
    int         bounding_xmax()     const
    {
        return m_clip_box.x2;
    }
    int         bounding_ymax()     const
    {
        return m_clip_box.y2;
    }
    void blend_hline(int x1, int y, int x2,
                     const color_type& c, cover_type cover)
    {
        if(x1 > x2) {
            int t = x2;
            x2 = x1;
            x1 = t;
        }
        if(y  > ymax()) {
            return;
        }
        if(y  < ymin()) {
            return;
        }
        if(x1 > xmax()) {
            return;
        }
        if(x2 < xmin()) {
            return;
        }
        if(x1 < xmin()) {
            x1 = xmin();
        }
        if(x2 > xmax()) {
            x2 = xmax();
        }
        m_ren->blend_hline(x1, y, x2 - x1 + 1, c, cover);
    }
    void blend_solid_hspan(int x, int y, int len,
                           const color_type& c,
                           const cover_type* covers)
    {
        if(y > ymax()) {
            return;
        }
        if(y < ymin()) {
            return;
        }
        if(x < xmin()) {
            len -= xmin() - x;
            if(len <= 0) {
                return;
            }
            covers += xmin() - x;
            x = xmin();
        }
        if(x + len > xmax()) {
            len = xmax() - x + 1;
            if(len <= 0) {
                return;
            }
        }
        m_ren->blend_solid_hspan(x, y, len, c, covers);
    }
private:
    pixfmt_type* m_ren;
    rect         m_clip_box;
};
}
#endif