Gnash  0.8.10
gui.h
Go to the documentation of this file.
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 
00098     virtual bool init(int argc, char **argv[]) = 0;
00099 
00101     virtual void setInterval(unsigned int interval) {
00102       _interval = interval;
00103     }
00104 
00106     //
00110     virtual VirtualClock& getClock() { return _virtualClock; }
00111 
00113     virtual void setTimeout(unsigned int timeout) = 0;
00114 
00115     void setScreenShotter(std::auto_ptr<ScreenShotter> ss);
00116 
00125     virtual bool createWindow(const char* title, int width, int height,
00126                        int xPosition = 0, int yPosition = 0) = 0;
00127 
00128     virtual void resizeWindow(int width, int height);
00129 
00131     virtual bool run() = 0;
00132 
00134     //
00136     void quit();
00137 
00140     virtual void renderBuffer() = 0;
00141 
00143     //
00157     // does not need to be implemented (optional feature),
00158     // but still needs to be available.
00159     //
00160     virtual void setInvalidatedRegion(const SWFRect& bounds);
00161     virtual void setInvalidatedRegions(const InvalidatedRanges& ranges);
00162     
00163     // Called right before rendering anything (after setInvalidatedRegion).
00164     // Used by GTK-AGG.
00165     virtual void beforeRendering() { /* nop */ };
00166     
00167     // Should return TRUE when the GUI/Renderer combination supports multiple
00168     // invalidated bounds regions. 
00169     virtual bool want_multiple_regions() { return false; }
00170 
00172     //
00176     virtual bool want_redraw();
00177 
00179     virtual void setCursor(gnash_cursor_type newcursor);
00180 
00181     virtual void setClipboard(const std::string& copy);
00182 
00183     // Information for System.capabilities to be reimplemented in
00184     // each gui.
00185     virtual double getPixelAspectRatio() const { return 0; }
00186 
00187     virtual std::pair<int, int> screenResolution() const {
00188         return std::make_pair(0, 0);
00189     }
00190 
00191     virtual double getScreenDPI() const { return 0; }
00192 
00194     //
00198     virtual std::string getScreenColor() const {
00199         return "color";
00200     }
00201 
00203     bool loops() const { return _loop; }
00204 
00206     bool isFullscreen() const { return _fullscreen; }
00207 
00209     //
00214     void notifyMouseMove(int x, int y);
00215 
00217     //
00220     void notifyMouseClick(bool mouse_pressed);
00221 
00223     //
00225     void notifyMouseWheel(int delta);
00226 
00228     //
00236     void notify_key_event(gnash::key::code k, int modifier, bool pressed);
00237 
00239     //
00242     void resize_view(int width, int height);
00243 
00246     //
00250     void updateStageMatrix();
00251 
00254     //
00263     bool advanceMovie(bool doDisplay = true);
00264 
00266     //
00270     static bool advance_movie(Gui* gui) {
00271         gui->advanceMovie();
00272         return true;
00273     }
00274 
00277     void refreshView();
00278 
00281     //
00286     virtual void setFullscreen();
00287 
00290     virtual void unsetFullscreen();
00291 
00294     virtual void hideMenu();
00295     
00297     //
00300     virtual bool showMouse(bool show);
00301 
00303     //
00305     virtual void showMenu(bool show);
00306 
00308     //
00310     virtual void allowScale(bool allow);
00311     
00312     // Toggle between fullscreen and normal mode
00313     void toggleFullscreen();
00314 
00316     //
00319     void stop();
00320 
00322     //
00325     void play();
00326 
00328     //
00331     void pause();
00332 
00334     //
00338     void start();
00339 
00341     bool isStopped() const { return _stopped; }
00342     
00344     bool isPlugin() const { return ((_xid)); }
00345 
00347     void takeScreenShot();
00348 
00350     void setMaxAdvances(unsigned long ul) { if (ul) _maxAdvances = ul; }
00351     
00352     void showUpdatedRegions(bool x) { _showUpdatedRegions = x; }
00353     bool showUpdatedRegions() const { return _showUpdatedRegions; }
00354 
00358     void restart();
00359 
00361     void setQuality(Quality q);
00362 
00364     Quality getQuality() const;
00365 
00368     void toggleSound();
00369 
00370 #ifdef GNASH_FPS_DEBUG
00371 
00372     //
00375     void setFpsTimerInterval(float interval)
00376     {
00377             assert(interval >= 0.0);
00378             fps_timer_interval = interval;
00379     }
00380 #endif // def GNASH_FPS_DEBUG
00381 
00382 
00383 #ifdef USE_SWFTREE
00384 
00385     std::auto_ptr<movie_root::InfoTree> getMovieInfo() const;
00386 #endif
00387 
00388     typedef std::map<std::string, std::string> VariableMap;
00389 
00391     void addFlashVars(VariableMap& vars);
00392 
00394     void setMovieDefinition(movie_definition* md);
00395 
00397     void setStage(movie_root* stage);
00398 
00400     void setAudioDump(const std::string& fname) {
00401         _audioDump = fname;
00402     }
00403 
00405     movie_root* getStage() { return _stage; };
00406     
00408     //
00411     virtual void error(const std::string& /*msg*/) {}
00412 
00414     //
00423     virtual bool yesno(const std::string& question);
00424 
00426     float getXScale() const { return _xscale; };
00427 
00429     float getYScale() const { return _yscale; };
00430 
00432     float getFPS() const { return (_movieDef) ? _movieDef->get_frame_rate() : 0;
00433     };
00434 
00435 protected:
00436 
00438     Gui(RunResources& r);
00439 
00454     Gui(unsigned long xid, float scale, bool loop, RunResources& r);
00455     
00457     //
00459     //
00462     virtual void quitUI() {
00463         std::exit(EXIT_SUCCESS);
00464     }
00465 
00467     //
00473     virtual bool watchFD(int /* fd */)
00474     {
00475         log_unimpl("This GUI does not implement FD watching.");
00476         return false;
00477     }
00478 
00479 
00481     bool _loop;
00482 
00484     unsigned long _xid;
00485 
00486     // This would be 0,0,_width,_height, so maybe
00487     // we should not duplicate the info with those
00488     // explicit values too..
00489     geometry::Range2d<int> _validbounds;
00490 
00492     int _width;
00493 
00495     int _height;
00496 
00498     RunResources& _runResources;
00499 
00501     unsigned int _interval;
00502 
00504     boost::shared_ptr<Renderer> _renderer;
00505 
00508     bool _redraw_flag;
00509 
00510     // True if Gnash is running in fullscreen
00511     bool _fullscreen;
00512 
00513     // True if mouse pointer is showing
00514     bool _mouseShown;
00515 
00516     // Maximum number of advances before exit; 0 for no limit.
00517     unsigned long _maxAdvances;
00518     
00520     unsigned long _advances;
00521 
00523     std::string _audioDump;
00524 
00527     virtual void stopHook() {}
00528 
00530     virtual void playHook() {}
00531 
00533     virtual bool visible() { return true; }
00534 private:
00535 
00536     struct Display;
00537 
00538     std::map<int /* fd */, boost::function<void ()> > _fd_callbacks;
00539 
00541     float _xscale;
00542 
00544     float _yscale;
00545 
00547     boost::int32_t _xoffset;
00548 
00550     boost::int32_t _yoffset;
00551 
00552     bool display(movie_root* m);
00553     
00554 #ifdef GNASH_FPS_DEBUG
00555     unsigned int fps_counter;
00556 
00557     float fps_rate_min, fps_rate_max;   
00558 
00559     // Number of calls to fpsCounterTick, which is also
00560     // the number of calls to movie_advance()
00561     unsigned int fps_counter_total;
00562 
00563     boost::uint64_t fps_timer, fps_start_timer;     
00564 
00566     //
00569     float fps_timer_interval;
00570     
00572     unsigned int frames_dropped;
00573 
00577     //
00580     void fpsCounterTick();
00581 
00582 #endif // def GNASH_FPS_DEBUG
00583 
00584     VariableMap _flashVars;
00585 
00586     boost::intrusive_ptr<movie_definition> _movieDef;
00587     
00589     movie_root* _stage;
00590 
00592     bool _stopped;
00593 
00595     bool _started;
00596 
00598     bool _showUpdatedRegions;
00599 
00600     SystemClock _systemClock;
00601     InterruptableVirtualClock _virtualClock;
00602     
00604     boost::scoped_ptr<ScreenShotter> _screenShotter;
00605 
00606 #ifdef ENABLE_KEYBOARD_MOUSE_MOVEMENTS 
00607     int _xpointer;
00608     int _ypointer;
00609     bool _keyboardMouseMovements;
00610     int _keyboardMouseMovementsStep;
00611 #endif // ENABLE_KEYBOARD_MOUSE_MOVEMENTS
00612 };
00613 
00615 namespace gui {
00616   std::auto_ptr<Gui> createFBGui(unsigned long xid, float scale, bool loop, RunResources& r);
00617 }
00618 std::auto_ptr<Gui> createGTKGui(unsigned long xid, float scale, bool loop, RunResources& r);
00619 std::auto_ptr<Gui> createKDEGui(unsigned long xid, float scale, bool loop, RunResources& r);
00620 std::auto_ptr<Gui> createQt4Gui(unsigned long xid, float scale, bool loop, RunResources& r);
00621 std::auto_ptr<Gui> createSDLGui(unsigned long xid, float scale, bool loop, RunResources& r);
00622 std::auto_ptr<Gui> createFLTKGui(unsigned long xid, float scale, bool loop, RunResources& r);
00623 std::auto_ptr<Gui> createAQUAGui(unsigned long xid, float scale, bool loop, RunResources& r);
00624 std::auto_ptr<Gui> createRISCOSGui(unsigned long xid, float scale, bool loop, RunResources& r);
00625 std::auto_ptr<Gui> createAOS4Gui(unsigned long xid, float scale, bool loop, RunResources& r);
00626 std::auto_ptr<Gui> createHaikuGui(unsigned long xid, float scale, bool loop, RunResources& r);
00627 std::auto_ptr<Gui> createDumpGui(unsigned long xid, float scale, bool loop, RunResources& r);
00628 
00629  
00630 } // end of gnash namespace
00631 
00632 // end of _GUI_H_
00633 #endif
00634 
00635 // Local Variables:
00636 // mode: C++
00637 // indent-tabs-mode: nil
00638 // End: