24
24
#include "Nux/Nux.h"
25
25
#include "QuicklistMenuItemLabel.h"
27
QuicklistMenuItemLabel::QuicklistMenuItemLabel (DbusmenuMenuitem* item,
29
QuicklistMenuItem (item,
27
QuicklistMenuItemLabel::QuicklistMenuItemLabel(DbusmenuMenuitem* item,
29
QuicklistMenuItem(item,
32
_name = g_strdup ("QuicklistMenuItemLabel");
32
_name = g_strdup("QuicklistMenuItemLabel");
36
QuicklistMenuItemLabel::QuicklistMenuItemLabel (DbusmenuMenuitem* item,
39
QuicklistMenuItem (item,
36
QuicklistMenuItemLabel::QuicklistMenuItemLabel(DbusmenuMenuitem* item,
39
QuicklistMenuItem(item,
43
_name = g_strdup ("QuicklistMenuItemLabel");
43
_name = g_strdup("QuicklistMenuItemLabel");
48
QuicklistMenuItemLabel::Initialize (DbusmenuMenuitem* item)
48
QuicklistMenuItemLabel::Initialize(DbusmenuMenuitem* item)
50
50
_item_type = MENUITEM_TYPE_LABEL;
53
_text = g_strdup (dbusmenu_menuitem_property_get (item, DBUSMENU_MENUITEM_PROP_LABEL));
53
_text = g_strdup(dbusmenu_menuitem_property_get(item, DBUSMENU_MENUITEM_PROP_LABEL));
55
_text = g_strdup ("Label");
55
_text = g_strdup("Label");
58
58
int textHeight = 1;
59
GetTextExtents (textWidth, textHeight);
60
SetMinimumSize (textWidth + ITEM_INDENT_ABS + 3 * ITEM_MARGIN,
61
textHeight + 2 * ITEM_MARGIN);
59
GetTextExtents(textWidth, textHeight);
60
SetMinimumSize(textWidth + ITEM_INDENT_ABS + 3 * ITEM_MARGIN,
61
textHeight + 2 * ITEM_MARGIN);
64
QuicklistMenuItemLabel::~QuicklistMenuItemLabel ()
64
QuicklistMenuItemLabel::~QuicklistMenuItemLabel()
66
66
if (_normalTexture[0])
67
_normalTexture[0]->UnReference ();
67
_normalTexture[0]->UnReference();
69
69
if (_normalTexture[1])
70
_normalTexture[1]->UnReference ();
70
_normalTexture[1]->UnReference();
72
72
if (_prelightTexture[0])
73
_prelightTexture[0]->UnReference ();
73
_prelightTexture[0]->UnReference();
75
75
if (_prelightTexture[1])
76
_prelightTexture[1]->UnReference ();
76
_prelightTexture[1]->UnReference();
80
QuicklistMenuItemLabel::PreLayoutManagement ()
80
QuicklistMenuItemLabel::PreLayoutManagement()
82
_pre_layout_width = GetBaseWidth ();
83
_pre_layout_height = GetBaseHeight ();
82
_pre_layout_width = GetBaseWidth();
83
_pre_layout_height = GetBaseHeight();
85
85
if (_normalTexture[0] == 0)
90
QuicklistMenuItem::PreLayoutManagement ();
90
QuicklistMenuItem::PreLayoutManagement();
94
QuicklistMenuItemLabel::PostLayoutManagement (long layoutResult)
94
QuicklistMenuItemLabel::PostLayoutManagement(long layoutResult)
96
96
int w = GetBaseWidth();
97
97
int h = GetBaseHeight();
137
137
nux::IntrusiveSP<nux::IOpenGLBaseTexture> texture;
139
nux::Geometry base = GetGeometry ();
139
nux::Geometry base = GetGeometry();
141
gfxContext.PushClippingRectangle (base);
141
gfxContext.PushClippingRectangle(base);
143
143
nux::TexCoordXForm texxform;
144
texxform.SetWrap (nux::TEXWRAP_REPEAT, nux::TEXWRAP_REPEAT);
145
texxform.SetTexCoordType (nux::TexCoordXForm::OFFSET_COORD);
147
gfxContext.GetRenderStates ().SetBlend (true);
148
gfxContext.GetRenderStates ().SetPremultipliedBlend (nux::SRC_OVER);
144
texxform.SetWrap(nux::TEXWRAP_REPEAT, nux::TEXWRAP_REPEAT);
145
texxform.SetTexCoordType(nux::TexCoordXForm::OFFSET_COORD);
147
gfxContext.GetRenderStates().SetBlend(true);
148
gfxContext.GetRenderStates().SetPremultipliedBlend(nux::SRC_OVER);
154
texture = _prelightTexture[0]->GetDeviceTexture ();
154
texture = _prelightTexture[0]->GetDeviceTexture();
158
texture = _normalTexture[0]->GetDeviceTexture ();
158
texture = _normalTexture[0]->GetDeviceTexture();
160
160
_color = nux::color::White;
164
texture = _normalTexture[0]->GetDeviceTexture ();
165
_color = nux::Color (0.8f, 0.8f, 0.8f, 1.0f);
164
texture = _normalTexture[0]->GetDeviceTexture();
165
_color = nux::Color(0.8f, 0.8f, 0.8f, 1.0f);
168
gfxContext.QRP_1Tex (base.x,
176
gfxContext.GetRenderStates().SetBlend (false);
178
gfxContext.PopClippingRectangle ();
182
QuicklistMenuItemLabel::DrawContent (nux::GraphicsEngine& gfxContext,
188
QuicklistMenuItemLabel::PostDraw (nux::GraphicsEngine& gfxContext,
194
QuicklistMenuItemLabel::UpdateTexture ()
196
nux::Color transparent = nux::Color (0.0f, 0.0f, 0.0f, 0.0f);
197
int width = GetBaseWidth ();
198
int height = GetBaseHeight ();
200
_cairoGraphics = new nux::CairoGraphics (CAIRO_FORMAT_ARGB32, width, height);
201
cairo_t *cr = _cairoGraphics->GetContext ();
168
gfxContext.QRP_1Tex(base.x,
176
gfxContext.GetRenderStates().SetBlend(false);
178
gfxContext.PopClippingRectangle();
182
QuicklistMenuItemLabel::DrawContent(nux::GraphicsEngine& gfxContext,
188
QuicklistMenuItemLabel::PostDraw(nux::GraphicsEngine& gfxContext,
194
QuicklistMenuItemLabel::UpdateTexture()
196
nux::Color transparent = nux::Color(0.0f, 0.0f, 0.0f, 0.0f);
197
int width = GetBaseWidth();
198
int height = GetBaseHeight();
200
_cairoGraphics = new nux::CairoGraphics(CAIRO_FORMAT_ARGB32, width, height);
201
cairo_t* cr = _cairoGraphics->GetContext();
203
203
// draw normal, unchecked version
204
cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
207
cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
208
cairo_scale (cr, 1.0f, 1.0f);
209
cairo_set_source_rgba (cr, 1.0f, 1.0f, 1.0f, 1.0f);
210
cairo_set_line_width (cr, 1.0f);
212
DrawText (cr, width, height, nux::color::White);
214
nux::NBitmapData* bitmap = _cairoGraphics->GetBitmap ();
204
cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR);
207
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
208
cairo_scale(cr, 1.0f, 1.0f);
209
cairo_set_source_rgba(cr, 1.0f, 1.0f, 1.0f, 1.0f);
210
cairo_set_line_width(cr, 1.0f);
212
DrawText(cr, width, height, nux::color::White);
214
nux::NBitmapData* bitmap = _cairoGraphics->GetBitmap();
216
216
if (_normalTexture[0])
217
_normalTexture[0]->UnReference ();
217
_normalTexture[0]->UnReference();
219
_normalTexture[0] = nux::GetGraphicsDisplay ()->GetGpuDevice ()->CreateSystemCapableTexture ();
220
_normalTexture[0]->Update (bitmap);
219
_normalTexture[0] = nux::GetGraphicsDisplay()->GetGpuDevice()->CreateSystemCapableTexture();
220
_normalTexture[0]->Update(bitmap);
223
223
// draw active/prelight, unchecked version
224
cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
227
cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
228
cairo_scale (cr, 1.0f, 1.0f);
229
cairo_set_source_rgba (cr, 1.0f, 1.0f, 1.0f, 1.0f);
230
cairo_set_line_width (cr, 1.0f);
232
_cairoGraphics->DrawRoundedRectangle (cr,
236
ITEM_CORNER_RADIUS_ABS,
241
cairo_set_source_rgba (cr, 0.0f, 0.0f, 0.0f, 0.0f);
243
DrawText (cr, width, height, transparent);
245
bitmap = _cairoGraphics->GetBitmap ();
224
cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR);
227
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
228
cairo_scale(cr, 1.0f, 1.0f);
229
cairo_set_source_rgba(cr, 1.0f, 1.0f, 1.0f, 1.0f);
230
cairo_set_line_width(cr, 1.0f);
232
_cairoGraphics->DrawRoundedRectangle(cr,
236
ITEM_CORNER_RADIUS_ABS,
241
cairo_set_source_rgba(cr, 0.0f, 0.0f, 0.0f, 0.0f);
243
DrawText(cr, width, height, transparent);
245
bitmap = _cairoGraphics->GetBitmap();
247
247
if (_prelightTexture[0])
248
_prelightTexture[0]->UnReference ();
248
_prelightTexture[0]->UnReference();
250
_prelightTexture[0] = nux::GetGraphicsDisplay ()->GetGpuDevice ()->CreateSystemCapableTexture ();
251
_prelightTexture[0]->Update (bitmap);
250
_prelightTexture[0] = nux::GetGraphicsDisplay()->GetGpuDevice()->CreateSystemCapableTexture();
251
_prelightTexture[0]->Update(bitmap);
254
254
// finally clean up
255
255
delete _cairoGraphics;
258
int QuicklistMenuItemLabel::CairoSurfaceWidth ()
258
int QuicklistMenuItemLabel::CairoSurfaceWidth()
260
260
if (_normalTexture[0])
261
return _normalTexture[0]->GetWidth ();
261
return _normalTexture[0]->GetWidth();