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