vgfx.cpp

Go to the documentation of this file.
00001 /*
00002  * vgfx.cpp
00003  *
00004  * Copyright (C) 2007,2009   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  * Implementation of vector graphics API (see vgfx.h).
00032  * This contains the core routines, with separate files for
00033  * specific primitives.
00034  */
00035 
00036 // includes --------------------------------------------------------------------
00037 #include "vgfx.h"               // always include our own header first!
00038 #include "drawer.h"
00039 
00040 #include "common/wave_ex.h"
00041 
00042 #include "util/parsing.h"
00043 
00044 
00045 
00046 namespace vgfx {
00047 
00048 
00049 // virtual destructor implementation
00050 Drawer::~Drawer(void) throw() { }
00051 
00052 Primitive::Primitive(void) throw() : m_refcount(0) { }
00053 Primitive::~Primitive(void) throw() { }
00054 
00055 
00056 
00057 ////////////////////////////////////////////////////////////////////////////////
00058 //
00059 //      Primitive -- default implementation of vgfx::Primitive methods
00060 //
00061 ////////////////////////////////////////////////////////////////////////////////
00062 
00063 const char *
00064 Primitive::getID(void)
00065 const
00066 throw()
00067 {
00068         return m_id.c_str();
00069 }
00070 
00071 
00072 
00073 void
00074 Primitive::setID
00075 (
00076 IN const char * id
00077 )
00078 {
00079         ASSERT(id, "null id in Primitive::setID()");
00080         m_id = id;
00081 }
00082 
00083 
00084 
00085 void
00086 Primitive::listContainers
00087 (
00088 IN const VecString& path,
00089 OUT VecString& ids
00090 )
00091 const
00092 {
00093         WAVE_EX(wex);
00094         wex << "Objects of type " << this->getType();
00095         wex << " do not support listContainers() calls.";
00096 }
00097 
00098 
00099 bool
00100 Primitive::doesContainerExist
00101 (
00102 IN const VecString& path
00103 )
00104 const
00105 {
00106         return false;
00107 }
00108 
00109 
00110 
00111 bool
00112 Primitive::canCreateContainer
00113 (
00114 IN const VecString& path
00115 )
00116 const
00117 {
00118         return false;
00119 }
00120 
00121 
00122 
00123 void
00124 Primitive::removeContainer
00125 (
00126 IN const VecString& path
00127 )
00128 {
00129         WAVE_EX(wex);
00130         wex << "Primitives of type '" << this->getType() << "' do not support ";
00131         wex << "removeContainer() calls.";
00132 }
00133 
00134 
00135 
00136 void
00137 Primitive::getContainerDictionary
00138 (
00139 IN const VecString& path,
00140 OUT dictionary_t& data
00141 )
00142 const
00143 {
00144         WAVE_EX(wex);
00145         wex << "Primitives of type '" << this->getType() << "' do not support ";
00146         wex << "getContainerDictionary() calls.";
00147 }
00148 
00149 
00150 
00151 void
00152 Primitive::setContainerDictionary
00153 (
00154 IN const VecString& path,
00155 IN const dictionary_t& data
00156 )
00157 {
00158         WAVE_EX(wex);
00159         wex << "Primitives of type '" << this->getType() << "' do not support ";
00160         wex << "getContainerDictionary() calls.";
00161 }
00162 
00163 
00164 
00165 void
00166 Primitive::draw
00167 (
00168 IN Drawer * drawer,
00169 IN const rect_t& r,
00170 IN const xform_2d_t& T
00171 )
00172 {
00173         ASSERT(drawer, "null drawer");
00174         // nothing to draw by default
00175 }
00176 
00177 
00178 
00179 bool
00180 Primitive::getPrimitive
00181 (
00182 IN const char * tag_path,
00183 IN const xform_2d_t& T,
00184 OUT visit_result_t& vr
00185 )
00186 {
00187         ASSERT(tag_path, "null");
00188 
00189         WAVE_EX(wex);
00190         wex << "primitives of type '" << this->getType() << "' do not support ";
00191         wex << "getPrimitive() calls.";
00192 
00193         return false;
00194 }
00195 
00196 
00197 
00198 bool
00199 Primitive::visit
00200 (
00201 IN const rect_t& r,
00202 IN const xform_2d_t& T,         // local --> global
00203 IN const char * tag_path,
00204 IN callback_t callback,
00205 IN void * context,
00206 IN eHitDetect hit
00207 )
00208 {
00209         ASSERT(callback, "Primitive::visit() called with null callback");
00210 
00211         // default implementation -- callback!  We don't care about input rect
00212         visit_result_t vr;
00213         vr.p = this;
00214         vr.tag_path = tag_path;
00215         vr.T = T;
00216         return callback(context, vr);
00217 }
00218 
00219 
00220 
00221 ////////////////////////////////////////////////////////////////////////////////
00222 //
00223 //      static helper methods
00224 //
00225 ////////////////////////////////////////////////////////////////////////////////
00226 
00227 
00228 ////////////////////////////////////////////////////////////////////////////////
00229 //
00230 //      public API
00231 //
00232 ////////////////////////////////////////////////////////////////////////////////
00233 
00234 #define CREATE(name)                                                    \
00235         if ( !strcmp( type, #name ) )                                   \
00236         {                                                               \
00237                 init_##name##_t init;                                   \
00238                 init_##name##_from_data (data, init);                   \
00239                 return create_##name (init);                            \
00240         }
00241 
00242 smart_ptr<Primitive>
00243 Primitive::create
00244 (
00245 IN const char * type,
00246 IN const dictionary_t& data
00247 )
00248 {
00249         ASSERT(type, "null primitive type name passed in");
00250 
00251         // DPRINTF("Primitive is of type '%s'...", type);
00252 
00253         // miniscule efficiency wins if these are ordered by expected frequency
00254         CREATE(line)
00255         CREATE(quad)
00256 //      CREATE(dxdy)
00257         CREATE(rect)
00258         CREATE(bezier)
00259         CREATE(text)
00260 //      CREATE(point)
00261 
00262         ASSERT(false, "Unrecognized primitive type: '%s'", type);
00263         return 0;
00264 }
00265 
00266 
00267 
00268 };      // vgfx namespace
00269