Merge lp:~brandontschaefer/unity/lp.982543-add-y-break-zone into lp:unity

Proposed by Brandon Schaefer
Status: Merged
Approved by: Marco Trevisan (Treviño)
Approved revision: no longer in the source branch.
Merged at revision: 3157
Proposed branch: lp:~brandontschaefer/unity/lp.982543-add-y-break-zone
Merge into: lp:unity
Diff against target: 107 lines (+60/-3)
3 files modified
launcher/EdgeBarrierController.cpp (+33/-3)
launcher/EdgeBarrierControllerPrivate.h (+2/-0)
tests/test_edge_barrier_controller.cpp (+25/-0)
To merge this branch: bzr merge lp:~brandontschaefer/unity/lp.982543-add-y-break-zone
Reviewer Review Type Date Requested Status
Marco Trevisan (Treviño) Approve
PS Jenkins bot continuous-integration Pending
Review via email: mp+148302@code.launchpad.net

Commit message

Adds a Y break zone on the barrier so you can only break the barrier if pushing hard enough within this zone. Otherwise it resets the decay.

Description of the change

=== Problem ===
When moving against the barrier along the y axis, you can still break through the barrier. This can be annoying if you want to do something along the launcher.

=== Fix ===
Only allow the barriers to be broken if you are pushing up against the barrier in a small area of the Y axis. Right now it takes the event.y plus a 20 on both sides of the y axis. This gives 40 on the y axis to where you can break the barrier, if you move out of it, it resets the barrier decay to 0.

=== Tests ===
2 unit tests.

To post a comment you must log in.
Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

It works as expected, thanks.
A nice addon could have been a new setting, but that's something that we don't really need a this point.

Revision history for this message
Marco Trevisan (Treviño) (3v1n0) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'launcher/EdgeBarrierController.cpp'
2--- launcher/EdgeBarrierController.cpp 2013-02-08 01:00:23 +0000
3+++ launcher/EdgeBarrierController.cpp 2013-02-13 19:46:24 +0000
4@@ -24,8 +24,15 @@
5 #include "unity-shared/UScreen.h"
6 #include "UnityCore/GLibSource.h"
7
8-namespace unity {
9-namespace ui {
10+namespace unity
11+{
12+namespace ui
13+{
14+
15+namespace
16+{
17+ int const Y_BREAK_BUFFER = 20;
18+}
19
20
21 EdgeBarrierController::Impl::Impl(EdgeBarrierController *parent)
22@@ -119,7 +126,14 @@
23
24 void EdgeBarrierController::Impl::BarrierPush(PointerBarrierWrapper* owner, BarrierEvent::Ptr const& event)
25 {
26- decaymulator_.value = decaymulator_.value + event->velocity;
27+ if (EventIsInsideYBreakZone(event))
28+ {
29+ decaymulator_.value = decaymulator_.value + event->velocity;
30+ }
31+ else
32+ {
33+ BarrierReset();
34+ }
35
36 if (decaymulator_.value > edge_overcome_pressure_)
37 {
38@@ -127,6 +141,22 @@
39 }
40 }
41
42+bool EdgeBarrierController::Impl::EventIsInsideYBreakZone(BarrierEvent::Ptr const& event)
43+{
44+ static int y_break_zone = event->y;
45+
46+ if (decaymulator_.value <= 0)
47+ y_break_zone = event->y;
48+
49+ if (event->y <= y_break_zone + Y_BREAK_BUFFER &&
50+ event->y >= y_break_zone - Y_BREAK_BUFFER)
51+ {
52+ return true;
53+ }
54+
55+ return false;
56+}
57+
58 void EdgeBarrierController::Impl::OnPointerBarrierEvent(PointerBarrierWrapper* owner, BarrierEvent::Ptr const& event)
59 {
60 if (owner->released)
61
62=== modified file 'launcher/EdgeBarrierControllerPrivate.h'
63--- launcher/EdgeBarrierControllerPrivate.h 2013-02-07 21:47:21 +0000
64+++ launcher/EdgeBarrierControllerPrivate.h 2013-02-13 19:46:24 +0000
65@@ -42,6 +42,8 @@
66 void BarrierRelease(PointerBarrierWrapper* owner, int event);
67 void BarrierReset();
68
69+ bool EventIsInsideYBreakZone(BarrierEvent::Ptr const& event);
70+
71 std::vector<PointerBarrierWrapper::Ptr> barriers_;
72 std::vector<EdgeBarrierSubscriber*> subscribers_;
73 Decaymulator decaymulator_;
74
75=== modified file 'tests/test_edge_barrier_controller.cpp'
76--- tests/test_edge_barrier_controller.cpp 2013-02-08 01:00:23 +0000
77+++ tests/test_edge_barrier_controller.cpp 2013-02-13 19:46:24 +0000
78@@ -342,4 +342,29 @@
79 ASSERT_EQ(barrier->direction, BarrierDirection::BOTH);
80 }
81
82+TEST_F(TestEdgeBarrierController, BarrierDoesNotBreakIfYEventToFarApart)
83+{
84+ MockPointerBarrier owner;
85+
86+ int velocity = bc.options()->edge_overcome_pressure() * bc.options()->edge_responsiveness();
87+ auto firstEvent = std::make_shared<BarrierEvent>(0, 50, velocity, 10);
88+ auto secondEvent = std::make_shared<BarrierEvent>(0, 150, velocity, 11);
89+
90+ EXPECT_CALL(owner, ReleaseBarrier(_)).Times(0);
91+ ProcessBarrierEvent(&owner, firstEvent);
92+ ProcessBarrierEvent(&owner, secondEvent);
93+}
94+
95+TEST_F(TestEdgeBarrierController, BarrierBreaksInYBreakZone)
96+{
97+ MockPointerBarrier owner;
98+
99+ int velocity = bc.options()->edge_overcome_pressure() * bc.options()->edge_responsiveness();
100+ auto firstEvent = std::make_shared<BarrierEvent>(0, 50, velocity, 10);
101+
102+ EXPECT_CALL(owner, ReleaseBarrier(_)).Times(1);
103+ ProcessBarrierEvent(&owner, firstEvent);
104+ ProcessBarrierEvent(&owner, firstEvent);
105+}
106+
107 }