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 <boost/function.hpp>
29 #include <string>
30 #include <map>
31 #include <utility>
32 
33 #include "SWFRect.h" // for composition
34 #include "snappingrange.h" // for InvalidatedRanges
35 #include "ScreenShotter.h"
36 #include "GnashKey.h"
37 #include "Renderer.h"
38 #include "VirtualClock.h"
39 #include "SystemClock.h"
40 #include "GnashEnums.h"
41 #include "movie_root.h"
42 
43 #ifdef USE_SWFTREE
44 #include "tree.hh" // for tree
45 #endif
46 
47 // Define this to enable fps debugging without touching
48 // gnashconfig.h
49 //#define GNASH_FPS_DEBUG
50 
61 //#define DISABLE_REGION_UPDATES_DEBUGGING 1
62 
63 
65 #define ENABLE_KEYBOARD_MOUSE_MOVEMENTS 1
66 
67 // Forward declarations
68 namespace gnash {
69  class SWFRect;
70  class ScreenShotter;
71  class RunResources;
72  class movie_root;
73  class movie_definition;
74 }
75 
76 namespace gnash {
77 
83 };
84 
86 class Gui {
87 
88 public:
89 
90  virtual ~Gui();
91 
98  virtual bool init(int argc, char **argv[]) = 0;
99 
101  virtual void setInterval(unsigned int interval) {
102  _interval = interval;
103  }
104 
106  //
110  virtual VirtualClock& getClock() { return _virtualClock; }
111 
113  virtual void setTimeout(unsigned int timeout) = 0;
114 
115  void setScreenShotter(std::auto_ptr<ScreenShotter> ss);
116 
125  virtual bool createWindow(const char* title, int width, int height,
126  int xPosition = 0, int yPosition = 0) = 0;
127 
128  virtual void resizeWindow(int width, int height);
129 
131  virtual bool run() = 0;
132 
134  //
136  void quit();
137 
140  virtual void renderBuffer() = 0;
141 
143  //
157  // does not need to be implemented (optional feature),
158  // but still needs to be available.
159  //
160  virtual void setInvalidatedRegion(const SWFRect& bounds);
161  virtual void setInvalidatedRegions(const InvalidatedRanges& ranges);
162 
163  // Called right before rendering anything (after setInvalidatedRegion).
164  // Used by GTK-AGG.
165  virtual void beforeRendering() { /* nop */ };
166 
167  // Should return TRUE when the GUI/Renderer combination supports multiple
168  // invalidated bounds regions.
169  virtual bool want_multiple_regions() { return false; }
170 
172  //
176  virtual bool want_redraw();
177 
179  virtual void setCursor(gnash_cursor_type newcursor);
180 
181  virtual void setClipboard(const std::string& copy);
182 
183  // Information for System.capabilities to be reimplemented in
184  // each gui.
185  virtual double getPixelAspectRatio() const { return 0; }
186 
187  virtual std::pair<int, int> screenResolution() const {
188  return std::make_pair(0, 0);
189  }
190 
191  virtual double getScreenDPI() const { return 0; }
192 
194  //
198  virtual std::string getScreenColor() const {
199  return "color";
200  }
201 
203  bool loops() const { return _loop; }
204 
206  bool isFullscreen() const { return _fullscreen; }
207 
209  //
214  void notifyMouseMove(int x, int y);
215 
217  //
220  void notifyMouseClick(bool mouse_pressed);
221 
223  //
225  void notifyMouseWheel(int delta);
226 
228  //
236  void notify_key_event(gnash::key::code k, int modifier, bool pressed);
237 
239  //
242  void resize_view(int width, int height);
243 
246  //
250  void updateStageMatrix();
251 
254  //
263  bool advanceMovie(bool doDisplay = true);
264 
266  //
270  static bool advance_movie(Gui* gui) {
271  gui->advanceMovie();
272  return true;
273  }
274 
277  void refreshView();
278 
281  //
286  virtual void setFullscreen();
287 
290  virtual void unsetFullscreen();
291 
294  virtual void hideMenu();
295 
297  //
300  virtual bool showMouse(bool show);
301 
303  //
305  virtual void showMenu(bool show);
306 
308  //
310  virtual void allowScale(bool allow);
311 
312  // Toggle between fullscreen and normal mode
313  void toggleFullscreen();
314 
316  //
319  void stop();
320 
322  //
325  void play();
326 
328  //
331  void pause();
332 
334  //
338  void start();
339 
341  bool isStopped() const { return _stopped; }
342 
344  bool isPlugin() const { return ((_xid)); }
345 
347  void takeScreenShot();
348 
350  void setMaxAdvances(unsigned long ul) { if (ul) _maxAdvances = ul; }
351 
352  void showUpdatedRegions(bool x) { _showUpdatedRegions = x; }
353  bool showUpdatedRegions() const { return _showUpdatedRegions; }
354 
358  void restart();
359 
361  void setQuality(Quality q);
362 
364  Quality getQuality() const;
365 
368  void toggleSound();
369 
370 #ifdef GNASH_FPS_DEBUG
371  //
375  void setFpsTimerInterval(float interval)
376  {
377  assert(interval >= 0.0);
378  fps_timer_interval = interval;
379  }
380 #endif // def GNASH_FPS_DEBUG
381 
382 
383 #ifdef USE_SWFTREE
384  std::auto_ptr<movie_root::InfoTree> getMovieInfo() const;
386 #endif
387 
388  typedef std::map<std::string, std::string> VariableMap;
389 
391  void addFlashVars(VariableMap& vars);
392 
395 
397  void setStage(movie_root* stage);
398 
400  void setAudioDump(const std::string& fname) {
401  _audioDump = fname;
402  }
403 
405  movie_root* getStage() { return _stage; };
406 
408  //
411  virtual void error(const std::string& /*msg*/) {}
412 
414  //
423  virtual bool yesno(const std::string& question);
424 
426  float getXScale() const { return _xscale; };
427 
429  float getYScale() const { return _yscale; };
430 
432  float getFPS() const { return (_movieDef) ? _movieDef->get_frame_rate() : 0;
433  };
434 
435 protected:
436 
438  Gui(RunResources& r);
439 
454  Gui(unsigned long xid, float scale, bool loop, RunResources& r);
455 
457  //
459  //
462  virtual void quitUI() {
463  std::exit(EXIT_SUCCESS);
464  }
465 
467  //
473  virtual bool watchFD(int /* fd */)
474  {
475  log_unimpl("This GUI does not implement FD watching.");
476  return false;
477  }
478 
479 
481  bool _loop;
482 
484  unsigned long _xid;
485 
486  // This would be 0,0,_width,_height, so maybe
487  // we should not duplicate the info with those
488  // explicit values too..
490 
492  int _width;
493 
495  int _height;
496 
499 
501  unsigned int _interval;
502 
504  boost::shared_ptr<Renderer> _renderer;
505 
509 
510  // True if Gnash is running in fullscreen
512 
513  // True if mouse pointer is showing
515 
516  // Maximum number of advances before exit; 0 for no limit.
517  unsigned long _maxAdvances;
518 
520  unsigned long _advances;
521 
523  std::string _audioDump;
524 
527  virtual void stopHook() {}
528 
530  virtual void playHook() {}
531 
533  virtual bool visible() { return true; }
534 private:
535 
536  struct Display;
537 
538  std::map<int /* fd */, boost::function<void ()> > _fd_callbacks;
539 
541  float _xscale;
542 
544  float _yscale;
545 
547  boost::int32_t _xoffset;
548 
550  boost::int32_t _yoffset;
551 
552  bool display(movie_root* m);
553 
554 #ifdef GNASH_FPS_DEBUG
555  unsigned int fps_counter;
556 
557  float fps_rate_min, fps_rate_max;
558 
559  // Number of calls to fpsCounterTick, which is also
560  // the number of calls to movie_advance()
561  unsigned int fps_counter_total;
562 
563  boost::uint64_t fps_timer, fps_start_timer;
564 
566  //
569  float fps_timer_interval;
570 
572  unsigned int frames_dropped;
573 
577  //
580  void fpsCounterTick();
581 
582 #endif // def GNASH_FPS_DEBUG
583 
584  VariableMap _flashVars;
585 
586  boost::intrusive_ptr<movie_definition> _movieDef;
587 
589  movie_root* _stage;
590 
592  bool _stopped;
593 
595  bool _started;
596 
598  bool _showUpdatedRegions;
599 
600  SystemClock _systemClock;
601  InterruptableVirtualClock _virtualClock;
602 
604  boost::scoped_ptr<ScreenShotter> _screenShotter;
605 
606 #ifdef ENABLE_KEYBOARD_MOUSE_MOVEMENTS
607  int _xpointer;
608  int _ypointer;
609  bool _keyboardMouseMovements;
610  int _keyboardMouseMovementsStep;
611 #endif // ENABLE_KEYBOARD_MOUSE_MOVEMENTS
612 };
613 
615 namespace gui {
616  std::auto_ptr<Gui> createFBGui(unsigned long xid, float scale, bool loop, RunResources& r);
617 }
618 std::auto_ptr<Gui> createGTKGui(unsigned long xid, float scale, bool loop, RunResources& r);
619 std::auto_ptr<Gui> createKDEGui(unsigned long xid, float scale, bool loop, RunResources& r);
620 std::auto_ptr<Gui> createQt4Gui(unsigned long xid, float scale, bool loop, RunResources& r);
621 std::auto_ptr<Gui> createSDLGui(unsigned long xid, float scale, bool loop, RunResources& r);
622 std::auto_ptr<Gui> createFLTKGui(unsigned long xid, float scale, bool loop, RunResources& r);
623 std::auto_ptr<Gui> createAQUAGui(unsigned long xid, float scale, bool loop, RunResources& r);
624 std::auto_ptr<Gui> createRISCOSGui(unsigned long xid, float scale, bool loop, RunResources& r);
625 std::auto_ptr<Gui> createAOS4Gui(unsigned long xid, float scale, bool loop, RunResources& r);
626 std::auto_ptr<Gui> createHaikuGui(unsigned long xid, float scale, bool loop, RunResources& r);
627 std::auto_ptr<Gui> createDumpGui(unsigned long xid, float scale, bool loop, RunResources& r);
628 
629 
630 } // end of gnash namespace
631 
632 // end of _GUI_H_
633 #endif
634 
635 // Local Variables:
636 // mode: C++
637 // indent-tabs-mode: nil
638 // End: