summaryrefslogtreecommitdiff
diff options
-rw-r--r--unity-shared/CMakeLists.txt1
-rw-r--r--unity-shared/PlacesOverlayVScrollBar.cpp465
-rw-r--r--unity-shared/PlacesOverlayVScrollBar.h60
-rw-r--r--unity-shared/PlacesVScrollBar.cpp93
-rw-r--r--unity-shared/PlacesVScrollBar.h7
-rw-r--r--unity-shared/VScrollBarOverlayWindow.cpp568
-rw-r--r--unity-shared/VScrollBarOverlayWindow.h114
7 files changed, 122 insertions, 1186 deletions
diff --git a/unity-shared/CMakeLists.txt b/unity-shared/CMakeLists.txt
index e37edb074..a65703171 100644
--- a/unity-shared/CMakeLists.txt
+++ b/unity-shared/CMakeLists.txt
@@ -71,7 +71,6 @@ set (UNITY_SHARED_SOURCES
UnityWindowView.cpp
UpstartWrapper.cpp
UserThumbnailProvider.cpp
- VScrollBarOverlayWindow.cpp
WindowButtons.cpp
WindowManager.cpp
)
diff --git a/unity-shared/PlacesOverlayVScrollBar.cpp b/unity-shared/PlacesOverlayVScrollBar.cpp
index ac5b47b31..0726b1e93 100644
--- a/unity-shared/PlacesOverlayVScrollBar.cpp
+++ b/unity-shared/PlacesOverlayVScrollBar.cpp
@@ -1,6 +1,6 @@
// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
/*
- * Copyright (C) 2012 Canonical Ltd
+ * Copyright (C) 2012-2015 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
@@ -15,11 +15,12 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Authored by: Brandon Schaefer <brandon.schaefer@canonical.com>
+ * Marco Trevisan <marco.trevisan@canonical.com>
*/
#include <Nux/Nux.h>
-#include "CairoTexture.h"
+#include "AnimationUtils.h"
#include "PlacesOverlayVScrollBar.h"
#include "RawPixel.h"
@@ -29,438 +30,124 @@ namespace dash
{
namespace
{
- const RawPixel PROXIMITY = 7_em;
- const int SCROLL_ANIMATION = 400;
- const int MAX_CONNECTOR_ANIMATION = 200;
- const nux::Color CONNECTOR_COLOR = nux::color::Gray;
+const RawPixel PROXIMITY = 7_em;
+const int PAGE_SCROLL_ANIMATION = 200;
+const int CLICK_SCROLL_ANIMATION = 80;
+
+const RawPixel BUTTONS_HEIGHT = 0_em;
+const RawPixel DEFAULT_WIDTH = 3_em;
+const RawPixel ACTIVE_WIDTH = 8_em;
}
-class PlacesOverlayVScrollBar::ProximityArea : public nux::InputAreaProximity, public sigc::trackable
+struct PlacesOverlayVScrollBar::ProximityArea : public nux::InputAreaProximity, public sigc::trackable
{
-public:
ProximityArea(nux::InputArea* area, unsigned prox)
: nux::InputAreaProximity(area, prox)
, proximity([this] { return proximity_; }, [this] (unsigned px) { proximity_ = px; return false; })
{}
nux::RWProperty<unsigned> proximity;
+
+ bool IsMouseNear() const { return is_mouse_near_; }
};
PlacesOverlayVScrollBar::PlacesOverlayVScrollBar(NUX_FILE_LINE_DECL)
: PlacesVScrollBar(NUX_FILE_LINE_PARAM)
- , overlay_window_(new VScrollBarOverlayWindow(_track->GetAbsoluteGeometry()))
, area_prox_(std::make_shared<ProximityArea>(this, PROXIMITY.CP(scale)))
- , thumb_above_slider_(false)
- , connector_height_(0)
- , mouse_down_offset_(0)
, delta_update_(0)
{
- area_prox_->mouse_near.connect(sigc::mem_fun(this, &PlacesOverlayVScrollBar::OnMouseNear));
- area_prox_->mouse_beyond.connect(sigc::mem_fun(this, &PlacesOverlayVScrollBar::OnMouseBeyond));
-
- overlay_window_->scale = scale();
- 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));
- overlay_window_->mouse_move.connect(sigc::mem_fun(this, &PlacesOverlayVScrollBar::OnMouseMove));
- overlay_window_->mouse_drag.connect(sigc::mem_fun(this, &PlacesOverlayVScrollBar::OnMouseDrag));
- overlay_window_->mouse_wheel.connect(sigc::mem_fun(this, &PlacesOverlayVScrollBar::OnMouseWheel));
- overlay_window_->sigHidden.connect(sigc::hide(sigc::mem_fun(this, &PlacesOverlayVScrollBar::ResetConnector)));
-
- _track->geometry_changed.connect(sigc::mem_fun(this, &PlacesOverlayVScrollBar::OnTrackGeometryChanged));
- OnVisibleChanged.connect(sigc::mem_fun(this, &PlacesOverlayVScrollBar::OnVisibilityChanged));
- OnSensitiveChanged.connect(sigc::mem_fun(this, &PlacesOverlayVScrollBar::OnSensitivityChanged));
-
scale.changed.connect([this] (double scale) {
area_prox_->proximity = PROXIMITY.CP(scale);
- overlay_window_->scale = scale;
+ UpdateScrollbarSize();
});
-}
-
-void PlacesOverlayVScrollBar::OnTrackGeometryChanged(nux::Area* /*area*/, nux::Geometry& /*geo*/)
-{
- UpdateStepY();
- overlay_window_->UpdateGeometry(_track->GetAbsoluteGeometry());
-
- if (overlay_window_->IsVisible() && !IsScrollBarVisible())
- {
- overlay_window_->ResetStates();
- ResetConnector();
- }
-}
-
-void PlacesOverlayVScrollBar::OnVisibilityChanged(nux::Area* /*area*/, bool visible)
-{
- if (overlay_window_->IsVisible() && !visible)
- {
- overlay_window_->ResetStates();
- ResetConnector();
- }
-}
-
-void PlacesOverlayVScrollBar::OnSensitivityChanged(nux::Area* /*area*/, bool sensitive)
-{
- if (!sensitive)
- {
- overlay_window_->ResetStates();
- ResetConnector();
- }
-}
-void PlacesOverlayVScrollBar::SetupAnimation(int start, int stop, int milliseconds)
-{
- tweening_connection_->disconnect();
- delta_update_ = 0;
-
- animation_.SetDuration(milliseconds);
- animation_.SetEasingCurve(nux::animation::EasingCurve(nux::animation::EasingCurve::Type::Linear));
-
- animation_.SetStartValue(start);
- animation_.SetFinishValue(stop);
-}
-
-void PlacesOverlayVScrollBar::PerformPageNavigation(ScrollDir dir)
-{
- StartScrollAnimation(dir, _slider->GetBaseHeight());
-}
-
-void PlacesOverlayVScrollBar::StartScrollAnimation(ScrollDir dir, int stop)
-{
- if (animation_.CurrentState() == nux::animation::Animation::State::Stopped)
- {
- SetupAnimation(0, stop, SCROLL_ANIMATION);
-
- tweening_connection_ = animation_.updated.connect([this, dir] (int const& update) {
- OnScroll(dir, update - delta_update_);
- delta_update_ = update;
-
- CheckIfThumbIsInsideSlider();
- UpdateConnectorPosition();
- QueueDraw();
- });
-
- animation_.Start();
- }
-}
-
-void PlacesOverlayVScrollBar::OnScroll(ScrollDir dir, int mouse_dy)
-{
- if (dir == ScrollDir::UP)
- OnScrollUp.emit(stepY, mouse_dy);
- else if (dir == ScrollDir::DOWN)
- OnScrollDown.emit(stepY, mouse_dy);
-}
-
-void PlacesOverlayVScrollBar::StartConnectorAnimation()
-{
- if (animation_.CurrentState() == nux::animation::Animation::State::Stopped)
- {
- SetupAnimation(connector_height_, 0, std::min(connector_height_, MAX_CONNECTOR_ANIMATION));
-
- tweening_connection_ = animation_.updated.connect([this] (int const& update) {
- connector_height_ = update;
- UpdateConnectorTexture();
- });
-
- animation_.Start();
- }
-}
-
-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 (IsSensitive() && IsVisible() && IsScrollBarVisible())
- {
- animation_.Stop();
-
- overlay_window_->MouseNear();
- AdjustThumbOffsetFromMouse();
- }
-}
-
-void PlacesOverlayVScrollBar::OnMouseBeyond(nux::Point const& mouse_pos)
-{
- if (IsVisible() && IsScrollBarVisible())
- {
- overlay_window_->MouseBeyond();
- UpdateConnectorPosition();
- }
-}
-
-void PlacesOverlayVScrollBar::AdjustThumbOffsetFromMouse()
-{
- if (!overlay_window_->IsMouseBeingDragged())
- {
- nux::Point const& mouse = nux::GetWindowCompositor().GetMousePosition();
-
- if (mouse.y > 0)
- {
- int const quarter_of_thumb = overlay_window_->GetThumbHeight()/4;
- int const new_offset = mouse.y - _track->GetAbsoluteY() - overlay_window_->GetThumbHeight()/2;
-
- int const slider_offset = _slider->GetAbsoluteY() - _track->GetAbsoluteY() + _slider->GetBaseHeight()/3;
- bool const mouse_above_slider = slider_offset < new_offset;
-
- if (mouse_above_slider)
- overlay_window_->SetThumbOffsetY(new_offset - quarter_of_thumb);
- else
- overlay_window_->SetThumbOffsetY(new_offset + quarter_of_thumb);
- }
-
- CheckIfThumbIsInsideSlider();
- }
-}
-
-void PlacesOverlayVScrollBar::CheckIfThumbIsInsideSlider()
-{
- nux::Geometry const& slider_geo = _slider->GetAbsoluteGeometry();
- nux::Geometry const& thumb_geo = overlay_window_->GetThumbGeometry();
-
- if (thumb_geo.IsIntersecting(slider_geo))
- {
- ResetConnector();
- overlay_window_->ThumbInsideSlider();
- }
- else
- {
- UpdateConnectorPosition();
- overlay_window_->ThumbOutsideSlider();
- }
-}
-
-void PlacesOverlayVScrollBar::UpdateConnectorPosition()
-{
- int const slider_y = _slider->GetBaseY() - GetBaseY();
- int const thumb_y = overlay_window_->GetThumbOffsetY();
- int const thumb_height = overlay_window_->GetThumbHeight();
-
- if (!overlay_window_->IsVisible())
- {
- ResetConnector();
- }
- else if (slider_y > thumb_y)
- {
- thumb_above_slider_ = true;
- connector_height_ = slider_y - (thumb_y + thumb_height);
- }
- else
- {
- thumb_above_slider_ = false;
- connector_height_ = thumb_y - (_slider->GetBaseY() + _slider->GetBaseHeight()) + _track->GetBaseY();
- }
-
- UpdateConnectorTexture();
-}
-
-void PlacesOverlayVScrollBar::ResetConnector()
-{
- if (animation_.CurrentState() == nux::animation::Animation::State::Stopped)
- {
- if (connector_height_ > 0)
- {
- StartConnectorAnimation();
- }
- }
- else
- {
- connector_height_ = 0;
- }
-
- QueueDraw();
-}
-
-void PlacesOverlayVScrollBar::OnMouseClick(int /*x*/, int y, unsigned int button_flags, unsigned int /*key_flags*/)
-{
- if (!overlay_window_->IsMouseBeingDragged())
- {
- int const button = nux::GetEventButton(button_flags);
-
- if (button == 1)
- LeftMouseClick(y);
- else if (button == 2)
- MiddleMouseClick(y);
- }
-
- overlay_window_->MouseUp();
-}
-
-void PlacesOverlayVScrollBar::LeftMouseClick(int y)
-{
- if (IsMouseInTopHalfOfThumb(y))
- {
- int const top = _slider->GetBaseY() - _track->GetBaseY();
- StartScrollAnimation(ScrollDir::UP, std::min(_slider->GetBaseHeight(), top));
- }
- else
- {
- int const bottom = (_track->GetBaseY() + _track->GetBaseHeight()) -
- (_slider->GetBaseHeight() + _slider->GetBaseY());
- StartScrollAnimation(ScrollDir::DOWN, std::min(_slider->GetBaseHeight(), bottom));
- }
-
- UpdateConnectorPosition();
-}
-
-void PlacesOverlayVScrollBar::MiddleMouseClick(int y)
-{
- int const slider_offset = _slider->GetBaseY() - _track->GetBaseY();
- bool const move_up = slider_offset > overlay_window_->GetThumbOffsetY();
-
- int const slider_thumb_diff = abs(overlay_window_->GetThumbOffsetY() - slider_offset);
-
- if (move_up)
- StartScrollAnimation(ScrollDir::UP, slider_thumb_diff);
- else
- StartScrollAnimation(ScrollDir::DOWN, slider_thumb_diff);
-}
-
-void PlacesOverlayVScrollBar::OnMouseDown(int /*x*/, int y, unsigned int /*button_flags*/, unsigned int /*key_flags*/)
-{
- if (overlay_window_->IsMouseInsideThumb(y))
- {
- if (IsMouseInTopHalfOfThumb(y))
- overlay_window_->PageUpAction();
+ auto update_sb_cb = sigc::mem_fun(this, &PlacesOverlayVScrollBar::UpdateScrollbarSize);
+
+ auto update_sb_proximity_cb = sigc::hide(update_sb_cb);
+ area_prox_->mouse_near.connect(update_sb_proximity_cb);
+ area_prox_->mouse_beyond.connect(update_sb_proximity_cb);
+
+ auto update_sb_mouse_cb = sigc::hide(sigc::hide(sigc::hide(update_sb_proximity_cb)));
+ _track->mouse_enter.connect(update_sb_mouse_cb);
+ _track->mouse_leave.connect(update_sb_mouse_cb);
+ _slider->mouse_enter.connect(update_sb_mouse_cb);
+ _slider->mouse_leave.connect(update_sb_mouse_cb);
+ _slider->mouse_up.connect(update_sb_mouse_cb);
+ _track->mouse_up.connect(update_sb_mouse_cb);
+
+ // Disable default track-click handlers
+ _track->mouse_down.clear();
+ _track->mouse_up.clear();
+ _track->mouse_down.connect([this] (int x, int y, unsigned long, unsigned long) {
+ int slider_vcenter = _slider->GetBaseY() - _track->GetBaseY() + _slider->GetBaseHeight() / 2;
+ int scroll_offset = slider_vcenter - y;
+
+ if (scroll_offset > 0)
+ StartScrollAnimation(ScrollDir::UP, scroll_offset, CLICK_SCROLL_ANIMATION);
else
- overlay_window_->PageDownAction();
+ StartScrollAnimation(ScrollDir::DOWN, -scroll_offset, CLICK_SCROLL_ANIMATION);
+ });
- mouse_down_offset_ = y - overlay_window_->GetThumbOffsetY();
- overlay_window_->MouseDown();
- }
+ UpdateScrollbarSize();
}
-bool PlacesOverlayVScrollBar::IsMouseInTopHalfOfThumb(int y)
+void PlacesOverlayVScrollBar::UpdateScrollbarSize()
{
- int const thumb_height = overlay_window_->GetThumbHeight();
- int const thumb_offset_y = overlay_window_->GetThumbOffsetY();
+ bool is_hovering = false;
+ SetMinimumWidth(ACTIVE_WIDTH.CP(scale));
+ SetMaximumWidth(ACTIVE_WIDTH.CP(scale));
- return (y < (thumb_height/2 + thumb_offset_y));
-}
+ _scroll_up_button->SetMaximumHeight(BUTTONS_HEIGHT.CP(scale));
+ _scroll_up_button->SetMinimumHeight(BUTTONS_HEIGHT.CP(scale));
+ _scroll_down_button->SetMaximumHeight(BUTTONS_HEIGHT.CP(scale));
+ _scroll_down_button->SetMinimumHeight(BUTTONS_HEIGHT.CP(scale));
-void PlacesOverlayVScrollBar::OnMouseUp(int x, int y, unsigned int /*button_flags*/, unsigned int /*key_flags*/)
-{
- nux::Geometry const& geo = overlay_window_->GetAbsoluteGeometry();
+ int slider_width = DEFAULT_WIDTH.CP(scale);
- if (!geo.IsPointInside(x + geo.x, y + geo.y))
+ if (_track->IsMouseInside() || _track->IsMouseOwner() ||
+ _slider->IsMouseInside() || _slider->IsMouseOwner() ||
+ area_prox_->IsMouseNear())
{
- overlay_window_->MouseUp();
- UpdateConnectorPosition();
+ is_hovering = true;
+ slider_width = ACTIVE_WIDTH.CP(scale);
}
-}
-
-void PlacesOverlayVScrollBar::OnMouseMove(int /*x*/, int y, int /*dx*/, int /*dy*/, unsigned int /*button_flags*/, unsigned int /*key_flags*/)
-{
- if (!overlay_window_->IsMouseInsideThumb(y))
- AdjustThumbOffsetFromMouse();
-}
-void PlacesOverlayVScrollBar::OnMouseDrag(int /*x*/, int y, int /*dx*/, int dy, unsigned int /*button_flags*/, unsigned int /*key_flags*/)
-{
- animation_.Stop();
- MouseDraggingOverlay(y, dy);
-}
-
-void PlacesOverlayVScrollBar::OnMouseWheel(int x, int y, int delta, unsigned long mouse_state, unsigned long key_state)
-{
- mouse_wheel.emit(x, y, delta, mouse_state, key_state);
- UpdateConnectorPosition();
-}
+ hovering = is_hovering;
-void PlacesOverlayVScrollBar::MouseDraggingOverlay(int y, int dy)
-{
- int const thumb_offset = overlay_window_->GetThumbOffsetY() + mouse_down_offset_;
-
- if (dy < 0 && !AtMinimum() && y <= thumb_offset)
- {
- OnScrollUp.emit(stepY, abs(dy));
- }
- else if (dy > 0 && !AtMaximum() && y >= thumb_offset)
- {
- OnScrollDown.emit(stepY, dy);
- }
+ _slider->SetMinimumWidth(slider_width);
+ _slider->SetMaximumWidth(slider_width);
+ _scroll_up_button->SetBaseWidth(slider_width);
- overlay_window_->SetThumbOffsetY(y - mouse_down_offset_);
- CheckIfThumbIsInsideSlider();
+ QueueDraw();
}
-void PlacesOverlayVScrollBar::UpdateStepY()
+void PlacesOverlayVScrollBar::PerformPageNavigation(ScrollDir dir)
{
- stepY = (float) (content_height_ - container_height_) / (float) (_track->GetBaseHeight() - _slider->GetBaseHeight());
+ StartScrollAnimation(dir, _slider->GetBaseHeight(), PAGE_SCROLL_ANIMATION);
}
-void PlacesOverlayVScrollBar::Draw(nux::GraphicsEngine& graphics_engine, bool force_draw)
+void PlacesOverlayVScrollBar::StartScrollAnimation(ScrollDir dir, int stop, unsigned duration)
{
- PlacesVScrollBar::Draw(graphics_engine, force_draw);
-
- if (connector_height_ > 0 && connector_texture_.IsValid())
- {
- int const connector_width = GetBaseWidth();
- int offset_y = 0;
- if (thumb_above_slider_)
- {
- offset_y = _slider->GetBaseY() - connector_height_;
- }
- else
- {
- offset_y = _slider->GetBaseY() + _slider->GetBaseHeight();
- }
-
- nux::Geometry base(_track->GetBaseX(), offset_y - 4, connector_width, connector_height_ + 5);
- nux::TexCoordXForm texxform;
-
- graphics_engine.QRP_1Tex(base.x,
- base.y,
- base.width,
- base.height,
- connector_texture_->GetDeviceTexture(),
- texxform,
- nux::color::White);
- }
-}
-
-void PlacesOverlayVScrollBar::UpdateConnectorTexture()
-{
- if (connector_height_ < 0)
+ if (animation_.CurrentState() != nux::animation::Animation::State::Stopped)
return;
- int width = _slider->GetWidth();
- int height = connector_height_;
-
- if (connector_texture_ && connector_texture_->GetWidth() == width && connector_texture_->GetHeight() == height)
- return;
-
- nux::CairoGraphics cairoGraphics(CAIRO_FORMAT_ARGB32, width, height);
- cairo_t* cr = cairoGraphics.GetInternalContext();
- cairo_surface_set_device_scale(cairo_get_target(cr), scale, scale);
+ delta_update_ = 0;
+ stepY = (float) (content_height_ - container_height_) / (float) (_track->GetBaseHeight() - _slider->GetBaseHeight());
- cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR);
- cairo_paint(cr);
+ tweening_connection_ = animation_.updated.connect([this, dir] (int update) {
+ int mouse_dy = update - delta_update_;
- cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
- cairo_set_source_rgba(cr, CONNECTOR_COLOR.red, CONNECTOR_COLOR.green, CONNECTOR_COLOR.blue, 0.8);
- cairo_rectangle(cr, 0, 0, static_cast<double>(width)/scale(), static_cast<double>(height)/scale());
- cairo_fill(cr);
+ if (dir == ScrollDir::UP)
+ OnScrollUp.emit(stepY, mouse_dy);
+ else if (dir == ScrollDir::DOWN)
+ OnScrollDown.emit(stepY, mouse_dy);
- connector_texture_ = texture_ptr_from_cairo_graphics(cairoGraphics);
+ delta_update_ = update;
+ QueueDraw();
+ });
- QueueDraw();
+ animation_.SetDuration(duration);
+ animation::Start(animation_, 0, stop);
}
} // namespace dash
diff --git a/unity-shared/PlacesOverlayVScrollBar.h b/unity-shared/PlacesOverlayVScrollBar.h
index 4319fe5fd..f85d612a0 100644
--- a/unity-shared/PlacesOverlayVScrollBar.h
+++ b/unity-shared/PlacesOverlayVScrollBar.h
@@ -1,6 +1,6 @@
// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
/*
- * Copyright (C) 2012 Canonical Ltd
+ * Copyright (C) 2012-2015 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
@@ -15,6 +15,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Authored by: Brandon Schaefer <brandon.schaefer@canonical.com>
+ * Marco Trevisan <marco.trevisan@canonical.com>
*/
#ifndef PLACES_OVERLAY_VSCROLLBAR_H
@@ -27,7 +28,6 @@
#include <memory>
#include "unity-shared/PlacesVScrollBar.h"
-#include "unity-shared/VScrollBarOverlayWindow.h"
namespace unity
{
@@ -46,67 +46,17 @@ public:
PlacesOverlayVScrollBar(NUX_FILE_LINE_PROTO);
virtual ~PlacesOverlayVScrollBar() {}
- void PerformPageNavigation(ScrollDir dir);
-
-protected:
- void Draw(nux::GraphicsEngine& graphics_engine, bool force_draw);
+ void PerformPageNavigation(ScrollDir);
private:
- void OnTrackGeometryChanged(nux::Area* area, nux::Geometry& geo);
- void OnVisibilityChanged(nux::Area* area, bool visible);
- void OnSensitivityChanged(nux::Area* area, bool sensitive);
-
- 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();
-
- void OnMouseClick(int x, int y, unsigned int button_flags, unsigned int key_flags);
- void LeftMouseClick(int y);
- void MiddleMouseClick(int y);
-
- void OnMouseDown(int x, int y, unsigned int button_flags, unsigned int key_flags);
- void OnMouseUp(int x, int y, unsigned int button_flags, unsigned int key_flags);
- void OnMouseMove(int x, int y, int dx, int dy, unsigned int button_flags, unsigned int key_flags);
- void OnMouseDrag(int x, int y, int dx, int dy, unsigned int button_flags, unsigned int key_flags);
- void OnMouseWheel(int x, int y, int delta, unsigned long mouse_state, unsigned long key_state);
-
- void MouseDraggingOverlay(int y, int dy);
-
- bool IsMouseInTopHalfOfThumb(int y);
- void CheckIfThumbIsInsideSlider();
-
- bool IsScrollBarVisible() const;
-
- void UpdateConnectorPosition();
- void ResetConnector();
-
- void UpdateStepY();
-
- void SetupAnimation(int start, int stop, int milliseconds);
-
- void StartScrollAnimation(ScrollDir dir, int stop);
- void OnScroll(ScrollDir dir, int mouse_dy);
-
- void StartConnectorAnimation();
-
- void UpdateConnectorTexture();
-
- nux::ObjectPtr<VScrollBarOverlayWindow> overlay_window_;
+ void UpdateScrollbarSize();
+ void StartScrollAnimation(ScrollDir, int stop, unsigned duration);
class ProximityArea;
std::shared_ptr<ProximityArea> area_prox_;
nux::animation::AnimateValue<int> animation_;
connection::Wrapper tweening_connection_;
-
- nux::ObjectPtr<nux::BaseTexture> connector_texture_;
-
- bool thumb_above_slider_;
- int connector_height_;
- int mouse_down_offset_;
int delta_update_;
friend class MockScrollBar;
diff --git a/unity-shared/PlacesVScrollBar.cpp b/unity-shared/PlacesVScrollBar.cpp
index 60ae8c804..9885fe12b 100644
--- a/unity-shared/PlacesVScrollBar.cpp
+++ b/unity-shared/PlacesVScrollBar.cpp
@@ -21,9 +21,10 @@
#include <Nux/Nux.h>
#include <NuxGraphics/CairoGraphics.h>
+#include "PlacesVScrollBar.h"
#include "unity-shared/CairoTexture.h"
#include "unity-shared/RawPixel.h"
-#include "PlacesVScrollBar.h"
+#include "unity-shared/GraphicsUtils.h"
namespace unity
{
@@ -31,13 +32,14 @@ namespace dash
{
namespace
{
-const RawPixel BUTTONS_HEIGHT = 15_em;
+const RawPixel BUTTONS_HEIGHT = 0_em;
const RawPixel WIDTH = 3_em;
}
PlacesVScrollBar::PlacesVScrollBar(NUX_FILE_LINE_DECL)
: nux::VScrollBar(NUX_FILE_LINE_PARAM)
, scale(1.0)
+ , hovering(false)
{
UpdateSize();
scale.changed.connect([this] (double scale) {
@@ -54,53 +56,16 @@ void PlacesVScrollBar::UpdateSize()
_scroll_down_button->SetMaximumHeight(BUTTONS_HEIGHT.CP(scale));
_scroll_down_button->SetMinimumHeight(BUTTONS_HEIGHT.CP(scale));
-
- _slider->SetMinimumWidth(WIDTH.CP(scale));
- _slider->SetMaximumWidth(WIDTH.CP(scale));
- SetMinimumWidth(WIDTH.CP(scale));
- SetMaximumWidth(WIDTH.CP(scale));
}
-void PlacesVScrollBar::PreLayoutManagement()
-{
- nux::VScrollBar::PreLayoutManagement();
-}
+void PlacesVScrollBar::Draw(nux::GraphicsEngine& graphics_engine, bool force_draw)
+{}
-long
-PlacesVScrollBar::PostLayoutManagement(long LayoutResult)
-{
- long ret = nux::VScrollBar::PostLayoutManagement(LayoutResult);
-
- UpdateTexture();
- return ret;
-}
-
-void
-PlacesVScrollBar::Draw(nux::GraphicsEngine& graphics_engine, bool force_draw)
+void PlacesVScrollBar::DrawContent(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)
-{
- // check if textures have been computed... if they haven't, exit function
- if (!slider_texture_)
return;
- nux::Color color = nux::color::White;
nux::Geometry const& base = GetGeometry();
nux::TexCoordXForm texxform;
@@ -108,7 +73,6 @@ PlacesVScrollBar::DrawScrollbar(nux::GraphicsEngine& graphics_engine)
unsigned int alpha = 0, src = 0, dest = 0;
graphics_engine.GetRenderStates().GetBlend(alpha, src, dest);
-
texxform.SetTexCoordType(nux::TexCoordXForm::OFFSET_SCALE_COORD);
graphics_engine.GetRenderStates().SetBlend(true);
@@ -117,29 +81,50 @@ PlacesVScrollBar::DrawScrollbar(nux::GraphicsEngine& graphics_engine)
if (content_height_ > container_height_)
{
nux::Geometry const& slider_geo = _slider->GetGeometry();
+ nux::GetPainter().PushBackgroundStack();
- graphics_engine.QRP_1Tex(slider_geo.x,
- slider_geo.y,
- slider_geo.width,
- slider_geo.height,
- slider_texture_->GetDeviceTexture(),
- texxform,
- color);
+ if (hovering)
+ graphics::ClearGeometry(base);
+
+ nux::ROPConfig rop;
+ rop.Blend = true;
+ rop.SrcBlend = GL_ONE;
+ rop.DstBlend = GL_ONE_MINUS_SRC_ALPHA;
+
+ nux::ColorLayer layer(nux::color::Transparent, true, rop);
+ nux::GetPainter().PushDrawLayer(graphics_engine, base, &layer);
+
+ if (hovering)
+ graphics_engine.QRP_Color(base.x, base.y, base.width, base.height, nux::color::White * 0.4);
+
+ UpdateTexture(slider_geo);
+ graphics_engine.QRP_1Tex(base.x + base.width - slider_geo.width,
+ slider_geo.y,
+ slider_geo.width,
+ slider_geo.height,
+ slider_texture_->GetDeviceTexture(),
+ texxform,
+ nux::color::White);
+
+ nux::GetPainter().PopBackgroundStack();
}
graphics_engine.PopClippingRectangle();
graphics_engine.GetRenderStates().SetBlend(alpha, src, dest);
}
-void PlacesVScrollBar::UpdateTexture()
+void PlacesVScrollBar::UpdateTexture(nux::Geometry const& geo)
{
// update texture of slider
- int width = _slider->GetBaseWidth();
- int height = _slider->GetBaseHeight();
+ int width = geo.width;
+ int height = geo.height;
if (slider_texture_ && slider_texture_->GetWidth() == width && slider_texture_->GetHeight() == height)
return;
+ double unscaled_width = static_cast<double>(width) / scale();
+ double unscaled_height = static_cast<double>(height) / scale();
+
nux::CairoGraphics cg(CAIRO_FORMAT_ARGB32, width, height);
auto* cr = cg.GetInternalContext();
cairo_surface_set_device_scale(cairo_get_target(cr), scale, scale);
@@ -149,7 +134,7 @@ void PlacesVScrollBar::UpdateTexture()
cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
cairo_set_source_rgba(cr, 1.0f, 1.0f, 1.0f, 1.0f);
- cg.DrawRoundedRectangle(cr, 1.0f, 0.0, 0.0, 1.5, 3.0, static_cast<double>(height)/scale() - 3.0);
+ cg.DrawRoundedRectangle(cr, 1.0f, 0, 0, unscaled_width / 2.0, unscaled_width, unscaled_height - 2.0);
cairo_fill(cr);
slider_texture_ = texture_ptr_from_cairo_graphics(cg);
diff --git a/unity-shared/PlacesVScrollBar.h b/unity-shared/PlacesVScrollBar.h
index 2a7fc16b2..ec6517cb4 100644
--- a/unity-shared/PlacesVScrollBar.h
+++ b/unity-shared/PlacesVScrollBar.h
@@ -33,18 +33,15 @@ public:
PlacesVScrollBar(NUX_FILE_LINE_PROTO);
nux::Property<double> scale;
+ nux::Property<bool> hovering;
protected:
- virtual void PreLayoutManagement();
- virtual long PostLayoutManagement(long LayoutResult);
-
void Draw(nux::GraphicsEngine& gfxContext, bool forceDraw);
void DrawContent(nux::GraphicsEngine& gfxContext, bool forceDraw);
private:
void UpdateSize();
- void UpdateTexture();
- void DrawScrollbar(nux::GraphicsEngine& graphics_engine);
+ void UpdateTexture(nux::Geometry const&);
private:
nux::ObjectPtr<nux::BaseTexture> slider_texture_;
diff --git a/unity-shared/VScrollBarOverlayWindow.cpp b/unity-shared/VScrollBarOverlayWindow.cpp
deleted file mode 100644
index 46f40eab3..000000000
--- a/unity-shared/VScrollBarOverlayWindow.cpp
+++ /dev/null
@@ -1,568 +0,0 @@
-// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
-/*
- * Copyright (C) 2012 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: Brandon Schaefer <brandon.schaefer@canonical.com>
- */
-
-#include <Nux/Nux.h>
-#include <NuxGraphics/CairoGraphics.h>
-
-#include "VScrollBarOverlayWindow.h"
-#include "UScreen.h"
-#include "DashStyle.h"
-#include "CairoTexture.h"
-#include "unity-shared/AnimationUtils.h"
-
-namespace unity
-{
-
-namespace
-{
- const RawPixel THUMB_WIDTH = 21_em;
- const RawPixel THUMB_HEIGHT = 68_em;
- const int THUMB_RADIUS = 3;
- const int ANIMATION_DURATION = 90;
-}
-
-VScrollBarOverlayWindow::VScrollBarOverlayWindow(nux::Geometry const& geo)
- : nux::BaseWindow("")
- , scale(1.0)
- , content_size_(geo)
- , content_offset_x_(0)
- , mouse_offset_y_(0)
- , current_state_(ThumbState::NONE)
- , current_action_(ThumbAction::NONE)
- , show_animator_(ANIMATION_DURATION)
-{
- Area::SetGeometry(content_size_.x, content_size_.y, THUMB_WIDTH.CP(scale), content_size_.height);
- SetBackgroundColor(nux::color::Transparent);
- SetAcceptMouseWheelEvent(true);
-
- show_animator_.updated.connect(sigc::mem_fun(this, &BaseWindow::SetOpacity));
- show_animator_.finished.connect([this] {
- if (animation::GetDirection(show_animator_) == animation::Direction::BACKWARD)
- ShowWindow(false);
- });
-
- SetOpacity(0.0f);
- UpdateTexture();
-
- scale.changed.connect([this] (double scale) {
- UpdateContentGeometry();
- UpdateTexture();
- });
-}
-
-void VScrollBarOverlayWindow::UpdateContentGeometry()
-{
- UpdateMouseOffsetX();
- Area::SetGeometry(content_size_.x + content_offset_x_, content_size_.y, THUMB_WIDTH.CP(scale), content_size_.height);
-}
-
-void VScrollBarOverlayWindow::UpdateGeometry(nux::Geometry const& geo)
-{
- if (content_size_.x != geo.x ||
- content_size_.y != geo.y ||
- content_size_.height != geo.height)
- {
- content_size_ = geo;
- UpdateContentGeometry();
- }
-}
-
-void VScrollBarOverlayWindow::SetThumbOffsetY(int y)
-{
- int const new_offset = GetValidOffsetYValue(y);
-
- if (new_offset != mouse_offset_y_)
- {
- if (HasState(ThumbState::MOUSE_DOWN))
- MouseDragging();
-
- mouse_offset_y_ = new_offset;
- QueueDraw();
- }
-}
-
-int VScrollBarOverlayWindow::GetValidOffsetYValue(int new_offset) const
-{
- if (new_offset < 0)
- return 0;
- else if (new_offset > content_size_.height - THUMB_HEIGHT.CP(scale))
- return content_size_.height - THUMB_HEIGHT.CP(scale);
-
- return new_offset;
-}
-
-void VScrollBarOverlayWindow::UpdateMouseOffsetX()
-{
- int monitor = unity::UScreen::GetDefault()->GetMonitorWithMouse();
- nux::Geometry const& geo = unity::UScreen::GetDefault()->GetMonitorGeometry(monitor);
-
- if (content_size_.x + THUMB_WIDTH.CP(scale) > geo.x + geo.width)
- content_offset_x_ = geo.x + geo.width - (content_size_.x + THUMB_WIDTH.CP(scale));
- else
- content_offset_x_ = 0;
-}
-
-bool VScrollBarOverlayWindow::IsMouseInsideThumb(int y) const
-{
- nux::Geometry const thumb(0, mouse_offset_y_, THUMB_WIDTH.CP(scale), THUMB_HEIGHT.CP(scale));
- return thumb.IsPointInside(0,y);
-}
-
-bool VScrollBarOverlayWindow::IsMouseBeingDragged() const
-{
- return current_action_ == ThumbAction::DRAGGING;
-}
-
-int VScrollBarOverlayWindow::GetThumbHeight() const
-{
- return THUMB_HEIGHT.CP(scale);
-}
-
-int VScrollBarOverlayWindow::GetThumbOffsetY() const
-{
- return mouse_offset_y_;
-}
-
-nux::Geometry VScrollBarOverlayWindow::GetThumbGeometry() const
-{
- return nux::Geometry(content_size_.x + content_offset_x_,
- content_size_.y + mouse_offset_y_,
- THUMB_WIDTH.CP(scale), THUMB_HEIGHT.CP(scale));
-}
-
-void VScrollBarOverlayWindow::MouseDown()
-{
- AddState(ThumbState::MOUSE_DOWN);
- UpdateTexture();
-}
-
-void VScrollBarOverlayWindow::MouseUp()
-{
- RemoveState(ThumbState::MOUSE_DOWN);
- current_action_ = ThumbAction::NONE;
- UpdateTexture();
- ShouldHide();
-}
-
-void VScrollBarOverlayWindow::MouseNear()
-{
- AddState(ThumbState::MOUSE_NEAR);
- ShouldShow();
-}
-
-void VScrollBarOverlayWindow::MouseBeyond()
-{
- 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 (!HasState(ThumbState::INSIDE_SLIDER))
- {
- AddState(ThumbState::INSIDE_SLIDER);
- UpdateTexture();
- }
-}
-
-void VScrollBarOverlayWindow::ThumbOutsideSlider()
-{
- if (HasState(ThumbState::INSIDE_SLIDER))
- {
- RemoveState(ThumbState::INSIDE_SLIDER);
- UpdateTexture();
- }
-}
-
-void VScrollBarOverlayWindow::PageUpAction()
-{
- current_action_ = ThumbAction::PAGE_UP;
- UpdateTexture();
-}
-
-void VScrollBarOverlayWindow::PageDownAction()
-{
- current_action_ = ThumbAction::PAGE_DOWN;
- UpdateTexture();
-}
-
-void VScrollBarOverlayWindow::MouseDragging()
-{
- if (current_action_ != ThumbAction::DRAGGING)
- {
- current_action_ = ThumbAction::DRAGGING;
- UpdateTexture();
- }
-}
-
-void VScrollBarOverlayWindow::ShouldShow()
-{
- if (!IsVisible())
- {
- if (HasState(ThumbState::MOUSE_DOWN) ||
- HasState(ThumbState::MOUSE_NEAR))
- {
- ShowWindow(true);
- PushToFront();
- animation::StartOrReverse(show_animator_, animation::Direction::FORWARD);
- }
- }
-}
-
-void VScrollBarOverlayWindow::ShouldHide()
-{
- if (IsVisible())
- {
- if (!(HasState(ThumbState::MOUSE_DOWN)) &&
- !(HasState(ThumbState::MOUSE_NEAR)) &&
- !(HasState(ThumbState::MOUSE_INSIDE)))
- {
- animation::StartOrReverse(show_animator_, animation::Direction::BACKWARD);
- }
- }
-}
-
-void VScrollBarOverlayWindow::ResetStates()
-{
- 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_)
- return;
-
- nux::Geometry base(0, mouse_offset_y_, THUMB_WIDTH.CP(scale), THUMB_HEIGHT.CP(scale));
- nux::TexCoordXForm texxform;
-
- graphics_engine.QRP_1Tex(base.x,
- base.y,
- base.width,
- base.height,
- thumb_texture_->GetDeviceTexture(),
- texxform,
- nux::color::White);
-}
-
-nux::color::RedGreenBlue ProduceColorShade(nux::color::RedGreenBlue const& rgb, float shade)
-{
- if (shade == 1.0f)
- return rgb;
-
- nux::color::HueLightnessSaturation hls(rgb);
-
- hls.lightness *= shade;
- if (hls.lightness > 1.0f)
- hls.lightness = 1.0f;
- else if (hls.lightness < 0.0f)
- hls.lightness = 0.0f;
-
- hls.saturation *= shade;
- if (hls.saturation > 1.0f)
- hls.saturation = 1.0f;
- else if (hls.saturation < 0.0f)
- hls.saturation = 0.0f;
-
- nux::color::RedGreenBlue rgb_shade(hls);
-
- return rgb_shade;
-}
-
-void PatternAddRGBStop(cairo_pattern_t* pat, nux::color::RedGreenBlue const& rgb, double stop, float alpha)
-{
- cairo_pattern_add_color_stop_rgba (pat, stop, rgb.red, rgb.green, rgb.blue, alpha);
-}
-
-void SetSourceRGB(cairo_t* cr, nux::color::RedGreenBlue const& rgb, float alpha)
-{
- cairo_set_source_rgba(cr, rgb.red, rgb.green, rgb.blue, alpha);
-}
-
-void DrawGrip (cairo_t* cr, double x, double y, int nx, int ny)
-{
- gint lx, ly;
-
- for (ly = 0; ly < ny; ly++)
- {
- for (lx = 0; lx < nx; lx++)
- {
- gint sx = lx * 3;
- gint sy = ly * 3;
-
- cairo_rectangle (cr, x + sx, y + sy, 1, 1);
- }
- }
-}
-
-void DrawBothGrips(cairo_t* cr, nux::color::RedGreenBlue const& rgb, int width, int height)
-{
- int const grip_width = 5;
- int const grip_height = 6;
- float const grip_y = 13.5;
- float const offset = 6.5;
-
- cairo_pattern_t* pat;
- pat = cairo_pattern_create_linear(0, 0, 0, height);
-
- PatternAddRGBStop(pat, rgb, 0.0, 0.0);
- PatternAddRGBStop(pat, rgb, 0.49, 0.5);
- PatternAddRGBStop(pat, rgb, 0.49, 0.5);
- PatternAddRGBStop(pat, rgb, 1.0, 0.0);
-
- cairo_set_source(cr, pat);
- cairo_pattern_destroy(pat);
-
- DrawGrip(cr, width/2 - offset, grip_y, grip_width, grip_height);
- DrawGrip(cr, width/2 - offset, height/2 + (grip_y - 10), grip_width, grip_height);
-
- cairo_fill(cr);
-}
-
-void DrawLineSeperator(cairo_t* cr, nux::color::RedGreenBlue const& top,
- nux::color::RedGreenBlue const& bottom, int width, int height)
-{
- int const offset = 1.5;
-
- // Top
- cairo_move_to(cr, offset, height/2);
- cairo_line_to(cr, width - offset, height/2);
- SetSourceRGB(cr, top, 0.36);
- cairo_stroke(cr);
-
- // Bottom
- cairo_move_to(cr, offset, 1 + height/2);
- cairo_line_to(cr, width - offset, 1 + height/2);
- SetSourceRGB(cr, bottom, 0.5);
- cairo_stroke(cr);
-}
-
-
-void DrawArrow(cairo_t* cr, nux::color::RedGreenBlue const& rgb, double x, double y, double width, double height)
-{
- cairo_save (cr);
-
- cairo_translate (cr, x, y);
- cairo_move_to (cr, -width / 2, -height / 2);
- cairo_line_to (cr, 0, height / 2);
- cairo_line_to (cr, width / 2, -height / 2);
- cairo_close_path (cr);
-
- SetSourceRGB(cr, rgb, 0.75);
- cairo_fill_preserve (cr);
-
- SetSourceRGB(cr, rgb, 1.0);
- cairo_stroke (cr);
-
- cairo_restore (cr);
-}
-
-void DrawBothArrows(cairo_t* cr, nux::color::RedGreenBlue const& rgb, int width, int height)
-{
- int const arrow_width = 5;
- int const arrow_height = 3;
- float const trans_height = 8.5;
- float const offset_x = 0.5;
-
- // Top
- cairo_save(cr);
- cairo_translate(cr, width/2 + offset_x, trans_height);
- cairo_rotate(cr, G_PI);
- DrawArrow(cr, rgb, offset_x, 0, arrow_width, arrow_height);
- cairo_restore(cr);
-
- // Bottom
- cairo_save(cr);
- cairo_translate(cr, width/2 + offset_x, height - trans_height);
- cairo_rotate(cr, 0);
- DrawArrow(cr, rgb, -offset_x, 0, arrow_width, arrow_height);
- cairo_restore(cr);
-}
-
-void VScrollBarOverlayWindow::UpdateTexture()
-{
- int width = THUMB_WIDTH;
- int height = THUMB_HEIGHT;
-
- float const aspect = 1.0f;
- float current_x = 0.0f;
- float current_y = 0.0f;
-
- auto const& bg = nux::color::WhiteSmoke;
- auto const& bg_selected = nux::color::White;
- auto const& bg_active = nux::color::Gray;
- auto const& arrow_color = nux::color::DarkSlateGray;
-
- auto const& bg_arrow_up = ProduceColorShade(bg, 0.86);
- auto const& bg_arrow_down = ProduceColorShade(bg, 1.1);
- auto const& bg_shadow = ProduceColorShade(bg, 0.2);
-
- auto const& bg_dark_line = ProduceColorShade(bg, 0.4);
- auto const& bg_bright_line = ProduceColorShade(bg, 1.2);
-
- nux::CairoGraphics cairoGraphics(CAIRO_FORMAT_ARGB32, THUMB_WIDTH.CP(scale), THUMB_HEIGHT.CP(scale));
- cairo_t* cr = cairoGraphics.GetInternalContext();
- cairo_surface_set_device_scale(cairo_get_target(cr), scale, scale);
-
- cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR);
- cairo_paint(cr);
-
- cairo_translate (cr, 0.5, 0.5);
- width--;
- height--;
-
- cairo_set_line_width (cr, 1.0);
-
- cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
-
- // Draw backgound
- SetSourceRGB(cr, bg, 1.0);
- cairoGraphics.DrawRoundedRectangle(cr, aspect, current_x, current_y, THUMB_RADIUS, width, height);
- cairo_fill_preserve(cr);
-
- // Draw shaded background
- cairo_pattern_t* pat = cairo_pattern_create_linear(0, 0, 0, height);
-
- PatternAddRGBStop(pat, bg_arrow_up, 0.0, 0.8);
- PatternAddRGBStop(pat, bg_arrow_down, 1.0, 0.8);
-
- cairo_set_source(cr, pat);
- cairo_pattern_destroy(pat);
-
- if (current_action_ == ThumbAction::DRAGGING)
- {
- cairo_fill_preserve(cr);
- SetSourceRGB(cr, bg, 0.8);
- cairo_fill(cr);
- }
- else
- {
- cairo_fill(cr);
- }
-
- // Draw Page Up/Down Action
- if (current_action_ == ThumbAction::PAGE_UP ||
- current_action_ == ThumbAction::PAGE_DOWN)
- {
- if (current_action_ == ThumbAction::PAGE_UP)
- cairo_rectangle(cr, 0, 0, width, height/2);
- else
- cairo_rectangle(cr, 0, height/2, width, height/2);
-
- SetSourceRGB(cr, bg, 0.8);
- cairo_fill(cr);
- }
-
- cairo_save(cr);
-
- // Draw Outline
- cairo_set_line_width (cr, 2.0);
-
- current_x += 0.5;
- current_y += 0.5;
- cairoGraphics.DrawRoundedRectangle(cr, aspect, current_x, current_y, THUMB_RADIUS - 1, width - 1, height - 1);
-
- if (HasState(ThumbState::INSIDE_SLIDER))
- SetSourceRGB(cr, bg_selected, 1.0);
- else
- SetSourceRGB(cr, bg_active, 0.9);
-
- cairo_stroke(cr);
-
- cairo_restore(cr);
-
- // Draw shade outline
- pat = cairo_pattern_create_linear(0, 0, 0, height);
-
- PatternAddRGBStop(pat, bg_shadow, 0.5, 0.06);
-
- switch(current_action_)
- {
- case ThumbAction::NONE:
- PatternAddRGBStop(pat, bg_shadow, 0.0, 0.22);
- PatternAddRGBStop(pat, bg_shadow, 1.0, 0.22);
- break;
- case ThumbAction::DRAGGING:
- PatternAddRGBStop(pat, bg_shadow, 0.0, 0.2);
- PatternAddRGBStop(pat, bg_shadow, 1.0, 0.2);
- break;
- case ThumbAction::PAGE_UP:
- PatternAddRGBStop(pat, bg_shadow, 0.0, 0.1);
- PatternAddRGBStop(pat, bg_shadow, 1.0, 0.22);
- break;
- case ThumbAction::PAGE_DOWN:
- PatternAddRGBStop(pat, bg_shadow, 0.0, 0.22);
- PatternAddRGBStop(pat, bg_shadow, 1.0, 0.1);
- break;
- default:
- break;
- }
-
- cairo_set_source(cr, pat);
- cairo_pattern_destroy(pat);
-
- current_x += 0.5;
- current_y += 0.5;
- cairoGraphics.DrawRoundedRectangle(cr, aspect, current_x, current_y, THUMB_RADIUS, width- 2, height - 2);
- cairo_stroke(cr);
-
- current_x += 1.0;
- current_y += 1.0;
- cairoGraphics.DrawRoundedRectangle(cr, aspect, current_x, current_y, THUMB_RADIUS - 1, width - 4, height- 4);
- SetSourceRGB(cr, bg_bright_line, 0.6);
- cairo_stroke(cr);
-
- DrawBothGrips(cr, bg_dark_line, width, height);
- DrawLineSeperator(cr, bg_dark_line, bg_bright_line, width, height);
- DrawBothArrows(cr, arrow_color, width, height);
-
- thumb_texture_ = texture_ptr_from_cairo_graphics(cairoGraphics);
-
- QueueDraw();
-}
-
-} // namespace unity
diff --git a/unity-shared/VScrollBarOverlayWindow.h b/unity-shared/VScrollBarOverlayWindow.h
deleted file mode 100644
index 5c8ad75f0..000000000
--- a/unity-shared/VScrollBarOverlayWindow.h
+++ /dev/null
@@ -1,114 +0,0 @@
-// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
-/*
- * Copyright (C) 2012 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: Brandon Schaefer <brandon.schaefer@canonical.com>
- */
-
-
-#ifndef VSCROLLBAR_OVERLAY_WINDOW_H
-#define VSCROLLBAR_OVERLAY_WINDOW_H
-
-#include <Nux/Nux.h>
-#include <Nux/BaseWindow.h>
-#include <NuxCore/Animation.h>
-
-namespace unity
-{
-
-class VScrollBarOverlayWindow : public nux::BaseWindow
-{
-public:
- VScrollBarOverlayWindow(nux::Geometry const& geo);
-
- nux::Property<double> scale;
-
- void UpdateGeometry(nux::Geometry const& geo);
- void SetThumbOffsetY(int y);
-
- void MouseDown();
- void MouseUp();
-
- void MouseNear();
- void MouseBeyond();
-
- void MouseEnter();
- void MouseLeave();
-
- void ThumbInsideSlider();
- void ThumbOutsideSlider();
-
- void PageUpAction();
- void PageDownAction();
-
- bool IsMouseInsideThumb(int y) const;
- bool IsMouseBeingDragged() const;
-
- int GetThumbHeight() const;
- int GetThumbOffsetY() const;
-
- nux::Geometry GetThumbGeometry() const;
-
- void ResetStates();
-
-protected:
- virtual void Draw(nux::GraphicsEngine& graphics_engine, bool force_draw);
-
-private:
- enum class ThumbAction : unsigned int
- {
- NONE,
- DRAGGING,
- PAGE_UP,
- 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();
- void UpdateContentGeometry();
- int GetValidOffsetYValue(int y) const;
-
- void ShouldShow();
- void ShouldHide();
-
- void UpdateTexture();
-
- nux::Geometry content_size_;
- nux::ObjectPtr<nux::BaseTexture> thumb_texture_;
-
- int content_offset_x_;
- int mouse_offset_y_;
-
- void AddState(ThumbState const& state);
- void RemoveState(ThumbState const& state);
- bool HasState(ThumbState const& state) const;
-
- unsigned int current_state_;
- ThumbAction current_action_;
- nux::animation::AnimateValue<double> show_animator_;
-};
-
-} // namespace unity
-
-#endif // VSCROLLBAR_OVERLAY_WINDOW_H