702.3.1
by Michael Terry
add modelines and fix up some inconsistent tabbings |
1 |
// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
|
572.4.1
by Jay Taoko
* Added StaticCairoText files |
2 |
/*
|
572.5.2
by Jay Taoko
* Adding license to files |
3 |
* Copyright (C) 2010 Canonical Ltd
|
4 |
*
|
|
5 |
* This program is free software: you can redistribute it and/or modify
|
|
6 |
* it under the terms of the GNU General Public License version 3 as
|
|
7 |
* published by the Free Software Foundation.
|
|
8 |
*
|
|
9 |
* This program is distributed in the hope that it will be useful,
|
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12 |
* GNU General Public License for more details.
|
|
13 |
*
|
|
14 |
* You should have received a copy of the GNU General Public License
|
|
15 |
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16 |
*
|
|
17 |
* Authored by: Jay Taoko <jay.taoko@canonical.com>
|
|
572.4.1
by Jay Taoko
* Added StaticCairoText files |
18 |
* Authored by: Mirco Müller <mirco.mueller@canonical.com
|
19 |
*/
|
|
20 |
||
613.1.25
by Mirco Müller
make StaticCairoText use GtkSettings for pulling system-wide font-settings, removed unneeded SetFontWeight() & Co |
21 |
#include <gdk/gdk.h> |
22 |
#include <gtk/gtk.h> |
|
23 |
||
1489.1.4
by Andrea Azzarone
Uses <Nux/...> instead of "Nux/...". |
24 |
#include <Nux/Nux.h> |
25 |
#include <Nux/Layout.h> |
|
26 |
#include <Nux/HLayout.h> |
|
27 |
#include <Nux/VLayout.h> |
|
28 |
#include <Nux/Validator.h> |
|
1468.2.3
by Tim Penhey
And done. Now to see if it compiles. |
29 |
|
30 |
#include "CairoTexture.h" |
|
572.5.1
by Jay Taoko
* Added button value to mouse down/up/click events |
31 |
#include "StaticCairoText.h" |
572.4.1
by Jay Taoko
* Added StaticCairoText files |
32 |
|
1468.2.4
by Tim Penhey
Damn namespaces. |
33 |
using unity::texture_from_cairo_graphics; |
34 |
||
1185.1.2
by Tim Penhey
More color updates. |
35 |
// TODO: Tim Penhey 2011-05-16
|
36 |
// We shouldn't be pushing stuff into the nux namespace from the unity
|
|
37 |
// codebase, that is just rude.
|
|
572.4.1
by Jay Taoko
* Added StaticCairoText files |
38 |
namespace nux |
39 |
{
|
|
1420.3.1
by Alejandro Piñeiro
Adding some debug messages, StaticCairoText and enabled Dash |
40 |
NUX_IMPLEMENT_OBJECT_TYPE (StaticCairoText); |
41 |
||
1990.2.4
by Thomi Richards
Cleanups. |
42 |
StaticCairoText::StaticCairoText(std::string const& text, |
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
43 |
NUX_FILE_LINE_DECL) : |
44 |
View(NUX_FILE_LINE_PARAM), |
|
2262.2.1
by Thomi Richards
Fixed valgrind error about using uninitialised valies in an if statement. |
45 |
_cached_base_width(-1), |
46 |
_cached_base_height(-1), |
|
2034.1.1
by Andrea Azzarone
Use something like a baseline alignment for the category header. |
47 |
_baseline(0), |
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
48 |
_fontstring(NULL), |
49 |
_cairoGraphics(NULL), |
|
50 |
_texture2D(NULL), |
|
51 |
_lines(-2), |
|
52 |
_actual_lines(0) |
|
572.4.1
by Jay Taoko
* Added StaticCairoText files |
53 |
{
|
54 |
_textColor = Color(1.0f, 1.0f, 1.0f, 1.0f); |
|
1990.2.3
by Thomi Richards
SCT takes a std::string in it's ctor now. |
55 |
_text = text; |
572.4.1
by Jay Taoko
* Added StaticCairoText files |
56 |
_texture2D = 0; |
831.4.2
by Gord Allott
smooth scrolling ftw |
57 |
_need_new_extent_cache = true; |
871.4.2
by Neil Jagdish Patel
Fix crashing and properly unref textures |
58 |
_pre_layout_width = 0; |
59 |
_pre_layout_height = 0; |
|
572.4.1
by Jay Taoko
* Added StaticCairoText files |
60 |
|
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
61 |
SetMinimumSize(1, 1); |
743.7.3
by Gord Allott
EOD workings |
62 |
_ellipsize = NUX_ELLIPSIZE_END; |
63 |
_align = NUX_ALIGN_LEFT; |
|
976.4.2
by Neil Jagdish Patel
Add support for showing empty search/sections, global doesn't work yet |
64 |
_valign = NUX_ALIGN_TOP; |
743.7.4
by Gord Allott
latest work so i can get on desktop |
65 |
_fontstring = NULL; |
1255.8.4
by Jay Taoko
* Key navigation fixes |
66 |
|
67 |
_accept_key_nav_focus = false; |
|
1790.1.4
by Andrea Azzarone
Fixes. |
68 |
SetAcceptKeyNavFocusOnMouseDown(false); |
572.4.1
by Jay Taoko
* Added StaticCairoText files |
69 |
}
|
70 |
||
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
71 |
StaticCairoText::~StaticCairoText() |
572.4.1
by Jay Taoko
* Added StaticCairoText files |
72 |
{
|
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
73 |
GtkSettings* settings = gtk_settings_get_default(); // not ref'ed |
74 |
g_signal_handlers_disconnect_by_func(settings, |
|
75 |
(void*) &StaticCairoText::OnFontChanged, |
|
76 |
this); |
|
785.6.2
by Gord Allott
fixes to work around nuxs weird layout system |
77 |
if (_texture2D) |
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
78 |
_texture2D->UnReference(); |
785.6.2
by Gord Allott
fixes to work around nuxs weird layout system |
79 |
|
80 |
if (_fontstring) |
|
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
81 |
g_free(_fontstring); |
572.4.1
by Jay Taoko
* Added StaticCairoText files |
82 |
}
|
572.1.45
by Sam Spilsbury
1. Use internal StaticCairoText |
83 |
|
743.7.3
by Gord Allott
EOD workings |
84 |
void
|
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
85 |
StaticCairoText::SetTextEllipsize(EllipsizeState state) |
743.7.3
by Gord Allott
EOD workings |
86 |
{
|
87 |
_ellipsize = state; |
|
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
88 |
NeedRedraw(); |
743.7.3
by Gord Allott
EOD workings |
89 |
}
|
90 |
||
91 |
void
|
|
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
92 |
StaticCairoText::SetTextAlignment(AlignState state) |
743.7.3
by Gord Allott
EOD workings |
93 |
{
|
94 |
_align = state; |
|
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
95 |
NeedRedraw(); |
743.7.3
by Gord Allott
EOD workings |
96 |
}
|
97 |
||
976.4.2
by Neil Jagdish Patel
Add support for showing empty search/sections, global doesn't work yet |
98 |
void
|
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
99 |
StaticCairoText::SetTextVerticalAlignment(AlignState state) |
976.4.2
by Neil Jagdish Patel
Add support for showing empty search/sections, global doesn't work yet |
100 |
{
|
101 |
_valign = state; |
|
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
102 |
QueueDraw(); |
976.4.2
by Neil Jagdish Patel
Add support for showing empty search/sections, global doesn't work yet |
103 |
}
|
104 |
||
1037.2.5
by Neil Jagdish Patel
Add support for a horizontal result tile in the dash |
105 |
void
|
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
106 |
StaticCairoText::SetLines(int lines) |
1037.2.5
by Neil Jagdish Patel
Add support for a horizontal result tile in the dash |
107 |
{
|
108 |
_lines = lines; |
|
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
109 |
UpdateTexture(); |
110 |
QueueDraw(); |
|
1037.2.5
by Neil Jagdish Patel
Add support for a horizontal result tile in the dash |
111 |
}
|
112 |
||
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
113 |
void StaticCairoText::PreLayoutManagement() |
572.4.1
by Jay Taoko
* Added StaticCairoText files |
114 |
{
|
743.3.1
by Michael Terry
watch for font changes and update tooltip appropriately |
115 |
int textWidth = 0; |
116 |
int textHeight = 0; |
|
894.3.1
by Gord Allott
erm, bunch of stuff. support for keynav, woo |
117 |
|
831.4.2
by Gord Allott
smooth scrolling ftw |
118 |
textWidth = _cached_extent_width; |
119 |
textHeight = _cached_extent_height; |
|
572.4.1
by Jay Taoko
* Added StaticCairoText files |
120 |
|
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
121 |
_pre_layout_width = GetBaseWidth(); |
122 |
_pre_layout_height = GetBaseHeight(); |
|
123 |
||
124 |
SetBaseSize(textWidth, textHeight); |
|
125 |
||
126 |
if ((_texture2D == 0)) |
|
572.1.45
by Sam Spilsbury
1. Use internal StaticCairoText |
127 |
{
|
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
128 |
GtkSettings* settings = gtk_settings_get_default(); // not ref'ed |
129 |
g_signal_connect(settings, "notify::gtk-font-name", |
|
130 |
(GCallback) &StaticCairoText::OnFontChanged, this); |
|
131 |
g_signal_connect(settings, "notify::gtk-xft-dpi", |
|
132 |
(GCallback) &StaticCairoText::OnFontChanged, this); |
|
743.3.1
by Michael Terry
watch for font changes and update tooltip appropriately |
133 |
|
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
134 |
UpdateTexture(); |
572.4.1
by Jay Taoko
* Added StaticCairoText files |
135 |
}
|
136 |
||
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
137 |
View::PreLayoutManagement(); |
572.4.1
by Jay Taoko
* Added StaticCairoText files |
138 |
}
|
139 |
||
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
140 |
long StaticCairoText::PostLayoutManagement(long layoutResult) |
572.4.1
by Jay Taoko
* Added StaticCairoText files |
141 |
{
|
142 |
// long result = View::PostLayoutManagement (layoutResult);
|
|
143 |
||
144 |
long result = 0; |
|
145 |
||
146 |
int w = GetBaseWidth(); |
|
147 |
int h = GetBaseHeight(); |
|
148 |
||
149 |
if (_pre_layout_width < w) |
|
150 |
result |= eLargerWidth; |
|
151 |
else if (_pre_layout_width > w) |
|
152 |
result |= eSmallerWidth; |
|
153 |
else
|
|
154 |
result |= eCompliantWidth; |
|
155 |
||
156 |
if (_pre_layout_height < h) |
|
157 |
result |= eLargerHeight; |
|
158 |
else if (_pre_layout_height > h) |
|
159 |
result |= eSmallerHeight; |
|
160 |
else
|
|
161 |
result |= eCompliantHeight; |
|
162 |
||
163 |
return result; |
|
164 |
}
|
|
165 |
||
166 |
void
|
|
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
167 |
StaticCairoText::Draw(GraphicsEngine& gfxContext, |
168 |
bool forceDraw) |
|
572.4.1
by Jay Taoko
* Added StaticCairoText files |
169 |
{
|
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
170 |
Geometry base = GetGeometry(); |
572.4.1
by Jay Taoko
* Added StaticCairoText files |
171 |
|
1885.4.9
by Marco Trevisan (Treviño)
StaticCairoText: update the cached texture if the base geometry has changed |
172 |
if (!_texture2D || _cached_base_width != base.width || _cached_base_height != base.height) |
173 |
{
|
|
174 |
_cached_base_width = base.width; |
|
175 |
_cached_base_height = base.height; |
|
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
176 |
UpdateTexture(); |
1885.4.9
by Marco Trevisan (Treviño)
StaticCairoText: update the cached texture if the base geometry has changed |
177 |
}
|
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
178 |
|
179 |
gfxContext.PushClippingRectangle(base); |
|
180 |
||
181 |
gPainter.PaintBackground(gfxContext, base); |
|
894.1.9
by Neil Jagdish Patel
Lots more clean up and first bits of making PlacesResultsController use the new stuff |
182 |
|
572.4.1
by Jay Taoko
* Added StaticCairoText files |
183 |
TexCoordXForm texxform; |
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
184 |
texxform.SetWrap(TEXWRAP_REPEAT, TEXWRAP_REPEAT); |
185 |
texxform.SetTexCoordType(TexCoordXForm::OFFSET_COORD); |
|
894.3.1
by Gord Allott
erm, bunch of stuff. support for keynav, woo |
186 |
|
1722.1.1
by Jay Taoko
* Removed custom nux type: t_u32 |
187 |
unsigned int alpha = 0, src = 0, dest = 0; |
572.4.1
by Jay Taoko
* Added StaticCairoText files |
188 |
|
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
189 |
gfxContext.GetRenderStates().GetBlend(alpha, src, dest); |
190 |
gfxContext.GetRenderStates().SetBlend(true, GL_ONE, GL_ONE_MINUS_SRC_ALPHA); |
|
572.4.1
by Jay Taoko
* Added StaticCairoText files |
191 |
|
1185.1.2
by Tim Penhey
More color updates. |
192 |
Color col = color::Black; |
193 |
col.alpha = 0; |
|
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
194 |
gfxContext.QRP_Color(base.x, |
195 |
base.y, |
|
871.4.26
by Neil Jagdish Patel
[merge] trunk and lots of other fixes of mine |
196 |
base.width, |
197 |
base.height, |
|
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
198 |
col); |
199 |
||
200 |
gfxContext.QRP_1Tex(base.x, |
|
201 |
base.y + ((base.height - _cached_extent_height) / 2), |
|
202 |
base.width, |
|
203 |
base.height, |
|
204 |
_texture2D->GetDeviceTexture(), |
|
205 |
texxform, |
|
206 |
_textColor); |
|
207 |
||
208 |
gfxContext.GetRenderStates().SetBlend(alpha, src, dest); |
|
209 |
||
210 |
gfxContext.PopClippingRectangle(); |
|
211 |
}
|
|
212 |
||
213 |
void
|
|
214 |
StaticCairoText::DrawContent(GraphicsEngine& gfxContext, |
|
215 |
bool forceDraw) |
|
216 |
{
|
|
217 |
// intentionally left empty
|
|
218 |
}
|
|
219 |
||
220 |
void
|
|
221 |
StaticCairoText::PostDraw(GraphicsEngine& gfxContext, |
|
222 |
bool forceDraw) |
|
223 |
{
|
|
224 |
// intentionally left empty
|
|
225 |
}
|
|
226 |
||
227 |
void
|
|
1990.2.2
by Thomi Richards
Removed NString from StaticCairoText, Tooltip and LauncherIcon classes. |
228 |
StaticCairoText::SetText(std::string const& text) |
572.4.1
by Jay Taoko
* Added StaticCairoText files |
229 |
{
|
230 |
if (_text != text) |
|
231 |
{
|
|
232 |
_text = text; |
|
831.4.2
by Gord Allott
smooth scrolling ftw |
233 |
_need_new_extent_cache = true; |
234 |
int width = 0; |
|
235 |
int height = 0; |
|
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
236 |
GetTextExtents(width, height); |
237 |
UpdateTexture(); |
|
238 |
sigTextChanged.emit(this); |
|
572.4.1
by Jay Taoko
* Added StaticCairoText files |
239 |
}
|
240 |
}
|
|
241 |
||
1990.2.2
by Thomi Richards
Removed NString from StaticCairoText, Tooltip and LauncherIcon classes. |
242 |
std::string |
243 |
StaticCairoText::GetText() const |
|
1420.3.1
by Alejandro Piñeiro
Adding some debug messages, StaticCairoText and enabled Dash |
244 |
{
|
245 |
return _text; |
|
246 |
}
|
|
247 |
||
2370.1.4
by Andrea Azzarone
Update the design of the hud button text. Use a full opacity for the highlighted text. |
248 |
nux::Color StaticCairoText::GetTextColor() const |
249 |
{
|
|
250 |
return _textColor; |
|
251 |
}
|
|
252 |
||
253 |
||
572.4.1
by Jay Taoko
* Added StaticCairoText files |
254 |
void
|
1885.4.25
by Marco Trevisan (Treviño)
StaticCairoText, Tooltip: using const& parameters... |
255 |
StaticCairoText::SetTextColor(Color const& textColor) |
572.4.1
by Jay Taoko
* Added StaticCairoText files |
256 |
{
|
257 |
if (_textColor != textColor) |
|
258 |
{
|
|
259 |
_textColor = textColor; |
|
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
260 |
UpdateTexture(); |
261 |
QueueDraw(); |
|
894.1.13
by Neil Jagdish Patel
Add support for expandable groups |
262 |
|
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
263 |
sigTextColorChanged.emit(this); |
572.4.1
by Jay Taoko
* Added StaticCairoText files |
264 |
}
|
265 |
}
|
|
266 |
||
743.7.4
by Gord Allott
latest work so i can get on desktop |
267 |
void
|
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
268 |
StaticCairoText::SetFont(const char* fontstring) |
743.7.4
by Gord Allott
latest work so i can get on desktop |
269 |
{
|
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
270 |
g_free(_fontstring); |
271 |
_fontstring = g_strdup(fontstring); |
|
831.4.2
by Gord Allott
smooth scrolling ftw |
272 |
_need_new_extent_cache = true; |
273 |
int width = 0; |
|
274 |
int height = 0; |
|
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
275 |
GetTextExtents(width, height); |
276 |
SetMinimumHeight(height); |
|
277 |
NeedRedraw(); |
|
278 |
sigFontChanged.emit(this); |
|
743.7.4
by Gord Allott
latest work so i can get on desktop |
279 |
}
|
280 |
||
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
281 |
int
|
282 |
StaticCairoText::GetLineCount() |
|
1065.1.8
by Neil Jagdish Patel
Horizontal renderer rendering issues |
283 |
{
|
284 |
return _actual_lines; |
|
285 |
}
|
|
743.7.4
by Gord Allott
latest work so i can get on desktop |
286 |
|
2034.1.1
by Andrea Azzarone
Use something like a baseline alignment for the category header. |
287 |
int StaticCairoText::GetBaseline() const |
288 |
{
|
|
289 |
return _baseline; |
|
290 |
}
|
|
291 |
||
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
292 |
void StaticCairoText::GetTextExtents(int& width, int& height) |
572.4.1
by Jay Taoko
* Added StaticCairoText files |
293 |
{
|
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
294 |
GtkSettings* settings = gtk_settings_get_default(); // not ref'ed |
613.1.25
by Mirco Müller
make StaticCairoText use GtkSettings for pulling system-wide font-settings, removed unneeded SetFontWeight() & Co |
295 |
gchar* fontName = NULL; |
296 |
||
743.7.4
by Gord Allott
latest work so i can get on desktop |
297 |
if (_fontstring == NULL) |
298 |
{
|
|
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
299 |
g_object_get(settings, "gtk-font-name", &fontName, NULL); |
743.7.4
by Gord Allott
latest work so i can get on desktop |
300 |
}
|
301 |
else
|
|
302 |
{
|
|
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
303 |
fontName = g_strdup(_fontstring); |
743.7.4
by Gord Allott
latest work so i can get on desktop |
304 |
}
|
305 |
||
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
306 |
GetTextExtents(fontName, width, height); |
307 |
g_free(fontName); |
|
572.4.1
by Jay Taoko
* Added StaticCairoText files |
308 |
}
|
309 |
||
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
310 |
void StaticCairoText::GetTextExtents(const TCHAR* font, |
311 |
int& width, |
|
312 |
int& height) |
|
572.4.1
by Jay Taoko
* Added StaticCairoText files |
313 |
{
|
314 |
cairo_surface_t* surface = NULL; |
|
315 |
cairo_t* cr = NULL; |
|
316 |
PangoLayout* layout = NULL; |
|
317 |
PangoFontDescription* desc = NULL; |
|
318 |
PangoContext* pangoCtx = NULL; |
|
2034.4.1
by Andrea Azzarone
Update the dash font settings. |
319 |
PangoRectangle inkRect = {0, 0, 0, 0}; |
572.4.1
by Jay Taoko
* Added StaticCairoText files |
320 |
PangoRectangle logRect = {0, 0, 0, 0}; |
613.1.25
by Mirco Müller
make StaticCairoText use GtkSettings for pulling system-wide font-settings, removed unneeded SetFontWeight() & Co |
321 |
int dpi = 0; |
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
322 |
GdkScreen* screen = gdk_screen_get_default(); // is not ref'ed |
323 |
GtkSettings* settings = gtk_settings_get_default(); // is not ref'ed |
|
572.4.1
by Jay Taoko
* Added StaticCairoText files |
324 |
|
325 |
// sanity check
|
|
326 |
if (!font) |
|
327 |
return; |
|
328 |
||
1311.2.15
by Tim Penhey
Simpler boolean |
329 |
if (!_need_new_extent_cache) |
831.4.2
by Gord Allott
smooth scrolling ftw |
330 |
{
|
331 |
width = _cached_extent_width; |
|
332 |
height = _cached_extent_height; |
|
333 |
return; |
|
334 |
}
|
|
894.3.1
by Gord Allott
erm, bunch of stuff. support for keynav, woo |
335 |
|
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
336 |
int maxwidth = GetMaximumWidth(); |
743.7.3
by Gord Allott
EOD workings |
337 |
|
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
338 |
surface = cairo_image_surface_create(CAIRO_FORMAT_A1, 1, 1); |
339 |
cr = cairo_create(surface); |
|
340 |
cairo_set_font_options(cr, gdk_screen_get_font_options(screen)); |
|
1990.2.2
by Thomi Richards
Removed NString from StaticCairoText, Tooltip and LauncherIcon classes. |
341 |
|
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
342 |
layout = pango_cairo_create_layout(cr); |
343 |
desc = pango_font_description_from_string(font); |
|
344 |
pango_layout_set_font_description(layout, desc); |
|
345 |
pango_layout_set_wrap(layout, PANGO_WRAP_WORD_CHAR); |
|
743.7.3
by Gord Allott
EOD workings |
346 |
|
347 |
if (_ellipsize == NUX_ELLIPSIZE_START) |
|
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
348 |
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_START); |
743.7.3
by Gord Allott
EOD workings |
349 |
else if (_ellipsize == NUX_ELLIPSIZE_MIDDLE) |
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
350 |
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_MIDDLE); |
743.7.3
by Gord Allott
EOD workings |
351 |
else if (_ellipsize == NUX_ELLIPSIZE_END) |
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
352 |
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END); |
743.7.3
by Gord Allott
EOD workings |
353 |
else
|
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
354 |
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_NONE); |
743.7.3
by Gord Allott
EOD workings |
355 |
|
356 |
if (_align == NUX_ALIGN_LEFT) |
|
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
357 |
pango_layout_set_alignment(layout, PANGO_ALIGN_LEFT); |
743.7.3
by Gord Allott
EOD workings |
358 |
else if (_align == NUX_ALIGN_CENTRE) |
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
359 |
pango_layout_set_alignment(layout, PANGO_ALIGN_CENTER); |
743.7.3
by Gord Allott
EOD workings |
360 |
else
|
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
361 |
pango_layout_set_alignment(layout, PANGO_ALIGN_RIGHT); |
362 |
||
1990.2.2
by Thomi Richards
Removed NString from StaticCairoText, Tooltip and LauncherIcon classes. |
363 |
pango_layout_set_markup(layout, _text.c_str(), -1); |
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
364 |
pango_layout_set_height(layout, _lines); |
365 |
pango_layout_set_width(layout, maxwidth * PANGO_SCALE); |
|
366 |
||
367 |
pangoCtx = pango_layout_get_context(layout); // is not ref'ed |
|
368 |
pango_cairo_context_set_font_options(pangoCtx, |
|
369 |
gdk_screen_get_font_options(screen)); |
|
370 |
g_object_get(settings, "gtk-xft-dpi", &dpi, NULL); |
|
613.1.25
by Mirco Müller
make StaticCairoText use GtkSettings for pulling system-wide font-settings, removed unneeded SetFontWeight() & Co |
371 |
if (dpi == -1) |
372 |
{
|
|
373 |
// use some default DPI-value
|
|
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
374 |
pango_cairo_context_set_resolution(pangoCtx, 96.0f); |
613.1.25
by Mirco Müller
make StaticCairoText use GtkSettings for pulling system-wide font-settings, removed unneeded SetFontWeight() & Co |
375 |
}
|
376 |
else
|
|
377 |
{
|
|
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
378 |
pango_cairo_context_set_resolution(pangoCtx, |
379 |
(float) dpi / (float) PANGO_SCALE); |
|
613.1.25
by Mirco Müller
make StaticCairoText use GtkSettings for pulling system-wide font-settings, removed unneeded SetFontWeight() & Co |
380 |
}
|
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
381 |
pango_layout_context_changed(layout); |
2034.4.1
by Andrea Azzarone
Update the dash font settings. |
382 |
pango_layout_get_extents(layout, &inkRect, &logRect); |
383 |
||
384 |
// logRect has some issues using italic style
|
|
385 |
if (inkRect.x + inkRect.width > logRect.x + logRect.width) |
|
2280.2.1
by Andrea Azzarone
Fix bug #830801. |
386 |
width = std::ceil(static_cast<float>(inkRect.x + inkRect.width - logRect.x) / PANGO_SCALE); |
2034.4.1
by Andrea Azzarone
Update the dash font settings. |
387 |
else
|
2280.2.1
by Andrea Azzarone
Fix bug #830801. |
388 |
width = std::ceil(static_cast<float>(logRect.width) / PANGO_SCALE); |
2034.4.1
by Andrea Azzarone
Update the dash font settings. |
389 |
|
2280.2.1
by Andrea Azzarone
Fix bug #830801. |
390 |
height = std::ceil(static_cast<float>(logRect.height) / PANGO_SCALE); |
831.4.2
by Gord Allott
smooth scrolling ftw |
391 |
_cached_extent_height = height; |
392 |
_cached_extent_width = width; |
|
2034.1.1
by Andrea Azzarone
Use something like a baseline alignment for the category header. |
393 |
_baseline = pango_layout_get_baseline(layout) / PANGO_SCALE; |
572.4.1
by Jay Taoko
* Added StaticCairoText files |
394 |
|
395 |
// clean up
|
|
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
396 |
pango_font_description_free(desc); |
397 |
g_object_unref(layout); |
|
398 |
cairo_destroy(cr); |
|
399 |
cairo_surface_destroy(surface); |
|
572.4.1
by Jay Taoko
* Added StaticCairoText files |
400 |
}
|
401 |
||
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
402 |
void StaticCairoText::DrawText(cairo_t* cr, |
403 |
int width, |
|
404 |
int height, |
|
405 |
Color color) |
|
572.4.1
by Jay Taoko
* Added StaticCairoText files |
406 |
{
|
407 |
PangoLayout* layout = NULL; |
|
408 |
PangoFontDescription* desc = NULL; |
|
409 |
PangoContext* pangoCtx = NULL; |
|
613.1.25
by Mirco Müller
make StaticCairoText use GtkSettings for pulling system-wide font-settings, removed unneeded SetFontWeight() & Co |
410 |
int dpi = 0; |
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
411 |
GdkScreen* screen = gdk_screen_get_default(); // not ref'ed |
412 |
GtkSettings* settings = gtk_settings_get_default(); // not ref'ed |
|
613.1.25
by Mirco Müller
make StaticCairoText use GtkSettings for pulling system-wide font-settings, removed unneeded SetFontWeight() & Co |
413 |
gchar* fontName = NULL; |
414 |
||
743.7.4
by Gord Allott
latest work so i can get on desktop |
415 |
if (_fontstring == NULL) |
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
416 |
g_object_get(settings, "gtk-font-name", &fontName, NULL); |
743.7.4
by Gord Allott
latest work so i can get on desktop |
417 |
else
|
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
418 |
fontName = g_strdup(_fontstring); |
419 |
||
420 |
cairo_set_font_options(cr, gdk_screen_get_font_options(screen)); |
|
421 |
layout = pango_cairo_create_layout(cr); |
|
422 |
desc = pango_font_description_from_string(fontName); |
|
423 |
||
424 |
pango_layout_set_font_description(layout, desc); |
|
425 |
pango_layout_set_wrap(layout, PANGO_WRAP_WORD_CHAR); |
|
743.7.3
by Gord Allott
EOD workings |
426 |
|
427 |
if (_ellipsize == NUX_ELLIPSIZE_START) |
|
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
428 |
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_START); |
743.7.3
by Gord Allott
EOD workings |
429 |
else if (_ellipsize == NUX_ELLIPSIZE_MIDDLE) |
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
430 |
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_MIDDLE); |
743.7.3
by Gord Allott
EOD workings |
431 |
else if (_ellipsize == NUX_ELLIPSIZE_END) |
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
432 |
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END); |
743.7.3
by Gord Allott
EOD workings |
433 |
else
|
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
434 |
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_NONE); |
743.7.3
by Gord Allott
EOD workings |
435 |
|
436 |
if (_align == NUX_ALIGN_LEFT) |
|
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
437 |
pango_layout_set_alignment(layout, PANGO_ALIGN_LEFT); |
743.7.3
by Gord Allott
EOD workings |
438 |
else if (_align == NUX_ALIGN_CENTRE) |
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
439 |
pango_layout_set_alignment(layout, PANGO_ALIGN_CENTER); |
743.7.3
by Gord Allott
EOD workings |
440 |
else
|
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
441 |
pango_layout_set_alignment(layout, PANGO_ALIGN_RIGHT); |
442 |
||
1990.2.2
by Thomi Richards
Removed NString from StaticCairoText, Tooltip and LauncherIcon classes. |
443 |
pango_layout_set_markup(layout, _text.c_str(), -1); |
1885.4.8
by Marco Trevisan (Treviño)
StaticCairoText: make the pango_layout to use all the available space when requested |
444 |
pango_layout_set_width(layout, width * PANGO_SCALE); |
445 |
pango_layout_set_height(layout, height * PANGO_SCALE); |
|
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
446 |
|
447 |
pango_layout_set_height(layout, _lines); |
|
448 |
pangoCtx = pango_layout_get_context(layout); // is not ref'ed |
|
449 |
pango_cairo_context_set_font_options(pangoCtx, |
|
450 |
gdk_screen_get_font_options(screen)); |
|
451 |
g_object_get(settings, "gtk-xft-dpi", &dpi, NULL); |
|
613.1.25
by Mirco Müller
make StaticCairoText use GtkSettings for pulling system-wide font-settings, removed unneeded SetFontWeight() & Co |
452 |
if (dpi == -1) |
453 |
{
|
|
454 |
// use some default DPI-value
|
|
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
455 |
pango_cairo_context_set_resolution(pangoCtx, 96.0f); |
613.1.25
by Mirco Müller
make StaticCairoText use GtkSettings for pulling system-wide font-settings, removed unneeded SetFontWeight() & Co |
456 |
}
|
457 |
else
|
|
458 |
{
|
|
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
459 |
pango_cairo_context_set_resolution(pangoCtx, |
460 |
(float) dpi / (float) PANGO_SCALE); |
|
613.1.25
by Mirco Müller
make StaticCairoText use GtkSettings for pulling system-wide font-settings, removed unneeded SetFontWeight() & Co |
461 |
}
|
572.4.1
by Jay Taoko
* Added StaticCairoText files |
462 |
|
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
463 |
cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR); |
464 |
cairo_paint(cr); |
|
465 |
||
466 |
cairo_set_operator(cr, CAIRO_OPERATOR_OVER); |
|
467 |
cairo_set_source_rgba(cr, color.red, color.green, color.blue, color.alpha); |
|
468 |
||
469 |
pango_layout_context_changed(layout); |
|
470 |
||
471 |
cairo_move_to(cr, 0.0f, 0.0f); |
|
472 |
pango_cairo_show_layout(cr, layout); |
|
473 |
||
474 |
_actual_lines = pango_layout_get_line_count(layout); |
|
1065.1.8
by Neil Jagdish Patel
Horizontal renderer rendering issues |
475 |
|
572.4.1
by Jay Taoko
* Added StaticCairoText files |
476 |
// clean up
|
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
477 |
pango_font_description_free(desc); |
478 |
g_object_unref(layout); |
|
479 |
g_free(fontName); |
|
572.4.1
by Jay Taoko
* Added StaticCairoText files |
480 |
}
|
481 |
||
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
482 |
void StaticCairoText::UpdateTexture() |
572.4.1
by Jay Taoko
* Added StaticCairoText files |
483 |
{
|
484 |
int width = 0; |
|
485 |
int height = 0; |
|
486 |
GetTextExtents(width, height); |
|
487 |
SetBaseSize(width, height); |
|
488 |
||
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
489 |
_cairoGraphics = new CairoGraphics(CAIRO_FORMAT_ARGB32, |
490 |
GetBaseWidth(), |
|
491 |
GetBaseHeight()); |
|
492 |
cairo_t* cr = cairo_reference(_cairoGraphics->GetContext()); |
|
493 |
||
494 |
DrawText(cr, GetBaseWidth(), GetBaseHeight(), _textColor); |
|
495 |
||
496 |
cairo_destroy(cr); |
|
497 |
||
572.4.1
by Jay Taoko
* Added StaticCairoText files |
498 |
// NTexture2D is the high level representation of an image that is backed by
|
499 |
// an actual opengl texture.
|
|
500 |
||
501 |
if (_texture2D) |
|
853.5.9
by Gord Allott
connected to texture destruction in case of epic fail |
502 |
{
|
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
503 |
_texture2D->UnReference(); |
853.5.9
by Gord Allott
connected to texture destruction in case of epic fail |
504 |
}
|
894.3.1
by Gord Allott
erm, bunch of stuff. support for keynav, woo |
505 |
|
1468.2.3
by Tim Penhey
And done. Now to see if it compiles. |
506 |
_texture2D = texture_from_cairo_graphics(*_cairoGraphics); |
572.4.1
by Jay Taoko
* Added StaticCairoText files |
507 |
|
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
508 |
cairo_destroy(cr); |
785.6.2
by Gord Allott
fixes to work around nuxs weird layout system |
509 |
|
572.4.1
by Jay Taoko
* Added StaticCairoText files |
510 |
delete _cairoGraphics; |
511 |
}
|
|
512 |
||
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
513 |
void StaticCairoText::OnFontChanged(GObject* gobject, GParamSpec* pspec, |
514 |
gpointer data) |
|
743.3.1
by Michael Terry
watch for font changes and update tooltip appropriately |
515 |
{
|
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
516 |
StaticCairoText* self = (StaticCairoText*) data; |
831.4.2
by Gord Allott
smooth scrolling ftw |
517 |
self->_need_new_extent_cache = true; |
518 |
int width = 0; |
|
519 |
int height = 0; |
|
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
520 |
self->GetTextExtents(width, height); |
521 |
self->UpdateTexture(); |
|
522 |
self->sigFontChanged.emit(self); |
|
743.3.1
by Michael Terry
watch for font changes and update tooltip appropriately |
523 |
}
|
524 |
||
1255.8.4
by Jay Taoko
* Key navigation fixes |
525 |
//
|
526 |
// Key navigation
|
|
527 |
//
|
|
528 |
||
529 |
void
|
|
530 |
StaticCairoText::SetAcceptKeyNavFocus(bool accept) |
|
531 |
{
|
|
532 |
_accept_key_nav_focus = accept; |
|
533 |
}
|
|
534 |
||
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
535 |
bool
|
1255.8.4
by Jay Taoko
* Key navigation fixes |
536 |
StaticCairoText::AcceptKeyNavFocus() |
537 |
{
|
|
538 |
return _accept_key_nav_focus; |
|
539 |
}
|
|
540 |
||
572.1.45
by Sam Spilsbury
1. Use internal StaticCairoText |
541 |
}
|