Author: mordante
Date: Wed Apr  9 21:04:01 2008
New Revision: 25714

URL: http://svn.gna.org/viewcvs/wesnoth?rev=25714&view=rev
Log:
Add positioning and scaling to an image on the canvas.
With this feature the window can look much more like the original so also made 
that change.

Modified:
    trunk/data/gui/default/macros.cfg
    trunk/data/gui/default/widget/window_default.cfg
    trunk/src/gui/widgets/canvas.cpp
    trunk/src/gui/widgets/canvas.hpp

Modified: trunk/data/gui/default/macros.cfg
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/data/gui/default/macros.cfg?rev=25714&r1=25713&r2=25714&view=diff
==============================================================================
--- trunk/data/gui/default/macros.cfg (original)
+++ trunk/data/gui/default/macros.cfg Wed Apr  9 21:04:01 2008
@@ -10,7 +10,7 @@
 #
 
 #define FONT_COLOUR_ENABLED
-       "0, 0, 0, 255"
+       "221, 221, 221, 255"
 #enddef
 
 #define FONT_COLOUR_DISABLED

Modified: trunk/data/gui/default/widget/window_default.cfg
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/data/gui/default/widget/window_default.cfg?rev=25714&r1=25713&r2=25714&view=diff
==============================================================================
--- trunk/data/gui/default/widget/window_default.cfg (original)
+++ trunk/data/gui/default/widget/window_default.cfg Wed Apr  9 21:04:01 2008
@@ -10,34 +10,93 @@
        [resolution]
 
                left_border = 10
-               right_border = 10
+               right_border = 13
                top_border = 10
-               bottom_border = 10
+               bottom_border = 13
 
                [background]
 
                        [draw]
 
-                               [rectangle]
+# Keep the old way, might come in handy for testing later.
+#                              [rectangle]
+#                                      x = 0
+#                                      y = 0
+#                                      w = "(width)"
+#                                      h = "(height)"
+
+#                                      border_thickness = 3
+#                                      border_colour = "55, 55, 55, 192"
+#                                      fill_colour = "128, 128, 128, 128"
+#                              [/rectangle]
+
+#                              [rectangle]
+#                                      x = 10
+#                                      y = 10
+#                                      w = "(width - 20)"
+#                                      h = "(height - 20)"
+
+#                                      border_thickness = 3
+#                                      border_colour = "55, 55, 55, 192"
+#                              [/rectangle]
+
+                               [image]
+                                       name = 
"dialogs/opaque-border-topleft.png"
+                               [/image]
+
+                               [image]
+                                       x = 5
+                                       y = 0
+                                       w = "(width - 14)"
+                                       name = "dialogs/opaque-border-top.png"
+                               [/image]
+
+                               [image]
+                                       x = "(width - 9)"
+                                       y = 0
+                                       name = 
"dialogs/opaque-border-topright.png"
+                               [/image]
+
+                               [image]
+                                       x = "(width - 9)"
+                                       y = 5
+                                       h = "(height - 14)"
+                                       name = "dialogs/opaque-border-right.png"
+                               [/image]
+
+                               [image]
+                                       x = "(width - 9)"
+                                       y = "(height - 9)"
+                                       name = 
"dialogs/opaque-border-botright.png"
+                               [/image]
+
+                               [image]
+                                       x = 5
+                                       y = "(height - 9)"
+                                       w = "(width - 14)"
+                                       name = 
"dialogs/opaque-border-bottom.png"
+                               [/image]
+
+                               [image]
                                        x = 0
-                                       y = 0
-                                       w = "(width)"
-                                       h = "(height)"
+                                       y = "(height - 9)"
+                                       name = 
"dialogs/opaque-border-botleft.png"
+                               [/image]
 
-                                       border_thickness = 3
-                                       border_colour = "55, 55, 55, 192"
-                                       fill_colour = "128, 128, 128, 128"
-                               [/rectangle]
+                               [image]
+                                       x = 0
+                                       y = 5
+                                       h = "(height - 14)"
+                                       name = "dialogs/opaque-border-left.png"
+                               [/image]
 
-                               [rectangle]
-                                       x = 10
-                                       y = 10
-                                       w = "(width - 20)"
-                                       h = "(height - 20)"
-
-                                       border_thickness = 3
-                                       border_colour = "55, 55, 55, 192"
-                               [/rectangle]
+                               [image]
+                                       x = 5
+                                       y = 5
+                                       w = "(width - 14)"
+                                       h = "(height - 14)"
+                                       name = "dialogs/opaque-background.png"
+                               [/image]
 
                        [/draw]
 

Modified: trunk/src/gui/widgets/canvas.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/canvas.cpp?rev=25714&r1=25713&r2=25714&view=diff
==============================================================================
--- trunk/src/gui/widgets/canvas.cpp (original)
+++ trunk/src/gui/widgets/canvas.cpp Wed Apr  9 21:04:01 2008
@@ -586,19 +586,42 @@
 }
 
 tcanvas::timage::timage(const config& cfg) :
+       x_(0),
+       y_(0),
+       w_(0),
+       h_(0),
+       x_formula_(""),
+       y_formula_(""),
+       w_formula_(""),
+       h_formula_(""),
        src_clip_(),
        dst_clip_(),
        image_()
 {
-
-//FIXME enhance the options and write the wiki block in the new style.
-
 /*WIKI
  * [image]
- *     name = (string)                The name of the image.
- *     debug = (string = "")          Debug message to show upon creation
+ * Definition of an image.
+ * Keys: 
+ *     x (f_unsigned = 0)              The x coordinate of the top left corner.
+ *     y (f_unsigned = 0)              The y coordinate of the top left corner.
+ *     w (f_unsigned = 0)              The width of the image, if not zero the
+ *                                     image will be scaled to the desired 
width.
+ *     h (f_unsigned = 0)              The height of the image, if not zero the
+ *                                     image will be scaled to the desired 
height.
+ *     name (string = "")              The name of the image.
+ *     debug = (string = "")           Debug message to show upon creation
+ *                                     this message is not stored.
+ *
+ * Variables:
+ * See [line].
+ *
  * [/image]
  */
+
+       read_possible_formula(cfg["x"], x_, x_formula_);
+       read_possible_formula(cfg["y"], y_, y_formula_);
+       read_possible_formula(cfg["w"], w_, w_formula_);
+       read_possible_formula(cfg["h"], h_, h_formula_);
 
        image_.assign(image::get_image(image::locator(cfg["name"])));
        src_clip_ = create_rect(0, 0, image_->w, image_->h);
@@ -614,9 +637,56 @@
 {
        DBG_G_D << "Image: draw.\n";
 
+       if(!x_formula_.empty()) {
+               DBG_G_D << "Image: execute x formula '" << x_formula_ << "'.\n";
+               x_ = 
game_logic::formula(x_formula_).execute(variables).as_int();
+       }
+
+       if(!y_formula_.empty()) {
+               DBG_G_D << "Image: execute y formula '" << y_formula_ << "'.\n";
+               y_ = 
game_logic::formula(y_formula_).execute(variables).as_int();
+       }
+
+       if(!w_formula_.empty()) {
+               DBG_G_D << "Image: execute width formula '" << w_formula_ << 
"'.\n";
+               w_ = 
game_logic::formula(w_formula_).execute(variables).as_int();
+       }
+
+       if(!h_formula_.empty()) {
+               DBG_G_D << "Image: execute height formula '" << h_formula_ << 
"'.\n";
+               h_ = 
game_logic::formula(h_formula_).execute(variables).as_int();
+       }
+
+       // Copy the data to local variables to avoid overwriting the originals.
        SDL_Rect src_clip = src_clip_;
        SDL_Rect dst_clip = dst_clip_;
-       SDL_BlitSurface(image_, &src_clip, canvas, &dst_clip);
+       dst_clip.x = x_;
+       dst_clip.y = y_;
+       unsigned w = w_;
+       unsigned h = h_;
+       surface surf;
+
+       // Test whether we need to scale and do the scaling if needed.
+       if(w || h) {
+               if(!w) {
+                       w = image_->w;
+               }
+
+               if(!h) {
+                       h = image_->h;
+               }
+
+               DBG_G_D << "Image: scaling from " << image_->w 
+                       << ',' << image_->h << " to " << w << ',' << h << ".\n";
+
+               surf = scale_surface(image_, w, h);
+               src_clip.w = w;
+               src_clip.h = h;
+       } else {
+               surf = image_;
+       }
+
+       SDL_BlitSurface(surf, &src_clip, canvas, &dst_clip);
 }
 
 tcanvas::ttext::ttext(const config& cfg) :

Modified: trunk/src/gui/widgets/canvas.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/canvas.hpp?rev=25714&r1=25713&r2=25714&view=diff
==============================================================================
--- trunk/src/gui/widgets/canvas.hpp (original)
+++ trunk/src/gui/widgets/canvas.hpp Wed Apr  9 21:04:01 2008
@@ -135,22 +135,6 @@
                        const game_logic::map_formula_callable& variables);
 
        private:
-               SDL_Rect src_clip_;
-               SDL_Rect dst_clip_;
-               surface image_;
-       };
-
-       //! Definition of a text shape.
-       class ttext : public tshape
-       {
-       public:
-               ttext(const config& cfg);
-               
-               //! Implement shape::draw().
-               void draw(surface& canvas,
-                       const game_logic::map_formula_callable& variables);
-
-       private:
                unsigned x_, y_;
                unsigned w_, h_;
 
@@ -160,6 +144,31 @@
                        w_formula_,
                        h_formula_;
 
+               SDL_Rect src_clip_;
+               SDL_Rect dst_clip_;
+               surface image_;
+       };
+
+       //! Definition of a text shape.
+       class ttext : public tshape
+       {
+       public:
+               ttext(const config& cfg);
+               
+               //! Implement shape::draw().
+               void draw(surface& canvas,
+                       const game_logic::map_formula_callable& variables);
+
+       private:
+               unsigned x_, y_;
+               unsigned w_, h_;
+
+               std::string
+                       x_formula_,
+                       y_formula_,
+                       w_formula_,
+                       h_formula_;
+
                unsigned font_size_;
                Uint32 colour_;
                t_string text_;


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

Reply via email to