-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtextview.hpp
141 lines (110 loc) · 4.5 KB
/
textview.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// SPDX-License-Identifier: GPL-3.0-or-later
//
// Copyright (c) 2016-2024 plan44.ch / Lukas Zeller, Zurich, Switzerland
//
// Author: Lukas Zeller <luz@plan44.ch>
//
// This file is part of p44lrgraphics.
//
// p44lrgraphics is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// p44lrgraphics is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with p44lrgraphics. If not, see <http://www.gnu.org/licenses/>.
//
#ifndef _p44lrgraphics_textview_hpp__
#define _p44lrgraphics_textview_hpp__
#include "p44lrg_common.hpp"
#include "coloreffectview.hpp"
#include "fonts.hpp"
namespace p44 {
class TextView : public ColorEffectView
{
typedef ColorEffectView inherited;
// text rendering
string mText; ///< internal representation of text
bool mCollapsed; ///< if not set, text view is reduced to zero width
int mTextSpacing; ///< pixels between characters
int mStretch; ///< pixel row repetitions
int mBolden; ///< how many shifted overlays
string mTextPixelData; ///< string of text column data (might be multiple bytes per columnt for fonts with dy>8)
LrgFontPtr mFont; ///< the font to use
bool mTextChanges;
public :
TextView();
virtual ~TextView();
static const char* staticTypeName() { return "text"; };
static P44View* newInstance() { return new TextView; };
virtual const char* getTypeName() const P44_OVERRIDE { return staticTypeName(); }
virtual void beginChanges() P44_OVERRIDE { inherited::beginChanges(); mTextChanges = false; }
virtual void finalizeChanges() P44_OVERRIDE;
void flagTextChange() { flagChange(mTextChanges); }
/// get font
const char* getFont() const { return mFont ? mFont->name() : nullptr; };
/// set font
/// @param aFontName name of the font to set
/// @return false if named font does not exist and font could not be changed
bool setFont(const char* aFontName);
/// @name trivial property getters/setters
/// @{
// - text
string getText() const { return mText; }
void setText(const string aVal) { mText = aVal; flagTextChange(); } ;
// - spacing
int getTextSpacing() const { return mTextSpacing; }
void setTextSpacing(int aVal) { mTextSpacing = aVal; flagTextChange(); }
// - effects
int getBolden() const { return mBolden; }
void setBolden(int aVal) { mBolden = aVal; flagTextChange(); }
int getStretch() const { return mStretch; }
void setStretch(int aVal) { mStretch = aVal; flagTextChange(); }
// - flags
bool getCollapsed() const { return mCollapsed; }
void setCollapsed(bool aVal) { mCollapsed = aVal; flagTextChange(); }
/// @}
/// clear contents of this view
virtual void clear() P44_OVERRIDE;
#if ENABLE_VIEWCONFIG && !ENABLE_P44SCRIPT
/// configure view from JSON
virtual ErrorPtr configureView(JsonObjectPtr aViewConfig) P44_OVERRIDE;
#endif
#if ENABLE_VIEWSTATUS && !ENABLE_P44SCRIPT
/// @return the current status of the view, in the same format as accepted by configure()
virtual JsonObjectPtr viewStatus() P44_OVERRIDE;
#endif // ENABLE_VIEWSTATUS
#if ENABLE_P44SCRIPT
/// @return ScriptObj representing this view
virtual P44Script::ScriptObjPtr newViewObj() P44_OVERRIDE;
#endif
/// get content color at aPt
virtual PixelColor contentColorAt(PixelPoint aPt) P44_OVERRIDE;
protected:
/// color effect params have changed
virtual void recalculateColoring() P44_OVERRIDE;
/// geometry has changed
virtual void geometryChanged(PixelRect aOldFrame, PixelRect aOldContent) P44_OVERRIDE;
private:
void renderText();
};
typedef boost::intrusive_ptr<TextView> TextViewPtr;
#if ENABLE_P44SCRIPT
namespace P44Script {
/// represents a TextView
class TextViewObj : public ColorEffectViewObj
{
typedef ColorEffectViewObj inherited;
public:
TextViewObj(P44ViewPtr aView);
TextViewPtr text() { return boost::static_pointer_cast<TextView>(inherited::view()); };
};
} // namespace P44Script
#endif // ENABLE_P44SCRIPT
} // namespace p44
#endif /* _p44lrgraphics_textview_hpp__ */