vgfx/drawer.h

Go to the documentation of this file.
00001 /*
00002  * drawer.h
00003  *
00004  * Copyright (C) 2007  Thomas A. Vaughan
00005  * All rights reserved.
00006  *
00007  *
00008  * Redistribution and use in source and binary forms, with or without
00009  * modification, are permitted provided that the following conditions are met:
00010  *     * Redistributions of source code must retain the above copyright
00011  *       notice, this list of conditions and the following disclaimer.
00012  *     * Redistributions in binary form must reproduce the above copyright
00013  *       notice, this list of conditions and the following disclaimer in the
00014  *       documentation and/or other materials provided with the distribution.
00015  *     * Neither the name of the <organization> nor the
00016  *       names of its contributors may be used to endorse or promote products
00017  *       derived from this software without specific prior written permission.
00018  *
00019  * THIS SOFTWARE IS PROVIDED BY THOMAS A. VAUGHAN ''AS IS'' AND ANY
00020  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00021  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00022  * DISCLAIMED. IN NO EVENT SHALL THOMAS A. VAUGHAN BE LIABLE FOR ANY
00023  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00024  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00025  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00026  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00027  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00028  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00029  *
00030  *
00031  * Interface declaration for objects capable of rendering vgfx primitives.
00032  */
00033 
00034 #ifndef WAVEPACKET_VGFX_DRAWER_H__
00035 #define WAVEPACKET_VGFX_DRAWER_H__
00036 
00037 // includes --------------------------------------------------------------------
00038 #include "vgfx.h"
00039 
00040 #include "bezier/quad.h"
00041 #include "bezier/bezier.h"
00042 
00043 
00044 namespace vgfx {
00045 
00046 
00047 /// \ingroup vgfx
00048 /*@{*/
00049 
00050 
00051 enum eBrushAttribute {
00052         // attribute                    enum    value?
00053         eBrush_PenColor                 = 1,    // color as rgba
00054         eBrush_FillColor                = 2,    // color as rgba
00055 
00056         eBrush_PenThickness             = 3,    // thickness in cm
00057 
00058         eBrush_Font                     = 50,   // encoded font info--see
00059                                                 //  objtree/prop_types.h
00060         eBrush_TextFlags                = 60,   // "center", "wrap", etc
00061 
00062         eBrush_Invalid                  = 0
00063 };
00064 
00065 
00066 
00067 /// \ingroup vgfx
00068 ///
00069 /// Clients must implement this if they want to draw
00070 ///
00071 /// The vgfx library is incapable of drawing!  It handles all of the logical
00072 /// details of a vector graphics canvas, but relies on someone else for the
00073 /// actual drawing (if any).
00074 ///
00075 /// This interface is declared so that software layers built on top of vgfx
00076 /// can declare and implement their own bindings to specific rendering
00077 /// technologies. 
00078 class Drawer {
00079 public:
00080         // virtual destructor --------------------------------------------------
00081         virtual ~Drawer(void) throw();
00082 
00083         // vgfx::Drawer class interface methods --------------------------------
00084         virtual void pushBrush(IN dword_t key) = 0;
00085         virtual void popBrush(IN dword_t key) throw() = 0;
00086         virtual void endPath(void) = 0;
00087         virtual void refreshBrush(void) = 0;
00088         virtual void setTransform(IN const xform_2d_t& T) throw() = 0;
00089         virtual void setBrushAttribute(IN eBrushAttribute attribute,
00090                                 IN const char * value) = 0;
00091         virtual void setClipRect(IN float left, IN float top,
00092                                 IN float right, IN float bottom) = 0;
00093         virtual void drawBezier(IN const bezier::curve_t& curve) = 0;
00094         virtual void drawQuadBezier(IN const bezier::quad_bezier_t& qb) = 0 ;
00095         virtual void drawLine(IN const point_t& p0, IN const point_t& p1) = 0;
00096         virtual void drawRect(IN const rect_t& r) = 0;
00097         virtual void fillRect(IN const rect_t& r) = 0;
00098         virtual void drawText(IN const rect_t& r,
00099                                 IN const char * text) = 0;
00100         virtual void getBoundingRect(IN const char * text,
00101                                 OUT rect_t& r) = 0;
00102         virtual void getRootTransform(OUT xform_2d_t& T) throw() = 0;
00103         virtual bool isPrinter(void) const throw() = 0;
00104 };
00105 
00106 
00107 
00108 /// helper class to throw on the stack
00109 class PushPopBrush {
00110 public:
00111         PushPopBrush(IN Drawer * drawer, IN dword_t key) {
00112                         ASSERT(drawer, "push/pop with null drawer");
00113                         m_drawer = drawer;
00114                         m_key = key;
00115                         m_drawer->pushBrush(m_key);
00116                 }
00117 
00118         ~PushPopBrush(void) throw() {
00119                         if (m_drawer)
00120                                 m_drawer->popBrush(m_key);
00121                 }
00122 
00123 private:
00124         Drawer *        m_drawer;
00125         dword_t         m_key;
00126 };
00127 
00128 
00129 
00130 };      // vgfx namespace
00131 
00132 #endif  // WAVEPACKET_VGFX_DRAWER_H__
00133