• 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     class GnashImage;
00055     namespace SWF {
00056         class PlaceObject2Tag;
00057     }
00058 }
00059 
00060 namespace gnash
00061 {
00062 
00064 //
00066 //
00069 //
00075 //
00081 //
00086 class MovieClip : public DisplayObjectContainer 
00087 {
00088 
00089 public:
00090 
00091     typedef std::map<std::string, std::string> MovieVariables;
00092 
00093     typedef std::list<const action_buffer*> ActionList;
00094 
00095     typedef movie_definition::PlayList PlayList;
00096 
00097     enum PlayState
00098     {
00099         PLAYSTATE_PLAY,
00100         PLAYSTATE_STOP
00101     };
00102 
00104     //
00121     MovieClip(as_object* object, const movie_definition* def,
00122             Movie* root, DisplayObject* parent);
00123 
00124     virtual ~MovieClip();
00125 
00126     // Return the originating SWF
00127     virtual Movie* get_root() const;
00128 
00129     virtual bool trackAsMenu();
00130 
00132     //
00135     virtual MovieClip* getAsRoot();
00136 
00138     virtual SWFRect getBounds() const;
00139 
00140     // See dox in DisplayObject.h
00141     virtual bool pointInShape(boost::int32_t x, boost::int32_t y) const;
00142 
00143     // See dox in DisplayObject.h
00144     virtual bool pointInVisibleShape(boost::int32_t x, boost::int32_t y) const;
00145 
00150     virtual bool pointInHitableShape(boost::int32_t x, boost::int32_t y) const;
00151 
00153     size_t get_current_frame() const
00154     {
00155         return _currentFrame;
00156     }
00157 
00158     size_t get_frame_count() const
00159     {
00160         return _def ? _def->get_frame_count() : 1;
00161     }
00162 
00164     //
00168     size_t get_loaded_frames() const
00169     {
00170         return _def ? _def->get_loading_frame() : 1;
00171     }
00172 
00175     size_t get_bytes_total() const
00176     {
00177         return isDynamic() ? 0 : _def->get_bytes_total();
00178     }
00179 
00182     size_t get_bytes_loaded() const
00183     {
00184         return isDynamic() ? 0 : _def->get_bytes_loaded();
00185     }
00186 
00187     const SWFRect& get_frame_size() const
00188     {
00189         static const SWFRect r;
00190         return _def ? _def->get_frame_size() : r;
00191     }
00192 
00194     //
00198     DSOEXPORT void setPlayState(PlayState s);
00199 
00200     PlayState getPlayState() const { return _playState; }
00201 
00202     // delegates to movie_root (possibly wrong)
00203     void set_background_color(const rgba& color);
00204 
00206     //
00209     virtual bool mouseEnabled() const;
00210 
00215     virtual InteractiveObject* topmostMouseEntity(boost::int32_t x,
00216             boost::int32_t y);
00217 
00218     // see dox in DisplayObject.h
00219     const DisplayObject* findDropTarget(boost::int32_t x, boost::int32_t y,
00220             DisplayObject* dragging) const;
00221 
00222     void setDropTarget(const std::string& tgt)
00223     {
00224         _droptarget = tgt;
00225     }
00226 
00227     const std::string& getDropTarget() const
00228     {
00229         return _droptarget;
00230     }
00231     
00233     //
00235     virtual void advance();
00236 
00238     //
00242     DSOEXPORT void goto_frame(size_t target_frame_number);
00243 
00245     //
00260     bool get_frame_number(const as_value& frame_spec, size_t& frameno) const;
00261 
00263     bool goto_labeled_frame(const std::string& label);
00264         
00266     void display(Renderer& renderer);
00267     
00268     void omit_display();
00269 
00271     //
00273     void swapDepths(DisplayObject* ch1, int newdepth)
00274     {
00275         _displayList.swapDepths(ch1, newdepth);
00276     }
00277 
00279     //
00281     DisplayObject* getDisplayObjectAtDepth(int depth);
00282 
00284     DisplayObject* addDisplayListObject(DisplayObject* obj, int depth);
00285 
00287     //
00306     DisplayObject* add_display_object(const SWF::PlaceObject2Tag* tag,
00307             DisplayList& dlist);
00308 
00310     void move_display_object(const SWF::PlaceObject2Tag* tag,
00311             DisplayList& dlist);
00312 
00314     void replace_display_object(const SWF::PlaceObject2Tag* tag,
00315             DisplayList& dlist);
00316 
00318     void remove_display_object(const SWF::PlaceObject2Tag* tag,
00319             DisplayList& dlist);
00320 
00323     //
00330     void remove_display_object(int depth, int /*id*/);
00331 
00332     void unloadMovie();
00333 
00335     //
00344     bool attachCharacter(DisplayObject& newch, int depth, as_object* initObject);
00345 
00347     //
00356     //
00360     virtual void construct(as_object* initObj = 0);
00361 
00363     //
00377     void destroy();
00378         
00382     void add_action_buffer(const action_buffer* a)
00383     {
00384         if (!_callingFrameActions) queueAction(*a);
00385         else execute_action(*a);
00386     }
00387 
00388     
00392     //
00402     void execute_init_action_buffer(const action_buffer& a, int cid);
00403 
00405     void execute_action(const action_buffer& ab);
00406 
00407     MovieClip* to_movie () { return this; }
00408 
00410     //
00412     enum VariablesMethod
00413     {
00414         METHOD_NONE = 0,
00415         METHOD_GET,
00416         METHOD_POST
00417     };
00418 
00419     // See dox in DisplayObject.h
00420     virtual void getLoadedMovie(Movie* newMovie);
00421 
00425     //
00437     void loadVariables(const std::string& urlstr,
00438             VariablesMethod sendVarsMethod);
00439 
00441     //
00444     bool getTextFieldVariables(const ObjectURI& uri, as_value& val);
00445 
00446     // Set TextField variables
00447     //
00449     bool setTextFieldVariables(const ObjectURI& uri, const as_value& val);
00450 
00452     //
00456     //
00460     DisplayObject* getDisplayListObject(string_table::key name);
00461 
00463     as_object* pathElement(string_table::key key);
00464 
00466     //
00468     virtual void call_frame_actions(const as_value& frame_spec);
00469 
00470     // delegates to movie_root 
00471     virtual void stop_drag();
00472 
00474     //
00491     MovieClip* duplicateMovieClip(const std::string& newname,
00492         int newdepth, as_object* init_object=NULL);
00493         
00495     virtual void notifyEvent(const event_id& id);
00496 
00497     // inherited from DisplayObject class, see dox in DisplayObject.h
00498     as_environment& get_environment() {
00499         return _environment;
00500     }
00501 
00504     //
00507     void set_textfield_variable(const std::string& name, TextField* ch);
00508 
00509     void add_invalidated_bounds(InvalidatedRanges& ranges, bool force);
00510     
00511     const DisplayList& getDisplayList() const {
00512             return _displayList;
00513     }
00514 
00516     //
00520     int getNextHighestDepth() const {
00521         return _displayList.getNextHighestDepth();
00522     }
00523 
00525     // 
00526     // TODO: rename to setStreamingSoundId
00527     void setStreamSoundId(int id);
00528 
00530     //
00550     void removeMovieClip();
00551 
00553     //
00555     virtual std::auto_ptr<GnashImage> drawToBitmap(
00556             const SWFMatrix& mat = SWFMatrix(), 
00557             const cxform& cx = cxform(),
00558             DisplayObject::BlendMode bm = DisplayObject::BLENDMODE_NORMAL,
00559             const SWFRect& clipRect = SWFRect(),
00560             bool smooth = false);
00561 
00563     DynamicShape& graphics() {
00564         set_invalidated();
00565         return _drawable;
00566     }
00567 
00569     //
00571     virtual bool handleFocus();
00572 
00574 
00576     DSOEXPORT void setVariables(const MovieVariables& vars);
00577 
00579     //
00582     virtual void enumerateNonProperties(as_environment&) const;
00583 
00586     void cleanupDisplayList();
00587 
00589     //
00593     void queueAction(const action_buffer& buf);
00594 
00596     //
00601     void constructAsScriptObject();
00602 
00605     bool getLockRoot() const { return _lockroot; }
00606 
00609     void setLockRoot(bool lr) { _lockroot=lr; }
00610 
00612     virtual int getDefinitionVersion() const;
00613 
00614 protected:
00615 
00617     //
00619     virtual bool unloadChildren();
00620 
00622     //
00631     virtual void markOwnResources() const;
00632     
00633     // Used by BitmapMovie.
00634     void placeDisplayObject(DisplayObject* ch, int depth) {       
00635         _displayList.placeDisplayObject(ch, depth);  
00636     }
00637 
00638 private:
00639 
00640     typedef std::vector<TextField*> TextFields;
00641 
00643     typedef std::map<std::string, TextFields> TextFieldIndex;
00644 
00646     void processCompletedLoadVariableRequests();
00647 
00649     void processCompletedLoadVariableRequest(LoadVariablesThread& request);
00650 
00651     
00653     //
00662     void executeFrameTags(size_t frame, DisplayList& dlist,
00663             int typeflags = SWF::ControlTag::TAG_DLIST |
00664                             SWF::ControlTag::TAG_ACTION);
00665 
00666     void stopStreamSound();
00667 
00669     //
00671     //
00674     bool isEnabled() const;
00675 
00677     //
00681     bool hitTestDrawable(boost::int32_t x, boost::int32_t y) const;
00682 
00684     //
00706     //  http://www.gnashdev.org/wiki/index.php/TimelineControl
00713     //
00721     void restoreDisplayList(size_t targetFrame);
00722 
00724     //
00728     void queueActions(ActionList& action_list);
00729 
00731     //
00735     void execute_actions(ActionList& action_list);
00736 
00738     void increment_frame_and_check_for_loop();
00739     
00743     //
00754     TextFields* get_textfield_variable(const std::string& name);
00755 
00757     void cleanup_textfield_variables();
00758 
00761     const boost::intrusive_ptr<const movie_definition> _def;
00762 
00764     typedef std::list<LoadVariablesThread*> LoadVariablesThreads;
00765     
00767     //
00771     LoadVariablesThreads _loadVariableRequests;
00772 
00774     Movie* _swf;
00775 
00777     DynamicShape _drawable;
00778 
00779     PlayState _playState;
00780 
00782     as_environment _environment;
00783 
00787     std::auto_ptr<TextFieldIndex> _text_variables;
00788 
00789     std::string _droptarget;
00790 
00791     // 0-based index to current frame
00792     size_t _currentFrame;
00793     
00795     int m_sound_stream_id;
00796 
00797     // true if this sprite reached the last frame and restarted
00798     bool _hasLooped;
00799 
00800     // true is we're calling frame actions
00801     bool _callingFrameActions;
00802 
00803     bool _lockroot;
00804 };
00805 
00806 } // end of namespace gnash
00807 
00808 #endif // GNASH_SPRITE_INSTANCE_H

Generated on Thu Sep 30 2010 14:35:01 for Gnash by  doxygen 1.7.1