Nux

Merge lp:~unity-team/nux/nux.expose-statictext-texture into lp:nux/2.0

Proposed by Jay Taoko
Status: Merged
Approved by: Jay Taoko
Approved revision: 561
Merged at revision: 561
Proposed branch: lp:~unity-team/nux/nux.expose-statictext-texture
Merge into: lp:nux/2.0
Diff against target: 391 lines (+116/-52)
3 files modified
Nux/StaticText.cpp (+61/-29)
Nux/StaticText.h (+54/-22)
configure.ac (+1/-1)
To merge this branch: bzr merge lp:~unity-team/nux/nux.expose-statictext-texture
Reviewer Review Type Date Requested Status
Jason Smith (community) Approve
Review via email: mp+91840@code.launchpad.net

Description of the change

* Expose the StaticText device texture
* Code style fixes

To post a comment you must log in.
557. By Gord Allott

Adds very basic completion support to nux,
Essentially just adds text to the end of the TextEntry widget without any real logic as the logic we want for unity is
different from what we want for a toolkit

Basically just a visual change to allow hud to offer completion. Fixes: . Approved by Tim Penhey.

558. By Thomi Richards

Moved keycode definitions from unity into nux, where they belong.. Fixes: . Approved by Jay Taoko.

Revision history for this message
Jason Smith (jassmith) wrote :

Looks good

review: Approve
559. By Jason Smith

Improves dash startup times dramatically.. Fixes: . Approved by Thomi Richards.

560. By Jason Smith

Makes nux lazy load some of its less frequently use, yet more expensive objects. Fixes: . Approved by Jay Taoko, Thomi Richards.

561. By Jay Taoko

* Merged with Nux trunk

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Nux/StaticText.cpp'
2--- Nux/StaticText.cpp 2012-02-02 17:05:21 +0000
3+++ Nux/StaticText.cpp 2012-02-09 20:51:18 +0000
4@@ -1,3 +1,24 @@
5+/*
6+ * Copyright 2012 Inalogic® Inc.
7+ *
8+ * This program is free software: you can redistribute it and/or modify it
9+ * under the terms of the GNU Lesser General Public License, as
10+ * published by the Free Software Foundation; either version 2.1 or 3.0
11+ * of the License.
12+ *
13+ * This program is distributed in the hope that it will be useful, but
14+ * WITHOUT ANY WARRANTY; without even the implied warranties of
15+ * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
16+ * PURPOSE. See the applicable version of the GNU Lesser General Public
17+ * License for more details.
18+ *
19+ * You should have received a copy of both the GNU Lesser General Public
20+ * License along with this program. If not, see <http://www.gnu.org/licenses/>
21+ *
22+ * Authored by: Jay Taoko <jaytaoko@inalogic.com>
23+ *
24+ */
25+
26 #include "Nux.h"
27 #include "Layout.h"
28 #include "HLayout.h"
29@@ -29,13 +50,13 @@
30
31 NUX_IMPLEMENT_OBJECT_TYPE(StaticText);
32
33- StaticText::StaticText(const std::string &text, NUX_FILE_LINE_DECL)
34- : View(NUX_FILE_LINE_PARAM)
35+ StaticText::StaticText(const std::string& text, NUX_FILE_LINE_DECL)
36+ : View(NUX_FILE_LINE_PARAM)
37+ , text_width_(0)
38+ , text_height_(0)
39 {
40 padding_x_ = 0;
41 padding_y_ = 0;
42- text_width_ = 0;
43- text_height_ = 0;
44 update_text_rendering_ = true;
45 text_alignment_ = ALIGN_CENTER;
46
47@@ -64,7 +85,7 @@
48 dpy_ = 96.0f;
49 #endif
50
51- _size_match_text = true;
52+ size_match_text_ = true;
53 text_color_ = color::White;
54 clip_to_width_ = 0;
55
56@@ -164,12 +185,12 @@
57
58 void StaticText::SetSizeMatchText(bool size_match_text)
59 {
60- _size_match_text = size_match_text;
61+ size_match_text_ = size_match_text;
62 }
63
64 bool StaticText::GetSizeMatchText() const
65 {
66- return _size_match_text;
67+ return size_match_text_;
68 }
69
70 void StaticText::SetClipping(int clipping)
71@@ -291,7 +312,7 @@
72 return GetFontSize();
73 }
74
75- void StaticText::SetText(const std::string &text)
76+ void StaticText::SetText(const std::string& text)
77 {
78 if (text_ == text)
79 return;
80@@ -317,7 +338,7 @@
81 return text_;
82 }
83
84- void StaticText::SetTextColor(const Color &text_color)
85+ void StaticText::SetTextColor(const Color& text_color)
86 {
87 text_color_ = text_color;
88 }
89@@ -327,7 +348,7 @@
90 return text_color_;
91 }
92
93- void StaticText::SetFontName(const std::string &font_name)
94+ void StaticText::SetFontName(const std::string& font_name)
95 {
96 if (font_name_ == font_name)
97 return;
98@@ -356,7 +377,7 @@
99 return font_name_;
100 }
101
102- void StaticText::GetTextLayoutSize(int &width, int &height) const
103+ void StaticText::GetTextLayoutSize(int& width, int& height) const
104 {
105 if (text_ == "")
106 {
107@@ -386,6 +407,17 @@
108 return text_alignment_;
109 }
110
111+ ObjectPtr<nux::IOpenGLBaseTexture> StaticText::GetTextTexture()
112+ {
113+ if (update_text_rendering_)
114+ {
115+ // If the text rendering needs to be updated, do it here.
116+ UpdateTextRendering();
117+ }
118+
119+ return dw_texture_;
120+ }
121+
122 Size StaticText::GetTextSizeNoClip()
123 {
124 if (no_clip_size_.width == 0)
125@@ -397,10 +429,10 @@
126 Size StaticText::ComputeTextSize(bool assign, bool with_clipping)
127 {
128 HRESULT hr;
129- IDWriteFactory *pDWriteFactory = GetGraphicsDisplay()->GetDirectWriteFactory();
130+ IDWriteFactory* pDWriteFactory = GetGraphicsDisplay()->GetDirectWriteFactory();
131
132- ID2D1RenderTarget *pRT = NULL;
133- IDWriteTextFormat *pTextFormat = NULL;
134+ ID2D1RenderTarget* pRT = NULL;
135+ IDWriteTextFormat* pTextFormat = NULL;
136
137 hr = pDWriteFactory->CreateTextFormat(
138 ANSICHAR_TO_UNICHAR(font_name_.c_str()), // Font family name.
139@@ -489,12 +521,12 @@
140
141 HRESULT hr;
142
143- ID2D1Factory *pD2DFactory = GetGraphicsDisplay()->GetDirect2DFactory();
144- IDWriteFactory *pDWriteFactory = GetGraphicsDisplay()->GetDirectWriteFactory();
145- IWICImagingFactory *pWICFactory = GetGraphicsDisplay()->GetWICFactory();
146+ ID2D1Factory* pD2DFactory = GetGraphicsDisplay()->GetDirect2DFactory();
147+ IDWriteFactory* pDWriteFactory = GetGraphicsDisplay()->GetDirectWriteFactory();
148+ IWICImagingFactory* pWICFactory = GetGraphicsDisplay()->GetWICFactory();
149
150- ID2D1RenderTarget *pRT = NULL;
151- IDWriteTextFormat *pTextFormat = NULL;
152+ ID2D1RenderTarget* pRT = NULL;
153+ IDWriteTextFormat* pTextFormat = NULL;
154
155 hr = pDWriteFactory->CreateTextFormat(
156 ANSICHAR_TO_UNICHAR(font_name_.c_str()), // Font family name.
157@@ -534,7 +566,7 @@
158 &pTextLayout_ // The IDWriteTextLayout interface pointer.
159 );
160
161- IDWriteInlineObject *inlineObject = nullptr;
162+ IDWriteInlineObject* inlineObject = nullptr;
163 if (SUCCEEDED(hr))
164 {
165 pDWriteFactory->CreateEllipsisTrimmingSign(
166@@ -544,7 +576,7 @@
167 DWRITE_TRIMMING trimming = {DWRITE_TRIMMING_GRANULARITY_CHARACTER, 0, 0};
168 hr = pTextLayout_->SetTrimming(&trimming, inlineObject);
169
170- IWICBitmap *pWICBitmap = NULL;
171+ IWICBitmap* pWICBitmap = NULL;
172 if (SUCCEEDED(hr))
173 {
174 hr = pWICFactory->CreateBitmap(
175@@ -574,11 +606,11 @@
176 &pRT);
177 }
178
179- ID2D1SolidColorBrush *pBrush;
180+ ID2D1SolidColorBrush* pBrush;
181 hr = pRT->CreateSolidColorBrush(D2D1::ColorF(D2D1::ColorF(color.red, color.green, color.blue, color.alpha)), &pBrush);
182
183 // Create the text renderer
184- CustomTextRenderer *pTextRenderer_ = new (std::nothrow) CustomTextRenderer(
185+ CustomTextRenderer* pTextRenderer_ = new (std::nothrow) CustomTextRenderer(
186 pD2DFactory,
187 pRT,
188 pBrush,
189@@ -779,11 +811,11 @@
190
191 void StaticText::RasterizeText(void* cairo_context, Color color)
192 {
193- cairo_t *cairo_ctx = (cairo_t*) cairo_context;
194+ cairo_t* cairo_ctx = (cairo_t*) cairo_context;
195
196- PangoLayout *pango_layout = NULL;
197- PangoFontDescription *font_desc = NULL;
198- PangoContext *pango_ctx = NULL;
199+ PangoLayout* pango_layout = NULL;
200+ PangoFontDescription* font_desc = NULL;
201+ PangoContext* pango_ctx = NULL;
202 int dpi = 96;
203
204 // Create layout.
205@@ -848,7 +880,7 @@
206 }
207
208 cairo_graphics_ = new CairoGraphics(CAIRO_FORMAT_ARGB32, sz.width, sz.height);
209- cairo_t *cairo_ctx = cairo_graphics_->GetContext();
210+ cairo_t* cairo_ctx = cairo_graphics_->GetContext();
211 cairo_set_operator(cairo_ctx, CAIRO_OPERATOR_CLEAR);
212 cairo_paint(cairo_ctx);
213 cairo_set_operator(cairo_ctx, CAIRO_OPERATOR_OVER);
214@@ -860,7 +892,7 @@
215 // NTexture2D is the high level representation of an image that is backed by
216 // an actual opengl texture.
217
218- BaseTexture *rasterized_text_texture = NULL;
219+ BaseTexture* rasterized_text_texture = NULL;
220
221 rasterized_text_texture = GetGraphicsDisplay()->GetGpuDevice()->CreateSystemCapableTexture();
222 rasterized_text_texture->Update(bitmap);
223
224=== modified file 'Nux/StaticText.h'
225--- Nux/StaticText.h 2012-02-02 17:13:45 +0000
226+++ Nux/StaticText.h 2012-02-09 20:51:18 +0000
227@@ -1,19 +1,44 @@
228+/*
229+ * Copyright 2012 Inalogic® Inc.
230+ *
231+ * This program is free software: you can redistribute it and/or modify it
232+ * under the terms of the GNU Lesser General Public License, as
233+ * published by the Free Software Foundation; either version 2.1 or 3.0
234+ * of the License.
235+ *
236+ * This program is distributed in the hope that it will be useful, but
237+ * WITHOUT ANY WARRANTY; without even the implied warranties of
238+ * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
239+ * PURPOSE. See the applicable version of the GNU Lesser General Public
240+ * License for more details.
241+ *
242+ * You should have received a copy of both the GNU Lesser General Public
243+ * License along with this program. If not, see <http://www.gnu.org/licenses/>
244+ *
245+ * Authored by: Jay Taoko <jaytaoko@inalogic.com>
246+ *
247+ */
248+
249 #ifndef STATICTEXT_H
250 #define STATICTEXT_H
251
252 #include "NuxCore/Size.h"
253
254- #if defined(NUX_OS_WINDOWS)
255- #define NUX_STATIC_TEXT_USE_DIRECT_WRITE
256- #elif defined(NUX_OS_LINUX)
257- #define NUX_STATIC_TEXT_USE_CAIRO
258- #else
259- #error Not implemented.
260- #endif
261+#if defined(NUX_OS_WINDOWS)
262+ #define NUX_STATIC_TEXT_USE_DIRECT_WRITE
263+#elif defined(NUX_OS_LINUX)
264+ #define NUX_STATIC_TEXT_USE_CAIRO
265+#else
266+ #error Not implemented.
267+#endif
268
269 namespace nux
270 {
271 class CairoGraphics;
272+
273+ /*!
274+ A View that renders as static text.
275+ */
276 class StaticText: public View
277 {
278 NUX_DECLARE_OBJECT_TYPE(StaticText, View);
279@@ -35,7 +60,7 @@
280 ALIGN_RIGHT,
281 };
282
283- StaticText(const std::string &text, NUX_FILE_LINE_PROTO);
284+ StaticText(const std::string& text, NUX_FILE_LINE_PROTO);
285 virtual ~StaticText();
286
287 //! Set size of widget according to the text extent.
288@@ -48,7 +73,7 @@
289 bool GetSizeMatchText() const;
290
291 //! Set the text string.
292- void SetText(const std::string &text);
293+ void SetText(const std::string& text);
294
295 //! Get the text string.
296 std::string GetText() const;
297@@ -59,7 +84,7 @@
298
299 @param text_color The text color.
300 */
301- void SetTextColor(const Color &text_color);
302+ void SetTextColor(const Color& text_color);
303
304 //! Get text color.
305 /*!
306@@ -75,7 +100,7 @@
307
308 @param font_name The font name.
309 */
310- void SetFontName(const std::string &font_name);
311+ void SetFontName(const std::string& font_name);
312
313 //! Get the font name.
314 /*!
315@@ -100,7 +125,7 @@
316 int GetFontSize() const;
317 int GetTextPointSize() const; //deprecated: use GetFontSize
318
319- void GetTextLayoutSize(int &width, int &height) const;
320+ void GetTextLayoutSize(int& width, int& height) const;
321
322 Size GetTextLayoutSize() const;
323
324@@ -116,6 +141,15 @@
325 */
326 TextAlignment GetTextAlignment() const;
327
328+ //! Returns the device texture for the text.
329+ /*!
330+ Returns the device texture for the text. The device texture may be used \n
331+ for direct rendering.
332+
333+ @return A smart point for the device texture.
334+ */
335+ ObjectPtr<nux::IOpenGLBaseTexture> GetTextTexture();
336+
337 sigc::signal<void, StaticText*> text_changed;
338
339 protected:
340@@ -129,12 +163,9 @@
341 std::string text_;
342 Color text_color_;
343
344- BaseTexture *rasterized_text_texture_;
345-
346- int _pre_layout_width;
347- int _pre_layout_height;
348-
349- bool _size_match_text;
350+ BaseTexture* rasterized_text_texture_;
351+
352+ bool size_match_text_;
353
354 int clip_to_width_; //!< Wrapping of line.
355
356@@ -167,7 +198,7 @@
357 void RasterizeText(void* cairo_context, Color color);
358 void UpdateTextRendering();
359
360- CairoGraphics *cairo_graphics_;
361+ CairoGraphics* cairo_graphics_;
362 #endif
363
364 private:
365@@ -190,9 +221,10 @@
366 @return The full text size.
367 */
368 Size GetTextSizeNoClip();
369- float padding_x_; //!< Adds a padding around the entire text box.
370- float padding_y_; //!< Adds a padding around the entire text box.
371- Size no_clip_size_; //! Cacne of the GetTextSizeNoClip results so we don't recompute them constantly.
372+
373+ float padding_x_; //!< Adds a padding around the entire text box.
374+ float padding_y_; //!< Adds a padding around the entire text box.
375+ Size no_clip_size_; //! Cache of the GetTextSizeNoClip results so we don't recompute them constantly.
376 };
377
378 }
379
380=== modified file 'configure.ac'
381--- configure.ac 2012-02-04 00:19:46 +0000
382+++ configure.ac 2012-02-09 20:51:18 +0000
383@@ -22,7 +22,7 @@
384 # The number format is : year/month/day
385 # e.g.: december 5th, 2011 is: 20111205
386 # To make more than one API change in a day, add a number to the date. Like 20111205.xx
387-m4_define([nux_abi_version], [20120203.02])
388+m4_define([nux_abi_version], [20120209.01])
389
390 m4_define([nux_version],
391 [nux_major_version.nux_minor_version.nux_micro_version])

Subscribers

People subscribed via source and target branches

to all changes: