KJB
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gui_text_overlay.h
Go to the documentation of this file.
1 /* $Id: gui_text_overlay.h 18278 2014-11-25 01:42:10Z ksimek $ */
2 /* {{{=========================================================================== *
3  |
4  | Copyright (c) 1994-2011 by Kobus Barnard (author)
5  |
6  | Personal and educational use of this code is granted, provided that this
7  | header is kept intact, and that the authorship is not misrepresented, that
8  | its use is acknowledged in publications, and relevant papers are cited.
9  |
10  | For other use contact the author (kobus AT cs DOT arizona DOT edu).
11  |
12  | Please note that the code in this file has not necessarily been adequately
13  | tested. Naturally, there is no guarantee of performance, support, or fitness
14  | for any particular task. Nonetheless, I am interested in hearing about
15  | problems that you encounter.
16  |
17  | Author: Kyle Simek
18  * =========================================================================== }}}*/
19 
20 // vim: tabstop=4 shiftwidth=4 foldmethod=marker
21 
22 #ifndef GUI_CPP_GUI_TEXT_OVERLAY_H
23 #define GUI_CPP_GUI_TEXT_OVERLAY_H
24 
25 #ifdef KJB_HAVE_GLUT
26 
27 #include <string>
28 #include <gui_cpp/gui_overlay.h>
29 #include <boost/optional.hpp>
30 #include <m_cpp/m_vector_d.h>
31 
32 namespace kjb
33 {
34 namespace gui
35 {
36 
37 class Text_overlay : public Overlay
38 {
39 typedef Overlay Base;
40 
41 enum Vertical_alignment {valign_top, valign_center, valign_bottom};
42 enum Horizontal_alignment {halign_left, halign_center, halign_right};
43 
44 public:
45  Text_overlay(float x, float y, float width);
46 
47  void size(float width)
48  {
49  Base::set_size(width, HEIGHT);
50  }
51 
52  void background_color(float x, float y, float z, float a = 1.0)
53  {
54  bg_color_ = Vector4(x,y,z,a);
55  }
56 
57  void color(float x, float y, float z, float a = 1.0)
58  {
59  color_ = Vector4(x,y,z,a);
60  }
61 
62  void make_transparent()
63  {
64  bg_color_ = boost::none;
65  }
66 
67  void set(const std::string& str)
68  {
69  text_ = str;
70  }
71 
72  void align_left()
73  {
74  alignment_ = halign_left;
75  }
76 
77  void align_right()
78  {
79  alignment_ = halign_right;
80  }
81 
82  void align_center()
83  {
84  alignment_ = halign_center;
85  }
86 
87 // void vertical_align_top()
88 // {
89 // v_alignment_ = valign_top;
90 // }
91 //
92 // void vertical_align_center()
93 // {
94 // v_alignment_ = valign_center;
95 // }
96 //
97 // void vertical_align_bottom()
98 // {
99 // v_alignment_ = valign_bottom;
100 // }
101 //
102  virtual void render() const;
103 
104 private:
105  std::string text_;
106  Horizontal_alignment alignment_;
107  Vertical_alignment v_alignment_;
108  kjb::Vector4 color_;
109  boost::optional<kjb::Vector4> bg_color_;
110 
111  static void* FONT;
112  static const int CHAR_WIDTH = 8;
113  static const int CHAR_HEIGHT = 13;
114  static const int PADDING = 3;
115  static const int HEIGHT = 2 * PADDING + CHAR_HEIGHT;
116 
117 };
118 
119 
126 class Textarea_overlay : public Overlay
127 {
128 typedef Overlay Base;
129 
130 enum Vertical_alignment {valign_top, valign_center, valign_bottom};
131 enum Horizontal_alignment {halign_left, halign_center, halign_right};
132 
133 public:
134  Textarea_overlay(float x, float y, float width, float height) :
135  Base(x, y, width, height),
136  text_(""),
137  alignment_(halign_left),
138  v_alignment_(valign_bottom),
139  color_(0.0,0.0,0.0,1.0),
140  bg_color_()
141  {}
142 
143  void size(float width, float height)
144  {
145  Base::set_size(width, height);
146  }
147 
148  void background_color(float x, float y, float z, float a = 1.0)
149  {
150  bg_color_ = Vector4(x,y,z,a);
151  }
152 
153  void color(float x, float y, float z, float a = 1.0)
154  {
155  color_ = Vector4(x,y,z,a);
156  }
157 
158  void make_transparent()
159  {
160  bg_color_ = boost::none;
161  }
162 
163  void set(const std::string& str)
164  {
165  text_ = str;
166  }
167 
168  void align_left()
169  {
170  alignment_ = halign_left;
171  }
172 
173  void align_right()
174  {
175  alignment_ = halign_right;
176  }
177 
178  void align_center()
179  {
180  alignment_ = halign_center;
181  }
182 
183 // void vertical_align_top()
184 // {
185 // v_alignment_ = valign_top;
186 // }
187 //
188 // void vertical_align_center()
189 // {
190 // v_alignment_ = valign_center;
191 // }
192 //
193 // void vertical_align_bottom()
194 // {
195 // v_alignment_ = valign_bottom;
196 // }
197 //
198  virtual void render() const;
199 
200 
201 private:
202  std::string text_;
203  Horizontal_alignment alignment_;
204  Vertical_alignment v_alignment_;
205  kjb::Vector4 color_;
206  boost::optional<kjb::Vector4> bg_color_;
207 
208  static void* FONT;
209  static const int CHAR_WIDTH = 8;
210  static const int CHAR_HEIGHT = 13;
211  static const int PADDING = 3;
212  static const int LINE_HEIGHT = 2 * PADDING + CHAR_HEIGHT;
213 
214 };
215 } // namespace gui
216 } // namespace kjb
217 
218 #endif /* have_glut */
219 #endif
Vector_d< 4 > Vector4
Definition: gr_opengl.h:38
height
Definition: APPgetLargeConnectedEdges.m:33
x
Definition: APPgetLargeConnectedEdges.m:100
void render(const Cuboid &c)
Definition: psi_weighted_box.cpp:56
Definition: g_quaternion.h:37