24
24
#include "PlacesStyle.h"
26
NUX_IMPLEMENT_OBJECT_TYPE (PlacesSearchBarSpinner);
26
NUX_IMPLEMENT_OBJECT_TYPE(PlacesSearchBarSpinner);
28
PlacesSearchBarSpinner::PlacesSearchBarSpinner ()
29
: nux::View (NUX_TRACKER_LOCATION),
28
PlacesSearchBarSpinner::PlacesSearchBarSpinner()
29
: nux::View(NUX_TRACKER_LOCATION),
34
PlacesStyle *style = PlacesStyle::GetDefault ();
36
_magnify = style->GetSearchMagnifyIcon ();
37
_close = style->GetSearchCloseIcon ();
38
_close_glow = style->GetSearchCloseGlowIcon ();
39
_spin = style->GetSearchSpinIcon ();
40
_spin_glow = style->GetSearchSpinGlowIcon ();
42
_2d_rotate.Identity ();
43
_2d_rotate.Rotate_z (0.0);
34
PlacesStyle* style = PlacesStyle::GetDefault();
36
_magnify = style->GetSearchMagnifyIcon();
37
_close = style->GetSearchCloseIcon();
38
_close_glow = style->GetSearchCloseGlowIcon();
39
_spin = style->GetSearchSpinIcon();
40
_spin_glow = style->GetSearchSpinGlowIcon();
42
_2d_rotate.Identity();
43
_2d_rotate.Rotate_z(0.0);
46
PlacesSearchBarSpinner::~PlacesSearchBarSpinner ()
46
PlacesSearchBarSpinner::~PlacesSearchBarSpinner()
48
48
if (_spinner_timeout)
49
g_source_remove (_spinner_timeout);
49
g_source_remove(_spinner_timeout);
53
PlacesSearchBarSpinner::ProcessEvent (nux::IEvent &ievent, long TraverseInfo, long ProcessEventInfo)
53
PlacesSearchBarSpinner::ProcessEvent(nux::IEvent& ievent, long TraverseInfo, long ProcessEventInfo)
55
return PostProcessEvent2 (ievent, TraverseInfo, ProcessEventInfo);
55
return PostProcessEvent2(ievent, TraverseInfo, ProcessEventInfo);
59
PlacesSearchBarSpinner::Draw (nux::GraphicsEngine& GfxContext, bool force_draw)
59
PlacesSearchBarSpinner::Draw(nux::GraphicsEngine& GfxContext, bool force_draw)
61
nux::Geometry geo = GetGeometry ();
61
nux::Geometry geo = GetGeometry();
62
62
nux::TexCoordXForm texxform;
64
GfxContext.PushClippingRectangle (geo);
66
nux::GetPainter ().PaintBackground (GfxContext, geo);
68
texxform.SetTexCoordType (nux::TexCoordXForm::OFFSET_COORD);
69
texxform.SetWrap (nux::TEXWRAP_REPEAT, nux::TEXWRAP_REPEAT);
64
GfxContext.PushClippingRectangle(geo);
66
nux::GetPainter().PaintBackground(GfxContext, geo);
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;
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 (),
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(),
81
81
if (_state == STATE_READY)
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 (),
83
GfxContext.QRP_1Tex(geo.x + ((geo.width - _magnify->GetWidth()) / 2),
84
geo.y + ((geo.height - _magnify->GetHeight()) / 2),
86
_magnify->GetHeight(),
87
_magnify->GetDeviceTexture(),
91
91
else if (_state == STATE_SEARCHING)
93
nux::Geometry spin_geo (geo.x + ((geo.width - _spin->GetWidth ())/2),
94
geo.y + ((geo.height - _spin->GetHeight ())/2),
93
nux::Geometry spin_geo(geo.x + ((geo.width - _spin->GetWidth()) / 2),
94
geo.y + ((geo.height - _spin->GetHeight()) / 2),
97
97
int spin_offset_w = (geo.width % 2) ? 0 : 1;
98
98
int spin_offset_h = (geo.height % 2) ? 0 : 1;
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));
106
GfxContext.QRP_1Tex (spin_geo.x,
110
_spin->GetDeviceTexture (),
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));
106
GfxContext.QRP_1Tex(spin_geo.x,
110
_spin->GetDeviceTexture(),
114
GfxContext.PopModelViewMatrix();
115
GfxContext.PopModelViewMatrix();
116
GfxContext.PopModelViewMatrix();
120
texxform.FlipVCoord (true);
121
GfxContext.QRP_1Tex (geo.x + ((geo.width - _spin->GetWidth ())/2),
122
geo.y + ((geo.height - _spin->GetHeight ())/2),
125
_spin->GetDeviceTexture (),
128
texxform.FlipVCoord (false);
130
GfxContext.QRP_1Tex (geo.x + ((geo.width - _spin->GetWidth ())/2),
131
geo.y + ((geo.height - _spin->GetHeight ())/2),
134
_spin->GetDeviceTexture (),
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 (),
147
GfxContext.QRP_1Tex (geo.x + ((geo.width - _close->GetWidth ())/2),
148
geo.y + ((geo.height - _close->GetHeight ())/2),
150
_close->GetHeight (),
151
_close->GetDeviceTexture (),
120
texxform.FlipVCoord(true);
121
GfxContext.QRP_1Tex(geo.x + ((geo.width - _spin->GetWidth()) / 2),
122
geo.y + ((geo.height - _spin->GetHeight()) / 2),
125
_spin->GetDeviceTexture(),
128
texxform.FlipVCoord(false);
130
GfxContext.QRP_1Tex(geo.x + ((geo.width - _spin->GetWidth()) / 2),
131
geo.y + ((geo.height - _spin->GetHeight()) / 2),
134
_spin->GetDeviceTexture(),
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(),
147
GfxContext.QRP_1Tex(geo.x + ((geo.width - _close->GetWidth()) / 2),
148
geo.y + ((geo.height - _close->GetHeight()) / 2),
151
_close->GetDeviceTexture(),
156
GfxContext.PopClippingRectangle ();
156
GfxContext.PopClippingRectangle();
160
PlacesSearchBarSpinner::DrawContent (nux::GraphicsEngine &GfxContext, bool force_draw)
160
PlacesSearchBarSpinner::DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw)
165
PlacesSearchBarSpinner::OnFrame (PlacesSearchBarSpinner *self)
165
PlacesSearchBarSpinner::OnFrame(PlacesSearchBarSpinner* self)
167
167
self->_rotation += 0.1f;
169
169
if (self->_rotation >= 360.0f)
170
170
self->_rotation = 0.0f;
172
self->_2d_rotate.Rotate_z (self->_rotation);
172
self->_2d_rotate.Rotate_z(self->_rotation);
180
PlacesSearchBarSpinner::SetState (SpinnerState state)
180
PlacesSearchBarSpinner::SetState(SpinnerState state)
182
182
if (_state == state)
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;
193
193
if (_state == STATE_SEARCHING)
195
_spinner_timeout = g_timeout_add (15, (GSourceFunc)PlacesSearchBarSpinner::OnFrame, this);
195
_spinner_timeout = g_timeout_add(15, (GSourceFunc)PlacesSearchBarSpinner::OnFrame, this);
202
PlacesSearchBarSpinner::GetName ()
204
return "PlacesSearchBarSpinner";
207
void PlacesSearchBarSpinner::AddProperties (GVariantBuilder *builder)
209
nux::Geometry geo = GetGeometry ();
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()
204
return "PlacesSearchBarSpinner";
207
void PlacesSearchBarSpinner::AddProperties(GVariantBuilder* builder)
209
nux::Geometry geo = GetGeometry();
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));
221
PlacesSearchBarSpinner::AcceptKeyNavFocus()