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 <boost/scoped_ptr.hpp>
28 #include <string>
29 #include <map>
30 #include <utility>
31 
32 #include "snappingrange.h" // for InvalidatedRanges
33 #include "GnashKey.h"
34 #include "VirtualClock.h"
35 #include "SystemClock.h"
36 #include "GnashEnums.h"
37 #include "movie_root.h"
38 
39 #ifdef USE_SWFTREE
40 #include "tree.hh" // for tree
41 #endif
42 
43 // Define this to enable fps debugging without touching
44 // gnashconfig.h
45 //#define GNASH_FPS_DEBUG
46 
57 //#define DISABLE_REGION_UPDATES_DEBUGGING 1
58 
59 
61 #define ENABLE_KEYBOARD_MOUSE_MOVEMENTS 1
62 
63 // Forward declarations
64 namespace gnash {
65  class SWFRect;
66  class ScreenShotter;
67  class RunResources;
68  class movie_root;
69  class movie_definition;
70  class Renderer;
71  class SWFRect;
72 }
73 namespace boost {
74  template <typename Signature> class function;
75 }
76 
77 namespace gnash {
78 
84 };
85 
87 class Gui {
88 
89 public:
90 
91  virtual ~Gui();
92 
99  virtual bool init(int argc, char **argv[]) = 0;
100 
102  virtual void setInterval(unsigned int interval) {
103  _interval = interval;
104  }
105 
107  //
111  virtual VirtualClock& getClock() { return _virtualClock; }
112 
114  virtual void setTimeout(unsigned int timeout) = 0;
115 
116  void setScreenShotter(std::auto_ptr<ScreenShotter> ss);
117 
126  virtual bool createWindow(const char* title, int width, int height,
127  int xPosition = 0, int yPosition = 0) = 0;
128 
129  virtual void resizeWindow(int width, int height);
130 
132  virtual bool run() = 0;
133 
135  //
137  void quit();
138 
141  virtual void renderBuffer() = 0;
142 
144  //
158  // does not need to be implemented (optional feature),
159  // but still needs to be available.
160  //
161  virtual void setInvalidatedRegion(const SWFRect& bounds);
162  virtual void setInvalidatedRegions(const InvalidatedRanges& ranges);
163 
164  // Called right before rendering anything (after setInvalidatedRegion).
165  // Used by GTK-AGG.
166  virtual void beforeRendering() { /* nop */ };
167 
168  // Should return TRUE when the GUI/Renderer combination supports multiple
169  // invalidated bounds regions.
170  virtual bool want_multiple_regions() { return false; }
171 
173  //
177  virtual bool want_redraw();
178 
180  virtual void setCursor(gnash_cursor_type newcursor);
181 
182  virtual void setClipboard(const std::string& copy);
183 
184  // Information for System.capabilities to be reimplemented in
185  // each gui.
186  virtual double getPixelAspectRatio() const { return 0; }
187 
188  virtual std::pair<int, int> screenResolution() const {
189  return std::make_pair(0, 0);
190  }
191 
192  virtual double getScreenDPI() const { return 0; }
193 
195  //
199  virtual std::string getScreenColor() const {
200  return "color";
201  }
202 
204  bool loops() const { return _loop; }
205 
207  bool isFullscreen() const { return _fullscreen; }
208 
210  //
215  void notifyMouseMove(int x, int y);
216 
218  //
221  void notifyMouseClick(bool mouse_pressed);
222 
224  //
226  void notifyMouseWheel(int delta);
227 
229  //
237  void notify_key_event(gnash::key::code k, int modifier, bool pressed);
238 
240  //
243  void resize_view(int width, int height);
244 
247  //
251  void updateStageMatrix();
252 
255  //
264  bool advanceMovie(bool doDisplay = true);
265 
267  //
271  static bool advance_movie(Gui* gui) {
272  gui->advanceMovie();
273  return true;
274  }
275 
278  void refreshView();
279 
282  //
287  virtual void setFullscreen();
288 
291  virtual void unsetFullscreen();
292 
295  virtual void hideMenu();
296 
298  //
301  virtual bool showMouse(bool show);
302 
304  //
306  virtual void showMenu(bool show);
307 
309  //
311  virtual void allowScale(bool allow);
312 
313  // Toggle between fullscreen and normal mode
314  void toggleFullscreen();
315 
317  //
320  void stop();
321 
323  //
326  void play();
327 
329  //
332  void pause();
333 
335  //
339  void start();
340 
342  bool isStopped() const { return _stopped; }
343 
345  bool isPlugin() const { return ((_xid)); }
346 
348  void takeScreenShot();
349 
351  void setMaxAdvances(unsigned long ul) { if (ul) _maxAdvances = ul; }
352 
353  void showUpdatedRegions(bool x) { _showUpdatedRegions = x; }
354  bool showUpdatedRegions() const { return _showUpdatedRegions; }
355 
359  void restart();
360 
362  void setQuality(Quality q);
363 
365  Quality getQuality() const;
366 
369  void toggleSound();
370 
371 #ifdef GNASH_FPS_DEBUG
372  //
376  void setFpsTimerInterval(float interval)
377  {
378  assert(interval >= 0.0);
379  fps_timer_interval = interval;
380  }
381 #endif // def GNASH_FPS_DEBUG
382 
383 
384 #ifdef USE_SWFTREE
385  std::auto_ptr<movie_root::InfoTree> getMovieInfo() const;
387 #endif
388 
389  typedef std::map<std::string, std::string> VariableMap;
390 
392  void addFlashVars(VariableMap& vars);
393 
396 
398  void setStage(movie_root* stage);
399 
401  void setAudioDump(const std::string& fname) {
402  _audioDump = fname;
403  }
404 
406  movie_root* getStage() { return _stage; };
407 
409  //
412  virtual void error(const std::string& /*msg*/) {}
413 
415  //
424  virtual bool yesno(const std::string& question);
425 
427  float getXScale() const { return _xscale; };
428 
430  float getYScale() const { return _yscale; };
431 
433  float getFPS() const { return (_movieDef) ? _movieDef->get_frame_rate() : 0;
434  };
435 
436 protected:
437 
439  Gui(RunResources& r);
440 
455  Gui(unsigned long xid, float scale, bool loop, RunResources& r);
456 
458  //
460  //
463  virtual void quitUI() {
464  std::exit(EXIT_SUCCESS);
465  }
466 
468  //
474  virtual bool watchFD(int /* fd */)
475  {
476  log_unimpl("This GUI does not implement FD watching.");
477  return false;
478  }
479 
480 
482  bool _loop;
483 
485  unsigned long _xid;
486 
487  // This would be 0,0,_width,_height, so maybe
488  // we should not duplicate the info with those
489  // explicit values too..
491 
493  int _width;
494 
496  int _height;
497 
500 
502  unsigned int _interval;
503 
505  boost::shared_ptr<Renderer> _renderer;
506 
510 
511  // True if Gnash is running in fullscreen
513 
514  // True if mouse pointer is showing
516 
517  // Maximum number of advances before exit; 0 for no limit.
518  unsigned long _maxAdvances;
519 
521  unsigned long _advances;
522 
524  std::string _audioDump;
525 
528  virtual void stopHook() {}
529 
531  virtual void playHook() {}
532 
534  virtual bool visible() { return true; }
535 private:
536 
537  struct Display;
538 
539  std::map<int /* fd */, boost::function<void ()> > _fd_callbacks;
540 
542  float _xscale;
543 
545  float _yscale;
546 
548  boost::int32_t _xoffset;
549 
551  boost::int32_t _yoffset;
552 
553  bool display(movie_root* m);
554 
555 #ifdef GNASH_FPS_DEBUG
556  unsigned int fps_counter;
557 
558  float fps_rate_min, fps_rate_max;
559 
560  // Number of calls to fpsCounterTick, which is also
561  // the number of calls to movie_advance()
562  unsigned int fps_counter_total;
563 
564  boost::uint64_t fps_timer, fps_start_timer;
565 
567  //
570  float fps_timer_interval;
571 
573  unsigned int frames_dropped;
574 
578  //
581  void fpsCounterTick();
582 
583 #endif // def GNASH_FPS_DEBUG
584 
585  VariableMap _flashVars;
586 
587  boost::intrusive_ptr<movie_definition> _movieDef;
588 
590  movie_root* _stage;
591 
593  bool _stopped;
594 
596  bool _started;
597 
599  bool _showUpdatedRegions;
600 
601  SystemClock _systemClock;
602  InterruptableVirtualClock _virtualClock;
603 
605  boost::scoped_ptr<ScreenShotter> _screenShotter;
606 
607 #ifdef ENABLE_KEYBOARD_MOUSE_MOVEMENTS
608  int _xpointer;
609  int _ypointer;
610  bool _keyboardMouseMovements;
611  int _keyboardMouseMovementsStep;
612 #endif // ENABLE_KEYBOARD_MOUSE_MOVEMENTS
613 };
614 
616 namespace gui {
617  std::auto_ptr<Gui> createFBGui(unsigned long xid, float scale, bool loop, RunResources& r);
618 }
619 std::auto_ptr<Gui> createGTKGui(unsigned long xid, float scale, bool loop, RunResources& r);
620 std::auto_ptr<Gui> createKDEGui(unsigned long xid, float scale, bool loop, RunResources& r);
621 std::auto_ptr<Gui> createQt4Gui(unsigned long xid, float scale, bool loop, RunResources& r);
622 std::auto_ptr<Gui> createSDLGui(unsigned long xid, float scale, bool loop, RunResources& r);
623 std::auto_ptr<Gui> createFLTKGui(unsigned long xid, float scale, bool loop, RunResources& r);
624 std::auto_ptr<Gui> createAQUAGui(unsigned long xid, float scale, bool loop, RunResources& r);
625 std::auto_ptr<Gui> createRISCOSGui(unsigned long xid, float scale, bool loop, RunResources& r);
626 std::auto_ptr<Gui> createAOS4Gui(unsigned long xid, float scale, bool loop, RunResources& r);
627 std::auto_ptr<Gui> createHaikuGui(unsigned long xid, float scale, bool loop, RunResources& r);
628 std::auto_ptr<Gui> createDumpGui(unsigned long xid, float scale, bool loop, RunResources& r);
629 
630 
631 } // end of gnash namespace
632 
633 // end of _GUI_H_
634 #endif
635 
636 // Local Variables:
637 // mode: C++
638 // indent-tabs-mode: nil
639 // End:
float getXScale() const
Width of a window pixel, in stage pseudopixel units.
Definition: gui.h:427
virtual double getPixelAspectRatio() const
Definition: gui.h:186
void stop()
Put the application in &quot;stop&quot; mode.
Definition: gui.cpp:853
std::string _audioDump
Name of a file to dump audio to.
Definition: gui.h:524
std::auto_ptr< Gui > createGTKGui(unsigned long, float, bool, RunResourcesfloat, bool, unsigned int)
Definition: gui_gtk.cpp:41
unsigned int _interval
Main loop interval: the time between successive advance_movie calls.
Definition: gui.h:502
bool showUpdatedRegions() const
Definition: gui.h:354
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
std::auto_ptr< Gui > createRISCOSGui(unsigned long xid, float scale, bool loop, RunResources &r)
std::auto_ptr< Gui > createKDEGui(unsigned long xid, float scale, bool loop, RunResources &r)
bool loops() const
Definition: gui.h:204
A system-clock based virtual clock.
Definition: SystemClock.h:36
bool isFullscreen() const
Definition: gui.h:207
void notify_key_event(gnash::key::code k, int modifier, bool pressed)
Key event notification to be called when a key is pressed or depressed.
Definition: gui.cpp:561
std::auto_ptr< Gui > createDumpGui(unsigned long, float, bool, RunResourcesfloat, bool, unsigned int)
Definition: gui_dump.cpp:40
virtual bool run()=0
Start main rendering loop.
virtual bool createWindow(const char *title, int width, int height, int xPosition=0, int yPosition=0)=0
Create and display our window.
virtual bool watchFD(int)
Watch a file descriptor.
Definition: gui.h:474
std::map< std::string, std::string > VariableMap
Definition: gui.h:389
int _height
Desired window height.
Definition: gui.h:496
virtual bool yesno(const std::string &question)
Prompt user with a question she can answer with yes/no.
Definition: gui.cpp:1264
virtual bool showMouse(bool show)
Sets whether the gui should show the system mouse pointer.
Definition: gui.cpp:234
void setScreenShotter(std::auto_ptr< ScreenShotter > ss)
Definition: gui.cpp:1004
virtual bool visible()
Determines whether the Gui is visible (not obscured).
Definition: gui.h:534
Definition: GnashKey.h:163
Definition: gui.h:82
std::auto_ptr< Gui > createHaikuGui(unsigned long xid, float scale, bool loop, RunResources &r)
void toggleFullscreen()
Definition: gui.cpp:259
void notifyMouseWheel(int delta)
Send a mouse wheel event to the stage.
Definition: gui.cpp:516
void showUpdatedRegions(bool x)
Definition: gui.h:353
Definition: GnashKey.h:157
virtual std::string getScreenColor() const
Get the screen color type.
Definition: gui.h:199
bool _loop
Determines if playback should restart after the movie ends.
Definition: gui.h:482
void pause()
Toggle between &quot;stop&quot; and &quot;play&quot; mode.
Definition: gui.cpp:875
bool isPlugin() const
Whether gnash is is running as a plugin.
Definition: gui.h:345
void toggleSound()
Definition: gui.cpp:454
std::auto_ptr< Gui > createAQUAGui(unsigned long, float, bool, RunResourcesfloat, bool, unsigned int)
Definition: gui_aqua.cpp:40
void resize_view(int width, int height)
Resize the client area view and the window accordingly.
Definition: gui.cpp:430
virtual ~Gui()
Definition: gui.cpp:177
void refreshView()
Definition: gui.cpp:548
gnash_cursor_type
Enumerates mouse cursor types.
Definition: gui.h:80
Definition: gui.h:74
Quality
Definition: GnashEnums.h:34
virtual void unsetFullscreen()
Definition: gui.cpp:210
virtual void setInvalidatedRegion(const SWFRect &bounds)
Gives the GUI a hint which region of the stage should be redrawn.
Definition: gui.cpp:1039
void setMaxAdvances(unsigned long ul)
Set the maximum number of frame advances before Gnash exits.
Definition: gui.h:351
virtual VirtualClock & getClock()
Return the clock provided by this Gui.
Definition: gui.h:111
Definition: klash_part.cpp:329
Definition: gui.h:83
virtual void setClipboard(const std::string &copy)
Definition: gui.cpp:192
bool _redraw_flag
Definition: gui.h:509
virtual void playHook()
Called by Gui::play().
Definition: gui.h:531
void restart()
Definition: gui.cpp:270
code
Definition: GnashKey.h:43
Parent class from which all GUI implementations will depend.
Definition: gui.h:87
Definition: GnashKey.h:164
std::auto_ptr< Gui > createQt4Gui(unsigned long xid, float scale, bool loop, RunResources &r)
movie_root * getStage()
The root movie, or &quot;Stage&quot;.
Definition: gui.h:406
RunResources & _runResources
Per-run resources.
Definition: gui.h:499
virtual void setCursor(gnash_cursor_type newcursor)
Sets the current mouse cursor for the Gui window.
Definition: gui.cpp:1027
void setMovieDefinition(movie_definition *md)
Set the definition of top-level movie.
Definition: gui.cpp:1249
bool _fullscreen
Definition: gui.h:512
boost::shared_ptr< Renderer > _renderer
The handler which is called to update the client area of our window.
Definition: gui.h:505
bool isStopped() const
See stop(), play() and pause()
Definition: gui.h:342
Definition: klash_part.cpp:329
bool _mouseShown
Definition: gui.h:515
virtual bool want_redraw()
Asks the GUI handler if the next frame should be redrawn completely.
Definition: gui.cpp:1033
float getFPS() const
Height of a window pixel, in stage pseudopixel units.
Definition: gui.h:433
std::auto_ptr< Gui > createAOS4Gui(unsigned long, float, bool, RunResourcesfloat, bool, unsigned int)
Definition: gui_aos4.cpp:40
Class to group together per-run and external resources for Gnash.
Definition: RunResources.h:43
unsigned long _advances
Counter to keep track of frame advances.
Definition: gui.h:521
virtual void setFullscreen()
Definition: gui.cpp:198
virtual void allowScale(bool allow)
Sets whether scaling should be allowed (for fscommand)
Definition: gui.cpp:247
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:275
virtual void error(const std::string &)
Handle error message from the core.
Definition: gui.h:412
void setAudioDump(const std::string &fname)
Set the name of a file to dump audio to.
Definition: gui.h:401
boost::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:271
void takeScreenShot()
Take a screenshot now!
Definition: gui.cpp:1010
void notifyMouseClick(bool mouse_pressed)
Mouse notification callback to be called when the mouse is clicked.
Definition: gui.cpp:532
virtual void resizeWindow(int width, int height)
Definition: gui.cpp:204
virtual void renderBuffer()=0
std::auto_ptr< Gui > createFBGui(unsigned long windowid, float scale, bool do_loop, RunResources &r)
Definition: fb.cpp:141
Definition: gui.h:81
virtual void showMenu(bool show)
Sets whether the menus should be shown (for fscommand)
Definition: gui.cpp:241
Gui(RunResources &r)
Default constructor. Initialises members to safe defaults.
Definition: gui.cpp:91
void updateStageMatrix()
Definition: gui.cpp:278
void play()
Put the application in &quot;play&quot; mode.
Definition: gui.cpp:830
virtual void beforeRendering()
Definition: gui.h:166
virtual void hideMenu()
Definition: gui.cpp:228
virtual bool init(int argc, char **argv[])=0
/ Initialise the gui and the associated renderer.
float getYScale() const
Height of a window pixel, in stage pseudopixel units.
Definition: gui.h:430
void setQuality(Quality q)
Set rendering quality, if not locked by RC file..
Definition: gui.cpp:1272
unsigned long _maxAdvances
Definition: gui.h:518
boost::int32_t y
Definition: BitmapData_as.cpp:435
virtual void stopHook()
Definition: gui.h:528
virtual std::pair< int, int > screenResolution() const
Definition: gui.h:188
Rectangle class, see swf defined rectangle record.
Definition: SWFRect.h:44
int _width
Desired window width.
Definition: gui.h:493
virtual void setTimeout(unsigned int timeout)=0
Set the time in milliseconds after which the programme should exit.
virtual void setInvalidatedRegions(const InvalidatedRanges &ranges)
Definition: gui.cpp:1045
virtual double getScreenDPI() const
Definition: gui.h:192
unsigned long _xid
The X Window ID to attach to. If zero, we create a new window.
Definition: gui.h:485
void start()
Start the movie.
Definition: gui.cpp:899
void notifyMouseMove(int x, int y)
Mouse notification callback to be called when the mouse is moved.
Definition: gui.cpp:470
std::auto_ptr< Gui > createSDLGui(unsigned long xid, float scale, bool loop, RunResources &r)
virtual bool want_multiple_regions()
Definition: gui.h:170
Quality getQuality() const
Get current rendering quality.
Definition: gui.cpp:1282
void addFlashVars(VariableMap &vars)
Add variables to set into instances of the top-level movie definition.
Definition: gui.cpp:1241
std::auto_ptr< Gui > createFLTKGui(unsigned long, float, bool, RunResourcesfloat, bool, unsigned int)
Definition: gui_fltk.cpp:40
Definition: GnashKey.h:159
void quit()
Always called on exit.
Definition: gui.cpp:216
geometry::Range2d< int > _validbounds
Definition: gui.h:490
void setStage(movie_root *stage)
Set the stage to advance/display.
Definition: gui.cpp:1256
virtual void quitUI()
End main rendering loop calling GUI-specific exit functions.
Definition: gui.h:463
virtual void setInterval(unsigned int interval)
Set main loop delay in milliseconds.
Definition: gui.h:102
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