1 // StaticText.h: StaticText DisplayObject implementation for Gnash.
3 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Free Software
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.
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.
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
20 #ifndef GNASH_STATIC_TEXT_H
21 #define GNASH_STATIC_TEXT_H
23 #include "smart_ptr.h" // GNASH_USE_GC
24 #include "DisplayObject.h" // for inheritance
25 #include "swf/DefineTextTag.h"
28 #include <boost/dynamic_bitset.hpp>
29 #include <boost/intrusive_ptr.hpp>
32 // Forward declarations
41 /// Static text fields, SWF-defined with read-only text.
43 /// StaticText objects hold mutable selection and color information.
44 class StaticText
: public DisplayObject
48 StaticText(movie_root
& mr
, as_object
* object
, const SWF::DefineTextTag
* def
,
49 DisplayObject
* parent
)
51 DisplayObject(mr
, object
, parent
),
53 _selectionColor(0, 255, 255, 255)
58 /// Return a pointer to this if our definition contains any static text.
60 /// This is non-const because a TextSnapshot needs to add selection and
61 /// color information to this StaticText. It also resets selection.
63 /// @param to A vector of pointers to TextRecords containing text.
64 /// @param numChars The total number of DisplayObjects in all TextRecords is
65 /// written to this variable.
66 /// Note: This function always removes any existing selection and resizes
67 /// the bitset to the number of DisplayObjects in all TextRecords.
68 virtual StaticText
* getStaticText(std::vector
<const SWF::TextRecord
*>& to
,
71 virtual void display(Renderer
& renderer
, const Transform
& xform
);
73 void setSelected(size_t pos
, bool selected
) {
74 _selectedText
.set(pos
, selected
);
77 /// Return a bitset showing which DisplayObjects (by index) are selected.
79 /// Note: mutable information is meaningless until the StaticText is
80 /// queried with getStaticText(). This is because under normal
81 /// circumstances there is no need for it.
82 /// Note also: the size() member of boost::dynamic_bitset returns 0 before
83 /// getStaticText() is called; afterwards it is equivalent to the
84 /// number of DisplayObjects in the StaticText's definition.
85 const boost::dynamic_bitset
<>& getSelected() const {
89 void setSelectionColor(boost::uint32_t color
);
91 virtual SWFRect
getBounds() const {
92 return _def
->bounds();
95 virtual bool pointInShape(boost::int32_t x
, boost::int32_t y
) const;
97 const rgba
& selectionColor() const {
98 return _selectionColor
;
103 const boost::intrusive_ptr
<const SWF::DefineTextTag
> _def
;
105 /// A bitmask indicating which static text DisplayObjects are selected
107 /// This is only present for static text fields, and only after
108 /// a TextSnapshot has queried the DisplayObject for text.
109 boost::dynamic_bitset
<> _selectedText
;
111 /// The color of the background for selected DisplayObjects.
113 /// This is alawys opaque.
114 rgba _selectionColor
;
119 } // end namespace gnash
127 // indent-tabs-mode: t