~ken-vandine/unity/make-quicklists-work-again

« back to all changes in this revision

Viewing changes to src/PanelView.cpp

  • Committer: Neil Jagdish Patel
  • Date: 2010-11-11 18:51:08 UTC
  • mfrom: (572.1.58 unity-3.0)
  • Revision ID: neil.patel@canonical.com-20101111185108-71923a90txzvxbit
[merge] Unity 3

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/Layout.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
  _remote->OnMenuPointerMoved.connect (sigc::mem_fun (this, &PanelView::OnMenuPointerMoved));
 
53
}
 
54
 
 
55
PanelView::~PanelView ()
 
56
{
 
57
  delete _remote;
 
58
  delete _bg_layer;
 
59
}
 
60
 
 
61
PanelHomeButton * 
 
62
PanelView::HomeButton ()
 
63
{
 
64
  return _home_button;
 
65
}
 
66
 
 
67
long
 
68
PanelView::ProcessEvent (nux::IEvent &ievent, long TraverseInfo, long ProcessEventInfo)
 
69
{
 
70
  long ret = TraverseInfo;
 
71
  ret = _layout->ProcessEvent (ievent, ret, ProcessEventInfo);
 
72
  return ret;
 
73
}
 
74
 
 
75
void
 
76
PanelView::Draw (nux::GraphicsEngine& GfxContext, bool force_draw)
 
77
{
 
78
  GfxContext.PushClippingRectangle (GetGeometry() );
 
79
 
 
80
  gPainter.PushDrawLayer (GfxContext, GetGeometry (), _bg_layer);
 
81
 
 
82
  gPainter.PopBackground ();
 
83
 
 
84
  GfxContext.PopClippingRectangle ();
 
85
}
 
86
 
 
87
void
 
88
PanelView::DrawContent (nux::GraphicsEngine &GfxContext, bool force_draw)
 
89
{
 
90
  GfxContext.PushClippingRectangle (GetGeometry() );
 
91
 
 
92
  gPainter.PushLayer (GfxContext, GetGeometry (), _bg_layer);
 
93
  
 
94
  _layout->ProcessDraw (GfxContext, force_draw);
 
95
 
 
96
  gPainter.PopBackground ();
 
97
  GfxContext.PopClippingRectangle();
 
98
}
 
99
 
 
100
void
 
101
PanelView::PreLayoutManagement ()
 
102
{
 
103
  nux::View::PreLayoutManagement ();
 
104
}
 
105
 
 
106
long
 
107
PanelView::PostLayoutManagement (long LayoutResult)
 
108
{
 
109
  // I'm imagining this is a good as time as any to update the background
 
110
  UpdateBackground ();
 
111
 
 
112
  return nux::View::PostLayoutManagement (LayoutResult);
 
113
}
 
114
 
 
115
void
 
116
PanelView::UpdateBackground ()
 
117
{
 
118
  nux::Geometry geo = GetGeometry ();
 
119
 
 
120
  if (geo.width == _last_width && geo.height == _last_height)
 
121
    return;
 
122
 
 
123
  _last_width = geo.width;
 
124
  _last_height = geo.height;
 
125
 
 
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);
 
129
 
 
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);
 
135
  cairo_fill (cr);
 
136
  cairo_pattern_destroy (pat);
 
137
 
 
138
  cairo_destroy (cr);
 
139
 
 
140
  nux::NBitmapData* bitmap =  cairo_graphics.GetBitmap();
 
141
 
 
142
  nux::BaseTexture* texture2D = nux::GetThreadGLDeviceFactory ()->CreateSystemCapableTexture ();
 
143
  texture2D->Update(bitmap);
 
144
  delete bitmap;
 
145
 
 
146
  nux::TexCoordXForm texxform;
 
147
  texxform.SetTexCoordType (nux::TexCoordXForm::OFFSET_COORD);
 
148
  texxform.SetWrap (nux::TEXWRAP_REPEAT, nux::TEXWRAP_REPEAT);
 
149
  if (_bg_layer)
 
150
    delete _bg_layer;
 
151
 
 
152
  nux::ROPConfig rop;
 
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.
 
156
  
 
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.
 
162
  );
 
163
 
 
164
  texture2D->UnReference ();
 
165
 
 
166
  NeedRedraw ();
 
167
}
 
168
 
 
169
//
 
170
// Signals
 
171
//
 
172
void
 
173
PanelView::OnObjectAdded (IndicatorObjectProxy *proxy)
 
174
{
 
175
  PanelIndicatorObjectView *view = new PanelIndicatorObjectView (proxy);
 
176
 
 
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);
 
181
 
 
182
  this->ComputeChildLayout (); 
 
183
  NeedRedraw ();
 
184
}
 
185
 
 
186
void
 
187
PanelView::OnMenuPointerMoved (int x, int y)
 
188
{
 
189
  nux::Geometry geo = GetGeometry ();
 
190
  nux::Geometry hgeo = _home_button->GetGeometry ();
 
191
 
 
192
  if (x <= (hgeo.x + hgeo.width))
 
193
    return; 
 
194
  
 
195
  if (x > geo.x && x < (geo.x + geo.width)
 
196
      && y > geo.y && y < (geo.y + geo.height))
 
197
    {
 
198
      std::list<Area *>::iterator it;
 
199
 
 
200
      std::list<Area *> my_children = _layout->GetChildren ();
 
201
      for (it = my_children.begin(); it != my_children.end(); it++)
 
202
      {
 
203
        PanelIndicatorObjectView *view = static_cast<PanelIndicatorObjectView *> (*it);
 
204
 
 
205
        geo = view->GetGeometry ();
 
206
        if (x > geo.x && x < (geo.x + geo.width)
 
207
            && y > geo.y && y < (geo.y + geo.height))
 
208
          {
 
209
            std::list<Area *>::iterator it2;
 
210
 
 
211
            std::list<Area *> its_children = view->_layout->GetChildren ();
 
212
            for (it2 = its_children.begin(); it2 != its_children.end(); it2++)
 
213
            {
 
214
              PanelIndicatorObjectEntryView *entry = static_cast<PanelIndicatorObjectEntryView *> (*it2);
 
215
 
 
216
              geo = entry->GetGeometry ();
 
217
              if (x > geo.x && x < (geo.x + geo.width)
 
218
                  && y > geo.y && y < (geo.y + geo.height))
 
219
                {
 
220
                  entry->OnMouseDown (x, y, 0, 0);
 
221
                  break;
 
222
                }
 
223
            }
 
224
            break;
 
225
          }
 
226
      }
 
227
    }
 
228
}