Author: mordante
Date: Tue Aug 12 20:21:04 2008
New Revision: 28496

URL: http://svn.gna.org/viewcvs/wesnoth?rev=28496&view=rev
Log:
Add a render cache in the control, this should reduce (or remove) the lag when
creating a dialog. It's still created at least twice, also in the canvas, this
could be changed but will involve some unwanted connections between the control
and the canvas, so rather not do that if not required.

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

Modified: trunk/src/gui/widgets/control.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/control.cpp?rev=28496&r1=28495&r2=28496&view=diff
==============================================================================
--- trunk/src/gui/widgets/control.cpp (original)
+++ trunk/src/gui/widgets/control.cpp Tue Aug 12 20:21:04 2008
@@ -17,7 +17,6 @@
 #include "foreach.hpp"
 #include "gui/widgets/window.hpp"
 #include "log.hpp"
-#include "../../text.hpp"
 
 #define DBG_G LOG_STREAM_INDENT(debug, gui)
 #define LOG_G LOG_STREAM_INDENT(info, gui)
@@ -50,7 +49,8 @@
        help_message_(),
        canvas_(canvas_count),
        restorer_(),
-       config_(0)
+       config_(0),
+       renderer_()
 {
 }
 
@@ -237,26 +237,25 @@
        const tpoint border(config_->text_extra_width, 
config_->text_extra_height);
        tpoint size = minimum_size - border;
 
-       font::ttext text;
-       text.set_text(label_, false);
-       text.set_font_size(config_->text_font_size);
+       renderer_.set_text(label_, false);
+       renderer_.set_font_size(config_->text_font_size);
 
        // Try with the minimum wanted size.
-       text.set_maximum_width(size.x);
+       renderer_.set_maximum_width(size.x);
        if(multiline_label_) {
-               text.set_maximum_height(size.y);
+               renderer_.set_maximum_height(size.y);
        }
 
        // If doesn't fit try the maximum.
-       if(text.is_truncated()) {
+       if(renderer_.is_truncated()) {
                const tpoint maximum_size(config_->max_width, 
config_->max_height);
-               text.set_maximum_width(maximum_size.x ? maximum_size.x - 
border.x : -1);
+               renderer_.set_maximum_width(maximum_size.x ? maximum_size.x - 
border.x : -1);
                if(multiline_label_) {
-                       text.set_maximum_height(maximum_size.y ? maximum_size.y 
- border.y : -1);
+                       renderer_.set_maximum_height(maximum_size.y ? 
maximum_size.y - border.y : -1);
                }
        }
 
-       size = text.get_size() + border;
+       size = renderer_.get_size() + border;
 
        if(size.x < minimum_size.x) {
                size.x = minimum_size.x;

Modified: trunk/src/gui/widgets/control.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/control.hpp?rev=28496&r1=28495&r2=28496&view=diff
==============================================================================
--- trunk/src/gui/widgets/control.hpp (original)
+++ trunk/src/gui/widgets/control.hpp Tue Aug 12 20:21:04 2008
@@ -18,6 +18,7 @@
 #include "gui/widgets/canvas.hpp"
 #include "gui/widgets/settings.hpp"
 #include "gui/widgets/widget.hpp"
+#include "../../text.hpp"
 #include "tstring.hpp"
 
 #include <cassert>
@@ -308,6 +309,20 @@
         * @returns                   The best size.
         */
        tpoint get_best_text_size(const tpoint& minimum_size) const;
+
+
+       /** 
+        * Contains a helper cache for the rendering.
+        *
+        * Creating a ttext object is quite expensive and is done on various
+        * occasions so it's cached here.
+        * 
+        * @todo Maybe if still too slow we might also copy this cache to the
+        * canvas so it can reuse our results, but for now it seems fast enough.
+        * Unfortunately that would make the dependency between the classes 
bigger
+        * as wanted.
+        */
+       mutable font::ttext renderer_;
 };
 
 } // namespace gui2


_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits

Reply via email to