Gnash  0.8.11dev
gui.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010,
3 // 2011 Free Software Foundation, Inc
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 
19 #ifndef GNASH_GUI_H
20 #define GNASH_GUI_H
21 
22 #ifdef HAVE_CONFIG_H
23 #include "gnashconfig.h"
24 #endif
25 
26 #include <boost/intrusive_ptr.hpp>
27 #include <memory>
28 #include <string>
29 #include <map>
30 #include <utility>
31 #include <functional>
32 
33 #include "snappingrange.h" // for InvalidatedRanges
34 #include "GnashKey.h"
35 #include "VirtualClock.h"
36 #include "SystemClock.h"
37 #include "GnashEnums.h"
38 #include "movie_root.h"
39 
40 #ifdef USE_SWFTREE
41 #include "tree.hh" // for tree
42 #endif
43 
44 // Define this to enable fps debugging without touching
45 // gnashconfig.h
46 //#define GNASH_FPS_DEBUG
47 
58 //#define DISABLE_REGION_UPDATES_DEBUGGING 1
59 
60 
62 #define ENABLE_KEYBOARD_MOUSE_MOVEMENTS 1
63 
64 // Forward declarations
65 namespace gnash {
66  class SWFRect;
67  class ScreenShotter;
68  class RunResources;
69  class movie_root;
70  class movie_definition;
71  class Renderer;
72  class SWFRect;
73 }
74 namespace boost {
75  template <typename Signature> class function;
76 }
77 
78 namespace gnash {
79 
85 };
86 
88 class Gui {
89 
90 public:
91 
92  virtual ~Gui();
93 
100  virtual bool init(int argc, char **argv[]) = 0;
101 
103  virtual void setInterval(unsigned int interval) {
104  _interval = interval;
105  }
106 
108  //
112  virtual VirtualClock& getClock() { return _virtualClock; }
113 
115  virtual void setTimeout(unsigned int timeout) = 0;
116 
117  void setScreenShotter(std::unique_ptr<ScreenShotter> ss);
118 
127  virtual bool createWindow(const char* title, int width, int height,
128  int xPosition = 0, int yPosition = 0) = 0;
129 
130  virtual void resizeWindow(int width, int height);
131 
133  virtual bool run() = 0;
134 
136  //
138  void quit();
139 
142  virtual void renderBuffer() = 0;
143 
145  //
159  // does not need to be implemented (optional feature),
160  // but still needs to be available.
161  //
162  virtual void setInvalidatedRegion(const SWFRect& bounds);
163  virtual void setInvalidatedRegions(const InvalidatedRanges& ranges);
164 
165  // Called right before rendering anything (after setInvalidatedRegion).
166  // Used by GTK-AGG.
167  virtual void beforeRendering() { /* nop */ };
168 
169  // Should return TRUE when the GUI/Renderer combination supports multiple
170  // invalidated bounds regions.
171  virtual bool want_multiple_regions() { return false; }
172 
174  //
178  virtual bool want_redraw();
179 
181  virtual void setCursor(gnash_cursor_type newcursor);
182 
183  virtual void setClipboard(const std::string& copy);
184 
185  // Information for System.capabilities to be reimplemented in
186  // each gui.
187  virtual double getPixelAspectRatio() const { return 0; }
188 
189  virtual std::pair<int, int> screenResolution() const {
190  return std::make_pair(0, 0);
191  }
192 
193  virtual double getScreenDPI() const { return 0; }
194 
196  //
200  virtual std::string getScreenColor() const {
201  return "color";
202  }
203 
205  bool loops() const { return _loop; }
206 
208  bool isFullscreen() const { return _fullscreen; }
209 
211  //
216  void notifyMouseMove(int x, int y);
217 
219  //
222  void notifyMouseClick(bool mouse_pressed);
223 
225  //
227  void notifyMouseWheel(int delta);
228 
230  //
238  void notify_key_event(gnash::key::code k, int modifier, bool pressed);
239 
241  //
244  void resize_view(int width, int height);
245 
248  //
252  void updateStageMatrix();
253 
256  //
265  bool advanceMovie(bool doDisplay = true);
266 
268  //
272  static bool advance_movie(Gui* gui) {
273  gui->advanceMovie();
274  return true;
275  }
276 
279  void refreshView();
280 
283  //
288  virtual void setFullscreen();
289 
292  virtual void unsetFullscreen();
293 
296  virtual void hideMenu();
297 
299  //
302  virtual bool showMouse(bool show);
303 
305  //
307  virtual void showMenu(bool show);
308 
310  //
312  virtual void allowScale(bool allow);
313 
314  // Toggle between fullscreen and normal mode
315  void toggleFullscreen();
316 
318  //
321  void stop();
322 
324  //
327  void play();
328 
330  //
333  void pause();
334 
336  //
340  void start();
341 
343  bool isStopped() const { return _stopped; }
344 
346  bool isPlugin() const { return ((_xid)); }
347 
349  void takeScreenShot();
350 
352  void setMaxAdvances(unsigned long ul) { if (ul) _maxAdvances = ul; }
353 
354  void showUpdatedRegions(bool x) { _showUpdatedRegions = x; }
355  bool showUpdatedRegions() const { return _showUpdatedRegions; }
356 
360  void restart();
361 
363  void setQuality(Quality q);
364 
366  Quality getQuality() const;
367 
370  void toggleSound();
371 
372 #ifdef GNASH_FPS_DEBUG
373  //
377  void setFpsTimerInterval(float interval)
378  {
379  assert(interval >= 0.0);
380  fps_timer_interval = interval;
381  }
382 #endif // def GNASH_FPS_DEBUG
383 
384 
385 #ifdef USE_SWFTREE
386  std::unique_ptr<movie_root::InfoTree> getMovieInfo() const;
388 #endif
389 
390  typedef std::map<std::string, std::string> VariableMap;
391 
393  void addFlashVars(VariableMap& vars);
394 
396  void setMovieDefinition(movie_definition* md);
397 
399  void setStage(movie_root* stage);
400 
402  void setAudioDump(const std::string& fname) {
403  _audioDump = fname;
404  }
405 
407  movie_root* getStage() { return _stage; };
408 
410  //
413  virtual void error(const std::string& /*msg*/) {}
414 
416  //
425  virtual bool yesno(const std::string& question);
426 
428  float getXScale() const { return _xscale; };
429 
431  float getYScale() const { return _yscale; };
432 
434  float getFPS() const { return (_movieDef) ? _movieDef->get_frame_rate() : 0;
435  };
436 
437 protected:
438 
440  Gui(RunResources& r);
441 
456  Gui(unsigned long xid, float scale, bool loop, RunResources& r);
457 
459  //
461  //
464  virtual void quitUI() {
465  std::exit(EXIT_SUCCESS);
466  }
467 
469  //
475  virtual bool watchFD(int /* fd */)
476  {
477  log_unimpl("This GUI does not implement FD watching.");
478  return false;
479  }
480 
481 
483  bool _loop;
484 
486  unsigned long _xid;
487 
488  // This would be 0,0,_width,_height, so maybe
489  // we should not duplicate the info with those
490  // explicit values too..
492 
494  int _width;
495 
497  int _height;
498 
501 
503  unsigned int _interval;
504 
506  std::shared_ptr<Renderer> _renderer;
507 
511 
512  // True if Gnash is running in fullscreen
514 
515  // True if mouse pointer is showing
517 
518  // Maximum number of advances before exit; 0 for no limit.
519  unsigned long _maxAdvances;
520 
522  unsigned long _advances;
523 
525  std::string _audioDump;
526 
529  virtual void stopHook() {}
530 
532  virtual void playHook() {}
533 
535  virtual bool visible() { return true; }
536 private:
537 
538  struct Display;
539 
540  std::map<int /* fd */, std::function<void ()> > _fd_callbacks;
541 
543  float _xscale;
544 
546  float _yscale;
547 
549  std::int32_t _xoffset;
550 
552  std::int32_t _yoffset;
553 
554  bool display(movie_root* m);
555 
556 #ifdef GNASH_FPS_DEBUG
557  unsigned int fps_counter;
558 
559  float fps_rate_min, fps_rate_max;
560 
561  // Number of calls to fpsCounterTick, which is also
562  // the number of calls to movie_advance()
563  unsigned int fps_counter_total;
564 
565  std::uint64_t fps_timer, fps_start_timer;
566 
568  //
571  float fps_timer_interval;
572 
574  unsigned int frames_dropped;
575 
579  //
582  void fpsCounterTick();
583 
584 #endif // def GNASH_FPS_DEBUG
585 
586  VariableMap _flashVars;
587 
588  boost::intrusive_ptr<movie_definition> _movieDef;
589 
591  movie_root* _stage;
592 
594  bool _stopped;
595 
597  bool _started;
598 
600  bool _showUpdatedRegions;
601 
602  SystemClock _systemClock;
603  InterruptableVirtualClock _virtualClock;
604 
606  std::unique_ptr<ScreenShotter> _screenShotter;
607 
608 #ifdef ENABLE_KEYBOARD_MOUSE_MOVEMENTS
609  int _xpointer;
610  int _ypointer;
611  bool _keyboardMouseMovements;
612  int _keyboardMouseMovementsStep;
613 #endif // ENABLE_KEYBOARD_MOUSE_MOVEMENTS
614 };
615 
617 namespace gui {
618  std::unique_ptr<Gui> createFBGui(unsigned long xid, float scale, bool loop, RunResources& r);
619 }
620 std::unique_ptr<Gui> createGTKGui(unsigned long xid, float scale, bool loop, RunResources& r);
621 std::unique_ptr<Gui> createKDEGui(unsigned long xid, float scale, bool loop, RunResources& r);
622 std::unique_ptr<Gui> createQt4Gui(unsigned long xid, float scale, bool loop, RunResources& r);
623 std::unique_ptr<Gui> createSDLGui(unsigned long xid, float scale, bool loop, RunResources& r);
624 std::unique_ptr<Gui> createFLTKGui(unsigned long xid, float scale, bool loop, RunResources& r);
625 std::unique_ptr<Gui> createAQUAGui(unsigned long xid, float scale, bool loop, RunResources& r);
626 std::unique_ptr<Gui> createRISCOSGui(unsigned long xid, float scale, bool loop, RunResources& r);
627 std::unique_ptr<Gui> createAOS4Gui(unsigned long xid, float scale, bool loop, RunResources& r);
628 std::unique_ptr<Gui> createHaikuGui(unsigned long xid, float scale, bool loop, RunResources& r);
629 std::unique_ptr<Gui> createDumpGui(unsigned long xid, float scale, bool loop, RunResources& r);
630 
631 
632 } // end of gnash namespace
633 
634 // end of _GUI_H_
635 #endif
636 
637 // Local Variables:
638 // mode: C++
639 // indent-tabs-mode: nil
640 // End:
std::string _audioDump
Name of a file to dump audio to.
Definition: gui.h:525
unsigned int _interval
Main loop interval: the time between successive advance_movie calls.
Definition: gui.h:503
std::unique_ptr< Gui > createFBGui(unsigned long windowid, float scale, bool do_loop, RunResources &r)
Definition: fb.cpp:141
modifier
Definition: GnashKey.h:33
Client program&#39;s interface to the definition of a movie or sprite.
Definition: movie_definition.h:95
A class used to virtualize time flow.
Definition: VirtualClock.h:33
float getYScale() const
Height of a window pixel, in stage pseudopixel units.
Definition: gui.h:431
Definition: gui.h:74
bool isFullscreen() const
Definition: gui.h:208
A system-clock based virtual clock.
Definition: SystemClock.h:36
std::unique_ptr< Gui > createAQUAGui(unsigned long, float, bool, RunResourcesfloat, bool, unsigned int)
Definition: gui_aqua.cpp:40
Definition: klash_part.cpp:330
std::unique_ptr< Gui > createQt4Gui(unsigned long xid, float scale, bool loop, RunResources &r)
virtual bool watchFD(int)
Watch a file descriptor.
Definition: gui.h:475
std::unique_ptr< Gui > createDumpGui(unsigned long, float, bool, RunResourcesfloat, bool, unsigned int)
Definition: gui_dump.cpp:40
std::map< std::string, std::string > VariableMap
Definition: gui.h:390
int _height
Desired window height.
Definition: gui.h:497
virtual bool visible()
Determines whether the Gui is visible (not obscured).
Definition: gui.h:535
Definition: GnashKey.h:163
Definition: gui.h:83
void showUpdatedRegions(bool x)
Definition: gui.h:354
Definition: GnashKey.h:157
bool _loop
Determines if playback should restart after the movie ends.
Definition: gui.h:483
float getXScale() const
Width of a window pixel, in stage pseudopixel units.
Definition: gui.h:428
Anonymous namespace for callbacks, local functions, event handlers etc.
Definition: dbus_ext.cpp:40
gnash_cursor_type
Enumerates mouse cursor types.
Definition: gui.h:81
Definition: gui.h:75
Quality
Definition: GnashEnums.h:34
void setMaxAdvances(unsigned long ul)
Set the maximum number of frame advances before Gnash exits.
Definition: gui.h:352
virtual std::string getScreenColor() const
Get the screen color type.
Definition: gui.h:200
virtual VirtualClock & getClock()
Return the clock provided by this Gui.
Definition: gui.h:112
Definition: klash_part.cpp:329
Definition: gui.h:84
bool _redraw_flag
Definition: gui.h:510
virtual void playHook()
Called by Gui::play().
Definition: gui.h:532
std::unique_ptr< Gui > createGTKGui(unsigned long, float, bool, RunResourcesfloat, bool, unsigned int)
Definition: gui_gtk.cpp:41
Definition: klash_part.cpp:330
code
Definition: GnashKey.h:43
Parent class from which all GUI implementations will depend.
Definition: gui.h:88
Definition: GnashKey.h:164
movie_root * getStage()
The root movie, or "Stage".
Definition: gui.h:407
RunResources & _runResources
Per-run resources.
Definition: gui.h:500
bool loops() const
Definition: gui.h:205
bool _fullscreen
Definition: gui.h:513
bool isStopped() const
See stop(), play() and pause()
Definition: gui.h:343
Definition: klash_part.cpp:329
bool _mouseShown
Definition: gui.h:516
void log_unimpl(StringType msg, Args... args)
Definition: log.h:289
Class to group together per-run and external resources for Gnash.
Definition: RunResources.h:53
virtual std::pair< int, int > screenResolution() const
Definition: gui.h:189
virtual double getScreenDPI() const
Definition: gui.h:193
unsigned long _advances
Counter to keep track of frame advances.
Definition: gui.h:522
bool isPlugin() const
Whether gnash is is running as a plugin.
Definition: gui.h:346
A VirtualClock wrapper adding pause/resume capabilities.
Definition: VirtualClock.h:54
bool allow(const URL &url, const URL &baseurl)
Return true if access to given url is allowed, false otherwise.
Definition: URLAccessManager.cpp:273
virtual void error(const std::string &)
Handle error message from the core.
Definition: gui.h:413
bool showUpdatedRegions() const
Definition: gui.h:355
void setAudioDump(const std::string &fname)
Set the name of a file to dump audio to.
Definition: gui.h:402
std::int32_t x
Definition: BitmapData_as.cpp:434
static bool advance_movie(Gui *gui)
Convenience static wrapper around advanceMovie for callbacks happiness.
Definition: gui.h:272
Definition: gui.h:82
virtual void beforeRendering()
Definition: gui.h:167
std::unique_ptr< Gui > createSDLGui(unsigned long xid, float scale, bool loop, RunResources &r)
std::shared_ptr< Renderer > _renderer
The handler which is called to update the client area of our window.
Definition: gui.h:506
unsigned long _maxAdvances
Definition: gui.h:519
std::int32_t y
Definition: BitmapData_as.cpp:435
float getFPS() const
Height of a window pixel, in stage pseudopixel units.
Definition: gui.h:434
std::unique_ptr< Gui > createFLTKGui(unsigned long, float, bool, RunResourcesfloat, bool, unsigned int)
Definition: gui_fltk.cpp:40
virtual void stopHook()
Definition: gui.h:529
Rectangle class, see swf defined rectangle record.
Definition: SWFRect.h:44
int _width
Desired window width.
Definition: gui.h:494
Definition: klash_part.cpp:330
std::unique_ptr< Gui > createKDEGui(unsigned long xid, float scale, bool loop, RunResources &r)
unsigned long _xid
The X Window ID to attach to. If zero, we create a new window.
Definition: gui.h:486
std::unique_ptr< Gui > createRISCOSGui(unsigned long xid, float scale, bool loop, RunResources &r)
virtual bool want_multiple_regions()
Definition: gui.h:171
std::unique_ptr< Gui > createHaikuGui(unsigned long xid, float scale, bool loop, RunResources &r)
Definition: GnashKey.h:159
std::unique_ptr< Gui > createAOS4Gui(unsigned long, float, bool, RunResourcesfloat, bool, unsigned int)
Definition: gui_aos4.cpp:40
virtual double getPixelAspectRatio() const
Definition: gui.h:187
geometry::Range2d< int > _validbounds
Definition: gui.h:491
virtual void quitUI()
End main rendering loop calling GUI-specific exit functions.
Definition: gui.h:464
virtual void setInterval(unsigned int interval)
Set main loop delay in milliseconds.
Definition: gui.h:103
bool advanceMovie(bool doDisplay=true)
Give movie an heart-beat.
Definition: gui.cpp:935
This class represents the &#39;Stage&#39; and top-level movie.
Definition: movie_root.h:150