summaryrefslogtreecommitdiff
path: root/unity-shared
diff options
Diffstat (limited to 'unity-shared')
-rw-r--r--unity-shared/SearchBarSpinner.cpp105
-rw-r--r--unity-shared/SearchBarSpinner.h22
2 files changed, 72 insertions, 55 deletions
diff --git a/unity-shared/SearchBarSpinner.cpp b/unity-shared/SearchBarSpinner.cpp
index 6e1dbaec2..645e64a76 100644
--- a/unity-shared/SearchBarSpinner.cpp
+++ b/unity-shared/SearchBarSpinner.cpp
@@ -31,18 +31,19 @@ NUX_IMPLEMENT_OBJECT_TYPE(SearchBarSpinner);
SearchBarSpinner::SearchBarSpinner()
: nux::View(NUX_TRACKER_LOCATION),
- _state(STATE_READY),
- _rotation(0.0f)
+ state_(STATE_READY),
+ search_timeout_(-1),
+ rotation_(0.0f)
{
dash::Style& style = dash::Style::Instance();
- _magnify = style.GetSearchMagnifyIcon();
- _circle = style.GetSearchCircleIcon();
- _close = style.GetSearchCloseIcon();
- _spin = style.GetSearchSpinIcon();
+ magnify_ = style.GetSearchMagnifyIcon();
+ circle_ = style.GetSearchCircleIcon();
+ close_ = style.GetSearchCloseIcon();
+ spin_ = style.GetSearchSpinIcon();
- _2d_rotate.Identity();
- _2d_rotate.Rotate_z(0.0);
+ rotate_.Identity();
+ rotate_.Rotate_z(0.0);
}
void
@@ -66,22 +67,22 @@ SearchBarSpinner::Draw(nux::GraphicsEngine& GfxContext, bool force_draw)
GfxContext.GetRenderStates().GetBlend(current_alpha_blend, current_src_blend_factor, current_dest_blend_factor);
GfxContext.GetRenderStates().SetBlend(true, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
- if (_state == STATE_READY)
+ if (state_ == STATE_READY)
{
- GfxContext.QRP_1Tex(geo.x + ((geo.width - _magnify->GetWidth()) / 2),
- geo.y + ((geo.height - _magnify->GetHeight()) / 2),
- _magnify->GetWidth(),
- _magnify->GetHeight(),
- _magnify->GetDeviceTexture(),
+ GfxContext.QRP_1Tex(geo.x + ((geo.width - magnify_->GetWidth()) / 2),
+ geo.y + ((geo.height - magnify_->GetHeight()) / 2),
+ magnify_->GetWidth(),
+ magnify_->GetHeight(),
+ magnify_->GetDeviceTexture(),
texxform,
nux::color::White);
}
- else if (_state == STATE_SEARCHING)
+ else if (state_ == STATE_SEARCHING)
{
- nux::Geometry spin_geo(geo.x + ((geo.width - _spin->GetWidth()) / 2),
- geo.y + ((geo.height - _spin->GetHeight()) / 2),
- _spin->GetWidth(),
- _spin->GetHeight());
+ nux::Geometry spin_geo(geo.x + ((geo.width - spin_->GetWidth()) / 2),
+ geo.y + ((geo.height - spin_->GetHeight()) / 2),
+ spin_->GetWidth(),
+ spin_->GetHeight());
// Geometry (== Rect) uses integers which were rounded above,
// hence an extra 0.5 offset for odd sizes is needed
// because pure floating point is not being used.
@@ -91,7 +92,7 @@ SearchBarSpinner::Draw(nux::GraphicsEngine& GfxContext, bool force_draw)
nux::Matrix4 matrix_texture;
matrix_texture = nux::Matrix4::TRANSLATE(-spin_geo.x - (spin_geo.width + spin_offset_w) / 2.0f,
-spin_geo.y - (spin_geo.height + spin_offset_h) / 2.0f, 0) * matrix_texture;
- matrix_texture = _2d_rotate * matrix_texture;
+ matrix_texture = rotate_ * matrix_texture;
matrix_texture = nux::Matrix4::TRANSLATE(spin_geo.x + (spin_geo.width + spin_offset_w) / 2.0f,
spin_geo.y + (spin_geo.height + spin_offset_h) / 2.0f, 0) * matrix_texture;
@@ -101,7 +102,7 @@ SearchBarSpinner::Draw(nux::GraphicsEngine& GfxContext, bool force_draw)
spin_geo.y,
spin_geo.width,
spin_geo.height,
- _spin->GetDeviceTexture(),
+ spin_->GetDeviceTexture(),
texxform,
nux::color::White);
@@ -110,19 +111,19 @@ SearchBarSpinner::Draw(nux::GraphicsEngine& GfxContext, bool force_draw)
}
else
{
- GfxContext.QRP_1Tex(geo.x + ((geo.width - _circle->GetWidth()) / 2),
- geo.y + ((geo.height - _circle->GetHeight()) / 2),
- _circle->GetWidth(),
- _circle->GetHeight(),
- _circle->GetDeviceTexture(),
+ GfxContext.QRP_1Tex(geo.x + ((geo.width - circle_->GetWidth()) / 2),
+ geo.y + ((geo.height - circle_->GetHeight()) / 2),
+ circle_->GetWidth(),
+ circle_->GetHeight(),
+ circle_->GetDeviceTexture(),
texxform,
nux::color::White);
- GfxContext.QRP_1Tex(geo.x + ((geo.width - _close->GetWidth()) / 2),
- geo.y + ((geo.height - _close->GetHeight()) / 2),
- _close->GetWidth(),
- _close->GetHeight(),
- _close->GetDeviceTexture(),
+ GfxContext.QRP_1Tex(geo.x + ((geo.width - close_->GetWidth()) / 2),
+ geo.y + ((geo.height - close_->GetHeight()) / 2),
+ close_->GetWidth(),
+ close_->GetHeight(),
+ close_->GetDeviceTexture(),
texxform,
nux::color::White);
}
@@ -130,9 +131,9 @@ SearchBarSpinner::Draw(nux::GraphicsEngine& GfxContext, bool force_draw)
GfxContext.GetRenderStates().SetBlend(current_alpha_blend, current_src_blend_factor, current_dest_blend_factor);
- if (_state == STATE_SEARCHING && !_frame_timeout)
+ if (state_ == STATE_SEARCHING && !frame_timeout_)
{
- _frame_timeout.reset(new glib::Timeout(22, sigc::mem_fun(this, &SearchBarSpinner::OnFrameTimeout)));
+ frame_timeout_.reset(new glib::Timeout(22, sigc::mem_fun(this, &SearchBarSpinner::OnFrameTimeout)));
}
}
@@ -144,33 +145,39 @@ SearchBarSpinner::DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw)
bool
SearchBarSpinner::OnFrameTimeout()
{
- _rotation += 0.1f;
+ rotation_ += 0.1f;
- if (_rotation >= 360.0f)
- _rotation = 0.0f;
+ if (rotation_ >= 360.0f)
+ rotation_ = 0.0f;
- _2d_rotate.Rotate_z(_rotation);
+ rotate_.Rotate_z(rotation_);
QueueDraw();
- _frame_timeout.reset();
+ frame_timeout_.reset();
return false;
}
void
+SearchBarSpinner::SetSpinnerTimeout(int timeout)
+{
+ search_timeout_ = timeout;
+}
+
+void
SearchBarSpinner::SetState(SpinnerState state)
{
- if (_state == state)
+ if (state_ == state)
return;
- _state = state;
- _spinner_timeout.reset();
- _2d_rotate.Rotate_z(0.0f);
- _rotation = 0.0f;
+ state_ = state;
+ spinner_timeout_.reset();
+ rotate_.Rotate_z(0.0f);
+ rotation_ = 0.0f;
- if (_state == STATE_SEARCHING)
+ if (search_timeout_ > 0 && state_== STATE_SEARCHING)
{
- _spinner_timeout.reset(new glib::TimeoutSeconds(5, [&] {
- _state = STATE_READY;
+ spinner_timeout_.reset(new glib::Timeout(search_timeout_, [&] {
+ state_ = STATE_READY;
return false;
}));
}
@@ -178,6 +185,12 @@ SearchBarSpinner::SetState(SpinnerState state)
QueueDraw();
}
+SpinnerState
+SearchBarSpinner::GetState() const
+{
+ return state_;
+}
+
std::string
SearchBarSpinner::GetName() const
{
diff --git a/unity-shared/SearchBarSpinner.h b/unity-shared/SearchBarSpinner.h
index aa1adf554..0200c1b6a 100644
--- a/unity-shared/SearchBarSpinner.h
+++ b/unity-shared/SearchBarSpinner.h
@@ -48,6 +48,9 @@ public:
void DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw);
void SetState(SpinnerState state);
+ SpinnerState GetState() const;
+
+ void SetSpinnerTimeout(int timeout);
protected:
// Introspectable methods
@@ -60,18 +63,19 @@ protected:
private:
bool OnFrameTimeout();
- SpinnerState _state;
+ SpinnerState state_;
- nux::BaseTexture* _magnify;
- nux::BaseTexture* _circle;
- nux::BaseTexture* _close;
- nux::BaseTexture* _spin;
+ nux::BaseTexture* magnify_;
+ nux::BaseTexture* circle_;
+ nux::BaseTexture* close_;
+ nux::BaseTexture* spin_;
- glib::Source::UniquePtr _spinner_timeout;
- glib::Source::UniquePtr _frame_timeout;
+ glib::Source::UniquePtr spinner_timeout_;
+ glib::Source::UniquePtr frame_timeout_;
+ int search_timeout_;
- nux::Matrix4 _2d_rotate;
- float _rotation;
+ nux::Matrix4 rotate_;
+ float rotation_;
};
}