Gnash 0.8.10dev
|
00001 // 00002 // Copyright (C) 2007, 2008, 2009, 2010, 2011 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 class Transform; 00033 } 00034 00035 namespace gnash { 00036 00038 // 00041 // 00044 class DynamicShape 00045 { 00046 public: 00047 00048 DynamicShape(); 00049 00050 ~DynamicShape() {} 00051 00053 void clear(); 00054 00056 void moveTo(boost::int32_t x, boost::int32_t y); 00057 00059 void lineTo(boost::int32_t x, boost::int32_t y, int swfVersion); 00060 00064 void curveTo(boost::int32_t cx, boost::int32_t cy, 00065 boost::int32_t ax, boost::int32_t ay, int swfVersion); 00066 00068 void beginFill(const FillStyle& f); 00069 00071 void endFill(); 00072 00073 const SWFRect& getBounds() const { 00074 return _shape.getBounds(); 00075 } 00076 00077 void setBounds(const SWFRect& bounds) { 00078 _shape.setBounds(bounds); 00079 } 00080 00082 void display(Renderer& renderer, const Transform& xform) const; 00083 00085 // 00095 void lineStyle(boost::uint16_t thickness, const rgba& color, 00096 bool vScale=true, bool hScale=true, 00097 bool pixelHinting=false, 00098 bool noClose=false, 00099 CapStyle startCapStyle=CAP_ROUND, 00100 CapStyle endCapStyle=CAP_ROUND, 00101 JoinStyle joinStyle=JOIN_ROUND, 00102 float miterLimitFactor=1.0f); 00103 00105 void resetLineStyle(); 00106 00110 // 00116 size_t addFillStyle(const FillStyle& stl); 00117 00121 // 00127 size_t add_line_style(const LineStyle& stl); 00128 00129 // Override from DefineShapeTag to call ::finalize 00130 // NOTE: this is not correct in that a call to hitTest should 00131 // not force closing the path being drawn. 00132 // Instead, the closeup should be "temporary" and in 00133 // the pointTestLocal itself (but only for dynamic drawing). 00134 // We need to add a testcase for this as we currently have none. 00135 // The testcase would look like this: 00136 // 00137 // moveTo(0, 0); lineTo(10, 0); lineTo(10, 10); // an L shape so far 00138 // hitTest(8, 2, true); !hitTest(2, 8, true); // imaginarly forming a closed triangle as hitTest is concerned 00139 // lineTo(0, 10); lineTo(0, 0); // explicitly closed as a square now 00140 // hitTest(8, 2, true); hitTest(2, 8, true); // effectively forming a closed square 00141 // 00142 // In the test above, permanently closing on hit-test (what this implementation does) 00143 // would result in a triangle and a stroke, which should fail the last hitTest(2,8). 00144 // 00145 // 00146 bool pointTestLocal(boost::int32_t x, boost::int32_t y, 00147 const SWFMatrix& wm) const 00148 { 00149 finalize(); 00150 return geometry::pointTest(_shape.paths(), _shape.lineStyles(), x, y, 00151 wm); 00152 } 00153 00154 const SWF::ShapeRecord& shapeRecord() const { 00155 return _shape; 00156 } 00157 00159 // 00164 void add_path(const Path& pth); 00165 00167 // 00170 void finalize() const; 00171 00172 private: 00173 00175 // 00182 void startNewPath(bool newShape); 00183 00184 Path* _currpath; 00185 00186 size_t _currfill; 00187 00188 size_t _currline; 00189 00190 // Current pen X position 00191 boost::int32_t _x; 00192 00193 // Current pen Y position 00194 boost::int32_t _y; 00195 00196 mutable bool _changed; 00197 00199 // 00201 mutable SWF::ShapeRecord _shape; 00202 }; 00203 00204 } // end namespace gnash 00205 00206 00207 #endif // GNASH_DYNAMIC_SHAPE_H 00208 00209 00210 // Local Variables: 00211 // mode: C++ 00212 // c-basic-offset: 8 00213 // tab-width: 8 00214 // indent-tabs-mode: t 00215 // End: