~3v1n0/unity/overlay-border-scale

« back to all changes in this revision

Viewing changes to plugins/unityshell/src/OverlayRenderer.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:
36
36
namespace
37
37
{
38
38
nux::logging::Logger logger("unity.overlayrenderer");
 
39
 
 
40
const int INNER_CORNER_RADIUS = 5;
39
41
}
40
42
 
41
43
// Impl class
48
50
  void Init();
49
51
  void OnBackgroundColorChanged(GVariant* args);
50
52
  
51
 
  void Draw(nux::GraphicsEngine& gfx_context, nux::Geometry content_geo, nux::Geometry absolute_geo, nux::Geometry geometry);
 
53
  void Draw(nux::GraphicsEngine& gfx_context, nux::Geometry content_geo, nux::Geometry absolute_geo, nux::Geometry geometry, bool force_draw);
52
54
  void DrawContent(nux::GraphicsEngine& gfx_context, nux::Geometry content_geo, nux::Geometry absolute_geo, nux::Geometry geometry);
53
55
  void DrawContentCleanup(nux::GraphicsEngine& gfx_context, nux::Geometry content_geo, nux::Geometry absolute_geo, nux::Geometry geometry);
54
56
  
116
118
  parent->need_redraw.emit();
117
119
}
118
120
 
119
 
void OverlayRendererImpl::Draw(nux::GraphicsEngine& gfx_context, nux::Geometry content_geo, nux::Geometry absolute_geo, nux::Geometry geometry)
 
121
void OverlayRendererImpl::Draw(nux::GraphicsEngine& gfx_context, nux::Geometry content_geo, nux::Geometry absolute_geo, nux::Geometry geometry, bool force_edges)
120
122
{
121
123
  bool paint_blur = BackgroundEffectHelper::blur_type != BLUR_NONE;
122
124
  nux::Geometry geo = content_geo;
123
125
 
124
 
  if (dash::Settings::Instance().GetFormFactor() != dash::FormFactor::NETBOOK)
 
126
  if (dash::Settings::Instance().GetFormFactor() != dash::FormFactor::NETBOOK || force_edges)
125
127
  {
126
128
    // Paint the edges
127
129
    {
254
256
    nux::Geometry blur_geo(absolute_geo.x, absolute_geo.y, content_geo.width, content_geo.height);
255
257
    bg_blur_texture_ = bg_effect_helper_.GetBlurRegion(blur_geo);
256
258
    
257
 
    if (bg_blur_texture_.IsValid()  && paint_blur)
 
259
    if (bg_blur_texture_.IsValid())
258
260
    {
259
261
      nux::Geometry bg_clip = geo;
260
262
      gfx_context.PushClippingRectangle(bg_clip);
268
270
      gfx_context.PopClippingRectangle();
269
271
    }
270
272
  }
 
273
 
 
274
  // Draw the left and top lines
 
275
  gfx_context.GetRenderStates().SetColorMask(true, true, true, true);
 
276
  gfx_context.GetRenderStates().SetBlend(true);
 
277
  gfx_context.GetRenderStates().SetPremultipliedBlend(nux::SRC_OVER);
 
278
 
 
279
  const double line_opacity = 0.22;
 
280
  nux::Color line_color = nux::color::White * line_opacity;
 
281
  nux::GetPainter().Paint2DQuadColor(gfx_context,
 
282
                                     nux::Geometry(geometry.x,
 
283
                                                   geometry.y,
 
284
                                                   1,
 
285
                                                   content_geo.height + INNER_CORNER_RADIUS),
 
286
                                     nux::color::Transparent,
 
287
                                     line_color,
 
288
                                     line_color,
 
289
                                     nux::color::Transparent);
 
290
 
 
291
  nux::GetPainter().Paint2DQuadColor(gfx_context,
 
292
                                     nux::Geometry(geometry.x,
 
293
                                                   geometry.y,
 
294
                                                   content_geo.width + INNER_CORNER_RADIUS,
 
295
                                                   1),
 
296
                                     nux::color::Transparent,
 
297
                                     nux::color::Transparent,
 
298
                                     line_color,
 
299
                                     line_color);
271
300
  
 
301
  // Draw the background
272
302
  bg_darken_layer_->SetGeometry(content_geo);
273
303
  nux::GetPainter().RenderSinglePaintLayer(gfx_context, content_geo, bg_darken_layer_);
274
304
  
277
307
  
278
308
  
279
309
  texxform_absolute_bg.flip_v_coord = false;
280
 
  texxform_absolute_bg.uoffset = (1.0f / bg_shine_texture_->GetWidth()) * (absolute_geo.x);
281
 
  texxform_absolute_bg.voffset = (1.0f / bg_shine_texture_->GetHeight()) * (absolute_geo.y);
 
310
  texxform_absolute_bg.uoffset = (1.0f / bg_shine_texture_->GetWidth()) * parent->x_offset;
 
311
  texxform_absolute_bg.voffset = (1.0f / bg_shine_texture_->GetHeight()) * parent->y_offset;
282
312
  
283
313
  gfx_context.GetRenderStates().SetColorMask(true, true, true, false);
284
314
  gfx_context.GetRenderStates().SetBlend(true, GL_DST_COLOR, GL_ONE);
287
317
                        content_geo.width, content_geo.height,
288
318
                        bg_shine_texture_, texxform_absolute_bg, nux::color::White);
289
319
  
290
 
  // Make round corners
291
 
  nux::ROPConfig rop;
292
 
  rop.Blend = true;
293
 
  rop.SrcBlend = GL_ZERO;
294
 
  rop.DstBlend = GL_SRC_ALPHA;
295
 
  nux::GetPainter().PaintShapeCornerROP(gfx_context,
296
 
                                        content_geo,
297
 
                                        nux::color::White,
298
 
                                        nux::eSHAPE_CORNER_ROUND4,
299
 
                                        nux::eCornerBottomRight,
300
 
                                        true,
301
 
                                        rop);
302
 
  
303
 
  gfx_context.GetRenderStates().SetColorMask(true, true, true, true);
304
 
  gfx_context.GetRenderStates().SetBlend(true);
305
 
  gfx_context.GetRenderStates().SetPremultipliedBlend(nux::SRC_OVER);
306
 
  
307
 
  geo = geometry;
308
 
  nux::GetPainter().Paint2DQuadColor(gfx_context,
309
 
                                     nux::Geometry(geo.x,
310
 
                                                   geo.y,
311
 
                                                   1,
312
 
                                                   content_geo.height + 5),
313
 
                                     nux::Color(0.0f, 0.0f, 0.0f, 0.0f),
314
 
                                     nux::Color(0.15f, 0.15f, 0.15f, 0.15f),
315
 
                                     nux::Color(0.15f, 0.15f, 0.15f, 0.15f),
316
 
                                     nux::Color(0.0f, 0.0f, 0.0f, 0.0f));
317
 
  nux::GetPainter().Paint2DQuadColor(gfx_context,
318
 
                                     nux::Geometry(geo.x,
319
 
                                                   geo.y,
320
 
                                                   content_geo.width + 5,
321
 
                                                   1),
322
 
                                     nux::Color(0.0f, 0.0f, 0.0f, 0.0f),
323
 
                                     nux::Color(0.0f, 0.0f, 0.0f, 0.0f),
324
 
                                     nux::Color(0.15f, 0.15f, 0.15f, 0.15f),
325
 
                                     nux::Color(0.15f, 0.15f, 0.15f, 0.15f));
326
 
  
327
 
  geo = content_geo;
328
 
  // Fill in corners (meh)
329
 
  for (int i = 1; i < 6; ++i)
 
320
  if (dash::Settings::Instance().GetFormFactor() != dash::FormFactor::NETBOOK)
330
321
  {
331
 
    nux::Geometry fill_geo (geo.x + geo.width, geo.y + i - 1, 6 - i, 1);
332
 
    nux::GetPainter().Paint2DQuadColor(gfx_context, fill_geo, bg_color_);
333
 
    
334
 
    nux::Color dark = bg_color_ * 0.8f;
335
 
    dark.alpha = bg_color_.alpha;
336
 
    fill_geo = nux::Geometry(geo.x + i - 1 , geo.y + geo.height, 1, 6 - i);
337
 
    nux::GetPainter().Paint2DQuadColor(gfx_context, fill_geo, dark);
 
322
    // Make bottom-right corner rounded
 
323
    nux::ROPConfig rop;
 
324
    rop.Blend = true;
 
325
    rop.SrcBlend = GL_ZERO;
 
326
    rop.DstBlend = GL_SRC_ALPHA;
 
327
    nux::GetPainter().PaintShapeCornerROP(gfx_context,
 
328
                                          content_geo,
 
329
                                          nux::color::White,
 
330
                                          nux::eSHAPE_CORNER_ROUND4,
 
331
                                          nux::eCornerBottomRight,
 
332
                                          true,
 
333
                                          rop);
 
334
 
 
335
    geo = content_geo;
 
336
 
 
337
    gfx_context.GetRenderStates().SetColorMask(true, true, true, true);
 
338
    gfx_context.GetRenderStates().SetBlend(true);
 
339
    gfx_context.GetRenderStates().SetPremultipliedBlend(nux::SRC_OVER);
 
340
 
 
341
    // Fill in corners (meh)
 
342
    for (int i = 0; i < INNER_CORNER_RADIUS; ++i)
 
343
    {
 
344
      nux::Geometry fill_geo (geo.x + geo.width, geo.y + i, INNER_CORNER_RADIUS - i, 1);
 
345
      nux::GetPainter().Paint2DQuadColor(gfx_context, fill_geo, bg_color_);
 
346
      
 
347
      nux::Color dark = bg_color_ * 0.8f;
 
348
      dark.alpha = bg_color_.alpha;
 
349
      fill_geo = nux::Geometry(geo.x + i, geo.y + geo.height, 1, INNER_CORNER_RADIUS - i);
 
350
      nux::GetPainter().Paint2DQuadColor(gfx_context, fill_geo, dark);
 
351
    }
338
352
  }
339
353
}
340
354
 
384
398
  rop.SrcBlend = GL_DST_COLOR;
385
399
  rop.DstBlend = GL_ONE;
386
400
  texxform_absolute_bg.flip_v_coord = false;
387
 
  texxform_absolute_bg.uoffset = (1.0f / bg_shine_texture_->GetWidth()) * (absolute_geo.x);
388
 
  texxform_absolute_bg.voffset = (1.0f / bg_shine_texture_->GetHeight()) * (absolute_geo.y);
 
401
  texxform_absolute_bg.uoffset = (1.0f / bg_shine_texture_->GetWidth()) * parent->x_offset;
 
402
  texxform_absolute_bg.voffset = (1.0f / bg_shine_texture_->GetHeight()) * parent->y_offset;
389
403
  
390
404
  nux::GetPainter().PushTextureLayer(gfx_context, bg_layer_->GetGeometry(),
391
405
                                     bg_shine_texture_,
403
417
  gfx_context.GetRenderStates().SetBlend(false);
404
418
  gfx_context.PopClippingRectangle();
405
419
  
406
 
  // Make round corners
407
 
  nux::ROPConfig rop;
408
 
  rop.Blend = true;
409
 
  rop.SrcBlend = GL_ZERO;
410
 
  rop.DstBlend = GL_SRC_ALPHA;
411
 
  nux::GetPainter().PaintShapeCornerROP(gfx_context,
412
 
                                        content_geo,
413
 
                                        nux::color::White,
414
 
                                        nux::eSHAPE_CORNER_ROUND4,
415
 
                                        nux::eCornerBottomRight,
416
 
                                        true,
417
 
                                        rop);
 
420
  if (dash::Settings::Instance().GetFormFactor() != dash::FormFactor::NETBOOK)
 
421
  {
 
422
    // Make bottom-right corner rounded
 
423
    nux::ROPConfig rop;
 
424
    rop.Blend = true;
 
425
    rop.SrcBlend = GL_ZERO;
 
426
    rop.DstBlend = GL_SRC_ALPHA;
 
427
    nux::GetPainter().PaintShapeCornerROP(gfx_context,
 
428
                                          content_geo,
 
429
                                          nux::color::White,
 
430
                                          nux::eSHAPE_CORNER_ROUND4,
 
431
                                          nux::eCornerBottomRight,
 
432
                                          true,
 
433
                                          rop);
 
434
  }
418
435
  
419
436
  bgs = 0;
420
437
}
458
475
  pimpl_->bg_effect_helper_.blur_type = BLUR_NONE;
459
476
}
460
477
 
461
 
void OverlayRenderer::DrawFull(nux::GraphicsEngine& gfx_context, nux::Geometry content_geo, nux::Geometry absolute_geo, nux::Geometry geo)
 
478
void OverlayRenderer::DrawFull(nux::GraphicsEngine& gfx_context, nux::Geometry content_geo, nux::Geometry absolute_geo, nux::Geometry geo, bool force_edges)
462
479
{
463
 
  pimpl_->Draw(gfx_context, content_geo, absolute_geo, geo);
 
480
  pimpl_->Draw(gfx_context, content_geo, absolute_geo, geo, force_edges);
464
481
}
465
482
 
466
483
void OverlayRenderer::DrawInner(nux::GraphicsEngine& gfx_context, nux::Geometry content_geo, nux::Geometry absolute_geo, nux::Geometry geo)