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