~didrocks/unity/launcher-bug-fix-fest

« back to all changes in this revision

Viewing changes to src/PanelView.cpp

Import the work done so far with Compiz

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
#include <Nux/BaseWindow.h>
 
21
#include <Nux/HLayout.h>
 
22
#include <Nux/VLayout.h>
 
23
#include <Nux/WindowCompositor.h>
 
24
 
 
25
#include <NuxImage/CairoGraphics.h>
 
26
#include <NuxImage/ImageSurface.h>
 
27
 
 
28
#include <NuxGraphics/GLThread.h>
 
29
#include <NuxGraphics/RenderingPipe.h>
 
30
 
 
31
#include <glib.h>
 
32
 
 
33
#include "PanelView.h"
 
34
 
 
35
#include "IndicatorObjectFactoryRemote.h"
 
36
#include "PanelIndicatorObjectView.h"
 
37
 
 
38
PanelView::PanelView (NUX_FILE_LINE_DECL)
 
39
:   View (NUX_FILE_LINE_PARAM)
 
40
{
 
41
  _bg_layer = new nux::ColorLayer (nux::Color (0xff595853), true);
 
42
 
 
43
  _layout = new nux::HLayout ("", NUX_TRACKER_LOCATION);
 
44
   SetCompositionLayout (_layout);
 
45
 
 
46
   // Home button
 
47
   _home_button = new PanelHomeButton ();
 
48
   _layout->AddView (_home_button, 0, nux::eCenter, nux::eFull);
 
49
 
 
50
  _remote = new IndicatorObjectFactoryRemote ();
 
51
  _remote->OnObjectAdded.connect (sigc::mem_fun (this, &PanelView::OnObjectAdded));
 
52
}
 
53
 
 
54
PanelView::~PanelView ()
 
55
{
 
56
  delete _remote;
 
57
  delete _bg_layer;
 
58
}
 
59
 
 
60
long
 
61
PanelView::ProcessEvent (nux::IEvent &ievent, long TraverseInfo, long ProcessEventInfo)
 
62
{
 
63
  long ret = TraverseInfo;
 
64
  ret = _layout->ProcessEvent (ievent, ret, ProcessEventInfo);
 
65
  return ret;
 
66
}
 
67
 
 
68
void
 
69
PanelView::Draw (nux::GraphicsContext& GfxContext, bool force_draw)
 
70
{
 
71
  GfxContext.PushClippingRectangle (GetGeometry() );
 
72
 
 
73
  gPainter.PushDrawLayer (GfxContext, GetGeometry (), _bg_layer);
 
74
 
 
75
  gPainter.PopBackground ();
 
76
 
 
77
  GfxContext.PopClippingRectangle ();
 
78
}
 
79
 
 
80
void
 
81
PanelView::DrawContent (nux::GraphicsContext &GfxContext, bool force_draw)
 
82
{
 
83
  GfxContext.PushClippingRectangle (GetGeometry() );
 
84
 
 
85
  gPainter.PushLayer (GfxContext, GetGeometry (), _bg_layer);
 
86
  
 
87
  _layout->ProcessDraw (GfxContext, force_draw);
 
88
 
 
89
  gPainter.PopBackground ();
 
90
  GfxContext.PopClippingRectangle();
 
91
}
 
92
 
 
93
void
 
94
PanelView::PreLayoutManagement ()
 
95
{
 
96
  nux::View::PreLayoutManagement ();
 
97
}
 
98
 
 
99
long
 
100
PanelView::PostLayoutManagement (long LayoutResult)
 
101
{
 
102
  // I'm imagining this is a good as time as any to update the background
 
103
  UpdateBackground ();
 
104
 
 
105
  return nux::View::PostLayoutManagement (LayoutResult);
 
106
}
 
107
 
 
108
void
 
109
PanelView::UpdateBackground ()
 
110
{
 
111
  nux::Geometry geo = GetGeometry ();
 
112
 
 
113
  if (geo.width == _last_width && geo.height == _last_height)
 
114
    return;
 
115
 
 
116
  _last_width = geo.width;
 
117
  _last_height = geo.height;
 
118
 
 
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);
 
122
 
 
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);
 
128
  cairo_fill (cr);
 
129
  cairo_pattern_destroy (pat);
 
130
 
 
131
  cairo_destroy (cr);
 
132
 
 
133
  nux::NBitmapData* bitmap =  cairo_graphics.GetBitmap();
 
134
 
 
135
  nux::BaseTexture* texture2D = nux::GetThreadGLDeviceFactory ()->CreateSystemCapableTexture ();
 
136
  texture2D->Update(bitmap);
 
137
  delete bitmap;
 
138
 
 
139
  nux::TexCoordXForm texxform;
 
140
  texxform.SetTexCoordType (nux::TexCoordXForm::OFFSET_COORD);
 
141
  texxform.SetWrap (nux::TEXWRAP_REPEAT, nux::TEXWRAP_REPEAT);
 
142
  if (_bg_layer)
 
143
    delete _bg_layer;
 
144
 
 
145
  nux::ROPConfig rop;
 
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.
 
149
  
 
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.
 
155
  );
 
156
 
 
157
  delete texture2D;
 
158
 
 
159
  NeedRedraw ();
 
160
}
 
161
 
 
162
//
 
163
// Signals
 
164
//
 
165
void
 
166
PanelView::OnObjectAdded (IndicatorObjectProxy *proxy)
 
167
{
 
168
  PanelIndicatorObjectView *view = new PanelIndicatorObjectView (proxy);
 
169
 
 
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);
 
174
 
 
175
  this->ComputeChildLayout (); 
 
176
  NeedRedraw ();
 
177
}