Make automated FSCommand invocation tests show player-side output.
[gnash.git] / libcore / InteractiveObject.h
blobff46e38069e21ef994c7134996f69d648897a2d4
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_INTERACTIVE_DISPLAY_OBJECT_H
20 #define GNASH_INTERACTIVE_DISPLAY_OBJECT_H
22 #include <vector>
23 #include <cassert>
25 #include "DisplayObject.h" // for inheritance
26 #include "log.h"
27 #include "as_object.h" // for getRoot()
29 namespace gnash {
30 class StaticText;
31 namespace SWF {
32 class TextRecord;
36 namespace gnash {
38 /// The base class for interactive objects.
40 /// Objects of type InteractiveObject can receive focus, mouse events,
41 /// and key events for user interaction.
43 /// Derived classes include TextField, Button, and MovieClip.
44 class InteractiveObject : public DisplayObject
47 public:
49 InteractiveObject(as_object* object, DisplayObject* parent)
51 DisplayObject(getRoot(*object), object, parent)
53 // It's a bit too late for this assertion as we've already
54 // deferenced it. All InteractiveObjects are AS-referenceable,
55 // so they must have an object.
56 assert(object);
59 virtual ~InteractiveObject() {}
61 /// Render this InteractiveObject
62 virtual void display(Renderer& renderer, const Transform& xform) = 0;
64 /// Whether the DisplayObject can handle a mouse event.
66 /// @return true if the DisplayObject can handle mouse
67 /// events
68 virtual bool mouseEnabled() const = 0;
70 /// ActionScript property of Buttons and MovieClips altering mouse handling
71 virtual bool trackAsMenu() {
72 return false;
75 /// Allow extraction of static text.
77 /// Default returns 0, implemented only for DefineText though
78 /// DisplayObject.
79 virtual StaticText* getStaticText(std::vector<const SWF::TextRecord*>&,
80 size_t&) {
81 return nullptr;
84 /// Returns local, untransformed bounds of this DisplayObject in TWIPS
86 /// Container DisplayObjects (sprite and buttons) return the composite
87 /// bounds of all their children, appropriately transformed with
88 /// their local SWFMatrix.
89 virtual SWFRect getBounds() const = 0;
91 /// \brief
92 /// Return the topmost entity covering the given point
93 /// and enabled to receive mouse events.
95 /// Return NULL if no "active" entity is found under the pointer.
96 ///
97 /// Coordinates of the point are given in parent's coordinate space.
98 /// This means that in order to convert the point to the local coordinate
99 /// space you need to apply an inverse transformation using this
100 /// DisplayObject SWFMatrix. Example:
102 /// point p(x,y);
103 /// getMatrix().transform_by_inverse(p);
104 /// -- p is now in local coordinates
106 /// Don't blame me for this mess, I'm just trying to document the existing
107 /// functions ... --strk
109 /// @param x
110 /// X ordinate of the pointer, in parent's coordinate space.
112 /// @param y
113 /// Y ordinate of the pointer, in parent's coordiante space.
115 virtual InteractiveObject* topmostMouseEntity(std::int32_t /*x*/,
116 std::int32_t /*y*/) = 0;
118 /// Called whenever a mouse event affects this InteractiveObject.
120 /// All InteractiveObjects (Button, MovieClip, TextField) can handle
121 /// mouse input, so must override this function.
122 virtual void mouseEvent(const event_id& id) = 0;
124 /// Return true if the given point falls in this DisplayObject's shape
126 /// Point coordinates are in world TWIPS
128 /// The default implementation warns about a missing
129 /// override and invokes pointInBounds().
132 virtual bool pointInShape(std::int32_t x, std::int32_t y) const
134 log_error("Character %s did not override pointInShape() - "
135 "using pointInBounds() instead", typeid(*this).name());
136 return pointInBounds(x, y);
139 void add_invalidated_bounds(InvalidatedRanges& ranges, bool force) = 0;
144 } // namespace gnash
147 #endif
150 // Local Variables:
151 // mode: C++
152 // indent-tabs-mode: t
153 // End: