Merge lp:~brandontschaefer/unity/lp608124-overlay-scrollbar-dash into lp:unity
- lp608124-overlay-scrollbar-dash
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | Brandon Schaefer |
Approved revision: | no longer in the source branch. |
Merged at revision: | 2928 |
Proposed branch: | lp:~brandontschaefer/unity/lp608124-overlay-scrollbar-dash |
Merge into: | lp:unity |
Diff against target: |
1700 lines (+1459/-15) 14 files modified
dash/DashView.cpp (+10/-3) dash/LensView.cpp (+14/-2) dash/previews/ApplicationPreview.cpp (+2/-2) dash/previews/GenericPreview.cpp (+2/-2) dash/previews/MoviePreview.cpp (+2/-2) dash/previews/SocialPreview.cpp (+2/-2) dash/previews/Tracks.cpp (+2/-2) tests/CMakeLists.txt (+1/-0) tests/test_overlay_scrollbar.cpp (+280/-0) unity-shared/CMakeLists.txt (+2/-0) unity-shared/PlacesOverlayVScrollBar.cpp (+417/-0) unity-shared/PlacesOverlayVScrollBar.h (+107/-0) unity-shared/VScrollBarOverlayWindow.cpp (+526/-0) unity-shared/VScrollBarOverlayWindow.h (+92/-0) |
To merge this branch: | bzr merge lp:~brandontschaefer/unity/lp608124-overlay-scrollbar-dash |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Marco Trevisan (Treviño) | Approve | ||
John Lea (community) | design | Approve | |
PS Jenkins bot | continuous-integration | Pending | |
Review via email: mp+134211@code.launchpad.net |
Commit message
Add an overlay scroll bar thumb that allows you to control the scroll bars in the dash.
Description of the change
=== Problem ===
The scroll bars in the dash are hard to grab because they are to thin.
=== Fix ===
Add an overlay scroll bar thumb that allows you to control the scroll bar. (Check out the video for more detail.)
New video showing off the overlay scrollbars:
http://
Video showing the connector.
http://
Three pixel wide connector...(Video is 2 pixels wide)
http://
Depends on this nux branch:
https:/
This branch fixes the problem when you mouse to quickly off the dash leaving the overlay thumb visible.
https:/
=== Test ===
Unit tests
Marco Trevisan (Treviño) (3v1n0) wrote : | # |
Stephen M. Webb (bregma) wrote : | # |
480 + _overlay_window = new VScrollBarOverl
Why can't this member be initialized in the initialization list?
507 + _overlay_
Does this not happen automatically? Is this going to mess up the refcount?
516 + _animation.
What is magic about 400?
656 + if (y < (thumb_height/2 + thumb_offset_y))
657 + return true;
658 +
659 + return false;
Or maybe "return y < (thumb_height/2 + thumb_offset_y)"?
1044 + const nux::Color& color = nux::color::White;
1122 + DrawGrip(cr, width/2 - 6.5, 13.5, 5, 6);
1123 + DrawGrip(cr, width/2 - 6.5, height/2 + 3.5, 5, 6);
Magic, everywhere. Are those pixels? Millimetres? Points? Ems? Will they
look as good on a 72 dpi screen as on a 300 dpi screen?
Same goes for a lot of the magic numbers used to generate color variants,
offsets, and sizes.
John Lea (johnlea) wrote : | # |
*almost* there, looking very good ;-) Other than one missing element it looks perfect!
The missing element is the 'connector' between the scrollbar and the thumb that should appear and connect the scrollbar and the thumb together when these two elements are not otherwise attached.
If you need any further visual designs contact Otto, I spoke to him a moment ago and he said that you discussed with him at UDS using a very light semi-transparent line as the connector.
Also ping me on IRC if you can't get in touch with Otto or have any other questions.
cheers,
John
Brandon Schaefer (brandontschaefer) wrote : | # |
Thank you for looking at it! I was using xchat as a reference and it seems to be missing that 'connector'. Ill get to working on that :).
I thought Otto and I talked about the outline of the thumb is self, which would refelct the color of the 'connector' I just missed the connector part!
Brandon Schaefer (brandontschaefer) wrote : | # |
@John
Video showing the connector.
http://
The connector is 2 pixels wide in the video because that matches up with the thumbs outline...though the slider is 3 pixels wide. Should it be left at 2?
John Lea (johnlea) wrote : | # |
Reviewed latest video showing connector, looks good, design wise approved ;-)
Andrea Azzarone (azzar1) wrote : | # |
+ OnVisibleChange
I'd prefert to comment out area here so: nux::Area* /*area*/, bool visible.
576 + , _overlay_window(new VScrollBarOverl
577 + , _area_prox(
578 + , _thumb_
579 + , _connector_
580 + , _mouse_
For new files please use the new style member_variable_ :)
+void PlacesOverlayVS
Comment out area and geo.
622 + _animation.
623 + _animation.
624 +
625 + _animation.
626 + _animation.
627 +
628 + StartScrollAnim
Maybe you can move 622..627 in a new function so you have:
SetupScrollAn
StartScrollAn
But if you don't like it's ok :)
Sometimes you use this condition (content_height_ > container_height_)
I'd move this condition in a readable function (something like IsVScrollbarActive, but I'm sure you'll find a better name :)
+ _overlay_
I'm sure this 4 is not a magic number but it's not so easy to get its purpose.
Marco Trevisan (Treviño) (3v1n0) wrote : | # |
Looks very good both code-wise and result-wise... Awesome work, approving it! :)
Marco Trevisan (Treviño) (3v1n0) wrote : | # |
623 +void PlacesOverlayVS
624 +{
625 + if (animation_
626 + animation_.Stop();
627 +}
This shouldn't be needed, since animation_.Stop() already does that check...
Preview Diff
1 | === modified file 'dash/DashView.cpp' | |||
2 | --- dash/DashView.cpp 2012-11-19 18:54:19 +0000 | |||
3 | +++ dash/DashView.cpp 2012-11-23 23:52:20 +0000 | |||
4 | @@ -166,6 +166,7 @@ | |||
5 | 166 | 166 | ||
6 | 167 | preview_navigation_mode_ = previews::Navigation::NONE; | 167 | preview_navigation_mode_ = previews::Navigation::NONE; |
7 | 168 | preview_displaying_ = false; | 168 | preview_displaying_ = false; |
8 | 169 | active_lens_view_->SetVisible(true); | ||
9 | 169 | 170 | ||
10 | 170 | // re-focus dash view component. | 171 | // re-focus dash view component. |
11 | 171 | nux::GetWindowCompositor().SetKeyFocusArea(default_focus()); | 172 | nux::GetWindowCompositor().SetKeyFocusArea(default_focus()); |
12 | @@ -269,6 +270,7 @@ | |||
13 | 269 | 270 | ||
14 | 270 | preview_container_->SetGeometry(layout_->GetGeometry()); | 271 | preview_container_->SetGeometry(layout_->GetGeometry()); |
15 | 271 | preview_displaying_ = true; | 272 | preview_displaying_ = true; |
16 | 273 | active_lens_view_->SetVisible(false); | ||
17 | 272 | 274 | ||
18 | 273 | // connect to nav left/right signals to request nav left/right movement. | 275 | // connect to nav left/right signals to request nav left/right movement. |
19 | 274 | preview_container_->navigate_left.connect([&] () { | 276 | preview_container_->navigate_left.connect([&] () { |
20 | @@ -328,18 +330,19 @@ | |||
21 | 328 | LOG_DEBUG(logger) << "Setting ViewType " << ViewType::LENS_VIEW | 330 | LOG_DEBUG(logger) << "Setting ViewType " << ViewType::LENS_VIEW |
22 | 329 | << " on '" << home_lens_->id() << "'"; | 331 | << " on '" << home_lens_->id() << "'"; |
23 | 330 | } | 332 | } |
25 | 331 | else if (active_lens_view_) | 333 | else |
26 | 332 | { | 334 | { |
27 | 333 | // careful here, the lens_view's view_type doesn't get reset when the dash | 335 | // careful here, the lens_view's view_type doesn't get reset when the dash |
28 | 334 | // hides, but lens' view_type does, so we need to update the lens directly | 336 | // hides, but lens' view_type does, so we need to update the lens directly |
29 | 335 | active_lens_view_->lens()->view_type = ViewType::LENS_VIEW; | 337 | active_lens_view_->lens()->view_type = ViewType::LENS_VIEW; |
30 | 336 | } | 338 | } |
31 | 339 | active_lens_view_->SetVisible(true); | ||
32 | 337 | 340 | ||
33 | 338 | // this will make sure the spinner animates if the search takes a while | 341 | // this will make sure the spinner animates if the search takes a while |
34 | 339 | search_bar_->ForceSearchChanged(); | 342 | search_bar_->ForceSearchChanged(); |
35 | 340 | 343 | ||
36 | 341 | // if a preview is open, close it | 344 | // if a preview is open, close it |
38 | 342 | if (preview_displaying_) | 345 | if (preview_displaying_) |
39 | 343 | { | 346 | { |
40 | 344 | ClosePreview(); | 347 | ClosePreview(); |
41 | 345 | } | 348 | } |
42 | @@ -363,8 +366,10 @@ | |||
43 | 363 | LOG_DEBUG(logger) << "Setting ViewType " << ViewType::HIDDEN | 366 | LOG_DEBUG(logger) << "Setting ViewType " << ViewType::HIDDEN |
44 | 364 | << " on '" << home_lens_->id() << "'"; | 367 | << " on '" << home_lens_->id() << "'"; |
45 | 365 | 368 | ||
46 | 369 | active_lens_view_->SetVisible(false); | ||
47 | 370 | |||
48 | 366 | // if a preview is open, close it | 371 | // if a preview is open, close it |
50 | 367 | if (preview_displaying_) | 372 | if (preview_displaying_) |
51 | 368 | { | 373 | { |
52 | 369 | ClosePreview(); | 374 | ClosePreview(); |
53 | 370 | } | 375 | } |
54 | @@ -967,6 +972,8 @@ | |||
55 | 967 | return; | 972 | return; |
56 | 968 | } | 973 | } |
57 | 969 | 974 | ||
58 | 975 | lens_views_[id]->SetVisible(true); | ||
59 | 976 | active_lens_view_->SetVisible(false); | ||
60 | 970 | LensView* view = active_lens_view_ = lens_views_[id]; | 977 | LensView* view = active_lens_view_ = lens_views_[id]; |
61 | 971 | view->JumpToTop(); | 978 | view->JumpToTop(); |
62 | 972 | 979 | ||
63 | 973 | 980 | ||
64 | === modified file 'dash/LensView.cpp' | |||
65 | --- dash/LensView.cpp 2012-11-19 18:54:19 +0000 | |||
66 | +++ dash/LensView.cpp 2012-11-23 23:52:20 +0000 | |||
67 | @@ -33,6 +33,7 @@ | |||
68 | 33 | #include "unity-shared/UBusMessages.h" | 33 | #include "unity-shared/UBusMessages.h" |
69 | 34 | #include "unity-shared/UBusWrapper.h" | 34 | #include "unity-shared/UBusWrapper.h" |
70 | 35 | #include "unity-shared/PlacesVScrollBar.h" | 35 | #include "unity-shared/PlacesVScrollBar.h" |
71 | 36 | #include "unity-shared/PlacesOverlayVScrollBar.h" | ||
72 | 36 | 37 | ||
73 | 37 | #include <glib/gi18n-lib.h> | 38 | #include <glib/gi18n-lib.h> |
74 | 38 | 39 | ||
75 | @@ -57,6 +58,13 @@ | |||
76 | 57 | , up_area_(nullptr) | 58 | , up_area_(nullptr) |
77 | 58 | { | 59 | { |
78 | 59 | SetVScrollBar(scroll_bar); | 60 | SetVScrollBar(scroll_bar); |
79 | 61 | |||
80 | 62 | OnVisibleChanged.connect([&] (nux::Area* /*area*/, bool visible) { | ||
81 | 63 | if (m_horizontal_scrollbar_enable) | ||
82 | 64 | _hscrollbar->SetVisible(visible); | ||
83 | 65 | if (m_vertical_scrollbar_enable) | ||
84 | 66 | _vscrollbar->SetVisible(visible); | ||
85 | 67 | }); | ||
86 | 60 | } | 68 | } |
87 | 61 | 69 | ||
88 | 62 | void ScrollToPosition(nux::Geometry const& position) | 70 | void ScrollToPosition(nux::Geometry const& position) |
89 | @@ -192,6 +200,10 @@ | |||
90 | 192 | } | 200 | } |
91 | 193 | }); | 201 | }); |
92 | 194 | 202 | ||
93 | 203 | OnVisibleChanged.connect([&] (nux::Area* area, bool visible) { | ||
94 | 204 | scroll_view_->SetVisible(visible); | ||
95 | 205 | }); | ||
96 | 206 | |||
97 | 195 | } | 207 | } |
98 | 196 | 208 | ||
99 | 197 | void LensView::SetupViews(nux::Area* show_filters) | 209 | void LensView::SetupViews(nux::Area* show_filters) |
100 | @@ -201,9 +213,9 @@ | |||
101 | 201 | layout_ = new nux::HLayout(NUX_TRACKER_LOCATION); | 213 | layout_ = new nux::HLayout(NUX_TRACKER_LOCATION); |
102 | 202 | layout_->SetSpaceBetweenChildren(style.GetSpaceBetweenLensAndFilters()); | 214 | layout_->SetSpaceBetweenChildren(style.GetSpaceBetweenLensAndFilters()); |
103 | 203 | 215 | ||
105 | 204 | scroll_view_ = new LensScrollView(new PlacesVScrollBar(NUX_TRACKER_LOCATION), | 216 | scroll_view_ = new LensScrollView(new PlacesOverlayVScrollBar(NUX_TRACKER_LOCATION), |
106 | 205 | NUX_TRACKER_LOCATION); | 217 | NUX_TRACKER_LOCATION); |
108 | 206 | scroll_view_->EnableVerticalScrollBar(false); | 218 | scroll_view_->EnableVerticalScrollBar(true); |
109 | 207 | scroll_view_->EnableHorizontalScrollBar(false); | 219 | scroll_view_->EnableHorizontalScrollBar(false); |
110 | 208 | layout_->AddView(scroll_view_); | 220 | layout_->AddView(scroll_view_); |
111 | 209 | 221 | ||
112 | 210 | 222 | ||
113 | === modified file 'dash/previews/ApplicationPreview.cpp' | |||
114 | --- dash/previews/ApplicationPreview.cpp 2012-10-29 09:34:54 +0000 | |||
115 | +++ dash/previews/ApplicationPreview.cpp 2012-11-23 23:52:20 +0000 | |||
116 | @@ -25,7 +25,7 @@ | |||
117 | 25 | #include "unity-shared/CoverArt.h" | 25 | #include "unity-shared/CoverArt.h" |
118 | 26 | #include "unity-shared/IconTexture.h" | 26 | #include "unity-shared/IconTexture.h" |
119 | 27 | #include "unity-shared/StaticCairoText.h" | 27 | #include "unity-shared/StaticCairoText.h" |
121 | 28 | #include "unity-shared/PlacesVScrollBar.h" | 28 | #include "unity-shared/PlacesOverlayVScrollBar.h" |
122 | 29 | #include <UnityCore/ApplicationPreview.h> | 29 | #include <UnityCore/ApplicationPreview.h> |
123 | 30 | #include <NuxCore/Logger.h> | 30 | #include <NuxCore/Logger.h> |
124 | 31 | #include <Nux/HLayout.h> | 31 | #include <Nux/HLayout.h> |
125 | @@ -54,7 +54,7 @@ | |||
126 | 54 | DetailsScrollView(NUX_FILE_LINE_PROTO) | 54 | DetailsScrollView(NUX_FILE_LINE_PROTO) |
127 | 55 | : ScrollView(NUX_FILE_LINE_PARAM) | 55 | : ScrollView(NUX_FILE_LINE_PARAM) |
128 | 56 | { | 56 | { |
130 | 57 | SetVScrollBar(new dash::PlacesVScrollBar(NUX_TRACKER_LOCATION)); | 57 | SetVScrollBar(new dash::PlacesOverlayVScrollBar(NUX_TRACKER_LOCATION)); |
131 | 58 | } | 58 | } |
132 | 59 | 59 | ||
133 | 60 | }; | 60 | }; |
134 | 61 | 61 | ||
135 | === modified file 'dash/previews/GenericPreview.cpp' | |||
136 | --- dash/previews/GenericPreview.cpp 2012-10-29 09:34:54 +0000 | |||
137 | +++ dash/previews/GenericPreview.cpp 2012-11-23 23:52:20 +0000 | |||
138 | @@ -24,7 +24,7 @@ | |||
139 | 24 | #include "unity-shared/PreviewStyle.h" | 24 | #include "unity-shared/PreviewStyle.h" |
140 | 25 | #include "unity-shared/CoverArt.h" | 25 | #include "unity-shared/CoverArt.h" |
141 | 26 | #include "unity-shared/StaticCairoText.h" | 26 | #include "unity-shared/StaticCairoText.h" |
143 | 27 | #include "unity-shared/PlacesVScrollBar.h" | 27 | #include "unity-shared/PlacesOverlayVScrollBar.h" |
144 | 28 | #include <NuxCore/Logger.h> | 28 | #include <NuxCore/Logger.h> |
145 | 29 | #include <Nux/HLayout.h> | 29 | #include <Nux/HLayout.h> |
146 | 30 | #include <Nux/VLayout.h> | 30 | #include <Nux/VLayout.h> |
147 | @@ -49,7 +49,7 @@ | |||
148 | 49 | DetailsScrollView(NUX_FILE_LINE_PROTO) | 49 | DetailsScrollView(NUX_FILE_LINE_PROTO) |
149 | 50 | : ScrollView(NUX_FILE_LINE_PARAM) | 50 | : ScrollView(NUX_FILE_LINE_PARAM) |
150 | 51 | { | 51 | { |
152 | 52 | SetVScrollBar(new dash::PlacesVScrollBar(NUX_TRACKER_LOCATION)); | 52 | SetVScrollBar(new dash::PlacesOverlayVScrollBar(NUX_TRACKER_LOCATION)); |
153 | 53 | } | 53 | } |
154 | 54 | 54 | ||
155 | 55 | }; | 55 | }; |
156 | 56 | 56 | ||
157 | === modified file 'dash/previews/MoviePreview.cpp' | |||
158 | --- dash/previews/MoviePreview.cpp 2012-10-29 09:34:54 +0000 | |||
159 | +++ dash/previews/MoviePreview.cpp 2012-11-23 23:52:20 +0000 | |||
160 | @@ -24,7 +24,7 @@ | |||
161 | 24 | #include "unity-shared/PreviewStyle.h" | 24 | #include "unity-shared/PreviewStyle.h" |
162 | 25 | #include "unity-shared/CoverArt.h" | 25 | #include "unity-shared/CoverArt.h" |
163 | 26 | #include "unity-shared/StaticCairoText.h" | 26 | #include "unity-shared/StaticCairoText.h" |
165 | 27 | #include "unity-shared/PlacesVScrollBar.h" | 27 | #include "unity-shared/PlacesOverlayVScrollBar.h" |
166 | 28 | #include <UnityCore/MoviePreview.h> | 28 | #include <UnityCore/MoviePreview.h> |
167 | 29 | #include <NuxCore/Logger.h> | 29 | #include <NuxCore/Logger.h> |
168 | 30 | #include <Nux/HLayout.h> | 30 | #include <Nux/HLayout.h> |
169 | @@ -50,7 +50,7 @@ | |||
170 | 50 | DetailsScrollView(NUX_FILE_LINE_PROTO) | 50 | DetailsScrollView(NUX_FILE_LINE_PROTO) |
171 | 51 | : ScrollView(NUX_FILE_LINE_PARAM) | 51 | : ScrollView(NUX_FILE_LINE_PARAM) |
172 | 52 | { | 52 | { |
174 | 53 | SetVScrollBar(new dash::PlacesVScrollBar(NUX_TRACKER_LOCATION)); | 53 | SetVScrollBar(new dash::PlacesOverlayVScrollBar(NUX_TRACKER_LOCATION)); |
175 | 54 | } | 54 | } |
176 | 55 | 55 | ||
177 | 56 | }; | 56 | }; |
178 | 57 | 57 | ||
179 | === modified file 'dash/previews/SocialPreview.cpp' | |||
180 | --- dash/previews/SocialPreview.cpp 2012-11-08 09:12:24 +0000 | |||
181 | +++ dash/previews/SocialPreview.cpp 2012-11-23 23:52:20 +0000 | |||
182 | @@ -25,7 +25,7 @@ | |||
183 | 25 | #include "unity-shared/CoverArt.h" | 25 | #include "unity-shared/CoverArt.h" |
184 | 26 | #include "unity-shared/IconTexture.h" | 26 | #include "unity-shared/IconTexture.h" |
185 | 27 | #include "unity-shared/StaticCairoText.h" | 27 | #include "unity-shared/StaticCairoText.h" |
187 | 28 | #include "unity-shared/PlacesVScrollBar.h" | 28 | #include "unity-shared/PlacesOverlayVScrollBar.h" |
188 | 29 | #include <UnityCore/SocialPreview.h> | 29 | #include <UnityCore/SocialPreview.h> |
189 | 30 | #include <NuxCore/Logger.h> | 30 | #include <NuxCore/Logger.h> |
190 | 31 | #include <Nux/HLayout.h> | 31 | #include <Nux/HLayout.h> |
191 | @@ -54,7 +54,7 @@ | |||
192 | 54 | DetailsScrollView(NUX_FILE_LINE_PROTO) | 54 | DetailsScrollView(NUX_FILE_LINE_PROTO) |
193 | 55 | : ScrollView(NUX_FILE_LINE_PARAM) | 55 | : ScrollView(NUX_FILE_LINE_PARAM) |
194 | 56 | { | 56 | { |
196 | 57 | SetVScrollBar(new dash::PlacesVScrollBar(NUX_TRACKER_LOCATION)); | 57 | SetVScrollBar(new dash::PlacesOverlayVScrollBar(NUX_TRACKER_LOCATION)); |
197 | 58 | } | 58 | } |
198 | 59 | 59 | ||
199 | 60 | }; | 60 | }; |
200 | 61 | 61 | ||
201 | === modified file 'dash/previews/Tracks.cpp' | |||
202 | --- dash/previews/Tracks.cpp 2012-10-29 09:34:54 +0000 | |||
203 | +++ dash/previews/Tracks.cpp 2012-11-23 23:52:20 +0000 | |||
204 | @@ -24,7 +24,7 @@ | |||
205 | 24 | #include <NuxCore/Logger.h> | 24 | #include <NuxCore/Logger.h> |
206 | 25 | #include <Nux/VLayout.h> | 25 | #include <Nux/VLayout.h> |
207 | 26 | #include "unity-shared/IntrospectableWrappers.h" | 26 | #include "unity-shared/IntrospectableWrappers.h" |
209 | 27 | #include "unity-shared/PlacesVScrollBar.h" | 27 | #include "unity-shared/PlacesOverlayVScrollBar.h" |
210 | 28 | #include "unity-shared/PreviewStyle.h" | 28 | #include "unity-shared/PreviewStyle.h" |
211 | 29 | #include <UnityCore/Track.h> | 29 | #include <UnityCore/Track.h> |
212 | 30 | #include <UnityCore/Variant.h> | 30 | #include <UnityCore/Variant.h> |
213 | @@ -76,7 +76,7 @@ | |||
214 | 76 | 76 | ||
215 | 77 | void Tracks::SetupViews() | 77 | void Tracks::SetupViews() |
216 | 78 | { | 78 | { |
218 | 79 | SetVScrollBar(new dash::PlacesVScrollBar(NUX_TRACKER_LOCATION)); | 79 | SetVScrollBar(new dash::PlacesOverlayVScrollBar(NUX_TRACKER_LOCATION)); |
219 | 80 | EnableHorizontalScrollBar(false); | 80 | EnableHorizontalScrollBar(false); |
220 | 81 | layout_ = new nux::VLayout(); | 81 | layout_ = new nux::VLayout(); |
221 | 82 | layout_->SetPadding(0, previews::Style::Instance().GetDetailsRightMargin(), 0, 0); | 82 | layout_->SetPadding(0, previews::Style::Instance().GetDetailsRightMargin(), 0, 0); |
222 | 83 | 83 | ||
223 | === modified file 'tests/CMakeLists.txt' | |||
224 | --- tests/CMakeLists.txt 2012-11-22 10:08:38 +0000 | |||
225 | +++ tests/CMakeLists.txt 2012-11-23 23:52:20 +0000 | |||
226 | @@ -233,6 +233,7 @@ | |||
227 | 233 | test_previews_movie.cpp | 233 | test_previews_movie.cpp |
228 | 234 | test_previews_music.cpp | 234 | test_previews_music.cpp |
229 | 235 | test_previews_social.cpp | 235 | test_previews_social.cpp |
230 | 236 | test_overlay_scrollbar.cpp | ||
231 | 236 | test_quicklist_menu_item.cpp | 237 | test_quicklist_menu_item.cpp |
232 | 237 | test_quicklist_view.cpp | 238 | test_quicklist_view.cpp |
233 | 238 | test_resultviewgrid.cpp | 239 | test_resultviewgrid.cpp |
234 | 239 | 240 | ||
235 | === added file 'tests/test_overlay_scrollbar.cpp' | |||
236 | --- tests/test_overlay_scrollbar.cpp 1970-01-01 00:00:00 +0000 | |||
237 | +++ tests/test_overlay_scrollbar.cpp 2012-11-23 23:52:20 +0000 | |||
238 | @@ -0,0 +1,280 @@ | |||
239 | 1 | /* | ||
240 | 2 | * Copyright 2012 Canonical Ltd. | ||
241 | 3 | * | ||
242 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
243 | 5 | * under the terms of the GNU Lesser General Public License version 3, as | ||
244 | 6 | * published by the Free Software Foundation. | ||
245 | 7 | * | ||
246 | 8 | * This program is distributed in the hope that it will be useful, but | ||
247 | 9 | * WITHOUT ANY WARRANTY; without even the implied warranties of | ||
248 | 10 | * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR | ||
249 | 11 | * PURPOSE. See the applicable version of the GNU Lesser General Public | ||
250 | 12 | * License for more details. | ||
251 | 13 | * | ||
252 | 14 | * You should have received a copy of both the GNU Lesser General Public | ||
253 | 15 | * License version 3 along with this program. If not, see | ||
254 | 16 | * <http://www.gnu.org/licenses/> | ||
255 | 17 | * | ||
256 | 18 | * Authored by: Brandon Schaefer <brandon.schaefer@canonical.com> | ||
257 | 19 | * | ||
258 | 20 | */ | ||
259 | 21 | |||
260 | 22 | #include <gtest/gtest.h> | ||
261 | 23 | |||
262 | 24 | #include <Nux/Nux.h> | ||
263 | 25 | #include <NuxCore/ObjectPtr.h> | ||
264 | 26 | #include <Nux/VLayout.h> | ||
265 | 27 | |||
266 | 28 | #include "unity-shared/VScrollBarOverlayWindow.h" | ||
267 | 29 | #include "unity-shared/PlacesOverlayVScrollBar.h" | ||
268 | 30 | #include "unity-shared/UScreen.h" | ||
269 | 31 | |||
270 | 32 | using namespace testing; | ||
271 | 33 | |||
272 | 34 | namespace | ||
273 | 35 | { | ||
274 | 36 | |||
275 | 37 | class TestOverlayWindow : public Test | ||
276 | 38 | { | ||
277 | 39 | public: | ||
278 | 40 | TestOverlayWindow() | ||
279 | 41 | { | ||
280 | 42 | overlay_window_ = new VScrollBarOverlayWindow(nux::Geometry(0,0,100,100)); | ||
281 | 43 | } | ||
282 | 44 | |||
283 | 45 | int GetProxListSize() const | ||
284 | 46 | { | ||
285 | 47 | return nux::GetWindowThread()->GetWindowCompositor().GetProximityListSize(); | ||
286 | 48 | } | ||
287 | 49 | |||
288 | 50 | nux::ObjectPtr<VScrollBarOverlayWindow> overlay_window_; | ||
289 | 51 | }; | ||
290 | 52 | |||
291 | 53 | class TestOverlayScrollBar : public Test | ||
292 | 54 | { | ||
293 | 55 | public: | ||
294 | 56 | class MockScrollBar : public unity::dash::PlacesOverlayVScrollBar | ||
295 | 57 | { | ||
296 | 58 | public: | ||
297 | 59 | MockScrollBar(NUX_FILE_LINE_DECL) | ||
298 | 60 | : unity::dash::PlacesOverlayVScrollBar(NUX_FILE_LINE_PARAM) | ||
299 | 61 | , scroll_dy(0) | ||
300 | 62 | , scroll_up_signal_(false) | ||
301 | 63 | , scroll_down_signal_(false) | ||
302 | 64 | { | ||
303 | 65 | SetGeometry(nux::Geometry(0,0,200,500)); | ||
304 | 66 | SetContainerSize(0,0,200,200); | ||
305 | 67 | SetContentSize(0,0,200,2000); | ||
306 | 68 | ComputeContentSize(); | ||
307 | 69 | |||
308 | 70 | OnScrollUp.connect([&] (float step, int dy) { | ||
309 | 71 | scroll_dy = dy; | ||
310 | 72 | scroll_up_signal_ = true; | ||
311 | 73 | }); | ||
312 | 74 | |||
313 | 75 | OnScrollDown.connect([&] (float step, int dy) { | ||
314 | 76 | scroll_dy = dy; | ||
315 | 77 | scroll_down_signal_ = true; | ||
316 | 78 | }); | ||
317 | 79 | } | ||
318 | 80 | |||
319 | 81 | void ScrollDown(int scroll_dy) | ||
320 | 82 | { | ||
321 | 83 | // Shows we are over the Overlay Thumb | ||
322 | 84 | int x = _track->GetBaseX() + _track->GetBaseWidth() + 5; | ||
323 | 85 | int y = _track->GetBaseY(); | ||
324 | 86 | |||
325 | 87 | MoveMouse(x,y); | ||
326 | 88 | MoveDown(x,y); | ||
327 | 89 | |||
328 | 90 | MoveMouse(x,y+scroll_dy); | ||
329 | 91 | MoveUp(x,y+scroll_dy); | ||
330 | 92 | } | ||
331 | 93 | |||
332 | 94 | void ScrollUp(int scroll_dy) | ||
333 | 95 | { | ||
334 | 96 | ScrollDown(scroll_dy); | ||
335 | 97 | |||
336 | 98 | // Shows we are over the Overlay Thumb | ||
337 | 99 | int x = _track->GetBaseX() + _track->GetBaseWidth() + 5; | ||
338 | 100 | int y = _track->GetBaseY(); | ||
339 | 101 | |||
340 | 102 | MoveMouse(x,y+scroll_dy); | ||
341 | 103 | MoveDown(x,y+scroll_dy); | ||
342 | 104 | |||
343 | 105 | MoveMouse(x,y); | ||
344 | 106 | MoveUp(x,y); | ||
345 | 107 | } | ||
346 | 108 | |||
347 | 109 | void MoveDown(int x, int y) | ||
348 | 110 | { | ||
349 | 111 | nux::Event event; | ||
350 | 112 | event.type = nux::NUX_MOUSE_PRESSED; | ||
351 | 113 | event.x = x; | ||
352 | 114 | event.y = y; | ||
353 | 115 | nux::GetWindowCompositor().ProcessEvent(event); | ||
354 | 116 | } | ||
355 | 117 | |||
356 | 118 | void MoveUp(int x, int y) | ||
357 | 119 | { | ||
358 | 120 | nux::Event event; | ||
359 | 121 | event.type = nux::NUX_MOUSE_RELEASED; | ||
360 | 122 | event.x = x; | ||
361 | 123 | event.y = y; | ||
362 | 124 | nux::GetWindowCompositor().ProcessEvent(event); | ||
363 | 125 | } | ||
364 | 126 | |||
365 | 127 | void MoveMouse(int x, int y) | ||
366 | 128 | { | ||
367 | 129 | nux::Event event; | ||
368 | 130 | event.type = nux::NUX_MOUSE_MOVE; | ||
369 | 131 | event.x = x; | ||
370 | 132 | event.y = y; | ||
371 | 133 | nux::GetWindowCompositor().ProcessEvent(event); | ||
372 | 134 | } | ||
373 | 135 | |||
374 | 136 | using nux::VScrollBar::AtMinimum; | ||
375 | 137 | using nux::VScrollBar::GetBaseHeight; | ||
376 | 138 | |||
377 | 139 | int scroll_dy; | ||
378 | 140 | bool scroll_up_signal_; | ||
379 | 141 | bool scroll_down_signal_; | ||
380 | 142 | }; | ||
381 | 143 | |||
382 | 144 | TestOverlayScrollBar() | ||
383 | 145 | { | ||
384 | 146 | scroll_bar_ = std::make_shared<MockScrollBar>(NUX_TRACKER_LOCATION); | ||
385 | 147 | } | ||
386 | 148 | |||
387 | 149 | std::shared_ptr<MockScrollBar> scroll_bar_; | ||
388 | 150 | }; | ||
389 | 151 | |||
390 | 152 | TEST_F(TestOverlayWindow, TestOverlayShows) | ||
391 | 153 | { | ||
392 | 154 | overlay_window_->MouseNear(); | ||
393 | 155 | EXPECT_TRUE(overlay_window_->IsVisible()); | ||
394 | 156 | } | ||
395 | 157 | |||
396 | 158 | TEST_F(TestOverlayWindow, TestOverlayHides) | ||
397 | 159 | { | ||
398 | 160 | overlay_window_->MouseNear(); | ||
399 | 161 | EXPECT_TRUE(overlay_window_->IsVisible()); | ||
400 | 162 | |||
401 | 163 | overlay_window_->MouseBeyond(); | ||
402 | 164 | EXPECT_FALSE(overlay_window_->IsVisible()); | ||
403 | 165 | } | ||
404 | 166 | |||
405 | 167 | TEST_F(TestOverlayWindow, TestOverlayStaysOpenWhenMouseDown) | ||
406 | 168 | { | ||
407 | 169 | overlay_window_->MouseNear(); | ||
408 | 170 | overlay_window_->MouseDown(); | ||
409 | 171 | |||
410 | 172 | overlay_window_->MouseBeyond(); | ||
411 | 173 | EXPECT_TRUE(overlay_window_->IsVisible()); | ||
412 | 174 | } | ||
413 | 175 | |||
414 | 176 | TEST_F(TestOverlayWindow, TestOverlayMouseDrags) | ||
415 | 177 | { | ||
416 | 178 | overlay_window_->MouseDown(); | ||
417 | 179 | EXPECT_FALSE(overlay_window_->IsMouseBeingDragged()); | ||
418 | 180 | |||
419 | 181 | overlay_window_->SetThumbOffsetY(10); | ||
420 | 182 | EXPECT_TRUE(overlay_window_->IsMouseBeingDragged()); | ||
421 | 183 | } | ||
422 | 184 | |||
423 | 185 | TEST_F(TestOverlayWindow, TestOverlayStopDraggingOnMouseUp) | ||
424 | 186 | { | ||
425 | 187 | overlay_window_->MouseDown(); | ||
426 | 188 | EXPECT_FALSE(overlay_window_->IsMouseBeingDragged()); | ||
427 | 189 | |||
428 | 190 | overlay_window_->SetThumbOffsetY(10); | ||
429 | 191 | EXPECT_TRUE(overlay_window_->IsMouseBeingDragged()); | ||
430 | 192 | |||
431 | 193 | overlay_window_->MouseUp(); | ||
432 | 194 | EXPECT_FALSE(overlay_window_->IsMouseBeingDragged()); | ||
433 | 195 | } | ||
434 | 196 | |||
435 | 197 | TEST_F(TestOverlayWindow, TestOverlaySetsOffsetY) | ||
436 | 198 | { | ||
437 | 199 | int const offset_y = 30; | ||
438 | 200 | |||
439 | 201 | overlay_window_->SetThumbOffsetY(offset_y); | ||
440 | 202 | EXPECT_EQ(overlay_window_->GetThumbOffsetY(), offset_y); | ||
441 | 203 | } | ||
442 | 204 | |||
443 | 205 | TEST_F(TestOverlayWindow, TestOverlaySetsOffsetYOutOfBoundsLower) | ||
444 | 206 | { | ||
445 | 207 | int const offset_y = -40; | ||
446 | 208 | |||
447 | 209 | overlay_window_->SetThumbOffsetY(offset_y); | ||
448 | 210 | EXPECT_EQ(overlay_window_->GetThumbOffsetY(), 0); | ||
449 | 211 | } | ||
450 | 212 | |||
451 | 213 | TEST_F(TestOverlayWindow, TestOverlaySetsOffsetYOutOfBoundsUpper) | ||
452 | 214 | { | ||
453 | 215 | int const offset_y = 1000; | ||
454 | 216 | int const expected_offset = overlay_window_->GetBaseHeight() - overlay_window_->GetThumbHeight(); | ||
455 | 217 | |||
456 | 218 | overlay_window_->SetThumbOffsetY(offset_y); | ||
457 | 219 | EXPECT_EQ(overlay_window_->GetThumbOffsetY(), expected_offset); | ||
458 | 220 | } | ||
459 | 221 | |||
460 | 222 | TEST_F(TestOverlayWindow, TestOverlayMouseIsInsideThumb) | ||
461 | 223 | { | ||
462 | 224 | nux::Geometry const geo(0, 50, 50, 400); | ||
463 | 225 | |||
464 | 226 | overlay_window_->UpdateGeometry(geo); | ||
465 | 227 | EXPECT_TRUE(overlay_window_->IsMouseInsideThumb(0)); | ||
466 | 228 | } | ||
467 | 229 | |||
468 | 230 | TEST_F(TestOverlayWindow, TestOverlayMouseIsInsideOnOffsetChange) | ||
469 | 231 | { | ||
470 | 232 | nux::Geometry const geo(0, 50, 50, 400); | ||
471 | 233 | int const offset_y = 50; | ||
472 | 234 | int const thumb_height = overlay_window_->GetThumbHeight(); | ||
473 | 235 | |||
474 | 236 | overlay_window_->UpdateGeometry(geo); | ||
475 | 237 | overlay_window_->SetThumbOffsetY(offset_y); | ||
476 | 238 | |||
477 | 239 | EXPECT_FALSE(overlay_window_->IsMouseInsideThumb(offset_y - 1)); | ||
478 | 240 | EXPECT_TRUE(overlay_window_->IsMouseInsideThumb(offset_y + thumb_height/2)); | ||
479 | 241 | EXPECT_FALSE(overlay_window_->IsMouseInsideThumb(offset_y + thumb_height + 1)); | ||
480 | 242 | } | ||
481 | 243 | |||
482 | 244 | TEST_F(TestOverlayScrollBar, TestScrollDownSignal) | ||
483 | 245 | { | ||
484 | 246 | scroll_bar_->ScrollDown(10); | ||
485 | 247 | EXPECT_TRUE(scroll_bar_->scroll_down_signal_); | ||
486 | 248 | } | ||
487 | 249 | |||
488 | 250 | TEST_F(TestOverlayScrollBar, TestScrollUpSignal) | ||
489 | 251 | { | ||
490 | 252 | scroll_bar_->ScrollUp(10); | ||
491 | 253 | EXPECT_TRUE(scroll_bar_->scroll_up_signal_); | ||
492 | 254 | } | ||
493 | 255 | |||
494 | 256 | TEST_F(TestOverlayScrollBar, TestScrollDownDeltaY) | ||
495 | 257 | { | ||
496 | 258 | int scroll_down = 15; | ||
497 | 259 | scroll_bar_->ScrollDown(scroll_down); | ||
498 | 260 | EXPECT_EQ(scroll_bar_->scroll_dy, scroll_down); | ||
499 | 261 | } | ||
500 | 262 | |||
501 | 263 | TEST_F(TestOverlayScrollBar, TestScrollUpDeltaY) | ||
502 | 264 | { | ||
503 | 265 | int scroll_up = 7; | ||
504 | 266 | scroll_bar_->ScrollUp(scroll_up); | ||
505 | 267 | EXPECT_EQ(scroll_bar_->scroll_dy, scroll_up); | ||
506 | 268 | } | ||
507 | 269 | |||
508 | 270 | TEST_F(TestOverlayScrollBar, TestScrollsSlowlyDeltaY) | ||
509 | 271 | { | ||
510 | 272 | int scroll_down = 10; | ||
511 | 273 | for (int i = 0; i < scroll_down; i++) | ||
512 | 274 | { | ||
513 | 275 | scroll_bar_->ScrollDown(1); | ||
514 | 276 | EXPECT_EQ(scroll_bar_->scroll_dy, 1); | ||
515 | 277 | } | ||
516 | 278 | } | ||
517 | 279 | |||
518 | 280 | } | ||
519 | 0 | 281 | ||
520 | === modified file 'unity-shared/CMakeLists.txt' | |||
521 | --- unity-shared/CMakeLists.txt 2012-11-15 18:44:55 +0000 | |||
522 | +++ unity-shared/CMakeLists.txt 2012-11-23 23:52:20 +0000 | |||
523 | @@ -49,6 +49,7 @@ | |||
524 | 49 | OverlayRenderer.cpp | 49 | OverlayRenderer.cpp |
525 | 50 | PanelStyle.cpp | 50 | PanelStyle.cpp |
526 | 51 | PlacesVScrollBar.cpp | 51 | PlacesVScrollBar.cpp |
527 | 52 | PlacesOverlayVScrollBar.cpp | ||
528 | 52 | PreviewStyle.cpp | 53 | PreviewStyle.cpp |
529 | 53 | RatingsButton.cpp | 54 | RatingsButton.cpp |
530 | 54 | SearchBar.cpp | 55 | SearchBar.cpp |
531 | @@ -66,6 +67,7 @@ | |||
532 | 66 | UnityWindowStyle.cpp | 67 | UnityWindowStyle.cpp |
533 | 67 | UnityWindowView.cpp | 68 | UnityWindowView.cpp |
534 | 68 | UserThumbnailProvider.cpp | 69 | UserThumbnailProvider.cpp |
535 | 70 | VScrollBarOverlayWindow.cpp | ||
536 | 69 | WindowManager.cpp | 71 | WindowManager.cpp |
537 | 70 | XPathQueryPart.cpp | 72 | XPathQueryPart.cpp |
538 | 71 | ) | 73 | ) |
539 | 72 | 74 | ||
540 | === added file 'unity-shared/PlacesOverlayVScrollBar.cpp' | |||
541 | --- unity-shared/PlacesOverlayVScrollBar.cpp 1970-01-01 00:00:00 +0000 | |||
542 | +++ unity-shared/PlacesOverlayVScrollBar.cpp 2012-11-23 23:52:20 +0000 | |||
543 | @@ -0,0 +1,417 @@ | |||
544 | 1 | // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- | ||
545 | 2 | /* | ||
546 | 3 | * Copyright (C) 2012 Canonical Ltd | ||
547 | 4 | * | ||
548 | 5 | * This program is free software: you can redistribute it and/or modify | ||
549 | 6 | * it under the terms of the GNU General Public License version 3 as | ||
550 | 7 | * published by the Free Software Foundation. | ||
551 | 8 | * | ||
552 | 9 | * This program is distributed in the hope that it will be useful, | ||
553 | 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
554 | 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
555 | 12 | * GNU General Public License for more details. | ||
556 | 13 | * | ||
557 | 14 | * You should have received a copy of the GNU General Public License | ||
558 | 15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
559 | 16 | * | ||
560 | 17 | * Authored by: Brandon Schaefer <brandon.schaefer@canonical.com> | ||
561 | 18 | */ | ||
562 | 19 | |||
563 | 20 | #include <Nux/Nux.h> | ||
564 | 21 | |||
565 | 22 | #include "PlacesOverlayVScrollBar.h" | ||
566 | 23 | #include "CairoTexture.h" | ||
567 | 24 | |||
568 | 25 | namespace | ||
569 | 26 | { | ||
570 | 27 | int const PROXIMITY = 7; | ||
571 | 28 | int const SCROLL_ANIMATION = 400; | ||
572 | 29 | int const MAX_CONNECTOR_ANIMATION = 200; | ||
573 | 30 | } | ||
574 | 31 | |||
575 | 32 | namespace unity | ||
576 | 33 | { | ||
577 | 34 | namespace dash | ||
578 | 35 | { | ||
579 | 36 | |||
580 | 37 | PlacesOverlayVScrollBar::PlacesOverlayVScrollBar(NUX_FILE_LINE_DECL) | ||
581 | 38 | : PlacesVScrollBar(NUX_FILE_LINE_PARAM) | ||
582 | 39 | , overlay_window_(new VScrollBarOverlayWindow(_track->GetAbsoluteGeometry())) | ||
583 | 40 | , area_prox_(overlay_window_.GetPointer(), PROXIMITY) | ||
584 | 41 | , thumb_above_slider_(false) | ||
585 | 42 | , connector_height_(0) | ||
586 | 43 | , mouse_down_offset_(0) | ||
587 | 44 | , delta_update_(0) | ||
588 | 45 | { | ||
589 | 46 | area_prox_.mouse_near.connect(sigc::mem_fun(this, &PlacesOverlayVScrollBar::OnMouseNear)); | ||
590 | 47 | area_prox_.mouse_beyond.connect(sigc::mem_fun(this, &PlacesOverlayVScrollBar::OnMouseBeyond)); | ||
591 | 48 | |||
592 | 49 | overlay_window_->mouse_down.connect(sigc::mem_fun(this, &PlacesOverlayVScrollBar::OnMouseDown)); | ||
593 | 50 | overlay_window_->mouse_up.connect(sigc::mem_fun(this, &PlacesOverlayVScrollBar::OnMouseUp)); | ||
594 | 51 | overlay_window_->mouse_click.connect(sigc::mem_fun(this, &PlacesOverlayVScrollBar::OnMouseClick)); | ||
595 | 52 | overlay_window_->mouse_move.connect(sigc::mem_fun(this, &PlacesOverlayVScrollBar::OnMouseMove)); | ||
596 | 53 | overlay_window_->mouse_drag.connect(sigc::mem_fun(this, &PlacesOverlayVScrollBar::OnMouseDrag)); | ||
597 | 54 | |||
598 | 55 | _track->geometry_changed.connect(sigc::mem_fun(this, &PlacesOverlayVScrollBar::OnTrackGeometryChanged)); | ||
599 | 56 | OnVisibleChanged.connect(sigc::mem_fun(this, &PlacesOverlayVScrollBar::OnVisibilityChanged)); | ||
600 | 57 | } | ||
601 | 58 | |||
602 | 59 | void PlacesOverlayVScrollBar::OnTrackGeometryChanged(nux::Area* /*area*/, nux::Geometry& /*geo*/) | ||
603 | 60 | { | ||
604 | 61 | UpdateStepY(); | ||
605 | 62 | overlay_window_->UpdateGeometry(_track->GetAbsoluteGeometry()); | ||
606 | 63 | |||
607 | 64 | if (overlay_window_->IsVisible() && !IsScrollBarVisible()) | ||
608 | 65 | { | ||
609 | 66 | overlay_window_->ResetStates(); | ||
610 | 67 | ResetConnector(); | ||
611 | 68 | } | ||
612 | 69 | } | ||
613 | 70 | |||
614 | 71 | void PlacesOverlayVScrollBar::OnVisibilityChanged(nux::Area* /*area*/, bool visible) | ||
615 | 72 | { | ||
616 | 73 | if (overlay_window_->IsVisible() && !visible) | ||
617 | 74 | { | ||
618 | 75 | overlay_window_->ResetStates(); | ||
619 | 76 | ResetConnector(); | ||
620 | 77 | } | ||
621 | 78 | } | ||
622 | 79 | |||
623 | 80 | void PlacesOverlayVScrollBar::StopAnimation() | ||
624 | 81 | { | ||
625 | 82 | if (animation_.CurrentState() != nux::animation::Animation::State::Stopped) | ||
626 | 83 | animation_.Stop(); | ||
627 | 84 | } | ||
628 | 85 | |||
629 | 86 | void PlacesOverlayVScrollBar::SetupAnimation(int start, int stop, int milliseconds) | ||
630 | 87 | { | ||
631 | 88 | tweening_connection_.disconnect(); | ||
632 | 89 | delta_update_ = 0; | ||
633 | 90 | |||
634 | 91 | animation_.SetDuration(milliseconds); | ||
635 | 92 | animation_.SetEasingCurve(nux::animation::EasingCurve(nux::animation::EasingCurve::Type::Linear)); | ||
636 | 93 | |||
637 | 94 | animation_.SetStartValue(start); | ||
638 | 95 | animation_.SetFinishValue(stop); | ||
639 | 96 | } | ||
640 | 97 | |||
641 | 98 | void PlacesOverlayVScrollBar::StartScrollAnimation(ScrollDir dir, int stop) | ||
642 | 99 | { | ||
643 | 100 | if (animation_.CurrentState() == nux::animation::Animation::State::Stopped) | ||
644 | 101 | { | ||
645 | 102 | SetupAnimation(0, stop, SCROLL_ANIMATION); | ||
646 | 103 | |||
647 | 104 | tweening_connection_ = animation_.updated.connect([this, dir] (int const& update) { | ||
648 | 105 | OnScroll(dir, update - delta_update_); | ||
649 | 106 | delta_update_ = update; | ||
650 | 107 | |||
651 | 108 | CheckIfThumbIsInsideSlider(); | ||
652 | 109 | UpdateConnectorPosition(); | ||
653 | 110 | QueueDraw(); | ||
654 | 111 | }); | ||
655 | 112 | |||
656 | 113 | animation_.Start(); | ||
657 | 114 | } | ||
658 | 115 | } | ||
659 | 116 | |||
660 | 117 | void PlacesOverlayVScrollBar::OnScroll(ScrollDir dir, int mouse_dy) | ||
661 | 118 | { | ||
662 | 119 | if (dir == ScrollDir::UP) | ||
663 | 120 | OnScrollUp.emit(stepY, mouse_dy); | ||
664 | 121 | else if (dir == ScrollDir::DOWN) | ||
665 | 122 | OnScrollDown.emit(stepY, mouse_dy); | ||
666 | 123 | } | ||
667 | 124 | |||
668 | 125 | void PlacesOverlayVScrollBar::StartConnectorAnimation() | ||
669 | 126 | { | ||
670 | 127 | if (animation_.CurrentState() == nux::animation::Animation::State::Stopped) | ||
671 | 128 | { | ||
672 | 129 | SetupAnimation(connector_height_, 0, std::min(connector_height_, MAX_CONNECTOR_ANIMATION)); | ||
673 | 130 | |||
674 | 131 | tweening_connection_ = animation_.updated.connect([this] (int const& update) { | ||
675 | 132 | connector_height_ = update; | ||
676 | 133 | UpdateConnectorTexture(); | ||
677 | 134 | }); | ||
678 | 135 | |||
679 | 136 | animation_.Start(); | ||
680 | 137 | } | ||
681 | 138 | } | ||
682 | 139 | |||
683 | 140 | bool PlacesOverlayVScrollBar::IsScrollBarVisible() const | ||
684 | 141 | { | ||
685 | 142 | return (content_height_ > container_height_); | ||
686 | 143 | } | ||
687 | 144 | |||
688 | 145 | void PlacesOverlayVScrollBar::OnMouseNear(nux::Point const& mouse_pos) | ||
689 | 146 | { | ||
690 | 147 | if (IsVisible() && IsScrollBarVisible()) | ||
691 | 148 | { | ||
692 | 149 | StopAnimation(); | ||
693 | 150 | |||
694 | 151 | overlay_window_->MouseNear(); | ||
695 | 152 | AdjustThumbOffsetFromMouse(); | ||
696 | 153 | } | ||
697 | 154 | } | ||
698 | 155 | |||
699 | 156 | void PlacesOverlayVScrollBar::OnMouseBeyond(nux::Point const& mouse_pos) | ||
700 | 157 | { | ||
701 | 158 | if (IsVisible() && IsScrollBarVisible()) | ||
702 | 159 | { | ||
703 | 160 | overlay_window_->MouseBeyond(); | ||
704 | 161 | UpdateConnectorPosition(); | ||
705 | 162 | } | ||
706 | 163 | } | ||
707 | 164 | |||
708 | 165 | void PlacesOverlayVScrollBar::AdjustThumbOffsetFromMouse() | ||
709 | 166 | { | ||
710 | 167 | if (!overlay_window_->IsMouseBeingDragged()) | ||
711 | 168 | { | ||
712 | 169 | nux::Point const& mouse = nux::GetWindowCompositor().GetMousePosition(); | ||
713 | 170 | |||
714 | 171 | if (mouse.y > 0) | ||
715 | 172 | { | ||
716 | 173 | int const quarter_of_thumb = overlay_window_->GetThumbHeight()/4; | ||
717 | 174 | int const new_offset = mouse.y - _track->GetAbsoluteY() - overlay_window_->GetThumbHeight()/2; | ||
718 | 175 | |||
719 | 176 | int const slider_offset = _slider->GetAbsoluteY() - _track->GetAbsoluteY() + _slider->GetBaseHeight()/3; | ||
720 | 177 | bool const mouse_above_slider = slider_offset < new_offset; | ||
721 | 178 | |||
722 | 179 | if (mouse_above_slider) | ||
723 | 180 | overlay_window_->SetThumbOffsetY(new_offset - quarter_of_thumb); | ||
724 | 181 | else | ||
725 | 182 | overlay_window_->SetThumbOffsetY(new_offset + quarter_of_thumb); | ||
726 | 183 | } | ||
727 | 184 | |||
728 | 185 | CheckIfThumbIsInsideSlider(); | ||
729 | 186 | } | ||
730 | 187 | } | ||
731 | 188 | |||
732 | 189 | void PlacesOverlayVScrollBar::CheckIfThumbIsInsideSlider() | ||
733 | 190 | { | ||
734 | 191 | nux::Geometry const& slider_geo = _slider->GetAbsoluteGeometry(); | ||
735 | 192 | nux::Geometry const& thumb_geo = overlay_window_->GetThumbGeometry(); | ||
736 | 193 | nux::Geometry const& intersection = (thumb_geo.Intersect(slider_geo)); | ||
737 | 194 | |||
738 | 195 | if (!intersection.IsNull()) | ||
739 | 196 | { | ||
740 | 197 | ResetConnector(); | ||
741 | 198 | overlay_window_->ThumbInsideSlider(); | ||
742 | 199 | } | ||
743 | 200 | else | ||
744 | 201 | { | ||
745 | 202 | UpdateConnectorPosition(); | ||
746 | 203 | overlay_window_->ThumbOutsideSlider(); | ||
747 | 204 | } | ||
748 | 205 | } | ||
749 | 206 | |||
750 | 207 | void PlacesOverlayVScrollBar::UpdateConnectorPosition() | ||
751 | 208 | { | ||
752 | 209 | int const slider_y = _slider->GetBaseY() - GetBaseY(); | ||
753 | 210 | int const thumb_y = overlay_window_->GetThumbOffsetY(); | ||
754 | 211 | int const thumb_height = overlay_window_->GetThumbHeight(); | ||
755 | 212 | |||
756 | 213 | if (!overlay_window_->IsVisible()) | ||
757 | 214 | { | ||
758 | 215 | ResetConnector(); | ||
759 | 216 | } | ||
760 | 217 | else if (slider_y > thumb_y) | ||
761 | 218 | { | ||
762 | 219 | thumb_above_slider_ = true; | ||
763 | 220 | connector_height_ = slider_y - (thumb_y + thumb_height); | ||
764 | 221 | } | ||
765 | 222 | else | ||
766 | 223 | { | ||
767 | 224 | thumb_above_slider_ = false; | ||
768 | 225 | connector_height_ = thumb_y - (_slider->GetBaseY() + _slider->GetBaseHeight()) + _track->GetBaseY(); | ||
769 | 226 | } | ||
770 | 227 | |||
771 | 228 | UpdateConnectorTexture(); | ||
772 | 229 | } | ||
773 | 230 | |||
774 | 231 | void PlacesOverlayVScrollBar::ResetConnector() | ||
775 | 232 | { | ||
776 | 233 | StartConnectorAnimation(); | ||
777 | 234 | QueueDraw(); | ||
778 | 235 | } | ||
779 | 236 | |||
780 | 237 | void PlacesOverlayVScrollBar::OnMouseClick(int /*x*/, int y, unsigned int button_flags, unsigned int /*key_flags*/) | ||
781 | 238 | { | ||
782 | 239 | if (!overlay_window_->IsMouseBeingDragged()) | ||
783 | 240 | { | ||
784 | 241 | int const button = nux::GetEventButton(button_flags); | ||
785 | 242 | |||
786 | 243 | if (button == 1) | ||
787 | 244 | LeftMouseClick(y); | ||
788 | 245 | else if (button == 2) | ||
789 | 246 | MiddleMouseClick(y); | ||
790 | 247 | } | ||
791 | 248 | |||
792 | 249 | overlay_window_->MouseUp(); | ||
793 | 250 | } | ||
794 | 251 | |||
795 | 252 | void PlacesOverlayVScrollBar::LeftMouseClick(int y) | ||
796 | 253 | { | ||
797 | 254 | if (IsMouseInTopHalfOfThumb(y)) | ||
798 | 255 | { | ||
799 | 256 | int const top = _slider->GetBaseY() - _track->GetBaseY(); | ||
800 | 257 | StartScrollAnimation(ScrollDir::UP, std::min(_slider->GetBaseHeight(), top)); | ||
801 | 258 | } | ||
802 | 259 | else | ||
803 | 260 | { | ||
804 | 261 | int const bottom = (_track->GetBaseY() + _track->GetBaseHeight()) - | ||
805 | 262 | (_slider->GetBaseHeight() + _slider->GetBaseY()); | ||
806 | 263 | StartScrollAnimation(ScrollDir::DOWN, std::min(_slider->GetBaseHeight(), bottom)); | ||
807 | 264 | } | ||
808 | 265 | |||
809 | 266 | UpdateConnectorPosition(); | ||
810 | 267 | } | ||
811 | 268 | |||
812 | 269 | void PlacesOverlayVScrollBar::MiddleMouseClick(int y) | ||
813 | 270 | { | ||
814 | 271 | int const slider_offset = _slider->GetBaseY() - _track->GetBaseY(); | ||
815 | 272 | bool const move_up = slider_offset > overlay_window_->GetThumbOffsetY(); | ||
816 | 273 | |||
817 | 274 | int const slider_thumb_diff = abs(overlay_window_->GetThumbOffsetY() - slider_offset); | ||
818 | 275 | |||
819 | 276 | if (move_up) | ||
820 | 277 | StartScrollAnimation(ScrollDir::UP, slider_thumb_diff); | ||
821 | 278 | else | ||
822 | 279 | StartScrollAnimation(ScrollDir::DOWN, slider_thumb_diff); | ||
823 | 280 | } | ||
824 | 281 | |||
825 | 282 | void PlacesOverlayVScrollBar::OnMouseDown(int /*x*/, int y, unsigned int /*button_flags*/, unsigned int /*key_flags*/) | ||
826 | 283 | { | ||
827 | 284 | if (overlay_window_->IsMouseInsideThumb(y)) | ||
828 | 285 | { | ||
829 | 286 | if (IsMouseInTopHalfOfThumb(y)) | ||
830 | 287 | overlay_window_->PageUpAction(); | ||
831 | 288 | else | ||
832 | 289 | overlay_window_->PageDownAction(); | ||
833 | 290 | |||
834 | 291 | mouse_down_offset_ = y - overlay_window_->GetThumbOffsetY(); | ||
835 | 292 | overlay_window_->MouseDown(); | ||
836 | 293 | } | ||
837 | 294 | } | ||
838 | 295 | |||
839 | 296 | bool PlacesOverlayVScrollBar::IsMouseInTopHalfOfThumb(int y) | ||
840 | 297 | { | ||
841 | 298 | int const thumb_height = overlay_window_->GetThumbHeight(); | ||
842 | 299 | int const thumb_offset_y = overlay_window_->GetThumbOffsetY(); | ||
843 | 300 | |||
844 | 301 | return (y < (thumb_height/2 + thumb_offset_y)); | ||
845 | 302 | } | ||
846 | 303 | |||
847 | 304 | void PlacesOverlayVScrollBar::OnMouseUp(int x, int y, unsigned int /*button_flags*/, unsigned int /*key_flags*/) | ||
848 | 305 | { | ||
849 | 306 | nux::Geometry const& geo = overlay_window_->GetAbsoluteGeometry(); | ||
850 | 307 | |||
851 | 308 | if (!geo.IsPointInside(x + geo.x, y + geo.y)) | ||
852 | 309 | { | ||
853 | 310 | overlay_window_->MouseUp(); | ||
854 | 311 | UpdateConnectorPosition(); | ||
855 | 312 | } | ||
856 | 313 | } | ||
857 | 314 | |||
858 | 315 | void PlacesOverlayVScrollBar::OnMouseMove(int /*x*/, int y, int /*dx*/, int /*dy*/, unsigned int /*button_flags*/, unsigned int /*key_flags*/) | ||
859 | 316 | { | ||
860 | 317 | if (!overlay_window_->IsMouseInsideThumb(y)) | ||
861 | 318 | AdjustThumbOffsetFromMouse(); | ||
862 | 319 | } | ||
863 | 320 | |||
864 | 321 | void PlacesOverlayVScrollBar::OnMouseDrag(int /*x*/, int y, int /*dx*/, int dy, unsigned int /*button_flags*/, unsigned int /*key_flags*/) | ||
865 | 322 | { | ||
866 | 323 | StopAnimation(); | ||
867 | 324 | MouseDraggingOverlay(y, dy); | ||
868 | 325 | } | ||
869 | 326 | |||
870 | 327 | void PlacesOverlayVScrollBar::MouseDraggingOverlay(int y, int dys) | ||
871 | 328 | { | ||
872 | 329 | int const dy = y - overlay_window_->GetThumbOffsetY() - mouse_down_offset_; | ||
873 | 330 | int const at_min = overlay_window_->GetThumbOffsetY() <= 0; | ||
874 | 331 | int const at_max = overlay_window_->GetThumbOffsetY() + overlay_window_->GetThumbHeight() >= _track->GetBaseHeight(); | ||
875 | 332 | |||
876 | 333 | if (dy < 0 && !at_min) | ||
877 | 334 | { | ||
878 | 335 | OnScrollUp.emit(stepY, abs(dy)); | ||
879 | 336 | } | ||
880 | 337 | else if (dy > 0 && !at_max) | ||
881 | 338 | { | ||
882 | 339 | OnScrollDown.emit(stepY, dy); | ||
883 | 340 | } | ||
884 | 341 | |||
885 | 342 | overlay_window_->SetThumbOffsetY(y - mouse_down_offset_); | ||
886 | 343 | CheckIfThumbIsInsideSlider(); | ||
887 | 344 | } | ||
888 | 345 | |||
889 | 346 | void PlacesOverlayVScrollBar::UpdateStepY() | ||
890 | 347 | { | ||
891 | 348 | stepY = (float) (content_height_ - container_height_) / (float) (_track->GetBaseHeight() - _slider->GetBaseHeight()); | ||
892 | 349 | } | ||
893 | 350 | |||
894 | 351 | void PlacesOverlayVScrollBar::Draw(nux::GraphicsEngine& graphics_engine, bool force_draw) | ||
895 | 352 | { | ||
896 | 353 | PlacesVScrollBar::Draw(graphics_engine, force_draw); | ||
897 | 354 | |||
898 | 355 | if (connector_height_ > 0 && connector_texture_.IsValid()) | ||
899 | 356 | { | ||
900 | 357 | int const connector_width = GetBaseWidth(); | ||
901 | 358 | int offset_y = 0; | ||
902 | 359 | if (thumb_above_slider_) | ||
903 | 360 | { | ||
904 | 361 | offset_y = _slider->GetBaseY() - connector_height_; | ||
905 | 362 | } | ||
906 | 363 | else | ||
907 | 364 | { | ||
908 | 365 | offset_y = _slider->GetBaseY() + _slider->GetBaseHeight(); | ||
909 | 366 | } | ||
910 | 367 | |||
911 | 368 | nux::Geometry base(_track->GetBaseX(), offset_y - 4, connector_width, connector_height_ + 5); | ||
912 | 369 | nux::TexCoordXForm texxform; | ||
913 | 370 | |||
914 | 371 | graphics_engine.QRP_1Tex(base.x, | ||
915 | 372 | base.y, | ||
916 | 373 | base.width, | ||
917 | 374 | base.height, | ||
918 | 375 | connector_texture_->GetDeviceTexture(), | ||
919 | 376 | texxform, | ||
920 | 377 | nux::color::White); | ||
921 | 378 | } | ||
922 | 379 | } | ||
923 | 380 | |||
924 | 381 | void PlacesOverlayVScrollBar::UpdateConnectorTexture() | ||
925 | 382 | { | ||
926 | 383 | if (connector_height_ < 0) | ||
927 | 384 | return; | ||
928 | 385 | |||
929 | 386 | int width = 3; | ||
930 | 387 | int height = connector_height_; | ||
931 | 388 | float const radius = 1.5f; | ||
932 | 389 | float const aspect = 1.0f; | ||
933 | 390 | |||
934 | 391 | cairo_t* cr = NULL; | ||
935 | 392 | |||
936 | 393 | nux::color::RedGreenBlue const& connector_bg = nux::color::Gray; | ||
937 | 394 | |||
938 | 395 | nux::CairoGraphics cairoGraphics(CAIRO_FORMAT_ARGB32, width, height); | ||
939 | 396 | cr = cairoGraphics.GetContext(); | ||
940 | 397 | cairo_save(cr); | ||
941 | 398 | |||
942 | 399 | cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR); | ||
943 | 400 | cairo_paint(cr); | ||
944 | 401 | |||
945 | 402 | cairo_set_operator(cr, CAIRO_OPERATOR_OVER); | ||
946 | 403 | cairo_save(cr); | ||
947 | 404 | |||
948 | 405 | cairo_set_source_rgba(cr, connector_bg.red, connector_bg.green, connector_bg.blue, 0.8); | ||
949 | 406 | cairoGraphics.DrawRoundedRectangle(cr, aspect, 0.0f, 0.0f, radius, width, height); | ||
950 | 407 | cairo_fill_preserve(cr); | ||
951 | 408 | |||
952 | 409 | connector_texture_.Adopt(texture_from_cairo_graphics(cairoGraphics)); | ||
953 | 410 | cairo_destroy(cr); | ||
954 | 411 | |||
955 | 412 | QueueDraw(); | ||
956 | 413 | } | ||
957 | 414 | |||
958 | 415 | } // namespace dash | ||
959 | 416 | } // namespace unity | ||
960 | 417 | |||
961 | 0 | 418 | ||
962 | === added file 'unity-shared/PlacesOverlayVScrollBar.h' | |||
963 | --- unity-shared/PlacesOverlayVScrollBar.h 1970-01-01 00:00:00 +0000 | |||
964 | +++ unity-shared/PlacesOverlayVScrollBar.h 2012-11-23 23:52:20 +0000 | |||
965 | @@ -0,0 +1,107 @@ | |||
966 | 1 | // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- | ||
967 | 2 | /* | ||
968 | 3 | * Copyright (C) 2012 Canonical Ltd | ||
969 | 4 | * | ||
970 | 5 | * This program is free software: you can redistribute it and/or modify | ||
971 | 6 | * it under the terms of the GNU General Public License version 3 as | ||
972 | 7 | * published by the Free Software Foundation. | ||
973 | 8 | * | ||
974 | 9 | * This program is distributed in the hope that it will be useful, | ||
975 | 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
976 | 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
977 | 12 | * GNU General Public License for more details. | ||
978 | 13 | * | ||
979 | 14 | * You should have received a copy of the GNU General Public License | ||
980 | 15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
981 | 16 | * | ||
982 | 17 | * Authored by: Brandon Schaefer <brandon.schaefer@canonical.com> | ||
983 | 18 | */ | ||
984 | 19 | |||
985 | 20 | #ifndef PLACES_OVERLAY_VSCROLLBAR_H | ||
986 | 21 | #define PLACES_OVERLAY_VSCROLLBAR_H | ||
987 | 22 | |||
988 | 23 | #include <Nux/Nux.h> | ||
989 | 24 | #include <Nux/InputAreaProximity.h> | ||
990 | 25 | #include <NuxCore/Animation.h> | ||
991 | 26 | #include <memory> | ||
992 | 27 | |||
993 | 28 | #include "unity-shared/PlacesVScrollBar.h" | ||
994 | 29 | #include "unity-shared/VScrollBarOverlayWindow.h" | ||
995 | 30 | |||
996 | 31 | namespace unity | ||
997 | 32 | { | ||
998 | 33 | namespace dash | ||
999 | 34 | { | ||
1000 | 35 | |||
1001 | 36 | class PlacesOverlayVScrollBar: public PlacesVScrollBar | ||
1002 | 37 | { | ||
1003 | 38 | public: | ||
1004 | 39 | PlacesOverlayVScrollBar(NUX_FILE_LINE_PROTO); | ||
1005 | 40 | |||
1006 | 41 | protected: | ||
1007 | 42 | void Draw(nux::GraphicsEngine& graphics_engine, bool force_draw); | ||
1008 | 43 | |||
1009 | 44 | private: | ||
1010 | 45 | enum class ScrollDir : unsigned int | ||
1011 | 46 | { | ||
1012 | 47 | UP, | ||
1013 | 48 | DOWN, | ||
1014 | 49 | }; | ||
1015 | 50 | |||
1016 | 51 | void OnTrackGeometryChanged(nux::Area* area, nux::Geometry& geo); | ||
1017 | 52 | void OnVisibilityChanged(nux::Area* area, bool visible); | ||
1018 | 53 | |||
1019 | 54 | void OnMouseNear(nux::Point const& mouse_pos); | ||
1020 | 55 | void OnMouseBeyond(nux::Point const& mouse_pos); | ||
1021 | 56 | void AdjustThumbOffsetFromMouse(); | ||
1022 | 57 | |||
1023 | 58 | void OnMouseClick(int x, int y, unsigned int button_flags, unsigned int key_flags); | ||
1024 | 59 | void LeftMouseClick(int y); | ||
1025 | 60 | void MiddleMouseClick(int y); | ||
1026 | 61 | |||
1027 | 62 | void OnMouseDown(int x, int y, unsigned int button_flags, unsigned int key_flags); | ||
1028 | 63 | void OnMouseUp(int x, int y, unsigned int button_flags, unsigned int key_flags); | ||
1029 | 64 | |||
1030 | 65 | void OnMouseMove(int x, int y, int dx, int dy, unsigned int button_flags, unsigned int key_flags); | ||
1031 | 66 | |||
1032 | 67 | void OnMouseDrag(int x, int y, int dx, int dy, unsigned int button_flags, unsigned int key_flags); | ||
1033 | 68 | void MouseDraggingOverlay(int y, int dy); | ||
1034 | 69 | |||
1035 | 70 | bool IsMouseInTopHalfOfThumb(int y); | ||
1036 | 71 | void CheckIfThumbIsInsideSlider(); | ||
1037 | 72 | |||
1038 | 73 | bool IsScrollBarVisible() const; | ||
1039 | 74 | |||
1040 | 75 | void UpdateConnectorPosition(); | ||
1041 | 76 | void ResetConnector(); | ||
1042 | 77 | |||
1043 | 78 | void UpdateStepY(); | ||
1044 | 79 | |||
1045 | 80 | void SetupAnimation(int start, int stop, int milliseconds); | ||
1046 | 81 | void StopAnimation(); | ||
1047 | 82 | |||
1048 | 83 | void StartScrollAnimation(ScrollDir dir, int stop); | ||
1049 | 84 | void OnScroll(ScrollDir dir, int mouse_dy); | ||
1050 | 85 | |||
1051 | 86 | void StartConnectorAnimation(); | ||
1052 | 87 | |||
1053 | 88 | void UpdateConnectorTexture(); | ||
1054 | 89 | |||
1055 | 90 | nux::ObjectPtr<VScrollBarOverlayWindow> overlay_window_; | ||
1056 | 91 | nux::InputAreaProximity area_prox_; | ||
1057 | 92 | |||
1058 | 93 | nux::animation::AnimateValue<int> animation_; | ||
1059 | 94 | sigc::connection tweening_connection_; | ||
1060 | 95 | |||
1061 | 96 | nux::ObjectPtr<nux::BaseTexture> connector_texture_; | ||
1062 | 97 | |||
1063 | 98 | bool thumb_above_slider_; | ||
1064 | 99 | int connector_height_; | ||
1065 | 100 | int mouse_down_offset_; | ||
1066 | 101 | int delta_update_; | ||
1067 | 102 | }; | ||
1068 | 103 | |||
1069 | 104 | } // namespace dash | ||
1070 | 105 | } // namespace unity | ||
1071 | 106 | |||
1072 | 107 | #endif // PLACES_OVERLAY_VSCROLLBAR_H | ||
1073 | 0 | 108 | ||
1074 | === added file 'unity-shared/VScrollBarOverlayWindow.cpp' | |||
1075 | --- unity-shared/VScrollBarOverlayWindow.cpp 1970-01-01 00:00:00 +0000 | |||
1076 | +++ unity-shared/VScrollBarOverlayWindow.cpp 2012-11-23 23:52:20 +0000 | |||
1077 | @@ -0,0 +1,526 @@ | |||
1078 | 1 | // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- | ||
1079 | 2 | /* | ||
1080 | 3 | * Copyright (C) 2012 Canonical Ltd | ||
1081 | 4 | * | ||
1082 | 5 | * This program is free software: you can redistribute it and/or modify | ||
1083 | 6 | * it under the terms of the GNU General Public License version 3 as | ||
1084 | 7 | * published by the Free Software Foundation. | ||
1085 | 8 | * | ||
1086 | 9 | * This program is distributed in the hope that it will be useful, | ||
1087 | 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1088 | 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1089 | 12 | * GNU General Public License for more details. | ||
1090 | 13 | * | ||
1091 | 14 | * You should have received a copy of the GNU General Public License | ||
1092 | 15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1093 | 16 | * | ||
1094 | 17 | * Authored by: Brandon Schaefer <brandon.schaefer@canonical.com> | ||
1095 | 18 | */ | ||
1096 | 19 | |||
1097 | 20 | #include <Nux/Nux.h> | ||
1098 | 21 | #include <NuxGraphics/CairoGraphics.h> | ||
1099 | 22 | |||
1100 | 23 | #include "VScrollBarOverlayWindow.h" | ||
1101 | 24 | #include "UScreen.h" | ||
1102 | 25 | #include "DashStyle.h" | ||
1103 | 26 | #include "CairoTexture.h" | ||
1104 | 27 | |||
1105 | 28 | namespace | ||
1106 | 29 | { | ||
1107 | 30 | int const THUMB_WIDTH = 21; | ||
1108 | 31 | int const THUMB_HEIGHT = 68; | ||
1109 | 32 | int const THUMB_RADIUS = 3; | ||
1110 | 33 | } | ||
1111 | 34 | |||
1112 | 35 | |||
1113 | 36 | VScrollBarOverlayWindow::VScrollBarOverlayWindow(nux::Geometry const& geo) | ||
1114 | 37 | : nux::BaseWindow("") | ||
1115 | 38 | , content_size_(geo) | ||
1116 | 39 | , content_offset_x_(0) | ||
1117 | 40 | , mouse_offset_y_(0) | ||
1118 | 41 | , mouse_down_(false) | ||
1119 | 42 | , mouse_near_(false) | ||
1120 | 43 | , inside_slider_(false) | ||
1121 | 44 | , current_action_(ThumbAction::NONE) | ||
1122 | 45 | { | ||
1123 | 46 | Area::SetGeometry(content_size_.x, content_size_.y, THUMB_WIDTH, content_size_.height); | ||
1124 | 47 | SetBackgroundColor(nux::color::Transparent); | ||
1125 | 48 | |||
1126 | 49 | UpdateTexture(); | ||
1127 | 50 | } | ||
1128 | 51 | |||
1129 | 52 | void VScrollBarOverlayWindow::UpdateGeometry(nux::Geometry const& geo) | ||
1130 | 53 | { | ||
1131 | 54 | if (content_size_.x != geo.x || | ||
1132 | 55 | content_size_.y != geo.y || | ||
1133 | 56 | content_size_.height != geo.height) | ||
1134 | 57 | { | ||
1135 | 58 | content_size_ = geo; | ||
1136 | 59 | UpdateMouseOffsetX(); | ||
1137 | 60 | |||
1138 | 61 | Area::SetGeometry(content_size_.x + content_offset_x_, content_size_.y, THUMB_WIDTH, content_size_.height); | ||
1139 | 62 | } | ||
1140 | 63 | } | ||
1141 | 64 | |||
1142 | 65 | void VScrollBarOverlayWindow::SetThumbOffsetY(int y) | ||
1143 | 66 | { | ||
1144 | 67 | int const new_offset = GetValidOffsetYValue(y); | ||
1145 | 68 | |||
1146 | 69 | if (new_offset != mouse_offset_y_) | ||
1147 | 70 | { | ||
1148 | 71 | if (mouse_down_) | ||
1149 | 72 | MouseDragging(); | ||
1150 | 73 | |||
1151 | 74 | mouse_offset_y_ = new_offset; | ||
1152 | 75 | QueueDraw(); | ||
1153 | 76 | } | ||
1154 | 77 | } | ||
1155 | 78 | |||
1156 | 79 | int VScrollBarOverlayWindow::GetValidOffsetYValue(int new_offset) const | ||
1157 | 80 | { | ||
1158 | 81 | if (new_offset < 0) | ||
1159 | 82 | return 0; | ||
1160 | 83 | else if (new_offset > content_size_.height - THUMB_HEIGHT) | ||
1161 | 84 | return content_size_.height - THUMB_HEIGHT; | ||
1162 | 85 | |||
1163 | 86 | return new_offset; | ||
1164 | 87 | } | ||
1165 | 88 | |||
1166 | 89 | void VScrollBarOverlayWindow::UpdateMouseOffsetX() | ||
1167 | 90 | { | ||
1168 | 91 | int monitor = unity::UScreen::GetDefault()->GetMonitorWithMouse(); | ||
1169 | 92 | nux::Geometry const& geo = unity::UScreen::GetDefault()->GetMonitorGeometry(monitor); | ||
1170 | 93 | |||
1171 | 94 | if (content_size_.x + THUMB_WIDTH > geo.x + geo.width) | ||
1172 | 95 | content_offset_x_ = geo.x + geo.width - (content_size_.x + THUMB_WIDTH); | ||
1173 | 96 | else | ||
1174 | 97 | content_offset_x_ = 0; | ||
1175 | 98 | } | ||
1176 | 99 | |||
1177 | 100 | bool VScrollBarOverlayWindow::IsMouseInsideThumb(int y) const | ||
1178 | 101 | { | ||
1179 | 102 | nux::Geometry const thumb(0, mouse_offset_y_, THUMB_WIDTH, THUMB_HEIGHT); | ||
1180 | 103 | return thumb.IsPointInside(0,y); | ||
1181 | 104 | } | ||
1182 | 105 | |||
1183 | 106 | bool VScrollBarOverlayWindow::IsMouseBeingDragged() const | ||
1184 | 107 | { | ||
1185 | 108 | return current_action_ == ThumbAction::DRAGGING; | ||
1186 | 109 | } | ||
1187 | 110 | |||
1188 | 111 | int VScrollBarOverlayWindow::GetThumbHeight() const | ||
1189 | 112 | { | ||
1190 | 113 | return THUMB_HEIGHT; | ||
1191 | 114 | } | ||
1192 | 115 | |||
1193 | 116 | int VScrollBarOverlayWindow::GetThumbOffsetY() const | ||
1194 | 117 | { | ||
1195 | 118 | return mouse_offset_y_; | ||
1196 | 119 | } | ||
1197 | 120 | |||
1198 | 121 | nux::Geometry VScrollBarOverlayWindow::GetThumbGeometry() const | ||
1199 | 122 | { | ||
1200 | 123 | return nux::Geometry(content_size_.x + content_offset_x_, | ||
1201 | 124 | content_size_.y + mouse_offset_y_, | ||
1202 | 125 | THUMB_WIDTH, THUMB_HEIGHT); | ||
1203 | 126 | } | ||
1204 | 127 | |||
1205 | 128 | void VScrollBarOverlayWindow::MouseDown() | ||
1206 | 129 | { | ||
1207 | 130 | mouse_down_ = true; | ||
1208 | 131 | UpdateTexture(); | ||
1209 | 132 | } | ||
1210 | 133 | |||
1211 | 134 | void VScrollBarOverlayWindow::MouseUp() | ||
1212 | 135 | { | ||
1213 | 136 | mouse_down_ = false; | ||
1214 | 137 | current_action_ = ThumbAction::NONE; | ||
1215 | 138 | UpdateTexture(); | ||
1216 | 139 | ShouldHide(); | ||
1217 | 140 | } | ||
1218 | 141 | |||
1219 | 142 | void VScrollBarOverlayWindow::MouseNear() | ||
1220 | 143 | { | ||
1221 | 144 | mouse_near_ = true; | ||
1222 | 145 | ShouldShow(); | ||
1223 | 146 | } | ||
1224 | 147 | |||
1225 | 148 | void VScrollBarOverlayWindow::MouseBeyond() | ||
1226 | 149 | { | ||
1227 | 150 | mouse_near_ = false; | ||
1228 | 151 | ShouldHide(); | ||
1229 | 152 | } | ||
1230 | 153 | |||
1231 | 154 | void VScrollBarOverlayWindow::ThumbInsideSlider() | ||
1232 | 155 | { | ||
1233 | 156 | if (!inside_slider_) | ||
1234 | 157 | { | ||
1235 | 158 | inside_slider_ = true; | ||
1236 | 159 | UpdateTexture(); | ||
1237 | 160 | } | ||
1238 | 161 | } | ||
1239 | 162 | |||
1240 | 163 | void VScrollBarOverlayWindow::ThumbOutsideSlider() | ||
1241 | 164 | { | ||
1242 | 165 | if (inside_slider_) | ||
1243 | 166 | { | ||
1244 | 167 | inside_slider_ = false; | ||
1245 | 168 | UpdateTexture(); | ||
1246 | 169 | } | ||
1247 | 170 | } | ||
1248 | 171 | |||
1249 | 172 | void VScrollBarOverlayWindow::PageUpAction() | ||
1250 | 173 | { | ||
1251 | 174 | current_action_ = ThumbAction::PAGE_UP; | ||
1252 | 175 | UpdateTexture(); | ||
1253 | 176 | } | ||
1254 | 177 | |||
1255 | 178 | void VScrollBarOverlayWindow::PageDownAction() | ||
1256 | 179 | { | ||
1257 | 180 | current_action_ = ThumbAction::PAGE_DOWN; | ||
1258 | 181 | UpdateTexture(); | ||
1259 | 182 | } | ||
1260 | 183 | |||
1261 | 184 | void VScrollBarOverlayWindow::MouseDragging() | ||
1262 | 185 | { | ||
1263 | 186 | if (current_action_ != ThumbAction::DRAGGING) | ||
1264 | 187 | { | ||
1265 | 188 | current_action_ = ThumbAction::DRAGGING; | ||
1266 | 189 | UpdateTexture(); | ||
1267 | 190 | } | ||
1268 | 191 | } | ||
1269 | 192 | |||
1270 | 193 | void VScrollBarOverlayWindow::ShouldShow() | ||
1271 | 194 | { | ||
1272 | 195 | if (!IsVisible()) | ||
1273 | 196 | { | ||
1274 | 197 | if (mouse_down_ || mouse_near_) | ||
1275 | 198 | { | ||
1276 | 199 | ShowWindow(true); | ||
1277 | 200 | PushToFront(); | ||
1278 | 201 | QueueDraw(); | ||
1279 | 202 | } | ||
1280 | 203 | } | ||
1281 | 204 | } | ||
1282 | 205 | |||
1283 | 206 | void VScrollBarOverlayWindow::ShouldHide() | ||
1284 | 207 | { | ||
1285 | 208 | if (IsVisible()) | ||
1286 | 209 | { | ||
1287 | 210 | if (!mouse_down_ && !mouse_near_) | ||
1288 | 211 | { | ||
1289 | 212 | ShowWindow(false); | ||
1290 | 213 | QueueDraw(); | ||
1291 | 214 | } | ||
1292 | 215 | } | ||
1293 | 216 | } | ||
1294 | 217 | |||
1295 | 218 | void VScrollBarOverlayWindow::ResetStates() | ||
1296 | 219 | { | ||
1297 | 220 | mouse_down_ = false; | ||
1298 | 221 | mouse_near_ = false; | ||
1299 | 222 | current_action_ = ThumbAction::NONE; | ||
1300 | 223 | ShouldHide(); | ||
1301 | 224 | } | ||
1302 | 225 | |||
1303 | 226 | void VScrollBarOverlayWindow::Draw(nux::GraphicsEngine& graphics_engine, bool force_draw) | ||
1304 | 227 | { | ||
1305 | 228 | if (!thumb_texture_) | ||
1306 | 229 | return; | ||
1307 | 230 | |||
1308 | 231 | nux::Geometry base(0, mouse_offset_y_, THUMB_WIDTH, THUMB_HEIGHT); | ||
1309 | 232 | nux::TexCoordXForm texxform; | ||
1310 | 233 | |||
1311 | 234 | graphics_engine.QRP_1Tex(base.x, | ||
1312 | 235 | base.y, | ||
1313 | 236 | base.width, | ||
1314 | 237 | base.height, | ||
1315 | 238 | thumb_texture_->GetDeviceTexture(), | ||
1316 | 239 | texxform, | ||
1317 | 240 | nux::color::White); | ||
1318 | 241 | } | ||
1319 | 242 | |||
1320 | 243 | nux::color::RedGreenBlue ProduceColorShade(nux::color::RedGreenBlue const& rgb, float shade) | ||
1321 | 244 | { | ||
1322 | 245 | if (shade == 1.0f) | ||
1323 | 246 | return rgb; | ||
1324 | 247 | |||
1325 | 248 | nux::color::HueLightnessSaturation hls(rgb); | ||
1326 | 249 | |||
1327 | 250 | hls.lightness *= shade; | ||
1328 | 251 | if (hls.lightness > 1.0f) | ||
1329 | 252 | hls.lightness = 1.0f; | ||
1330 | 253 | else if (hls.lightness < 0.0f) | ||
1331 | 254 | hls.lightness = 0.0f; | ||
1332 | 255 | |||
1333 | 256 | hls.saturation *= shade; | ||
1334 | 257 | if (hls.saturation > 1.0f) | ||
1335 | 258 | hls.saturation = 1.0f; | ||
1336 | 259 | else if (hls.saturation < 0.0f) | ||
1337 | 260 | hls.saturation = 0.0f; | ||
1338 | 261 | |||
1339 | 262 | nux::color::RedGreenBlue rgb_shade(hls); | ||
1340 | 263 | |||
1341 | 264 | return rgb_shade; | ||
1342 | 265 | } | ||
1343 | 266 | |||
1344 | 267 | void PatternAddRGBStop(cairo_pattern_t* pat, nux::color::RedGreenBlue const& rgb, double stop, float alpha) | ||
1345 | 268 | { | ||
1346 | 269 | cairo_pattern_add_color_stop_rgba (pat, stop, rgb.red, rgb.green, rgb.blue, alpha); | ||
1347 | 270 | } | ||
1348 | 271 | |||
1349 | 272 | void SetSourceRGB(cairo_t* cr, nux::color::RedGreenBlue const& rgb, float alpha) | ||
1350 | 273 | { | ||
1351 | 274 | cairo_set_source_rgba(cr, rgb.red, rgb.green, rgb.blue, alpha); | ||
1352 | 275 | } | ||
1353 | 276 | |||
1354 | 277 | void DrawGrip (cairo_t* cr, double x, double y, int nx, int ny) | ||
1355 | 278 | { | ||
1356 | 279 | gint lx, ly; | ||
1357 | 280 | |||
1358 | 281 | for (ly = 0; ly < ny; ly++) | ||
1359 | 282 | { | ||
1360 | 283 | for (lx = 0; lx < nx; lx++) | ||
1361 | 284 | { | ||
1362 | 285 | gint sx = lx * 3; | ||
1363 | 286 | gint sy = ly * 3; | ||
1364 | 287 | |||
1365 | 288 | cairo_rectangle (cr, x + sx, y + sy, 1, 1); | ||
1366 | 289 | } | ||
1367 | 290 | } | ||
1368 | 291 | } | ||
1369 | 292 | |||
1370 | 293 | void DrawBothGrips(cairo_t* cr, nux::color::RedGreenBlue const& rgb, int width, int height) | ||
1371 | 294 | { | ||
1372 | 295 | int const grip_width = 5; | ||
1373 | 296 | int const grip_height = 6; | ||
1374 | 297 | float const grip_y = 13.5; | ||
1375 | 298 | float const offset = 6.5; | ||
1376 | 299 | |||
1377 | 300 | cairo_pattern_t* pat; | ||
1378 | 301 | pat = cairo_pattern_create_linear(0, 0, 0, height); | ||
1379 | 302 | |||
1380 | 303 | PatternAddRGBStop(pat, rgb, 0.0, 0.0); | ||
1381 | 304 | PatternAddRGBStop(pat, rgb, 0.49, 0.5); | ||
1382 | 305 | PatternAddRGBStop(pat, rgb, 0.49, 0.5); | ||
1383 | 306 | PatternAddRGBStop(pat, rgb, 1.0, 0.0); | ||
1384 | 307 | |||
1385 | 308 | cairo_set_source(cr, pat); | ||
1386 | 309 | cairo_pattern_destroy(pat); | ||
1387 | 310 | |||
1388 | 311 | DrawGrip(cr, width/2 - offset, grip_y, grip_width, grip_height); | ||
1389 | 312 | DrawGrip(cr, width/2 - offset, height/2 + (grip_y - 10), grip_width, grip_height); | ||
1390 | 313 | |||
1391 | 314 | cairo_fill(cr); | ||
1392 | 315 | } | ||
1393 | 316 | |||
1394 | 317 | void DrawLineSeperator(cairo_t* cr, nux::color::RedGreenBlue const& top, | ||
1395 | 318 | nux::color::RedGreenBlue const& bottom, int width, int height) | ||
1396 | 319 | { | ||
1397 | 320 | int const offset = 1.5; | ||
1398 | 321 | |||
1399 | 322 | // Top | ||
1400 | 323 | cairo_move_to(cr, offset, height/2); | ||
1401 | 324 | cairo_line_to(cr, width - offset, height/2); | ||
1402 | 325 | SetSourceRGB(cr, top, 0.36); | ||
1403 | 326 | cairo_stroke(cr); | ||
1404 | 327 | |||
1405 | 328 | // Bottom | ||
1406 | 329 | cairo_move_to(cr, offset, 1 + height/2); | ||
1407 | 330 | cairo_line_to(cr, width - offset, 1 + height/2); | ||
1408 | 331 | SetSourceRGB(cr, bottom, 0.5); | ||
1409 | 332 | cairo_stroke(cr); | ||
1410 | 333 | } | ||
1411 | 334 | |||
1412 | 335 | |||
1413 | 336 | void DrawArrow (cairo_t* cr, nux::color::RedGreenBlue const& rgb, double x, double y, double width, double height) | ||
1414 | 337 | { | ||
1415 | 338 | cairo_save (cr); | ||
1416 | 339 | |||
1417 | 340 | cairo_translate (cr, x, y); | ||
1418 | 341 | cairo_move_to (cr, -width / 2, -height / 2); | ||
1419 | 342 | cairo_line_to (cr, 0, height / 2); | ||
1420 | 343 | cairo_line_to (cr, width / 2, -height / 2); | ||
1421 | 344 | cairo_close_path (cr); | ||
1422 | 345 | |||
1423 | 346 | SetSourceRGB(cr, rgb, 0.75); | ||
1424 | 347 | cairo_fill_preserve (cr); | ||
1425 | 348 | |||
1426 | 349 | SetSourceRGB(cr, rgb, 1.0); | ||
1427 | 350 | cairo_stroke (cr); | ||
1428 | 351 | |||
1429 | 352 | cairo_restore (cr); | ||
1430 | 353 | } | ||
1431 | 354 | |||
1432 | 355 | void DrawBothArrows(cairo_t* cr, nux::color::RedGreenBlue const& rgb, int width, int height) | ||
1433 | 356 | { | ||
1434 | 357 | int const arrow_width = 5; | ||
1435 | 358 | int const arrow_height = 3; | ||
1436 | 359 | float const trans_height = 8.5; | ||
1437 | 360 | float const offset_x = 0.5; | ||
1438 | 361 | |||
1439 | 362 | // Top | ||
1440 | 363 | cairo_save(cr); | ||
1441 | 364 | cairo_translate(cr, width/2 + offset_x, trans_height); | ||
1442 | 365 | cairo_rotate(cr, G_PI); | ||
1443 | 366 | DrawArrow(cr, rgb, offset_x, 0, arrow_width, arrow_height); | ||
1444 | 367 | cairo_restore(cr); | ||
1445 | 368 | |||
1446 | 369 | // Bottom | ||
1447 | 370 | cairo_save(cr); | ||
1448 | 371 | cairo_translate(cr, width/2 + offset_x, height - trans_height); | ||
1449 | 372 | cairo_rotate(cr, 0); | ||
1450 | 373 | DrawArrow(cr, rgb, -offset_x, 0, arrow_width, arrow_height); | ||
1451 | 374 | cairo_restore(cr); | ||
1452 | 375 | } | ||
1453 | 376 | |||
1454 | 377 | void VScrollBarOverlayWindow::UpdateTexture() | ||
1455 | 378 | { | ||
1456 | 379 | int width = THUMB_WIDTH; | ||
1457 | 380 | int height = THUMB_HEIGHT; | ||
1458 | 381 | int radius = THUMB_RADIUS; | ||
1459 | 382 | |||
1460 | 383 | float const aspect = 1.0f; | ||
1461 | 384 | float current_x = 0.0f; | ||
1462 | 385 | float current_y = 0.0f; | ||
1463 | 386 | |||
1464 | 387 | cairo_t* cr = NULL; | ||
1465 | 388 | cairo_pattern_t* pat = NULL; | ||
1466 | 389 | |||
1467 | 390 | nux::color::RedGreenBlue const& bg = nux::color::WhiteSmoke; | ||
1468 | 391 | nux::color::RedGreenBlue const& bg_selected = nux::color::White; | ||
1469 | 392 | nux::color::RedGreenBlue const& bg_active = nux::color::Gray; | ||
1470 | 393 | nux::color::RedGreenBlue const& arrow_color = nux::color::DarkSlateGray; | ||
1471 | 394 | |||
1472 | 395 | nux::color::RedGreenBlue const& bg_arrow_up = ProduceColorShade(bg, 0.86); | ||
1473 | 396 | nux::color::RedGreenBlue const& bg_arrow_down = ProduceColorShade(bg, 1.1); | ||
1474 | 397 | nux::color::RedGreenBlue const& bg_shadow = ProduceColorShade(bg, 0.2); | ||
1475 | 398 | |||
1476 | 399 | nux::color::RedGreenBlue const& bg_dark_line = ProduceColorShade(bg, 0.4); | ||
1477 | 400 | nux::color::RedGreenBlue const& bg_bright_line = ProduceColorShade(bg, 1.2); | ||
1478 | 401 | |||
1479 | 402 | nux::CairoGraphics cairoGraphics(CAIRO_FORMAT_ARGB32, width, height); | ||
1480 | 403 | cr = cairoGraphics.GetContext(); | ||
1481 | 404 | |||
1482 | 405 | cairo_save(cr); | ||
1483 | 406 | |||
1484 | 407 | cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR); | ||
1485 | 408 | cairo_paint(cr); | ||
1486 | 409 | |||
1487 | 410 | cairo_save(cr); | ||
1488 | 411 | |||
1489 | 412 | cairo_translate (cr, 0.5, 0.5); | ||
1490 | 413 | width--; | ||
1491 | 414 | height--; | ||
1492 | 415 | |||
1493 | 416 | cairo_set_line_width (cr, 1.0); | ||
1494 | 417 | |||
1495 | 418 | cairo_set_operator(cr, CAIRO_OPERATOR_OVER); | ||
1496 | 419 | cairo_save(cr); | ||
1497 | 420 | |||
1498 | 421 | // Draw backgound | ||
1499 | 422 | SetSourceRGB(cr, bg, 1.0); | ||
1500 | 423 | cairoGraphics.DrawRoundedRectangle(cr, aspect, current_x, current_y, radius, width, height); | ||
1501 | 424 | cairo_fill_preserve(cr); | ||
1502 | 425 | |||
1503 | 426 | // Draw shaded background | ||
1504 | 427 | pat = cairo_pattern_create_linear(0, 0, 0, height); | ||
1505 | 428 | |||
1506 | 429 | PatternAddRGBStop(pat, bg_arrow_up, 0.0, 0.8); | ||
1507 | 430 | PatternAddRGBStop(pat, bg_arrow_down, 1.0, 0.8); | ||
1508 | 431 | |||
1509 | 432 | cairo_set_source(cr, pat); | ||
1510 | 433 | cairo_pattern_destroy(pat); | ||
1511 | 434 | |||
1512 | 435 | if (current_action_ == ThumbAction::DRAGGING) | ||
1513 | 436 | { | ||
1514 | 437 | cairo_fill_preserve(cr); | ||
1515 | 438 | SetSourceRGB(cr, bg, 0.8); | ||
1516 | 439 | cairo_fill(cr); | ||
1517 | 440 | } | ||
1518 | 441 | else | ||
1519 | 442 | { | ||
1520 | 443 | cairo_fill(cr); | ||
1521 | 444 | } | ||
1522 | 445 | |||
1523 | 446 | // Draw Page Up/Down Action | ||
1524 | 447 | if (current_action_ == ThumbAction::PAGE_UP || | ||
1525 | 448 | current_action_ == ThumbAction::PAGE_DOWN) | ||
1526 | 449 | { | ||
1527 | 450 | if (current_action_ == ThumbAction::PAGE_UP) | ||
1528 | 451 | cairo_rectangle(cr, 0, 0, width, height/2); | ||
1529 | 452 | else | ||
1530 | 453 | cairo_rectangle(cr, 0, height/2, width, height/2); | ||
1531 | 454 | |||
1532 | 455 | SetSourceRGB(cr, bg, 0.8); | ||
1533 | 456 | cairo_fill(cr); | ||
1534 | 457 | } | ||
1535 | 458 | |||
1536 | 459 | cairo_save(cr); | ||
1537 | 460 | |||
1538 | 461 | // Draw Outline | ||
1539 | 462 | cairo_set_line_width (cr, 2.0); | ||
1540 | 463 | |||
1541 | 464 | current_x += 0.5; | ||
1542 | 465 | current_y += 0.5; | ||
1543 | 466 | cairoGraphics.DrawRoundedRectangle(cr, aspect, current_x, current_y, radius - 1, width - 1, height - 1); | ||
1544 | 467 | |||
1545 | 468 | if (inside_slider_) | ||
1546 | 469 | SetSourceRGB(cr, bg_selected, 1.0); | ||
1547 | 470 | else | ||
1548 | 471 | SetSourceRGB(cr, bg_active, 0.9); | ||
1549 | 472 | |||
1550 | 473 | cairo_stroke(cr); | ||
1551 | 474 | |||
1552 | 475 | cairo_restore(cr); | ||
1553 | 476 | |||
1554 | 477 | // Draw shade outline | ||
1555 | 478 | pat = cairo_pattern_create_linear(0, 0, 0, height); | ||
1556 | 479 | |||
1557 | 480 | PatternAddRGBStop(pat, bg_shadow, 0.5, 0.06); | ||
1558 | 481 | |||
1559 | 482 | switch(current_action_) | ||
1560 | 483 | { | ||
1561 | 484 | case ThumbAction::NONE: | ||
1562 | 485 | PatternAddRGBStop(pat, bg_shadow, 0.0, 0.22); | ||
1563 | 486 | PatternAddRGBStop(pat, bg_shadow, 1.0, 0.22); | ||
1564 | 487 | break; | ||
1565 | 488 | case ThumbAction::DRAGGING: | ||
1566 | 489 | PatternAddRGBStop(pat, bg_shadow, 0.0, 0.2); | ||
1567 | 490 | PatternAddRGBStop(pat, bg_shadow, 1.0, 0.2); | ||
1568 | 491 | break; | ||
1569 | 492 | case ThumbAction::PAGE_UP: | ||
1570 | 493 | PatternAddRGBStop(pat, bg_shadow, 0.0, 0.1); | ||
1571 | 494 | PatternAddRGBStop(pat, bg_shadow, 1.0, 0.22); | ||
1572 | 495 | break; | ||
1573 | 496 | case ThumbAction::PAGE_DOWN: | ||
1574 | 497 | PatternAddRGBStop(pat, bg_shadow, 0.0, 0.22); | ||
1575 | 498 | PatternAddRGBStop(pat, bg_shadow, 1.0, 0.1); | ||
1576 | 499 | break; | ||
1577 | 500 | default: | ||
1578 | 501 | break; | ||
1579 | 502 | } | ||
1580 | 503 | |||
1581 | 504 | cairo_set_source(cr, pat); | ||
1582 | 505 | cairo_pattern_destroy(pat); | ||
1583 | 506 | |||
1584 | 507 | current_x += 0.5; | ||
1585 | 508 | current_y += 0.5; | ||
1586 | 509 | cairoGraphics.DrawRoundedRectangle(cr, aspect, current_x, current_y, radius, width- 2, height - 2); | ||
1587 | 510 | cairo_stroke(cr); | ||
1588 | 511 | |||
1589 | 512 | current_x += 1.0; | ||
1590 | 513 | current_y += 1.0; | ||
1591 | 514 | cairoGraphics.DrawRoundedRectangle(cr, aspect, current_x, current_y, radius - 1, width - 4, height- 4); | ||
1592 | 515 | SetSourceRGB(cr, bg_bright_line, 0.6); | ||
1593 | 516 | cairo_stroke(cr); | ||
1594 | 517 | |||
1595 | 518 | DrawBothGrips(cr, bg_dark_line, width, height); | ||
1596 | 519 | DrawLineSeperator(cr, bg_dark_line, bg_bright_line, width, height); | ||
1597 | 520 | DrawBothArrows(cr, arrow_color, width, height); | ||
1598 | 521 | |||
1599 | 522 | thumb_texture_.Adopt(unity::texture_from_cairo_graphics(cairoGraphics)); | ||
1600 | 523 | cairo_destroy(cr); | ||
1601 | 524 | |||
1602 | 525 | QueueDraw(); | ||
1603 | 526 | } | ||
1604 | 0 | 527 | ||
1605 | === added file 'unity-shared/VScrollBarOverlayWindow.h' | |||
1606 | --- unity-shared/VScrollBarOverlayWindow.h 1970-01-01 00:00:00 +0000 | |||
1607 | +++ unity-shared/VScrollBarOverlayWindow.h 2012-11-23 23:52:20 +0000 | |||
1608 | @@ -0,0 +1,92 @@ | |||
1609 | 1 | // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- | ||
1610 | 2 | /* | ||
1611 | 3 | * Copyright (C) 2012 Canonical Ltd | ||
1612 | 4 | * | ||
1613 | 5 | * This program is free software: you can redistribute it and/or modify | ||
1614 | 6 | * it under the terms of the GNU General Public License version 3 as | ||
1615 | 7 | * published by the Free Software Foundation. | ||
1616 | 8 | * | ||
1617 | 9 | * This program is distributed in the hope that it will be useful, | ||
1618 | 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1619 | 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1620 | 12 | * GNU General Public License for more details. | ||
1621 | 13 | * | ||
1622 | 14 | * You should have received a copy of the GNU General Public License | ||
1623 | 15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1624 | 16 | * | ||
1625 | 17 | * Authored by: Brandon Schaefer <brandon.schaefer@canonical.com> | ||
1626 | 18 | */ | ||
1627 | 19 | |||
1628 | 20 | |||
1629 | 21 | #ifndef VSCROLLBAR_OVERLAY_WINDOW_H | ||
1630 | 22 | #define VSCROLLBAR_OVERLAY_WINDOW_H | ||
1631 | 23 | |||
1632 | 24 | #include <Nux/Nux.h> | ||
1633 | 25 | #include <Nux/BaseWindow.h> | ||
1634 | 26 | |||
1635 | 27 | |||
1636 | 28 | class VScrollBarOverlayWindow : public nux::BaseWindow | ||
1637 | 29 | { | ||
1638 | 30 | public: | ||
1639 | 31 | VScrollBarOverlayWindow(nux::Geometry const& geo); | ||
1640 | 32 | |||
1641 | 33 | void UpdateGeometry(nux::Geometry const& geo); | ||
1642 | 34 | void SetThumbOffsetY(int y); | ||
1643 | 35 | |||
1644 | 36 | void MouseDown(); | ||
1645 | 37 | void MouseUp(); | ||
1646 | 38 | |||
1647 | 39 | void MouseNear(); | ||
1648 | 40 | void MouseBeyond(); | ||
1649 | 41 | |||
1650 | 42 | void ThumbInsideSlider(); | ||
1651 | 43 | void ThumbOutsideSlider(); | ||
1652 | 44 | |||
1653 | 45 | void PageUpAction(); | ||
1654 | 46 | void PageDownAction(); | ||
1655 | 47 | |||
1656 | 48 | bool IsMouseInsideThumb(int y) const; | ||
1657 | 49 | bool IsMouseBeingDragged() const; | ||
1658 | 50 | |||
1659 | 51 | int GetThumbHeight() const; | ||
1660 | 52 | int GetThumbOffsetY() const; | ||
1661 | 53 | |||
1662 | 54 | nux::Geometry GetThumbGeometry() const; | ||
1663 | 55 | |||
1664 | 56 | void ResetStates(); | ||
1665 | 57 | |||
1666 | 58 | protected: | ||
1667 | 59 | virtual void Draw(nux::GraphicsEngine& graphics_engine, bool force_draw); | ||
1668 | 60 | |||
1669 | 61 | private: | ||
1670 | 62 | enum class ThumbAction : unsigned int | ||
1671 | 63 | { | ||
1672 | 64 | NONE, | ||
1673 | 65 | DRAGGING, | ||
1674 | 66 | PAGE_UP, | ||
1675 | 67 | PAGE_DOWN | ||
1676 | 68 | }; | ||
1677 | 69 | |||
1678 | 70 | void MouseDragging(); | ||
1679 | 71 | void UpdateMouseOffsetX(); | ||
1680 | 72 | int GetValidOffsetYValue(int y) const; | ||
1681 | 73 | |||
1682 | 74 | void ShouldShow(); | ||
1683 | 75 | void ShouldHide(); | ||
1684 | 76 | |||
1685 | 77 | void UpdateTexture(); | ||
1686 | 78 | |||
1687 | 79 | nux::Geometry content_size_; | ||
1688 | 80 | nux::ObjectPtr<nux::BaseTexture> thumb_texture_; | ||
1689 | 81 | |||
1690 | 82 | int content_offset_x_; | ||
1691 | 83 | int mouse_offset_y_; | ||
1692 | 84 | |||
1693 | 85 | bool mouse_down_; | ||
1694 | 86 | bool mouse_near_; | ||
1695 | 87 | bool inside_slider_; | ||
1696 | 88 | |||
1697 | 89 | ThumbAction current_action_; | ||
1698 | 90 | }; | ||
1699 | 91 | |||
1700 | 92 | #endif |
First of all, looking at the screencast: awesome work!
430 + _prox_area = std::make_ shared< nux::ProximityA rea>(_overlay_ window. GetPointer( ), 7);
I like shared pointers, but since we're using a view here I think you should use an ObjectPtr instead. Also please remember to put the magic number to a global constant, so that is defined and easily editable.
773 +VScrollBarOver layWindow: :VScrollBarOver layWindow( const nux::Geometry geo) de(bg, 0.2); de(bg, 0.4); de(bg, 1.2);
970 + nux::Color color = nux::color::White;
1208 + nux::Color bg_shadow = ProduceColorSha
1239 + nux::Color bg_dark_line = ProduceColorSha
1240 + nux::Color bg_bright_line = ProduceColorSha
const& ;)
971 + nux::Geometry base = content_size_; mouse_offset_ y_); THUMB_WIDTH) ; THUMB_HEIGHT) ;
972 + base.SetX(0);
973 + base.SetY(
974 + base.SetWidth(
975 + base.SetHeight(
No need to copy content_size_ here since you're changing everything, just initialize a new Geometry.
979 + if (!thumb_texture_)
980 + return;
Add this on top of the function... It's always better to return as soon as you can to avoid unneeded computation.
1130 + cairoGraphics = new nux::CairoGraph ics(CAIRO_ FORMAT_ ARGB32, width, height);
Don't use a pointer here, you don't need it.
1250 + if (thumb_texture_) ->UnReference( );
1251 + thumb_texture_
You don't need this, just do: .Adopt( unity:: texture_ from_cairo_ graphics( *cairoGraphics) );
thumb_texture_
1255 + delete cairoGraphics;
Remove it with the pointer ;)
I see a lot of public methods in VScrollBarOverl ayWindow and PlacesOverlayVS crollBar. Please make them private when possible and at least protected when you need them for testing (even if in that case you could just use the "friendship hack" to get things testable anyway).