Labyrinth
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
label.hpp
1 //////////////////////////////
2 //
3 // File: lxs/windowing/label.hpp
4 // Author: Maciej Kaminski
5 // E-mail: maciej.a.kaminski@gmail.com
6 // Website: maciejkaminski.pl
7 //
8 // File creation date: Nov 2 2012
9 // This file is part of Project Labyrinth
10 // This file is going to be released under terms of GNU GPL in near future
11 //
12 //////////////////////////////
13 
14 #ifndef __LXS_LABEL_WINDOW__
15 #define __LXS_LABEL_WINDOW__
16 #include "helper/opengl.h"
17 #include "helper/tr1.h"
18 #include <string>
19 #include "lxs/windowing/containerwindow.hpp"
20 namespace LxS
21 {
22  namespace CoreGraphics
23  {
24  class Font;
25  }
26  namespace Windowing
27  {
28  class Rectangle2D;
29  //! a text label
30  class Label: public Window
31  {
32  private:
33  // called by all variants of constructor;
34  void ConstructorCommon();
35  protected:
36  //! configured x coordinate (for movement handling)
37  float configured_x;
38  //! configured y coordinate (for movement handling)
39  float configured_y;
40  //! configured width (for movement handling)
41  float configured_w;
42  //! configured height (for movement handling)
43  float configured_h;
44  //! background
46  //! text configured
47  std::string text;
48  //! font size
49  float font_height;
50  //! font object
52  //! prepare text to be displayed
53  virtual void PrepareText();
54  //! configure background position
55  virtual void PositionBackground();
56  //! Text color - red
57  float r;
58  //! Text color - green
59  float g;
60  //! Text color - blue
61  float b;
62  //! background image path
63  std::string background;
64  public:
65  //! constructor
66  //! \param text text to be displayed
67  //! \param background path to background image
68  Label(const std::string & text, const std::string & background);
69  //! default constructor
70  Label();
71  ~Label();
72  //! \brief set color of font
73  //! \param _r red
74  //! \param _g green
75  //! \param _b blue
76  void SetFontColor(float _r, float _g, float _b)
77  {
78  r=_r;
79  g=_g;
80  b=_b;
81  PrepareText();
82  }
83  //! font size
84  void SetFontHeight(float h);
85  //! Set background of an label
86  void SetBackground(const std::string & bg) { background.assign(bg);}
87  void MovementHandler();// {PrepareText();}
88  void ResizeHandler()
89  {
90  if (GetWidth()!=configured_w
91  || GetHeight()!=configured_h)
92  PrepareText();
93  }
94  void UnloadResources() ;
95  //! set text to be displayed and formatted
96  void SetText(const std::string & t);
97  //! get label text
98  const std::string & GetText() {return text;}
99  void Initialize();
100  void Animate(float dt);
101  void Render(Rendermode mode);
102  unsigned long GetTexelsCount();
103  unsigned long GetFacesCount();
104  };
105  }
106 }
107 #endif