~marcobiscaro2112/unity/fixes-724739

« back to all changes in this revision

Viewing changes to src/PanelMenuView.cpp

  • Committer: Neil Jagdish Patel
  • Date: 2011-02-17 11:04:21 UTC
  • mfrom: (853.4.21 panel-fixes)
  • Revision ID: neil.patel@canonical.com-20110217110421-p48vy0p2q4r79lo4
[merge] Panel fixes

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
#include "Nux/WindowCompositor.h"
30
30
 
31
31
#include "PanelMenuView.h"
 
32
#include "PanelStyle.h"
32
33
 
33
34
#include "WindowManager.h"
34
35
 
56
57
  _title_tex (NULL),
57
58
  _is_inside (false),
58
59
  _is_maximized (false),
 
60
  _is_own_window (false),
59
61
  _last_active_view (NULL)
60
62
{
61
63
  WindowManager *win_manager;
98
100
  win_manager->window_restored.connect (sigc::mem_fun (this, &PanelMenuView::OnWindowRestored));
99
101
  win_manager->window_unmapped.connect (sigc::mem_fun (this, &PanelMenuView::OnWindowUnmapped));
100
102
 
 
103
  PanelStyle::GetDefault ()->changed.connect (sigc::mem_fun (this, &PanelMenuView::Refresh));
 
104
 
101
105
  Refresh ();
102
106
}
103
107
 
223
227
  nux::ColorLayer layer (nux::Color (0x00000000), true, rop);
224
228
  gPainter.PushDrawLayer (GfxContext, GetGeometry (), &layer);
225
229
 
226
 
  if (_is_maximized)
 
230
  if (_is_own_window)
 
231
  {
 
232
 
 
233
  }
 
234
  else if (_is_maximized)
227
235
  {
228
236
    if (!_is_inside && !_last_active_view)
229
237
      gPainter.PushDrawLayer (GfxContext, GetGeometry (), _title_layer);
230
238
  }
231
239
  else
232
240
  {
233
 
    if (_is_inside || _last_active_view)
 
241
    if ((_is_inside || _last_active_view) && _entries.size ())
234
242
    {
235
243
      if (_gradient_texture == NULL)
236
244
      {
273
281
        }
274
282
        _gradient_texture->UnlockRect (0);
275
283
      }
 
284
      guint alpha = 0, src = 0, dest = 0;
276
285
 
277
 
      GfxContext.GetRenderStates ().SetBlend (true);
278
 
      GfxContext.GetRenderStates ().SetPremultipliedBlend (nux::SRC_OVER);
 
286
      GfxContext.GetRenderStates ().GetBlend (alpha, src, dest);
 
287
      GfxContext.GetRenderStates ().SetBlend (true, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
279
288
 
280
289
      nux::TexCoordXForm texxform0;
281
290
      nux::TexCoordXForm texxform1;
289
298
                             texxform1,
290
299
                             nux::Color::White);
291
300
 
292
 
      GfxContext.GetRenderStates ().SetBlend(false);
293
 
 
 
301
      GfxContext.GetRenderStates ().SetBlend (alpha, src, dest);
294
302
      // The previous blend is too aggressive on the texture and therefore there
295
303
      // is a slight loss of clarity. This fixes that
296
304
      geo.width = button_width * (factor - 1);
317
325
 
318
326
  GfxContext.PushClippingRectangle (geo);
319
327
 
320
 
  if (_is_inside || _last_active_view)
 
328
  if (!_is_own_window)
321
329
  {
322
 
    _layout->ProcessDraw (GfxContext, force_draw);
323
 
  }
 
330
    if (_is_inside || _last_active_view)
 
331
    {
 
332
      _layout->ProcessDraw (GfxContext, force_draw);
 
333
    }
324
334
 
325
 
  if (_is_maximized)
326
 
  {
327
 
    _window_buttons->ProcessDraw (GfxContext, true);
 
335
    if (_is_maximized)
 
336
    {
 
337
      _window_buttons->ProcessDraw (GfxContext, true);
 
338
    }
328
339
  }
329
340
 
330
341
  GfxContext.PopClippingRectangle();
333
344
gchar *
334
345
PanelMenuView::GetActiveViewName ()
335
346
{
336
 
  gchar *label = NULL;
 
347
  gchar         *label = NULL;
 
348
  BamfWindow    *window;
 
349
 
 
350
  // There's probably a better way to do this, but we really only want to ignore our own windows
 
351
  // as there could be cases where windows like ours have menus and we don't want them to fall
 
352
  // into this statement. Still, will investigate better ways to do this.
 
353
  window = bamf_matcher_get_active_window (_matcher);
 
354
  if (BAMF_IS_WINDOW (window) 
 
355
      && g_str_has_prefix (bamf_view_get_name (BAMF_VIEW (window)), "nux input"))
 
356
  {
 
357
    _is_own_window = true;
 
358
  }
 
359
  else
 
360
    _is_own_window = false;
337
361
 
338
362
  if (_is_maximized)
339
363
  {
448
472
  cr = cairo_graphics.GetContext();
449
473
  cairo_set_line_width (cr, 1);
450
474
 
 
475
  cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
 
476
  cairo_paint (cr);
 
477
 
 
478
  cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
 
479
 
451
480
  x = _padding;
452
481
  y = 0;
453
482
 
456
485
 
457
486
  if (label)
458
487
  {
 
488
    nux::Color col = PanelStyle::GetDefault ()->GetTextColor ();
 
489
    float red = col.GetRed (), blue = col.GetBlue (), green = col.GetGreen ();
 
490
 
459
491
    pango_cairo_update_layout (cr, layout);
460
492
 
461
493
    y += (height - text_height)/2;
462
494
    double startalpha = 1.0 - ((double)text_margin/(double)width);
463
495
 
464
 
    // Once for the homies that couldn't be here
465
 
    if (x+text_width >= width-1)
466
 
    {
467
 
        linpat = cairo_pattern_create_linear (x, y-1, width-1, y-1+text_height);
468
 
        cairo_pattern_add_color_stop_rgb (linpat, 0, 50/255.0f, 50/255.0f, 45/255.0f);
469
 
        cairo_pattern_add_color_stop_rgb (linpat, startalpha, 50/255.0f, 50/255.0f, 45/255.0f);
470
 
        cairo_pattern_add_color_stop_rgba (linpat, startalpha, 0, 0.0, 0.0, 0);
471
 
        cairo_pattern_add_color_stop_rgba (linpat, 1, 0, 0.0, 0.0, 0);
472
 
        cairo_set_source(cr, linpat);
473
 
        cairo_pattern_destroy(linpat);
474
 
    }
475
 
    else
476
 
    {
477
 
        cairo_set_source_rgb (cr, 50/255.0f, 50/255.0f, 45/255.0f);
478
 
    }
479
 
    cairo_move_to (cr, x, y-1);
480
 
    pango_cairo_show_layout (cr, layout);
481
 
    cairo_stroke (cr);
482
 
 
483
496
    // Once again for the homies that could
484
497
    if (x+text_width >= width-1)
485
498
    {
486
499
        linpat = cairo_pattern_create_linear (x, y, width-1, y+text_height);
487
 
        cairo_pattern_add_color_stop_rgb (linpat, 0, 223/255.0f, 219/255.0f, 210/255.0f);
488
 
        cairo_pattern_add_color_stop_rgb (linpat, startalpha, 223/255.0f, 219/255.0f, 210/255.0f);
 
500
        cairo_pattern_add_color_stop_rgb (linpat, 0, red, green, blue);
 
501
        cairo_pattern_add_color_stop_rgb (linpat, startalpha, red, green, blue);
489
502
        cairo_pattern_add_color_stop_rgba (linpat, 1, 0, 0.0, 0.0, 0);
490
503
        cairo_set_source(cr, linpat);
491
504
        cairo_pattern_destroy(linpat);
492
505
    }
493
506
    else
494
507
    {
495
 
        cairo_set_source_rgb (cr, 223/255.0f, 219/255.0f, 210/255.0f);
 
508
      cairo_set_source_rgb (cr, red, green, blue);
496
509
    }
497
510
    cairo_move_to (cr, x, y);
498
511
    pango_cairo_show_layout (cr, layout);
524
537
  _title_layer = new nux::TextureLayer (texture2D->GetDeviceTexture(),
525
538
                                        texxform,
526
539
                                        nux::Color::White,
527
 
                                        false, 
 
540
                                        true, 
528
541
                                        rop);
529
542
 
530
543