~om26er/ubuntu/oneiric/unity/sru-778256

« back to all changes in this revision

Viewing changes to plugins/unityshell/src/PlacesSearchBarSpinner.cpp

  • Committer: Didier Roche
  • Date: 2011-07-21 16:17:59 UTC
  • mfrom: (55.813.3 upstream)
  • Revision ID: didier.roche@canonical.com-20110721161759-osmh94x428t2bf2b
* New upstream release.
* debian/control:
  - build-dep on libnotify-dev
  - bump libnux-1.0-dev dep for ABI break

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
 
24
24
#include "PlacesStyle.h"
25
25
 
26
 
NUX_IMPLEMENT_OBJECT_TYPE (PlacesSearchBarSpinner);
 
26
NUX_IMPLEMENT_OBJECT_TYPE(PlacesSearchBarSpinner);
27
27
 
28
 
PlacesSearchBarSpinner::PlacesSearchBarSpinner ()
29
 
: nux::View (NUX_TRACKER_LOCATION),
30
 
  _state (STATE_READY),
31
 
  _rotation (0.0f),
32
 
  _spinner_timeout (0)
 
28
PlacesSearchBarSpinner::PlacesSearchBarSpinner()
 
29
  : nux::View(NUX_TRACKER_LOCATION),
 
30
    _state(STATE_READY),
 
31
    _rotation(0.0f),
 
32
    _spinner_timeout(0)
33
33
{
34
 
  PlacesStyle *style = PlacesStyle::GetDefault ();
35
 
 
36
 
  _magnify = style->GetSearchMagnifyIcon ();
37
 
  _close = style->GetSearchCloseIcon ();
38
 
  _close_glow = style->GetSearchCloseGlowIcon ();
39
 
  _spin = style->GetSearchSpinIcon ();
40
 
  _spin_glow = style->GetSearchSpinGlowIcon ();
41
 
 
42
 
  _2d_rotate.Identity ();
43
 
  _2d_rotate.Rotate_z (0.0);
 
34
  PlacesStyle* style = PlacesStyle::GetDefault();
 
35
 
 
36
  _magnify = style->GetSearchMagnifyIcon();
 
37
  _close = style->GetSearchCloseIcon();
 
38
  _close_glow = style->GetSearchCloseGlowIcon();
 
39
  _spin = style->GetSearchSpinIcon();
 
40
  _spin_glow = style->GetSearchSpinGlowIcon();
 
41
 
 
42
  _2d_rotate.Identity();
 
43
  _2d_rotate.Rotate_z(0.0);
44
44
}
45
45
 
46
 
PlacesSearchBarSpinner::~PlacesSearchBarSpinner ()
 
46
PlacesSearchBarSpinner::~PlacesSearchBarSpinner()
47
47
{
48
48
  if (_spinner_timeout)
49
 
    g_source_remove (_spinner_timeout);
 
49
    g_source_remove(_spinner_timeout);
50
50
}
51
51
 
52
52
long
53
 
PlacesSearchBarSpinner::ProcessEvent (nux::IEvent &ievent, long TraverseInfo, long ProcessEventInfo)
 
53
PlacesSearchBarSpinner::ProcessEvent(nux::IEvent& ievent, long TraverseInfo, long ProcessEventInfo)
54
54
{
55
 
  return PostProcessEvent2 (ievent, TraverseInfo, ProcessEventInfo);
 
55
  return PostProcessEvent2(ievent, TraverseInfo, ProcessEventInfo);
56
56
}
57
57
 
58
58
void
59
 
PlacesSearchBarSpinner::Draw (nux::GraphicsEngine& GfxContext, bool force_draw)
 
59
PlacesSearchBarSpinner::Draw(nux::GraphicsEngine& GfxContext, bool force_draw)
60
60
{
61
 
  nux::Geometry geo = GetGeometry ();
 
61
  nux::Geometry geo = GetGeometry();
62
62
  nux::TexCoordXForm texxform;
63
63
 
64
 
  GfxContext.PushClippingRectangle (geo);
65
 
 
66
 
  nux::GetPainter ().PaintBackground (GfxContext, geo);
67
 
 
68
 
  texxform.SetTexCoordType (nux::TexCoordXForm::OFFSET_COORD);
69
 
  texxform.SetWrap (nux::TEXWRAP_REPEAT, nux::TEXWRAP_REPEAT);
 
64
  GfxContext.PushClippingRectangle(geo);
 
65
 
 
66
  nux::GetPainter().PaintBackground(GfxContext, geo);
 
67
 
 
68
  texxform.SetTexCoordType(nux::TexCoordXForm::OFFSET_COORD);
 
69
  texxform.SetWrap(nux::TEXWRAP_REPEAT, nux::TEXWRAP_REPEAT);
70
70
  texxform.min_filter = nux::TEXFILTER_LINEAR;
71
71
  texxform.mag_filter = nux::TEXFILTER_LINEAR;
72
72
 
73
 
  GfxContext.QRP_1Tex (geo.x + ((geo.width - _spin_glow->GetWidth ())/2),
74
 
                       geo.y + ((geo.height - _spin_glow->GetHeight ())/2),
75
 
                       _spin_glow->GetWidth (),
76
 
                       _spin_glow->GetHeight (),
77
 
                       _spin_glow->GetDeviceTexture (),
78
 
                       texxform,
79
 
                       nux::color::White);
 
73
  GfxContext.QRP_1Tex(geo.x + ((geo.width - _spin_glow->GetWidth()) / 2),
 
74
                      geo.y + ((geo.height - _spin_glow->GetHeight()) / 2),
 
75
                      _spin_glow->GetWidth(),
 
76
                      _spin_glow->GetHeight(),
 
77
                      _spin_glow->GetDeviceTexture(),
 
78
                      texxform,
 
79
                      nux::color::White);
80
80
 
81
81
  if (_state == STATE_READY)
82
82
  {
83
 
    GfxContext.QRP_1Tex (geo.x + ((geo.width - _magnify->GetWidth ())/2),
84
 
                         geo.y + ((geo.height - _magnify->GetHeight ())/2),
85
 
                         _magnify->GetWidth (),
86
 
                         _magnify->GetHeight (),
87
 
                         _magnify->GetDeviceTexture (),
88
 
                         texxform,
89
 
                         nux::color::White);
 
83
    GfxContext.QRP_1Tex(geo.x + ((geo.width - _magnify->GetWidth()) / 2),
 
84
                        geo.y + ((geo.height - _magnify->GetHeight()) / 2),
 
85
                        _magnify->GetWidth(),
 
86
                        _magnify->GetHeight(),
 
87
                        _magnify->GetDeviceTexture(),
 
88
                        texxform,
 
89
                        nux::color::White);
90
90
  }
91
91
  else if (_state == STATE_SEARCHING)
92
92
  {
93
 
    nux::Geometry spin_geo (geo.x + ((geo.width - _spin->GetWidth ())/2),
94
 
                             geo.y + ((geo.height - _spin->GetHeight ())/2),
95
 
                             _spin->GetWidth (),
96
 
                             _spin->GetHeight ());
 
93
    nux::Geometry spin_geo(geo.x + ((geo.width - _spin->GetWidth()) / 2),
 
94
                           geo.y + ((geo.height - _spin->GetHeight()) / 2),
 
95
                           _spin->GetWidth(),
 
96
                           _spin->GetHeight());
97
97
    int spin_offset_w = (geo.width % 2) ? 0 : 1;
98
98
    int spin_offset_h = (geo.height % 2) ? 0 : 1;
99
99
 
100
 
    GfxContext.PushModelViewMatrix (nux::Matrix4::TRANSLATE(-spin_geo.x - (spin_geo.width + spin_offset_w) / 2.0f,
101
 
                                    -spin_geo.y - (spin_geo.height + spin_offset_h) / 2.0f, 0));
102
 
    GfxContext.PushModelViewMatrix (_2d_rotate);    
103
 
    GfxContext.PushModelViewMatrix (nux::Matrix4::TRANSLATE(spin_geo.x + (spin_geo.width + spin_offset_w)/ 2.0f,
104
 
                                    spin_geo.y + (spin_geo.height + spin_offset_h) / 2.0f, 0));
105
 
 
106
 
    GfxContext.QRP_1Tex (spin_geo.x,
107
 
                         spin_geo.y,
108
 
                         spin_geo.width,
109
 
                         spin_geo.height,
110
 
                         _spin->GetDeviceTexture (),
111
 
                         texxform,
112
 
                         nux::color::White);
113
 
 
114
 
    GfxContext.PopModelViewMatrix ();
115
 
    GfxContext.PopModelViewMatrix ();
116
 
    GfxContext.PopModelViewMatrix ();
 
100
    GfxContext.PushModelViewMatrix(nux::Matrix4::TRANSLATE(-spin_geo.x - (spin_geo.width + spin_offset_w) / 2.0f,
 
101
                                                           -spin_geo.y - (spin_geo.height + spin_offset_h) / 2.0f, 0));
 
102
    GfxContext.PushModelViewMatrix(_2d_rotate);
 
103
    GfxContext.PushModelViewMatrix(nux::Matrix4::TRANSLATE(spin_geo.x + (spin_geo.width + spin_offset_w) / 2.0f,
 
104
                                                           spin_geo.y + (spin_geo.height + spin_offset_h) / 2.0f, 0));
 
105
 
 
106
    GfxContext.QRP_1Tex(spin_geo.x,
 
107
                        spin_geo.y,
 
108
                        spin_geo.width,
 
109
                        spin_geo.height,
 
110
                        _spin->GetDeviceTexture(),
 
111
                        texxform,
 
112
                        nux::color::White);
 
113
 
 
114
    GfxContext.PopModelViewMatrix();
 
115
    GfxContext.PopModelViewMatrix();
 
116
    GfxContext.PopModelViewMatrix();
117
117
  }
118
118
  else
119
119
  {
120
 
    texxform.FlipVCoord (true);
121
 
    GfxContext.QRP_1Tex (geo.x + ((geo.width - _spin->GetWidth ())/2),
122
 
                         geo.y + ((geo.height - _spin->GetHeight ())/2),
123
 
                         _spin->GetWidth (),
124
 
                         _spin->GetHeight (),
125
 
                         _spin->GetDeviceTexture (),
126
 
                         texxform,
127
 
                         nux::color::White);
128
 
    texxform.FlipVCoord (false);
129
 
 
130
 
    GfxContext.QRP_1Tex (geo.x + ((geo.width - _spin->GetWidth ())/2),
131
 
                         geo.y + ((geo.height - _spin->GetHeight ())/2),
132
 
                         _spin->GetWidth (),
133
 
                         _spin->GetHeight (),
134
 
                         _spin->GetDeviceTexture (),
135
 
                         texxform,
136
 
                         nux::color::White);
137
 
 
138
 
 
139
 
    GfxContext.QRP_1Tex (geo.x + ((geo.width - _close_glow->GetWidth ())/2),
140
 
                         geo.y + ((geo.height - _close_glow->GetHeight ())/2),
141
 
                         _close_glow->GetWidth (),
142
 
                         _close_glow->GetHeight (),
143
 
                         _close_glow->GetDeviceTexture (),
144
 
                         texxform,
145
 
                         nux::color::White);
146
 
 
147
 
    GfxContext.QRP_1Tex (geo.x + ((geo.width - _close->GetWidth ())/2),
148
 
                         geo.y + ((geo.height - _close->GetHeight ())/2),
149
 
                         _close->GetWidth (),
150
 
                         _close->GetHeight (),
151
 
                         _close->GetDeviceTexture (),
152
 
                         texxform,
153
 
                         nux::color::White);
 
120
    texxform.FlipVCoord(true);
 
121
    GfxContext.QRP_1Tex(geo.x + ((geo.width - _spin->GetWidth()) / 2),
 
122
                        geo.y + ((geo.height - _spin->GetHeight()) / 2),
 
123
                        _spin->GetWidth(),
 
124
                        _spin->GetHeight(),
 
125
                        _spin->GetDeviceTexture(),
 
126
                        texxform,
 
127
                        nux::color::White);
 
128
    texxform.FlipVCoord(false);
 
129
 
 
130
    GfxContext.QRP_1Tex(geo.x + ((geo.width - _spin->GetWidth()) / 2),
 
131
                        geo.y + ((geo.height - _spin->GetHeight()) / 2),
 
132
                        _spin->GetWidth(),
 
133
                        _spin->GetHeight(),
 
134
                        _spin->GetDeviceTexture(),
 
135
                        texxform,
 
136
                        nux::color::White);
 
137
 
 
138
 
 
139
    GfxContext.QRP_1Tex(geo.x + ((geo.width - _close_glow->GetWidth()) / 2),
 
140
                        geo.y + ((geo.height - _close_glow->GetHeight()) / 2),
 
141
                        _close_glow->GetWidth(),
 
142
                        _close_glow->GetHeight(),
 
143
                        _close_glow->GetDeviceTexture(),
 
144
                        texxform,
 
145
                        nux::color::White);
 
146
 
 
147
    GfxContext.QRP_1Tex(geo.x + ((geo.width - _close->GetWidth()) / 2),
 
148
                        geo.y + ((geo.height - _close->GetHeight()) / 2),
 
149
                        _close->GetWidth(),
 
150
                        _close->GetHeight(),
 
151
                        _close->GetDeviceTexture(),
 
152
                        texxform,
 
153
                        nux::color::White);
154
154
  }
155
155
 
156
 
  GfxContext.PopClippingRectangle ();
 
156
  GfxContext.PopClippingRectangle();
157
157
}
158
158
 
159
159
void
160
 
PlacesSearchBarSpinner::DrawContent (nux::GraphicsEngine &GfxContext, bool force_draw)
 
160
PlacesSearchBarSpinner::DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw)
161
161
{
162
162
}
163
163
 
164
164
gboolean
165
 
PlacesSearchBarSpinner::OnFrame (PlacesSearchBarSpinner *self)
 
165
PlacesSearchBarSpinner::OnFrame(PlacesSearchBarSpinner* self)
166
166
{
167
167
  self->_rotation += 0.1f;
168
168
 
169
169
  if (self->_rotation >= 360.0f)
170
170
    self->_rotation = 0.0f;
171
171
 
172
 
  self->_2d_rotate.Rotate_z (self->_rotation);
 
172
  self->_2d_rotate.Rotate_z(self->_rotation);
173
173
 
174
 
  self->QueueDraw ();
 
174
  self->QueueDraw();
175
175
 
176
176
  return TRUE;
177
177
}
178
178
 
179
179
void
180
 
PlacesSearchBarSpinner::SetState (SpinnerState state)
 
180
PlacesSearchBarSpinner::SetState(SpinnerState state)
181
181
{
182
182
  if (_state == state)
183
183
    return;
185
185
  _state = state;
186
186
 
187
187
  if (_spinner_timeout)
188
 
    g_source_remove (_spinner_timeout);
 
188
    g_source_remove(_spinner_timeout);
189
189
  _spinner_timeout = 0;
190
 
  _2d_rotate.Rotate_z (0.0f);
 
190
  _2d_rotate.Rotate_z(0.0f);
191
191
  _rotation = 0.0f;
192
192
 
193
193
  if (_state == STATE_SEARCHING)
194
194
  {
195
 
    _spinner_timeout = g_timeout_add (15, (GSourceFunc)PlacesSearchBarSpinner::OnFrame, this);
 
195
    _spinner_timeout = g_timeout_add(15, (GSourceFunc)PlacesSearchBarSpinner::OnFrame, this);
196
196
  }
197
197
 
198
 
  QueueDraw ();
 
198
  QueueDraw();
199
199
}
200
200
 
201
201
const gchar*
202
 
PlacesSearchBarSpinner::GetName ()
203
 
{
204
 
        return "PlacesSearchBarSpinner";
205
 
}
206
 
 
207
 
void PlacesSearchBarSpinner::AddProperties (GVariantBuilder *builder)
208
 
{
209
 
  nux::Geometry geo = GetGeometry ();
210
 
 
211
 
  g_variant_builder_add (builder, "{sv}", "x", g_variant_new_int32 (geo.x));
212
 
  g_variant_builder_add (builder, "{sv}", "y", g_variant_new_int32 (geo.y));
213
 
  g_variant_builder_add (builder, "{sv}", "width", g_variant_new_int32 (geo.width));
214
 
  g_variant_builder_add (builder, "{sv}", "height", g_variant_new_int32 (geo.height));
 
202
PlacesSearchBarSpinner::GetName()
 
203
{
 
204
  return "PlacesSearchBarSpinner";
 
205
}
 
206
 
 
207
void PlacesSearchBarSpinner::AddProperties(GVariantBuilder* builder)
 
208
{
 
209
  nux::Geometry geo = GetGeometry();
 
210
 
 
211
  g_variant_builder_add(builder, "{sv}", "x", g_variant_new_int32(geo.x));
 
212
  g_variant_builder_add(builder, "{sv}", "y", g_variant_new_int32(geo.y));
 
213
  g_variant_builder_add(builder, "{sv}", "width", g_variant_new_int32(geo.width));
 
214
  g_variant_builder_add(builder, "{sv}", "height", g_variant_new_int32(geo.height));
 
215
}
 
216
 
 
217
//
 
218
// Key navigation
 
219
//
 
220
bool
 
221
PlacesSearchBarSpinner::AcceptKeyNavFocus()
 
222
{
 
223
  return false;
215
224
}