Update with current status
[gnash.git] / libcore / DragState.h
blobf44330f56d5a8806402736a766e4b1b814c3ac27
1 //
2 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
3 // Free Software Foundation, Inc
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 #ifndef GNASH_DRAG_STATE_H
20 #define GNASH_DRAG_STATE_H
22 #include <boost/optional.hpp>
24 #include "SWFRect.h"
25 #include "DisplayObject.h"
27 // Forward declarations
28 namespace gnash {
29 class DisplayObject;
32 namespace gnash {
34 /// What is being dragged and how
35 class DragState
37 public:
39 DragState(DisplayObject* d, bool lock)
41 _displayObject(d),
42 _lock_centered(lock),
43 _xoffset(0),
44 _yoffset(0)
48 bool isLockCentered() const {
49 return _lock_centered;
52 /// Set displacement offset from origin
53 /// at time of drag start.
54 /// Coordinates are in stage space (twips)
55 ///
56 void setOffset(std::int32_t x, std::int32_t y) {
57 _xoffset = x;
58 _yoffset = y;
61 std::int32_t xOffset() const { return _xoffset; }
62 std::int32_t yOffset() const { return _yoffset; }
64 bool hasBounds() const {
65 return _bounds ? true : false;
68 /// \brief
69 /// Get the boundaries to constraint
70 /// the drag into.
72 /// Coordinates of the rectangle are
73 /// expected in TWIPS.
74 ///
75 /// Note that if hasBounds() is false
76 /// the returned rectangle is the NULL
77 /// rectangle - see SWFRect::is_null().
78 ///
79 const SWFRect& getBounds() const { return *_bounds; }
81 /// \brief
82 /// Set the boundaries to constraint
83 /// the drag into.
85 /// Coordinates of the rectangle are
86 /// expected in TWIPS.
87 ///
88 void setBounds(const SWFRect& bounds) {
89 _bounds = bounds;
92 /// May return NULL !!
93 DisplayObject* getCharacter() const {
94 return _displayObject;
97 /// Reset drag state to its initial condition
98 void reset() {
99 _displayObject = nullptr;
100 _bounds.reset();
101 _lock_centered = false;
104 /// Mark DisplayObject as reachable (if any)
105 void markReachableResources() const {
106 if (_displayObject) _displayObject->setReachable();
109 private:
111 /// Boundaries to constrain the drag into.
112 /// Coordinates in TWIPS.
113 boost::optional<SWFRect> _bounds;
115 DisplayObject* _displayObject;
117 bool _lock_centered;
119 /// Offsets of displacement from DisplayObject origin
120 /// at time of drag start. These are used for non
121 /// lock-centered dragging.
122 /// Coordinates are in stage space (TWIPS)
123 std::int32_t _xoffset;
124 std::int32_t _yoffset;
129 } // namespace gnash
131 #endif // GNASH_DRAG_STATE_H