Gnash 0.8.10dev
Button.h
Go to the documentation of this file.
00001 // 
00002 //   Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010,
00003 //   2011 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 // SWF buttons.  Mouse-sensitive update/display, actions, etc.
00021 
00022 
00023 #ifndef GNASH_BUTTON_H
00024 #define GNASH_BUTTON_H
00025 
00026 #include "InteractiveObject.h" // for inheritance
00027 
00028 #include <boost/intrusive_ptr.hpp>
00029 #include <vector>
00030 #include <set>
00031 
00032 // Forward declarations.
00033 namespace gnash {
00034     namespace SWF {
00035         class DefineButtonTag;
00036     }
00037 }
00038 
00039 namespace gnash {
00040 //
00041 // Button
00042 //
00043 
00044 class Button : public InteractiveObject
00045 {
00046 public:
00047 
00048         typedef std::vector<DisplayObject*> DisplayObjects;
00049         typedef std::vector<const DisplayObject*> ConstDisplayObjects;
00050         
00052     typedef std::set<int> ActiveRecords;
00053 
00054         enum mouse_flags
00055         {
00056                 FLAG_IDLE = 0,
00057                 FLAG_OVER = 1,
00058                 FLAG_DOWN = 2,
00059                 OVER_DOWN = FLAG_OVER | FLAG_DOWN,
00060 
00061                 // aliases
00062                 OVER_UP = FLAG_OVER,
00063                 OUT_DOWN = FLAG_DOWN
00064         };
00065 
00066         enum MouseState
00067         {
00068                 MOUSESTATE_UP = 0,
00069                 MOUSESTATE_DOWN,
00070                 MOUSESTATE_OVER,
00071                 MOUSESTATE_HIT
00072         };
00073 
00075     //
00077         Button(as_object* object, const SWF::DefineButtonTag* def,
00078             DisplayObject* parent);
00079 
00080         ~Button();
00081         
00082     static const char* mouseStateName(MouseState s);
00083 
00084         bool mouseEnabled() const { return true; }
00085 
00086     virtual bool trackAsMenu();
00087 
00088         // called from keypress listener only
00089         void notifyEvent(const event_id& id);
00090 
00092         virtual void display(Renderer& renderer, const Transform& xform);
00093         
00094         void set_current_state(MouseState new_state);
00095 
00099         //
00102         virtual InteractiveObject* topmostMouseEntity(boost::int32_t x,
00103             boost::int32_t y);
00104         
00105         virtual void mouseEvent(const event_id& event);
00106 
00107     virtual bool handleFocus();
00108 
00109         void add_invalidated_bounds(InvalidatedRanges& ranges, bool force);
00110         
00111         virtual SWFRect getBounds() const;
00112         
00113         // See dox in DisplayObject.h
00114         bool pointInShape(boost::int32_t x, boost::int32_t y) const;
00115 
00116         bool isEnabled();
00117 
00119         void destroy();
00120 
00122     //
00125     //
00128     virtual void construct(as_object* init = 0);
00129 
00130 #ifdef USE_SWFTREE
00131         // Override to append button DisplayObjects info, see dox in DisplayObject.h
00132         virtual InfoTree::iterator getMovieInfo(InfoTree& tr,
00133             InfoTree::iterator it);
00134 #endif
00135 
00136 protected:
00137         
00139         virtual bool unloadChildren();
00140 
00142         //
00148         void markOwnResources() const;
00149 
00150 private:
00151 
00153         //
00162         void getActiveCharacters(DisplayObjects& list, bool includeUnloaded=false);
00163 
00165     //
00170         void getActiveCharacters(ConstDisplayObjects& list) const;
00171 
00174         //
00181         void get_active_records(ActiveRecords& list, MouseState state);
00182 
00184     virtual int getDefinitionVersion() const;
00185         
00186         MouseState _mouseState;
00187     
00188     const boost::intrusive_ptr<const SWF::DefineButtonTag> _def;
00189 
00190         DisplayObjects _stateCharacters;
00191 
00192         DisplayObjects _hitCharacters;
00193 
00194 
00195 };
00196 
00197 
00199 void button_class_init(as_object& global, const ObjectURI& uri);
00200 
00201 void registerButtonNative(as_object& global);
00202 
00203 }       // end namespace gnash
00204 
00205 
00206 #endif // GNASH_BUTTON_H
00207 
00208 
00209 // Local Variables:
00210 // mode: C++
00211 // c-basic-offset: 8 
00212 // tab-width: 8
00213 // indent-tabs-mode: t
00214 // End: