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/Layout.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));
52
_remote->OnMenuPointerMoved.connect (sigc::mem_fun (this, &PanelView::OnMenuPointerMoved));
55
PanelView::~PanelView ()
62
PanelView::HomeButton ()
68
PanelView::ProcessEvent (nux::IEvent &ievent, long TraverseInfo, long ProcessEventInfo)
70
long ret = TraverseInfo;
71
ret = _layout->ProcessEvent (ievent, ret, ProcessEventInfo);
76
PanelView::Draw (nux::GraphicsEngine& GfxContext, bool force_draw)
78
GfxContext.PushClippingRectangle (GetGeometry() );
80
gPainter.PushDrawLayer (GfxContext, GetGeometry (), _bg_layer);
82
gPainter.PopBackground ();
84
GfxContext.PopClippingRectangle ();
88
PanelView::DrawContent (nux::GraphicsEngine &GfxContext, bool force_draw)
90
GfxContext.PushClippingRectangle (GetGeometry() );
92
gPainter.PushLayer (GfxContext, GetGeometry (), _bg_layer);
94
_layout->ProcessDraw (GfxContext, force_draw);
96
gPainter.PopBackground ();
97
GfxContext.PopClippingRectangle();
101
PanelView::PreLayoutManagement ()
103
nux::View::PreLayoutManagement ();
107
PanelView::PostLayoutManagement (long LayoutResult)
109
// I'm imagining this is a good as time as any to update the background
112
return nux::View::PostLayoutManagement (LayoutResult);
116
PanelView::UpdateBackground ()
118
nux::Geometry geo = GetGeometry ();
120
if (geo.width == _last_width && geo.height == _last_height)
123
_last_width = geo.width;
124
_last_height = geo.height;
126
nux::CairoGraphics cairo_graphics(CAIRO_FORMAT_ARGB32, _last_width, _last_height);
127
cairo_t *cr = cairo_graphics.GetContext();
128
cairo_set_line_width (cr, 1);
130
cairo_pattern_t *pat = cairo_pattern_create_linear (0, 0, 0, _last_height);
131
cairo_pattern_add_color_stop_rgb (pat, 0.0f, 89/255.0f, 88/255.0f, 83/255.0f);
132
cairo_pattern_add_color_stop_rgb (pat, 1.0f, 50/255.0f, 50/255.0f, 45/255.0f);
133
cairo_set_source (cr, pat);
134
cairo_rectangle (cr, 0, 0, _last_width, _last_height);
136
cairo_pattern_destroy (pat);
140
nux::NBitmapData* bitmap = cairo_graphics.GetBitmap();
142
nux::BaseTexture* texture2D = nux::GetThreadGLDeviceFactory ()->CreateSystemCapableTexture ();
143
texture2D->Update(bitmap);
146
nux::TexCoordXForm texxform;
147
texxform.SetTexCoordType (nux::TexCoordXForm::OFFSET_COORD);
148
texxform.SetWrap (nux::TEXWRAP_REPEAT, nux::TEXWRAP_REPEAT);
153
rop.Blend = false; // Disable the blending. By default rop.Blend is false.
154
rop.SrcBlend = GL_SRC_ALPHA; // Set the source blend factor.
155
rop.DstBlend = GL_ONE_MINUS_SRC_ALPHA; // Set the destination blend factor.
157
_bg_layer = new nux::TextureLayer (texture2D->GetDeviceTexture(),
158
texxform, // The Oject that defines the texture wraping and coordinate transformation.
159
nux::Color::White, // The color used to modulate the texture.
160
true, // Write the alpha value of the texture to the destination buffer.
161
rop // Use the given raster operation to set the blending when the layer is being rendered.
164
texture2D->UnReference ();
173
PanelView::OnObjectAdded (IndicatorObjectProxy *proxy)
175
PanelIndicatorObjectView *view = new PanelIndicatorObjectView (proxy);
177
// Appmenu is treated differently as it needs to expand
178
// We could do this in a more special way, but who has the time for special?
179
_layout->AddView (view, (g_strstr_len (proxy->GetName ().c_str (), -1, "appmenu") != NULL), nux::eCenter, nux::eFull);
180
_layout->SetContentDistribution (nux::eStackLeft);
182
this->ComputeChildLayout ();
187
PanelView::OnMenuPointerMoved (int x, int y)
189
nux::Geometry geo = GetGeometry ();
190
nux::Geometry hgeo = _home_button->GetGeometry ();
192
if (x <= (hgeo.x + hgeo.width))
195
if (x > geo.x && x < (geo.x + geo.width)
196
&& y > geo.y && y < (geo.y + geo.height))
198
std::list<Area *>::iterator it;
200
std::list<Area *> my_children = _layout->GetChildren ();
201
for (it = my_children.begin(); it != my_children.end(); it++)
203
PanelIndicatorObjectView *view = static_cast<PanelIndicatorObjectView *> (*it);
205
geo = view->GetGeometry ();
206
if (x > geo.x && x < (geo.x + geo.width)
207
&& y > geo.y && y < (geo.y + geo.height))
209
std::list<Area *>::iterator it2;
211
std::list<Area *> its_children = view->_layout->GetChildren ();
212
for (it2 = its_children.begin(); it2 != its_children.end(); it2++)
214
PanelIndicatorObjectEntryView *entry = static_cast<PanelIndicatorObjectEntryView *> (*it2);
216
geo = entry->GetGeometry ();
217
if (x > geo.x && x < (geo.x + geo.width)
218
&& y > geo.y && y < (geo.y + geo.height))
220
entry->OnMouseDown (x, y, 0, 0);