diff options
| author | Nick Dedekind <nicholas.dedekind@gmail.com> | 2012-12-14 10:16:42 +0000 |
|---|---|---|
| committer | Nick Dedekind <nicholas.dedekind@gmail.com> | 2012-12-14 10:16:42 +0000 |
| commit | 818d25bad4e0847e097f3b1561b60d18c7d96799 (patch) | |
| tree | eb498b4cb673feb59730e8f920f4ac1e47ed0861 /unity-shared | |
| parent | bec80fb387fd41ebddb3d30da4448523a59dfdda (diff) | |
| parent | 938153447e0791e31a89b2d0dfa838427a58a162 (diff) | |
Merged with trunk
(bzr r2934.2.13)
Diffstat (limited to 'unity-shared')
| -rw-r--r-- | unity-shared/Animator.cpp | 135 | ||||
| -rw-r--r-- | unity-shared/Animator.h | 64 | ||||
| -rw-r--r-- | unity-shared/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | unity-shared/DebugDBusInterface.cpp | 1 | ||||
| -rw-r--r-- | unity-shared/GraphicsUtils.cpp | 17 | ||||
| -rw-r--r-- | unity-shared/GraphicsUtils.h | 2 | ||||
| -rw-r--r-- | unity-shared/IconTexture.cpp | 10 | ||||
| -rw-r--r-- | unity-shared/PlacesOverlayVScrollBar.cpp | 39 | ||||
| -rw-r--r-- | unity-shared/PlacesOverlayVScrollBar.h | 6 | ||||
| -rw-r--r-- | unity-shared/PlacesVScrollBar.cpp | 26 | ||||
| -rw-r--r-- | unity-shared/PlacesVScrollBar.h | 3 | ||||
| -rw-r--r-- | unity-shared/SearchBar.cpp | 79 | ||||
| -rw-r--r-- | unity-shared/SearchBarSpinner.cpp | 8 | ||||
| -rw-r--r-- | unity-shared/VScrollBarOverlayWindow.cpp | 66 | ||||
| -rw-r--r-- | unity-shared/VScrollBarOverlayWindow.h | 27 |
15 files changed, 194 insertions, 290 deletions
diff --git a/unity-shared/Animator.cpp b/unity-shared/Animator.cpp deleted file mode 100644 index 18ec7139b..000000000 --- a/unity-shared/Animator.cpp +++ /dev/null @@ -1,135 +0,0 @@ -// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- -/* - * Copyright (C) 2011 Canonical Ltd - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 3 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * Authored by: Marco Trevisan (Treviño) <mail@3v1n0.net> - */ - -#include "Animator.h" - -namespace unity -{ - -Animator::Animator(unsigned int default_duration, unsigned int fps_rate) - : start_time_(0) - , rate_(1) - , duration_(0) - , one_time_duration_(0) - , start_progress_(0.0f) - , progress_(0.0f) -{ - SetDuration(default_duration); - SetRate(fps_rate); -} - -Animator::~Animator() -{ - Stop(); -} - -void Animator::SetRate(unsigned int fps_rate) -{ - if (fps_rate != 0) - rate_ = 1000 / fps_rate; -} - -void Animator::SetDuration(unsigned int duration) -{ - duration_ = duration * 1000; -} - -unsigned int Animator::GetRate() const -{ - if (rate_ != 0) - return 1000 / rate_; - - return rate_; -} - -unsigned int Animator::GetDuration() const -{ - return (one_time_duration_ > 0 ? one_time_duration_ : duration_) / 1000; -} - -bool Animator::IsRunning() const -{ - return bool(timeout_); -} - -double Animator::GetProgress() const -{ - return progress_; -} - -void Animator::Start(unsigned int one_time_duration, double start_progress) -{ - if (!timeout_ && start_progress < 1.0f) - { - if (start_progress < 0.0f) - start_progress = 0.0f; - - one_time_duration_ = one_time_duration * 1000; - start_progress_ = start_progress; - progress_ = start_progress_; - start_time_ = g_get_monotonic_time(); - timeout_.reset(new glib::Timeout(rate_, sigc::mem_fun(this, &Animator::DoStep))); - animation_started.emit(); - } -} - -void Animator::Start(double start_progress) -{ - Start(0, start_progress); -} - -void Animator::Stop() -{ - if (timeout_) - { - timeout_.reset(); - animation_updated.emit(progress_); - animation_ended.emit(); - animation_stopped.emit(progress_); - one_time_duration_ = 0; - } -} - -bool Animator::DoStep() -{ - const gint64 current_time = g_get_monotonic_time(); - const gint64 duration = one_time_duration_ > 0 ? one_time_duration_ : duration_; - const gint64 end_time = start_time_ + duration; - - if (current_time < end_time && progress_ < 1.0f && duration > 0) - { - const double diff_time = current_time - start_time_; - progress_ = CLAMP(start_progress_ + (diff_time / duration), 0.0f, 1.0f); - animation_updated.emit(progress_); - - return true; - } - else - { - progress_ = 1.0f; - animation_updated.emit(1.0f); - animation_ended.emit(); - one_time_duration_ = 0; - timeout_.reset(); - - return false; - } -} - -} //namespace diff --git a/unity-shared/Animator.h b/unity-shared/Animator.h deleted file mode 100644 index 50a544d19..000000000 --- a/unity-shared/Animator.h +++ /dev/null @@ -1,64 +0,0 @@ -// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- -/* - * Copyright (C) 2011 Canonical Ltd - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 3 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * Authored by: Marco Trevisan (Treviño) <mail@3v1n0.net> - */ - -#ifndef UNITY_ANIMATOR_H_ -#define UNITY_ANIMATOR_H_ - -#include <cstdint> -#include <UnityCore/GLibSource.h> - -namespace unity -{ -class Animator : boost::noncopyable -{ -public: - Animator(unsigned int default_duration, unsigned int fps_rate = 30); - ~Animator(); - - void SetRate(unsigned int fps_rate); - void SetDuration(unsigned int duration); - - unsigned int GetRate() const; - unsigned int GetDuration() const; - double GetProgress() const; - bool IsRunning() const; - - void Start(double start_progress = 0.0f); - void Start(unsigned int one_time_duration, double start_progress = 0.0f); - bool DoStep(); - void Stop(); - - sigc::signal<void> animation_started; - sigc::signal<void> animation_ended; - - sigc::signal<void, double> animation_updated; - sigc::signal<void, double> animation_stopped; - -private: - glib::Source::UniquePtr timeout_; - int64_t start_time_; - unsigned int rate_; - unsigned int duration_; - unsigned int one_time_duration_; - double start_progress_; - double progress_; -}; - -} -#endif diff --git a/unity-shared/CMakeLists.txt b/unity-shared/CMakeLists.txt index 27cceddd2..bb5e98662 100644 --- a/unity-shared/CMakeLists.txt +++ b/unity-shared/CMakeLists.txt @@ -26,7 +26,6 @@ include_directories (.. ../services ../UnityCore ${UNITY_SRC} ${CMAKE_BINARY_DIR set (UNITY_SHARED_SOURCES AbstractSeparator.cpp ApplicationManager.cpp - Animator.cpp BGHash.cpp CoverArt.cpp BackgroundEffectHelper.cpp diff --git a/unity-shared/DebugDBusInterface.cpp b/unity-shared/DebugDBusInterface.cpp index 68c6ef6b2..7aedca53a 100644 --- a/unity-shared/DebugDBusInterface.cpp +++ b/unity-shared/DebugDBusInterface.cpp @@ -21,6 +21,7 @@ #include <iostream> #include <fstream> #include <sstream> +#include <iostream> #include <boost/algorithm/string.hpp> #include <boost/algorithm/string/split.hpp> #include <boost/algorithm/string/classification.hpp> diff --git a/unity-shared/GraphicsUtils.cpp b/unity-shared/GraphicsUtils.cpp index 1e1114cb6..ab4c7823c 100644 --- a/unity-shared/GraphicsUtils.cpp +++ b/unity-shared/GraphicsUtils.cpp @@ -67,5 +67,22 @@ void PopOffscreenRenderTarget() } } +void ClearGeometry(nux::Geometry const& geo, nux::Color const& color) +{ + nux::GraphicsEngine* graphics_engine = nux::GetGraphicsDisplay()->GetGraphicsEngine(); + + // This is necessary when doing redirected rendering. Clean the area below this view. + unsigned int current_alpha_blend; + unsigned int current_src_blend_factor; + unsigned int current_dest_blend_factor; + graphics_engine->GetRenderStates().GetBlend(current_alpha_blend, current_src_blend_factor, current_dest_blend_factor); + + graphics_engine->GetRenderStates().SetBlend(false); + graphics_engine->QRP_Color(geo.x, geo.y, geo.width, geo.height, color); + + graphics_engine->GetRenderStates().SetBlend(current_alpha_blend, current_src_blend_factor, current_dest_blend_factor); +} + + } } diff --git a/unity-shared/GraphicsUtils.h b/unity-shared/GraphicsUtils.h index dd65d3b00..d4064b021 100644 --- a/unity-shared/GraphicsUtils.h +++ b/unity-shared/GraphicsUtils.h @@ -30,6 +30,8 @@ namespace graphics void PushOffscreenRenderTarget(nux::ObjectPtr<nux::IOpenGLBaseTexture> texture); void PopOffscreenRenderTarget(); +void ClearGeometry(nux::Geometry const& geo, nux::Color const& color = nux::Color(0.0f, 0.0f, 0.0f, 0.0f)); + } } diff --git a/unity-shared/IconTexture.cpp b/unity-shared/IconTexture.cpp index 0b7393545..c78fd844d 100644 --- a/unity-shared/IconTexture.cpp +++ b/unity-shared/IconTexture.cpp @@ -181,6 +181,12 @@ void IconTexture::IconLoaded(std::string const& icon_name, void IconTexture::Draw(nux::GraphicsEngine& GfxContext, bool force_draw) { + unsigned int current_alpha_blend; + unsigned int current_src_blend_factor; + unsigned int current_dest_blend_factor; + 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); + nux::Geometry geo = GetGeometry(); GfxContext.PushClippingRectangle(geo); @@ -243,11 +249,11 @@ void IconTexture::Draw(nux::GraphicsEngine& GfxContext, bool force_draw) texxform, col); } - - } GfxContext.PopClippingRectangle(); + + GfxContext.GetRenderStates().SetBlend(current_alpha_blend, current_src_blend_factor, current_dest_blend_factor); } void IconTexture::GetTextureSize(int* width, int* height) diff --git a/unity-shared/PlacesOverlayVScrollBar.cpp b/unity-shared/PlacesOverlayVScrollBar.cpp index e318cdf3c..6943176e6 100644 --- a/unity-shared/PlacesOverlayVScrollBar.cpp +++ b/unity-shared/PlacesOverlayVScrollBar.cpp @@ -37,7 +37,7 @@ namespace dash PlacesOverlayVScrollBar::PlacesOverlayVScrollBar(NUX_FILE_LINE_DECL) : PlacesVScrollBar(NUX_FILE_LINE_PARAM) , overlay_window_(new VScrollBarOverlayWindow(_track->GetAbsoluteGeometry())) - , area_prox_(overlay_window_.GetPointer(), PROXIMITY) + , area_prox_(this, PROXIMITY) , thumb_above_slider_(false) , connector_height_(0) , mouse_down_offset_(0) @@ -46,6 +46,8 @@ PlacesOverlayVScrollBar::PlacesOverlayVScrollBar(NUX_FILE_LINE_DECL) area_prox_.mouse_near.connect(sigc::mem_fun(this, &PlacesOverlayVScrollBar::OnMouseNear)); area_prox_.mouse_beyond.connect(sigc::mem_fun(this, &PlacesOverlayVScrollBar::OnMouseBeyond)); + overlay_window_->mouse_enter.connect(sigc::mem_fun(this, &PlacesOverlayVScrollBar::OnMouseEnter)); + overlay_window_->mouse_leave.connect(sigc::mem_fun(this, &PlacesOverlayVScrollBar::OnMouseLeave)); overlay_window_->mouse_down.connect(sigc::mem_fun(this, &PlacesOverlayVScrollBar::OnMouseDown)); overlay_window_->mouse_up.connect(sigc::mem_fun(this, &PlacesOverlayVScrollBar::OnMouseUp)); overlay_window_->mouse_click.connect(sigc::mem_fun(this, &PlacesOverlayVScrollBar::OnMouseClick)); @@ -77,12 +79,6 @@ void PlacesOverlayVScrollBar::OnVisibilityChanged(nux::Area* /*area*/, bool visi } } -void PlacesOverlayVScrollBar::StopAnimation() -{ - if (animation_.CurrentState() != nux::animation::Animation::State::Stopped) - animation_.Stop(); -} - void PlacesOverlayVScrollBar::SetupAnimation(int start, int stop, int milliseconds) { tweening_connection_.disconnect(); @@ -142,11 +138,23 @@ bool PlacesOverlayVScrollBar::IsScrollBarVisible() const return (content_height_ > container_height_); } +void PlacesOverlayVScrollBar::OnMouseEnter(int x, int y, unsigned int button_flags, unsigned int key_flags) +{ + overlay_window_->MouseEnter(); + UpdateConnectorPosition(); +} + +void PlacesOverlayVScrollBar::OnMouseLeave(int x, int y, unsigned int button_flags, unsigned int key_flags) +{ + overlay_window_->MouseLeave(); + UpdateConnectorPosition(); +} + void PlacesOverlayVScrollBar::OnMouseNear(nux::Point const& mouse_pos) { if (IsVisible() && IsScrollBarVisible()) { - StopAnimation(); + animation_.Stop(); overlay_window_->MouseNear(); AdjustThumbOffsetFromMouse(); @@ -230,7 +238,18 @@ void PlacesOverlayVScrollBar::UpdateConnectorPosition() void PlacesOverlayVScrollBar::ResetConnector() { - StartConnectorAnimation(); + if (animation_.CurrentState() == nux::animation::Animation::State::Stopped) + { + if (connector_height_ > 0) + { + StartConnectorAnimation(); + } + } + else + { + connector_height_ = 0; + } + QueueDraw(); } @@ -320,7 +339,7 @@ void PlacesOverlayVScrollBar::OnMouseMove(int /*x*/, int y, int /*dx*/, int /*dy void PlacesOverlayVScrollBar::OnMouseDrag(int /*x*/, int y, int /*dx*/, int dy, unsigned int /*button_flags*/, unsigned int /*key_flags*/) { - StopAnimation(); + animation_.Stop(); MouseDraggingOverlay(y, dy); } diff --git a/unity-shared/PlacesOverlayVScrollBar.h b/unity-shared/PlacesOverlayVScrollBar.h index f1b09403d..64945b944 100644 --- a/unity-shared/PlacesOverlayVScrollBar.h +++ b/unity-shared/PlacesOverlayVScrollBar.h @@ -51,6 +51,9 @@ private: void OnTrackGeometryChanged(nux::Area* area, nux::Geometry& geo); void OnVisibilityChanged(nux::Area* area, bool visible); + void OnMouseEnter(int x, int y, unsigned int button_flags, unsigned int key_flags); + void OnMouseLeave(int x, int y, unsigned int button_flags, unsigned int key_flags); + void OnMouseNear(nux::Point const& mouse_pos); void OnMouseBeyond(nux::Point const& mouse_pos); void AdjustThumbOffsetFromMouse(); @@ -78,7 +81,6 @@ private: void UpdateStepY(); void SetupAnimation(int start, int stop, int milliseconds); - void StopAnimation(); void StartScrollAnimation(ScrollDir dir, int stop); void OnScroll(ScrollDir dir, int mouse_dy); @@ -99,6 +101,8 @@ private: int connector_height_; int mouse_down_offset_; int delta_update_; + + friend class MockScrollBar; }; } // namespace dash diff --git a/unity-shared/PlacesVScrollBar.cpp b/unity-shared/PlacesVScrollBar.cpp index 2af828916..0058fb465 100644 --- a/unity-shared/PlacesVScrollBar.cpp +++ b/unity-shared/PlacesVScrollBar.cpp @@ -69,6 +69,24 @@ PlacesVScrollBar::PostLayoutManagement(long LayoutResult) void PlacesVScrollBar::Draw(nux::GraphicsEngine& graphics_engine, bool force_draw) { + if(!RedirectedAncestor()) + { + DrawScrollbar(graphics_engine); + } +} + +void +PlacesVScrollBar::DrawContent(nux::GraphicsEngine& graphics_engine, bool force_draw) +{ + if(RedirectedAncestor()) + { + DrawScrollbar(graphics_engine); + } +} + +void +PlacesVScrollBar::DrawScrollbar(nux::GraphicsEngine& graphics_engine) +{ nux::Color color = nux::color::White; nux::Geometry const& base = GetGeometry(); nux::TexCoordXForm texxform; @@ -77,14 +95,6 @@ PlacesVScrollBar::Draw(nux::GraphicsEngine& graphics_engine, bool force_draw) unsigned int alpha = 0, src = 0, dest = 0; graphics_engine.GetRenderStates().GetBlend(alpha, src, dest); - if(RedirectedAncestor()) - { - // This is necessary when doing redirected rendering. - // Clean the area below this view before drawing anything. - graphics_engine.GetRenderStates().SetBlend(false); - graphics_engine.QRP_Color(GetX(), GetY(), GetWidth(), GetHeight(), nux::Color(0.0f, 0.0f, 0.0f, 0.0f)); - } - // check if textures have been computed... if they haven't, exit function if (!_slider_texture) return; diff --git a/unity-shared/PlacesVScrollBar.h b/unity-shared/PlacesVScrollBar.h index de9a9dca7..87f793ea9 100644 --- a/unity-shared/PlacesVScrollBar.h +++ b/unity-shared/PlacesVScrollBar.h @@ -44,9 +44,12 @@ protected: void Draw(nux::GraphicsEngine& gfxContext, bool forceDraw); + void DrawContent(nux::GraphicsEngine& gfxContext, + bool forceDraw); private: void UpdateTexture(); + void DrawScrollbar(nux::GraphicsEngine& graphics_engine); private: nux::BaseTexture* _slider_texture; diff --git a/unity-shared/SearchBar.cpp b/unity-shared/SearchBar.cpp index cdc33d44b..744f83ee2 100644 --- a/unity-shared/SearchBar.cpp +++ b/unity-shared/SearchBar.cpp @@ -30,7 +30,8 @@ #include "SearchBar.h" #include "CairoTexture.h" -#include "unity-shared/DashStyle.h" +#include "DashStyle.h" +#include "GraphicsUtils.h" namespace { @@ -362,21 +363,14 @@ void SearchBar::Draw(nux::GraphicsEngine& graphics_engine, bool force_draw) graphics_engine.PushClippingRectangle(base); if (RedirectedAncestor()) + graphics::ClearGeometry(base); + + if (bg_layer_) { - unsigned int alpha = 0, src = 0, dest = 0; - graphics_engine.GetRenderStates().GetBlend(alpha, src, dest); - // This is necessary when doing redirected rendering. - // Clean the area below this view before drawing anything. - graphics_engine.GetRenderStates().SetBlend(false); - graphics_engine.QRP_Color(base.x, base.y, base.width, base.height, nux::Color(0.0f, 0.0f, 0.0f, 0.0f)); - graphics_engine.GetRenderStates().SetBlend(alpha, src, dest); + bg_layer_->SetGeometry(nux::Geometry(base.x, base.y, last_width_, last_height_)); + bg_layer_->Renderlayer(graphics_engine); } - bg_layer_->SetGeometry(nux::Geometry(base.x, base.y, last_width_, last_height_)); - nux::GetPainter().RenderSinglePaintLayer(graphics_engine, - bg_layer_->GetGeometry(), - bg_layer_.get()); - if (ShouldBeHighlighted()) { dash::Style& style = dash::Style::Instance(); @@ -398,56 +392,46 @@ void SearchBar::Draw(nux::GraphicsEngine& graphics_engine, bool force_draw) void SearchBar::DrawContent(nux::GraphicsEngine& graphics_engine, bool force_draw) { - nux::Geometry const& geo = GetGeometry(); - - graphics_engine.PushClippingRectangle(geo); + nux::Geometry const& base = GetGeometry(); - if (highlight_layer_ && ShouldBeHighlighted() && !IsFullRedraw()) - { - nux::GetPainter().PushLayer(graphics_engine, highlight_layer_->GetGeometry(), highlight_layer_.get()); - } + graphics_engine.PushClippingRectangle(base); + int pushed_paint_layers = 0; if (!IsFullRedraw()) { - unsigned int current_alpha_blend; - unsigned int current_src_blend_factor; - unsigned int current_dest_blend_factor; - graphics_engine.GetRenderStates().GetBlend(current_alpha_blend, current_src_blend_factor, current_dest_blend_factor); - - graphics_engine.GetRenderStates().SetBlend(false); - graphics_engine.QRP_Color( - pango_entry_->GetX(), - pango_entry_->GetY(), - pango_entry_->GetWidth(), - pango_entry_->GetHeight(), nux::Color(0.0f, 0.0f, 0.0f, 0.0f)); - - if (spinner_->IsRedrawNeeded()) + if (RedirectedAncestor()) { - graphics_engine.QRP_Color( - spinner_->GetX(), - spinner_->GetY(), - spinner_->GetWidth(), - spinner_->GetHeight(), nux::Color(0.0f, 0.0f, 0.0f, 0.0f)); + graphics::ClearGeometry(pango_entry_->GetGeometry()); + if (spinner_->IsRedrawNeeded()) + graphics::ClearGeometry(spinner_->GetGeometry()); } - - graphics_engine.GetRenderStates().SetBlend(current_alpha_blend, current_src_blend_factor, current_dest_blend_factor); - gPainter.PushLayer(graphics_engine, bg_layer_->GetGeometry(), bg_layer_.get()); + if (highlight_layer_ && ShouldBeHighlighted()) + { + pushed_paint_layers++; + nux::GetPainter().PushLayer(graphics_engine, highlight_layer_->GetGeometry(), highlight_layer_.get()); + } + + if (bg_layer_) + { + pushed_paint_layers++; + nux::GetPainter().PushLayer(graphics_engine, bg_layer_->GetGeometry(), bg_layer_.get()); + } } else { - nux::GetPainter().PushPaintLayerStack(); + nux::GetPainter().PushPaintLayerStack(); } layout_->ProcessDraw(graphics_engine, force_draw); - if (!IsFullRedraw()) + if (IsFullRedraw()) { - gPainter.PopBackground(); + nux::GetPainter().PopPaintLayerStack(); } - else + else if (pushed_paint_layers > 0) { - nux::GetPainter().PopPaintLayerStack(); + nux::GetPainter().PopBackground(pushed_paint_layers); } graphics_engine.PopClippingRectangle(); @@ -505,7 +489,8 @@ void SearchBar::UpdateBackground(bool force) << layered_layout_->GetGeometry().height << " - " << pango_entry_->GetGeometry().height; - if (geo.width == last_width_ + if (!bg_layer_ && + geo.width == last_width_ && geo.height == last_height_ && force == false) return; diff --git a/unity-shared/SearchBarSpinner.cpp b/unity-shared/SearchBarSpinner.cpp index 240118785..39b62b523 100644 --- a/unity-shared/SearchBarSpinner.cpp +++ b/unity-shared/SearchBarSpinner.cpp @@ -60,6 +60,12 @@ SearchBarSpinner::Draw(nux::GraphicsEngine& GfxContext, bool force_draw) texxform.min_filter = nux::TEXFILTER_LINEAR; texxform.mag_filter = nux::TEXFILTER_LINEAR; + unsigned int current_alpha_blend; + unsigned int current_src_blend_factor; + unsigned int current_dest_blend_factor; + 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) { GfxContext.QRP_1Tex(geo.x + ((geo.width - _magnify->GetWidth()) / 2), @@ -120,6 +126,8 @@ SearchBarSpinner::Draw(nux::GraphicsEngine& GfxContext, bool force_draw) } GfxContext.PopClippingRectangle(); + GfxContext.GetRenderStates().SetBlend(current_alpha_blend, current_src_blend_factor, current_dest_blend_factor); + if (_state == STATE_SEARCHING && !_frame_timeout) { _frame_timeout.reset(new glib::Timeout(22, sigc::mem_fun(this, &SearchBarSpinner::OnFrameTimeout))); diff --git a/unity-shared/VScrollBarOverlayWindow.cpp b/unity-shared/VScrollBarOverlayWindow.cpp index 750feda63..71d490ad3 100644 --- a/unity-shared/VScrollBarOverlayWindow.cpp +++ b/unity-shared/VScrollBarOverlayWindow.cpp @@ -25,6 +25,9 @@ #include "DashStyle.h" #include "CairoTexture.h" +namespace unity +{ + namespace { int const THUMB_WIDTH = 21; @@ -38,9 +41,7 @@ VScrollBarOverlayWindow::VScrollBarOverlayWindow(nux::Geometry const& geo) , content_size_(geo) , content_offset_x_(0) , mouse_offset_y_(0) - , mouse_down_(false) - , mouse_near_(false) - , inside_slider_(false) + , current_state_(ThumbState::NONE) , current_action_(ThumbAction::NONE) { Area::SetGeometry(content_size_.x, content_size_.y, THUMB_WIDTH, content_size_.height); @@ -68,7 +69,7 @@ void VScrollBarOverlayWindow::SetThumbOffsetY(int y) if (new_offset != mouse_offset_y_) { - if (mouse_down_) + if (HasState(ThumbState::MOUSE_DOWN)) MouseDragging(); mouse_offset_y_ = new_offset; @@ -127,13 +128,13 @@ nux::Geometry VScrollBarOverlayWindow::GetThumbGeometry() const void VScrollBarOverlayWindow::MouseDown() { - mouse_down_ = true; + AddState(ThumbState::MOUSE_DOWN); UpdateTexture(); } void VScrollBarOverlayWindow::MouseUp() { - mouse_down_ = false; + RemoveState(ThumbState::MOUSE_DOWN); current_action_ = ThumbAction::NONE; UpdateTexture(); ShouldHide(); @@ -141,30 +142,42 @@ void VScrollBarOverlayWindow::MouseUp() void VScrollBarOverlayWindow::MouseNear() { - mouse_near_ = true; + AddState(ThumbState::MOUSE_NEAR); ShouldShow(); } void VScrollBarOverlayWindow::MouseBeyond() { - mouse_near_ = false; + RemoveState(ThumbState::MOUSE_NEAR); + ShouldHide(); +} + +void VScrollBarOverlayWindow::MouseEnter() +{ + AddState(ThumbState::MOUSE_INSIDE); + ShouldShow(); +} + +void VScrollBarOverlayWindow::MouseLeave() +{ + RemoveState(ThumbState::MOUSE_INSIDE); ShouldHide(); } void VScrollBarOverlayWindow::ThumbInsideSlider() { - if (!inside_slider_) + if (!HasState(ThumbState::INSIDE_SLIDER)) { - inside_slider_ = true; + AddState(ThumbState::INSIDE_SLIDER); UpdateTexture(); } } void VScrollBarOverlayWindow::ThumbOutsideSlider() { - if (inside_slider_) + if (HasState(ThumbState::INSIDE_SLIDER)) { - inside_slider_ = false; + RemoveState(ThumbState::INSIDE_SLIDER); UpdateTexture(); } } @@ -194,7 +207,8 @@ void VScrollBarOverlayWindow::ShouldShow() { if (!IsVisible()) { - if (mouse_down_ || mouse_near_) + if (HasState(ThumbState::MOUSE_DOWN) || + HasState(ThumbState::MOUSE_NEAR)) { ShowWindow(true); PushToFront(); @@ -207,7 +221,9 @@ void VScrollBarOverlayWindow::ShouldHide() { if (IsVisible()) { - if (!mouse_down_ && !mouse_near_) + if (!(HasState(ThumbState::MOUSE_DOWN)) && + !(HasState(ThumbState::MOUSE_NEAR)) && + !(HasState(ThumbState::MOUSE_INSIDE))) { ShowWindow(false); QueueDraw(); @@ -217,12 +233,26 @@ void VScrollBarOverlayWindow::ShouldHide() void VScrollBarOverlayWindow::ResetStates() { - mouse_down_ = false; - mouse_near_ = false; + current_state_ = ThumbState::NONE; current_action_ = ThumbAction::NONE; ShouldHide(); } +void VScrollBarOverlayWindow::AddState(ThumbState const& state) +{ + current_state_ |= state; +} + +void VScrollBarOverlayWindow::RemoveState(ThumbState const& state) +{ + current_state_ &= ~(state); +} + +bool VScrollBarOverlayWindow::HasState(ThumbState const& state) const +{ + return (current_state_ & state); +} + void VScrollBarOverlayWindow::Draw(nux::GraphicsEngine& graphics_engine, bool force_draw) { if (!thumb_texture_) @@ -465,7 +495,7 @@ void VScrollBarOverlayWindow::UpdateTexture() current_y += 0.5; cairoGraphics.DrawRoundedRectangle(cr, aspect, current_x, current_y, radius - 1, width - 1, height - 1); - if (inside_slider_) + if (HasState(ThumbState::INSIDE_SLIDER)) SetSourceRGB(cr, bg_selected, 1.0); else SetSourceRGB(cr, bg_active, 0.9); @@ -524,3 +554,5 @@ void VScrollBarOverlayWindow::UpdateTexture() QueueDraw(); } + +} // namespace unity diff --git a/unity-shared/VScrollBarOverlayWindow.h b/unity-shared/VScrollBarOverlayWindow.h index abcf6db25..5ac11db16 100644 --- a/unity-shared/VScrollBarOverlayWindow.h +++ b/unity-shared/VScrollBarOverlayWindow.h @@ -24,6 +24,8 @@ #include <Nux/Nux.h> #include <Nux/BaseWindow.h> +namespace unity +{ class VScrollBarOverlayWindow : public nux::BaseWindow { @@ -39,6 +41,9 @@ public: void MouseNear(); void MouseBeyond(); + void MouseEnter(); + void MouseLeave(); + void ThumbInsideSlider(); void ThumbOutsideSlider(); @@ -67,6 +72,15 @@ private: PAGE_DOWN }; + enum ThumbState + { + NONE = 1 << 0, + MOUSE_DOWN = 1 << 1, + MOUSE_NEAR = 1 << 2, + MOUSE_INSIDE = 1 << 3, + INSIDE_SLIDER = 1 << 4 + }; + void MouseDragging(); void UpdateMouseOffsetX(); int GetValidOffsetYValue(int y) const; @@ -82,11 +96,14 @@ private: int content_offset_x_; int mouse_offset_y_; - bool mouse_down_; - bool mouse_near_; - bool inside_slider_; - + void AddState(ThumbState const& state); + void RemoveState(ThumbState const& state); + bool HasState(ThumbState const& state) const; + + unsigned int current_state_; ThumbAction current_action_; }; -#endif +} // namespace unity + +#endif // VSCROLLBAR_OVERLAY_WINDOW_H |
