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/BaseWindow.h>
21
#include <Nux/HLayout.h>
22
#include <Nux/VLayout.h>
23
#include <Nux/WindowCompositor.h>
25
#include <NuxImage/CairoGraphics.h>
26
#include <NuxImage/ImageSurface.h>
28
#include <NuxGraphics/GLThread.h>
29
#include <NuxGraphics/RenderingPipe.h>
33
#include "PanelView.h"
35
#include "IndicatorObjectFactoryRemote.h"
36
#include "PanelIndicatorObjectView.h"
38
PanelView::PanelView (NUX_FILE_LINE_DECL)
39
: View (NUX_FILE_LINE_PARAM)
41
_bg_layer = new nux::ColorLayer (nux::Color (0xff595853), true);
43
_layout = new nux::HLayout ("", NUX_TRACKER_LOCATION);
44
SetCompositionLayout (_layout);
47
_home_button = new PanelHomeButton ();
48
_layout->AddView (_home_button, 0, nux::eCenter, nux::eFull);
50
_remote = new IndicatorObjectFactoryRemote ();
51
_remote->OnObjectAdded.connect (sigc::mem_fun (this, &PanelView::OnObjectAdded));
54
PanelView::~PanelView ()
61
PanelView::ProcessEvent (nux::IEvent &ievent, long TraverseInfo, long ProcessEventInfo)
63
long ret = TraverseInfo;
64
ret = _layout->ProcessEvent (ievent, ret, ProcessEventInfo);
69
PanelView::Draw (nux::GraphicsContext& GfxContext, bool force_draw)
71
GfxContext.PushClippingRectangle (GetGeometry() );
73
gPainter.PushDrawLayer (GfxContext, GetGeometry (), _bg_layer);
75
gPainter.PopBackground ();
77
GfxContext.PopClippingRectangle ();
81
PanelView::DrawContent (nux::GraphicsContext &GfxContext, bool force_draw)
83
GfxContext.PushClippingRectangle (GetGeometry() );
85
gPainter.PushLayer (GfxContext, GetGeometry (), _bg_layer);
87
_layout->ProcessDraw (GfxContext, force_draw);
89
gPainter.PopBackground ();
90
GfxContext.PopClippingRectangle();
94
PanelView::PreLayoutManagement ()
96
nux::View::PreLayoutManagement ();
100
PanelView::PostLayoutManagement (long LayoutResult)
102
// I'm imagining this is a good as time as any to update the background
105
return nux::View::PostLayoutManagement (LayoutResult);
109
PanelView::UpdateBackground ()
111
nux::Geometry geo = GetGeometry ();
113
if (geo.width == _last_width && geo.height == _last_height)
116
_last_width = geo.width;
117
_last_height = geo.height;
119
nux::CairoGraphics cairo_graphics(CAIRO_FORMAT_ARGB32, _last_width, _last_height);
120
cairo_t *cr = cairo_graphics.GetContext();
121
cairo_set_line_width (cr, 1);
123
cairo_pattern_t *pat = cairo_pattern_create_linear (0, 0, 0, _last_height);
124
cairo_pattern_add_color_stop_rgb (pat, 0.0f, 89/255.0f, 88/255.0f, 83/255.0f);
125
cairo_pattern_add_color_stop_rgb (pat, 1.0f, 50/255.0f, 50/255.0f, 45/255.0f);
126
cairo_set_source (cr, pat);
127
cairo_rectangle (cr, 0, 0, _last_width, _last_height);
129
cairo_pattern_destroy (pat);
133
nux::NBitmapData* bitmap = cairo_graphics.GetBitmap();
135
nux::BaseTexture* texture2D = nux::GetThreadGLDeviceFactory ()->CreateSystemCapableTexture ();
136
texture2D->Update(bitmap);
139
nux::TexCoordXForm texxform;
140
texxform.SetTexCoordType (nux::TexCoordXForm::OFFSET_COORD);
141
texxform.SetWrap (nux::TEXWRAP_REPEAT, nux::TEXWRAP_REPEAT);
146
rop.Blend = false; // Disable the blending. By default rop.Blend is false.
147
rop.SrcBlend = GL_SRC_ALPHA; // Set the source blend factor.
148
rop.DstBlend = GL_ONE_MINUS_SRC_ALPHA; // Set the destination blend factor.
150
_bg_layer = new nux::TextureLayer (texture2D->GetDeviceTexture(),
151
texxform, // The Oject that defines the texture wraping and coordinate transformation.
152
nux::Color::White, // The color used to modulate the texture.
153
true, // Write the alpha value of the texture to the destination buffer.
154
rop // Use the given raster operation to set the blending when the layer is being rendered.
166
PanelView::OnObjectAdded (IndicatorObjectProxy *proxy)
168
PanelIndicatorObjectView *view = new PanelIndicatorObjectView (proxy);
170
// Appmenu is treated differently as it needs to expand
171
// We could do this in a more special way, but who has the time for special?
172
_layout->AddView (view, (g_strstr_len (proxy->GetName ().c_str (), -1, "appmenu") != NULL), nux::eCenter, nux::eFull);
173
_layout->SetContentDistribution (nux::eStackLeft);
175
this->ComputeChildLayout ();