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 
373  //
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 
386  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: