Gnash  0.8.11dev
LineStyle.h
Go to the documentation of this file.
1 // LineStyle.h Line style types.
2 //
3 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
4 // Free Software Foundation, Inc
5 //
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 3 of the License, or
9 // (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 //
20 // Based on public domain work by Thatcher Ulrich <tu@tulrich.com> 2003
21 
22 #ifndef GNASH_LINESTYLE_H
23 #define GNASH_LINESTYLE_H
24 
25 #include "RGBA.h"
26 #include "SWF.h"
27 #include <utility>
28 
29 namespace gnash {
30  class SWFStream;
31  class movie_definition;
32  class RunResources;
33 }
34 
35 namespace gnash {
36 
37 enum CapStyle {
38  CAP_ROUND = 0,
39  CAP_NONE = 1,
40  CAP_SQUARE = 2
41 };
42 
43 enum JoinStyle {
46  JOIN_MITER = 2
47 };
48 
50 class LineStyle
51 {
52 public:
53 
55  LineStyle();
56 
70  LineStyle(std::uint16_t width, rgba color,
71  bool scaleThicknessVertically=true,
73  bool pixelHinting=false,
74  bool noClose=false,
78  float miterLimitFactor=1.0f
79  )
80  :
81  m_width(width),
82  m_color(std::move(color)),
83  _scaleVertically(scaleThicknessVertically),
84  _scaleHorizontally(scaleThicknessHorizontally),
85  _pixelHinting(pixelHinting),
86  _noClose(noClose),
87  _startCapStyle(startCapStyle),
88  _endCapStyle(endCapStyle),
89  _joinStyle(joinStyle),
90  _miterLimitFactor(miterLimitFactor)
91  {
92  }
93 
95  //
102  const RunResources& r);
103 
107  const RunResources& r, LineStyle *pOther);
108 
110  std::uint16_t getThickness() const {
111  return m_width;
112  }
113 
116  return _scaleVertically;
117  }
118 
121  return _scaleHorizontally;
122  }
123 
126  return _startCapStyle;
127  }
128 
131  return _endCapStyle;
132  }
133 
136  return _joinStyle;
137  }
138 
140  float miterLimitFactor() const {
141  return _miterLimitFactor;
142  }
143 
146  bool noClose() const {
147  return _noClose;
148  }
149 
151  bool doPixelHinting() const {
152  return _pixelHinting;
153  }
154 
156  const rgba& get_color() const { return m_color; }
157 
159  //
165  void set_lerp(const LineStyle& ls1, const LineStyle& ls2, float ratio);
166 
167 private:
168 
170  std::uint16_t m_width;
171 
172  rgba m_color;
173 
174  bool _scaleVertically;
175 
176  bool _scaleHorizontally;
177 
178  bool _pixelHinting;
179 
180  bool _noClose;
181 
182  CapStyle _startCapStyle;
183 
184  CapStyle _endCapStyle;
185 
186  JoinStyle _joinStyle;
187 
188  float _miterLimitFactor;
189 };
190 
191 inline void
192 setLerp(LineStyle& s, const LineStyle& ls1, const LineStyle& ls2, double ratio)
193 {
194  s.set_lerp(ls1, ls2, ratio);
195 }
196 
197 } // namespace gnash
198 
199 #endif
200 
201 // Local Variables:
202 // mode: C++
203 // indent-tabs-mode: t
204 // End:
gnash::CAP_NONE
@ CAP_NONE
Definition: LineStyle.h:39
gnash::LineStyle::joinStyle
JoinStyle joinStyle() const
Return the join style.
Definition: LineStyle.h:135
TypesParser.h
gnash::SWF::TagType
TagType
SWF tag types. Symbolic names copied from Ming.
Definition: SWF.h:31
gnash::SWF::DEFINESHAPE
@ DEFINESHAPE
Definition: SWF.h:34
LOG_ONCE
#define LOG_ONCE(x)
Definition: log.h:49
gnash::rgba
A basic RGBA type.
Definition: RGBA.h:36
gnash::OptionalFillPair
std::pair< FillStyle, boost::optional< FillStyle > > OptionalFillPair
Either a single or a morph-pair FillStyle.
Definition: TypesParser.h:52
_
#define _(String)
Definition: log.h:44
gnash
Anonymous namespace for callbacks, local functions, event handlers etc.
Definition: dbus_ext.cpp:41
gnash::LineStyle::noClose
bool noClose() const
Definition: LineStyle.h:146
gnash::frnd
int frnd(float f)
Definition: GnashNumeric.h:91
gnash::key::s
@ s
Definition: GnashKey.h:165
gnash::SWF::DEFINEMORPHSHAPE2
@ DEFINEMORPHSHAPE2
Definition: SWF.h:111
gnash::CAP_SQUARE
@ CAP_SQUARE
Definition: LineStyle.h:40
gnash::JOIN_BEVEL
@ JOIN_BEVEL
Definition: LineStyle.h:45
gnash::LineStyle::endCapStyle
CapStyle endCapStyle() const
Return the end cap style.
Definition: LineStyle.h:130
gnash::movie_definition
Client program's interface to the definition of a movie or sprite.
Definition: movie_definition.h:96
gnash::log_error
void log_error(StringType msg, Args... args)
Definition: log.h:283
gnash::SWFStream::read_short_ufixed
float read_short_ufixed()
Read a 8.8 fixed point unsigned value.
Definition: SWFStream.cpp:228
gnash::LineStyle::doPixelHinting
bool doPixelHinting() const
Return true if pixel hinting should be activated.
Definition: LineStyle.h:151
gnash::LineStyle::miterLimitFactor
float miterLimitFactor() const
Return the miter limit factor.
Definition: LineStyle.h:140
gnash::key::t
@ t
Definition: GnashKey.h:166
color
const VGfloat color[4]
Definition: testr_gtk.cpp:82
gnash::LineStyle::set_lerp
void set_lerp(const LineStyle &ls1, const LineStyle &ls2, float ratio)
Set this style to the interpolation of the given one.
Definition: LineStyle.cpp:179
gnash::key::r
@ r
Definition: GnashKey.h:164
gnash::lerp
T lerp(T a, T b, T f)
Definition: GnashNumeric.h:85
gnash::LineStyle::read
void read(SWFStream &in, SWF::TagType t, movie_definition &md, const RunResources &r)
Read the line style from an SWF stream.
Definition: LineStyle.cpp:123
gnash::SWF::DEFINEMORPHSHAPE
@ DEFINEMORPHSHAPE
Definition: SWF.h:76
gnash::CAP_ROUND
@ CAP_ROUND
Definition: LineStyle.h:38
gnash::LineStyle::read_morph
void read_morph(SWFStream &in, SWF::TagType t, movie_definition &md, const RunResources &r, LineStyle *pOther)
Definition: LineStyle.cpp:71
gnash::SWF::DEFINESHAPE2
@ DEFINESHAPE2
Definition: SWF.h:54
gnash::LineStyle
For the outside of outline shapes, or just bare lines.
Definition: LineStyle.h:51
gnash::SWF::DEFINESHAPE4_
@ DEFINESHAPE4_
Definition: SWF.h:97
RGBA.h
gnash::LineStyle::scaleThicknessHorizontally
bool scaleThicknessHorizontally() const
Return true if line thickness should be scaled horizontally.
Definition: LineStyle.h:120
gnash::LineStyle::scaleThicknessVertically
bool scaleThicknessVertically() const
Return true if line thickness should be scaled vertically.
Definition: LineStyle.h:115
gnash::setLerp
void setLerp(FillStyle &f, const FillStyle &a, const FillStyle &b, double t)
Set the FillStyle to a lerp of a and b.
Definition: FillStyle.cpp:221
gnash::JOIN_ROUND
@ JOIN_ROUND
Definition: LineStyle.h:44
gnash::LineStyle::startCapStyle
CapStyle startCapStyle() const
Return the start cap style.
Definition: LineStyle.h:125
GnashNumeric.h
gnash::JOIN_MITER
@ JOIN_MITER
Definition: LineStyle.h:46
gnash::RunResources
Class to group together per-run and external resources for Gnash.
Definition: RunResources.h:54
gnash::LineStyle::LineStyle
LineStyle()
Construct a default LineStyle.
Definition: LineStyle.cpp:55
gnash::readFills
OptionalFillPair readFills(SWFStream &in, SWF::TagType t, movie_definition &md, bool readMorph)
Read FillStyles from a stream.
Definition: TypesParser.cpp:161
log.h
gnash::readRGB
rgba readRGB(SWFStream &in)
Read an RGB rgba from input stream.
Definition: TypesParser.cpp:106
gnash::LineStyle::LineStyle
LineStyle(std::uint16_t width, rgba color, bool scaleThicknessVertically=true, bool scaleThicknessHorizontally=true, bool pixelHinting=false, bool noClose=false, CapStyle startCapStyle=CAP_ROUND, CapStyle endCapStyle=CAP_ROUND, JoinStyle joinStyle=JOIN_ROUND, float miterLimitFactor=1.0f)
Definition: LineStyle.h:70
gnash::CapStyle
CapStyle
Definition: LineStyle.h:37
gnash::LineStyle::get_color
const rgba & get_color() const
Return line color and alpha.
Definition: LineStyle.h:156
gnash::SWF::DEFINESHAPE4
@ DEFINESHAPE4
Definition: SWF.h:110
gnash::key::f
@ f
Definition: GnashKey.h:152
gnash::LineStyle::getThickness
std::uint16_t getThickness() const
Return thickness of the line, in TWIPS.
Definition: LineStyle.h:110
SWF.h
gnash::SWFStream::read_u16
std::uint16_t read_u16()
Read a aligned unsigned 16-bit value from the stream.
Definition: SWFStream.cpp:332
RunResources.h
LineStyle.h
gnash::JoinStyle
JoinStyle
Definition: LineStyle.h:43
gnash::SWFStream::read_u8
std::uint8_t read_u8()
Read a aligned unsigned 8-bit value from the stream.
Definition: SWFStream.cpp:319
movie_definition.h
gnash::SWFStream
SWF stream wrapper class.
Definition: SWFStream.h:59
FillStyle.h
gnash::SWFStream::ensureBytes
void ensureBytes(unsigned long needed)
Ensure the requested number of bytes are available for an aligned read in the currently opened tag.
Definition: SWFStream.cpp:50
width
@ width
Definition: klash_part.cpp:329
GnashException.h
SWFStream.h
gnash::SWF::DEFINEMORPHSHAPE2_
@ DEFINEMORPHSHAPE2_
Definition: SWF.h:98
gnash::readRGBA
rgba readRGBA(SWFStream &in)
Read an RGBA rgba from input stream.
Definition: TypesParser.cpp:95