~3v1n0/unity/overlay-border-scale

« back to all changes in this revision

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

  • Committer: Daniel van Vugt
  • Date: 2012-03-14 06:24:18 UTC
  • mfrom: (2108 unity)
  • mto: This revision was merged to the branch mainline in revision 2146.
  • Revision ID: daniel.van.vugt@canonical.com-20120314062418-nprucpbr0m7qky5e
MergedĀ latestĀ lp:unity

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
#include "CairoTexture.h"
27
27
#include "QuicklistMenuItemCheckmark.h"
28
28
 
29
 
using unity::texture_from_cairo_graphics;
 
29
namespace unity
 
30
{
30
31
 
31
32
static double
32
33
_align(double val)
110
111
}
111
112
 
112
113
void
113
 
QuicklistMenuItemCheckmark::Draw(nux::GraphicsEngine& gfxContext,
114
 
                                 bool                 forceDraw)
 
114
QuicklistMenuItemCheckmark::Draw(nux::GraphicsEngine& gfxContext, bool forceDraw)
115
115
{
116
116
  nux::ObjectPtr<nux::IOpenGLBaseTexture> texture;
117
117
 
118
118
  // Check if the texture have been computed. If they haven't, exit the function.
119
 
  if (!_normalTexture[0])
 
119
  if (!_normalTexture[0] || !_prelightTexture[0])
120
120
    return;
121
121
 
122
122
  nux::Geometry base = GetGeometry();
130
130
  gfxContext.GetRenderStates().SetBlend(true);
131
131
  gfxContext.GetRenderStates().SetPremultipliedBlend(nux::SRC_OVER);
132
132
 
133
 
  if (GetEnabled())
 
133
  unsigned int texture_idx = GetActive() ? 1 : 0;
 
134
 
 
135
  if (!_prelight || !GetEnabled())
134
136
  {
135
 
    if (GetActive() && _prelight)
136
 
    {
137
 
      texture = _prelightTexture[0]->GetDeviceTexture();
138
 
    }
139
 
    else if (GetActive())
140
 
    {
141
 
      texture = _normalTexture[0]->GetDeviceTexture();
142
 
    }
143
 
 
144
 
    if ((!GetActive()) && _prelight)
145
 
    {
146
 
      texture = _prelightTexture[1]->GetDeviceTexture();
147
 
    }
148
 
    else if (!GetActive())
149
 
    {
150
 
      texture = _normalTexture[1]->GetDeviceTexture();
151
 
    }
152
 
 
153
 
    _color = nux::color::White;
 
137
    texture = _normalTexture[texture_idx]->GetDeviceTexture();
154
138
  }
155
139
  else
156
140
  {
157
 
    if (GetActive())
158
 
    {
159
 
      texture = _prelightTexture[0]->GetDeviceTexture();
160
 
    }
161
 
    else
162
 
    {
163
 
      texture = _normalTexture[0]->GetDeviceTexture();
164
 
    }
165
 
 
166
 
    _color = nux::Color(0.8f, 0.8f, 0.8f, 1.0f);
 
141
    texture = _prelightTexture[texture_idx]->GetDeviceTexture();
167
142
  }
168
143
 
 
144
  _color = GetEnabled() ? nux::color::White : nux::color::White * 0.35;
 
145
 
169
146
  gfxContext.QRP_1Tex(base.x,
170
147
                      base.y,
171
148
                      base.width,
192
169
void
193
170
QuicklistMenuItemCheckmark::UpdateTexture()
194
171
{
195
 
  nux::Color transparent = nux::Color(0.0f, 0.0f, 0.0f, 0.0f);
196
172
  int        width       = GetBaseWidth();
197
173
  int        height      = GetBaseHeight();
198
174
 
208
184
  cairo_set_source_rgba(cr, 1.0f, 1.0f, 1.0f, 1.0f);
209
185
  cairo_set_line_width(cr, 1.0f);
210
186
 
211
 
  DrawText(cr, width, height, nux::color::White);
 
187
  DrawText(_cairoGraphics, width, height, nux::color::White);
212
188
 
213
189
  if (_normalTexture[0])
214
190
    _normalTexture[0]->UnReference();
245
221
 
246
222
  cairo_restore(cr);
247
223
 
248
 
  DrawText(cr, width, height, nux::color::White);
 
224
  DrawText(_cairoGraphics, width, height, nux::color::White);
249
225
 
250
226
  if (_normalTexture[1])
251
227
    _normalTexture[1]->UnReference();
256
232
  cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR);
257
233
  cairo_paint(cr);
258
234
 
259
 
  cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
260
 
  cairo_scale(cr, 1.0f, 1.0f);
261
 
  cairo_set_source_rgba(cr, 1.0f, 1.0f, 1.0f, 1.0f);
262
 
  cairo_set_line_width(cr, 1.0f);
263
 
 
264
 
  _cairoGraphics->DrawRoundedRectangle(cr,
265
 
                                       1.0f,
266
 
                                       0.5f,
267
 
                                       0.5f,
268
 
                                       ITEM_CORNER_RADIUS_ABS,
269
 
                                       width - 1.0f,
270
 
                                       height - 1.0f);
271
 
  cairo_fill(cr);
272
 
 
273
 
  cairo_set_source_rgba(cr, 0.0f, 0.0f, 0.0f, 0.0f);
274
 
 
275
 
  DrawText(cr, width, height, transparent);
 
235
  DrawPrelight(_cairoGraphics, width, height, nux::color::White);
 
236
  DrawText(_cairoGraphics, width, height, nux::color::White * 0.0f);
276
237
 
277
238
  if (_prelightTexture[0])
278
239
    _prelightTexture[0]->UnReference();
283
244
  cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR);
284
245
  cairo_paint(cr);
285
246
 
286
 
  cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
287
 
  cairo_scale(cr, 1.0f, 1.0f);
288
 
  cairo_set_source_rgba(cr, 1.0f, 1.0f, 1.0f, 1.0f);
289
 
  cairo_set_line_width(cr, 1.0f);
290
 
 
291
 
  _cairoGraphics->DrawRoundedRectangle(cr,
292
 
                                       1.0f,
293
 
                                       0.5f,
294
 
                                       0.5f,
295
 
                                       ITEM_CORNER_RADIUS_ABS,
296
 
                                       width - 1.0f,
297
 
                                       height - 1.0f);
298
 
  cairo_fill(cr);
 
247
  DrawPrelight(_cairoGraphics, width, height, nux::color::White);
299
248
 
300
249
  cairo_set_source_rgba(cr, 0.0f, 0.0f, 0.0f, 0.0f);
301
250
 
319
268
 
320
269
  cairo_restore(cr);
321
270
 
322
 
  DrawText(cr, width, height, transparent);
 
271
  DrawText(_cairoGraphics, width, height, nux::color::White * 0.0f);
323
272
 
324
273
  if (_prelightTexture[1])
325
274
    _prelightTexture[1]->UnReference();
327
276
  _prelightTexture[1] = texture_from_cairo_graphics(*_cairoGraphics);
328
277
 
329
278
  // finally clean up
 
279
  cairo_destroy(cr);
330
280
  delete _cairoGraphics;
331
281
}
332
282
 
337
287
 
338
288
  return 0;
339
289
}
 
290
 
 
291
}