]> git.tdb.fi Git - libs/gltk.git/blob - source/graphic.h
Support loading Buttons from datafiles
[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 class Graphic
14 {
15 public:
16         class Loader: public DataFile::Loader
17         {
18         private:
19                 Graphic &graph;
20                 Resources &res;
21
22         public:
23                 typedef Resources Collection;
24
25                 Loader(Graphic &, Resources &);
26                 Graphic &get_object() const { return graph; }
27         private:
28                 void texture(const std::string &);
29                 void slice(unsigned, unsigned, unsigned, unsigned);
30                 void border();
31                 void shadow();
32         };
33
34         Graphic();
35         const Sides &get_border() const { return border; }
36         const Sides &get_shadow() const { return shadow; }
37         const GL::Texture2D *get_texture() const { return texture; }
38         unsigned get_width() const  { return slice.w; }
39         unsigned get_height() const { return slice.h; }
40         void render(unsigned, unsigned) const;
41 private:
42         Sides border;
43         Sides shadow;
44         const GL::Texture2D *texture;
45         Geometry slice;
46         bool repeat;
47
48         void create_coords(float, float, float, float, float, std::vector<float> &) const;
49         void create_texcoords(float, float, float, float, float, std::vector<float> &) const;
50 };
51
52 } // namespace GLtk
53 } // namespace Msp
54
55 #endif