Author: mordante
Date: Sun Mar 9 15:53:23 2008
New Revision: 24443
URL: http://svn.gna.org/viewcvs/wesnoth?rev=24443&view=rev
Log:
Add image tag for the canvas
Modified:
trunk/src/gui/widgets/canvas.cpp
trunk/src/gui/widgets/canvas.hpp
Modified: trunk/src/gui/widgets/canvas.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/canvas.cpp?rev=24443&r1=24442&r2=24443&view=diff
==============================================================================
--- trunk/src/gui/widgets/canvas.cpp (original)
+++ trunk/src/gui/widgets/canvas.cpp Sun Mar 9 15:53:23 2008
@@ -18,6 +18,7 @@
#include "gui/widgets/canvas.hpp"
#include "config.hpp"
+#include "image.hpp"
#include "log.hpp"
#include "serialization/parser.hpp"
#include "variable.hpp"
@@ -131,6 +132,8 @@
shapes_.push_back(new tline(data));
} else if(type == "rectangle") {
shapes_.push_back(new trectangle(data));
+ } else if(type == "image") {
+ shapes_.push_back(new timage(data));
} else {
std::cerr << "Type of shape is unknown : " << type <<
'\n';
}
@@ -317,7 +320,7 @@
fill_colour(0)
{
/*WIKI
- * [rect]
+ * [rectangle]
* x, y = (int = 0), (int = 0) The top left corner of the rectangle.
* w = (int = 0) The width of the rectangle.
* h = (int = 0) The height of the rectangle.
@@ -332,7 +335,7 @@
* does nothing).
* debug = (string = "") Debug message to show upon creation
* this message is not stored.
- * [/line]
+ * [/rectangle]
*/
rect.x = lexical_cast_default<int>(cfg["x"]);
@@ -395,4 +398,33 @@
}
+
+tcanvas::timage::timage(const vconfig& cfg) :
+ src_clip_(),
+ dst_clip_(),
+ image_()
+{
+/*WIKI
+ * [image]
+ * name = (string) The name of the image.
+ * debug = (string = "") Debug message to show upon creation
+ * [/image]
+ */
+
+ image_.assign(image::get_image(image::locator(cfg["name"])));
+ src_clip_ = create_rect(0, 0, image_->w, image_->h);
+
+ const std::string& debug = (cfg["debug"]);
+ if(!debug.empty()) {
+ DBG_GUI << debug << '\n';
+ }
+
+}
+void tcanvas::timage::draw(surface& canvas)
+{
+ SDL_Rect src_clip = src_clip_;
+ SDL_Rect dst_clip = dst_clip_;
+ SDL_BlitSurface(image_, &src_clip, canvas, &dst_clip);
+}
+
} // namespace gui2
Modified: trunk/src/gui/widgets/canvas.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/canvas.hpp?rev=24443&r1=24442&r2=24443&view=diff
==============================================================================
--- trunk/src/gui/widgets/canvas.hpp (original)
+++ trunk/src/gui/widgets/canvas.hpp Sun Mar 9 15:53:23 2008
@@ -102,6 +102,19 @@
Uint32 fill_colour;
};
+ //! Definition of an image shape.
+ class timage : public tshape
+ {
+ public:
+ timage(const vconfig& cfg);
+
+ //! Implement shape::draw().
+ void draw(surface& canvas);
+ private:
+ SDL_Rect src_clip_;
+ SDL_Rect dst_clip_;
+ surface image_;
+ };
tcanvas();
tcanvas(const config& cfg);
@@ -137,4 +150,5 @@
} // namespace gui2
+
#endif
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits