video.hpp

Go to the documentation of this file.
00001 /* $Id: video.hpp 52533 2012-01-07 02:35:17Z shadowmaster $ */
00002 /*
00003    Copyright (C) 2003 - 2012 by David White <dave@whitevine.net>
00004    Part of the Battle for Wesnoth Project http://www.wesnoth.org/
00005 
00006    This program is free software; you can redistribute it and/or modify
00007    it under the terms of the GNU General Public License as published by
00008    the Free Software Foundation; either version 2 of the License, or
00009    (at your option) any later version.
00010    This program is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY.
00012 
00013    See the COPYING file for more details.
00014 */
00015 #ifndef VIDEO_HPP_INCLUDED
00016 #define VIDEO_HPP_INCLUDED
00017 
00018 #include "events.hpp"
00019 #include "exceptions.hpp"
00020 #include "lua_jailbreak_exception.hpp"
00021 
00022 #include <boost/utility.hpp>
00023 
00024 struct surface;
00025 
00026 //possible flags when setting video modes
00027 #define FULL_SCREEN SDL_FULLSCREEN
00028 #define VIDEO_MEMORY SDL_HWSURFACE
00029 #define SYSTEM_MEMORY SDL_SWSURFACE
00030 
00031 surface display_format_alpha(surface surf);
00032 surface get_video_surface();
00033 SDL_Rect screen_area();
00034 
00035 bool non_interactive();
00036 
00037 //which areas of the screen will be updated when the buffer is flipped?
00038 void update_rect(size_t x, size_t y, size_t w, size_t h);
00039 void update_rect(const SDL_Rect& rect);
00040 void update_whole_screen();
00041 
00042 class CVideo : private boost::noncopyable {
00043      public:
00044          enum FAKE_TYPES {
00045              NO_FAKE,
00046              FAKE,
00047              FAKE_TEST
00048          };
00049 
00050     CVideo(FAKE_TYPES type = NO_FAKE);
00051     ~CVideo();
00052 
00053 
00054     int bppForMode( int x, int y, int flags);
00055     int modePossible( int x, int y, int bits_per_pixel, int flags, bool current_screen_optimal=false);
00056     int setMode( int x, int y, int bits_per_pixel, int flags );
00057 
00058     //did the mode change, since the last call to the modeChanged() method?
00059     bool modeChanged();
00060 
00061     //functions to get the dimensions of the current video-mode
00062     int getx() const;
00063     int gety() const;
00064 
00065     //blits a surface with black as alpha
00066     void blit_surface(int x, int y, surface surf, SDL_Rect* srcrect=NULL, SDL_Rect* clip_rect=NULL);
00067     void flip();
00068 
00069     surface& getSurface();
00070 
00071     bool isFullScreen() const;
00072 
00073     struct error : public game::error
00074     {
00075         error() : game::error("Video initialization failed") {}
00076     };
00077 
00078     class quit
00079         : public tlua_jailbreak_exception
00080     {
00081     public:
00082 
00083         quit()
00084             : tlua_jailbreak_exception()
00085         {
00086         }
00087 
00088     private:
00089 
00090         IMPLEMENT_LUA_JAILBREAK_EXCEPTION(quit)
00091     };
00092 
00093     //functions to allow changing video modes when 16BPP is emulated
00094     void setBpp( int bpp );
00095     int getBpp();
00096 
00097     void make_fake();
00098     /**
00099      * Creates a fake frame buffer for the unit tests.
00100      *
00101      * @param width               The width of the buffer.
00102      * @param height              The height of the buffer.
00103      * @param bpp                 The bpp of the buffer.
00104      */
00105     void make_test_fake(const unsigned width = 1024,
00106             const unsigned height = 768, const unsigned bpp = 32);
00107     bool faked() const { return fake_screen_; }
00108 
00109     //functions to set and clear 'help strings'. A 'help string' is like a tooltip, but it appears
00110     //at the bottom of the screen, so as to not be intrusive. Setting a help string sets what
00111     //is currently displayed there.
00112     int set_help_string(const std::string& str);
00113     void clear_help_string(int handle);
00114     void clear_all_help_strings();
00115 
00116     //function to stop the screen being redrawn. Anything that happens while
00117     //the update is locked will be hidden from the user's view.
00118     //note that this function is re-entrant, meaning that if lock_updates(true)
00119     //is called twice, lock_updates(false) must be called twice to unlock
00120     //updates.
00121     void lock_updates(bool value);
00122     bool update_locked() const;
00123 
00124 private:
00125 
00126     void initSDL();
00127 
00128     bool mode_changed_;
00129 
00130     int bpp_;   // Store real bits per pixel
00131 
00132     //if there is no display at all, but we 'fake' it for clients
00133     bool fake_screen_;
00134 
00135     //variables for help strings
00136     int help_string_;
00137 
00138     int updatesLocked_;
00139 };
00140 
00141 //an object which will lock the display for the duration of its lifetime.
00142 struct update_locker
00143 {
00144     update_locker(CVideo& v, bool lock=true) : video(v), unlock(lock) {
00145         if(lock) {
00146             video.lock_updates(true);
00147         }
00148     }
00149 
00150     ~update_locker() {
00151         unlock_update();
00152     }
00153 
00154     void unlock_update() {
00155         if(unlock) {
00156             video.lock_updates(false);
00157             unlock = false;
00158         }
00159     }
00160 
00161 private:
00162     CVideo& video;
00163     bool unlock;
00164 };
00165 
00166 class resize_monitor : public events::pump_monitor {
00167     void process(events::pump_info &info);
00168 };
00169 
00170 //an object which prevents resizing of the screen occurring during
00171 //its lifetime.
00172 struct resize_lock {
00173     resize_lock();
00174     ~resize_lock();
00175 };
00176 
00177 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated by doxygen 1.7.1 on Fri May 25 2012 01:03:14 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs