Gnash 0.8.10dev
|
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 "dsodefs.h" // for DSOEXPORT 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 00062 // 00064 // 00067 // 00073 // 00079 // 00084 class MovieClip : public DisplayObjectContainer 00085 { 00086 public: 00087 00088 typedef std::vector<TextField*> TextFields; 00089 00091 typedef std::map<ObjectURI, TextFields, ObjectURI::LessThan> 00092 TextFieldIndex; 00093 00094 typedef std::map<std::string, std::string> MovieVariables; 00095 00096 typedef std::list<const action_buffer*> ActionList; 00097 00098 typedef movie_definition::PlayList PlayList; 00099 00100 enum PlayState 00101 { 00102 PLAYSTATE_PLAY, 00103 PLAYSTATE_STOP 00104 }; 00105 00107 // 00124 MovieClip(as_object* object, const movie_definition* def, 00125 Movie* root, DisplayObject* parent); 00126 00127 virtual ~MovieClip(); 00128 00129 // Return the originating SWF 00130 virtual Movie* get_root() const; 00131 00132 virtual bool trackAsMenu(); 00133 00135 // 00138 virtual MovieClip* getAsRoot(); 00139 00141 virtual SWFRect getBounds() const; 00142 00143 // See dox in DisplayObject.h 00144 virtual bool pointInShape(boost::int32_t x, boost::int32_t y) const; 00145 00146 // See dox in DisplayObject.h 00147 virtual bool pointInVisibleShape(boost::int32_t x, boost::int32_t y) const; 00148 00153 virtual bool pointInHitableShape(boost::int32_t x, boost::int32_t y) const; 00154 00156 size_t get_current_frame() const 00157 { 00158 return _currentFrame; 00159 } 00160 00161 size_t get_frame_count() const 00162 { 00163 return _def ? _def->get_frame_count() : 1; 00164 } 00165 00167 // 00171 size_t get_loaded_frames() const 00172 { 00173 return _def ? _def->get_loading_frame() : 1; 00174 } 00175 00178 size_t get_bytes_total() const 00179 { 00180 return isDynamic() ? 0 : _def->get_bytes_total(); 00181 } 00182 00185 size_t get_bytes_loaded() const 00186 { 00187 return isDynamic() ? 0 : _def->get_bytes_loaded(); 00188 } 00189 00190 const SWFRect& get_frame_size() const 00191 { 00192 static const SWFRect r; 00193 return _def ? _def->get_frame_size() : r; 00194 } 00195 00197 // 00201 DSOEXPORT void setPlayState(PlayState s); 00202 00203 PlayState getPlayState() const { return _playState; } 00204 00205 // delegates to movie_root (possibly wrong) 00206 void set_background_color(const rgba& color); 00207 00209 // 00212 virtual bool mouseEnabled() const; 00213 00218 virtual InteractiveObject* topmostMouseEntity(boost::int32_t x, 00219 boost::int32_t y); 00220 00221 // see dox in DisplayObject.h 00222 const DisplayObject* findDropTarget(boost::int32_t x, boost::int32_t y, 00223 DisplayObject* dragging) const; 00224 00225 void setDropTarget(const std::string& tgt) { 00226 _droptarget = tgt; 00227 } 00228 00229 const std::string& getDropTarget() const { 00230 return _droptarget; 00231 } 00232 00234 // 00236 virtual void advance(); 00237 00239 // 00243 DSOEXPORT void goto_frame(size_t target_frame_number); 00244 00246 // 00261 bool get_frame_number(const as_value& frame_spec, size_t& frameno) const; 00262 00264 bool goto_labeled_frame(const std::string& label); 00265 00267 virtual void display(Renderer& renderer, const Transform& xform); 00268 00270 // 00273 void draw(Renderer& renderer, const Transform& xform); 00274 00275 void omit_display(); 00276 00278 // 00280 void swapDepths(DisplayObject* ch1, int newdepth) 00281 { 00282 _displayList.swapDepths(ch1, newdepth); 00283 } 00284 00286 // 00288 DisplayObject* getDisplayObjectAtDepth(int depth); 00289 00291 DisplayObject* addDisplayListObject(DisplayObject* obj, int depth); 00292 00294 // 00313 DisplayObject* add_display_object(const SWF::PlaceObject2Tag* tag, 00314 DisplayList& dlist); 00315 00317 void move_display_object(const SWF::PlaceObject2Tag* tag, 00318 DisplayList& dlist); 00319 00321 void replace_display_object(const SWF::PlaceObject2Tag* tag, 00322 DisplayList& dlist); 00323 00325 void remove_display_object(const SWF::PlaceObject2Tag* tag, 00326 DisplayList& dlist); 00327 00330 // 00337 void remove_display_object(int depth, int /*id*/); 00338 00339 void unloadMovie(); 00340 00342 // 00345 void attachCharacter(DisplayObject& newch, int depth, as_object* initObject); 00346 00348 // 00357 // 00361 virtual void construct(as_object* initObj = 0); 00362 00364 // 00378 void destroy(); 00379 00383 void add_action_buffer(const action_buffer* a) 00384 { 00385 if (!_callingFrameActions) queueAction(*a); 00386 else execute_action(*a); 00387 } 00388 00389 00393 // 00403 void execute_init_action_buffer(const action_buffer& a, int cid); 00404 00406 void execute_action(const action_buffer& ab); 00407 00408 MovieClip* to_movie () { return this; } 00409 00411 // 00413 enum VariablesMethod 00414 { 00415 METHOD_NONE = 0, 00416 METHOD_GET, 00417 METHOD_POST 00418 }; 00419 00420 // See dox in DisplayObject.h 00421 virtual void getLoadedMovie(Movie* newMovie); 00422 00426 // 00438 void loadVariables(const std::string& urlstr, 00439 VariablesMethod sendVarsMethod); 00440 00442 // 00445 bool getTextFieldVariables(const ObjectURI& uri, as_value& val); 00446 00447 // Set TextField variables 00448 // 00450 bool setTextFieldVariables(const ObjectURI& uri, const as_value& val); 00451 00453 // 00457 // 00461 DisplayObject* getDisplayListObject(const ObjectURI& uri); 00462 00464 as_object* pathElement(const ObjectURI& uri); 00465 00467 // 00469 virtual void call_frame_actions(const as_value& frame_spec); 00470 00471 // delegates to movie_root 00472 virtual void stop_drag(); 00473 00475 // 00492 MovieClip* duplicateMovieClip(const std::string& newname, 00493 int newdepth, as_object* init_object=NULL); 00494 00496 virtual void notifyEvent(const event_id& id); 00497 00498 // inherited from DisplayObject class, see dox in DisplayObject.h 00499 virtual as_environment& get_environment() { 00500 return _environment; 00501 } 00502 00505 // 00508 void set_textfield_variable(const ObjectURI& name, TextField* ch); 00509 00510 void add_invalidated_bounds(InvalidatedRanges& ranges, bool force); 00511 00512 const DisplayList& getDisplayList() const { 00513 return _displayList; 00514 } 00515 00517 // 00521 int getNextHighestDepth() const { 00522 return _displayList.getNextHighestDepth(); 00523 } 00524 00526 // 00527 // TODO: rename to setStreamingSoundId 00528 void setStreamSoundId(int id); 00529 00531 // 00551 void removeMovieClip(); 00552 00554 DynamicShape& graphics() { 00555 set_invalidated(); 00556 return _drawable; 00557 } 00558 00560 // 00562 virtual bool handleFocus(); 00563 00565 00567 DSOEXPORT void setVariables(const MovieVariables& vars); 00568 00570 // 00572 virtual void visitNonProperties(KeyVisitor& v) const; 00573 00576 void cleanupDisplayList(); 00577 00579 // 00583 void queueAction(const action_buffer& buf); 00584 00586 // 00591 void constructAsScriptObject(); 00592 00595 bool getLockRoot() const { return _lockroot; } 00596 00599 void setLockRoot(bool lr) { _lockroot=lr; } 00600 00602 virtual int getDefinitionVersion() const; 00603 00604 protected: 00605 00607 // 00609 virtual bool unloadChildren(); 00610 00612 // 00621 virtual void markOwnResources() const; 00622 00623 // Used by BitmapMovie. 00624 void placeDisplayObject(DisplayObject* ch, int depth) { 00625 _displayList.placeDisplayObject(ch, depth); 00626 } 00627 00628 private: 00629 00631 void processCompletedLoadVariableRequests(); 00632 00634 void processCompletedLoadVariableRequest(LoadVariablesThread& request); 00635 00636 00638 // 00647 void executeFrameTags(size_t frame, DisplayList& dlist, 00648 int typeflags = SWF::ControlTag::TAG_DLIST | 00649 SWF::ControlTag::TAG_ACTION); 00650 00651 void stopStreamSound(); 00652 00654 // 00656 // 00659 bool isEnabled() const; 00660 00662 // 00666 bool hitTestDrawable(boost::int32_t x, boost::int32_t y) const; 00667 00669 // 00691 // http://www.gnashdev.org/wiki/index.php/TimelineControl 00698 // 00706 void restoreDisplayList(size_t targetFrame); 00707 00709 void increment_frame_and_check_for_loop(); 00710 00712 void cleanup_textfield_variables(); 00713 00716 const boost::intrusive_ptr<const movie_definition> _def; 00717 00719 typedef boost::ptr_list<LoadVariablesThread> LoadVariablesThreads; 00720 00722 // 00726 LoadVariablesThreads _loadVariableRequests; 00727 00729 Movie* _swf; 00730 00732 DynamicShape _drawable; 00733 00734 PlayState _playState; 00735 00737 as_environment _environment; 00738 00742 std::auto_ptr<TextFieldIndex> _text_variables; 00743 00744 std::string _droptarget; 00745 00746 // 0-based index to current frame 00747 size_t _currentFrame; 00748 00750 int m_sound_stream_id; 00751 00752 // true if this sprite reached the last frame and restarted 00753 bool _hasLooped; 00754 00755 // true if orphaned tags (tags found after last advertised showframe) 00756 // have been executed at least once. 00757 bool _flushedOrphanedTags; 00758 00759 // true is we're calling frame actions 00760 bool _callingFrameActions; 00761 00762 bool _lockroot; 00763 }; 00764 00765 } // end of namespace gnash 00766 00767 #endif // GNASH_SPRITE_INSTANCE_H