ClanLib  2.3.7
span_layout.h
Go to the documentation of this file.
1 /*
2 ** ClanLib SDK
3 ** Copyright (c) 1997-2011 The ClanLib Team
4 **
5 ** This software is provided 'as-is', without any express or implied
6 ** warranty. In no event will the authors be held liable for any damages
7 ** arising from the use of this software.
8 **
9 ** Permission is granted to anyone to use this software for any purpose,
10 ** including commercial applications, and to alter it and redistribute it
11 ** freely, subject to the following restrictions:
12 **
13 ** 1. The origin of this software must not be misrepresented; you must not
14 ** claim that you wrote the original software. If you use this software
15 ** in a product, an acknowledgment in the product documentation would be
16 ** appreciated but is not required.
17 ** 2. Altered source versions must be plainly marked as such, and must not be
18 ** misrepresented as being the original software.
19 ** 3. This notice may not be removed or altered from any source distribution.
20 **
21 ** Note: Some of the libraries ClanLib may link to may have additional
22 ** requirements or restrictions.
23 **
24 ** File Author(s):
25 **
26 ** Magnus Norddahl
27 */
28 
31 
32 #pragma once
33 
34 #include "../../Core/System/sharedptr.h"
35 #include "../../Core/Math/rect.h"
36 #include "../../Core/Math/size.h"
37 #include "color.h"
38 
39 class CL_Font;
40 class CL_GraphicContext;
41 class CL_Point;
42 class CL_Size;
43 class CL_SpanLayout_Impl;
44 class CL_Image;
45 class CL_SpanComponent;
46 
51 {
56 };
57 
62 {
63 public:
64  virtual ~CL_SpanComponent() { }
65 
69  virtual CL_Size get_size() const = 0;
70 
74  virtual void set_geometry(const CL_Rect &geometry) = 0;
75 };
76 
80 template<typename T>
82 {
83 public:
84 
88  CL_SpanComponentBinder(T *component)
89  : component(component)
90  {
91  }
92 
96  CL_Size get_size() const
97  {
98  return component->get_size();
99  }
100 
104  void set_geometry(const CL_Rect &geometry)
105  {
106  component->set_geometry(geometry);
107  }
108 
109 private:
110  T *component;
111 };
112 
117 {
120 public:
121  CL_SpanLayout();
122  ~CL_SpanLayout();
124 
126  {
128 
129  enum Type
130  {
137  } type;
138 
140  int offset;
141  };
142 
145 public:
147  void clear();
148 
155  void add_text(const CL_String &text, const CL_Font &font, const CL_Colorf &color = CL_Colorf::white, int id = -1);
156 
162  void add_image(const CL_Image &image, int baseline_offset = 0, int id = -1);
163 
164  template<typename T>
165 
171  void add_component(T *component, int baseline_offset = 0, int id = -1)
172  {
173  add_component_helper(new CL_SpanComponentBinder<T>(component), baseline_offset, id);
174  }
175 
180  void layout(CL_GraphicContext &gc, int max_width);
181 
185  void set_position(const CL_Point &pos);
186 
190  CL_Size get_size() const;
191 
195  std::vector<CL_Rect> get_rect_by_id(int id) const;
196 
197 
204  HitTestResult hit_test(CL_GraphicContext &gc, const CL_Point &pos);
205 
209  void draw_layout(CL_GraphicContext &gc);
210 
215  void draw_layout_ellipsis(CL_GraphicContext &gc, const CL_Rect &content_rect);
216 
218  void set_component_geometry();
219 
226 
232 
237  void set_selection_colors(const CL_Colorf &foreground, const CL_Colorf &background);
238 
240  void show_cursor();
241 
243  void hide_cursor();
244 
249 
253  void set_cursor_overwrite_mode(bool enable);
254 
258  void set_cursor_color(const CL_Colorf &color);
259 
264 
270  void set_align(CL_SpanAlign align);
271 
274 
277 
279 
282 private:
283 
289  void add_component_helper(CL_SpanComponent *component, int baseline_offset, int id);
290 
291  CL_SharedPtr<CL_SpanLayout_Impl> impl;
293 };