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 <map>
31 #include <string>
32 #include <boost/ptr_container/ptr_list.hpp>
33 #include <boost/intrusive_ptr.hpp>
34 
35 #include "ControlTag.h"
36 #include "movie_definition.h" // for inlines
37 #include "DisplayObjectContainer.h"
38 #include "as_environment.h" // for composition
39 #include "DynamicShape.h" // for composition
40 #include "dsodefs.h" // for DSOEXPORT
41 
42 // Forward declarations
43 namespace gnash {
44  class Movie;
45  class swf_event;
46  class drag_state;
47  class LoadVariablesThread;
48  class GradientRecord;
49  class TextField;
50  class BitmapData_as;
51  class CachedBitmap;
52  class DisplayList;
53  namespace SWF {
54  class PlaceObject2Tag;
55  }
56 }
57 
58 namespace gnash {
59 
61 //
63 //
66 //
72 //
78 //
84 {
85 public:
86 
87  typedef std::vector<TextField*> TextFields;
88 
90  typedef std::map<ObjectURI, TextFields, ObjectURI::LessThan>
92 
93  typedef std::map<std::string, std::string> MovieVariables;
94 
96 
97  enum PlayState
98  {
100  PLAYSTATE_STOP
101  };
102 
104  //
121  MovieClip(as_object* object, const movie_definition* def,
122  Movie* root, DisplayObject* parent);
123 
124  virtual ~MovieClip();
125 
126  // Return the originating SWF
127  virtual Movie* get_root() const;
128 
129  virtual bool trackAsMenu();
130 
132  //
135  void queueEvent(const event_id& id, int lvl);
136 
137  void queueLoad();
138 
140  //
143  virtual MovieClip* getAsRoot();
144 
146  virtual SWFRect getBounds() const;
147 
148  // See dox in DisplayObject.h
149  virtual bool pointInShape(std::int32_t x, std::int32_t y) const;
150 
151  // See dox in DisplayObject.h
152  virtual bool pointInVisibleShape(std::int32_t x, std::int32_t y) const;
153 
158  virtual bool pointInHitableShape(std::int32_t x, std::int32_t y) const;
159 
161  size_t get_current_frame() const
162  {
163  return _currentFrame;
164  }
165 
166  size_t get_frame_count() const
167  {
168  return _def ? _def->get_frame_count() : 1;
169  }
170 
172  //
176  size_t get_loaded_frames() const
177  {
178  return _def ? _def->get_loading_frame() : 1;
179  }
180 
183  size_t get_bytes_total() const
184  {
185  return isDynamic() ? 0 : _def->get_bytes_total();
186  }
187 
190  size_t get_bytes_loaded() const
191  {
192  return isDynamic() ? 0 : _def->get_bytes_loaded();
193  }
194 
195  const SWFRect& get_frame_size() const
196  {
197  static const SWFRect r;
198  return _def ? _def->get_frame_size() : r;
199  }
200 
202  //
206  DSOEXPORT void setPlayState(PlayState s);
207 
208  PlayState getPlayState() const { return _playState; }
209 
210  // delegates to movie_root (possibly wrong)
211  void set_background_color(const rgba& color);
212 
214  //
217  virtual bool mouseEnabled() const;
218 
223  virtual InteractiveObject* topmostMouseEntity(std::int32_t x,
224  std::int32_t y);
225 
226  // see dox in DisplayObject.h
227  const DisplayObject* findDropTarget(std::int32_t x, std::int32_t y,
228  DisplayObject* dragging) const;
229 
230  void setDropTarget(const std::string& tgt) {
231  _droptarget = tgt;
232  }
233 
234  const std::string& getDropTarget() const {
235  return _droptarget;
236  }
237 
239  //
241  virtual void advance();
242 
244  //
248  DSOEXPORT void goto_frame(size_t target_frame_number);
249 
251  //
266  bool get_frame_number(const as_value& frame_spec, size_t& frameno) const;
267 
269  bool goto_labeled_frame(const std::string& label);
270 
272  virtual void display(Renderer& renderer, const Transform& xform);
273 
275  //
278  void draw(Renderer& renderer, const Transform& xform);
279 
280  void omit_display();
281 
283  //
285  void swapDepths(DisplayObject* ch1, int newdepth)
286  {
287  _displayList.swapDepths(ch1, newdepth);
288  }
289 
291  //
293  DisplayObject* getDisplayObjectAtDepth(int depth);
294 
296  DisplayObject* addDisplayListObject(DisplayObject* obj, int depth);
297 
299  //
318  DisplayObject* add_display_object(const SWF::PlaceObject2Tag* tag,
319  DisplayList& dlist);
320 
322  void move_display_object(const SWF::PlaceObject2Tag* tag,
323  DisplayList& dlist);
324 
326  void replace_display_object(const SWF::PlaceObject2Tag* tag,
327  DisplayList& dlist);
328 
330  void remove_display_object(const SWF::PlaceObject2Tag* tag,
331  DisplayList& dlist);
332 
335  //
342  void remove_display_object(int depth, int /*id*/);
343 
344  void unloadMovie();
345 
347  //
350  void attachCharacter(DisplayObject& newch, int depth, as_object* initObject);
351 
353  //
362  //
366  virtual void construct(as_object* initObj = nullptr);
367 
369  //
383  void destroy();
384 
389  {
390  if (!_callingFrameActions) queueAction(*a);
391  else execute_action(*a);
392  }
393 
394 
398  //
408  void execute_init_action_buffer(const action_buffer& a, int cid);
409 
411  void execute_action(const action_buffer& ab);
412 
413  MovieClip* to_movie () { return this; }
414 
416  //
419  {
420  METHOD_NONE = 0,
422  METHOD_POST
423  };
424 
425  // See dox in DisplayObject.h
426  virtual void getLoadedMovie(Movie* newMovie);
427 
431  //
443  void loadVariables(const std::string& urlstr,
444  VariablesMethod sendVarsMethod);
445 
447  //
450  bool getTextFieldVariables(const ObjectURI& uri, as_value& val);
451 
452  // Set TextField variables
453  //
455  bool setTextFieldVariables(const ObjectURI& uri, const as_value& val);
456 
458  //
462  //
466  DisplayObject* getDisplayListObject(const ObjectURI& uri);
467 
469  as_object* pathElement(const ObjectURI& uri);
470 
472  //
474  virtual void call_frame_actions(const as_value& frame_spec);
475 
477  //
494  MovieClip* duplicateMovieClip(const std::string& newname,
495  int newdepth, as_object* init_object = nullptr);
496 
498  virtual void mouseEvent(const event_id& id) {
499  notifyEvent(id);
500  }
501 
503  //
506  void notifyEvent(const event_id& id);
507 
508  // inherited from DisplayObject class, see dox in DisplayObject.h
510  return _environment;
511  }
512 
515  //
518  void set_textfield_variable(const ObjectURI& name, TextField* ch);
519 
520  void add_invalidated_bounds(InvalidatedRanges& ranges, bool force);
521 
522  const DisplayList& getDisplayList() const {
523  return _displayList;
524  }
525 
527  //
531  int getNextHighestDepth() const {
532  return _displayList.getNextHighestDepth();
533  }
534 
536  //
537  // TODO: rename to setStreamingSoundId
538  void setStreamSoundId(int id);
539 
541  //
561  void removeMovieClip();
562 
565  set_invalidated();
566  return _drawable;
567  }
568 
570  //
572  virtual bool handleFocus();
573 
575 
577  DSOEXPORT void setVariables(const MovieVariables& vars);
578 
580  //
582  virtual void visitNonProperties(KeyVisitor& v) const;
583 
586  void cleanupDisplayList();
587 
589  //
593  void queueAction(const action_buffer& buf);
594 
596  //
601  void constructAsScriptObject();
602 
605  bool getLockRoot() const { return _lockroot; }
606 
609  void setLockRoot(bool lr) { _lockroot=lr; }
610 
612  virtual int getDefinitionVersion() const;
613 
614 protected:
615 
617  //
619  virtual bool unloadChildren();
620 
622  //
631  virtual void markOwnResources() const;
632 
633  // Used by BitmapMovie.
634  void placeDisplayObject(DisplayObject* ch, int depth) {
635  _displayList.placeDisplayObject(ch, depth);
636  }
637 
638 private:
639 
641  void processCompletedLoadVariableRequests();
642 
644  void processCompletedLoadVariableRequest(LoadVariablesThread& request);
645 
646 
648  //
657  void executeFrameTags(size_t frame, DisplayList& dlist,
658  int typeflags = SWF::ControlTag::TAG_DLIST |
660 
661  void stopStreamSound();
662 
664  //
666  //
669  bool isEnabled() const;
670 
672  //
676  bool hitTestDrawable(std::int32_t x, std::int32_t y) const;
677 
679  //
701  // http://www.gnashdev.org/wiki/index.php/TimelineControl
708  //
716  void restoreDisplayList(size_t targetFrame);
717 
719  void increment_frame_and_check_for_loop();
720 
722  void cleanup_textfield_variables();
723 
726  const boost::intrusive_ptr<const movie_definition> _def;
727 
729  typedef boost::ptr_list<LoadVariablesThread> LoadVariablesThreads;
730 
732  //
736  LoadVariablesThreads _loadVariableRequests;
737 
739  Movie* _swf;
740 
742  DynamicShape _drawable;
743 
744  PlayState _playState;
745 
747  as_environment _environment;
748 
752  std::unique_ptr<TextFieldIndex> _text_variables;
753 
754  std::string _droptarget;
755 
756  // 0-based index to current frame
757  size_t _currentFrame;
758 
760  int m_sound_stream_id;
761 
762  // true if this sprite reached the last frame and restarted
763  bool _hasLooped;
764 
765  // true if orphaned tags (tags found after last advertised showframe)
766  // have been executed at least once.
767  bool _flushedOrphanedTags;
768 
769  // true is we're calling frame actions
770  bool _callingFrameActions;
771 
772  bool _lockroot;
773 
774  bool _onLoadCalled;
775 };
776 
777 } // end of namespace gnash
778 
779 #endif // GNASH_SPRITE_INSTANCE_H
Definition: GnashKey.h:147
VariablesMethod
The various methods for sending data in requests.
Definition: MovieClip.h:418
std::vector< TextField * > TextFields
Definition: MovieClip.h:87
std::map< ObjectURI, TextFields, ObjectURI::LessThan > TextFieldIndex
A container for textfields, indexed by their variable name.
Definition: MovieClip.h:91
Client program&#39;s interface to the definition of a movie or sprite.
Definition: movie_definition.h:95
Definition: ControlTag.h:51
size_t get_loaded_frames() const
Return number of completely loaded frames of this sprite/movie.
Definition: MovieClip.h:176
MovieClip * to_movie()
Definition: MovieClip.h:413
A MovieClip is a container for DisplayObjects.
Definition: MovieClip.h:83
DisplayObject is the base class for all DisplayList objects.
Definition: DisplayObject.h:168
ActionScript value type.
Definition: as_value.h:94
const SWFRect & get_frame_size() const
Definition: MovieClip.h:195
movie_definition::PlayList PlayList
Definition: MovieClip.h:95
uri
Definition: test.py:12
virtual as_environment & get_environment()
Return a reference to the variable scope of this DisplayObject.
Definition: MovieClip.h:509
v
Definition: test.py:11
A top-level, standalone Movie that can be loaded and played.
Definition: Movie.h:46
Anonymous namespace for callbacks, local functions, event handlers etc.
Definition: dbus_ext.cpp:40
std::map< std::string, std::string > MovieVariables
Definition: MovieClip.h:93
bool getLockRoot() const
Definition: MovieClip.h:605
The base class for all ActionScript objects.
Definition: as_object.h:161
SWF Tag PlaceObject (4) or PlaceObject2 (9)
Definition: PlaceObject2Tag.h:85
Base class for render handlers.
Definition: Renderer.h:188
size_t get_bytes_total() const
Definition: MovieClip.h:183
const VGfloat color[4]
Definition: testr_gtk.cpp:82
A URI for describing as_objects.
Definition: ObjectURI.h:44
Definition: GnashKey.h:164
PlayState
Definition: MovieClip.h:97
The DynamicShape class represents a mutable shape.
Definition: DynamicShape.h:44
Provides information about timeline context.
Definition: as_environment.h:50
size_t get_frame_count() const
Definition: MovieClip.h:166
void swapDepths(DisplayObject *ch1, int newdepth)
Swap depth of the given DisplayObjects in the DisplayList.
Definition: MovieClip.h:285
A manager for loadVariable requests.
Definition: LoadVariablesThread.h:48
std::vector< boost::intrusive_ptr< SWF::ControlTag > > PlayList
Definition: movie_definition.h:98
int getNextHighestDepth() const
Return the next highest available depth.
Definition: MovieClip.h:531
const std::string & getDropTarget() const
Definition: MovieClip.h:234
const DisplayList & getDisplayList() const
Definition: MovieClip.h:522
std::int32_t x
Definition: BitmapData_as.cpp:434
size_t get_bytes_loaded() const
Definition: MovieClip.h:190
Definition: DisplayObjectContainer.h:42
#define DSOEXPORT
Definition: dsodefs.h:55
DynamicShape & graphics()
Direct access to the Graphics object for drawing.
Definition: MovieClip.h:564
Definition: MovieClip.h:99
void setDropTarget(const std::string &tgt)
Definition: MovieClip.h:230
virtual void mouseEvent(const event_id &id)
Called when a mouse event affects this MovieClip.
Definition: MovieClip.h:498
The base class for interactive objects.
Definition: InteractiveObject.h:44
std::int32_t y
Definition: BitmapData_as.cpp:435
Rectangle class, see swf defined rectangle record.
Definition: SWFRect.h:44
#define DSOTEXPORT
Definition: dsodefs.h:63
Definition: MovieClip.h:421
PlayState getPlayState() const
Definition: MovieClip.h:208
void add_action_buffer(const action_buffer *a)
Definition: MovieClip.h:388
A class to identify &#39;static&#39; SWF events (system events).
Definition: event_id.h:52
size_t get_current_frame() const
Return 0-based index to current frame.
Definition: MovieClip.h:161
Definition: GnashKey.h:165
A code segment.
Definition: action_buffer.h:49
void setLockRoot(bool lr)
Definition: MovieClip.h:609
An abstract key visitor.
Definition: PropertyList.h:58
A list of on-stage DisplayObjects, ordered by depth.
Definition: DisplayList.h:64
std::string name
Definition: LocalConnection_as.cpp:149
Definition: GnashKey.h:331
The Transform class expresses a stage in a cumulative transformation.
Definition: Transform.h:33
An instance of a DefineEditTextTag.
Definition: TextField.h:56
void placeDisplayObject(DisplayObject *ch, int depth)
Definition: MovieClip.h:634
Definition: ControlTag.h:50
A basic RGBA type.
Definition: RGBA.h:35