~om26er/ubuntu/oneiric/unity/sru-778256

« back to all changes in this revision

Viewing changes to plugins/unityshell/src/QuicklistMenuItemLabel.cpp

  • Committer: Didier Roche
  • Date: 2011-07-21 16:17:59 UTC
  • mfrom: (55.813.3 upstream)
  • Revision ID: didier.roche@canonical.com-20110721161759-osmh94x428t2bf2b
* New upstream release.
* debian/control:
  - build-dep on libnotify-dev
  - bump libnux-1.0-dev dep for ABI break

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
#include "Nux/Nux.h"
25
25
#include "QuicklistMenuItemLabel.h"
26
26
 
27
 
QuicklistMenuItemLabel::QuicklistMenuItemLabel (DbusmenuMenuitem* item,
28
 
                                                        NUX_FILE_LINE_DECL) :
29
 
QuicklistMenuItem (item,
30
 
                   NUX_FILE_LINE_PARAM)
 
27
QuicklistMenuItemLabel::QuicklistMenuItemLabel(DbusmenuMenuitem* item,
 
28
                                               NUX_FILE_LINE_DECL) :
 
29
  QuicklistMenuItem(item,
 
30
                    NUX_FILE_LINE_PARAM)
31
31
{
32
 
  _name = g_strdup ("QuicklistMenuItemLabel");
33
 
  Initialize (item);
 
32
  _name = g_strdup("QuicklistMenuItemLabel");
 
33
  Initialize(item);
34
34
}
35
35
 
36
 
QuicklistMenuItemLabel::QuicklistMenuItemLabel (DbusmenuMenuitem* item,
37
 
                                                        bool              debug,
38
 
                                                        NUX_FILE_LINE_DECL) :
39
 
QuicklistMenuItem (item,
40
 
                   debug,
41
 
                   NUX_FILE_LINE_PARAM)
 
36
QuicklistMenuItemLabel::QuicklistMenuItemLabel(DbusmenuMenuitem* item,
 
37
                                               bool              debug,
 
38
                                               NUX_FILE_LINE_DECL) :
 
39
  QuicklistMenuItem(item,
 
40
                    debug,
 
41
                    NUX_FILE_LINE_PARAM)
42
42
{
43
 
  _name = g_strdup ("QuicklistMenuItemLabel");
44
 
  Initialize (item);
 
43
  _name = g_strdup("QuicklistMenuItemLabel");
 
44
  Initialize(item);
45
45
}
46
46
 
47
47
void
48
 
QuicklistMenuItemLabel::Initialize (DbusmenuMenuitem* item)
 
48
QuicklistMenuItemLabel::Initialize(DbusmenuMenuitem* item)
49
49
{
50
50
  _item_type  = MENUITEM_TYPE_LABEL;
51
51
 
52
52
  if (item)
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));
54
54
  else
55
 
    _text = g_strdup ("Label");
 
55
    _text = g_strdup("Label");
56
56
 
57
57
  int textWidth = 1;
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);
62
62
}
63
63
 
64
 
QuicklistMenuItemLabel::~QuicklistMenuItemLabel ()
 
64
QuicklistMenuItemLabel::~QuicklistMenuItemLabel()
65
65
{
66
66
  if (_normalTexture[0])
67
 
    _normalTexture[0]->UnReference ();
 
67
    _normalTexture[0]->UnReference();
68
68
 
69
69
  if (_normalTexture[1])
70
 
    _normalTexture[1]->UnReference ();
 
70
    _normalTexture[1]->UnReference();
71
71
 
72
72
  if (_prelightTexture[0])
73
 
    _prelightTexture[0]->UnReference ();
 
73
    _prelightTexture[0]->UnReference();
74
74
 
75
75
  if (_prelightTexture[1])
76
 
    _prelightTexture[1]->UnReference ();
 
76
    _prelightTexture[1]->UnReference();
77
77
}
78
78
 
79
79
void
80
 
QuicklistMenuItemLabel::PreLayoutManagement ()
 
80
QuicklistMenuItemLabel::PreLayoutManagement()
81
81
{
82
 
  _pre_layout_width = GetBaseWidth ();
83
 
  _pre_layout_height = GetBaseHeight ();
 
82
  _pre_layout_width = GetBaseWidth();
 
83
  _pre_layout_height = GetBaseHeight();
84
84
 
85
85
  if (_normalTexture[0] == 0)
86
86
  {
87
 
    UpdateTexture ();
 
87
    UpdateTexture();
88
88
  }
89
89
 
90
 
  QuicklistMenuItem::PreLayoutManagement ();
 
90
  QuicklistMenuItem::PreLayoutManagement();
91
91
}
92
92
 
93
93
long
94
 
QuicklistMenuItemLabel::PostLayoutManagement (long layoutResult)
 
94
QuicklistMenuItemLabel::PostLayoutManagement(long layoutResult)
95
95
{
96
96
  int w = GetBaseWidth();
97
97
  int h = GetBaseHeight();
116
116
}
117
117
 
118
118
long
119
 
QuicklistMenuItemLabel::ProcessEvent (nux::IEvent& event,
120
 
                                          long         traverseInfo,
121
 
                                          long         processEventInfo)
 
119
QuicklistMenuItemLabel::ProcessEvent(nux::IEvent& event,
 
120
                                     long         traverseInfo,
 
121
                                     long         processEventInfo)
122
122
{
123
123
  long result = traverseInfo;
124
124
 
125
 
  result = nux::View::PostProcessEvent2 (event, result, processEventInfo);
 
125
  result = nux::View::PostProcessEvent2(event, result, processEventInfo);
126
126
  return result;
127
127
}
128
128
 
129
129
void
130
 
QuicklistMenuItemLabel::Draw (nux::GraphicsEngine& gfxContext,
131
 
                                  bool                 forceDraw)
 
130
QuicklistMenuItemLabel::Draw(nux::GraphicsEngine& gfxContext,
 
131
                             bool                 forceDraw)
132
132
{
133
133
  // Check if the texture have been computed. If they haven't, exit the function.
134
134
  if (_normalTexture[0] == NULL)
136
136
 
137
137
  nux::IntrusiveSP<nux::IOpenGLBaseTexture> texture;
138
138
 
139
 
  nux::Geometry base = GetGeometry ();
 
139
  nux::Geometry base = GetGeometry();
140
140
 
141
 
  gfxContext.PushClippingRectangle (base);
 
141
  gfxContext.PushClippingRectangle(base);
142
142
 
143
143
  nux::TexCoordXForm texxform;
144
 
  texxform.SetWrap (nux::TEXWRAP_REPEAT, nux::TEXWRAP_REPEAT);
145
 
  texxform.SetTexCoordType (nux::TexCoordXForm::OFFSET_COORD);
146
 
 
147
 
  gfxContext.GetRenderStates ().SetBlend (true);
148
 
  gfxContext.GetRenderStates ().SetPremultipliedBlend (nux::SRC_OVER);
149
 
 
150
 
  if (GetEnabled ())
 
144
  texxform.SetWrap(nux::TEXWRAP_REPEAT, nux::TEXWRAP_REPEAT);
 
145
  texxform.SetTexCoordType(nux::TexCoordXForm::OFFSET_COORD);
 
146
 
 
147
  gfxContext.GetRenderStates().SetBlend(true);
 
148
  gfxContext.GetRenderStates().SetPremultipliedBlend(nux::SRC_OVER);
 
149
 
 
150
  if (GetEnabled())
151
151
  {
152
152
    if (_prelight)
153
153
    {
154
 
      texture = _prelightTexture[0]->GetDeviceTexture ();
 
154
      texture = _prelightTexture[0]->GetDeviceTexture();
155
155
    }
156
156
    else
157
157
    {
158
 
      texture = _normalTexture[0]->GetDeviceTexture ();
 
158
      texture = _normalTexture[0]->GetDeviceTexture();
159
159
    }
160
160
    _color = nux::color::White;
161
161
  }
162
162
  else
163
163
  {
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);
166
166
  }
167
167
 
168
 
  gfxContext.QRP_1Tex (base.x,
169
 
                            base.y,
170
 
                            base.width,
171
 
                            base.height,
172
 
                            texture,
173
 
                            texxform,
174
 
                            _color);
175
 
 
176
 
  gfxContext.GetRenderStates().SetBlend (false);
177
 
 
178
 
  gfxContext.PopClippingRectangle ();
179
 
}
180
 
 
181
 
void
182
 
QuicklistMenuItemLabel::DrawContent (nux::GraphicsEngine& gfxContext,
183
 
                                         bool                 forceDraw)
184
 
{
185
 
}
186
 
 
187
 
void
188
 
QuicklistMenuItemLabel::PostDraw (nux::GraphicsEngine& gfxContext,
189
 
                                      bool                 forceDraw)
190
 
{
191
 
}
192
 
 
193
 
void
194
 
QuicklistMenuItemLabel::UpdateTexture ()
195
 
{
196
 
  nux::Color transparent = nux::Color (0.0f, 0.0f, 0.0f, 0.0f);
197
 
  int        width       = GetBaseWidth ();
198
 
  int        height      = GetBaseHeight ();
199
 
 
200
 
  _cairoGraphics = new nux::CairoGraphics (CAIRO_FORMAT_ARGB32, width, height);
201
 
  cairo_t *cr = _cairoGraphics->GetContext ();
 
168
  gfxContext.QRP_1Tex(base.x,
 
169
                      base.y,
 
170
                      base.width,
 
171
                      base.height,
 
172
                      texture,
 
173
                      texxform,
 
174
                      _color);
 
175
 
 
176
  gfxContext.GetRenderStates().SetBlend(false);
 
177
 
 
178
  gfxContext.PopClippingRectangle();
 
179
}
 
180
 
 
181
void
 
182
QuicklistMenuItemLabel::DrawContent(nux::GraphicsEngine& gfxContext,
 
183
                                    bool                 forceDraw)
 
184
{
 
185
}
 
186
 
 
187
void
 
188
QuicklistMenuItemLabel::PostDraw(nux::GraphicsEngine& gfxContext,
 
189
                                 bool                 forceDraw)
 
190
{
 
191
}
 
192
 
 
193
void
 
194
QuicklistMenuItemLabel::UpdateTexture()
 
195
{
 
196
  nux::Color transparent = nux::Color(0.0f, 0.0f, 0.0f, 0.0f);
 
197
  int        width       = GetBaseWidth();
 
198
  int        height      = GetBaseHeight();
 
199
 
 
200
  _cairoGraphics = new nux::CairoGraphics(CAIRO_FORMAT_ARGB32, width, height);
 
201
  cairo_t* cr = _cairoGraphics->GetContext();
202
202
 
203
203
  // draw normal, unchecked version
204
 
  cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
205
 
  cairo_paint (cr);
206
 
 
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);
211
 
 
212
 
  DrawText (cr, width, height, nux::color::White);
213
 
 
214
 
  nux::NBitmapData* bitmap = _cairoGraphics->GetBitmap ();
 
204
  cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR);
 
205
  cairo_paint(cr);
 
206
 
 
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);
 
211
 
 
212
  DrawText(cr, width, height, nux::color::White);
 
213
 
 
214
  nux::NBitmapData* bitmap = _cairoGraphics->GetBitmap();
215
215
 
216
216
  if (_normalTexture[0])
217
 
    _normalTexture[0]->UnReference ();
 
217
    _normalTexture[0]->UnReference();
218
218
 
219
 
  _normalTexture[0] = nux::GetGraphicsDisplay ()->GetGpuDevice ()->CreateSystemCapableTexture ();
220
 
  _normalTexture[0]->Update (bitmap);
 
219
  _normalTexture[0] = nux::GetGraphicsDisplay()->GetGpuDevice()->CreateSystemCapableTexture();
 
220
  _normalTexture[0]->Update(bitmap);
221
221
  delete bitmap;
222
222
 
223
223
  // draw active/prelight, unchecked version
224
 
  cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
225
 
  cairo_paint (cr);
226
 
 
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);
231
 
 
232
 
  _cairoGraphics->DrawRoundedRectangle (cr,
233
 
                                        1.0f,
234
 
                                        0.5f,
235
 
                                        0.5f,
236
 
                                        ITEM_CORNER_RADIUS_ABS,
237
 
                                        width - 1.0f,
238
 
                                        height - 1.0f);
239
 
  cairo_fill (cr);
240
 
 
241
 
  cairo_set_source_rgba (cr, 0.0f, 0.0f, 0.0f, 0.0f);
242
 
 
243
 
  DrawText (cr, width, height, transparent);
244
 
 
245
 
  bitmap = _cairoGraphics->GetBitmap ();
 
224
  cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR);
 
225
  cairo_paint(cr);
 
226
 
 
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);
 
231
 
 
232
  _cairoGraphics->DrawRoundedRectangle(cr,
 
233
                                       1.0f,
 
234
                                       0.5f,
 
235
                                       0.5f,
 
236
                                       ITEM_CORNER_RADIUS_ABS,
 
237
                                       width - 1.0f,
 
238
                                       height - 1.0f);
 
239
  cairo_fill(cr);
 
240
 
 
241
  cairo_set_source_rgba(cr, 0.0f, 0.0f, 0.0f, 0.0f);
 
242
 
 
243
  DrawText(cr, width, height, transparent);
 
244
 
 
245
  bitmap = _cairoGraphics->GetBitmap();
246
246
 
247
247
  if (_prelightTexture[0])
248
 
    _prelightTexture[0]->UnReference ();
 
248
    _prelightTexture[0]->UnReference();
249
249
 
250
 
  _prelightTexture[0] = nux::GetGraphicsDisplay ()->GetGpuDevice ()->CreateSystemCapableTexture ();
251
 
  _prelightTexture[0]->Update (bitmap);
 
250
  _prelightTexture[0] = nux::GetGraphicsDisplay()->GetGpuDevice()->CreateSystemCapableTexture();
 
251
  _prelightTexture[0]->Update(bitmap);
252
252
  delete bitmap;
253
253
 
254
254
  // finally clean up
255
255
  delete _cairoGraphics;
256
256
}
257
257
 
258
 
int QuicklistMenuItemLabel::CairoSurfaceWidth ()
 
258
int QuicklistMenuItemLabel::CairoSurfaceWidth()
259
259
{
260
260
  if (_normalTexture[0])
261
 
    return _normalTexture[0]->GetWidth ();
 
261
    return _normalTexture[0]->GetWidth();
262
262
 
263
263
  return 0;
264
264
}