Gnash
0.8.10
|
00001 // MovieClip.h: Stateful live Sprite instance, for Gnash. 00002 // 00003 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 00004 // 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 movie_definition::PlayList PlayList; 00097 00098 enum PlayState 00099 { 00100 PLAYSTATE_PLAY, 00101 PLAYSTATE_STOP 00102 }; 00103 00105 // 00122 MovieClip(as_object* object, const movie_definition* def, 00123 Movie* root, DisplayObject* parent); 00124 00125 virtual ~MovieClip(); 00126 00127 // Return the originating SWF 00128 virtual Movie* get_root() const; 00129 00130 virtual bool trackAsMenu(); 00131 00133 // 00136 void queueEvent(const event_id& id, int lvl); 00137 00138 void queueLoad(); 00139 00141 // 00144 virtual MovieClip* getAsRoot(); 00145 00147 virtual SWFRect getBounds() const; 00148 00149 // See dox in DisplayObject.h 00150 virtual bool pointInShape(boost::int32_t x, boost::int32_t y) const; 00151 00152 // See dox in DisplayObject.h 00153 virtual bool pointInVisibleShape(boost::int32_t x, boost::int32_t y) const; 00154 00159 virtual bool pointInHitableShape(boost::int32_t x, boost::int32_t y) const; 00160 00162 size_t get_current_frame() const 00163 { 00164 return _currentFrame; 00165 } 00166 00167 size_t get_frame_count() const 00168 { 00169 return _def ? _def->get_frame_count() : 1; 00170 } 00171 00173 // 00177 size_t get_loaded_frames() const 00178 { 00179 return _def ? _def->get_loading_frame() : 1; 00180 } 00181 00184 size_t get_bytes_total() const 00185 { 00186 return isDynamic() ? 0 : _def->get_bytes_total(); 00187 } 00188 00191 size_t get_bytes_loaded() const 00192 { 00193 return isDynamic() ? 0 : _def->get_bytes_loaded(); 00194 } 00195 00196 const SWFRect& get_frame_size() const 00197 { 00198 static const SWFRect r; 00199 return _def ? _def->get_frame_size() : r; 00200 } 00201 00203 // 00207 DSOEXPORT void setPlayState(PlayState s); 00208 00209 PlayState getPlayState() const { return _playState; } 00210 00211 // delegates to movie_root (possibly wrong) 00212 void set_background_color(const rgba& color); 00213 00215 // 00218 virtual bool mouseEnabled() const; 00219 00224 virtual InteractiveObject* topmostMouseEntity(boost::int32_t x, 00225 boost::int32_t y); 00226 00227 // see dox in DisplayObject.h 00228 const DisplayObject* findDropTarget(boost::int32_t x, boost::int32_t y, 00229 DisplayObject* dragging) const; 00230 00231 void setDropTarget(const std::string& tgt) { 00232 _droptarget = tgt; 00233 } 00234 00235 const std::string& getDropTarget() const { 00236 return _droptarget; 00237 } 00238 00240 // 00242 virtual void advance(); 00243 00245 // 00249 DSOEXPORT void goto_frame(size_t target_frame_number); 00250 00252 // 00267 bool get_frame_number(const as_value& frame_spec, size_t& frameno) const; 00268 00270 bool goto_labeled_frame(const std::string& label); 00271 00273 virtual void display(Renderer& renderer, const Transform& xform); 00274 00276 // 00279 void draw(Renderer& renderer, const Transform& xform); 00280 00281 void omit_display(); 00282 00284 // 00286 void swapDepths(DisplayObject* ch1, int newdepth) 00287 { 00288 _displayList.swapDepths(ch1, newdepth); 00289 } 00290 00292 // 00294 DisplayObject* getDisplayObjectAtDepth(int depth); 00295 00297 DisplayObject* addDisplayListObject(DisplayObject* obj, int depth); 00298 00300 // 00319 DisplayObject* add_display_object(const SWF::PlaceObject2Tag* tag, 00320 DisplayList& dlist); 00321 00323 void move_display_object(const SWF::PlaceObject2Tag* tag, 00324 DisplayList& dlist); 00325 00327 void replace_display_object(const SWF::PlaceObject2Tag* tag, 00328 DisplayList& dlist); 00329 00331 void remove_display_object(const SWF::PlaceObject2Tag* tag, 00332 DisplayList& dlist); 00333 00336 // 00343 void remove_display_object(int depth, int /*id*/); 00344 00345 void unloadMovie(); 00346 00348 // 00351 void attachCharacter(DisplayObject& newch, int depth, as_object* initObject); 00352 00354 // 00363 // 00367 virtual void construct(as_object* initObj = 0); 00368 00370 // 00384 void destroy(); 00385 00389 void add_action_buffer(const action_buffer* a) 00390 { 00391 if (!_callingFrameActions) queueAction(*a); 00392 else execute_action(*a); 00393 } 00394 00395 00399 // 00409 void execute_init_action_buffer(const action_buffer& a, int cid); 00410 00412 void execute_action(const action_buffer& ab); 00413 00414 MovieClip* to_movie () { return this; } 00415 00417 // 00419 enum VariablesMethod 00420 { 00421 METHOD_NONE = 0, 00422 METHOD_GET, 00423 METHOD_POST 00424 }; 00425 00426 // See dox in DisplayObject.h 00427 virtual void getLoadedMovie(Movie* newMovie); 00428 00432 // 00444 void loadVariables(const std::string& urlstr, 00445 VariablesMethod sendVarsMethod); 00446 00448 // 00451 bool getTextFieldVariables(const ObjectURI& uri, as_value& val); 00452 00453 // Set TextField variables 00454 // 00456 bool setTextFieldVariables(const ObjectURI& uri, const as_value& val); 00457 00459 // 00463 // 00467 DisplayObject* getDisplayListObject(const ObjectURI& uri); 00468 00470 as_object* pathElement(const ObjectURI& uri); 00471 00473 // 00475 virtual void call_frame_actions(const as_value& frame_spec); 00476 00478 // 00495 MovieClip* duplicateMovieClip(const std::string& newname, 00496 int newdepth, as_object* init_object = 0); 00497 00499 virtual void mouseEvent(const event_id& id) { 00500 notifyEvent(id); 00501 } 00502 00504 // 00507 void notifyEvent(const event_id& id); 00508 00509 // inherited from DisplayObject class, see dox in DisplayObject.h 00510 virtual as_environment& get_environment() { 00511 return _environment; 00512 } 00513 00516 // 00519 void set_textfield_variable(const ObjectURI& name, TextField* ch); 00520 00521 void add_invalidated_bounds(InvalidatedRanges& ranges, bool force); 00522 00523 const DisplayList& getDisplayList() const { 00524 return _displayList; 00525 } 00526 00528 // 00532 int getNextHighestDepth() const { 00533 return _displayList.getNextHighestDepth(); 00534 } 00535 00537 // 00538 // TODO: rename to setStreamingSoundId 00539 void setStreamSoundId(int id); 00540 00542 // 00562 void removeMovieClip(); 00563 00565 DynamicShape& graphics() { 00566 set_invalidated(); 00567 return _drawable; 00568 } 00569 00571 // 00573 virtual bool handleFocus(); 00574 00576 00578 DSOEXPORT void setVariables(const MovieVariables& vars); 00579 00581 // 00583 virtual void visitNonProperties(KeyVisitor& v) const; 00584 00587 void cleanupDisplayList(); 00588 00590 // 00594 void queueAction(const action_buffer& buf); 00595 00597 // 00602 void constructAsScriptObject(); 00603 00606 bool getLockRoot() const { return _lockroot; } 00607 00610 void setLockRoot(bool lr) { _lockroot=lr; } 00611 00613 virtual int getDefinitionVersion() const; 00614 00615 protected: 00616 00618 // 00620 virtual bool unloadChildren(); 00621 00623 // 00632 virtual void markOwnResources() const; 00633 00634 // Used by BitmapMovie. 00635 void placeDisplayObject(DisplayObject* ch, int depth) { 00636 _displayList.placeDisplayObject(ch, depth); 00637 } 00638 00639 private: 00640 00642 void processCompletedLoadVariableRequests(); 00643 00645 void processCompletedLoadVariableRequest(LoadVariablesThread& request); 00646 00647 00649 // 00658 void executeFrameTags(size_t frame, DisplayList& dlist, 00659 int typeflags = SWF::ControlTag::TAG_DLIST | 00660 SWF::ControlTag::TAG_ACTION); 00661 00662 void stopStreamSound(); 00663 00665 // 00667 // 00670 bool isEnabled() const; 00671 00673 // 00677 bool hitTestDrawable(boost::int32_t x, boost::int32_t y) const; 00678 00680 // 00702 // http://www.gnashdev.org/wiki/index.php/TimelineControl 00709 // 00717 void restoreDisplayList(size_t targetFrame); 00718 00720 void increment_frame_and_check_for_loop(); 00721 00723 void cleanup_textfield_variables(); 00724 00727 const boost::intrusive_ptr<const movie_definition> _def; 00728 00730 typedef boost::ptr_list<LoadVariablesThread> LoadVariablesThreads; 00731 00733 // 00737 LoadVariablesThreads _loadVariableRequests; 00738 00740 Movie* _swf; 00741 00743 DynamicShape _drawable; 00744 00745 PlayState _playState; 00746 00748 as_environment _environment; 00749 00753 std::auto_ptr<TextFieldIndex> _text_variables; 00754 00755 std::string _droptarget; 00756 00757 // 0-based index to current frame 00758 size_t _currentFrame; 00759 00761 int m_sound_stream_id; 00762 00763 // true if this sprite reached the last frame and restarted 00764 bool _hasLooped; 00765 00766 // true if orphaned tags (tags found after last advertised showframe) 00767 // have been executed at least once. 00768 bool _flushedOrphanedTags; 00769 00770 // true is we're calling frame actions 00771 bool _callingFrameActions; 00772 00773 bool _lockroot; 00774 00775 bool _onLoadCalled; 00776 }; 00777 00778 } // end of namespace gnash 00779 00780 #endif // GNASH_SPRITE_INSTANCE_H