Gnash  0.8.10
Button.h
Go to the documentation of this file.
00001 // 
00002 //   Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
00003 //   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 <boost/intrusive_ptr.hpp>
00027 #include <vector>
00028 #include <set>
00029 
00030 #include "InteractiveObject.h" 
00031 #include "GnashKey.h"
00032 
00033 // Forward declarations.
00034 namespace gnash {
00035     namespace SWF {
00036         class DefineButtonTag;
00037     }
00038 }
00039 
00040 namespace gnash {
00041 
00043 class Button : public InteractiveObject
00044 {
00045 public:
00046 
00047     typedef std::vector<DisplayObject*> DisplayObjects;
00048     typedef std::vector<const DisplayObject*> ConstDisplayObjects;
00049     
00051     typedef std::set<int> ActiveRecords;
00052 
00053     enum mouse_flags
00054     {
00055         FLAG_IDLE = 0,
00056         FLAG_OVER = 1,
00057         FLAG_DOWN = 2,
00058         OVER_DOWN = FLAG_OVER | FLAG_DOWN,
00059 
00060         // aliases
00061         OVER_UP = FLAG_OVER,
00062         OUT_DOWN = FLAG_DOWN
00063     };
00064 
00065     enum MouseState
00066     {
00067         MOUSESTATE_UP = 0,
00068         MOUSESTATE_DOWN,
00069         MOUSESTATE_OVER,
00070         MOUSESTATE_HIT
00071     };
00072 
00074     //
00076     Button(as_object* object, const SWF::DefineButtonTag* def,
00077             DisplayObject* parent);
00078 
00079     ~Button();
00080 
00081     bool mouseEnabled() const { return true; }
00082 
00083     virtual bool trackAsMenu();
00084 
00086     void keyPress(key::code c);
00087 
00089     virtual void display(Renderer& renderer, const Transform& xform);
00090     
00091     void set_current_state(MouseState new_state);
00092 
00094     //
00096     virtual InteractiveObject* topmostMouseEntity(boost::int32_t x,
00097             boost::int32_t y);
00098     
00100     virtual void mouseEvent(const event_id& event);
00101 
00103     virtual bool handleFocus();
00104 
00105     void add_invalidated_bounds(InvalidatedRanges& ranges, bool force);
00106     
00107     virtual SWFRect getBounds() const;
00108     
00109     // See dox in DisplayObject.h
00110     bool pointInShape(boost::int32_t x, boost::int32_t y) const;
00111 
00112     bool isEnabled();
00113 
00115     void destroy();
00116 
00118     //
00120     //
00123     virtual void construct(as_object* init = 0);
00124 
00125 #ifdef USE_SWFTREE
00126     // Override to append button DisplayObjects info, see dox in DisplayObject.h
00127     virtual InfoTree::iterator getMovieInfo(InfoTree& tr,
00128             InfoTree::iterator it);
00129 #endif
00130 
00131 protected:
00132     
00134     virtual bool unloadChildren();
00135 
00137     //
00143     void markOwnResources() const;
00144 
00145 private:
00146 
00148     //
00154     void getActiveCharacters(DisplayObjects& list, bool includeUnloaded=false);
00155 
00157     //
00162     void getActiveCharacters(ConstDisplayObjects& list) const;
00163 
00166     //
00173     void get_active_records(ActiveRecords& list, MouseState state);
00174 
00176     virtual int getDefinitionVersion() const;
00177     
00178     MouseState _mouseState;
00179     
00180     const boost::intrusive_ptr<const SWF::DefineButtonTag> _def;
00181 
00182     DisplayObjects _stateCharacters;
00183 
00184     DisplayObjects _hitCharacters;
00185 
00186 };
00187 
00188 std::ostream& operator<<(std::ostream& o, const Button::MouseState& st);
00189 
00191 void button_class_init(as_object& global, const ObjectURI& uri);
00192 
00193 void registerButtonNative(as_object& global);
00194 
00195 } // namespace gnash
00196 
00197 
00198 #endif // GNASH_BUTTON_H
00199 
00200 
00201 // Local Variables:
00202 // mode: C++
00203 // c-basic-offset: 8 
00204 // tab-width: 8
00205 // indent-tabs-mode: t
00206 // End: