diff options
| author | Marco Trevisan (Treviño) <mail@3v1n0.net> | 2014-07-31 18:38:48 +0000 |
|---|---|---|
| committer | CI bot <ps-jenkins@lists.canonical.com> | 2014-07-31 18:38:48 +0000 |
| commit | 7ca6f5931385f949ae6707b9e1a502ac518f96cb (patch) | |
| tree | 0683d4e1d3f0c0adaa73f7b946bc877f4cdeeec1 /unity-shared | |
| parent | 1e0b49b54c44e656d0f34dad96486c29c3a89a70 (diff) | |
| parent | 760b988cc92e97dc2be3d773aac8004609e8ae95 (diff) | |
PlacesOverlayVScrollBar and VScrollBarOverlayWindow: add support for scaling
Add a new ScrollView class to create ScrollViews with an OverlayScrollbar and with scaling support. Using them in dash Scopes and Previews. Fixes: 1340996 Approved by: Brandon Schaefer, PS Jenkins bot (bzr r3846)
Diffstat (limited to 'unity-shared')
| -rw-r--r-- | unity-shared/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | unity-shared/OverlayScrollView.cpp | 56 | ||||
| -rw-r--r-- | unity-shared/OverlayScrollView.h | 43 | ||||
| -rw-r--r-- | unity-shared/PlacesOverlayVScrollBar.cpp | 61 | ||||
| -rw-r--r-- | unity-shared/PlacesOverlayVScrollBar.h | 6 | ||||
| -rw-r--r-- | unity-shared/PlacesVScrollBar.cpp | 95 | ||||
| -rw-r--r-- | unity-shared/PlacesVScrollBar.h | 17 | ||||
| -rw-r--r-- | unity-shared/VScrollBarOverlayWindow.cpp | 89 | ||||
| -rw-r--r-- | unity-shared/VScrollBarOverlayWindow.h | 4 |
9 files changed, 243 insertions, 129 deletions
diff --git a/unity-shared/CMakeLists.txt b/unity-shared/CMakeLists.txt index b56c77990..ed39e5809 100644 --- a/unity-shared/CMakeLists.txt +++ b/unity-shared/CMakeLists.txt @@ -44,6 +44,7 @@ set (UNITY_SHARED_SOURCES LineSeparator.cpp MenuManager.cpp OverlayRenderer.cpp + OverlayScrollView.cpp OverlayWindowButtons.cpp PanelStyle.cpp PlacesVScrollBar.cpp diff --git a/unity-shared/OverlayScrollView.cpp b/unity-shared/OverlayScrollView.cpp new file mode 100644 index 000000000..c8cc72280 --- /dev/null +++ b/unity-shared/OverlayScrollView.cpp @@ -0,0 +1,56 @@ +// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- +/* + * Copyright (C) 2014 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 <marco.trevisan@canonical.com> + */ + +#include "OverlayScrollView.h" +#include "PlacesOverlayVScrollBar.h" +#include "RawPixel.h" + +namespace unity +{ +namespace dash +{ +namespace +{ + const RawPixel MOUSE_WHEEL_SCROLL_SIZE = 32_em; +} + +ScrollView::ScrollView(NUX_FILE_LINE_DECL) + : nux::ScrollView(NUX_FILE_LINE_PARAM) +{ + auto* scrollbar = new PlacesOverlayVScrollBar(NUX_TRACKER_LOCATION); + SetVScrollBar(scrollbar); + + scale.SetGetterFunction([scrollbar] { return scrollbar->scale(); }); + scale.SetSetterFunction([scrollbar] (double scale) { + if (scrollbar->scale() == scale) + return false; + + scrollbar->scale = scale; + return true; + }); + + m_MouseWheelScrollSize = MOUSE_WHEEL_SCROLL_SIZE.CP(scale); + + scale.changed.connect([this] (double scale) { + m_MouseWheelScrollSize = MOUSE_WHEEL_SCROLL_SIZE.CP(scale); + }); +} + +} // dash namespace +} // unity namespace \ No newline at end of file diff --git a/unity-shared/OverlayScrollView.h b/unity-shared/OverlayScrollView.h new file mode 100644 index 000000000..1cabd05a8 --- /dev/null +++ b/unity-shared/OverlayScrollView.h @@ -0,0 +1,43 @@ +// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- +/* + * Copyright (C) 2014 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 <marco.trevisan@canonical.com> + */ + +#ifndef _UNITY_SCROLL_VIEW_H_ +#define _UNITY_SCROLL_VIEW_H_ + +#include <Nux/Nux.h> + +namespace unity +{ +namespace dash +{ + +class ScrollView : public nux::ScrollView +{ +public: + ScrollView(NUX_FILE_LINE_PROTO); + + nux::RWProperty<double> scale; + + using nux::ScrollView::SetVScrollBar; +}; + +} // dash namespace +} // unity namespace + +#endif // _UNITY_SCROLL_VIEW_H_ diff --git a/unity-shared/PlacesOverlayVScrollBar.cpp b/unity-shared/PlacesOverlayVScrollBar.cpp index b715f62cf..5136ed58f 100644 --- a/unity-shared/PlacesOverlayVScrollBar.cpp +++ b/unity-shared/PlacesOverlayVScrollBar.cpp @@ -19,33 +19,46 @@ #include <Nux/Nux.h> -#include "PlacesOverlayVScrollBar.h" #include "CairoTexture.h" +#include "PlacesOverlayVScrollBar.h" +#include "RawPixel.h" +namespace unity +{ +namespace dash +{ namespace { - int const PROXIMITY = 7; - int const SCROLL_ANIMATION = 400; - int const MAX_CONNECTOR_ANIMATION = 200; + const RawPixel PROXIMITY = 7_em; + const int SCROLL_ANIMATION = 400; + const int MAX_CONNECTOR_ANIMATION = 200; + const nux::Color CONNECTOR_COLOR = nux::color::Gray; } -namespace unity -{ -namespace dash +class 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; +}; PlacesOverlayVScrollBar::PlacesOverlayVScrollBar(NUX_FILE_LINE_DECL) : PlacesVScrollBar(NUX_FILE_LINE_PARAM) , overlay_window_(new VScrollBarOverlayWindow(_track->GetAbsoluteGeometry())) - , area_prox_(this, PROXIMITY) + , 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)); + 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)); @@ -58,6 +71,11 @@ PlacesOverlayVScrollBar::PlacesOverlayVScrollBar(NUX_FILE_LINE_DECL) _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; + }); } void PlacesOverlayVScrollBar::OnTrackGeometryChanged(nux::Area* /*area*/, nux::Geometry& /*geo*/) @@ -410,30 +428,25 @@ void PlacesOverlayVScrollBar::UpdateConnectorTexture() if (connector_height_ < 0) return; - int width = 3; + int width = _slider->GetWidth(); int height = connector_height_; - float const radius = 1.5f; - float const aspect = 1.0f; - cairo_t* cr = NULL; - - nux::color::RedGreenBlue const& connector_bg = nux::color::Gray; + if (connector_texture_ && connector_texture_->GetWidth() == width && connector_texture_->GetHeight() == height) + return; nux::CairoGraphics cairoGraphics(CAIRO_FORMAT_ARGB32, width, height); - cr = cairoGraphics.GetInternalContext(); - cairo_save(cr); + 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_set_operator(cr, CAIRO_OPERATOR_OVER); - cairo_save(cr); - - cairo_set_source_rgba(cr, connector_bg.red, connector_bg.green, connector_bg.blue, 0.8); - cairoGraphics.DrawRoundedRectangle(cr, aspect, 0.0f, 0.0f, radius, width, height); - cairo_fill_preserve(cr); + 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); - connector_texture_.Adopt(texture_from_cairo_graphics(cairoGraphics)); + connector_texture_ = texture_ptr_from_cairo_graphics(cairoGraphics); QueueDraw(); } diff --git a/unity-shared/PlacesOverlayVScrollBar.h b/unity-shared/PlacesOverlayVScrollBar.h index b9697ef47..43a91d3ef 100644 --- a/unity-shared/PlacesOverlayVScrollBar.h +++ b/unity-shared/PlacesOverlayVScrollBar.h @@ -80,7 +80,7 @@ private: void UpdateConnectorPosition(); void ResetConnector(); - + void UpdateStepY(); void SetupAnimation(int start, int stop, int milliseconds); @@ -93,7 +93,9 @@ private: void UpdateConnectorTexture(); nux::ObjectPtr<VScrollBarOverlayWindow> overlay_window_; - nux::InputAreaProximity area_prox_; + + class ProximityArea; + std::shared_ptr<ProximityArea> area_prox_; nux::animation::AnimateValue<int> animation_; connection::Wrapper tweening_connection_; diff --git a/unity-shared/PlacesVScrollBar.cpp b/unity-shared/PlacesVScrollBar.cpp index 0058fb465..25eba0dfc 100644 --- a/unity-shared/PlacesVScrollBar.cpp +++ b/unity-shared/PlacesVScrollBar.cpp @@ -1,6 +1,6 @@ // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- /* - * Copyright (C) 2011 Canonical Ltd + * Copyright (C) 2011-2014 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,44 +15,53 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. * * Authored by: Mirco Müller <mirco.mueller@canonical.com> + * Marco Trevisan <marco.trevisan@canonical.com> */ #include <Nux/Nux.h> +#include <NuxGraphics/CairoGraphics.h> #include "unity-shared/CairoTexture.h" +#include "unity-shared/RawPixel.h" #include "PlacesVScrollBar.h" -using unity::texture_from_cairo_graphics; - namespace unity { namespace dash { +namespace +{ +const RawPixel BUTTONS_HEIGHT = 15_em; +const RawPixel WIDTH = 3_em; +} PlacesVScrollBar::PlacesVScrollBar(NUX_FILE_LINE_DECL) - : VScrollBar(NUX_FILE_LINE_PARAM), - _slider_texture(NULL) + : nux::VScrollBar(NUX_FILE_LINE_PARAM) + , scale(1.0) { - _scroll_up_button->SetMaximumHeight(15); - _scroll_up_button->SetMinimumHeight(15); - - _scroll_down_button->SetMaximumHeight(15); - _scroll_down_button->SetMinimumHeight(15); - - _slider->SetMinimumWidth(3); - _slider->SetMaximumWidth(3); - SetMinimumWidth(3); - SetMaximumWidth(3); + UpdateSize(); + scale.changed.connect([this] (double scale) { + UpdateSize(); + QueueRelayout(); + QueueDraw(); + }); } -PlacesVScrollBar::~PlacesVScrollBar() +void PlacesVScrollBar::UpdateSize() { - if (_slider_texture) - _slider_texture->UnReference(); + _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)); + + _slider->SetMinimumWidth(WIDTH.CP(scale)); + _slider->SetMaximumWidth(WIDTH.CP(scale)); + SetMinimumWidth(WIDTH.CP(scale)); + SetMaximumWidth(WIDTH.CP(scale)); } -void -PlacesVScrollBar::PreLayoutManagement() +void PlacesVScrollBar::PreLayoutManagement() { nux::VScrollBar::PreLayoutManagement(); } @@ -69,8 +78,8 @@ PlacesVScrollBar::PostLayoutManagement(long LayoutResult) void PlacesVScrollBar::Draw(nux::GraphicsEngine& graphics_engine, bool force_draw) { - if(!RedirectedAncestor()) - { + if (!RedirectedAncestor()) + { DrawScrollbar(graphics_engine); } } @@ -78,15 +87,19 @@ PlacesVScrollBar::Draw(nux::GraphicsEngine& graphics_engine, bool force_draw) void PlacesVScrollBar::DrawContent(nux::GraphicsEngine& graphics_engine, bool force_draw) { - if(RedirectedAncestor()) - { - DrawScrollbar(graphics_engine); + 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; @@ -95,9 +108,6 @@ PlacesVScrollBar::DrawScrollbar(nux::GraphicsEngine& graphics_engine) unsigned int alpha = 0, src = 0, dest = 0; graphics_engine.GetRenderStates().GetBlend(alpha, src, dest); - // check if textures have been computed... if they haven't, exit function - if (!_slider_texture) - return; texxform.SetTexCoordType(nux::TexCoordXForm::OFFSET_SCALE_COORD); @@ -112,7 +122,7 @@ PlacesVScrollBar::DrawScrollbar(nux::GraphicsEngine& graphics_engine) slider_geo.y, slider_geo.width, slider_geo.height, - _slider_texture->GetDeviceTexture(), + slider_texture_->GetDeviceTexture(), texxform, color); } @@ -123,35 +133,26 @@ PlacesVScrollBar::DrawScrollbar(nux::GraphicsEngine& graphics_engine) void PlacesVScrollBar::UpdateTexture() { - nux::CairoGraphics* cairoGraphics = NULL; - cairo_t* cr = NULL; - // update texture of slider int width = _slider->GetBaseWidth(); int height = _slider->GetBaseHeight(); - cairoGraphics = new nux::CairoGraphics(CAIRO_FORMAT_ARGB32, width, height); - cr = cairoGraphics->GetContext(); + + if (slider_texture_ && slider_texture_->GetWidth() == width && slider_texture_->GetHeight() == height) + return; + + nux::CairoGraphics cg(CAIRO_FORMAT_ARGB32, width, height); + auto* cr = cg.GetContext(); + cairo_surface_set_device_scale(cairo_get_target(cr), scale, scale); cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR); cairo_paint(cr); cairo_set_operator(cr, CAIRO_OPERATOR_OVER); cairo_set_source_rgba(cr, 1.0f, 1.0f, 1.0f, 1.0f); - cairoGraphics->DrawRoundedRectangle(cr, - 1.0f, - 0.0, - 0.0, - 1.5, - 3.0, - (double) height - 3.0); + cg.DrawRoundedRectangle(cr, 1.0f, 0.0, 0.0, 1.5, 3.0, static_cast<double>(height)/scale() - 3.0); cairo_fill(cr); - if (_slider_texture) - _slider_texture->UnReference(); - _slider_texture = texture_from_cairo_graphics(*cairoGraphics); - - cairo_destroy(cr); - delete cairoGraphics; + slider_texture_ = texture_ptr_from_cairo_graphics(cg); } } // namespace dash diff --git a/unity-shared/PlacesVScrollBar.h b/unity-shared/PlacesVScrollBar.h index c6bc201cb..2a7fc16b2 100644 --- a/unity-shared/PlacesVScrollBar.h +++ b/unity-shared/PlacesVScrollBar.h @@ -20,12 +20,7 @@ #ifndef PLACES_VSCROLLBAR_H #define PLACES_VSCROLLBAR_H -#include <Nux/Nux.h> -#include <Nux/View.h> -#include <Nux/ScrollView.h> -#include <Nux/BaseWindow.h> #include <Nux/VScrollBar.h> -#include <NuxGraphics/CairoGraphics.h> namespace unity { @@ -36,23 +31,23 @@ class PlacesVScrollBar : public nux::VScrollBar { public: PlacesVScrollBar(NUX_FILE_LINE_PROTO); - virtual ~PlacesVScrollBar(); + + nux::Property<double> scale; protected: virtual void PreLayoutManagement(); virtual long PostLayoutManagement(long LayoutResult); - void Draw(nux::GraphicsEngine& gfxContext, - bool forceDraw); - void DrawContent(nux::GraphicsEngine& gfxContext, - bool forceDraw); + 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); private: - nux::BaseTexture* _slider_texture; + nux::ObjectPtr<nux::BaseTexture> slider_texture_; }; } // namespace dash diff --git a/unity-shared/VScrollBarOverlayWindow.cpp b/unity-shared/VScrollBarOverlayWindow.cpp index 6f2587de5..f2dd21af9 100644 --- a/unity-shared/VScrollBarOverlayWindow.cpp +++ b/unity-shared/VScrollBarOverlayWindow.cpp @@ -31,15 +31,15 @@ namespace unity namespace { - int const THUMB_WIDTH = 21; - int const THUMB_HEIGHT = 68; - int const THUMB_RADIUS = 3; - int const ANIMATION_DURATION = 90; + 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) @@ -47,7 +47,7 @@ VScrollBarOverlayWindow::VScrollBarOverlayWindow(nux::Geometry const& geo) , current_action_(ThumbAction::NONE) , show_animator_(ANIMATION_DURATION) { - Area::SetGeometry(content_size_.x, content_size_.y, THUMB_WIDTH, content_size_.height); + Area::SetGeometry(content_size_.x, content_size_.y, THUMB_WIDTH.CP(scale), content_size_.height); SetBackgroundColor(nux::color::Transparent); show_animator_.updated.connect(sigc::mem_fun(this, &BaseWindow::SetOpacity)); @@ -58,6 +58,17 @@ VScrollBarOverlayWindow::VScrollBarOverlayWindow(nux::Geometry const& geo) 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) @@ -67,9 +78,7 @@ void VScrollBarOverlayWindow::UpdateGeometry(nux::Geometry const& geo) content_size_.height != geo.height) { content_size_ = geo; - UpdateMouseOffsetX(); - - Area::SetGeometry(content_size_.x + content_offset_x_, content_size_.y, THUMB_WIDTH, content_size_.height); + UpdateContentGeometry(); } } @@ -91,8 +100,8 @@ int VScrollBarOverlayWindow::GetValidOffsetYValue(int new_offset) const { if (new_offset < 0) return 0; - else if (new_offset > content_size_.height - THUMB_HEIGHT) - return content_size_.height - THUMB_HEIGHT; + else if (new_offset > content_size_.height - THUMB_HEIGHT.CP(scale)) + return content_size_.height - THUMB_HEIGHT.CP(scale); return new_offset; } @@ -102,15 +111,15 @@ void VScrollBarOverlayWindow::UpdateMouseOffsetX() int monitor = unity::UScreen::GetDefault()->GetMonitorWithMouse(); nux::Geometry const& geo = unity::UScreen::GetDefault()->GetMonitorGeometry(monitor); - if (content_size_.x + THUMB_WIDTH > geo.x + geo.width) - content_offset_x_ = geo.x + geo.width - (content_size_.x + THUMB_WIDTH); + 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, THUMB_HEIGHT); + nux::Geometry const thumb(0, mouse_offset_y_, THUMB_WIDTH.CP(scale), THUMB_HEIGHT.CP(scale)); return thumb.IsPointInside(0,y); } @@ -121,7 +130,7 @@ bool VScrollBarOverlayWindow::IsMouseBeingDragged() const int VScrollBarOverlayWindow::GetThumbHeight() const { - return THUMB_HEIGHT; + return THUMB_HEIGHT.CP(scale); } int VScrollBarOverlayWindow::GetThumbOffsetY() const @@ -133,7 +142,7 @@ nux::Geometry VScrollBarOverlayWindow::GetThumbGeometry() const { return nux::Geometry(content_size_.x + content_offset_x_, content_size_.y + mouse_offset_y_, - THUMB_WIDTH, THUMB_HEIGHT); + THUMB_WIDTH.CP(scale), THUMB_HEIGHT.CP(scale)); } void VScrollBarOverlayWindow::MouseDown() @@ -267,7 +276,7 @@ void VScrollBarOverlayWindow::Draw(nux::GraphicsEngine& graphics_engine, bool fo if (!thumb_texture_) return; - nux::Geometry base(0, mouse_offset_y_, THUMB_WIDTH, THUMB_HEIGHT); + nux::Geometry base(0, mouse_offset_y_, THUMB_WIDTH.CP(scale), THUMB_HEIGHT.CP(scale)); nux::TexCoordXForm texxform; graphics_engine.QRP_1Tex(base.x, @@ -372,7 +381,7 @@ void DrawLineSeperator(cairo_t* cr, nux::color::RedGreenBlue const& top, } -void DrawArrow (cairo_t* cr, nux::color::RedGreenBlue const& rgb, double x, double y, double width, double height) +void DrawArrow(cairo_t* cr, nux::color::RedGreenBlue const& rgb, double x, double y, double width, double height) { cairo_save (cr); @@ -417,37 +426,30 @@ void VScrollBarOverlayWindow::UpdateTexture() { int width = THUMB_WIDTH; int height = THUMB_HEIGHT; - int radius = THUMB_RADIUS; float const aspect = 1.0f; float current_x = 0.0f; float current_y = 0.0f; - cairo_t* cr = NULL; - cairo_pattern_t* pat = NULL; + 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; - nux::color::RedGreenBlue const& bg = nux::color::WhiteSmoke; - nux::color::RedGreenBlue const& bg_selected = nux::color::White; - nux::color::RedGreenBlue const& bg_active = nux::color::Gray; - nux::color::RedGreenBlue 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); - nux::color::RedGreenBlue const& bg_arrow_up = ProduceColorShade(bg, 0.86); - nux::color::RedGreenBlue const& bg_arrow_down = ProduceColorShade(bg, 1.1); - nux::color::RedGreenBlue 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::color::RedGreenBlue const& bg_dark_line = ProduceColorShade(bg, 0.4); - nux::color::RedGreenBlue const& bg_bright_line = ProduceColorShade(bg, 1.2); - - nux::CairoGraphics cairoGraphics(CAIRO_FORMAT_ARGB32, width, height); - cr = cairoGraphics.GetInternalContext(); - - cairo_save(cr); + 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_save(cr); - cairo_translate (cr, 0.5, 0.5); width--; height--; @@ -455,15 +457,14 @@ void VScrollBarOverlayWindow::UpdateTexture() cairo_set_line_width (cr, 1.0); cairo_set_operator(cr, CAIRO_OPERATOR_OVER); - cairo_save(cr); // Draw backgound SetSourceRGB(cr, bg, 1.0); - cairoGraphics.DrawRoundedRectangle(cr, aspect, current_x, current_y, radius, width, height); + cairoGraphics.DrawRoundedRectangle(cr, aspect, current_x, current_y, THUMB_RADIUS, width, height); cairo_fill_preserve(cr); // Draw shaded background - pat = cairo_pattern_create_linear(0, 0, 0, height); + 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); @@ -502,7 +503,7 @@ void VScrollBarOverlayWindow::UpdateTexture() current_x += 0.5; current_y += 0.5; - cairoGraphics.DrawRoundedRectangle(cr, aspect, current_x, current_y, radius - 1, width - 1, height - 1); + 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); @@ -545,12 +546,12 @@ void VScrollBarOverlayWindow::UpdateTexture() current_x += 0.5; current_y += 0.5; - cairoGraphics.DrawRoundedRectangle(cr, aspect, current_x, current_y, radius, width- 2, height - 2); + 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, radius - 1, width - 4, height- 4); + 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); @@ -558,7 +559,7 @@ void VScrollBarOverlayWindow::UpdateTexture() DrawLineSeperator(cr, bg_dark_line, bg_bright_line, width, height); DrawBothArrows(cr, arrow_color, width, height); - thumb_texture_.Adopt(unity::texture_from_cairo_graphics(cairoGraphics)); + thumb_texture_ = texture_ptr_from_cairo_graphics(cairoGraphics); QueueDraw(); } diff --git a/unity-shared/VScrollBarOverlayWindow.h b/unity-shared/VScrollBarOverlayWindow.h index ce78e8c14..5c8ad75f0 100644 --- a/unity-shared/VScrollBarOverlayWindow.h +++ b/unity-shared/VScrollBarOverlayWindow.h @@ -32,7 +32,8 @@ class VScrollBarOverlayWindow : public nux::BaseWindow { public: VScrollBarOverlayWindow(nux::Geometry const& geo); - virtual ~VScrollBarOverlayWindow() {} + + nux::Property<double> scale; void UpdateGeometry(nux::Geometry const& geo); void SetThumbOffsetY(int y); @@ -85,6 +86,7 @@ private: void MouseDragging(); void UpdateMouseOffsetX(); + void UpdateContentGeometry(); int GetValidOffsetYValue(int y) const; void ShouldShow(); |
