mail[Wesnoth-commits] r28448 - in /trunk/src: display.cpp display.hpp


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by kailoran on August 11, 2008 - 06:43:
Author: ilor
Date: Sun Aug 10 22:33:36 2008
New Revision: 28448

URL: http://svn.gna.org/viewcvs/wesnoth?rev=28448&view=rev
Log:
add redraw observers functionality in display: allow void (display&) 
callbacks to be placed in a display object that will be called on each 
redraw_everything call

Modified:
    trunk/src/display.cpp
    trunk/src/display.hpp

Modified: trunk/src/display.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/display.cpp?rev=28448&r1=28447&r2=28448&view=diff
==============================================================================
--- trunk/src/display.cpp (original)
+++ trunk/src/display.cpp Sun Aug 10 22:33:36 2008
@@ -119,7 +119,8 @@
        fps_handle_(0),
        idle_anim_(preferences::idle_anim()),
        idle_anim_rate_(1.0),
-       map_screenshot_surf_(NULL)
+       map_screenshot_surf_(NULL),
+       redraw_observers_()
 {
        if(non_interactive()
                && (get_video_surface() != NULL
@@ -1788,6 +1789,20 @@
        draw(true,true);
        int ticks3 = SDL_GetTicks();
        INFO_DP << "invalidate and draw: " << (ticks3 - ticks2) << " and " << 
(ticks2 - ticks1) << "\n";
+       
+       foreach (boost::function<void(display&)> f, redraw_observers_) {
+               f(*this);
+       }       
+}
+
+void display::add_redraw_observer(boost::function<void(display&)> f)
+{
+       redraw_observers_.push_back(f);
+}
+
+void display::clear_redraw_observers()
+{
+       redraw_observers_.clear();
 }
 
 void display::draw(bool update,bool force) {

Modified: trunk/src/display.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/display.hpp?rev=28448&r1=28447&r2=28448&view=diff
==============================================================================
--- trunk/src/display.hpp (original)
+++ trunk/src/display.hpp Sun Aug 10 22:33:36 2008
@@ -57,6 +57,8 @@
 #include <set>
 #include <string>
 
+#include <boost/function.hpp>
+
 
 class display
 {
@@ -224,8 +226,14 @@
        /** Save a (map-)screenshot and return the estimated file size */
        int screenshot(std::string filename, bool map_screenshot = false);
 
-       /** Invalidates entire screen, including all tiles and sidebar. */
+       /** Invalidates entire screen, including all tiles and sidebar. Calls 
redraw observers. */
        void redraw_everything();
+       
+       /** Adds a redraw observer, a function object to be called when 
redraw_everything is used */
+       void add_redraw_observer(boost::function<void(display&)> f);
+       
+       /** Clear the redraw observers */
+       void clear_redraw_observers();
 
        theme& get_theme() { return theme_; }
        gui::button* find_button(const std::string& id);
@@ -761,6 +769,8 @@
        double idle_anim_rate_;
 
        surface map_screenshot_surf_;
+       
+       std::vector<boost::function<void(display&)> > redraw_observers_;
 };
 
 #endif




Related Messages


Powered by MHonArc, Updated Mon Aug 11 08:21:57 2008