Gnash 0.8.10dev
|
00001 // 00002 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 00003 // 2011 Free Software Foundation, Inc 00004 // 00005 // This program is free software; you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation; either version 3 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // This program is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with this program; if not, write to the Free Software 00017 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00018 00019 #ifndef GNASH_GUI_H 00020 #define GNASH_GUI_H 00021 00022 #ifdef HAVE_CONFIG_H 00023 #include "gnashconfig.h" 00024 #endif 00025 00026 #include <boost/intrusive_ptr.hpp> 00027 #include <boost/scoped_ptr.hpp> 00028 #include <boost/function.hpp> 00029 #include <string> 00030 #include <map> 00031 #include <utility> 00032 00033 #include "SWFRect.h" // for composition 00034 #include "snappingrange.h" // for InvalidatedRanges 00035 #include "ScreenShotter.h" 00036 #include "GnashKey.h" 00037 #include "Renderer.h" 00038 #include "VirtualClock.h" 00039 #include "SystemClock.h" 00040 #include "GnashEnums.h" 00041 #include "movie_root.h" 00042 00043 #ifdef USE_SWFTREE 00044 #include "tree.hh" // for tree 00045 #endif 00046 00047 // Define this to enable fps debugging without touching 00048 // gnashconfig.h 00049 //#define GNASH_FPS_DEBUG 00050 00061 //#define DISABLE_REGION_UPDATES_DEBUGGING 1 00062 00063 00065 #define ENABLE_KEYBOARD_MOUSE_MOVEMENTS 1 00066 00067 // Forward declarations 00068 namespace gnash { 00069 class SWFRect; 00070 class ScreenShotter; 00071 class RunResources; 00072 class movie_root; 00073 class movie_definition; 00074 } 00075 00076 namespace gnash { 00077 00079 enum gnash_cursor_type { 00080 CURSOR_HAND, 00081 CURSOR_NORMAL, 00082 CURSOR_INPUT 00083 }; 00084 00086 class Gui { 00087 00088 public: 00089 00090 virtual ~Gui(); 00091 00099 virtual bool init(int argc, char **argv[]) = 0; 00100 00102 virtual void setInterval(unsigned int interval) { 00103 _interval = interval; 00104 } 00105 00107 // 00111 virtual VirtualClock& getClock() { return _virtualClock; } 00112 00114 virtual void setTimeout(unsigned int timeout) = 0; 00115 00116 void setScreenShotter(std::auto_ptr<ScreenShotter> ss); 00117 00127 virtual bool createWindow(const char* title, int width, int height, 00128 int xPosition = 0, int yPosition = 0) = 0; 00129 00130 virtual void resizeWindow(int width, int height); 00131 00133 virtual bool run() = 0; 00134 00136 // 00138 void quit(); 00139 00142 virtual void renderBuffer() = 0; 00143 00145 // 00159 // does not need to be implemented (optional feature), 00160 // but still needs to be available. 00161 // 00162 virtual void setInvalidatedRegion(const SWFRect& bounds); 00163 virtual void setInvalidatedRegions(const InvalidatedRanges& ranges); 00164 00165 // Called right before rendering anything (after setInvalidatedRegion). 00166 // Used by GTK-AGG. 00167 virtual void beforeRendering() { /* nop */ }; 00168 00169 // Should return TRUE when the GUI/Renderer combination supports multiple 00170 // invalidated bounds regions. 00171 virtual bool want_multiple_regions() { return false; } 00172 00174 // 00178 virtual bool want_redraw(); 00179 00181 virtual void setCursor(gnash_cursor_type newcursor); 00182 00183 virtual void setClipboard(const std::string& copy); 00184 00185 // Information for System.capabilities to be reimplemented in 00186 // each gui. 00187 virtual double getPixelAspectRatio() const { return 0; } 00188 00189 virtual std::pair<int, int> screenResolution() const { 00190 return std::make_pair(0, 0); 00191 } 00192 00193 virtual double getScreenDPI() const { return 0; } 00194 00196 // 00200 virtual std::string getScreenColor() const { 00201 return "color"; 00202 } 00203 00205 bool loops() const { return _loop; } 00206 00208 bool isFullscreen() const { return _fullscreen; } 00209 00211 // 00216 void notifyMouseMove(int x, int y); 00217 00219 // 00222 void notifyMouseClick(bool mouse_pressed); 00223 00225 // 00227 void notifyMouseWheel(int delta); 00228 00230 // 00238 void notify_key_event(gnash::key::code k, int modifier, bool pressed); 00239 00241 // 00244 void resize_view(int width, int height); 00245 00248 // 00252 void updateStageMatrix(); 00253 00256 // 00265 bool advanceMovie(bool doDisplay = true); 00266 00268 // 00272 static bool advance_movie(Gui* gui) { 00273 gui->advanceMovie(); 00274 return true; 00275 } 00276 00279 void refreshView(); 00280 00283 // 00288 virtual void setFullscreen(); 00289 00292 virtual void unsetFullscreen(); 00293 00296 virtual void hideMenu(); 00297 00299 // 00302 virtual bool showMouse(bool show); 00303 00305 // 00307 virtual void showMenu(bool show); 00308 00310 // 00312 virtual void allowScale(bool allow); 00313 00314 // Toggle between fullscreen and normal mode 00315 void toggleFullscreen(); 00316 00318 // 00321 void stop(); 00322 00324 // 00327 void play(); 00328 00330 // 00333 void pause(); 00334 00336 // 00340 void start(); 00341 00343 bool isStopped() const { return _stopped; } 00344 00346 bool isPlugin() const { return ((_xid)); } 00347 00349 void takeScreenShot(); 00350 00352 void setMaxAdvances(unsigned long ul) { if (ul) _maxAdvances = ul; } 00353 00354 void showUpdatedRegions(bool x) { _showUpdatedRegions = x; } 00355 bool showUpdatedRegions() const { return _showUpdatedRegions; } 00356 00360 void restart(); 00361 00363 void setQuality(Quality q); 00364 00366 Quality getQuality() const; 00367 00370 void toggleSound(); 00371 00372 #ifdef GNASH_FPS_DEBUG 00373 00374 // 00377 void setFpsTimerInterval(float interval) 00378 { 00379 assert(interval >= 0.0); 00380 fps_timer_interval = interval; 00381 } 00382 #endif // def GNASH_FPS_DEBUG 00383 00384 00385 #ifdef USE_SWFTREE 00386 00387 std::auto_ptr<movie_root::InfoTree> getMovieInfo() const; 00388 #endif 00389 00390 typedef std::map<std::string, std::string> VariableMap; 00391 00393 void addFlashVars(VariableMap& vars); 00394 00396 void setMovieDefinition(movie_definition* md); 00397 00399 void setStage(movie_root* stage); 00400 00402 void setAudioDump(const std::string& fname) { 00403 _audioDump = fname; 00404 } 00405 00407 movie_root* getStage() { return _stage; }; 00408 00410 // 00413 virtual void error(const std::string& /*msg*/) {} 00414 00416 // 00425 virtual bool yesno(const std::string& question); 00426 00428 float getXScale() const { return _xscale; }; 00429 00431 float getYScale() const { return _yscale; }; 00432 00433 protected: 00434 00436 Gui(RunResources& r); 00437 00452 Gui(unsigned long xid, float scale, bool loop, RunResources& r); 00453 00455 // 00457 // 00460 virtual void quitUI() { 00461 std::exit(EXIT_SUCCESS); 00462 } 00463 00465 // 00471 virtual bool watchFD(int /* fd */) 00472 { 00473 log_unimpl("This GUI does not implement FD watching."); 00474 return false; 00475 } 00476 00477 00479 bool _loop; 00480 00482 unsigned long _xid; 00483 00484 // This would be 0,0,_width,_height, so maybe 00485 // we should not duplicate the info with those 00486 // explicit values too.. 00487 geometry::Range2d<int> _validbounds; 00488 00490 int _width; 00491 00493 int _height; 00494 00496 RunResources& _runResources; 00497 00499 unsigned int _interval; 00500 00502 boost::shared_ptr<Renderer> _renderer; 00503 00506 bool _redraw_flag; 00507 00508 // True if Gnash is running in fullscreen 00509 bool _fullscreen; 00510 00511 // True if mouse pointer is showing 00512 bool _mouseShown; 00513 00514 // Maximum number of advances before exit; 0 for no limit. 00515 unsigned long _maxAdvances; 00516 00518 unsigned long _advances; 00519 00521 std::string _audioDump; 00522 00525 virtual void stopHook() {} 00526 00528 virtual void playHook() {} 00529 00531 virtual bool visible() { return true; } 00532 private: 00533 00534 struct Display; 00535 00536 std::map<int /* fd */, boost::function<void ()> > _fd_callbacks; 00537 00539 float _xscale; 00540 00542 float _yscale; 00543 00545 boost::int32_t _xoffset; 00546 00548 boost::int32_t _yoffset; 00549 00550 bool display(movie_root* m); 00551 00552 #ifdef GNASH_FPS_DEBUG 00553 unsigned int fps_counter; 00554 00555 float fps_rate_min, fps_rate_max; 00556 00557 // Number of calls to fpsCounterTick, which is also 00558 // the number of calls to movie_advance() 00559 unsigned int fps_counter_total; 00560 00561 boost::uint64_t fps_timer, fps_start_timer; 00562 00564 // 00567 float fps_timer_interval; 00568 00570 unsigned int frames_dropped; 00571 00575 // 00578 void fpsCounterTick(); 00579 00580 #endif // def GNASH_FPS_DEBUG 00581 00582 VariableMap _flashVars; 00583 00584 boost::intrusive_ptr<movie_definition> _movieDef; 00585 00587 movie_root* _stage; 00588 00590 bool _stopped; 00591 00593 bool _started; 00594 00596 bool _showUpdatedRegions; 00597 00598 SystemClock _systemClock; 00599 InterruptableVirtualClock _virtualClock; 00600 00602 boost::scoped_ptr<ScreenShotter> _screenShotter; 00603 00604 #ifdef ENABLE_KEYBOARD_MOUSE_MOVEMENTS 00605 int _xpointer; 00606 int _ypointer; 00607 bool _keyboardMouseMovements; 00608 int _keyboardMouseMovementsStep; 00609 #endif // ENABLE_KEYBOARD_MOUSE_MOVEMENTS 00610 }; 00611 00613 std::auto_ptr<Gui> createGTKGui(unsigned long xid, float scale, bool loop, RunResources& r); 00614 std::auto_ptr<Gui> createKDEGui(unsigned long xid, float scale, bool loop, RunResources& r); 00615 std::auto_ptr<Gui> createQt4Gui(unsigned long xid, float scale, bool loop, RunResources& r); 00616 std::auto_ptr<Gui> createSDLGui(unsigned long xid, float scale, bool loop, RunResources& r); 00617 std::auto_ptr<Gui> createFLTKGui(unsigned long xid, float scale, bool loop, RunResources& r); 00618 std::auto_ptr<Gui> createFBGui(unsigned long xid, float scale, bool loop, RunResources& r); 00619 std::auto_ptr<Gui> createAQUAGui(unsigned long xid, float scale, bool loop, RunResources& r); 00620 std::auto_ptr<Gui> createRISCOSGui(unsigned long xid, float scale, bool loop, RunResources& r); 00621 std::auto_ptr<Gui> createAOS4Gui(unsigned long xid, float scale, bool loop, RunResources& r); 00622 std::auto_ptr<Gui> createHaikuGui(unsigned long xid, float scale, bool loop, RunResources& r); 00623 std::auto_ptr<Gui> createDumpGui(unsigned long xid, float scale, bool loop, RunResources& r); 00624 00625 00626 } // end of gnash namespace 00627 00628 // end of _GUI_H_ 00629 #endif 00630 00631 // Local Variables: 00632 // mode: C++ 00633 // indent-tabs-mode: nil 00634 // End: