00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef __GUI_WIDGETS_CANVAS_HPP_INCLUDED__
00020 #define __GUI_WIDGETS_CANVAS_HPP_INCLUDED__
00021
00022 #include "formula_callable.hpp"
00023 #include "reference_counted_object.hpp"
00024 #include "sdl_utils.hpp"
00025 #include "tstring.hpp"
00026 #include "variant.hpp"
00027
00028 #include <vector>
00029
00030 class config;
00031 class surface;
00032
00033 namespace gui2 {
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044 class tcanvas
00045 {
00046 public:
00047
00048
00049
00050 class tshape : public reference_counted_object
00051 {
00052 public:
00053 virtual void draw(surface& canvas,
00054 const game_logic::map_formula_callable& variables) = 0;
00055
00056 virtual ~tshape() {}
00057 protected:
00058
00059
00060
00061 void put_pixel(ptrdiff_t start, Uint32 colour, unsigned w, unsigned x, unsigned y);
00062 void draw_line(surface& canvas, Uint32 colour,
00063 const unsigned x1, unsigned y1, const unsigned x2, unsigned y2);
00064
00065 };
00066
00067 typedef boost::intrusive_ptr<tshape> tshape_ptr;
00068 typedef boost::intrusive_ptr<const tshape> const_tshape_ptr;
00069
00070 tcanvas();
00071 tcanvas(const config& cfg);
00072
00073 void draw(const config& cfg);
00074 void draw(const bool force = false);
00075
00076 void set_width(const unsigned width) { w_ = width; set_dirty(); }
00077 unsigned get_width() const { return w_; }
00078
00079 void set_height(const unsigned height) { h_ = height; set_dirty(); }
00080 unsigned get_height() const { return h_; }
00081
00082 surface& surf() { return canvas_; }
00083
00084 void set_cfg(const config& cfg) { parse_cfg(cfg); }
00085
00086 void set_variable(const std::string& key, const variant& value)
00087 { variables_.add(key, value); }
00088
00089 private:
00090 void set_dirty(const bool dirty = true) { dirty_ = dirty; }
00091
00092 void parse_cfg(const config& cfg);
00093
00094 std::vector<tshape_ptr> shapes_;
00095
00096 unsigned w_;
00097 unsigned h_;
00098
00099
00100 surface canvas_;
00101
00102 game_logic::map_formula_callable variables_;
00103
00104 bool dirty_;
00105 };
00106
00107 }
00108
00109
00110 #endif