00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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 "SWFRect.h"
00027 #include "snappingrange.h"
00028 #include "GnashKey.h"
00029 #include "Renderer.h"
00030 #include "VirtualClock.h"
00031 #include "SystemClock.h"
00032 #include "gnash.h"
00033 #include "movie_root.h"
00034
00035 #ifdef USE_SWFTREE
00036 #include "tree.hh"
00037 #endif
00038
00039 #include <boost/intrusive_ptr.hpp>
00040 #include <boost/scoped_ptr.hpp>
00041 #include <boost/function.hpp>
00042 #include <vector>
00043 #include <cstdlib>
00044 #include <string>
00045 #include <map>
00046
00047
00048
00049
00050
00061
00062
00063
00065 #define ENABLE_KEYBOARD_MOUSE_MOVEMENTS 1
00066
00067
00068 namespace gnash
00069 {
00070 class RunResources;
00071 class movie_root;
00072 class movie_definition;
00073 }
00074
00075 namespace gnash {
00076
00078 enum gnash_cursor_type {
00079 CURSOR_HAND,
00080 CURSOR_NORMAL,
00081 CURSOR_INPUT
00082 };
00083
00084
00086 class ScreenShotter
00087 {
00088 public:
00089
00090 typedef std::vector<size_t> FrameList;
00091
00093 ScreenShotter(boost::shared_ptr<Renderer> r, const std::string& fileName)
00094 :
00095 _renderer(r),
00096 _immediate(false),
00097 _fileName(fileName),
00098 _last(false)
00099 {}
00100
00102 void now() {
00103 _immediate = true;
00104 }
00105
00107 void lastFrame() {
00108 _last = true;
00109 }
00110
00112
00117 void last() const;
00118
00120
00122
00125 void screenShot(size_t frameAdvance);
00126
00128 void setFrames(const FrameList& frames);
00129
00130 private:
00131
00133 void saveImage(const std::string& filename) const;
00134
00135 boost::shared_ptr<Renderer> _renderer;
00136
00138 bool _immediate;
00139
00141 const std::string _fileName;
00142
00144 bool _last;
00145
00146 FrameList _frames;
00147
00148 };
00149
00151 class Gui {
00152
00153 public:
00154
00155 virtual ~Gui();
00156
00164 virtual bool init(int argc, char **argv[]) = 0;
00165
00167 virtual void setInterval(unsigned int interval) {
00168 _interval = interval;
00169 }
00170
00172
00175 void setFDCallback(int fd, boost::function<void ()> callback);
00176
00178
00181 void callCallback(int fd);
00182
00184
00188 VirtualClock& getClock() { return _virtualClock; }
00189
00191 virtual void setTimeout(unsigned int timeout) = 0;
00192
00194
00198 void requestScreenShots(const ScreenShotter::FrameList& l, bool last,
00199 const std::string& filename);
00200
00210 virtual bool createWindow(const char* title, int width, int height,
00211 int xPosition = 0, int yPosition = 0) = 0;
00212
00213 virtual void resizeWindow(int width, int height);
00214
00216 virtual bool run() = 0;
00217
00219
00221 void quit();
00222
00225 virtual void renderBuffer() = 0;
00226
00228
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253 virtual void setInvalidatedRegion(const SWFRect& bounds);
00254 virtual void setInvalidatedRegions(const InvalidatedRanges& ranges);
00255
00256
00257
00258 virtual void beforeRendering() { };
00259
00260
00261
00262 virtual bool want_multiple_regions() { return false; }
00263
00265
00269 virtual bool want_redraw();
00270
00272 virtual void setCursor(gnash_cursor_type newcursor);
00273
00274
00275
00276 virtual double getPixelAspectRatio() { return 0; }
00277 virtual int getScreenResX() { return 0; }
00278 virtual int getScreenResY() { return 0; }
00279 virtual double getScreenDPI() { return 0; }
00280 virtual std::string getScreenColor() { return ""; }
00281
00283 bool loops() const { return _loop; }
00284
00286 bool isFullscreen() const { return _fullscreen; }
00287
00289
00294 void notifyMouseMove(int x, int y);
00295
00297
00300 void notifyMouseClick(bool mouse_pressed);
00301
00303
00305 void notifyMouseWheel(int delta);
00306
00308
00314 void notify_key_event(gnash::key::code k, int modifier, bool pressed);
00315
00317
00320 void resize_view(int width, int height);
00321
00324
00328 void updateStageMatrix();
00329
00333 bool advanceMovie();
00334
00336 static bool advance_movie(Gui* gui) {
00337 return gui->advanceMovie();
00338 }
00339
00342 void refreshView();
00343
00346
00351 virtual void setFullscreen();
00352
00355 virtual void unsetFullscreen();
00356
00359 virtual void hideMenu();
00360
00362
00365 virtual bool showMouse(bool show);
00366
00368
00370 virtual void showMenu(bool show);
00371
00373
00375 virtual void allowScale(bool allow);
00376
00377
00378 void toggleFullscreen();
00379
00381
00384 void stop();
00385
00387
00390 void play();
00391
00393
00396 void pause();
00397
00399
00403 void start();
00404
00406 bool isStopped() const { return _stopped; }
00407
00409 bool isPlugin() const { return ((_xid)); }
00410
00412 void takeScreenShot();
00413
00415 void setMaxAdvances(unsigned long ul) { if (ul) _maxAdvances = ul; }
00416
00417 void showUpdatedRegions(bool x) { _showUpdatedRegions = x; }
00418 bool showUpdatedRegions() const { return _showUpdatedRegions; }
00419
00423 void restart();
00424
00426 void setQuality(Quality q);
00427
00429 Quality getQuality() const;
00430
00433 void toggleSound();
00434
00435 #ifdef GNASH_FPS_DEBUG
00436
00437
00440 void setFpsTimerInterval(float interval)
00441 {
00442 assert(interval >= 0.0);
00443 fps_timer_interval = interval;
00444 }
00445 #endif // def GNASH_FPS_DEBUG
00446
00447
00448 #ifdef USE_SWFTREE
00449
00450 typedef std::pair<std::string, std::string> StringPair;
00451 typedef tree<StringPair> InfoTree;
00452
00457 std::auto_ptr<InfoTree> getMovieInfo() const;
00458 #endif
00459
00460 typedef std::map<std::string, std::string> VariableMap;
00461
00463 void addFlashVars(VariableMap& vars);
00464
00466 void addScriptableVar(const std::string &name, const std::string &value);
00467
00469 void setMovieDefinition(movie_definition* md);
00470
00472 void setStage(movie_root* stage);
00473
00475 movie_root *getStage() { return _stage; };
00476
00478
00481 virtual void error(const std::string& ) {}
00482
00484
00493 virtual bool yesno(const std::string& question);
00494
00496 float getXScale() { return _xscale; };
00497
00499 float getYScale() { return _yscale; };
00500
00501 protected:
00502
00504 Gui(RunResources& r);
00505
00520 Gui(unsigned long xid, float scale, bool loop, RunResources& r);
00521
00523
00525
00528 virtual void quitUI() {
00529 std::exit(EXIT_SUCCESS);
00530 }
00531
00533
00539 virtual bool watchFD(int )
00540 {
00541 log_unimpl("This GUI does not implement FD watching.");
00542 return false;
00543 }
00544
00545
00547 bool _loop;
00548
00550 unsigned long _xid;
00551
00552
00553
00554
00555
00556 geometry::Range2d<int> _validbounds;
00557
00559 int _width;
00560
00562 int _height;
00563
00565 RunResources& _runResources;
00566
00568 unsigned int _interval;
00569
00571 boost::shared_ptr<Renderer> _renderer;
00572
00575 bool _redraw_flag;
00576
00577
00578 bool _fullscreen;
00579
00580
00581 bool _mouseShown;
00582
00583
00584 unsigned long _maxAdvances;
00585
00587 unsigned long _advances;
00588
00591 virtual void stopHook() {}
00592
00594 virtual void playHook() {}
00595
00596 private:
00597 std::map<int , boost::function<void ()> > _fd_callbacks;
00598
00600 float _xscale;
00601
00603 float _yscale;
00604
00606 boost::int32_t _xoffset;
00607
00609 boost::int32_t _yoffset;
00610
00611 bool display(movie_root* m);
00612
00613 #ifdef GNASH_FPS_DEBUG
00614 unsigned int fps_counter;
00615
00616 float fps_rate_min, fps_rate_max;
00617
00618
00619
00620 unsigned int fps_counter_total;
00621
00622 boost::uint64_t fps_timer, fps_start_timer;
00623
00625
00628 float fps_timer_interval;
00629
00631 unsigned int frames_dropped;
00632
00636
00639 void fpsCounterTick();
00640
00641 #endif // def GNASH_FPS_DEBUG
00642
00643 VariableMap _flashVars;
00644 VariableMap _scriptableVars;
00645
00646 boost::intrusive_ptr<movie_definition> _movieDef;
00647
00649 movie_root* _stage;
00650
00652 bool _stopped;
00653
00655 bool _started;
00656
00658 bool _showUpdatedRegions;
00659
00660 SystemClock _systemClock;
00661 InterruptableVirtualClock _virtualClock;
00662
00664 boost::scoped_ptr<ScreenShotter> _screenShotter;
00665
00666 #ifdef ENABLE_KEYBOARD_MOUSE_MOVEMENTS
00667 int _xpointer;
00668 int _ypointer;
00669 bool _keyboardMouseMovements;
00670 int _keyboardMouseMovementsStep;
00671 #endif // ENABLE_KEYBOARD_MOUSE_MOVEMENTS
00672 };
00673
00675 std::auto_ptr<Gui> createGTKGui(unsigned long xid, float scale, bool loop, RunResources& r);
00676 std::auto_ptr<Gui> createKDEGui(unsigned long xid, float scale, bool loop, RunResources& r);
00677 std::auto_ptr<Gui> createKDE4Gui(unsigned long xid, float scale, bool loop, RunResources& r);
00678 std::auto_ptr<Gui> createSDLGui(unsigned long xid, float scale, bool loop, RunResources& r);
00679 std::auto_ptr<Gui> createFLTKGui(unsigned long xid, float scale, bool loop, RunResources& r);
00680 std::auto_ptr<Gui> createFBGui(unsigned long xid, float scale, bool loop, RunResources& r);
00681 std::auto_ptr<Gui> createAQUAGui(unsigned long xid, float scale, bool loop, RunResources& r);
00682 std::auto_ptr<Gui> createRISCOSGui(unsigned long xid, float scale, bool loop, RunResources& r);
00683 std::auto_ptr<Gui> createAOS4Gui(unsigned long xid, float scale, bool loop, RunResources& r);
00684 std::auto_ptr<Gui> createHaikuGui(unsigned long xid, float scale, bool loop, RunResources& r);
00685 std::auto_ptr<Gui> createDumpGui(unsigned long xid, float scale, bool loop, RunResources& r);
00686
00687
00688 }
00689
00690
00691 #endif
00692
00693
00694
00695
00696