]> git.tdb.fi Git - libs/gltk.git/blob - source/graphic.h
Rework how widget ownership works in 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/objectloader.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::CollectionObjectLoader<Graphic, Resources>
21         {
22         public:
23                 Loader(Graphic &, Resources &);
24
25         private:
26                 void texture(const std::string &);
27                 void slice(unsigned, unsigned, unsigned, unsigned);
28                 void border();
29                 void shadow();
30         };
31
32 private:
33         Sides border;
34         Sides shadow;
35         const GL::Texture2D *texture;
36         Geometry slice;
37         bool repeat;
38
39 public:
40         Graphic();
41         const Sides &get_border() const { return border; }
42         const Sides &get_shadow() const { return shadow; }
43         const GL::Texture2D *get_texture() const { return texture; }
44         unsigned get_width() const  { return slice.w; }
45         unsigned get_height() const { return slice.h; }
46         void build(unsigned, unsigned, GL::PrimitiveBuilder &) const;
47 private:
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