diff options
| author | Andrea Azzarone <azzaronea@gmail.com> | 2012-06-12 10:23:23 +0200 |
|---|---|---|
| committer | Andrea Azzarone <azzaronea@gmail.com> | 2012-06-12 10:23:23 +0200 |
| commit | 093e8059178a5c61bacca0f5137435cb97c8e626 (patch) | |
| tree | 908fc7d3da01f3b32f14da4b96a0078c029430f4 /hud | |
| parent | 031e732929a0434688c45ba017bb8148c2ced1ef (diff) | |
| parent | af943085c7928121e495e71b6a8ee50308f59e1e (diff) | |
Merge trunk.
(bzr r2388.1.4)
Diffstat (limited to 'hud')
| -rw-r--r-- | hud/HudController.cpp | 71 | ||||
| -rw-r--r-- | hud/HudController.h | 14 | ||||
| -rw-r--r-- | hud/HudView.cpp | 21 | ||||
| -rw-r--r-- | hud/HudView.h | 3 |
4 files changed, 29 insertions, 80 deletions
diff --git a/hud/HudController.cpp b/hud/HudController.cpp index 9bccda638..1fcbf5dea 100644 --- a/hud/HudController.cpp +++ b/hud/HudController.cpp @@ -45,15 +45,11 @@ Controller::Controller(std::function<AbstractView*(void)> const& function) , launcher_locked_out(false) , multiple_launchers(true) , hud_service_("com.canonical.hud", "/com/canonical/hud") - , window_(nullptr) , visible_(false) , need_show_(false) - , timeline_id_(0) - , last_opacity_(0.0f) - , start_time_(0) + , timeline_animator_(90) , view_(nullptr) , monitor_index_(0) - , type_wait_handle_(0) , view_function_(function) { LOG_DEBUG(logger) << "hud startup"; @@ -82,26 +78,11 @@ Controller::Controller(std::function<AbstractView*(void)> const& function) WindowManager::Default()->compiz_screen_ungrabbed.connect(sigc::mem_fun(this, &Controller::OnScreenUngrabbed)); hud_service_.queries_updated.connect(sigc::mem_fun(this, &Controller::OnQueriesFinished)); + timeline_animator_.animation_updated.connect(sigc::mem_fun(this, &Controller::OnViewShowHideFrame)); EnsureHud(); } -Controller::~Controller() -{ - if (window_) - window_->UnReference(); - window_ = 0; - - if (timeline_id_) - g_source_remove(timeline_id_); - - if (ensure_id_) - g_source_remove(ensure_id_); - - if (type_wait_handle_) - g_source_remove(type_wait_handle_); -} - void Controller::SetupWindow() { window_ = new nux::BaseWindow("Hud"); @@ -165,12 +146,11 @@ void Controller::EnsureHud() if (!window_) SetupWindow(); - + if (!view_) { SetupHudView(); Relayout(); - ensure_id_ = 0; } } @@ -186,7 +166,7 @@ void Controller::SetIcon(std::string const& icon_name) nux::BaseWindow* Controller::window() const { - return window_; + return window_.GetPointer(); } // We update the @geo that's sent in with our desired width and height @@ -417,51 +397,28 @@ void Controller::StartShowHideTimeline() { EnsureHud(); - if (timeline_id_) - g_source_remove(timeline_id_); - - timeline_id_ = g_timeout_add(15, (GSourceFunc)Controller::OnViewShowHideFrame, this); - last_opacity_ = window_->GetOpacity(); - start_time_ = g_get_monotonic_time(); - + double current_opacity = window_->GetOpacity(); + timeline_animator_.Stop(); + timeline_animator_.Start(visible_ ? current_opacity : 1.0f - current_opacity); } -gboolean Controller::OnViewShowHideFrame(Controller* self) +void Controller::OnViewShowHideFrame(double progress) { - const float LENGTH = 90000.0f; - float diff = g_get_monotonic_time() - self->start_time_; - float progress = diff / LENGTH; - float last_opacity = self->last_opacity_; + window_->SetOpacity(visible_ ? progress : 1.0f - progress); - if (self->visible_) + if (progress == 1.0f) { - self->window_->SetOpacity(last_opacity + ((1.0f - last_opacity) * progress)); - } - else - { - self->window_->SetOpacity(last_opacity - (last_opacity * progress)); - } - - if (diff > LENGTH) - { - self->timeline_id_ = 0; - - // Make sure the state is right - self->window_->SetOpacity(self->visible_ ? 1.0f : 0.0f); - if (!self->visible_) + if (!visible_) { - self->window_->ShowWindow(false); - self->view_->ResetToDefault(); + window_->ShowWindow(false); + view_->ResetToDefault(); } else { // ensure the text entry is focused - nux::GetWindowCompositor().SetKeyFocusArea(self->view_->default_focus()); + nux::GetWindowCompositor().SetKeyFocusArea(view_->default_focus()); } - return FALSE; } - - return TRUE; } void Controller::OnActivateRequest(GVariant* variant) diff --git a/hud/HudController.h b/hud/HudController.h index 77b44ec30..8579b6729 100644 --- a/hud/HudController.h +++ b/hud/HudController.h @@ -30,8 +30,9 @@ #include <Nux/Nux.h> #include <Nux/BaseWindow.h> -#include "HudView.h" +#include "unity-shared/Animator.h" #include "unity-shared/UBusWrapper.h" +#include "HudView.h" namespace unity { @@ -44,7 +45,6 @@ public: typedef std::shared_ptr<Controller> Ptr; Controller(std::function<AbstractView*(void)> const& function = []() { return new View; }); - ~Controller(); nux::BaseWindow* window() const; @@ -89,29 +89,25 @@ private: void OnQuerySelected(Query::Ptr query); void StartShowHideTimeline(); - static gboolean OnViewShowHideFrame(Controller* self); + void OnViewShowHideFrame(double progress); static void OnWindowConfigure(int width, int height, nux::Geometry& geo, void* data); void OnQueriesFinished(Hud::Queries queries); private: + nux::ObjectPtr<nux::BaseWindow> window_; UBusManager ubus; Hud hud_service_; - nux::BaseWindow* window_; bool visible_; bool need_show_; - guint timeline_id_; - float last_opacity_; - gint64 start_time_; + Animator timeline_animator_; AbstractView* view_; - guint ensure_id_; std::string focused_app_icon_; nux::Layout* layout_; uint monitor_index_; - guint type_wait_handle_; std::string last_search_; std::function<AbstractView*(void)> view_function_; diff --git a/hud/HudView.cpp b/hud/HudView.cpp index 9b8548eaa..6c0e02531 100644 --- a/hud/HudView.cpp +++ b/hud/HudView.cpp @@ -57,8 +57,7 @@ NUX_IMPLEMENT_OBJECT_TYPE(View); View::View() : AbstractView() - , button_views_(NULL) - , timeline_id_(0) + , button_views_(nullptr) , start_time_(0) , last_known_height_(0) , current_height_(0) @@ -121,9 +120,6 @@ View::~View() { RemoveChild((*button).GetPointer()); } - - if (timeline_id_) - g_source_remove(timeline_id_); } void View::ProcessGrowShrink() @@ -473,15 +469,13 @@ void View::DrawContent(nux::GraphicsEngine& gfx_context, bool force_draw) renderer_.DrawInnerCleanup(gfx_context, draw_content_geo, absolute_window_geometry_, window_geometry_); - if (timeline_need_more_draw_ && !timeline_id_) + if (timeline_need_more_draw_ && !timeline_idle_) { - timeline_id_ = g_idle_add([] (gpointer data) -> gboolean - { - View *self = static_cast<View*>(data); - self->QueueDraw(); - self->timeline_id_ = 0; - return FALSE; - }, this); + timeline_idle_.reset(new glib::Idle([&] () { + QueueDraw(); + timeline_idle_.reset(); + return false; + })); } } @@ -686,3 +680,4 @@ nux::Area* View::FindKeyFocusArea(unsigned int event_type, } } + diff --git a/hud/HudView.h b/hud/HudView.h index e99768405..ca1e1a6f4 100644 --- a/hud/HudView.h +++ b/hud/HudView.h @@ -23,6 +23,7 @@ #include <Nux/Nux.h> #include <Nux/VLayout.h> +#include <UnityCore/GLibSource.h> #include "HudIcon.h" #include "HudButton.h" @@ -104,8 +105,8 @@ private: OverlayRenderer renderer_; nux::Geometry window_geometry_; nux::Geometry absolute_window_geometry_; + glib::Source::UniquePtr timeline_idle_; - guint timeline_id_; guint64 start_time_; int last_known_height_; int current_height_; |
