Gnash 0.8.9

MovieClip.h

Go to the documentation of this file.
00001 // MovieClip.h:  Stateful live Sprite instance, for Gnash.
00002 // 
00003 //   Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010,
00004 //   2011 Free Software Foundation, Inc
00005 // 
00006 // This program is free software; you can redistribute it and/or modify
00007 // it under the terms of the GNU General Public License as published by
00008 // the Free Software Foundation; either version 3 of the License, or
00009 // (at your option) any later version.
00010 // 
00011 // This program is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 // GNU General Public License for more details.
00015 // 
00016 // You should have received a copy of the GNU General Public License
00017 // along with this program; if not, write to the Free Software
00018 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00019 
00020 // Stateful live Sprite instance
00021 
00022 #ifndef GNASH_MOVIECLIP_H
00023 #define GNASH_MOVIECLIP_H
00024 
00025 #ifdef HAVE_CONFIG_H
00026 #include "gnashconfig.h" 
00027 #endif
00028 
00029 #include <vector>
00030 #include <list>
00031 #include <map>
00032 #include <string>
00033 #include <boost/ptr_container/ptr_list.hpp>
00034 #include <boost/intrusive_ptr.hpp>
00035 
00036 #include "ControlTag.h"
00037 #include "movie_definition.h" // for inlines
00038 #include "DisplayList.h" // DisplayList 
00039 #include "DisplayObjectContainer.h"
00040 #include "as_environment.h" // for composition
00041 #include "DynamicShape.h" // for composition
00042 #include "snappingrange.h"
00043 #include "dsodefs.h" // for DSOEXPORT
00044 
00045 // Forward declarations
00046 namespace gnash {
00047     class Movie;
00048     class swf_event;
00049     class drag_state;
00050     class LoadVariablesThread;
00051     class GradientRecord;
00052     class TextField;
00053     class BitmapData_as;
00054     class CachedBitmap;
00055     namespace SWF {
00056         class PlaceObject2Tag;
00057     }
00058 }
00059 
00060 namespace gnash {
00061 
00063 //
00065 //
00068 //
00074 //
00080 //
00085 class MovieClip : public DisplayObjectContainer 
00086 {
00087 public:
00088 
00089     typedef std::vector<TextField*> TextFields;
00090 
00092     typedef std::map<ObjectURI, TextFields, ObjectURI::LessThan>
00093         TextFieldIndex;
00094 
00095     typedef std::map<std::string, std::string> MovieVariables;
00096 
00097     typedef std::list<const action_buffer*> ActionList;
00098 
00099     typedef movie_definition::PlayList PlayList;
00100 
00101     enum PlayState
00102     {
00103         PLAYSTATE_PLAY,
00104         PLAYSTATE_STOP
00105     };
00106 
00108     //
00125     MovieClip(as_object* object, const movie_definition* def,
00126             Movie* root, DisplayObject* parent);
00127 
00128     virtual ~MovieClip();
00129 
00130     // Return the originating SWF
00131     virtual Movie* get_root() const;
00132 
00133     virtual bool trackAsMenu();
00134 
00136     //
00139     virtual MovieClip* getAsRoot();
00140 
00142     virtual SWFRect getBounds() const;
00143 
00144     // See dox in DisplayObject.h
00145     virtual bool pointInShape(boost::int32_t x, boost::int32_t y) const;
00146 
00147     // See dox in DisplayObject.h
00148     virtual bool pointInVisibleShape(boost::int32_t x, boost::int32_t y) const;
00149 
00154     virtual bool pointInHitableShape(boost::int32_t x, boost::int32_t y) const;
00155 
00157     size_t get_current_frame() const
00158     {
00159         return _currentFrame;
00160     }
00161 
00162     size_t get_frame_count() const
00163     {
00164         return _def ? _def->get_frame_count() : 1;
00165     }
00166 
00168     //
00172     size_t get_loaded_frames() const
00173     {
00174         return _def ? _def->get_loading_frame() : 1;
00175     }
00176 
00179     size_t get_bytes_total() const
00180     {
00181         return isDynamic() ? 0 : _def->get_bytes_total();
00182     }
00183 
00186     size_t get_bytes_loaded() const
00187     {
00188         return isDynamic() ? 0 : _def->get_bytes_loaded();
00189     }
00190 
00191     const SWFRect& get_frame_size() const
00192     {
00193         static const SWFRect r;
00194         return _def ? _def->get_frame_size() : r;
00195     }
00196 
00198     //
00202     DSOEXPORT void setPlayState(PlayState s);
00203 
00204     PlayState getPlayState() const { return _playState; }
00205 
00206     // delegates to movie_root (possibly wrong)
00207     void set_background_color(const rgba& color);
00208 
00210     //
00213     virtual bool mouseEnabled() const;
00214 
00219     virtual InteractiveObject* topmostMouseEntity(boost::int32_t x,
00220             boost::int32_t y);
00221 
00222     // see dox in DisplayObject.h
00223     const DisplayObject* findDropTarget(boost::int32_t x, boost::int32_t y,
00224             DisplayObject* dragging) const;
00225 
00226     void setDropTarget(const std::string& tgt) {
00227         _droptarget = tgt;
00228     }
00229 
00230     const std::string& getDropTarget() const {
00231         return _droptarget;
00232     }
00233     
00235     //
00237     virtual void advance();
00238 
00240     //
00244     DSOEXPORT void goto_frame(size_t target_frame_number);
00245 
00247     //
00262     bool get_frame_number(const as_value& frame_spec, size_t& frameno) const;
00263 
00265     bool goto_labeled_frame(const std::string& label);
00266         
00268     virtual void display(Renderer& renderer, const Transform& xform);
00269     
00271     //
00274     void draw(Renderer& renderer, const Transform& xform);
00275 
00276     void omit_display();
00277 
00279     //
00281     void swapDepths(DisplayObject* ch1, int newdepth)
00282     {
00283         _displayList.swapDepths(ch1, newdepth);
00284     }
00285 
00287     //
00289     DisplayObject* getDisplayObjectAtDepth(int depth);
00290 
00292     DisplayObject* addDisplayListObject(DisplayObject* obj, int depth);
00293 
00295     //
00314     DisplayObject* add_display_object(const SWF::PlaceObject2Tag* tag,
00315             DisplayList& dlist);
00316 
00318     void move_display_object(const SWF::PlaceObject2Tag* tag,
00319             DisplayList& dlist);
00320 
00322     void replace_display_object(const SWF::PlaceObject2Tag* tag,
00323             DisplayList& dlist);
00324 
00326     void remove_display_object(const SWF::PlaceObject2Tag* tag,
00327             DisplayList& dlist);
00328 
00331     //
00338     void remove_display_object(int depth, int /*id*/);
00339 
00340     void unloadMovie();
00341 
00343     //
00346     void attachCharacter(DisplayObject& newch, int depth, as_object* initObject);
00347 
00349     //
00358     //
00362     virtual void construct(as_object* initObj = 0);
00363 
00365     //
00379     void destroy();
00380         
00384     void add_action_buffer(const action_buffer* a)
00385     {
00386         if (!_callingFrameActions) queueAction(*a);
00387         else execute_action(*a);
00388     }
00389 
00390     
00394     //
00404     void execute_init_action_buffer(const action_buffer& a, int cid);
00405 
00407     void execute_action(const action_buffer& ab);
00408 
00409     MovieClip* to_movie () { return this; }
00410 
00412     //
00414     enum VariablesMethod
00415     {
00416         METHOD_NONE = 0,
00417         METHOD_GET,
00418         METHOD_POST
00419     };
00420 
00421     // See dox in DisplayObject.h
00422     virtual void getLoadedMovie(Movie* newMovie);
00423 
00427     //
00439     void loadVariables(const std::string& urlstr,
00440             VariablesMethod sendVarsMethod);
00441 
00443     //
00446     bool getTextFieldVariables(const ObjectURI& uri, as_value& val);
00447 
00448     // Set TextField variables
00449     //
00451     bool setTextFieldVariables(const ObjectURI& uri, const as_value& val);
00452 
00454     //
00458     //
00462     DisplayObject* getDisplayListObject(const ObjectURI& uri);
00463 
00465     as_object* pathElement(const ObjectURI& uri);
00466 
00468     //
00470     virtual void call_frame_actions(const as_value& frame_spec);
00471 
00472     // delegates to movie_root 
00473     virtual void stop_drag();
00474 
00476     //
00493     MovieClip* duplicateMovieClip(const std::string& newname,
00494         int newdepth, as_object* init_object=NULL);
00495         
00497     virtual void notifyEvent(const event_id& id);
00498 
00499     // inherited from DisplayObject class, see dox in DisplayObject.h
00500     virtual as_environment& get_environment() {
00501         return _environment;
00502     }
00503 
00506     //
00509     void set_textfield_variable(const ObjectURI& name, TextField* ch);
00510 
00511     void add_invalidated_bounds(InvalidatedRanges& ranges, bool force);
00512     
00513     const DisplayList& getDisplayList() const {
00514             return _displayList;
00515     }
00516 
00518     //
00522     int getNextHighestDepth() const {
00523         return _displayList.getNextHighestDepth();
00524     }
00525 
00527     // 
00528     // TODO: rename to setStreamingSoundId
00529     void setStreamSoundId(int id);
00530 
00532     //
00552     void removeMovieClip();
00553 
00555     DynamicShape& graphics() {
00556         set_invalidated();
00557         return _drawable;
00558     }
00559 
00561     //
00563     virtual bool handleFocus();
00564 
00566 
00568     DSOEXPORT void setVariables(const MovieVariables& vars);
00569 
00571     //
00573     virtual void visitNonProperties(KeyVisitor& v) const;
00574 
00577     void cleanupDisplayList();
00578 
00580     //
00584     void queueAction(const action_buffer& buf);
00585 
00587     //
00592     void constructAsScriptObject();
00593 
00596     bool getLockRoot() const { return _lockroot; }
00597 
00600     void setLockRoot(bool lr) { _lockroot=lr; }
00601 
00603     virtual int getDefinitionVersion() const;
00604 
00605 protected:
00606 
00608     //
00610     virtual bool unloadChildren();
00611 
00613     //
00622     virtual void markOwnResources() const;
00623     
00624     // Used by BitmapMovie.
00625     void placeDisplayObject(DisplayObject* ch, int depth) {       
00626         _displayList.placeDisplayObject(ch, depth);  
00627     }
00628 
00629 private:
00630 
00632     void processCompletedLoadVariableRequests();
00633 
00635     void processCompletedLoadVariableRequest(LoadVariablesThread& request);
00636 
00637     
00639     //
00648     void executeFrameTags(size_t frame, DisplayList& dlist,
00649             int typeflags = SWF::ControlTag::TAG_DLIST |
00650                             SWF::ControlTag::TAG_ACTION);
00651 
00652     void stopStreamSound();
00653 
00655     //
00657     //
00660     bool isEnabled() const;
00661 
00663     //
00667     bool hitTestDrawable(boost::int32_t x, boost::int32_t y) const;
00668 
00670     //
00692     //  http://www.gnashdev.org/wiki/index.php/TimelineControl
00699     //
00707     void restoreDisplayList(size_t targetFrame);
00708 
00710     void increment_frame_and_check_for_loop();
00711 
00713     void cleanup_textfield_variables();
00714 
00717     const boost::intrusive_ptr<const movie_definition> _def;
00718 
00720     typedef boost::ptr_list<LoadVariablesThread> LoadVariablesThreads;
00721     
00723     //
00727     LoadVariablesThreads _loadVariableRequests;
00728 
00730     Movie* _swf;
00731 
00733     DynamicShape _drawable;
00734 
00735     PlayState _playState;
00736 
00738     as_environment _environment;
00739 
00743     std::auto_ptr<TextFieldIndex> _text_variables;
00744 
00745     std::string _droptarget;
00746 
00747     // 0-based index to current frame
00748     size_t _currentFrame;
00749     
00751     int m_sound_stream_id;
00752 
00753     // true if this sprite reached the last frame and restarted
00754     bool _hasLooped;
00755 
00756     // true is we're calling frame actions
00757     bool _callingFrameActions;
00758 
00759     bool _lockroot;
00760 };
00761 
00762 } // end of namespace gnash
00763 
00764 #endif // GNASH_SPRITE_INSTANCE_H