Author: mordante
Date: Wed Aug 27 00:20:58 2008
New Revision: 29008

URL: http://svn.gna.org/viewcvs/wesnoth?rev=29008&view=rev
Log:
Added constness to the font::ttext class.

A lot of functions weren't marked const since they change internal
variables. All those variables are internal caching values and don't
change the state of the object. Marked the logical functions const and
added mutable to the internal variables.

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

Modified: trunk/src/text.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/text.cpp?rev=29008&r1=29007&r2=29008&view=diff
==============================================================================
--- trunk/src/text.cpp (original)
+++ trunk/src/text.cpp Wed Aug 27 00:20:58 2008
@@ -98,30 +98,30 @@
        }
 }
 
-surface ttext::render()
+surface ttext::render() const
 {
        rerender();
        return surface_;
 }
 
-int ttext::get_width() 
+int ttext::get_width() const
 {
        return get_size().x;
 }
 
-int ttext::get_height() 
+int ttext::get_height() const
 {
        return get_size().y;
 }
 
-gui2::tpoint ttext::get_size() 
+gui2::tpoint ttext::get_size() const
 {
        recalculate();
 
        return gui2::tpoint(rect_.width, rect_.height);
 }
 
-bool ttext::is_truncated()
+bool ttext::is_truncated() const
 {
        recalculate();
 
@@ -129,7 +129,7 @@
 }
 
 gui2::tpoint ttext::get_cursor_position(
-               const unsigned column, const unsigned line)
+               const unsigned column, const unsigned line) const
 {
        recalculate();
 
@@ -172,7 +172,7 @@
        return gui2::tpoint(PANGO_PIXELS(rect.x), PANGO_PIXELS(rect.y));
 }
 
-gui2::tpoint ttext::get_column_line(const gui2::tpoint& position)
+gui2::tpoint ttext::get_column_line(const gui2::tpoint& position) const
 {
        recalculate();
 
@@ -332,7 +332,7 @@
 
 } // namespace
 
-void ttext::recalculate(const bool force)
+void ttext::recalculate(const bool force) const
 {
        if(calculation_dirty_ || force) {
                calculation_dirty_ = false;
@@ -345,7 +345,7 @@
        }
 }
 
-void ttext::rerender(const bool force) 
+void ttext::rerender(const bool force) const
 {
        if(surface_dirty_ || force) {
                recalculate(force);
@@ -384,7 +384,7 @@
        }
 }
 
-void ttext::create_surface_buffer(const size_t size)
+void ttext::create_surface_buffer(const size_t size) const
 {
        // clear old buffer
        if(surface_buffer_) {

Modified: trunk/src/text.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/text.hpp?rev=29008&r1=29007&r2=29008&view=diff
==============================================================================
--- trunk/src/text.hpp (original)
+++ trunk/src/text.hpp Wed Aug 27 00:20:58 2008
@@ -50,19 +50,19 @@
         * Before rendering it tests whether a redraw is needed and if so it 
first
         * redraws the surface before returning it.
         */
-       surface render();
+       surface render() const;
 
        /** Returns the width needed for the text. */
-       int get_width() ;
+       int get_width() const;
 
        /** Returns the height needed for the text. */
-       int get_height() ;
+       int get_height() const;
 
        /** Returns the size needed for the text. */
-       gui2::tpoint get_size() ;
+       gui2::tpoint get_size() const;
 
        /** Has the text been truncated? */
-       bool is_truncated();
+       bool is_truncated() const;
 
        /***** ***** ***** ***** Font flags ***** ***** ***** *****/
 
@@ -90,7 +90,7 @@
         *                            returned.
         */
        gui2::tpoint get_cursor_position(
-               const unsigned column, const unsigned line = 0);
+               const unsigned column, const unsigned line = 0) const;
 
        /**
         * Gets the column of line of the character at the position.
@@ -101,7 +101,7 @@
         *                            value the line of the character found (or 
last
         *                            character if not found.
         */
-       gui2::tpoint get_column_line(const gui2::tpoint& position);
+       gui2::tpoint get_column_line(const gui2::tpoint& position) const;
 
        /**
         * Gets the length of the text in characters. 
@@ -132,7 +132,7 @@
        /***** ***** ***** *****  Pango variables ***** ***** ***** *****/
        PangoContext* context_;
        PangoLayout* layout_;
-       PangoRectangle rect_;
+       mutable PangoRectangle rect_;
 
        /** The surface to render upon used as a cache. */
        mutable surface surface_;
@@ -169,7 +169,7 @@
         */
 
        /** The dirty state of the calculations. */
-       bool calculation_dirty_;
+       mutable bool calculation_dirty_;
 
        /**
         * Recalculates the text.
@@ -178,10 +178,10 @@
         *
         * @param force               Recalculate even if not dirty?
         */
-       void recalculate(const bool force = false);
+       void recalculate(const bool force = false) const;
 
        /** The dirty state of the surface. */
-       bool surface_dirty_;
+       mutable bool surface_dirty_;
 
        /**
         * Renders the text.
@@ -191,7 +191,7 @@
         * @param force               Render even if not dirty? This parameter 
is
         *                            also send to recalculate().
         */
-       void rerender(const bool force = false);
+       void rerender(const bool force = false) const;
 
        /** 
         * Buffer to store the image on.
@@ -200,7 +200,7 @@
         * data source for the SDL_Surface. This means the buffer needs to be 
stored
         * in the object.
         */
-       unsigned char* surface_buffer_;
+       mutable unsigned char* surface_buffer_;
        
        /**
         * Creates a new buffer.
@@ -208,9 +208,13 @@
         * If needed frees the other surface and then creates a new buffer and
         * initializes the entire buffer with values 0.
         *
+        * NOTE eventhough we're clearly modifing function we don't change the
+        * state of the object. The const is needed so other functions can also 
be
+        * marked const (those also don't change the state of the object.
+        *
         * @param size                The required size of the buffer.
         */
-       void create_surface_buffer(const size_t size); 
+       void create_surface_buffer(const size_t size) const; 
 };
 
 } // namespace font 


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

Reply via email to