Gnash  0.8.11dev
MovieClip.h
Go to the documentation of this file.
1 // MovieClip.h: Stateful live Sprite instance, for Gnash.
2 //
3 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
4 // Free Software Foundation, Inc
5 //
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 3 of the License, or
9 // (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 
20 // Stateful live Sprite instance
21 
22 #ifndef GNASH_MOVIECLIP_H
23 #define GNASH_MOVIECLIP_H
24 
25 #ifdef HAVE_CONFIG_H
26 #include "gnashconfig.h"
27 #endif
28 
29 #include <vector>
30 #include <list>
31 #include <map>
32 #include <string>
33 #include <boost/ptr_container/ptr_list.hpp>
34 #include <boost/intrusive_ptr.hpp>
35 
36 #include "ControlTag.h"
37 #include "movie_definition.h" // for inlines
38 #include "DisplayList.h" // DisplayList
39 #include "DisplayObjectContainer.h"
40 #include "as_environment.h" // for composition
41 #include "DynamicShape.h" // for composition
42 #include "dsodefs.h" // for DSOEXPORT
43 
44 // Forward declarations
45 namespace gnash {
46  class Movie;
47  class swf_event;
48  class drag_state;
49  class LoadVariablesThread;
50  class GradientRecord;
51  class TextField;
52  class BitmapData_as;
53  class CachedBitmap;
54  namespace SWF {
55  class PlaceObject2Tag;
56  }
57 }
58 
59 namespace gnash {
60 
62 //
64 //
67 //
73 //
79 //
85 {
86 public:
87 
88  typedef std::vector<TextField*> TextFields;
89 
91  typedef std::map<ObjectURI, TextFields, ObjectURI::LessThan>
93 
94  typedef std::map<std::string, std::string> MovieVariables;
95 
97 
98  enum PlayState
99  {
102  };
103 
105  //
122  MovieClip(as_object* object, const movie_definition* def,
123  Movie* root, DisplayObject* parent);
124 
125  virtual ~MovieClip();
126 
127  // Return the originating SWF
128  virtual Movie* get_root() const;
129 
130  virtual bool trackAsMenu();
131 
133  //
136  void queueEvent(const event_id& id, int lvl);
137 
138  void queueLoad();
139 
141  //
144  virtual MovieClip* getAsRoot();
145 
147  virtual SWFRect getBounds() const;
148 
149  // See dox in DisplayObject.h
150  virtual bool pointInShape(boost::int32_t x, boost::int32_t y) const;
151 
152  // See dox in DisplayObject.h
153  virtual bool pointInVisibleShape(boost::int32_t x, boost::int32_t y) const;
154 
159  virtual bool pointInHitableShape(boost::int32_t x, boost::int32_t y) const;
160 
162  size_t get_current_frame() const
163  {
164  return _currentFrame;
165  }
166 
167  size_t get_frame_count() const
168  {
169  return _def ? _def->get_frame_count() : 1;
170  }
171 
173  //
177  size_t get_loaded_frames() const
178  {
179  return _def ? _def->get_loading_frame() : 1;
180  }
181 
184  size_t get_bytes_total() const
185  {
186  return isDynamic() ? 0 : _def->get_bytes_total();
187  }
188 
191  size_t get_bytes_loaded() const
192  {
193  return isDynamic() ? 0 : _def->get_bytes_loaded();
194  }
195 
196  const SWFRect& get_frame_size() const
197  {
198  static const SWFRect r;
199  return _def ? _def->get_frame_size() : r;
200  }
201 
203  //
208 
209  PlayState getPlayState() const { return _playState; }
210 
211  // delegates to movie_root (possibly wrong)
212  void set_background_color(const rgba& color);
213 
215  //
218  virtual bool mouseEnabled() const;
219 
224  virtual InteractiveObject* topmostMouseEntity(boost::int32_t x,
225  boost::int32_t y);
226 
227  // see dox in DisplayObject.h
228  const DisplayObject* findDropTarget(boost::int32_t x, boost::int32_t y,
229  DisplayObject* dragging) const;
230 
231  void setDropTarget(const std::string& tgt) {
232  _droptarget = tgt;
233  }
234 
235  const std::string& getDropTarget() const {
236  return _droptarget;
237  }
238 
240  //
242  virtual void advance();
243 
245  //
249  DSOEXPORT void goto_frame(size_t target_frame_number);
250 
252  //
267  bool get_frame_number(const as_value& frame_spec, size_t& frameno) const;
268 
270  bool goto_labeled_frame(const std::string& label);
271 
273  virtual void display(Renderer& renderer, const Transform& xform);
274 
276  //
279  void draw(Renderer& renderer, const Transform& xform);
280 
281  void omit_display();
282 
284  //
286  void swapDepths(DisplayObject* ch1, int newdepth)
287  {
288  _displayList.swapDepths(ch1, newdepth);
289  }
290 
292  //
295 
298 
300  //
320  DisplayList& dlist);
321 
324  DisplayList& dlist);
325 
328  DisplayList& dlist);
329 
332  DisplayList& dlist);
333 
336  //
343  void remove_display_object(int depth, int /*id*/);
344 
345  void unloadMovie();
346 
348  //
351  void attachCharacter(DisplayObject& newch, int depth, as_object* initObject);
352 
354  //
363  //
367  virtual void construct(as_object* initObj = 0);
368 
370  //
384  void destroy();
385 
390  {
391  if (!_callingFrameActions) queueAction(*a);
392  else execute_action(*a);
393  }
394 
395 
399  //
409  void execute_init_action_buffer(const action_buffer& a, int cid);
410 
412  void execute_action(const action_buffer& ab);
413 
414  MovieClip* to_movie () { return this; }
415 
417  //
420  {
424  };
425 
426  // See dox in DisplayObject.h
427  virtual void getLoadedMovie(Movie* newMovie);
428 
432  //
444  void loadVariables(const std::string& urlstr,
445  VariablesMethod sendVarsMethod);
446 
448  //
451  bool getTextFieldVariables(const ObjectURI& uri, as_value& val);
452 
453  // Set TextField variables
454  //
456  bool setTextFieldVariables(const ObjectURI& uri, const as_value& val);
457 
459  //
463  //
468 
470  as_object* pathElement(const ObjectURI& uri);
471 
473  //
475  virtual void call_frame_actions(const as_value& frame_spec);
476 
478  //
495  MovieClip* duplicateMovieClip(const std::string& newname,
496  int newdepth, as_object* init_object = 0);
497 
499  virtual void mouseEvent(const event_id& id) {
500  notifyEvent(id);
501  }
502 
504  //
507  void notifyEvent(const event_id& id);
508 
509  // inherited from DisplayObject class, see dox in DisplayObject.h
511  return _environment;
512  }
513 
516  //
519  void set_textfield_variable(const ObjectURI& name, TextField* ch);
520 
521  void add_invalidated_bounds(InvalidatedRanges& ranges, bool force);
522 
523  const DisplayList& getDisplayList() const {
524  return _displayList;
525  }
526 
528  //
532  int getNextHighestDepth() const {
534  }
535 
537  //
538  // TODO: rename to setStreamingSoundId
539  void setStreamSoundId(int id);
540 
542  //
562  void removeMovieClip();
563 
566  set_invalidated();
567  return _drawable;
568  }
569 
571  //
573  virtual bool handleFocus();
574 
576 
578  DSOEXPORT void setVariables(const MovieVariables& vars);
579 
581  //
583  virtual void visitNonProperties(KeyVisitor& v) const;
584 
587  void cleanupDisplayList();
588 
590  //
594  void queueAction(const action_buffer& buf);
595 
597  //
603 
606  bool getLockRoot() const { return _lockroot; }
607 
610  void setLockRoot(bool lr) { _lockroot=lr; }
611 
613  virtual int getDefinitionVersion() const;
614 
615 protected:
616 
618  //
620  virtual bool unloadChildren();
621 
623  //
632  virtual void markOwnResources() const;
633 
634  // Used by BitmapMovie.
635  void placeDisplayObject(DisplayObject* ch, int depth) {
636  _displayList.placeDisplayObject(ch, depth);
637  }
638 
639 private:
640 
642  void processCompletedLoadVariableRequests();
643 
645  void processCompletedLoadVariableRequest(LoadVariablesThread& request);
646 
647 
649  //
658  void executeFrameTags(size_t frame, DisplayList& dlist,
659  int typeflags = SWF::ControlTag::TAG_DLIST |
661 
662  void stopStreamSound();
663 
665  //
667  //
670  bool isEnabled() const;
671 
673  //
677  bool hitTestDrawable(boost::int32_t x, boost::int32_t y) const;
678 
680  //
702  // http://www.gnashdev.org/wiki/index.php/TimelineControl
709  //
717  void restoreDisplayList(size_t targetFrame);
718 
720  void increment_frame_and_check_for_loop();
721 
723  void cleanup_textfield_variables();
724 
727  const boost::intrusive_ptr<const movie_definition> _def;
728 
730  typedef boost::ptr_list<LoadVariablesThread> LoadVariablesThreads;
731 
733  //
737  LoadVariablesThreads _loadVariableRequests;
738 
740  Movie* _swf;
741 
743  DynamicShape _drawable;
744 
745  PlayState _playState;
746 
748  as_environment _environment;
749 
753  std::auto_ptr<TextFieldIndex> _text_variables;
754 
755  std::string _droptarget;
756 
757  // 0-based index to current frame
758  size_t _currentFrame;
759 
761  int m_sound_stream_id;
762 
763  // true if this sprite reached the last frame and restarted
764  bool _hasLooped;
765 
766  // true if orphaned tags (tags found after last advertised showframe)
767  // have been executed at least once.
768  bool _flushedOrphanedTags;
769 
770  // true is we're calling frame actions
771  bool _callingFrameActions;
772 
773  bool _lockroot;
774 
775  bool _onLoadCalled;
776 };
777 
778 } // end of namespace gnash
779 
780 #endif // GNASH_SPRITE_INSTANCE_H