• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • Examples
  • File List
  • File Members

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 Free Software
00004 //   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" // GNASH_USE_GC, USE_SWFTREE
00027 #endif
00028 
00029 #include "ControlTag.h"
00030 #include "movie_definition.h" // for inlines
00031 #include "DisplayList.h" // DisplayList 
00032 #include "DisplayObjectContainer.h"
00033 #include "as_environment.h" // for composition
00034 #include "DynamicShape.h" // for composition
00035 #include "snappingrange.h"
00036 #include "dsodefs.h" // for DSOEXPORT
00037 
00038 #include <boost/intrusive_ptr.hpp>
00039 #include <vector>
00040 #include <list>
00041 #include <map>
00042 #include <string>
00043 
00044 // Forward declarations
00045 namespace gnash {
00046     class Movie;
00047     class swf_event;
00048     class drag_state;
00049     class LoadVariablesThread;
00050     class GradientRecord;
00051     class TextField;
00052     class BitmapData_as;
00053     class CachedBitmap;
00054     namespace SWF {
00055         class PlaceObject2Tag;
00056     }
00057 }
00058 
00059 namespace gnash
00060 {
00061 
00063 //
00065 //
00068 //
00074 //
00080 //
00085 class MovieClip : public DisplayObjectContainer 
00086 {
00087 
00088 public:
00089 
00090     typedef std::map<std::string, std::string> MovieVariables;
00091 
00092     typedef std::list<const action_buffer*> ActionList;
00093 
00094     typedef movie_definition::PlayList PlayList;
00095 
00096     enum PlayState
00097     {
00098         PLAYSTATE_PLAY,
00099         PLAYSTATE_STOP
00100     };
00101 
00103     //
00120     MovieClip(as_object* object, const movie_definition* def,
00121             Movie* root, DisplayObject* parent);
00122 
00123     virtual ~MovieClip();
00124 
00125     // Return the originating SWF
00126     virtual Movie* get_root() const;
00127 
00128     virtual bool trackAsMenu();
00129 
00131     //
00134     virtual MovieClip* getAsRoot();
00135 
00137     virtual SWFRect getBounds() const;
00138 
00139     // See dox in DisplayObject.h
00140     virtual bool pointInShape(boost::int32_t x, boost::int32_t y) const;
00141 
00142     // See dox in DisplayObject.h
00143     virtual bool pointInVisibleShape(boost::int32_t x, boost::int32_t y) const;
00144 
00149     virtual bool pointInHitableShape(boost::int32_t x, boost::int32_t y) const;
00150 
00152     size_t get_current_frame() const
00153     {
00154         return _currentFrame;
00155     }
00156 
00157     size_t get_frame_count() const
00158     {
00159         return _def ? _def->get_frame_count() : 1;
00160     }
00161 
00163     //
00167     size_t get_loaded_frames() const
00168     {
00169         return _def ? _def->get_loading_frame() : 1;
00170     }
00171 
00174     size_t get_bytes_total() const
00175     {
00176         return isDynamic() ? 0 : _def->get_bytes_total();
00177     }
00178 
00181     size_t get_bytes_loaded() const
00182     {
00183         return isDynamic() ? 0 : _def->get_bytes_loaded();
00184     }
00185 
00186     const SWFRect& get_frame_size() const
00187     {
00188         static const SWFRect r;
00189         return _def ? _def->get_frame_size() : r;
00190     }
00191 
00193     //
00197     DSOEXPORT void setPlayState(PlayState s);
00198 
00199     PlayState getPlayState() const { return _playState; }
00200 
00201     // delegates to movie_root (possibly wrong)
00202     void set_background_color(const rgba& color);
00203 
00205     //
00208     virtual bool mouseEnabled() const;
00209 
00214     virtual InteractiveObject* topmostMouseEntity(boost::int32_t x,
00215             boost::int32_t y);
00216 
00217     // see dox in DisplayObject.h
00218     const DisplayObject* findDropTarget(boost::int32_t x, boost::int32_t y,
00219             DisplayObject* dragging) const;
00220 
00221     void setDropTarget(const std::string& tgt)
00222     {
00223         _droptarget = tgt;
00224     }
00225 
00226     const std::string& getDropTarget() const
00227     {
00228         return _droptarget;
00229     }
00230     
00232     //
00234     virtual void advance();
00235 
00237     //
00241     DSOEXPORT void goto_frame(size_t target_frame_number);
00242 
00244     //
00259     bool get_frame_number(const as_value& frame_spec, size_t& frameno) const;
00260 
00262     bool goto_labeled_frame(const std::string& label);
00263         
00265     virtual void display(Renderer& renderer, const Transform& xform);
00266     
00268     //
00271     void draw(Renderer& renderer, const Transform& xform);
00272 
00273     void omit_display();
00274 
00276     //
00278     void swapDepths(DisplayObject* ch1, int newdepth)
00279     {
00280         _displayList.swapDepths(ch1, newdepth);
00281     }
00282 
00284     //
00286     DisplayObject* getDisplayObjectAtDepth(int depth);
00287 
00289     DisplayObject* addDisplayListObject(DisplayObject* obj, int depth);
00290 
00292     //
00311     DisplayObject* add_display_object(const SWF::PlaceObject2Tag* tag,
00312             DisplayList& dlist);
00313 
00315     void move_display_object(const SWF::PlaceObject2Tag* tag,
00316             DisplayList& dlist);
00317 
00319     void replace_display_object(const SWF::PlaceObject2Tag* tag,
00320             DisplayList& dlist);
00321 
00323     void remove_display_object(const SWF::PlaceObject2Tag* tag,
00324             DisplayList& dlist);
00325 
00328     //
00335     void remove_display_object(int depth, int /*id*/);
00336 
00337     void unloadMovie();
00338 
00340     //
00349     bool attachCharacter(DisplayObject& newch, int depth, as_object* initObject);
00350 
00352     //
00361     //
00365     virtual void construct(as_object* initObj = 0);
00366 
00368     //
00382     void destroy();
00383         
00387     void add_action_buffer(const action_buffer* a)
00388     {
00389         if (!_callingFrameActions) queueAction(*a);
00390         else execute_action(*a);
00391     }
00392 
00393     
00397     //
00407     void execute_init_action_buffer(const action_buffer& a, int cid);
00408 
00410     void execute_action(const action_buffer& ab);
00411 
00412     MovieClip* to_movie () { return this; }
00413 
00415     //
00417     enum VariablesMethod
00418     {
00419         METHOD_NONE = 0,
00420         METHOD_GET,
00421         METHOD_POST
00422     };
00423 
00424     // See dox in DisplayObject.h
00425     virtual void getLoadedMovie(Movie* newMovie);
00426 
00430     //
00442     void loadVariables(const std::string& urlstr,
00443             VariablesMethod sendVarsMethod);
00444 
00446     //
00449     bool getTextFieldVariables(const ObjectURI& uri, as_value& val);
00450 
00451     // Set TextField variables
00452     //
00454     bool setTextFieldVariables(const ObjectURI& uri, const as_value& val);
00455 
00457     //
00461     //
00465     DisplayObject* getDisplayListObject(string_table::key name);
00466 
00468     as_object* pathElement(string_table::key key);
00469 
00471     //
00473     virtual void call_frame_actions(const as_value& frame_spec);
00474 
00475     // delegates to movie_root 
00476     virtual void stop_drag();
00477 
00479     //
00496     MovieClip* duplicateMovieClip(const std::string& newname,
00497         int newdepth, as_object* init_object=NULL);
00498         
00500     virtual void notifyEvent(const event_id& id);
00501 
00502     // inherited from DisplayObject class, see dox in DisplayObject.h
00503     as_environment& get_environment() {
00504         return _environment;
00505     }
00506 
00509     //
00512     void set_textfield_variable(const std::string& name, TextField* ch);
00513 
00514     void add_invalidated_bounds(InvalidatedRanges& ranges, bool force);
00515     
00516     const DisplayList& getDisplayList() const {
00517             return _displayList;
00518     }
00519 
00521     //
00525     int getNextHighestDepth() const {
00526         return _displayList.getNextHighestDepth();
00527     }
00528 
00530     // 
00531     // TODO: rename to setStreamingSoundId
00532     void setStreamSoundId(int id);
00533 
00535     //
00555     void removeMovieClip();
00556 
00558     DynamicShape& graphics() {
00559         set_invalidated();
00560         return _drawable;
00561     }
00562 
00564     //
00566     virtual bool handleFocus();
00567 
00569 
00571     DSOEXPORT void setVariables(const MovieVariables& vars);
00572 
00574     //
00577     virtual void enumerateNonProperties(as_environment&) const;
00578 
00581     void cleanupDisplayList();
00582 
00584     //
00588     void queueAction(const action_buffer& buf);
00589 
00591     //
00596     void constructAsScriptObject();
00597 
00600     bool getLockRoot() const { return _lockroot; }
00601 
00604     void setLockRoot(bool lr) { _lockroot=lr; }
00605 
00607     virtual int getDefinitionVersion() const;
00608 
00609 protected:
00610 
00612     //
00614     virtual bool unloadChildren();
00615 
00617     //
00626     virtual void markOwnResources() const;
00627     
00628     // Used by BitmapMovie.
00629     void placeDisplayObject(DisplayObject* ch, int depth) {       
00630         _displayList.placeDisplayObject(ch, depth);  
00631     }
00632 
00633 private:
00634 
00635     typedef std::vector<TextField*> TextFields;
00636 
00638     typedef std::map<std::string, TextFields> TextFieldIndex;
00639 
00641     void processCompletedLoadVariableRequests();
00642 
00644     void processCompletedLoadVariableRequest(LoadVariablesThread& request);
00645 
00646     
00648     //
00657     void executeFrameTags(size_t frame, DisplayList& dlist,
00658             int typeflags = SWF::ControlTag::TAG_DLIST |
00659                             SWF::ControlTag::TAG_ACTION);
00660 
00661     void stopStreamSound();
00662 
00664     //
00666     //
00669     bool isEnabled() const;
00670 
00672     //
00676     bool hitTestDrawable(boost::int32_t x, boost::int32_t y) const;
00677 
00679     //
00701     //  http://www.gnashdev.org/wiki/index.php/TimelineControl
00708     //
00716     void restoreDisplayList(size_t targetFrame);
00717 
00719     //
00723     void queueActions(ActionList& action_list);
00724 
00726     //
00730     void execute_actions(ActionList& action_list);
00731 
00733     void increment_frame_and_check_for_loop();
00734     
00738     //
00749     TextFields* get_textfield_variable(const std::string& name);
00750 
00752     void cleanup_textfield_variables();
00753 
00756     const boost::intrusive_ptr<const movie_definition> _def;
00757 
00759     typedef std::list<LoadVariablesThread*> LoadVariablesThreads;
00760     
00762     //
00766     LoadVariablesThreads _loadVariableRequests;
00767 
00769     Movie* _swf;
00770 
00772     DynamicShape _drawable;
00773 
00774     PlayState _playState;
00775 
00777     as_environment _environment;
00778 
00782     std::auto_ptr<TextFieldIndex> _text_variables;
00783 
00784     std::string _droptarget;
00785 
00786     // 0-based index to current frame
00787     size_t _currentFrame;
00788     
00790     int m_sound_stream_id;
00791 
00792     // true if this sprite reached the last frame and restarted
00793     bool _hasLooped;
00794 
00795     // true is we're calling frame actions
00796     bool _callingFrameActions;
00797 
00798     bool _lockroot;
00799 };
00800 
00801 } // end of namespace gnash
00802 
00803 #endif // GNASH_SPRITE_INSTANCE_H

Generated on Thu Sep 2 2010 for Gnash by  doxygen 1.7.1