~ken-vandine/unity/make-quicklists-work-again

« back to all changes in this revision

Viewing changes to src/PanelHomeButton.cpp

  • Committer: Neil Jagdish Patel
  • Date: 2010-11-11 18:51:08 UTC
  • mfrom: (572.1.58 unity-3.0)
  • Revision ID: neil.patel@canonical.com-20101111185108-71923a90txzvxbit
[merge] Unity 3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2010 Canonical Ltd
 
3
 *
 
4
 * This program is free software: you can redistribute it and/or modify
 
5
 * it under the terms of the GNU General Public License version 3 as
 
6
 * published by the Free Software Foundation.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful,
 
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
 * GNU General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU General Public License
 
14
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
 *
 
16
 * Authored by: Neil Jagdish Patel <neil.patel@canonical.com>
 
17
 */
 
18
 
 
19
#include "Nux/Nux.h"
 
20
 
 
21
#include "NuxGraphics/GLThread.h"
 
22
 
 
23
#include "PanelHomeButton.h"
 
24
 
 
25
#include <glib.h>
 
26
#include <pango/pangocairo.h>
 
27
#include <gtk/gtk.h>
 
28
 
 
29
#define PANEL_HEIGHT 24
 
30
#define BUTTON_WIDTH 66
 
31
 
 
32
PanelHomeButton::PanelHomeButton ()
 
33
: TextureArea (NUX_TRACKER_LOCATION),
 
34
  _util_cg (CAIRO_FORMAT_ARGB32, BUTTON_WIDTH, PANEL_HEIGHT)
 
35
{
 
36
  // FIXME: This obviously needs a lookup
 
37
  _pixbuf = gdk_pixbuf_new_from_file ("/usr/share/unity/bfb.png", NULL);
 
38
  SetMinMaxSize (BUTTON_WIDTH, PANEL_HEIGHT);
 
39
  Refresh ();
 
40
}
 
41
 
 
42
PanelHomeButton::~PanelHomeButton ()
 
43
{
 
44
  g_object_unref (_pixbuf);
 
45
}
 
46
 
 
47
void
 
48
PanelHomeButton::Refresh ()
 
49
{
 
50
  int width = BUTTON_WIDTH;
 
51
  int height = PANEL_HEIGHT;
 
52
 
 
53
  nux::CairoGraphics cairo_graphics(CAIRO_FORMAT_ARGB32, width, height);
 
54
  cairo_t *cr = cairo_graphics.GetContext();
 
55
  cairo_set_line_width (cr, 1);
 
56
 
 
57
  gdk_cairo_set_source_pixbuf (cr, _pixbuf,
 
58
                               (BUTTON_WIDTH-gdk_pixbuf_get_width (_pixbuf))/2,
 
59
                               (PANEL_HEIGHT-gdk_pixbuf_get_height (_pixbuf))/2);
 
60
  cairo_paint (cr);
 
61
 
 
62
  cairo_set_source_rgba (cr, 0.0f, 0.0f, 0.0f, 0.2f);
 
63
  cairo_rectangle (cr, width-2, 2, 1, height-4);
 
64
  cairo_fill (cr);
 
65
 
 
66
  cairo_set_source_rgba (cr, 1.0f, 1.0f, 1.0f, 0.1f);
 
67
  cairo_rectangle (cr, width-1, 2, 1, height-4);
 
68
  cairo_fill (cr);
 
69
 
 
70
  cairo_destroy (cr);
 
71
 
 
72
  nux::NBitmapData* bitmap =  cairo_graphics.GetBitmap();
 
73
  
 
74
  // The Texture is created with a reference count of 1.
 
75
  nux::BaseTexture* texture2D = nux::GetThreadGLDeviceFactory ()->CreateSystemCapableTexture ();
 
76
  texture2D->Update(bitmap);
 
77
  delete bitmap;
 
78
  
 
79
  nux::TexCoordXForm texxform;
 
80
  texxform.SetTexCoordType (nux::TexCoordXForm::OFFSET_COORD);
 
81
  texxform.SetWrap (nux::TEXWRAP_REPEAT, nux::TEXWRAP_REPEAT);
 
82
  
 
83
  nux::ROPConfig rop; 
 
84
  rop.Blend = true;                       // Enable the blending. By default rop.Blend is false.
 
85
  rop.SrcBlend = GL_ONE;                  // Set the source blend factor.
 
86
  rop.DstBlend = GL_ONE_MINUS_SRC_ALPHA;  // Set the destination blend factor.
 
87
  nux::TextureLayer* texture_layer = new nux::TextureLayer (texture2D->GetDeviceTexture(),
 
88
                                                            texxform,           // The Oject that defines the texture wraping and coordinate transformation.
 
89
                                                            nux::Color::White,  // The color used to modulate the texture.
 
90
                                                            false,  // Write the alpha value of the texture to the destination buffer.
 
91
                                                            rop     // Use the given raster operation to set the blending when the layer is being rendered.
 
92
                                                            );
 
93
 
 
94
  SetPaintLayer(texture_layer);
 
95
 
 
96
  // We don't need the texture anymore. Since it hasn't been reference, it ref count should still be 1.
 
97
  // UnReference it and it will be destroyed.  
 
98
  texture2D->UnReference ();
 
99
  
 
100
  // The texture layer has been cloned by this object when calling SetPaintLayer. It is safe to delete it now.
 
101
  delete texture_layer;
 
102
  
 
103
  NeedRedraw ();
 
104
}