Home | History | Annotate | Download | only in agg23
      1 
      2 //----------------------------------------------------------------------------
      3 // Anti-Grain Geometry - Version 2.3
      4 // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
      5 //
      6 // Permission to copy, use, modify, sell and distribute this software
      7 // is granted provided this copyright notice appears in all copies.
      8 // This software is provided "as is" without express or implied
      9 // warranty, and with no claim as to its suitability for any purpose.
     10 //
     11 //----------------------------------------------------------------------------
     12 // Contact: mcseem (at) antigrain.com
     13 //          mcseemagg (at) yahoo.com
     14 //          http://www.antigrain.com
     15 //----------------------------------------------------------------------------
     16 //
     17 // class renderer_base
     18 //
     19 //----------------------------------------------------------------------------
     20 #ifndef AGG_RENDERER_BASE_INCLUDED
     21 #define AGG_RENDERER_BASE_INCLUDED
     22 #include "agg_basics.h"
     23 #include "agg_rendering_buffer.h"
     24 namespace agg
     25 {
     26 template<class PixelFormat> class renderer_base
     27 {
     28 public:
     29     typedef PixelFormat pixfmt_type;
     30     typedef typename pixfmt_type::color_type color_type;
     31     typedef typename pixfmt_type::row_data row_data;
     32     typedef typename pixfmt_type::span_data span_data;
     33     renderer_base() : m_ren(0), m_clip_box(1, 1, 0, 0) {}
     34     renderer_base(pixfmt_type& ren) :
     35         m_ren(&ren),
     36         m_clip_box(0, 0, ren.width() - 1, ren.height() - 1)
     37     {}
     38     void attach(pixfmt_type& ren)
     39     {
     40         m_ren = &ren;
     41         m_clip_box = rect(0, 0, ren.width() - 1, ren.height() - 1);
     42     }
     43     const pixfmt_type& ren() const
     44     {
     45         return *m_ren;
     46     }
     47     pixfmt_type& ren()
     48     {
     49         return *m_ren;
     50     }
     51     unsigned width()  const
     52     {
     53         return m_ren->width();
     54     }
     55     unsigned height() const
     56     {
     57         return m_ren->height();
     58     }
     59     void first_clip_box() {}
     60     bool next_clip_box()
     61     {
     62         return false;
     63     }
     64     const rect& clip_box() const
     65     {
     66         return m_clip_box;
     67     }
     68     int         xmin()     const
     69     {
     70         return m_clip_box.x1;
     71     }
     72     int         ymin()     const
     73     {
     74         return m_clip_box.y1;
     75     }
     76     int         xmax()     const
     77     {
     78         return m_clip_box.x2;
     79     }
     80     int         ymax()     const
     81     {
     82         return m_clip_box.y2;
     83     }
     84     const rect& bounding_clip_box() const
     85     {
     86         return m_clip_box;
     87     }
     88     int         bounding_xmin()     const
     89     {
     90         return m_clip_box.x1;
     91     }
     92     int         bounding_ymin()     const
     93     {
     94         return m_clip_box.y1;
     95     }
     96     int         bounding_xmax()     const
     97     {
     98         return m_clip_box.x2;
     99     }
    100     int         bounding_ymax()     const
    101     {
    102         return m_clip_box.y2;
    103     }
    104     void blend_hline(int x1, int y, int x2,
    105                      const color_type& c, cover_type cover)
    106     {
    107         if(x1 > x2) {
    108             int t = x2;
    109             x2 = x1;
    110             x1 = t;
    111         }
    112         if(y  > ymax()) {
    113             return;
    114         }
    115         if(y  < ymin()) {
    116             return;
    117         }
    118         if(x1 > xmax()) {
    119             return;
    120         }
    121         if(x2 < xmin()) {
    122             return;
    123         }
    124         if(x1 < xmin()) {
    125             x1 = xmin();
    126         }
    127         if(x2 > xmax()) {
    128             x2 = xmax();
    129         }
    130         m_ren->blend_hline(x1, y, x2 - x1 + 1, c, cover);
    131     }
    132     void blend_solid_hspan(int x, int y, int len,
    133                            const color_type& c,
    134                            const cover_type* covers)
    135     {
    136         if(y > ymax()) {
    137             return;
    138         }
    139         if(y < ymin()) {
    140             return;
    141         }
    142         if(x < xmin()) {
    143             len -= xmin() - x;
    144             if(len <= 0) {
    145                 return;
    146             }
    147             covers += xmin() - x;
    148             x = xmin();
    149         }
    150         if(x + len > xmax()) {
    151             len = xmax() - x + 1;
    152             if(len <= 0) {
    153                 return;
    154             }
    155         }
    156         m_ren->blend_solid_hspan(x, y, len, c, covers);
    157     }
    158 private:
    159     pixfmt_type* m_ren;
    160     rect         m_clip_box;
    161 };
    162 }
    163 #endif
    164