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