]> git.tdb.fi Git - libs/gltk.git/blob - source/graphic.h
Use nullptr instead of 0 for pointers
[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 #include "mspgltk_api.h"
9
10 namespace Msp {
11 namespace GLtk {
12
13 class Resources;
14
15 /**
16 Stores a single graphical element.  Graphics are used as parts of widgets.
17 */
18 class MSPGLTK_API Graphic
19 {
20 public:
21         class Loader: public DataFile::CollectionObjectLoader<Graphic, Resources>
22         {
23         public:
24                 Loader(Graphic &, Resources &);
25
26         private:
27                 void texture(const std::string &);
28                 void slice(unsigned, unsigned, unsigned, unsigned);
29                 void border();
30                 void shadow();
31         };
32
33 private:
34         Sides border;
35         Sides shadow;
36         const GL::Texture2D *texture = nullptr;
37         Geometry slice;
38         bool repeat = false;
39
40 public:
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