Merge lp:~3v1n0/unity/overlay-scrollbars-gtk-like into lp:unity
- overlay-scrollbars-gtk-like
- Merge into trunk
Proposed by
Marco Trevisan (Treviño)
Status: | Merged |
---|---|
Approved by: | Andrea Azzarone |
Approved revision: | no longer in the source branch. |
Merged at revision: | 4045 |
Proposed branch: | lp:~3v1n0/unity/overlay-scrollbars-gtk-like |
Merge into: | lp:unity |
Diff against target: |
2354 lines (+202/-1737) 17 files modified
dash/PlacesGroup.cpp (+17/-18) dash/ScopeView.cpp (+8/-19) dash/ScopeView.h (+0/-2) dash/StandaloneDash.cpp (+13/-6) dash/pch/dash_pch.hh (+7/-0) tests/CMakeLists.txt (+0/-1) tests/test_overlay_scrollbar.cpp (+0/-478) unity-shared/CMakeLists.txt (+0/-1) unity-shared/CoverArt.cpp (+1/-0) unity-shared/OverlayScrollView.cpp (+2/-1) unity-shared/OverlayWindowButtons.cpp (+6/-0) unity-shared/PlacesOverlayVScrollBar.cpp (+98/-411) unity-shared/PlacesOverlayVScrollBar.h (+5/-55) unity-shared/PlacesVScrollBar.cpp (+43/-58) unity-shared/PlacesVScrollBar.h (+2/-5) unity-shared/VScrollBarOverlayWindow.cpp (+0/-568) unity-shared/VScrollBarOverlayWindow.h (+0/-114) |
To merge this branch: | bzr merge lp:~3v1n0/unity/overlay-scrollbars-gtk-like |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
PS Jenkins bot (community) | continuous-integration | Approve | |
Andrea Azzarone (community) | Approve | ||
Review via email: mp+276906@code.launchpad.net |
Commit message
Places(
Description of the change
To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote : | # |
review:
Needs Fixing
(continuous-integration)
Revision history for this message
Andrea Azzarone (azzar1) wrote : | # |
Overall looks good. Just few redrawing issues:
* with a different scale, scrolling inside the scope view makes the dash flicker in the right border.
* some redrawing issues with the filter view.
I suggested some possible fix on IRC.
review:
Needs Fixing
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:4020
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
review:
Approve
(continuous-integration)
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'dash/PlacesGroup.cpp' |
2 | --- dash/PlacesGroup.cpp 2015-08-25 08:15:50 +0000 |
3 | +++ dash/PlacesGroup.cpp 2015-12-09 12:47:13 +0000 |
4 | @@ -49,14 +49,13 @@ |
5 | { |
6 | namespace |
7 | { |
8 | - |
9 | -const nux::Color kExpandDefaultTextColor(1.0f, 1.0f, 1.0f, 0.5f); |
10 | -const float kExpandDefaultIconOpacity = 0.5f; |
11 | +const nux::Color EXPAND_DEFAULT_TEXT_COLOR(1.0f, 1.0f, 1.0f, 0.5f); |
12 | +const float EXPAND_DEFAULT_ICON_OPACITY = 0.5f; |
13 | |
14 | // Category highlight |
15 | -const RawPixel kHighlightRightPadding = 7_em; // FIXME 10 - 3 because the scrollbar is not a real overlay scrollbar! |
16 | -const RawPixel kHighlightHeight = 24_em; |
17 | -const RawPixel kHighlightLeftPadding = 10_em; |
18 | +const RawPixel HIGHLIGHT_RIGHT_PADDING = 10_em; |
19 | +const RawPixel HIGHLIGHT_HEIGHT = 24_em; |
20 | +const RawPixel HIGHLIGHT_LEFT_PADDING = 10_em; |
21 | const RawPixel SPACE_BETWEEN_CHILDREN = 10_em; |
22 | const RawPixel TEXT_INTERNAL_MARGIN = 15_em; |
23 | const RawPixel EXPAND_INTERNAL_MARGIN = 8_em; |
24 | @@ -65,7 +64,6 @@ |
25 | // Font |
26 | const char* const NAME_LABEL_FONT = "Ubuntu 13"; // 17px = 13 |
27 | const char* const EXPANDER_LABEL_FONT = "Ubuntu 10"; // 13px = 10 |
28 | - |
29 | } |
30 | |
31 | class HeaderView : public nux::View |
32 | @@ -184,12 +182,12 @@ |
33 | _expand_label->SetLines(-1); |
34 | _expand_label->SetTextEllipsize(StaticCairoText::NUX_ELLIPSIZE_END); |
35 | _expand_label->SetTextAlignment(StaticCairoText::NUX_ALIGN_LEFT); |
36 | - _expand_label->SetTextColor(kExpandDefaultTextColor); |
37 | + _expand_label->SetTextColor(EXPAND_DEFAULT_TEXT_COLOR); |
38 | _expand_label_layout->AddView(_expand_label, 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FIX); |
39 | |
40 | _expand_icon = new IconTexture(_style.GetGroupExpandIcon()); |
41 | _expand_icon->SetDrawMode(IconTexture::DrawMode::STRETCH_WITH_ASPECT); |
42 | - _expand_icon->SetOpacity(kExpandDefaultIconOpacity); |
43 | + _expand_icon->SetOpacity(EXPAND_DEFAULT_ICON_OPACITY); |
44 | _expand_icon->SetVisible(false); |
45 | _expand_layout->AddView(_expand_icon, 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_MATCHCONTENT); |
46 | |
47 | @@ -466,9 +464,9 @@ |
48 | if (_cached_geometry.GetWidth() != geo.GetWidth()) |
49 | { |
50 | _focus_layer.reset(_style.FocusOverlay(geo.width - |
51 | - kHighlightLeftPadding.CP(scale()) - |
52 | - kHighlightRightPadding.CP(scale()), |
53 | - kHighlightHeight.CP(scale()))); |
54 | + HIGHLIGHT_LEFT_PADDING.CP(scale()) - |
55 | + HIGHLIGHT_RIGHT_PADDING.CP(scale()), |
56 | + HIGHLIGHT_HEIGHT.CP(scale()))); |
57 | _cached_geometry = geo; |
58 | } |
59 | return ret; |
60 | @@ -487,10 +485,10 @@ |
61 | { |
62 | nux::Geometry geo(_header_layout->GetGeometry()); |
63 | geo.width = base.width - |
64 | - kHighlightRightPadding.CP(scale()) - |
65 | - kHighlightLeftPadding.CP(scale()); |
66 | + HIGHLIGHT_RIGHT_PADDING.CP(scale()) - |
67 | + HIGHLIGHT_LEFT_PADDING.CP(scale()); |
68 | |
69 | - geo.x += kHighlightLeftPadding.CP(scale()); |
70 | + geo.x += HIGHLIGHT_LEFT_PADDING.CP(scale()); |
71 | |
72 | _focus_layer->SetGeometry(geo); |
73 | _focus_layer->Renderlayer(graphics_engine); |
74 | @@ -500,9 +498,10 @@ |
75 | { |
76 | nux::Geometry bg_geo = base; |
77 | int bg_width = _background_layer->GetDeviceTexture()->GetWidth(); |
78 | - bg_geo.x = std::max(bg_geo.width - bg_width,0); |
79 | - |
80 | - bg_geo.width = std::min(bg_width, bg_geo.GetWidth()) + 1; // to render into a space left over by the scrollview |
81 | + bg_geo.x = std::max(bg_geo.width - bg_width, 0); |
82 | + |
83 | + // to render into a space left over by the scrollview (1 has NOT to be scaled) |
84 | + bg_geo.width = std::min(bg_width, bg_geo.GetWidth()) + 1; |
85 | bg_geo.height = _background->GetHeight(); |
86 | |
87 | _background_layer->SetGeometry(bg_geo); |
88 | |
89 | === modified file 'dash/ScopeView.cpp' |
90 | --- dash/ScopeView.cpp 2015-05-22 13:21:01 +0000 |
91 | +++ dash/ScopeView.cpp 2015-12-09 12:47:13 +0000 |
92 | @@ -105,24 +105,16 @@ |
93 | up_area_ = area; |
94 | } |
95 | |
96 | - void DrawContent(nux::GraphicsEngine& graphics_engine, bool force_draw) |
97 | - { |
98 | - if (RedirectedAncestor()) |
99 | - { |
100 | - if (m_horizontal_scrollbar_enable && _hscrollbar->IsRedrawNeeded()) |
101 | - graphics::ClearGeometry(_hscrollbar->GetGeometry()); |
102 | - if (m_vertical_scrollbar_enable && _vscrollbar->IsRedrawNeeded()) |
103 | - graphics::ClearGeometry(_vscrollbar->GetGeometry()); |
104 | - } |
105 | - |
106 | - ScrollView::DrawContent(graphics_engine, force_draw); |
107 | - } |
108 | - |
109 | void EnableScrolling(bool enable_scrolling) |
110 | { |
111 | _vscrollbar->SetInputEventSensitivity(enable_scrolling); |
112 | } |
113 | |
114 | + nux::VScrollBar* GetScrollbar() const |
115 | + { |
116 | + return _vscrollbar; |
117 | + } |
118 | + |
119 | protected: |
120 | |
121 | // This is so we can break the natural key navigation path. |
122 | @@ -161,7 +153,7 @@ |
123 | { |
124 | SetupViews(show_filters); |
125 | |
126 | - search_string.SetGetterFunction(sigc::mem_fun(this, &ScopeView::get_search_string)); |
127 | + search_string.SetGetterFunction([this] { return search_string_; }); |
128 | filters_expanded.changed.connect(sigc::mem_fun(this, &ScopeView::OnScopeFilterExpanded)); |
129 | view_type.changed.connect(sigc::mem_fun(this, &ScopeView::OnViewTypeChanged)); |
130 | scale.changed.connect(sigc::mem_fun(this, &ScopeView::UpdateScale)); |
131 | @@ -243,6 +235,7 @@ |
132 | scroll_layout_ = new nux::VLayout(NUX_TRACKER_LOCATION); |
133 | scroll_view_->SetLayout(scroll_layout_); |
134 | scroll_view_->SetRightArea(show_filters); |
135 | + scroll_view_->GetScrollbar()->queue_draw.connect(sigc::hide(sigc::mem_fun(scroll_layout_, &nux::VLayout::QueueDraw))); |
136 | |
137 | no_results_ = new StaticCairoText("", NUX_TRACKER_LOCATION); |
138 | no_results_->SetTextColor(nux::color::White); |
139 | @@ -260,6 +253,7 @@ |
140 | |
141 | fscroll_layout_ = new nux::VLayout(); |
142 | fscroll_view_->SetLayout(fscroll_layout_); |
143 | + fscroll_view_->GetScrollbar()->queue_draw.connect(sigc::hide(sigc::mem_fun(fscroll_layout_, &nux::VLayout::QueueDraw))); |
144 | |
145 | filter_bar_ = new FilterBar(); |
146 | |
147 | @@ -876,11 +870,6 @@ |
148 | return false; |
149 | } |
150 | |
151 | -std::string ScopeView::get_search_string() const |
152 | -{ |
153 | - return search_string_; |
154 | -} |
155 | - |
156 | void ScopeView::OnGroupExpanded(PlacesGroup* group) |
157 | { |
158 | ResultViewGrid* grid = static_cast<ResultViewGrid*>(group->GetChildView()); |
159 | |
160 | === modified file 'dash/ScopeView.h' |
161 | --- dash/ScopeView.h 2015-05-04 20:55:56 +0000 |
162 | +++ dash/ScopeView.h 2015-12-09 12:47:13 +0000 |
163 | @@ -143,8 +143,6 @@ |
164 | |
165 | void OnCompositorKeyNavFocusChanged(nux::Area*, bool, nux::KeyNavDirection); |
166 | |
167 | - std::string get_search_string() const; |
168 | - |
169 | CategoryGroups category_views_; |
170 | |
171 | Scope::Ptr scope_; |
172 | |
173 | === modified file 'dash/StandaloneDash.cpp' |
174 | --- dash/StandaloneDash.cpp 2014-07-09 10:31:21 +0000 |
175 | +++ dash/StandaloneDash.cpp 2015-12-09 12:47:13 +0000 |
176 | @@ -37,7 +37,7 @@ |
177 | #include "unity-shared/PanelStyle.h" |
178 | #include "unity-shared/ThumbnailGenerator.h" |
179 | #include "unity-shared/UBusMessages.h" |
180 | -#include "unity-shared/UBusServer.h" |
181 | +#include "unity-shared/UBusWrapper.h" |
182 | #include <UnityCore/GSettingsScopes.h> |
183 | #include <UnityCore/ScopeProxyInterface.h> |
184 | |
185 | @@ -50,12 +50,13 @@ |
186 | { |
187 | public: |
188 | TestRunner(std::string const& scope, double scale) |
189 | - : scope_(scope) |
190 | + : scope_(scope.empty() ? "home.scope" : scope) |
191 | , scale_(scale) |
192 | {} |
193 | |
194 | - static void InitWindowThread (nux::NThread* thread, void* InitData); |
195 | - void Init (); |
196 | + static void InitWindowThread(nux::NThread* thread, void* InitData); |
197 | + void Init(); |
198 | + |
199 | std::string scope_; |
200 | double scale_; |
201 | nux::Layout *layout; |
202 | @@ -78,14 +79,14 @@ |
203 | nux::GetWindowThread()->SetLayout (layout); |
204 | nux::GetWindowCompositor().SetKeyFocusArea(view->default_focus()); |
205 | |
206 | - unity::UBusServer().SendMessage(UBUS_PLACE_ENTRY_ACTIVATE_REQUEST, |
207 | + unity::UBusManager::SendMessage(UBUS_PLACE_ENTRY_ACTIVATE_REQUEST, |
208 | g_variant_new("(sus)", scope_.c_str(), GOTO_DASH_URI, "")); |
209 | } |
210 | |
211 | void TestRunner::InitWindowThread(nux::NThread* thread, void* InitData) |
212 | { |
213 | TestRunner *self = (TestRunner *) InitData; |
214 | - self->Init (); |
215 | + self->Init(); |
216 | } |
217 | |
218 | int main(int argc, char **argv) |
219 | @@ -124,6 +125,12 @@ |
220 | WIDTH.CP(scale), HEIGHT.CP(scale), |
221 | 0, &TestRunner::InitWindowThread, test_runner)); |
222 | |
223 | + nux::ObjectPtr<nux::BaseTexture> background_tex; |
224 | + background_tex.Adopt(nux::CreateTextureFromFile("/usr/share/backgrounds/warty-final-ubuntu.png")); |
225 | + nux::TexCoordXForm texxform; |
226 | + auto tex_layer = std::make_shared<nux::TextureLayer>(background_tex->GetDeviceTexture(), texxform, nux::color::White); |
227 | + wt->SetWindowBackgroundPaintLayer(tex_layer.get()); |
228 | + |
229 | nux::NuxTimerTickSource tick_source; |
230 | nux::animation::AnimationController animation_controller(tick_source); |
231 | wt->Run(nullptr); |
232 | |
233 | === modified file 'dash/pch/dash_pch.hh' |
234 | --- dash/pch/dash_pch.hh 2012-12-18 13:31:10 +0000 |
235 | +++ dash/pch/dash_pch.hh 2015-12-09 12:47:13 +0000 |
236 | @@ -27,3 +27,10 @@ |
237 | #include <memory> |
238 | |
239 | #include <Nux/Nux.h> |
240 | + |
241 | +#include <UnityCore/ModelRowAdaptor.h> |
242 | +#include <UnityCore/Model.h> |
243 | +#include <UnityCore/Category.h> |
244 | +#include <UnityCore/Categories.h> |
245 | +#include <UnityCore/Result.h> |
246 | +#include <UnityCore/Results.h> |
247 | |
248 | === modified file 'tests/CMakeLists.txt' |
249 | --- tests/CMakeLists.txt 2015-10-16 08:46:03 +0000 |
250 | +++ tests/CMakeLists.txt 2015-12-09 12:47:13 +0000 |
251 | @@ -261,7 +261,6 @@ |
252 | test_previews_music_payment.cpp |
253 | test_previews_payment.cpp |
254 | test_previews_social.cpp |
255 | - test_overlay_scrollbar.cpp |
256 | test_quicklist_manager.cpp |
257 | test_quicklist_menu_item.cpp |
258 | test_quicklist_view.cpp |
259 | |
260 | === removed file 'tests/test_overlay_scrollbar.cpp' |
261 | --- tests/test_overlay_scrollbar.cpp 2013-11-06 11:21:43 +0000 |
262 | +++ tests/test_overlay_scrollbar.cpp 1970-01-01 00:00:00 +0000 |
263 | @@ -1,478 +0,0 @@ |
264 | -/* |
265 | - * Copyright 2012 Canonical Ltd. |
266 | - * |
267 | - * This program is free software: you can redistribute it and/or modify it |
268 | - * under the terms of the GNU Lesser General Public License version 3, as |
269 | - * published by the Free Software Foundation. |
270 | - * |
271 | - * This program is distributed in the hope that it will be useful, but |
272 | - * WITHOUT ANY WARRANTY; without even the implied warranties of |
273 | - * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR |
274 | - * PURPOSE. See the applicable version of the GNU Lesser General Public |
275 | - * License for more details. |
276 | - * |
277 | - * You should have received a copy of both the GNU Lesser General Public |
278 | - * License version 3 along with this program. If not, see |
279 | - * <http://www.gnu.org/licenses/> |
280 | - * |
281 | - * Authored by: Brandon Schaefer <brandon.schaefer@canonical.com> |
282 | - * |
283 | - */ |
284 | - |
285 | -#include <gtest/gtest.h> |
286 | - |
287 | -#include <Nux/Nux.h> |
288 | -#include <Nux/NuxTimerTickSource.h> |
289 | -#include <Nux/VLayout.h> |
290 | -#include <NuxCore/ObjectPtr.h> |
291 | -#include <NuxCore/AnimationController.h> |
292 | - |
293 | - |
294 | -#include "unity-shared/VScrollBarOverlayWindow.h" |
295 | -#include "unity-shared/PlacesOverlayVScrollBar.h" |
296 | -#include "unity-shared/UScreen.h" |
297 | - |
298 | -using namespace unity::dash; |
299 | -using namespace testing; |
300 | - |
301 | -namespace unity |
302 | -{ |
303 | - |
304 | -namespace |
305 | -{ |
306 | - const unsigned SCROLL_TICK = 1000 * 401; |
307 | - const unsigned SHOW_TICK = 1000 * 91; |
308 | -} |
309 | - |
310 | -class TestOverlayWindow : public Test |
311 | -{ |
312 | -public: |
313 | - TestOverlayWindow() |
314 | - : show_tick_(0) |
315 | - , animation_controller_(tick_source_) |
316 | - , overlay_window_(new VScrollBarOverlayWindow(nux::Geometry(0,0,100,100))) |
317 | - {} |
318 | - |
319 | - int GetProxListSize() const |
320 | - { |
321 | - return nux::GetWindowThread()->GetWindowCompositor().GetProximityListSize(); |
322 | - } |
323 | - |
324 | - void ShowAnimation() |
325 | - { |
326 | - // (tick_source_); |
327 | - show_tick_ += SHOW_TICK; |
328 | - tick_source_.tick(show_tick_); |
329 | - } |
330 | - |
331 | - unsigned show_tick_; |
332 | - nux::NuxTimerTickSource tick_source_; |
333 | - nux::animation::AnimationController animation_controller_; |
334 | - nux::ObjectPtr<VScrollBarOverlayWindow> overlay_window_; |
335 | -}; |
336 | - |
337 | -namespace dash |
338 | -{ |
339 | - |
340 | -class MockScrollBar : public unity::dash::PlacesOverlayVScrollBar |
341 | -{ |
342 | - public: |
343 | - MockScrollBar(NUX_FILE_LINE_DECL) |
344 | - : PlacesOverlayVScrollBar(NUX_FILE_LINE_PARAM) |
345 | - , animation_controller(tick_source_) |
346 | - , scroll_tick_(0) |
347 | - , scroll_dy_(0) |
348 | - , thumbs_height_(overlay_window_->GetThumbGeometry().height) |
349 | - , scroll_up_signal_(false) |
350 | - , scroll_down_signal_(false) |
351 | - { |
352 | - OnScrollUp.connect([&] (float step, int dy) { |
353 | - scroll_dy_ = dy; |
354 | - scroll_up_signal_ = true; |
355 | - }); |
356 | - |
357 | - OnScrollDown.connect([&] (float step, int dy) { |
358 | - scroll_dy_ = dy; |
359 | - scroll_down_signal_ = true; |
360 | - }); |
361 | - } |
362 | - |
363 | - virtual ~MockScrollBar() {} |
364 | - |
365 | - // ScrollDown/Up moves the mouse over the overlay scroll bar, then |
366 | - // moves it down/up by scroll_dy |
367 | - void ScrollDown(int scroll_dy) |
368 | - { |
369 | - UpdateStepY(); |
370 | - |
371 | - auto geo = overlay_window_->GetThumbGeometry(); |
372 | - int x = geo.x; |
373 | - int y = geo.y; |
374 | - |
375 | - MoveMouse(x, y); |
376 | - MoveDown(x, y); |
377 | - |
378 | - MoveMouse(x, y+scroll_dy); |
379 | - MoveUp(x, y+scroll_dy); |
380 | - } |
381 | - |
382 | - void ScrollUp(int scroll_dy) |
383 | - { |
384 | - UpdateStepY(); |
385 | - |
386 | - auto geo = overlay_window_->GetThumbGeometry(); |
387 | - int x = geo.x; |
388 | - int y = geo.y; |
389 | - |
390 | - MoveMouse(x, y); |
391 | - MoveDown(x, y); |
392 | - |
393 | - MoveMouse(x, y-scroll_dy); |
394 | - MoveUp(x, y-scroll_dy); |
395 | - } |
396 | - |
397 | - void MoveDown(int x, int y) |
398 | - { |
399 | - nux::Event event; |
400 | - event.type = nux::NUX_MOUSE_PRESSED; |
401 | - event.x = x; |
402 | - event.y = y; |
403 | - nux::GetWindowCompositor().ProcessEvent(event); |
404 | - } |
405 | - |
406 | - void MoveUp(int x, int y) |
407 | - { |
408 | - nux::Event event; |
409 | - event.type = nux::NUX_MOUSE_RELEASED; |
410 | - event.x = x; |
411 | - event.y = y; |
412 | - nux::GetWindowCompositor().ProcessEvent(event); |
413 | - } |
414 | - |
415 | - void MoveMouse(int x, int y) |
416 | - { |
417 | - nux::Event event; |
418 | - event.type = nux::NUX_MOUSE_MOVE; |
419 | - event.x = x; |
420 | - event.y = y; |
421 | - nux::GetWindowCompositor().ProcessEvent(event); |
422 | - } |
423 | - |
424 | - void MoveMouseNear() |
425 | - { |
426 | - auto geo = overlay_window_->GetThumbGeometry(); |
427 | - MoveMouse(geo.x, geo.y); |
428 | - } |
429 | - |
430 | - void ScrollUpAnimation(int scroll_dy) |
431 | - { |
432 | - MoveMouseNear(); |
433 | - UpdateStepY(); |
434 | - |
435 | - StartScrollAnimation(ScrollDir::UP, scroll_dy); |
436 | - scroll_tick_ += SCROLL_TICK; |
437 | - tick_source_.tick(scroll_tick_); |
438 | - } |
439 | - |
440 | - void ScrollDownAnimation(int scroll_dy) |
441 | - { |
442 | - MoveMouseNear(); |
443 | - UpdateStepY(); |
444 | - |
445 | - StartScrollAnimation(ScrollDir::DOWN, scroll_dy); |
446 | - scroll_tick_ += SCROLL_TICK; |
447 | - tick_source_.tick(scroll_tick_); |
448 | - } |
449 | - |
450 | - void SetThumbOffset(int y) |
451 | - { |
452 | - overlay_window_->SetThumbOffsetY(y); |
453 | - UpdateConnectorPosition(); |
454 | - } |
455 | - |
456 | - void StartScrollThenConnectorAnimation() |
457 | - { |
458 | - StartScrollAnimation(ScrollDir::DOWN, 20); |
459 | - MoveMouse(0,0); |
460 | - StartConnectorAnimation(); |
461 | - |
462 | - scroll_tick_ += SCROLL_TICK; |
463 | - tick_source_.tick(scroll_tick_); |
464 | - } |
465 | - |
466 | - void FakeDragDown() |
467 | - { |
468 | - OnMouseDrag(0, overlay_window_->GetThumbOffsetY() + 1, 0, 5, 0, 0); |
469 | - } |
470 | - |
471 | - nux::NuxTimerTickSource tick_source_; |
472 | - nux::animation::AnimationController animation_controller; |
473 | - |
474 | - using PlacesOverlayVScrollBar::connector_height_; |
475 | - using VScrollBar::_slider; |
476 | - |
477 | - unsigned scroll_tick_; |
478 | - int scroll_dy_; |
479 | - int thumbs_height_; |
480 | - bool scroll_up_signal_; |
481 | - bool scroll_down_signal_; |
482 | -}; |
483 | - |
484 | -} |
485 | - |
486 | -class MockScrollView : public nux::ScrollView |
487 | -{ |
488 | -public: |
489 | - MockScrollView(NUX_FILE_LINE_DECL) |
490 | - : nux::ScrollView(NUX_FILE_LINE_PARAM) |
491 | - { |
492 | - scroll_bar_ = new MockScrollBar(NUX_TRACKER_LOCATION); |
493 | - SetVScrollBar(scroll_bar_.GetPointer()); |
494 | - } |
495 | - |
496 | - nux::ObjectPtr<MockScrollBar> scroll_bar_; |
497 | -}; |
498 | - |
499 | -class TestOverlayVScrollBar : public Test |
500 | -{ |
501 | -public: |
502 | - TestOverlayVScrollBar() |
503 | - { |
504 | - nux::VLayout* scroll_layout_ = new nux::VLayout(NUX_TRACKER_LOCATION); |
505 | - scroll_layout_->SetGeometry(0,0,1000,5000); |
506 | - scroll_layout_->SetScaleFactor(0); |
507 | - |
508 | - scroll_view_ = new MockScrollView(NUX_TRACKER_LOCATION); |
509 | - scroll_view_->EnableVerticalScrollBar(true); |
510 | - scroll_view_->EnableHorizontalScrollBar(false); |
511 | - scroll_view_->SetLayout(scroll_layout_); |
512 | - |
513 | - scroll_view_->scroll_bar_->SetContentSize(0, 0, 201, 2000); |
514 | - scroll_view_->scroll_bar_->SetContainerSize(0, 0, 202, 400); |
515 | - } |
516 | - |
517 | - nux::ObjectPtr<MockScrollView> scroll_view_; |
518 | -}; |
519 | - |
520 | -TEST_F(TestOverlayWindow, TestOverlayShows) |
521 | -{ |
522 | - ASSERT_FALSE(overlay_window_->IsVisible()); |
523 | - overlay_window_->MouseNear(); |
524 | - EXPECT_TRUE(overlay_window_->IsVisible()); |
525 | - EXPECT_DOUBLE_EQ(0.0f, overlay_window_->GetOpacity()); |
526 | - |
527 | - ShowAnimation(); |
528 | - EXPECT_DOUBLE_EQ(1.0f, overlay_window_->GetOpacity()); |
529 | -} |
530 | - |
531 | -TEST_F(TestOverlayWindow, TestOverlayHides) |
532 | -{ |
533 | - overlay_window_->MouseNear(); |
534 | - ShowAnimation(); |
535 | - EXPECT_TRUE(overlay_window_->IsVisible()); |
536 | - |
537 | - overlay_window_->MouseBeyond(); |
538 | - ShowAnimation(); |
539 | - |
540 | - overlay_window_->MouseLeave(); |
541 | - ShowAnimation(); |
542 | - |
543 | - EXPECT_FALSE(overlay_window_->IsVisible()); |
544 | - EXPECT_DOUBLE_EQ(0.0f, overlay_window_->GetOpacity()); |
545 | -} |
546 | - |
547 | -TEST_F(TestOverlayWindow, TestOverlayStaysOpenWhenMouseDown) |
548 | -{ |
549 | - overlay_window_->MouseNear(); |
550 | - ShowAnimation(); |
551 | - |
552 | - overlay_window_->MouseDown(); |
553 | - ShowAnimation(); |
554 | - |
555 | - overlay_window_->MouseBeyond(); |
556 | - ShowAnimation(); |
557 | - |
558 | - overlay_window_->MouseLeave(); |
559 | - ShowAnimation(); |
560 | - |
561 | - EXPECT_TRUE(overlay_window_->IsVisible()); |
562 | -} |
563 | - |
564 | -TEST_F(TestOverlayWindow, TestOverlayMouseDrags) |
565 | -{ |
566 | - overlay_window_->MouseDown(); |
567 | - EXPECT_FALSE(overlay_window_->IsMouseBeingDragged()); |
568 | - |
569 | - overlay_window_->SetThumbOffsetY(10); |
570 | - EXPECT_TRUE(overlay_window_->IsMouseBeingDragged()); |
571 | -} |
572 | - |
573 | -TEST_F(TestOverlayWindow, TestOverlayStopDraggingOnMouseUp) |
574 | -{ |
575 | - overlay_window_->MouseDown(); |
576 | - EXPECT_FALSE(overlay_window_->IsMouseBeingDragged()); |
577 | - |
578 | - overlay_window_->SetThumbOffsetY(10); |
579 | - EXPECT_TRUE(overlay_window_->IsMouseBeingDragged()); |
580 | - |
581 | - overlay_window_->MouseUp(); |
582 | - EXPECT_FALSE(overlay_window_->IsMouseBeingDragged()); |
583 | -} |
584 | - |
585 | -TEST_F(TestOverlayWindow, TestOverlaySetsOffsetY) |
586 | -{ |
587 | - int const offset_y = 30; |
588 | - |
589 | - overlay_window_->SetThumbOffsetY(offset_y); |
590 | - EXPECT_EQ(overlay_window_->GetThumbOffsetY(), offset_y); |
591 | -} |
592 | - |
593 | -TEST_F(TestOverlayWindow, TestOverlaySetsOffsetYOutOfBoundsLower) |
594 | -{ |
595 | - int const offset_y = -40; |
596 | - |
597 | - overlay_window_->SetThumbOffsetY(offset_y); |
598 | - EXPECT_EQ(overlay_window_->GetThumbOffsetY(), 0); |
599 | -} |
600 | - |
601 | -TEST_F(TestOverlayWindow, TestOverlaySetsOffsetYOutOfBoundsUpper) |
602 | -{ |
603 | - int const offset_y = 1000; |
604 | - int const expected_offset = overlay_window_->GetBaseHeight() - overlay_window_->GetThumbHeight(); |
605 | - |
606 | - overlay_window_->SetThumbOffsetY(offset_y); |
607 | - EXPECT_EQ(overlay_window_->GetThumbOffsetY(), expected_offset); |
608 | -} |
609 | - |
610 | -TEST_F(TestOverlayWindow, TestOverlayMouseIsInsideThumb) |
611 | -{ |
612 | - nux::Geometry const geo(0, 50, 50, 400); |
613 | - |
614 | - overlay_window_->UpdateGeometry(geo); |
615 | - EXPECT_TRUE(overlay_window_->IsMouseInsideThumb(0)); |
616 | -} |
617 | - |
618 | -TEST_F(TestOverlayWindow, TestOverlayMouseIsInsideOnOffsetChange) |
619 | -{ |
620 | - nux::Geometry const geo(0, 50, 50, 400); |
621 | - int const offset_y = 50; |
622 | - int const thumb_height = overlay_window_->GetThumbHeight(); |
623 | - |
624 | - overlay_window_->UpdateGeometry(geo); |
625 | - overlay_window_->SetThumbOffsetY(offset_y); |
626 | - |
627 | - EXPECT_FALSE(overlay_window_->IsMouseInsideThumb(offset_y - 1)); |
628 | - EXPECT_TRUE(overlay_window_->IsMouseInsideThumb(offset_y + thumb_height/2)); |
629 | - EXPECT_FALSE(overlay_window_->IsMouseInsideThumb(offset_y + thumb_height + 1)); |
630 | -} |
631 | - |
632 | - |
633 | -TEST_F(TestOverlayVScrollBar, TestScrollDownSignal) |
634 | -{ |
635 | - scroll_view_->scroll_bar_->ScrollDown(10); |
636 | - EXPECT_TRUE(scroll_view_->scroll_bar_->scroll_down_signal_); |
637 | -} |
638 | - |
639 | -TEST_F(TestOverlayVScrollBar, TestScrollUpSignal) |
640 | -{ |
641 | - scroll_view_->scroll_bar_->ScrollDown(10); |
642 | - scroll_view_->scroll_bar_->ScrollUp(10); |
643 | - EXPECT_TRUE(scroll_view_->scroll_bar_->scroll_up_signal_); |
644 | -} |
645 | - |
646 | -TEST_F(TestOverlayVScrollBar, TestScrollDownDeltaY) |
647 | -{ |
648 | - int scroll_down = 15; |
649 | - scroll_view_->scroll_bar_->ScrollDown(scroll_down); |
650 | - EXPECT_EQ(scroll_view_->scroll_bar_->scroll_dy_, scroll_down); |
651 | -} |
652 | - |
653 | -TEST_F(TestOverlayVScrollBar, TestScrollUpDeltaY) |
654 | -{ |
655 | - int scroll_up = 7; |
656 | - scroll_view_->scroll_bar_->ScrollDown(scroll_up+1); |
657 | - scroll_view_->scroll_bar_->ScrollUp(scroll_up); |
658 | - EXPECT_EQ(scroll_view_->scroll_bar_->scroll_dy_, scroll_up); |
659 | -} |
660 | - |
661 | -TEST_F(TestOverlayVScrollBar, TestScrollDownBaseYMoves) |
662 | -{ |
663 | - int slider_y = scroll_view_->scroll_bar_->_slider->GetBaseY(); |
664 | - int scroll_down = 10; |
665 | - scroll_view_->scroll_bar_->ScrollDown(scroll_down); |
666 | - EXPECT_EQ(scroll_view_->scroll_bar_->scroll_dy_, scroll_down); |
667 | - EXPECT_GT(scroll_view_->scroll_bar_->_slider->GetBaseY(), slider_y); |
668 | -} |
669 | - |
670 | -TEST_F(TestOverlayVScrollBar, TestScrollUpBaseYMoves) |
671 | -{ |
672 | - int scroll_up = 10; |
673 | - scroll_view_->scroll_bar_->ScrollDown(scroll_up+1); |
674 | - |
675 | - int slider_y = scroll_view_->scroll_bar_->_slider->GetBaseY(); |
676 | - scroll_view_->scroll_bar_->ScrollUp(scroll_up); |
677 | - EXPECT_EQ(scroll_view_->scroll_bar_->scroll_dy_, scroll_up); |
678 | - EXPECT_LT(scroll_view_->scroll_bar_->_slider->GetBaseY(), slider_y); |
679 | -} |
680 | - |
681 | -TEST_F(TestOverlayVScrollBar, TestScrollsSlowlyDeltaY) |
682 | -{ |
683 | - int scroll_down = 10; |
684 | - for (int i = 0; i < scroll_down; i++) |
685 | - { |
686 | - scroll_view_->scroll_bar_->ScrollDown(1); |
687 | - EXPECT_EQ(scroll_view_->scroll_bar_->scroll_dy_, 1); |
688 | - } |
689 | -} |
690 | - |
691 | -TEST_F(TestOverlayVScrollBar, TestScrollUpAnimationMovesSlider) |
692 | -{ |
693 | - int scroll_up = 10; |
694 | - scroll_view_->scroll_bar_->ScrollDown(scroll_up+10); |
695 | - |
696 | - int slider_y = scroll_view_->scroll_bar_->_slider->GetBaseY(); |
697 | - scroll_view_->scroll_bar_->ScrollUpAnimation(scroll_up); |
698 | - |
699 | - EXPECT_EQ(scroll_view_->scroll_bar_->scroll_dy_, scroll_up); |
700 | - EXPECT_LT(scroll_view_->scroll_bar_->_slider->GetBaseY(), slider_y); |
701 | -} |
702 | - |
703 | -TEST_F(TestOverlayVScrollBar, TestScrollDownAnimationMovesSlider) |
704 | -{ |
705 | - int scroll_down = 10; |
706 | - int slider_y = scroll_view_->scroll_bar_->_slider->GetBaseY(); |
707 | - |
708 | - scroll_view_->scroll_bar_->ScrollDownAnimation(scroll_down); |
709 | - |
710 | - EXPECT_EQ(scroll_view_->scroll_bar_->scroll_dy_, scroll_down); |
711 | - EXPECT_GT(scroll_view_->scroll_bar_->_slider->GetBaseY(), slider_y); |
712 | -} |
713 | - |
714 | -TEST_F(TestOverlayVScrollBar, TestConnectorResetsDuringScrollAnimation) |
715 | -{ |
716 | - scroll_view_->scroll_bar_->MoveMouseNear(); |
717 | - scroll_view_->scroll_bar_->SetThumbOffset(100); |
718 | - |
719 | - int connector_height = scroll_view_->scroll_bar_->connector_height_; |
720 | - EXPECT_GT(connector_height, 0); |
721 | - |
722 | - scroll_view_->scroll_bar_->StartScrollThenConnectorAnimation(); |
723 | - |
724 | - connector_height = scroll_view_->scroll_bar_->connector_height_; |
725 | - EXPECT_EQ(connector_height, 0); |
726 | -} |
727 | - |
728 | - |
729 | -TEST_F(TestOverlayVScrollBar, TestAllowDragIfOverlayIsAtMaximum) |
730 | -{ |
731 | - // Offset that sets the thumb at the bottom of the scrollbar |
732 | - int thumb_offset = scroll_view_->scroll_bar_->GetHeight() - |
733 | - scroll_view_->scroll_bar_->thumbs_height_; |
734 | - |
735 | - scroll_view_->scroll_bar_->SetThumbOffset(thumb_offset); |
736 | - scroll_view_->scroll_bar_->FakeDragDown(); |
737 | - EXPECT_TRUE(scroll_view_->scroll_bar_->scroll_down_signal_); |
738 | -} |
739 | - |
740 | -} |
741 | - |
742 | |
743 | === modified file 'unity-shared/CMakeLists.txt' |
744 | --- unity-shared/CMakeLists.txt 2015-05-05 02:03:52 +0000 |
745 | +++ unity-shared/CMakeLists.txt 2015-12-09 12:47:13 +0000 |
746 | @@ -71,7 +71,6 @@ |
747 | UnityWindowView.cpp |
748 | UpstartWrapper.cpp |
749 | UserThumbnailProvider.cpp |
750 | - VScrollBarOverlayWindow.cpp |
751 | WindowButtons.cpp |
752 | WindowManager.cpp |
753 | ) |
754 | |
755 | === modified file 'unity-shared/CoverArt.cpp' |
756 | --- unity-shared/CoverArt.cpp 2014-07-11 03:36:45 +0000 |
757 | +++ unity-shared/CoverArt.cpp 2015-12-09 12:47:13 +0000 |
758 | @@ -450,6 +450,7 @@ |
759 | overlay_text_->SetLines(-3); |
760 | overlay_text_->SetScale(scale); |
761 | overlay_text_->SetText(_("No Image Available")); |
762 | + overlay_text_->SetInputEventSensitivity(false); |
763 | |
764 | spin_ = dash::Style::Instance().GetSearchSpinIcon(scale); |
765 | |
766 | |
767 | === modified file 'unity-shared/OverlayScrollView.cpp' |
768 | --- unity-shared/OverlayScrollView.cpp 2015-05-05 13:07:36 +0000 |
769 | +++ unity-shared/OverlayScrollView.cpp 2015-12-09 12:47:13 +0000 |
770 | @@ -1,3 +1,4 @@ |
771 | + |
772 | // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- |
773 | /* |
774 | * Copyright (C) 2014 Canonical Ltd |
775 | @@ -52,7 +53,7 @@ |
776 | }); |
777 | |
778 | page_direction.connect([scrollbar] (ScrollDir dir) { |
779 | - scrollbar->PerformPageNavigation(dir); |
780 | + scrollbar->PerformPageNavigation(dir); |
781 | }); |
782 | } |
783 | |
784 | |
785 | === modified file 'unity-shared/OverlayWindowButtons.cpp' |
786 | --- unity-shared/OverlayWindowButtons.cpp 2015-06-03 12:11:00 +0000 |
787 | +++ unity-shared/OverlayWindowButtons.cpp 2015-12-09 12:47:13 +0000 |
788 | @@ -72,6 +72,9 @@ |
789 | |
790 | void OverlayWindowButtons::Show() |
791 | { |
792 | + if (!nux::GetWindowThread()->IsEmbeddedWindow()) |
793 | + return; |
794 | + |
795 | UpdateGeometry(); |
796 | ShowWindow(true); |
797 | PushToFront(); |
798 | @@ -80,6 +83,9 @@ |
799 | |
800 | void OverlayWindowButtons::Hide() |
801 | { |
802 | + if (!nux::GetWindowThread()->IsEmbeddedWindow()) |
803 | + return; |
804 | + |
805 | ShowWindow(false); |
806 | PushToBack(); |
807 | QueueDraw(); |
808 | |
809 | === modified file 'unity-shared/PlacesOverlayVScrollBar.cpp' |
810 | --- unity-shared/PlacesOverlayVScrollBar.cpp 2015-05-04 20:55:56 +0000 |
811 | +++ unity-shared/PlacesOverlayVScrollBar.cpp 2015-12-09 12:47:13 +0000 |
812 | @@ -1,6 +1,6 @@ |
813 | // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- |
814 | /* |
815 | - * Copyright (C) 2012 Canonical Ltd |
816 | + * Copyright (C) 2012-2015 Canonical Ltd |
817 | * |
818 | * This program is free software: you can redistribute it and/or modify |
819 | * it under the terms of the GNU General Public License version 3 as |
820 | @@ -15,11 +15,12 @@ |
821 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
822 | * |
823 | * Authored by: Brandon Schaefer <brandon.schaefer@canonical.com> |
824 | + * Marco Trevisan <marco.trevisan@canonical.com> |
825 | */ |
826 | |
827 | #include <Nux/Nux.h> |
828 | |
829 | -#include "CairoTexture.h" |
830 | +#include "AnimationUtils.h" |
831 | #include "PlacesOverlayVScrollBar.h" |
832 | #include "RawPixel.h" |
833 | |
834 | @@ -29,438 +30,124 @@ |
835 | { |
836 | namespace |
837 | { |
838 | - const RawPixel PROXIMITY = 7_em; |
839 | - const int SCROLL_ANIMATION = 400; |
840 | - const int MAX_CONNECTOR_ANIMATION = 200; |
841 | - const nux::Color CONNECTOR_COLOR = nux::color::Gray; |
842 | +const RawPixel PROXIMITY = 7_em; |
843 | +const int PAGE_SCROLL_ANIMATION = 200; |
844 | +const int CLICK_SCROLL_ANIMATION = 80; |
845 | + |
846 | +const RawPixel BUTTONS_HEIGHT = 0_em; |
847 | +const RawPixel DEFAULT_WIDTH = 3_em; |
848 | +const RawPixel ACTIVE_WIDTH = 8_em; |
849 | } |
850 | |
851 | -class PlacesOverlayVScrollBar::ProximityArea : public nux::InputAreaProximity, public sigc::trackable |
852 | +struct PlacesOverlayVScrollBar::ProximityArea : public nux::InputAreaProximity, public sigc::trackable |
853 | { |
854 | -public: |
855 | ProximityArea(nux::InputArea* area, unsigned prox) |
856 | : nux::InputAreaProximity(area, prox) |
857 | , proximity([this] { return proximity_; }, [this] (unsigned px) { proximity_ = px; return false; }) |
858 | {} |
859 | |
860 | nux::RWProperty<unsigned> proximity; |
861 | + |
862 | + bool IsMouseNear() const { return is_mouse_near_; } |
863 | }; |
864 | |
865 | PlacesOverlayVScrollBar::PlacesOverlayVScrollBar(NUX_FILE_LINE_DECL) |
866 | : PlacesVScrollBar(NUX_FILE_LINE_PARAM) |
867 | - , overlay_window_(new VScrollBarOverlayWindow(_track->GetAbsoluteGeometry())) |
868 | , area_prox_(std::make_shared<ProximityArea>(this, PROXIMITY.CP(scale))) |
869 | - , thumb_above_slider_(false) |
870 | - , connector_height_(0) |
871 | - , mouse_down_offset_(0) |
872 | , delta_update_(0) |
873 | { |
874 | - area_prox_->mouse_near.connect(sigc::mem_fun(this, &PlacesOverlayVScrollBar::OnMouseNear)); |
875 | - area_prox_->mouse_beyond.connect(sigc::mem_fun(this, &PlacesOverlayVScrollBar::OnMouseBeyond)); |
876 | - |
877 | - overlay_window_->scale = scale(); |
878 | - overlay_window_->mouse_enter.connect(sigc::mem_fun(this, &PlacesOverlayVScrollBar::OnMouseEnter)); |
879 | - overlay_window_->mouse_leave.connect(sigc::mem_fun(this, &PlacesOverlayVScrollBar::OnMouseLeave)); |
880 | - overlay_window_->mouse_down.connect(sigc::mem_fun(this, &PlacesOverlayVScrollBar::OnMouseDown)); |
881 | - overlay_window_->mouse_up.connect(sigc::mem_fun(this, &PlacesOverlayVScrollBar::OnMouseUp)); |
882 | - overlay_window_->mouse_click.connect(sigc::mem_fun(this, &PlacesOverlayVScrollBar::OnMouseClick)); |
883 | - overlay_window_->mouse_move.connect(sigc::mem_fun(this, &PlacesOverlayVScrollBar::OnMouseMove)); |
884 | - overlay_window_->mouse_drag.connect(sigc::mem_fun(this, &PlacesOverlayVScrollBar::OnMouseDrag)); |
885 | - overlay_window_->mouse_wheel.connect(sigc::mem_fun(this, &PlacesOverlayVScrollBar::OnMouseWheel)); |
886 | - overlay_window_->sigHidden.connect(sigc::hide(sigc::mem_fun(this, &PlacesOverlayVScrollBar::ResetConnector))); |
887 | - |
888 | - _track->geometry_changed.connect(sigc::mem_fun(this, &PlacesOverlayVScrollBar::OnTrackGeometryChanged)); |
889 | - OnVisibleChanged.connect(sigc::mem_fun(this, &PlacesOverlayVScrollBar::OnVisibilityChanged)); |
890 | - OnSensitiveChanged.connect(sigc::mem_fun(this, &PlacesOverlayVScrollBar::OnSensitivityChanged)); |
891 | - |
892 | scale.changed.connect([this] (double scale) { |
893 | area_prox_->proximity = PROXIMITY.CP(scale); |
894 | - overlay_window_->scale = scale; |
895 | - }); |
896 | -} |
897 | - |
898 | -void PlacesOverlayVScrollBar::OnTrackGeometryChanged(nux::Area* /*area*/, nux::Geometry& /*geo*/) |
899 | -{ |
900 | - UpdateStepY(); |
901 | - overlay_window_->UpdateGeometry(_track->GetAbsoluteGeometry()); |
902 | - |
903 | - if (overlay_window_->IsVisible() && !IsScrollBarVisible()) |
904 | - { |
905 | - overlay_window_->ResetStates(); |
906 | - ResetConnector(); |
907 | - } |
908 | -} |
909 | - |
910 | -void PlacesOverlayVScrollBar::OnVisibilityChanged(nux::Area* /*area*/, bool visible) |
911 | -{ |
912 | - if (overlay_window_->IsVisible() && !visible) |
913 | - { |
914 | - overlay_window_->ResetStates(); |
915 | - ResetConnector(); |
916 | - } |
917 | -} |
918 | - |
919 | -void PlacesOverlayVScrollBar::OnSensitivityChanged(nux::Area* /*area*/, bool sensitive) |
920 | -{ |
921 | - if (!sensitive) |
922 | - { |
923 | - overlay_window_->ResetStates(); |
924 | - ResetConnector(); |
925 | - } |
926 | -} |
927 | - |
928 | -void PlacesOverlayVScrollBar::SetupAnimation(int start, int stop, int milliseconds) |
929 | -{ |
930 | - tweening_connection_->disconnect(); |
931 | + UpdateScrollbarSize(); |
932 | + }); |
933 | + |
934 | + auto update_sb_cb = sigc::mem_fun(this, &PlacesOverlayVScrollBar::UpdateScrollbarSize); |
935 | + |
936 | + auto update_sb_proximity_cb = sigc::hide(update_sb_cb); |
937 | + area_prox_->mouse_near.connect(update_sb_proximity_cb); |
938 | + area_prox_->mouse_beyond.connect(update_sb_proximity_cb); |
939 | + |
940 | + auto update_sb_mouse_cb = sigc::hide(sigc::hide(sigc::hide(update_sb_proximity_cb))); |
941 | + _track->mouse_enter.connect(update_sb_mouse_cb); |
942 | + _track->mouse_leave.connect(update_sb_mouse_cb); |
943 | + _slider->mouse_enter.connect(update_sb_mouse_cb); |
944 | + _slider->mouse_leave.connect(update_sb_mouse_cb); |
945 | + _slider->mouse_up.connect(update_sb_mouse_cb); |
946 | + _track->mouse_up.connect(update_sb_mouse_cb); |
947 | + |
948 | + // Disable default track-click handlers |
949 | + _track->mouse_down.clear(); |
950 | + _track->mouse_up.clear(); |
951 | + _track->mouse_down.connect([this] (int x, int y, unsigned long, unsigned long) { |
952 | + int slider_vcenter = _slider->GetBaseY() - _track->GetBaseY() + _slider->GetBaseHeight() / 2; |
953 | + int scroll_offset = slider_vcenter - y; |
954 | + |
955 | + if (scroll_offset > 0) |
956 | + StartScrollAnimation(ScrollDir::UP, scroll_offset, CLICK_SCROLL_ANIMATION); |
957 | + else |
958 | + StartScrollAnimation(ScrollDir::DOWN, -scroll_offset, CLICK_SCROLL_ANIMATION); |
959 | + }); |
960 | + |
961 | + UpdateScrollbarSize(); |
962 | +} |
963 | + |
964 | +void PlacesOverlayVScrollBar::UpdateScrollbarSize() |
965 | +{ |
966 | + bool is_hovering = false; |
967 | + SetMinimumWidth(ACTIVE_WIDTH.CP(scale)); |
968 | + SetMaximumWidth(ACTIVE_WIDTH.CP(scale)); |
969 | + |
970 | + _scroll_up_button->SetMaximumHeight(BUTTONS_HEIGHT.CP(scale)); |
971 | + _scroll_up_button->SetMinimumHeight(BUTTONS_HEIGHT.CP(scale)); |
972 | + _scroll_down_button->SetMaximumHeight(BUTTONS_HEIGHT.CP(scale)); |
973 | + _scroll_down_button->SetMinimumHeight(BUTTONS_HEIGHT.CP(scale)); |
974 | + |
975 | + int slider_width = DEFAULT_WIDTH.CP(scale); |
976 | + |
977 | + if (_track->IsMouseInside() || _track->IsMouseOwner() || |
978 | + _slider->IsMouseInside() || _slider->IsMouseOwner() || |
979 | + area_prox_->IsMouseNear()) |
980 | + { |
981 | + is_hovering = true; |
982 | + slider_width = ACTIVE_WIDTH.CP(scale); |
983 | + } |
984 | + |
985 | + hovering = is_hovering; |
986 | + |
987 | + _slider->SetMinimumWidth(slider_width); |
988 | + _slider->SetMaximumWidth(slider_width); |
989 | + _scroll_up_button->SetBaseWidth(slider_width); |
990 | + |
991 | + QueueDraw(); |
992 | +} |
993 | + |
994 | +void PlacesOverlayVScrollBar::PerformPageNavigation(ScrollDir dir) |
995 | +{ |
996 | + StartScrollAnimation(dir, _slider->GetBaseHeight(), PAGE_SCROLL_ANIMATION); |
997 | +} |
998 | + |
999 | +void PlacesOverlayVScrollBar::StartScrollAnimation(ScrollDir dir, int stop, unsigned duration) |
1000 | +{ |
1001 | + if (animation_.CurrentState() != nux::animation::Animation::State::Stopped) |
1002 | + return; |
1003 | + |
1004 | delta_update_ = 0; |
1005 | - |
1006 | - animation_.SetDuration(milliseconds); |
1007 | - animation_.SetEasingCurve(nux::animation::EasingCurve(nux::animation::EasingCurve::Type::Linear)); |
1008 | - |
1009 | - animation_.SetStartValue(start); |
1010 | - animation_.SetFinishValue(stop); |
1011 | -} |
1012 | - |
1013 | -void PlacesOverlayVScrollBar::PerformPageNavigation(ScrollDir dir) |
1014 | -{ |
1015 | - StartScrollAnimation(dir, _slider->GetBaseHeight()); |
1016 | -} |
1017 | - |
1018 | -void PlacesOverlayVScrollBar::StartScrollAnimation(ScrollDir dir, int stop) |
1019 | -{ |
1020 | - if (animation_.CurrentState() == nux::animation::Animation::State::Stopped) |
1021 | - { |
1022 | - SetupAnimation(0, stop, SCROLL_ANIMATION); |
1023 | - |
1024 | - tweening_connection_ = animation_.updated.connect([this, dir] (int const& update) { |
1025 | - OnScroll(dir, update - delta_update_); |
1026 | + stepY = (float) (content_height_ - container_height_) / (float) (_track->GetBaseHeight() - _slider->GetBaseHeight()); |
1027 | + |
1028 | + tweening_connection_ = animation_.updated.connect([this, dir] (int update) { |
1029 | + int mouse_dy = update - delta_update_; |
1030 | + |
1031 | + if (dir == ScrollDir::UP) |
1032 | + OnScrollUp.emit(stepY, mouse_dy); |
1033 | + else if (dir == ScrollDir::DOWN) |
1034 | + OnScrollDown.emit(stepY, mouse_dy); |
1035 | + |
1036 | delta_update_ = update; |
1037 | - |
1038 | - CheckIfThumbIsInsideSlider(); |
1039 | - UpdateConnectorPosition(); |
1040 | QueueDraw(); |
1041 | }); |
1042 | |
1043 | - animation_.Start(); |
1044 | - } |
1045 | -} |
1046 | - |
1047 | -void PlacesOverlayVScrollBar::OnScroll(ScrollDir dir, int mouse_dy) |
1048 | -{ |
1049 | - if (dir == ScrollDir::UP) |
1050 | - OnScrollUp.emit(stepY, mouse_dy); |
1051 | - else if (dir == ScrollDir::DOWN) |
1052 | - OnScrollDown.emit(stepY, mouse_dy); |
1053 | -} |
1054 | - |
1055 | -void PlacesOverlayVScrollBar::StartConnectorAnimation() |
1056 | -{ |
1057 | - if (animation_.CurrentState() == nux::animation::Animation::State::Stopped) |
1058 | - { |
1059 | - SetupAnimation(connector_height_, 0, std::min(connector_height_, MAX_CONNECTOR_ANIMATION)); |
1060 | - |
1061 | - tweening_connection_ = animation_.updated.connect([this] (int const& update) { |
1062 | - connector_height_ = update; |
1063 | - UpdateConnectorTexture(); |
1064 | - }); |
1065 | - |
1066 | - animation_.Start(); |
1067 | - } |
1068 | -} |
1069 | - |
1070 | -bool PlacesOverlayVScrollBar::IsScrollBarVisible() const |
1071 | -{ |
1072 | - return (content_height_ > container_height_); |
1073 | -} |
1074 | - |
1075 | -void PlacesOverlayVScrollBar::OnMouseEnter(int x, int y, unsigned int button_flags, unsigned int key_flags) |
1076 | -{ |
1077 | - overlay_window_->MouseEnter(); |
1078 | - UpdateConnectorPosition(); |
1079 | -} |
1080 | - |
1081 | -void PlacesOverlayVScrollBar::OnMouseLeave(int x, int y, unsigned int button_flags, unsigned int key_flags) |
1082 | -{ |
1083 | - overlay_window_->MouseLeave(); |
1084 | - UpdateConnectorPosition(); |
1085 | -} |
1086 | - |
1087 | -void PlacesOverlayVScrollBar::OnMouseNear(nux::Point const& mouse_pos) |
1088 | -{ |
1089 | - if (IsSensitive() && IsVisible() && IsScrollBarVisible()) |
1090 | - { |
1091 | - animation_.Stop(); |
1092 | - |
1093 | - overlay_window_->MouseNear(); |
1094 | - AdjustThumbOffsetFromMouse(); |
1095 | - } |
1096 | -} |
1097 | - |
1098 | -void PlacesOverlayVScrollBar::OnMouseBeyond(nux::Point const& mouse_pos) |
1099 | -{ |
1100 | - if (IsVisible() && IsScrollBarVisible()) |
1101 | - { |
1102 | - overlay_window_->MouseBeyond(); |
1103 | - UpdateConnectorPosition(); |
1104 | - } |
1105 | -} |
1106 | - |
1107 | -void PlacesOverlayVScrollBar::AdjustThumbOffsetFromMouse() |
1108 | -{ |
1109 | - if (!overlay_window_->IsMouseBeingDragged()) |
1110 | - { |
1111 | - nux::Point const& mouse = nux::GetWindowCompositor().GetMousePosition(); |
1112 | - |
1113 | - if (mouse.y > 0) |
1114 | - { |
1115 | - int const quarter_of_thumb = overlay_window_->GetThumbHeight()/4; |
1116 | - int const new_offset = mouse.y - _track->GetAbsoluteY() - overlay_window_->GetThumbHeight()/2; |
1117 | - |
1118 | - int const slider_offset = _slider->GetAbsoluteY() - _track->GetAbsoluteY() + _slider->GetBaseHeight()/3; |
1119 | - bool const mouse_above_slider = slider_offset < new_offset; |
1120 | - |
1121 | - if (mouse_above_slider) |
1122 | - overlay_window_->SetThumbOffsetY(new_offset - quarter_of_thumb); |
1123 | - else |
1124 | - overlay_window_->SetThumbOffsetY(new_offset + quarter_of_thumb); |
1125 | - } |
1126 | - |
1127 | - CheckIfThumbIsInsideSlider(); |
1128 | - } |
1129 | -} |
1130 | - |
1131 | -void PlacesOverlayVScrollBar::CheckIfThumbIsInsideSlider() |
1132 | -{ |
1133 | - nux::Geometry const& slider_geo = _slider->GetAbsoluteGeometry(); |
1134 | - nux::Geometry const& thumb_geo = overlay_window_->GetThumbGeometry(); |
1135 | - |
1136 | - if (thumb_geo.IsIntersecting(slider_geo)) |
1137 | - { |
1138 | - ResetConnector(); |
1139 | - overlay_window_->ThumbInsideSlider(); |
1140 | - } |
1141 | - else |
1142 | - { |
1143 | - UpdateConnectorPosition(); |
1144 | - overlay_window_->ThumbOutsideSlider(); |
1145 | - } |
1146 | -} |
1147 | - |
1148 | -void PlacesOverlayVScrollBar::UpdateConnectorPosition() |
1149 | -{ |
1150 | - int const slider_y = _slider->GetBaseY() - GetBaseY(); |
1151 | - int const thumb_y = overlay_window_->GetThumbOffsetY(); |
1152 | - int const thumb_height = overlay_window_->GetThumbHeight(); |
1153 | - |
1154 | - if (!overlay_window_->IsVisible()) |
1155 | - { |
1156 | - ResetConnector(); |
1157 | - } |
1158 | - else if (slider_y > thumb_y) |
1159 | - { |
1160 | - thumb_above_slider_ = true; |
1161 | - connector_height_ = slider_y - (thumb_y + thumb_height); |
1162 | - } |
1163 | - else |
1164 | - { |
1165 | - thumb_above_slider_ = false; |
1166 | - connector_height_ = thumb_y - (_slider->GetBaseY() + _slider->GetBaseHeight()) + _track->GetBaseY(); |
1167 | - } |
1168 | - |
1169 | - UpdateConnectorTexture(); |
1170 | -} |
1171 | - |
1172 | -void PlacesOverlayVScrollBar::ResetConnector() |
1173 | -{ |
1174 | - if (animation_.CurrentState() == nux::animation::Animation::State::Stopped) |
1175 | - { |
1176 | - if (connector_height_ > 0) |
1177 | - { |
1178 | - StartConnectorAnimation(); |
1179 | - } |
1180 | - } |
1181 | - else |
1182 | - { |
1183 | - connector_height_ = 0; |
1184 | - } |
1185 | - |
1186 | - QueueDraw(); |
1187 | -} |
1188 | - |
1189 | -void PlacesOverlayVScrollBar::OnMouseClick(int /*x*/, int y, unsigned int button_flags, unsigned int /*key_flags*/) |
1190 | -{ |
1191 | - if (!overlay_window_->IsMouseBeingDragged()) |
1192 | - { |
1193 | - int const button = nux::GetEventButton(button_flags); |
1194 | - |
1195 | - if (button == 1) |
1196 | - LeftMouseClick(y); |
1197 | - else if (button == 2) |
1198 | - MiddleMouseClick(y); |
1199 | - } |
1200 | - |
1201 | - overlay_window_->MouseUp(); |
1202 | -} |
1203 | - |
1204 | -void PlacesOverlayVScrollBar::LeftMouseClick(int y) |
1205 | -{ |
1206 | - if (IsMouseInTopHalfOfThumb(y)) |
1207 | - { |
1208 | - int const top = _slider->GetBaseY() - _track->GetBaseY(); |
1209 | - StartScrollAnimation(ScrollDir::UP, std::min(_slider->GetBaseHeight(), top)); |
1210 | - } |
1211 | - else |
1212 | - { |
1213 | - int const bottom = (_track->GetBaseY() + _track->GetBaseHeight()) - |
1214 | - (_slider->GetBaseHeight() + _slider->GetBaseY()); |
1215 | - StartScrollAnimation(ScrollDir::DOWN, std::min(_slider->GetBaseHeight(), bottom)); |
1216 | - } |
1217 | - |
1218 | - UpdateConnectorPosition(); |
1219 | -} |
1220 | - |
1221 | -void PlacesOverlayVScrollBar::MiddleMouseClick(int y) |
1222 | -{ |
1223 | - int const slider_offset = _slider->GetBaseY() - _track->GetBaseY(); |
1224 | - bool const move_up = slider_offset > overlay_window_->GetThumbOffsetY(); |
1225 | - |
1226 | - int const slider_thumb_diff = abs(overlay_window_->GetThumbOffsetY() - slider_offset); |
1227 | - |
1228 | - if (move_up) |
1229 | - StartScrollAnimation(ScrollDir::UP, slider_thumb_diff); |
1230 | - else |
1231 | - StartScrollAnimation(ScrollDir::DOWN, slider_thumb_diff); |
1232 | -} |
1233 | - |
1234 | -void PlacesOverlayVScrollBar::OnMouseDown(int /*x*/, int y, unsigned int /*button_flags*/, unsigned int /*key_flags*/) |
1235 | -{ |
1236 | - if (overlay_window_->IsMouseInsideThumb(y)) |
1237 | - { |
1238 | - if (IsMouseInTopHalfOfThumb(y)) |
1239 | - overlay_window_->PageUpAction(); |
1240 | - else |
1241 | - overlay_window_->PageDownAction(); |
1242 | - |
1243 | - mouse_down_offset_ = y - overlay_window_->GetThumbOffsetY(); |
1244 | - overlay_window_->MouseDown(); |
1245 | - } |
1246 | -} |
1247 | - |
1248 | -bool PlacesOverlayVScrollBar::IsMouseInTopHalfOfThumb(int y) |
1249 | -{ |
1250 | - int const thumb_height = overlay_window_->GetThumbHeight(); |
1251 | - int const thumb_offset_y = overlay_window_->GetThumbOffsetY(); |
1252 | - |
1253 | - return (y < (thumb_height/2 + thumb_offset_y)); |
1254 | -} |
1255 | - |
1256 | -void PlacesOverlayVScrollBar::OnMouseUp(int x, int y, unsigned int /*button_flags*/, unsigned int /*key_flags*/) |
1257 | -{ |
1258 | - nux::Geometry const& geo = overlay_window_->GetAbsoluteGeometry(); |
1259 | - |
1260 | - if (!geo.IsPointInside(x + geo.x, y + geo.y)) |
1261 | - { |
1262 | - overlay_window_->MouseUp(); |
1263 | - UpdateConnectorPosition(); |
1264 | - } |
1265 | -} |
1266 | - |
1267 | -void PlacesOverlayVScrollBar::OnMouseMove(int /*x*/, int y, int /*dx*/, int /*dy*/, unsigned int /*button_flags*/, unsigned int /*key_flags*/) |
1268 | -{ |
1269 | - if (!overlay_window_->IsMouseInsideThumb(y)) |
1270 | - AdjustThumbOffsetFromMouse(); |
1271 | -} |
1272 | - |
1273 | -void PlacesOverlayVScrollBar::OnMouseDrag(int /*x*/, int y, int /*dx*/, int dy, unsigned int /*button_flags*/, unsigned int /*key_flags*/) |
1274 | -{ |
1275 | - animation_.Stop(); |
1276 | - MouseDraggingOverlay(y, dy); |
1277 | -} |
1278 | - |
1279 | -void PlacesOverlayVScrollBar::OnMouseWheel(int x, int y, int delta, unsigned long mouse_state, unsigned long key_state) |
1280 | -{ |
1281 | - mouse_wheel.emit(x, y, delta, mouse_state, key_state); |
1282 | - UpdateConnectorPosition(); |
1283 | -} |
1284 | - |
1285 | -void PlacesOverlayVScrollBar::MouseDraggingOverlay(int y, int dy) |
1286 | -{ |
1287 | - int const thumb_offset = overlay_window_->GetThumbOffsetY() + mouse_down_offset_; |
1288 | - |
1289 | - if (dy < 0 && !AtMinimum() && y <= thumb_offset) |
1290 | - { |
1291 | - OnScrollUp.emit(stepY, abs(dy)); |
1292 | - } |
1293 | - else if (dy > 0 && !AtMaximum() && y >= thumb_offset) |
1294 | - { |
1295 | - OnScrollDown.emit(stepY, dy); |
1296 | - } |
1297 | - |
1298 | - overlay_window_->SetThumbOffsetY(y - mouse_down_offset_); |
1299 | - CheckIfThumbIsInsideSlider(); |
1300 | -} |
1301 | - |
1302 | -void PlacesOverlayVScrollBar::UpdateStepY() |
1303 | -{ |
1304 | - stepY = (float) (content_height_ - container_height_) / (float) (_track->GetBaseHeight() - _slider->GetBaseHeight()); |
1305 | -} |
1306 | - |
1307 | -void PlacesOverlayVScrollBar::Draw(nux::GraphicsEngine& graphics_engine, bool force_draw) |
1308 | -{ |
1309 | - PlacesVScrollBar::Draw(graphics_engine, force_draw); |
1310 | - |
1311 | - if (connector_height_ > 0 && connector_texture_.IsValid()) |
1312 | - { |
1313 | - int const connector_width = GetBaseWidth(); |
1314 | - int offset_y = 0; |
1315 | - if (thumb_above_slider_) |
1316 | - { |
1317 | - offset_y = _slider->GetBaseY() - connector_height_; |
1318 | - } |
1319 | - else |
1320 | - { |
1321 | - offset_y = _slider->GetBaseY() + _slider->GetBaseHeight(); |
1322 | - } |
1323 | - |
1324 | - nux::Geometry base(_track->GetBaseX(), offset_y - 4, connector_width, connector_height_ + 5); |
1325 | - nux::TexCoordXForm texxform; |
1326 | - |
1327 | - graphics_engine.QRP_1Tex(base.x, |
1328 | - base.y, |
1329 | - base.width, |
1330 | - base.height, |
1331 | - connector_texture_->GetDeviceTexture(), |
1332 | - texxform, |
1333 | - nux::color::White); |
1334 | - } |
1335 | -} |
1336 | - |
1337 | -void PlacesOverlayVScrollBar::UpdateConnectorTexture() |
1338 | -{ |
1339 | - if (connector_height_ < 0) |
1340 | - return; |
1341 | - |
1342 | - int width = _slider->GetWidth(); |
1343 | - int height = connector_height_; |
1344 | - |
1345 | - if (connector_texture_ && connector_texture_->GetWidth() == width && connector_texture_->GetHeight() == height) |
1346 | - return; |
1347 | - |
1348 | - nux::CairoGraphics cairoGraphics(CAIRO_FORMAT_ARGB32, width, height); |
1349 | - cairo_t* cr = cairoGraphics.GetInternalContext(); |
1350 | - cairo_surface_set_device_scale(cairo_get_target(cr), scale, scale); |
1351 | - |
1352 | - cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR); |
1353 | - cairo_paint(cr); |
1354 | - |
1355 | - cairo_set_operator(cr, CAIRO_OPERATOR_OVER); |
1356 | - cairo_set_source_rgba(cr, CONNECTOR_COLOR.red, CONNECTOR_COLOR.green, CONNECTOR_COLOR.blue, 0.8); |
1357 | - cairo_rectangle(cr, 0, 0, static_cast<double>(width)/scale(), static_cast<double>(height)/scale()); |
1358 | - cairo_fill(cr); |
1359 | - |
1360 | - connector_texture_ = texture_ptr_from_cairo_graphics(cairoGraphics); |
1361 | - |
1362 | - QueueDraw(); |
1363 | + animation_.SetDuration(duration); |
1364 | + animation::Start(animation_, 0, stop); |
1365 | } |
1366 | |
1367 | } // namespace dash |
1368 | |
1369 | === modified file 'unity-shared/PlacesOverlayVScrollBar.h' |
1370 | --- unity-shared/PlacesOverlayVScrollBar.h 2015-05-04 20:55:56 +0000 |
1371 | +++ unity-shared/PlacesOverlayVScrollBar.h 2015-12-09 12:47:13 +0000 |
1372 | @@ -1,6 +1,6 @@ |
1373 | // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- |
1374 | /* |
1375 | - * Copyright (C) 2012 Canonical Ltd |
1376 | + * Copyright (C) 2012-2015 Canonical Ltd |
1377 | * |
1378 | * This program is free software: you can redistribute it and/or modify |
1379 | * it under the terms of the GNU General Public License version 3 as |
1380 | @@ -15,6 +15,7 @@ |
1381 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1382 | * |
1383 | * Authored by: Brandon Schaefer <brandon.schaefer@canonical.com> |
1384 | + * Marco Trevisan <marco.trevisan@canonical.com> |
1385 | */ |
1386 | |
1387 | #ifndef PLACES_OVERLAY_VSCROLLBAR_H |
1388 | @@ -27,7 +28,6 @@ |
1389 | #include <memory> |
1390 | |
1391 | #include "unity-shared/PlacesVScrollBar.h" |
1392 | -#include "unity-shared/VScrollBarOverlayWindow.h" |
1393 | |
1394 | namespace unity |
1395 | { |
1396 | @@ -46,67 +46,17 @@ |
1397 | PlacesOverlayVScrollBar(NUX_FILE_LINE_PROTO); |
1398 | virtual ~PlacesOverlayVScrollBar() {} |
1399 | |
1400 | - void PerformPageNavigation(ScrollDir dir); |
1401 | - |
1402 | -protected: |
1403 | - void Draw(nux::GraphicsEngine& graphics_engine, bool force_draw); |
1404 | + void PerformPageNavigation(ScrollDir); |
1405 | |
1406 | private: |
1407 | - void OnTrackGeometryChanged(nux::Area* area, nux::Geometry& geo); |
1408 | - void OnVisibilityChanged(nux::Area* area, bool visible); |
1409 | - void OnSensitivityChanged(nux::Area* area, bool sensitive); |
1410 | - |
1411 | - void OnMouseEnter(int x, int y, unsigned int button_flags, unsigned int key_flags); |
1412 | - void OnMouseLeave(int x, int y, unsigned int button_flags, unsigned int key_flags); |
1413 | - |
1414 | - void OnMouseNear(nux::Point const& mouse_pos); |
1415 | - void OnMouseBeyond(nux::Point const& mouse_pos); |
1416 | - void AdjustThumbOffsetFromMouse(); |
1417 | - |
1418 | - void OnMouseClick(int x, int y, unsigned int button_flags, unsigned int key_flags); |
1419 | - void LeftMouseClick(int y); |
1420 | - void MiddleMouseClick(int y); |
1421 | - |
1422 | - void OnMouseDown(int x, int y, unsigned int button_flags, unsigned int key_flags); |
1423 | - void OnMouseUp(int x, int y, unsigned int button_flags, unsigned int key_flags); |
1424 | - void OnMouseMove(int x, int y, int dx, int dy, unsigned int button_flags, unsigned int key_flags); |
1425 | - void OnMouseDrag(int x, int y, int dx, int dy, unsigned int button_flags, unsigned int key_flags); |
1426 | - void OnMouseWheel(int x, int y, int delta, unsigned long mouse_state, unsigned long key_state); |
1427 | - |
1428 | - void MouseDraggingOverlay(int y, int dy); |
1429 | - |
1430 | - bool IsMouseInTopHalfOfThumb(int y); |
1431 | - void CheckIfThumbIsInsideSlider(); |
1432 | - |
1433 | - bool IsScrollBarVisible() const; |
1434 | - |
1435 | - void UpdateConnectorPosition(); |
1436 | - void ResetConnector(); |
1437 | - |
1438 | - void UpdateStepY(); |
1439 | - |
1440 | - void SetupAnimation(int start, int stop, int milliseconds); |
1441 | - |
1442 | - void StartScrollAnimation(ScrollDir dir, int stop); |
1443 | - void OnScroll(ScrollDir dir, int mouse_dy); |
1444 | - |
1445 | - void StartConnectorAnimation(); |
1446 | - |
1447 | - void UpdateConnectorTexture(); |
1448 | - |
1449 | - nux::ObjectPtr<VScrollBarOverlayWindow> overlay_window_; |
1450 | + void UpdateScrollbarSize(); |
1451 | + void StartScrollAnimation(ScrollDir, int stop, unsigned duration); |
1452 | |
1453 | class ProximityArea; |
1454 | std::shared_ptr<ProximityArea> area_prox_; |
1455 | |
1456 | nux::animation::AnimateValue<int> animation_; |
1457 | connection::Wrapper tweening_connection_; |
1458 | - |
1459 | - nux::ObjectPtr<nux::BaseTexture> connector_texture_; |
1460 | - |
1461 | - bool thumb_above_slider_; |
1462 | - int connector_height_; |
1463 | - int mouse_down_offset_; |
1464 | int delta_update_; |
1465 | |
1466 | friend class MockScrollBar; |
1467 | |
1468 | === modified file 'unity-shared/PlacesVScrollBar.cpp' |
1469 | --- unity-shared/PlacesVScrollBar.cpp 2015-02-03 13:06:47 +0000 |
1470 | +++ unity-shared/PlacesVScrollBar.cpp 2015-12-09 12:47:13 +0000 |
1471 | @@ -21,9 +21,10 @@ |
1472 | #include <Nux/Nux.h> |
1473 | #include <NuxGraphics/CairoGraphics.h> |
1474 | |
1475 | +#include "PlacesVScrollBar.h" |
1476 | #include "unity-shared/CairoTexture.h" |
1477 | #include "unity-shared/RawPixel.h" |
1478 | -#include "PlacesVScrollBar.h" |
1479 | +#include "unity-shared/GraphicsUtils.h" |
1480 | |
1481 | namespace unity |
1482 | { |
1483 | @@ -31,13 +32,14 @@ |
1484 | { |
1485 | namespace |
1486 | { |
1487 | -const RawPixel BUTTONS_HEIGHT = 15_em; |
1488 | +const RawPixel BUTTONS_HEIGHT = 0_em; |
1489 | const RawPixel WIDTH = 3_em; |
1490 | } |
1491 | |
1492 | PlacesVScrollBar::PlacesVScrollBar(NUX_FILE_LINE_DECL) |
1493 | : nux::VScrollBar(NUX_FILE_LINE_PARAM) |
1494 | , scale(1.0) |
1495 | + , hovering(false) |
1496 | { |
1497 | UpdateSize(); |
1498 | scale.changed.connect([this] (double scale) { |
1499 | @@ -54,53 +56,16 @@ |
1500 | |
1501 | _scroll_down_button->SetMaximumHeight(BUTTONS_HEIGHT.CP(scale)); |
1502 | _scroll_down_button->SetMinimumHeight(BUTTONS_HEIGHT.CP(scale)); |
1503 | - |
1504 | - _slider->SetMinimumWidth(WIDTH.CP(scale)); |
1505 | - _slider->SetMaximumWidth(WIDTH.CP(scale)); |
1506 | - SetMinimumWidth(WIDTH.CP(scale)); |
1507 | - SetMaximumWidth(WIDTH.CP(scale)); |
1508 | -} |
1509 | - |
1510 | -void PlacesVScrollBar::PreLayoutManagement() |
1511 | -{ |
1512 | - nux::VScrollBar::PreLayoutManagement(); |
1513 | -} |
1514 | - |
1515 | -long |
1516 | -PlacesVScrollBar::PostLayoutManagement(long LayoutResult) |
1517 | -{ |
1518 | - long ret = nux::VScrollBar::PostLayoutManagement(LayoutResult); |
1519 | - |
1520 | - UpdateTexture(); |
1521 | - return ret; |
1522 | -} |
1523 | - |
1524 | -void |
1525 | -PlacesVScrollBar::Draw(nux::GraphicsEngine& graphics_engine, bool force_draw) |
1526 | +} |
1527 | + |
1528 | +void PlacesVScrollBar::Draw(nux::GraphicsEngine& graphics_engine, bool force_draw) |
1529 | +{} |
1530 | + |
1531 | +void PlacesVScrollBar::DrawContent(nux::GraphicsEngine& graphics_engine, bool force_draw) |
1532 | { |
1533 | if (!RedirectedAncestor()) |
1534 | - { |
1535 | - DrawScrollbar(graphics_engine); |
1536 | - } |
1537 | -} |
1538 | - |
1539 | -void |
1540 | -PlacesVScrollBar::DrawContent(nux::GraphicsEngine& graphics_engine, bool force_draw) |
1541 | -{ |
1542 | - if (RedirectedAncestor()) |
1543 | - { |
1544 | - DrawScrollbar(graphics_engine); |
1545 | - } |
1546 | -} |
1547 | - |
1548 | -void |
1549 | -PlacesVScrollBar::DrawScrollbar(nux::GraphicsEngine& graphics_engine) |
1550 | -{ |
1551 | - // check if textures have been computed... if they haven't, exit function |
1552 | - if (!slider_texture_) |
1553 | return; |
1554 | |
1555 | - nux::Color color = nux::color::White; |
1556 | nux::Geometry const& base = GetGeometry(); |
1557 | nux::TexCoordXForm texxform; |
1558 | |
1559 | @@ -108,7 +73,6 @@ |
1560 | unsigned int alpha = 0, src = 0, dest = 0; |
1561 | graphics_engine.GetRenderStates().GetBlend(alpha, src, dest); |
1562 | |
1563 | - |
1564 | texxform.SetTexCoordType(nux::TexCoordXForm::OFFSET_SCALE_COORD); |
1565 | |
1566 | graphics_engine.GetRenderStates().SetBlend(true); |
1567 | @@ -117,29 +81,50 @@ |
1568 | if (content_height_ > container_height_) |
1569 | { |
1570 | nux::Geometry const& slider_geo = _slider->GetGeometry(); |
1571 | - |
1572 | - graphics_engine.QRP_1Tex(slider_geo.x, |
1573 | - slider_geo.y, |
1574 | - slider_geo.width, |
1575 | - slider_geo.height, |
1576 | - slider_texture_->GetDeviceTexture(), |
1577 | - texxform, |
1578 | - color); |
1579 | + nux::GetPainter().PushBackgroundStack(); |
1580 | + |
1581 | + if (hovering) |
1582 | + graphics::ClearGeometry(base); |
1583 | + |
1584 | + nux::ROPConfig rop; |
1585 | + rop.Blend = true; |
1586 | + rop.SrcBlend = GL_ONE; |
1587 | + rop.DstBlend = GL_ONE_MINUS_SRC_ALPHA; |
1588 | + |
1589 | + nux::ColorLayer layer(nux::color::Transparent, true, rop); |
1590 | + nux::GetPainter().PushDrawLayer(graphics_engine, base, &layer); |
1591 | + |
1592 | + if (hovering) |
1593 | + graphics_engine.QRP_Color(base.x, base.y, base.width, base.height, nux::color::White * 0.4); |
1594 | + |
1595 | + UpdateTexture(slider_geo); |
1596 | + graphics_engine.QRP_1Tex(base.x + base.width - slider_geo.width, |
1597 | + slider_geo.y, |
1598 | + slider_geo.width, |
1599 | + slider_geo.height, |
1600 | + slider_texture_->GetDeviceTexture(), |
1601 | + texxform, |
1602 | + nux::color::White); |
1603 | + |
1604 | + nux::GetPainter().PopBackgroundStack(); |
1605 | } |
1606 | |
1607 | graphics_engine.PopClippingRectangle(); |
1608 | graphics_engine.GetRenderStates().SetBlend(alpha, src, dest); |
1609 | } |
1610 | |
1611 | -void PlacesVScrollBar::UpdateTexture() |
1612 | +void PlacesVScrollBar::UpdateTexture(nux::Geometry const& geo) |
1613 | { |
1614 | // update texture of slider |
1615 | - int width = _slider->GetBaseWidth(); |
1616 | - int height = _slider->GetBaseHeight(); |
1617 | + int width = geo.width; |
1618 | + int height = geo.height; |
1619 | |
1620 | if (slider_texture_ && slider_texture_->GetWidth() == width && slider_texture_->GetHeight() == height) |
1621 | return; |
1622 | |
1623 | + double unscaled_width = static_cast<double>(width) / scale(); |
1624 | + double unscaled_height = static_cast<double>(height) / scale(); |
1625 | + |
1626 | nux::CairoGraphics cg(CAIRO_FORMAT_ARGB32, width, height); |
1627 | auto* cr = cg.GetInternalContext(); |
1628 | cairo_surface_set_device_scale(cairo_get_target(cr), scale, scale); |
1629 | @@ -149,7 +134,7 @@ |
1630 | |
1631 | cairo_set_operator(cr, CAIRO_OPERATOR_OVER); |
1632 | cairo_set_source_rgba(cr, 1.0f, 1.0f, 1.0f, 1.0f); |
1633 | - cg.DrawRoundedRectangle(cr, 1.0f, 0.0, 0.0, 1.5, 3.0, static_cast<double>(height)/scale() - 3.0); |
1634 | + cg.DrawRoundedRectangle(cr, 1.0f, 0, 0, unscaled_width / 2.0, unscaled_width, unscaled_height - 2.0); |
1635 | cairo_fill(cr); |
1636 | |
1637 | slider_texture_ = texture_ptr_from_cairo_graphics(cg); |
1638 | |
1639 | === modified file 'unity-shared/PlacesVScrollBar.h' |
1640 | --- unity-shared/PlacesVScrollBar.h 2014-07-11 19:14:00 +0000 |
1641 | +++ unity-shared/PlacesVScrollBar.h 2015-12-09 12:47:13 +0000 |
1642 | @@ -33,18 +33,15 @@ |
1643 | PlacesVScrollBar(NUX_FILE_LINE_PROTO); |
1644 | |
1645 | nux::Property<double> scale; |
1646 | + nux::Property<bool> hovering; |
1647 | |
1648 | protected: |
1649 | - virtual void PreLayoutManagement(); |
1650 | - virtual long PostLayoutManagement(long LayoutResult); |
1651 | - |
1652 | void Draw(nux::GraphicsEngine& gfxContext, bool forceDraw); |
1653 | void DrawContent(nux::GraphicsEngine& gfxContext, bool forceDraw); |
1654 | |
1655 | private: |
1656 | void UpdateSize(); |
1657 | - void UpdateTexture(); |
1658 | - void DrawScrollbar(nux::GraphicsEngine& graphics_engine); |
1659 | + void UpdateTexture(nux::Geometry const&); |
1660 | |
1661 | private: |
1662 | nux::ObjectPtr<nux::BaseTexture> slider_texture_; |
1663 | |
1664 | === removed file 'unity-shared/VScrollBarOverlayWindow.cpp' |
1665 | --- unity-shared/VScrollBarOverlayWindow.cpp 2014-07-11 22:42:00 +0000 |
1666 | +++ unity-shared/VScrollBarOverlayWindow.cpp 1970-01-01 00:00:00 +0000 |
1667 | @@ -1,568 +0,0 @@ |
1668 | -// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- |
1669 | -/* |
1670 | - * Copyright (C) 2012 Canonical Ltd |
1671 | - * |
1672 | - * This program is free software: you can redistribute it and/or modify |
1673 | - * it under the terms of the GNU General Public License version 3 as |
1674 | - * published by the Free Software Foundation. |
1675 | - * |
1676 | - * This program is distributed in the hope that it will be useful, |
1677 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1678 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1679 | - * GNU General Public License for more details. |
1680 | - * |
1681 | - * You should have received a copy of the GNU General Public License |
1682 | - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1683 | - * |
1684 | - * Authored by: Brandon Schaefer <brandon.schaefer@canonical.com> |
1685 | - */ |
1686 | - |
1687 | -#include <Nux/Nux.h> |
1688 | -#include <NuxGraphics/CairoGraphics.h> |
1689 | - |
1690 | -#include "VScrollBarOverlayWindow.h" |
1691 | -#include "UScreen.h" |
1692 | -#include "DashStyle.h" |
1693 | -#include "CairoTexture.h" |
1694 | -#include "unity-shared/AnimationUtils.h" |
1695 | - |
1696 | -namespace unity |
1697 | -{ |
1698 | - |
1699 | -namespace |
1700 | -{ |
1701 | - const RawPixel THUMB_WIDTH = 21_em; |
1702 | - const RawPixel THUMB_HEIGHT = 68_em; |
1703 | - const int THUMB_RADIUS = 3; |
1704 | - const int ANIMATION_DURATION = 90; |
1705 | -} |
1706 | - |
1707 | -VScrollBarOverlayWindow::VScrollBarOverlayWindow(nux::Geometry const& geo) |
1708 | - : nux::BaseWindow("") |
1709 | - , scale(1.0) |
1710 | - , content_size_(geo) |
1711 | - , content_offset_x_(0) |
1712 | - , mouse_offset_y_(0) |
1713 | - , current_state_(ThumbState::NONE) |
1714 | - , current_action_(ThumbAction::NONE) |
1715 | - , show_animator_(ANIMATION_DURATION) |
1716 | -{ |
1717 | - Area::SetGeometry(content_size_.x, content_size_.y, THUMB_WIDTH.CP(scale), content_size_.height); |
1718 | - SetBackgroundColor(nux::color::Transparent); |
1719 | - SetAcceptMouseWheelEvent(true); |
1720 | - |
1721 | - show_animator_.updated.connect(sigc::mem_fun(this, &BaseWindow::SetOpacity)); |
1722 | - show_animator_.finished.connect([this] { |
1723 | - if (animation::GetDirection(show_animator_) == animation::Direction::BACKWARD) |
1724 | - ShowWindow(false); |
1725 | - }); |
1726 | - |
1727 | - SetOpacity(0.0f); |
1728 | - UpdateTexture(); |
1729 | - |
1730 | - scale.changed.connect([this] (double scale) { |
1731 | - UpdateContentGeometry(); |
1732 | - UpdateTexture(); |
1733 | - }); |
1734 | -} |
1735 | - |
1736 | -void VScrollBarOverlayWindow::UpdateContentGeometry() |
1737 | -{ |
1738 | - UpdateMouseOffsetX(); |
1739 | - Area::SetGeometry(content_size_.x + content_offset_x_, content_size_.y, THUMB_WIDTH.CP(scale), content_size_.height); |
1740 | -} |
1741 | - |
1742 | -void VScrollBarOverlayWindow::UpdateGeometry(nux::Geometry const& geo) |
1743 | -{ |
1744 | - if (content_size_.x != geo.x || |
1745 | - content_size_.y != geo.y || |
1746 | - content_size_.height != geo.height) |
1747 | - { |
1748 | - content_size_ = geo; |
1749 | - UpdateContentGeometry(); |
1750 | - } |
1751 | -} |
1752 | - |
1753 | -void VScrollBarOverlayWindow::SetThumbOffsetY(int y) |
1754 | -{ |
1755 | - int const new_offset = GetValidOffsetYValue(y); |
1756 | - |
1757 | - if (new_offset != mouse_offset_y_) |
1758 | - { |
1759 | - if (HasState(ThumbState::MOUSE_DOWN)) |
1760 | - MouseDragging(); |
1761 | - |
1762 | - mouse_offset_y_ = new_offset; |
1763 | - QueueDraw(); |
1764 | - } |
1765 | -} |
1766 | - |
1767 | -int VScrollBarOverlayWindow::GetValidOffsetYValue(int new_offset) const |
1768 | -{ |
1769 | - if (new_offset < 0) |
1770 | - return 0; |
1771 | - else if (new_offset > content_size_.height - THUMB_HEIGHT.CP(scale)) |
1772 | - return content_size_.height - THUMB_HEIGHT.CP(scale); |
1773 | - |
1774 | - return new_offset; |
1775 | -} |
1776 | - |
1777 | -void VScrollBarOverlayWindow::UpdateMouseOffsetX() |
1778 | -{ |
1779 | - int monitor = unity::UScreen::GetDefault()->GetMonitorWithMouse(); |
1780 | - nux::Geometry const& geo = unity::UScreen::GetDefault()->GetMonitorGeometry(monitor); |
1781 | - |
1782 | - if (content_size_.x + THUMB_WIDTH.CP(scale) > geo.x + geo.width) |
1783 | - content_offset_x_ = geo.x + geo.width - (content_size_.x + THUMB_WIDTH.CP(scale)); |
1784 | - else |
1785 | - content_offset_x_ = 0; |
1786 | -} |
1787 | - |
1788 | -bool VScrollBarOverlayWindow::IsMouseInsideThumb(int y) const |
1789 | -{ |
1790 | - nux::Geometry const thumb(0, mouse_offset_y_, THUMB_WIDTH.CP(scale), THUMB_HEIGHT.CP(scale)); |
1791 | - return thumb.IsPointInside(0,y); |
1792 | -} |
1793 | - |
1794 | -bool VScrollBarOverlayWindow::IsMouseBeingDragged() const |
1795 | -{ |
1796 | - return current_action_ == ThumbAction::DRAGGING; |
1797 | -} |
1798 | - |
1799 | -int VScrollBarOverlayWindow::GetThumbHeight() const |
1800 | -{ |
1801 | - return THUMB_HEIGHT.CP(scale); |
1802 | -} |
1803 | - |
1804 | -int VScrollBarOverlayWindow::GetThumbOffsetY() const |
1805 | -{ |
1806 | - return mouse_offset_y_; |
1807 | -} |
1808 | - |
1809 | -nux::Geometry VScrollBarOverlayWindow::GetThumbGeometry() const |
1810 | -{ |
1811 | - return nux::Geometry(content_size_.x + content_offset_x_, |
1812 | - content_size_.y + mouse_offset_y_, |
1813 | - THUMB_WIDTH.CP(scale), THUMB_HEIGHT.CP(scale)); |
1814 | -} |
1815 | - |
1816 | -void VScrollBarOverlayWindow::MouseDown() |
1817 | -{ |
1818 | - AddState(ThumbState::MOUSE_DOWN); |
1819 | - UpdateTexture(); |
1820 | -} |
1821 | - |
1822 | -void VScrollBarOverlayWindow::MouseUp() |
1823 | -{ |
1824 | - RemoveState(ThumbState::MOUSE_DOWN); |
1825 | - current_action_ = ThumbAction::NONE; |
1826 | - UpdateTexture(); |
1827 | - ShouldHide(); |
1828 | -} |
1829 | - |
1830 | -void VScrollBarOverlayWindow::MouseNear() |
1831 | -{ |
1832 | - AddState(ThumbState::MOUSE_NEAR); |
1833 | - ShouldShow(); |
1834 | -} |
1835 | - |
1836 | -void VScrollBarOverlayWindow::MouseBeyond() |
1837 | -{ |
1838 | - RemoveState(ThumbState::MOUSE_NEAR); |
1839 | - ShouldHide(); |
1840 | -} |
1841 | - |
1842 | -void VScrollBarOverlayWindow::MouseEnter() |
1843 | -{ |
1844 | - AddState(ThumbState::MOUSE_INSIDE); |
1845 | - ShouldShow(); |
1846 | -} |
1847 | - |
1848 | -void VScrollBarOverlayWindow::MouseLeave() |
1849 | -{ |
1850 | - RemoveState(ThumbState::MOUSE_INSIDE); |
1851 | - ShouldHide(); |
1852 | -} |
1853 | - |
1854 | -void VScrollBarOverlayWindow::ThumbInsideSlider() |
1855 | -{ |
1856 | - if (!HasState(ThumbState::INSIDE_SLIDER)) |
1857 | - { |
1858 | - AddState(ThumbState::INSIDE_SLIDER); |
1859 | - UpdateTexture(); |
1860 | - } |
1861 | -} |
1862 | - |
1863 | -void VScrollBarOverlayWindow::ThumbOutsideSlider() |
1864 | -{ |
1865 | - if (HasState(ThumbState::INSIDE_SLIDER)) |
1866 | - { |
1867 | - RemoveState(ThumbState::INSIDE_SLIDER); |
1868 | - UpdateTexture(); |
1869 | - } |
1870 | -} |
1871 | - |
1872 | -void VScrollBarOverlayWindow::PageUpAction() |
1873 | -{ |
1874 | - current_action_ = ThumbAction::PAGE_UP; |
1875 | - UpdateTexture(); |
1876 | -} |
1877 | - |
1878 | -void VScrollBarOverlayWindow::PageDownAction() |
1879 | -{ |
1880 | - current_action_ = ThumbAction::PAGE_DOWN; |
1881 | - UpdateTexture(); |
1882 | -} |
1883 | - |
1884 | -void VScrollBarOverlayWindow::MouseDragging() |
1885 | -{ |
1886 | - if (current_action_ != ThumbAction::DRAGGING) |
1887 | - { |
1888 | - current_action_ = ThumbAction::DRAGGING; |
1889 | - UpdateTexture(); |
1890 | - } |
1891 | -} |
1892 | - |
1893 | -void VScrollBarOverlayWindow::ShouldShow() |
1894 | -{ |
1895 | - if (!IsVisible()) |
1896 | - { |
1897 | - if (HasState(ThumbState::MOUSE_DOWN) || |
1898 | - HasState(ThumbState::MOUSE_NEAR)) |
1899 | - { |
1900 | - ShowWindow(true); |
1901 | - PushToFront(); |
1902 | - animation::StartOrReverse(show_animator_, animation::Direction::FORWARD); |
1903 | - } |
1904 | - } |
1905 | -} |
1906 | - |
1907 | -void VScrollBarOverlayWindow::ShouldHide() |
1908 | -{ |
1909 | - if (IsVisible()) |
1910 | - { |
1911 | - if (!(HasState(ThumbState::MOUSE_DOWN)) && |
1912 | - !(HasState(ThumbState::MOUSE_NEAR)) && |
1913 | - !(HasState(ThumbState::MOUSE_INSIDE))) |
1914 | - { |
1915 | - animation::StartOrReverse(show_animator_, animation::Direction::BACKWARD); |
1916 | - } |
1917 | - } |
1918 | -} |
1919 | - |
1920 | -void VScrollBarOverlayWindow::ResetStates() |
1921 | -{ |
1922 | - current_state_ = ThumbState::NONE; |
1923 | - current_action_ = ThumbAction::NONE; |
1924 | - ShouldHide(); |
1925 | -} |
1926 | - |
1927 | -void VScrollBarOverlayWindow::AddState(ThumbState const& state) |
1928 | -{ |
1929 | - current_state_ |= state; |
1930 | -} |
1931 | - |
1932 | -void VScrollBarOverlayWindow::RemoveState(ThumbState const& state) |
1933 | -{ |
1934 | - current_state_ &= ~(state); |
1935 | -} |
1936 | - |
1937 | -bool VScrollBarOverlayWindow::HasState(ThumbState const& state) const |
1938 | -{ |
1939 | - return (current_state_ & state); |
1940 | -} |
1941 | - |
1942 | -void VScrollBarOverlayWindow::Draw(nux::GraphicsEngine& graphics_engine, bool force_draw) |
1943 | -{ |
1944 | - if (!thumb_texture_) |
1945 | - return; |
1946 | - |
1947 | - nux::Geometry base(0, mouse_offset_y_, THUMB_WIDTH.CP(scale), THUMB_HEIGHT.CP(scale)); |
1948 | - nux::TexCoordXForm texxform; |
1949 | - |
1950 | - graphics_engine.QRP_1Tex(base.x, |
1951 | - base.y, |
1952 | - base.width, |
1953 | - base.height, |
1954 | - thumb_texture_->GetDeviceTexture(), |
1955 | - texxform, |
1956 | - nux::color::White); |
1957 | -} |
1958 | - |
1959 | -nux::color::RedGreenBlue ProduceColorShade(nux::color::RedGreenBlue const& rgb, float shade) |
1960 | -{ |
1961 | - if (shade == 1.0f) |
1962 | - return rgb; |
1963 | - |
1964 | - nux::color::HueLightnessSaturation hls(rgb); |
1965 | - |
1966 | - hls.lightness *= shade; |
1967 | - if (hls.lightness > 1.0f) |
1968 | - hls.lightness = 1.0f; |
1969 | - else if (hls.lightness < 0.0f) |
1970 | - hls.lightness = 0.0f; |
1971 | - |
1972 | - hls.saturation *= shade; |
1973 | - if (hls.saturation > 1.0f) |
1974 | - hls.saturation = 1.0f; |
1975 | - else if (hls.saturation < 0.0f) |
1976 | - hls.saturation = 0.0f; |
1977 | - |
1978 | - nux::color::RedGreenBlue rgb_shade(hls); |
1979 | - |
1980 | - return rgb_shade; |
1981 | -} |
1982 | - |
1983 | -void PatternAddRGBStop(cairo_pattern_t* pat, nux::color::RedGreenBlue const& rgb, double stop, float alpha) |
1984 | -{ |
1985 | - cairo_pattern_add_color_stop_rgba (pat, stop, rgb.red, rgb.green, rgb.blue, alpha); |
1986 | -} |
1987 | - |
1988 | -void SetSourceRGB(cairo_t* cr, nux::color::RedGreenBlue const& rgb, float alpha) |
1989 | -{ |
1990 | - cairo_set_source_rgba(cr, rgb.red, rgb.green, rgb.blue, alpha); |
1991 | -} |
1992 | - |
1993 | -void DrawGrip (cairo_t* cr, double x, double y, int nx, int ny) |
1994 | -{ |
1995 | - gint lx, ly; |
1996 | - |
1997 | - for (ly = 0; ly < ny; ly++) |
1998 | - { |
1999 | - for (lx = 0; lx < nx; lx++) |
2000 | - { |
2001 | - gint sx = lx * 3; |
2002 | - gint sy = ly * 3; |
2003 | - |
2004 | - cairo_rectangle (cr, x + sx, y + sy, 1, 1); |
2005 | - } |
2006 | - } |
2007 | -} |
2008 | - |
2009 | -void DrawBothGrips(cairo_t* cr, nux::color::RedGreenBlue const& rgb, int width, int height) |
2010 | -{ |
2011 | - int const grip_width = 5; |
2012 | - int const grip_height = 6; |
2013 | - float const grip_y = 13.5; |
2014 | - float const offset = 6.5; |
2015 | - |
2016 | - cairo_pattern_t* pat; |
2017 | - pat = cairo_pattern_create_linear(0, 0, 0, height); |
2018 | - |
2019 | - PatternAddRGBStop(pat, rgb, 0.0, 0.0); |
2020 | - PatternAddRGBStop(pat, rgb, 0.49, 0.5); |
2021 | - PatternAddRGBStop(pat, rgb, 0.49, 0.5); |
2022 | - PatternAddRGBStop(pat, rgb, 1.0, 0.0); |
2023 | - |
2024 | - cairo_set_source(cr, pat); |
2025 | - cairo_pattern_destroy(pat); |
2026 | - |
2027 | - DrawGrip(cr, width/2 - offset, grip_y, grip_width, grip_height); |
2028 | - DrawGrip(cr, width/2 - offset, height/2 + (grip_y - 10), grip_width, grip_height); |
2029 | - |
2030 | - cairo_fill(cr); |
2031 | -} |
2032 | - |
2033 | -void DrawLineSeperator(cairo_t* cr, nux::color::RedGreenBlue const& top, |
2034 | - nux::color::RedGreenBlue const& bottom, int width, int height) |
2035 | -{ |
2036 | - int const offset = 1.5; |
2037 | - |
2038 | - // Top |
2039 | - cairo_move_to(cr, offset, height/2); |
2040 | - cairo_line_to(cr, width - offset, height/2); |
2041 | - SetSourceRGB(cr, top, 0.36); |
2042 | - cairo_stroke(cr); |
2043 | - |
2044 | - // Bottom |
2045 | - cairo_move_to(cr, offset, 1 + height/2); |
2046 | - cairo_line_to(cr, width - offset, 1 + height/2); |
2047 | - SetSourceRGB(cr, bottom, 0.5); |
2048 | - cairo_stroke(cr); |
2049 | -} |
2050 | - |
2051 | - |
2052 | -void DrawArrow(cairo_t* cr, nux::color::RedGreenBlue const& rgb, double x, double y, double width, double height) |
2053 | -{ |
2054 | - cairo_save (cr); |
2055 | - |
2056 | - cairo_translate (cr, x, y); |
2057 | - cairo_move_to (cr, -width / 2, -height / 2); |
2058 | - cairo_line_to (cr, 0, height / 2); |
2059 | - cairo_line_to (cr, width / 2, -height / 2); |
2060 | - cairo_close_path (cr); |
2061 | - |
2062 | - SetSourceRGB(cr, rgb, 0.75); |
2063 | - cairo_fill_preserve (cr); |
2064 | - |
2065 | - SetSourceRGB(cr, rgb, 1.0); |
2066 | - cairo_stroke (cr); |
2067 | - |
2068 | - cairo_restore (cr); |
2069 | -} |
2070 | - |
2071 | -void DrawBothArrows(cairo_t* cr, nux::color::RedGreenBlue const& rgb, int width, int height) |
2072 | -{ |
2073 | - int const arrow_width = 5; |
2074 | - int const arrow_height = 3; |
2075 | - float const trans_height = 8.5; |
2076 | - float const offset_x = 0.5; |
2077 | - |
2078 | - // Top |
2079 | - cairo_save(cr); |
2080 | - cairo_translate(cr, width/2 + offset_x, trans_height); |
2081 | - cairo_rotate(cr, G_PI); |
2082 | - DrawArrow(cr, rgb, offset_x, 0, arrow_width, arrow_height); |
2083 | - cairo_restore(cr); |
2084 | - |
2085 | - // Bottom |
2086 | - cairo_save(cr); |
2087 | - cairo_translate(cr, width/2 + offset_x, height - trans_height); |
2088 | - cairo_rotate(cr, 0); |
2089 | - DrawArrow(cr, rgb, -offset_x, 0, arrow_width, arrow_height); |
2090 | - cairo_restore(cr); |
2091 | -} |
2092 | - |
2093 | -void VScrollBarOverlayWindow::UpdateTexture() |
2094 | -{ |
2095 | - int width = THUMB_WIDTH; |
2096 | - int height = THUMB_HEIGHT; |
2097 | - |
2098 | - float const aspect = 1.0f; |
2099 | - float current_x = 0.0f; |
2100 | - float current_y = 0.0f; |
2101 | - |
2102 | - auto const& bg = nux::color::WhiteSmoke; |
2103 | - auto const& bg_selected = nux::color::White; |
2104 | - auto const& bg_active = nux::color::Gray; |
2105 | - auto const& arrow_color = nux::color::DarkSlateGray; |
2106 | - |
2107 | - auto const& bg_arrow_up = ProduceColorShade(bg, 0.86); |
2108 | - auto const& bg_arrow_down = ProduceColorShade(bg, 1.1); |
2109 | - auto const& bg_shadow = ProduceColorShade(bg, 0.2); |
2110 | - |
2111 | - auto const& bg_dark_line = ProduceColorShade(bg, 0.4); |
2112 | - auto const& bg_bright_line = ProduceColorShade(bg, 1.2); |
2113 | - |
2114 | - nux::CairoGraphics cairoGraphics(CAIRO_FORMAT_ARGB32, THUMB_WIDTH.CP(scale), THUMB_HEIGHT.CP(scale)); |
2115 | - cairo_t* cr = cairoGraphics.GetInternalContext(); |
2116 | - cairo_surface_set_device_scale(cairo_get_target(cr), scale, scale); |
2117 | - |
2118 | - cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR); |
2119 | - cairo_paint(cr); |
2120 | - |
2121 | - cairo_translate (cr, 0.5, 0.5); |
2122 | - width--; |
2123 | - height--; |
2124 | - |
2125 | - cairo_set_line_width (cr, 1.0); |
2126 | - |
2127 | - cairo_set_operator(cr, CAIRO_OPERATOR_OVER); |
2128 | - |
2129 | - // Draw backgound |
2130 | - SetSourceRGB(cr, bg, 1.0); |
2131 | - cairoGraphics.DrawRoundedRectangle(cr, aspect, current_x, current_y, THUMB_RADIUS, width, height); |
2132 | - cairo_fill_preserve(cr); |
2133 | - |
2134 | - // Draw shaded background |
2135 | - cairo_pattern_t* pat = cairo_pattern_create_linear(0, 0, 0, height); |
2136 | - |
2137 | - PatternAddRGBStop(pat, bg_arrow_up, 0.0, 0.8); |
2138 | - PatternAddRGBStop(pat, bg_arrow_down, 1.0, 0.8); |
2139 | - |
2140 | - cairo_set_source(cr, pat); |
2141 | - cairo_pattern_destroy(pat); |
2142 | - |
2143 | - if (current_action_ == ThumbAction::DRAGGING) |
2144 | - { |
2145 | - cairo_fill_preserve(cr); |
2146 | - SetSourceRGB(cr, bg, 0.8); |
2147 | - cairo_fill(cr); |
2148 | - } |
2149 | - else |
2150 | - { |
2151 | - cairo_fill(cr); |
2152 | - } |
2153 | - |
2154 | - // Draw Page Up/Down Action |
2155 | - if (current_action_ == ThumbAction::PAGE_UP || |
2156 | - current_action_ == ThumbAction::PAGE_DOWN) |
2157 | - { |
2158 | - if (current_action_ == ThumbAction::PAGE_UP) |
2159 | - cairo_rectangle(cr, 0, 0, width, height/2); |
2160 | - else |
2161 | - cairo_rectangle(cr, 0, height/2, width, height/2); |
2162 | - |
2163 | - SetSourceRGB(cr, bg, 0.8); |
2164 | - cairo_fill(cr); |
2165 | - } |
2166 | - |
2167 | - cairo_save(cr); |
2168 | - |
2169 | - // Draw Outline |
2170 | - cairo_set_line_width (cr, 2.0); |
2171 | - |
2172 | - current_x += 0.5; |
2173 | - current_y += 0.5; |
2174 | - cairoGraphics.DrawRoundedRectangle(cr, aspect, current_x, current_y, THUMB_RADIUS - 1, width - 1, height - 1); |
2175 | - |
2176 | - if (HasState(ThumbState::INSIDE_SLIDER)) |
2177 | - SetSourceRGB(cr, bg_selected, 1.0); |
2178 | - else |
2179 | - SetSourceRGB(cr, bg_active, 0.9); |
2180 | - |
2181 | - cairo_stroke(cr); |
2182 | - |
2183 | - cairo_restore(cr); |
2184 | - |
2185 | - // Draw shade outline |
2186 | - pat = cairo_pattern_create_linear(0, 0, 0, height); |
2187 | - |
2188 | - PatternAddRGBStop(pat, bg_shadow, 0.5, 0.06); |
2189 | - |
2190 | - switch(current_action_) |
2191 | - { |
2192 | - case ThumbAction::NONE: |
2193 | - PatternAddRGBStop(pat, bg_shadow, 0.0, 0.22); |
2194 | - PatternAddRGBStop(pat, bg_shadow, 1.0, 0.22); |
2195 | - break; |
2196 | - case ThumbAction::DRAGGING: |
2197 | - PatternAddRGBStop(pat, bg_shadow, 0.0, 0.2); |
2198 | - PatternAddRGBStop(pat, bg_shadow, 1.0, 0.2); |
2199 | - break; |
2200 | - case ThumbAction::PAGE_UP: |
2201 | - PatternAddRGBStop(pat, bg_shadow, 0.0, 0.1); |
2202 | - PatternAddRGBStop(pat, bg_shadow, 1.0, 0.22); |
2203 | - break; |
2204 | - case ThumbAction::PAGE_DOWN: |
2205 | - PatternAddRGBStop(pat, bg_shadow, 0.0, 0.22); |
2206 | - PatternAddRGBStop(pat, bg_shadow, 1.0, 0.1); |
2207 | - break; |
2208 | - default: |
2209 | - break; |
2210 | - } |
2211 | - |
2212 | - cairo_set_source(cr, pat); |
2213 | - cairo_pattern_destroy(pat); |
2214 | - |
2215 | - current_x += 0.5; |
2216 | - current_y += 0.5; |
2217 | - cairoGraphics.DrawRoundedRectangle(cr, aspect, current_x, current_y, THUMB_RADIUS, width- 2, height - 2); |
2218 | - cairo_stroke(cr); |
2219 | - |
2220 | - current_x += 1.0; |
2221 | - current_y += 1.0; |
2222 | - cairoGraphics.DrawRoundedRectangle(cr, aspect, current_x, current_y, THUMB_RADIUS - 1, width - 4, height- 4); |
2223 | - SetSourceRGB(cr, bg_bright_line, 0.6); |
2224 | - cairo_stroke(cr); |
2225 | - |
2226 | - DrawBothGrips(cr, bg_dark_line, width, height); |
2227 | - DrawLineSeperator(cr, bg_dark_line, bg_bright_line, width, height); |
2228 | - DrawBothArrows(cr, arrow_color, width, height); |
2229 | - |
2230 | - thumb_texture_ = texture_ptr_from_cairo_graphics(cairoGraphics); |
2231 | - |
2232 | - QueueDraw(); |
2233 | -} |
2234 | - |
2235 | -} // namespace unity |
2236 | |
2237 | === removed file 'unity-shared/VScrollBarOverlayWindow.h' |
2238 | --- unity-shared/VScrollBarOverlayWindow.h 2014-07-11 20:04:06 +0000 |
2239 | +++ unity-shared/VScrollBarOverlayWindow.h 1970-01-01 00:00:00 +0000 |
2240 | @@ -1,114 +0,0 @@ |
2241 | -// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- |
2242 | -/* |
2243 | - * Copyright (C) 2012 Canonical Ltd |
2244 | - * |
2245 | - * This program is free software: you can redistribute it and/or modify |
2246 | - * it under the terms of the GNU General Public License version 3 as |
2247 | - * published by the Free Software Foundation. |
2248 | - * |
2249 | - * This program is distributed in the hope that it will be useful, |
2250 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
2251 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
2252 | - * GNU General Public License for more details. |
2253 | - * |
2254 | - * You should have received a copy of the GNU General Public License |
2255 | - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
2256 | - * |
2257 | - * Authored by: Brandon Schaefer <brandon.schaefer@canonical.com> |
2258 | - */ |
2259 | - |
2260 | - |
2261 | -#ifndef VSCROLLBAR_OVERLAY_WINDOW_H |
2262 | -#define VSCROLLBAR_OVERLAY_WINDOW_H |
2263 | - |
2264 | -#include <Nux/Nux.h> |
2265 | -#include <Nux/BaseWindow.h> |
2266 | -#include <NuxCore/Animation.h> |
2267 | - |
2268 | -namespace unity |
2269 | -{ |
2270 | - |
2271 | -class VScrollBarOverlayWindow : public nux::BaseWindow |
2272 | -{ |
2273 | -public: |
2274 | - VScrollBarOverlayWindow(nux::Geometry const& geo); |
2275 | - |
2276 | - nux::Property<double> scale; |
2277 | - |
2278 | - void UpdateGeometry(nux::Geometry const& geo); |
2279 | - void SetThumbOffsetY(int y); |
2280 | - |
2281 | - void MouseDown(); |
2282 | - void MouseUp(); |
2283 | - |
2284 | - void MouseNear(); |
2285 | - void MouseBeyond(); |
2286 | - |
2287 | - void MouseEnter(); |
2288 | - void MouseLeave(); |
2289 | - |
2290 | - void ThumbInsideSlider(); |
2291 | - void ThumbOutsideSlider(); |
2292 | - |
2293 | - void PageUpAction(); |
2294 | - void PageDownAction(); |
2295 | - |
2296 | - bool IsMouseInsideThumb(int y) const; |
2297 | - bool IsMouseBeingDragged() const; |
2298 | - |
2299 | - int GetThumbHeight() const; |
2300 | - int GetThumbOffsetY() const; |
2301 | - |
2302 | - nux::Geometry GetThumbGeometry() const; |
2303 | - |
2304 | - void ResetStates(); |
2305 | - |
2306 | -protected: |
2307 | - virtual void Draw(nux::GraphicsEngine& graphics_engine, bool force_draw); |
2308 | - |
2309 | -private: |
2310 | - enum class ThumbAction : unsigned int |
2311 | - { |
2312 | - NONE, |
2313 | - DRAGGING, |
2314 | - PAGE_UP, |
2315 | - PAGE_DOWN |
2316 | - }; |
2317 | - |
2318 | - enum ThumbState |
2319 | - { |
2320 | - NONE = 1 << 0, |
2321 | - MOUSE_DOWN = 1 << 1, |
2322 | - MOUSE_NEAR = 1 << 2, |
2323 | - MOUSE_INSIDE = 1 << 3, |
2324 | - INSIDE_SLIDER = 1 << 4 |
2325 | - }; |
2326 | - |
2327 | - void MouseDragging(); |
2328 | - void UpdateMouseOffsetX(); |
2329 | - void UpdateContentGeometry(); |
2330 | - int GetValidOffsetYValue(int y) const; |
2331 | - |
2332 | - void ShouldShow(); |
2333 | - void ShouldHide(); |
2334 | - |
2335 | - void UpdateTexture(); |
2336 | - |
2337 | - nux::Geometry content_size_; |
2338 | - nux::ObjectPtr<nux::BaseTexture> thumb_texture_; |
2339 | - |
2340 | - int content_offset_x_; |
2341 | - int mouse_offset_y_; |
2342 | - |
2343 | - void AddState(ThumbState const& state); |
2344 | - void RemoveState(ThumbState const& state); |
2345 | - bool HasState(ThumbState const& state) const; |
2346 | - |
2347 | - unsigned int current_state_; |
2348 | - ThumbAction current_action_; |
2349 | - nux::animation::AnimateValue<double> show_animator_; |
2350 | -}; |
2351 | - |
2352 | -} // namespace unity |
2353 | - |
2354 | -#endif // VSCROLLBAR_OVERLAY_WINDOW_H |
FAILED: Continuous integration, rev:4019 jenkins. qa.ubuntu. com/job/ unity-ci/ 1345/ jenkins. qa.ubuntu. com/job/ unity-wily- amd64-ci/ 122 jenkins. qa.ubuntu. com/job/ unity-wily- armhf-ci/ 121 jenkins. qa.ubuntu. com/job/ unity-wily- i386-ci/ 120/console
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
FAILURE: http://
Click here to trigger a rebuild: s-jenkins. ubuntu- ci:8080/ job/unity- ci/1345/ rebuild
http://