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>
20
#include "Nux/HLayout.h"
21
#include "Nux/VLayout.h"
23
#include "NuxGraphics/GLThread.h"
24
#include "Nux/BaseWindow.h"
25
#include "Nux/WindowCompositor.h"
27
#include "PanelIndicatorObjectEntryView.h"
30
#include <pango/pangocairo.h>
34
#define PANEL_HEIGHT 24
38
static void draw_menu_bg (cairo_t *cr, int width, int height);
41
PanelIndicatorObjectEntryView::PanelIndicatorObjectEntryView (IndicatorObjectEntryProxy *proxy)
42
: TextureArea (NUX_TRACKER_LOCATION),
44
_util_cg (CAIRO_FORMAT_ARGB32, 1, 1)
46
_proxy->Updated.connect (sigc::mem_fun (this, &PanelIndicatorObjectEntryView::Refresh));
47
//InputArea::OnMouseDown.connect (sigc::mem_fun (this, &PanelIndicatorObjectEntryView::OnMouseDown));
48
InputArea::OnMouseUp.connect (sigc::mem_fun (this, &PanelIndicatorObjectEntryView::OnMouseDown));
53
PanelIndicatorObjectEntryView::~PanelIndicatorObjectEntryView ()
58
PanelIndicatorObjectEntryView::OnMouseDown (int x, int y, long button_flags, long key_flags)
60
//printf ("OnMouseDown: %d %d %ld %ld\n", x, y, button_flags, key_flags);
61
//printf ("Geometry : %d %d %d %d\n", GetGeometry ().x, GetGeometry ().y, GetGeometry ().width, GetGeometry ().height);
63
_proxy->ShowMenu (GetGeometry ().x, PANEL_HEIGHT, time (NULL));
67
fix_string (const char *string)
75
int len = strlen (string);
77
for (i = 0; i < len; i++)
81
buf[buf_pos] = string[i];
87
return g_strdup (buf);
90
// We need to do a couple of things here:
91
// 1. Figure out our width
92
// 2. Figure out if we're active
95
PanelIndicatorObjectEntryView::Refresh ()
97
GdkPixbuf *pixbuf = _proxy->GetPixbuf ();
98
char *label = fix_string (_proxy->GetLabel ());
99
PangoLayout *layout = NULL;
100
PangoFontDescription *desc = NULL;
101
GtkSettings *settings = gtk_settings_get_default ();
103
char *font_description = NULL;
104
GdkScreen *screen = gdk_screen_get_default ();
110
int height = PANEL_HEIGHT;
116
// First lets figure out our size
117
if (pixbuf && _proxy->icon_visible)
119
width = gdk_pixbuf_get_width (pixbuf);
123
if (label && _proxy->label_visible)
126
PangoRectangle log_rect;
128
cr = _util_cg.GetContext ();
130
g_object_get (settings,
131
"gtk-font-name", &font_description,
134
desc = pango_font_description_from_string (font_description);
135
pango_font_description_set_weight (desc, PANGO_WEIGHT_NORMAL);
137
layout = pango_cairo_create_layout (cr);
138
pango_layout_set_font_description (layout, desc);
139
pango_layout_set_text (layout, label, -1);
141
cxt = pango_layout_get_context (layout);
142
pango_cairo_context_set_font_options (cxt, gdk_screen_get_font_options (screen));
143
pango_cairo_context_set_resolution (cxt, (float)dpi/(float)PANGO_SCALE);
144
pango_layout_context_changed (layout);
146
pango_layout_get_extents (layout, NULL, &log_rect);
147
text_width = log_rect.width / PANGO_SCALE;
148
text_height = log_rect.height / PANGO_SCALE;
154
pango_font_description_free (desc);
155
g_free (font_description);
162
SetMinimumWidth (width);
164
nux::CairoGraphics cairo_graphics(CAIRO_FORMAT_ARGB32, width, height);
165
cr = cairo_graphics.GetContext();
166
cairo_set_line_width (cr, 1);
168
if (_proxy->GetActive ())
169
draw_menu_bg (cr, width, height);
174
if (_proxy->GetPixbuf () && _proxy->icon_visible)
176
gdk_cairo_set_source_pixbuf (cr, pixbuf, x, (height - gdk_pixbuf_get_height (pixbuf))/2);
179
x += icon_width + SPACING;
182
if (label && _proxy->label_visible)
184
pango_cairo_update_layout (cr, layout);
186
// Once for the homies that couldn't be here
187
cairo_set_source_rgb (cr, 50/255.0f, 50/255.0f, 45/255.0f);
188
cairo_move_to (cr, x, ((height - text_height)/2)-1);
189
pango_cairo_show_layout (cr, layout);
192
// Once again for the homies that could
193
cairo_set_source_rgba (cr, 223/255.0f, 219/255.0f, 210/255.0f, 1.0f);
194
cairo_move_to (cr, x, (height - text_height)/2);
195
pango_cairo_show_layout (cr, layout);
201
g_object_unref (layout);
203
nux::NBitmapData* bitmap = cairo_graphics.GetBitmap();
205
nux::BaseTexture* texture2D = nux::GetThreadGLDeviceFactory ()->CreateSystemCapableTexture ();
206
texture2D->Update(bitmap);
209
nux::TexCoordXForm texxform;
210
texxform.SetTexCoordType (nux::TexCoordXForm::OFFSET_COORD);
211
texxform.SetWrap (nux::TEXWRAP_REPEAT, nux::TEXWRAP_REPEAT);
214
rop.Blend = true; // Enable the blending. By default rop.Blend is false.
215
rop.SrcBlend = GL_ONE; // Set the source blend factor.
216
rop.DstBlend = GL_ONE_MINUS_SRC_ALPHA; // Set the destination blend factor.
217
nux::TextureLayer* texture_layer = new nux::TextureLayer (texture2D->GetDeviceTexture(),
218
texxform, // The Oject that defines the texture wraping and coordinate transformation.
219
nux::Color::White, // The color used to modulate the texture.
220
false, // Write the alpha value of the texture to the destination buffer.
221
rop // Use the given raster operation to set the blending when the layer is being rendered.
226
SetPaintLayer (texture_layer);
235
draw_menu_bg (cairo_t *cr, int width, int height)
243
double mpi = 3.14159265358979323846;
245
cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
247
cairo_set_line_width (cr, 1.0);
249
cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 0.2);
251
cairo_move_to (cr, x+xos+radius, y+yos);
252
cairo_arc (cr, x+xos+width-xos*2-radius, y+yos+radius, radius, mpi*1.5, mpi*2);
253
cairo_line_to (cr, x+xos+width-xos*2, y+yos+height-yos*2+2);
254
cairo_line_to (cr, x+xos, y+yos+height-yos*2+2);
255
cairo_arc (cr, x+xos+radius, y+yos+radius, radius, mpi, mpi*1.5);
257
cairo_pattern_t * pat = cairo_pattern_create_linear (x+xos, y, x+xos, y+height-yos*2+2);
258
cairo_pattern_add_color_stop_rgba (pat, 0.0, 83/255.0f, 82/255.0f, 78/255.0f, 1.0f);
259
cairo_pattern_add_color_stop_rgba (pat, 1.0, 66/255.0f, 65/255.0f, 63/255.0f, 1.0f);
260
cairo_set_source (cr, pat);
261
cairo_fill_preserve (cr);
262
cairo_pattern_destroy (pat);
264
pat = cairo_pattern_create_linear (x+xos, y, x+xos, y+height-yos*2+2);
265
cairo_pattern_add_color_stop_rgba (pat, 0.0, 62/255.0f, 61/255.0f, 58/255.0f, 1.0f);
266
cairo_pattern_add_color_stop_rgba (pat, 1.0, 54/255.0f, 54/255.0f, 52/255.0f, 1.0f);
267
cairo_set_source (cr, pat);
269
cairo_pattern_destroy (pat);
274
/* enlarging the area to not draw the lightborder at bottom, ugly trick :P */
275
cairo_move_to (cr, x+radius+xos, y+yos);
276
cairo_arc (cr, x+xos+width-xos*2-radius, y+yos+radius, radius, mpi*1.5, mpi*2);
277
cairo_line_to (cr, x+xos+width-xos*2, y+yos+height-yos*2+3);
278
cairo_line_to (cr, x+xos, y+yos+height-yos*2+3);
279
cairo_arc (cr, x+xos+radius, y+yos+radius, radius, mpi, mpi*1.5);
281
pat = cairo_pattern_create_linear (x+xos, y, x+xos, y+height-yos*2+3);
282
cairo_pattern_add_color_stop_rgba (pat, 0.0, 92/255.0f, 90/255.0f, 85/255.0f, 1.0f);
283
cairo_pattern_add_color_stop_rgba (pat, 1.0, 70/255.0f, 69/255.0f, 66/255.0f, 1.0f);
284
cairo_set_source (cr, pat);
286
cairo_pattern_destroy (pat);