• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • Examples
  • File List
  • File Members

DynamicShape.h

Go to the documentation of this file.
00001 // 
00002 //   Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
00003 // 
00004 // This program is free software; you can redistribute it and/or modify
00005 // it under the terms of the GNU General Public License as published by
00006 // the Free Software Foundation; either version 3 of the License, or
00007 // (at your option) any later version.
00008 // 
00009 // This program is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU General Public License for more details.
00013 // 
00014 // You should have received a copy of the GNU General Public License
00015 // along with this program; if not, write to the Free Software
00016 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00017 
00018 
00019 
00020 #ifndef GNASH_DYNAMIC_SHAPE_H
00021 #define GNASH_DYNAMIC_SHAPE_H
00022 
00023 #include <vector>
00024 #include "LineStyle.h" 
00025 #include "ShapeRecord.h"
00026 
00027 namespace gnash {
00028     class DisplayObject;
00029     class Renderer;
00030     class FillStyle;
00031     class GradientRecord;
00032 }
00033 
00034 namespace gnash {
00035 
00037 //
00040 //
00043 class DynamicShape
00044 {
00045 public:
00046 
00047         DynamicShape();
00048 
00049         ~DynamicShape() {}
00050 
00052         void clear();
00053 
00055         void moveTo(boost::int32_t x, boost::int32_t y);
00056 
00058         void lineTo(boost::int32_t x, boost::int32_t y, int swfVersion);
00059 
00063         void curveTo(boost::int32_t cx, boost::int32_t cy, 
00064                  boost::int32_t ax, boost::int32_t ay, int swfVersion);
00065 
00067         void beginFill(const FillStyle& f);
00068 
00070         void endFill();
00071 
00072     const SWFRect& getBounds() const {
00073         return _shape.getBounds();
00074     }
00075 
00076     void setBounds(const SWFRect& bounds) {
00077         _shape.setBounds(bounds);
00078     }
00079 
00081     void display(Renderer& renderer, const DisplayObject& inst) const;
00082 
00084         //
00103         void lineStyle(boost::uint16_t thickness, const rgba& color,
00104                 bool vScale=true, bool hScale=true,
00105                 bool pixelHinting=false,
00106                 bool noClose=false,
00107                 CapStyle startCapStyle=CAP_ROUND,
00108                 CapStyle endCapStyle=CAP_ROUND,
00109                 JoinStyle joinStyle=JOIN_ROUND,
00110                 float miterLimitFactor=1.0f);
00111 
00113         void resetLineStyle();
00114 
00118         //
00124         size_t addFillStyle(const FillStyle& stl);
00125 
00129         //
00135         size_t add_line_style(const LineStyle& stl);
00136 
00137         // Override from DefineShapeTag to call ::finalize
00138         // NOTE: this is not correct in that a call to hitTest should
00139         //       not force closing the path being drawn.
00140         //       Instead, the closeup should be "temporary" and in
00141         //       the pointTestLocal itself (but only for dynamic drawing).
00142         //       We need to add a testcase for this as we currently have none.
00143         //       The testcase would look like this:
00144         //
00145         //       moveTo(0, 0); lineTo(10, 0); lineTo(10, 10); // an L shape so far
00146         //       hitTest(8, 2, true); !hitTest(2, 8, true); // imaginarly forming a closed triangle as hitTest is concerned
00147         //       lineTo(0, 10); lineTo(0, 0); // explicitly closed as a square now
00148         //       hitTest(8, 2, true); hitTest(2, 8, true); // effectively forming a closed square
00149         //
00150         //       In the test above, permanently closing on hit-test (what this implementation does)
00151         //       would result in a triangle and a stroke, which should fail the last hitTest(2,8).
00152         //
00153         //
00154         bool pointTestLocal(boost::int32_t x, boost::int32_t y,
00155             const SWFMatrix& wm) const
00156         {
00157                 finalize();
00158                 return geometry::pointTest(_shape.paths(), _shape.lineStyles(), x, y,
00159                 wm);
00160         }
00161 
00162     const SWF::ShapeRecord& shapeRecord() const {
00163         return _shape;
00164     }
00165 
00167         //
00172         void add_path(const Path& pth);
00173 
00175         //
00178         void finalize() const;
00179 
00180 private:
00181 
00183         //
00190         void startNewPath(bool newShape);
00191 
00192         Path* _currpath;
00193 
00194         size_t _currfill;
00195 
00196         size_t _currline;
00197 
00198         // Current pen X position
00199         boost::int32_t  _x;
00200 
00201         // Current pen Y position
00202         boost::int32_t  _y;
00203 
00204         mutable bool _changed;
00205 
00207     //
00209     mutable SWF::ShapeRecord _shape;
00210 };
00211 
00212 }       // end namespace gnash
00213 
00214 
00215 #endif // GNASH_DYNAMIC_SHAPE_H
00216 
00217 
00218 // Local Variables:
00219 // mode: C++
00220 // c-basic-offset: 8 
00221 // tab-width: 8
00222 // indent-tabs-mode: t
00223 // End:

Generated on Thu Sep 30 2010 14:34:57 for Gnash by  doxygen 1.7.1