]> git.tdb.fi Git - libs/gltk.git/blob - source/graphic.h
Rework exceptions and use maputils
[libs/gltk.git] / source / graphic.h
1 #ifndef MSP_GLTK_GRAPHIC_H_
2 #define MSP_GLTK_GRAPHIC_H_
3
4 #include <msp/gl/texture2d.h>
5 #include <msp/datafile/loader.h>
6 #include "geometry.h"
7
8 namespace Msp {
9 namespace GLtk {
10
11 class Resources;
12
13 /**
14 Stores a single graphical element.  Graphics are used as parts of widgets.
15 */
16 class Graphic
17 {
18 public:
19         class Loader: public DataFile::Loader
20         {
21         private:
22                 Graphic &graph;
23                 Resources &res;
24
25         public:
26                 typedef Resources Collection;
27
28                 Loader(Graphic &, Resources &);
29                 Graphic &get_object() const { return graph; }
30         private:
31                 void texture(const std::string &);
32                 void slice(unsigned, unsigned, unsigned, unsigned);
33                 void border();
34                 void shadow();
35         };
36
37 private:
38         Sides border;
39         Sides shadow;
40         const GL::Texture2D *texture;
41         Geometry slice;
42         bool repeat;
43
44 public:
45         Graphic();
46         const Sides &get_border() const { return border; }
47         const Sides &get_shadow() const { return shadow; }
48         const GL::Texture2D *get_texture() const { return texture; }
49         unsigned get_width() const  { return slice.w; }
50         unsigned get_height() const { return slice.h; }
51         void render(unsigned, unsigned) const;
52 private:
53         void create_coords(float, float, float, float, float, std::vector<float> &) const;
54         void create_texcoords(float, float, float, float, float, std::vector<float> &) const;
55 };
56
57 } // namespace GLtk
58 } // namespace Msp
59
60 #endif