mail[Wesnoth-commits] r24673 - in /trunk/src/gui/widgets: window.cpp window.hpp


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

Header


Content

Posted by koraq on March 15, 2008 - 22:50:
Author: mordante
Date: Sat Mar 15 22:35:00 2008
New Revision: 24673

URL: http://svn.gna.org/viewcvs/wesnoth?rev=24673&view=rev
Log:
Added proof-of-concept code to do the window drawing, the window
can now draw it's own contents and the closing now properly cleans
up.

Modified:
    trunk/src/gui/widgets/window.cpp
    trunk/src/gui/widgets/window.hpp

Modified: trunk/src/gui/widgets/window.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/window.cpp?rev=24673&r1=24672&r2=24673&view=diff
==============================================================================
--- trunk/src/gui/widgets/window.cpp (original)
+++ trunk/src/gui/widgets/window.cpp Sat Mar 15 22:35:00 2008
@@ -40,7 +40,10 @@
        status_(NEW),
        event_info_(),
        event_context_(),
-       need_layout_(true)
+       need_layout_(true),
+       restorer_(),
+       canvas_background_(),
+       canvas_foreground_()
 {
        set_x(x);
        set_y(y);
@@ -64,24 +67,13 @@
        // We cut a piec of the screen and use that, that way all coordinates
        // are relative to the window.
        SDL_Rect rect = get_rect();
-       surface screen = get_surface_portion(video_.getSurface(), rect);
-
-       // Preserve area
-       surface restorer;
-       if(restore) {
-               restorer = screen;
-       }
-
-       // draw Window hack
-       SDL_Rect Xrect = {0, 0, screen->w, screen->h};
-       fill_rect_alpha(Xrect, 0, 128, screen);
+       restorer_ = get_surface_portion(video_.getSurface(), rect);
+       surface screen;
 
        // Start our loop drawing will happen here as well.
        for(status_ = SHOWING; status_ != REQUEST_CLOSE; ) {
                events::pump();
 
-       
-       
        
                // fixme hack to disable 
                if(event_info_.mouse_right_button_down) {
@@ -94,14 +86,22 @@
                }
 
                if(dirty() || need_layout_) {
+                       const bool draw_foreground = need_layout_;
                        if(need_layout_) {
                                DBG_GUI << "Layout.\n";
-                               layout(Xrect);
+                               resolve_definition();
+                               layout(get_client_rect());
+
+                               screen = create_optimized_surface(restorer_);
+
+                               canvas_background_.draw();
+                               SDL_Rect blit = {0, 0, screen->w, screen->h};
+                               SDL_BlitSurface(canvas_background_.surf(), 0, 
screen, &blit);
                        }
 #if 0                  
                        // Darkening for debugging redraw.
-                       SDL_Rect Xrect = {0, 0, screen->w, screen->h};
-                       fill_rect_alpha(Xrect, 0, 1, screen);
+                       SDL_Rect temp_rect = {0, 0, screen->w, screen->h};
+                       fill_rect_alpha(temp_rect, 0, 1, screen);
 #endif
 
                        for(tsizer::iterator itor = begin(); itor != end(); 
++itor) {
@@ -114,9 +114,16 @@
 
                                itor->draw(screen);
                        }
+                       if(draw_foreground) {
+                               canvas_foreground_.draw();
+                               SDL_Rect blit = {0, 0, screen->w, screen->h};
+                               SDL_BlitSurface(canvas_foreground_.surf(), 0, 
screen, &blit);
+                       }
+
                        rect = get_rect();
                        SDL_BlitSurface(screen, 0, video_.getSurface(), 
&rect);
                        update_rect(get_rect());
+                       set_dirty(false);
                }
 
                // delay until it's our frame see display.ccp code for how to 
do that
@@ -127,7 +134,7 @@
        // restore area
        if(restore) {
                rect = get_rect();
-               SDL_BlitSurface(restorer, 0, screen, &rect);
+               SDL_BlitSurface(restorer_, 0, video_.getSurface(), &rect);
                update_rect(get_rect());
                flip();
        }
@@ -140,7 +147,7 @@
        tpoint best_size = get_best_size();
 
        if(best_size.x < position.w && best_size.y < position.h) {
-               set_best_size(tpoint(0, 0));
+               set_best_size(tpoint(position.x, position.y));
                return;
        }
 
@@ -152,6 +159,31 @@
        // Failed at best size try minumum.
        
        // Failed at minimum log error and try to do the best possible thing.
+}
+
+void twindow::set_width(const int width)
+{
+
+       DBG_GUI << "Setting width to " << width << '\n';
+
+       canvas_background_.set_width(width);
+       canvas_foreground_.set_width(width);
+       need_layout_ = true;
+
+       // inherited
+       tcontrol::set_width(width);
+}
+
+void twindow::set_height(const int height)
+{
+       DBG_GUI << "Setting height to " << height << '\n';
+
+       canvas_background_.set_height(height);
+       canvas_foreground_.set_height(height);
+       need_layout_ = true;
+
+       // inherited
+       tcontrol::set_height(height);
 }
 
 void twindow::flip()
@@ -291,5 +323,36 @@
        need_layout_ = true;
 }
 
+void twindow::resolve_definition()
+{
+       if(definition_ == 
std::vector<twindow_definition::tresolution>::const_iterator()) {
+               definition_ = get_window(definition());
+
+               canvas_background_ = definition_->background.canvas;
+               canvas_background_.set_width(get_width());
+               canvas_background_.set_height(get_height());
+
+               canvas_foreground_ = definition_->foreground.canvas;
+               canvas_foreground_.set_width(get_width());
+               canvas_foreground_.set_height(get_height());
+       }
+
+}
+SDL_Rect twindow::get_client_rect()
+{
+       assert(definition_ != 
std::vector<twindow_definition::tresolution>::const_iterator());
+
+       SDL_Rect result = get_rect();
+       result.x = definition_->left_border;
+       result.y = definition_->top_border;
+       result.w -= definition_->left_border + definition_->right_border;
+       result.h -= definition_->top_border + definition_->bottom_border;
+
+       // FIXME validate for an available client area.
+       
+       return result;
+
+}
+
 } // namespace gui2
 

Modified: trunk/src/gui/widgets/window.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/window.hpp?rev=24673&r1=24672&r2=24673&view=diff
==============================================================================
--- trunk/src/gui/widgets/window.hpp (original)
+++ trunk/src/gui/widgets/window.hpp Sat Mar 15 22:35:00 2008
@@ -21,6 +21,7 @@
 
 #include "gui/widgets/widget.hpp"
 #include "gui/widgets/canvas.hpp"
+#include "gui/widgets/settings.hpp"
 #include "gui/widgets/event_info.hpp"
 
 #include "sdl_utils.hpp"
@@ -66,9 +67,12 @@
 
        enum tstatus{ NEW, SHOWING, REQUEST_CLOSE, CLOSED };
 
+       void set_width(const int width);
+
+       void set_height(const int height);
+
 protected:
 private:
-
 
 
        void flip();
@@ -102,7 +106,18 @@
 
        //! When set the form needs a full layout redraw cycle.
        bool need_layout_;
+
+       surface restorer_;
        
+       tcanvas
+               canvas_background_,
+               canvas_foreground_;
+
+       std::vector<twindow_definition::tresolution>::const_iterator 
definition_;
+
+       void resolve_definition();
+
+       SDL_Rect get_client_rect();
 };
 
 } // namespace gui2




Related Messages


Powered by MHonArc, Updated Sat Mar 15 23:02:00 2008