Label.h
1 /* Copyright (C) 2015 Marc Boris Duerner
2  Copyright (C) 2015 Laurentiu-Gheorghe Crisan
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Lesser General Public
6  License as published by the Free Software Foundation; either
7  version 2.1 of the License, or (at your option) any later version.
8 
9  As a special exception, you may use this file as part of a free
10  software library without restriction. Specifically, if other files
11  instantiate templates or use macros or inline functions from this
12  file, or you compile this file and link it with other files to
13  produce an executable, this file does not by itself cause the
14  resulting executable to be covered by the GNU General Public
15  License. This exception does not however invalidate any other
16  reasons why the executable file might be covered by the GNU Library
17  General Public License.
18 
19  This library is distributed in the hope that it will be useful,
20  but WITHOUT ANY WARRANTY; without even the implied warranty of
21  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22  Lesser General Public License for more details.
23 
24  You should have received a copy of the GNU Lesser General Public
25  License along with this library; if not, write to the Free Software
26  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
27  MA 02110-1301 USA
28 */
29 
30 #ifndef Pt_Forms_Label_H
31 #define Pt_Forms_Label_H
32 
33 #include <Pt/Forms/Control.h>
34 #include <Pt/Forms/Alignment.h>
35 #include <Pt/Forms/Adjustment.h>
36 #include <Pt/Forms/TextBlock.h>
37 #include <Pt/Forms/PixmapSurface.h>
38 #include <Pt/Forms/Icon.h>
39 #include <Pt/SmartPtr.h>
40 #include <Pt/String.h>
41 
42 namespace Pt {
43 
44 namespace Forms {
45 
46 class PT_FORMS_API Label : public Control
47 {
48  public:
49  typedef Control Base;
50 
51  public:
52  Label();
53 
54  virtual ~Label();
55 
56  Alignment alignment() const;
57 
58  void setAlignment(Alignment a);
59 
60  const Pt::String& text() const;
61 
62  void setText(const Pt::String& text);
63 
64  void setIcon(const Icon& icon, const Gfx::SizeF& iconSize);
65 
66  public:
67  const Gfx::Brush* background() const;
68 
69  void setBackground(const Gfx::Brush& b);
70 
71  const Gfx::Pen* contour() const;
72 
73  void setContour(const Gfx::Pen& p);
74 
75  const Gfx::Color& textColor() const;
76 
77  void setTextColor(const Gfx::Color& color);
78 
79  const Gfx::Font& font() const;
80 
81  void setFont(const Gfx::Font& font);
82 
83  void setFontSize(std::size_t size);
84 
85  void setFontWeight(Gfx::Font::Weight weight);
86 
87  void setFontSlant(Gfx::Font::Slant slant);
88 
89  void setRenderer(LabelRenderer* renderer);
90 
91  protected:
92  virtual Gfx::SizeF onMeasure(const SizePolicy& policy);
93 
94  virtual void onLayout(const Gfx::RectF& rect);
95 
96  virtual void onRescaleEvent(const RescaleEvent& ev);
97 
98  virtual void onResizeEvent(const ResizeEvent& ev);
99 
100  protected:
101  virtual void onConnect(Screen& screen);
102 
103  virtual void onInvalidate();
104 
105  virtual void onPaint(PaintSurface& surface,
106  const Gfx::RectF& rect);
107 
108  private:
109  Pixmap& getIconPixmap();
110 
111  Adjustment adjustment() const;
112 
113  void layoutText();
114 
115  void layoutImage();
116 
117  Gfx::Font getFont() const;
118 
119  private:
120  enum FontOverride : unsigned
121  {
122  OverrideSize = 0x01,
123  OverrideWeight = 0x02,
124  OverrideSlant = 0x04,
125  OverrideAll = 0xFF
126  };
127 
128  private:
129  Alignment _alignment;
130 
131  Pt::String _text;
132  Adjustment _adjustment;
133  TextBlock _textBlock;
134 
135  Icon _icon;
136  Gfx::PointF _iconPos;
137  Gfx::SizeF _iconSize;
138  bool _iconInvalid;
139 
140  FacetPtr<LabelRenderer> _renderer;
141  bool _hasRenderer;
142 
143  AutoPtr<Gfx::Brush> _background;
144  AutoPtr<Gfx::Pen> _contour;
145  AutoPtr<Gfx::Color> _textColor;
146  Gfx::Font _customFont;
147  unsigned _fontOverride;
148  std::size_t _styleGeneration;
149  bool _styleInvalid;
150 
151  Gfx::Pen _textPen;
152  Gfx::Pen _pen;
153  Gfx::Font _font;
154  Pixmap _pixmap;
155 };
156 
157 } // namespace
158 
159 } // namespace
160 
161 #endif
Unicode capable basic_string.
Definition: String.h:42