2
* Copyright (C) 2010 Canonical Ltd
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.
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.
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/>.
16
* Authored by: Neil Jagdish Patel <neil.patel@canonical.com>
21
#include "NuxGraphics/GLThread.h"
23
#include "PanelHomeButton.h"
26
#include <pango/pangocairo.h>
29
#define PANEL_HEIGHT 24
30
#define BUTTON_WIDTH 66
32
PanelHomeButton::PanelHomeButton ()
33
: TextureArea (NUX_TRACKER_LOCATION),
34
_util_cg (CAIRO_FORMAT_ARGB32, BUTTON_WIDTH, PANEL_HEIGHT)
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);
42
PanelHomeButton::~PanelHomeButton ()
44
g_object_unref (_pixbuf);
48
PanelHomeButton::Refresh ()
50
int width = BUTTON_WIDTH;
51
int height = PANEL_HEIGHT;
53
nux::CairoGraphics cairo_graphics(CAIRO_FORMAT_ARGB32, width, height);
54
cairo_t *cr = cairo_graphics.GetContext();
55
cairo_set_line_width (cr, 1);
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);
62
cairo_set_source_rgba (cr, 0.0f, 0.0f, 0.0f, 0.2f);
63
cairo_rectangle (cr, width-2, 2, 1, height-4);
66
cairo_set_source_rgba (cr, 1.0f, 1.0f, 1.0f, 0.1f);
67
cairo_rectangle (cr, width-1, 2, 1, height-4);
72
nux::NBitmapData* bitmap = cairo_graphics.GetBitmap();
74
// The Texture is created with a reference count of 1.
75
nux::BaseTexture* texture2D = nux::GetThreadGLDeviceFactory ()->CreateSystemCapableTexture ();
76
texture2D->Update(bitmap);
79
nux::TexCoordXForm texxform;
80
texxform.SetTexCoordType (nux::TexCoordXForm::OFFSET_COORD);
81
texxform.SetWrap (nux::TEXWRAP_REPEAT, nux::TEXWRAP_REPEAT);
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.
94
SetPaintLayer(texture_layer);
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 ();
100
// The texture layer has been cloned by this object when calling SetPaintLayer. It is safe to delete it now.
101
delete texture_layer;