Gnash 0.8.9

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 
00099     virtual bool init(int argc, char **argv[]) = 0;
00100 
00102     virtual void setInterval(unsigned int interval) {
00103       _interval = interval;
00104     }
00105 
00107     //
00110     void setFDCallback(int fd, boost::function<void ()> callback);
00111 
00113     //
00116     void callCallback(int fd);
00117 
00119     //
00123     virtual VirtualClock& getClock() { return _virtualClock; }
00124 
00126     virtual void setTimeout(unsigned int timeout) = 0;
00127 
00128     void setScreenShotter(std::auto_ptr<ScreenShotter> ss);
00129 
00139     virtual bool createWindow(const char* title, int width, int height,
00140                        int xPosition = 0, int yPosition = 0) = 0;
00141 
00142     virtual void resizeWindow(int width, int height);
00143 
00145     virtual bool run() = 0;
00146 
00148     //
00150     void quit();
00151 
00154     virtual void renderBuffer() = 0;
00155 
00157     //
00171     // does not need to be implemented (optional feature),
00172     // but still needs to be available.
00173     //
00174     virtual void setInvalidatedRegion(const SWFRect& bounds);
00175     virtual void setInvalidatedRegions(const InvalidatedRanges& ranges);
00176     
00177     // Called right before rendering anything (after setInvalidatedRegion).
00178     // Used by GTK-AGG.
00179     virtual void beforeRendering() { /* nop */ };
00180     
00181     // Should return TRUE when the GUI/Renderer combination supports multiple
00182     // invalidated bounds regions. 
00183     virtual bool want_multiple_regions() { return false; }
00184 
00186     //
00190     virtual bool want_redraw();
00191 
00193     virtual void setCursor(gnash_cursor_type newcursor);
00194 
00195     virtual void setClipboard(const std::string& copy);
00196 
00197     // Information for System.capabilities to be reimplemented in
00198     // each gui.
00199     virtual double getPixelAspectRatio() const { return 0; }
00200 
00201     virtual std::pair<int, int> screenResolution() const {
00202         return std::make_pair(0, 0);
00203     }
00204 
00205     virtual double getScreenDPI() const { return 0; }
00206 
00208     //
00212     virtual std::string getScreenColor() const {
00213         return "color";
00214     }
00215 
00217     bool loops() const { return _loop; }
00218 
00220     bool isFullscreen() const { return _fullscreen; }
00221 
00223     //
00228     void notifyMouseMove(int x, int y);
00229 
00231     //
00234     void notifyMouseClick(bool mouse_pressed);
00235 
00237     //
00239     void notifyMouseWheel(int delta);
00240 
00242     //
00250     void notify_key_event(gnash::key::code k, int modifier, bool pressed);
00251 
00253     //
00256     void resize_view(int width, int height);
00257 
00260     //
00264     void updateStageMatrix();
00265 
00268     //
00277     bool advanceMovie(bool doDisplay = true);
00278 
00280     //
00284     static bool advance_movie(Gui* gui) {
00285         gui->advanceMovie();
00286         return true;
00287     }
00288 
00291     void refreshView();
00292 
00295     //
00300     virtual void setFullscreen();
00301 
00304     virtual void unsetFullscreen();
00305 
00308     virtual void hideMenu();
00309     
00311     //
00314     virtual bool showMouse(bool show);
00315 
00317     //
00319     virtual void showMenu(bool show);
00320 
00322     //
00324     virtual void allowScale(bool allow);
00325     
00326     // Toggle between fullscreen and normal mode
00327     void toggleFullscreen();
00328 
00330     //
00333     void stop();
00334 
00336     //
00339     void play();
00340 
00342     //
00345     void pause();
00346 
00348     //
00352     void start();
00353 
00355     bool isStopped() const { return _stopped; }
00356     
00358     bool isPlugin() const { return ((_xid)); }
00359 
00361     void takeScreenShot();
00362 
00364     void setMaxAdvances(unsigned long ul) { if (ul) _maxAdvances = ul; }
00365     
00366     void showUpdatedRegions(bool x) { _showUpdatedRegions = x; }
00367     bool showUpdatedRegions() const { return _showUpdatedRegions; }
00368 
00372     void restart();
00373 
00375     void setQuality(Quality q);
00376 
00378     Quality getQuality() const;
00379 
00382     void toggleSound();
00383 
00384 #ifdef GNASH_FPS_DEBUG
00385 
00386     //
00389     void setFpsTimerInterval(float interval)
00390     {
00391             assert(interval >= 0.0);
00392             fps_timer_interval = interval;
00393     }
00394 #endif // def GNASH_FPS_DEBUG
00395 
00396 
00397 #ifdef USE_SWFTREE
00398 
00399     std::auto_ptr<movie_root::InfoTree> getMovieInfo() const;
00400 #endif
00401 
00402     typedef std::map<std::string, std::string> VariableMap;
00403 
00405     void addFlashVars(VariableMap& vars);
00406 
00408     void setMovieDefinition(movie_definition* md);
00409 
00411     void setStage(movie_root* stage);
00412 
00414     void setAudioDump(const std::string& fname) {
00415         _audioDump = fname;
00416     }
00417 
00419     movie_root* getStage() { return _stage; };
00420     
00422     //
00425     virtual void error(const std::string& /*msg*/) {}
00426 
00428     //
00437     virtual bool yesno(const std::string& question);
00438 
00440     float getXScale() const { return _xscale; };
00441 
00443     float getYScale() const { return _yscale; };
00444 
00445 protected:
00446 
00448     Gui(RunResources& r);
00449 
00464     Gui(unsigned long xid, float scale, bool loop, RunResources& r);
00465     
00467     //
00469     //
00472     virtual void quitUI() {
00473         std::exit(EXIT_SUCCESS);
00474     }
00475 
00477     //
00483     virtual bool watchFD(int /* fd */)
00484     {
00485         log_unimpl("This GUI does not implement FD watching.");
00486         return false;
00487     }
00488 
00489 
00491     bool _loop;
00492 
00494     unsigned long _xid;
00495 
00496     // This would be 0,0,_width,_height, so maybe
00497     // we should not duplicate the info with those
00498     // explicit values too..
00499     geometry::Range2d<int> _validbounds;
00500 
00502     int _width;
00503 
00505     int _height;
00506 
00508     RunResources& _runResources;
00509 
00511     unsigned int _interval;
00512 
00514     boost::shared_ptr<Renderer> _renderer;
00515 
00518     bool _redraw_flag;
00519 
00520     // True if Gnash is running in fullscreen
00521     bool _fullscreen;
00522 
00523     // True if mouse pointer is showing
00524     bool _mouseShown;
00525 
00526     // Maximum number of advances before exit; 0 for no limit.
00527     unsigned long _maxAdvances;
00528     
00530     unsigned long _advances;
00531 
00533     std::string _audioDump;
00534 
00537     virtual void stopHook() {}
00538 
00540     virtual void playHook() {}
00541 
00543     virtual bool visible() { return true; }
00544 private:
00545 
00546     struct Display;
00547 
00548     std::map<int /* fd */, boost::function<void ()> > _fd_callbacks;
00549 
00551     float _xscale;
00552 
00554     float _yscale;
00555 
00557     boost::int32_t _xoffset;
00558 
00560     boost::int32_t _yoffset;
00561 
00562     bool display(movie_root* m);
00563     
00564 #ifdef GNASH_FPS_DEBUG
00565     unsigned int fps_counter;
00566 
00567     float fps_rate_min, fps_rate_max;   
00568 
00569     // Number of calls to fpsCounterTick, which is also
00570     // the number of calls to movie_advance()
00571     unsigned int fps_counter_total;
00572 
00573     boost::uint64_t fps_timer, fps_start_timer;     
00574 
00576     //
00579     float fps_timer_interval;
00580     
00582     unsigned int frames_dropped;
00583 
00587     //
00590     void fpsCounterTick();
00591 
00592 #endif // def GNASH_FPS_DEBUG
00593 
00594     VariableMap _flashVars;
00595 
00596     boost::intrusive_ptr<movie_definition> _movieDef;
00597     
00599     movie_root* _stage;
00600 
00602     bool _stopped;
00603 
00605     bool _started;
00606 
00608     bool _showUpdatedRegions;
00609 
00610     SystemClock _systemClock;
00611     InterruptableVirtualClock _virtualClock;
00612     
00614     boost::scoped_ptr<ScreenShotter> _screenShotter;
00615 
00616 #ifdef ENABLE_KEYBOARD_MOUSE_MOVEMENTS 
00617     int _xpointer;
00618     int _ypointer;
00619     bool _keyboardMouseMovements;
00620     int _keyboardMouseMovementsStep;
00621 #endif // ENABLE_KEYBOARD_MOUSE_MOVEMENTS
00622 };
00623 
00625 std::auto_ptr<Gui> createGTKGui(unsigned long xid, float scale, bool loop, RunResources& r);
00626 std::auto_ptr<Gui> createKDEGui(unsigned long xid, float scale, bool loop, RunResources& r);
00627 std::auto_ptr<Gui> createKDE4Gui(unsigned long xid, float scale, bool loop, RunResources& r);
00628 std::auto_ptr<Gui> createSDLGui(unsigned long xid, float scale, bool loop, RunResources& r);
00629 std::auto_ptr<Gui> createFLTKGui(unsigned long xid, float scale, bool loop, RunResources& r);
00630 std::auto_ptr<Gui> createFBGui(unsigned long xid, float scale, bool loop, RunResources& r);
00631 std::auto_ptr<Gui> createAQUAGui(unsigned long xid, float scale, bool loop, RunResources& r);
00632 std::auto_ptr<Gui> createRISCOSGui(unsigned long xid, float scale, bool loop, RunResources& r);
00633 std::auto_ptr<Gui> createAOS4Gui(unsigned long xid, float scale, bool loop, RunResources& r);
00634 std::auto_ptr<Gui> createHaikuGui(unsigned long xid, float scale, bool loop, RunResources& r);
00635 std::auto_ptr<Gui> createDumpGui(unsigned long xid, float scale, bool loop, RunResources& r);
00636 
00637  
00638 } // end of gnash namespace
00639 
00640 // end of _GUI_H_
00641 #endif
00642 
00643 // Local Variables:
00644 // mode: C++
00645 // indent-tabs-mode: nil
00646 // End: