Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
97b25712
Commit
97b25712
authored
Sep 16, 2015
by
Collin Jackson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update scale API and add example
parent
842e94e9
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
144 additions
and
70 deletions
+144
-70
scale.dart
examples/widgets/scale.dart
+72
-0
constants.dart
packages/flutter/lib/gestures/constants.dart
+1
-1
drag.dart
packages/flutter/lib/gestures/drag.dart
+0
-1
scale.dart
packages/flutter/lib/gestures/scale.dart
+43
-42
gesture_detector.dart
packages/flutter/lib/src/widgets/gesture_detector.dart
+28
-26
No files found.
examples/widgets/scale.dart
0 → 100644
View file @
97b25712
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'dart:math'
as
math
;
import
'package:sky/rendering.dart'
;
import
'package:sky/theme/colors.dart'
as
colors
;
import
'package:sky/widgets.dart'
;
class
ScaleApp
extends
App
{
Point
_startingFocalPoint
;
Offset
_previousOffset
;
Offset
_offset
;
double
_previousZoom
;
double
_zoom
;
void
initState
()
{
_offset
=
Offset
.
zero
;
_zoom
=
1.0
;
}
void
_handleScaleStart
(
Point
focalPoint
)
{
setState
(()
{
_startingFocalPoint
=
focalPoint
;
_previousOffset
=
_offset
;
_previousZoom
=
_zoom
;
});
}
void
_handleScaleUpdate
(
double
scale
,
Point
focalPoint
)
{
setState
(()
{
_zoom
=
_previousZoom
*
scale
;
_offset
=
_previousOffset
+
(
focalPoint
-
_startingFocalPoint
)
/
_zoom
;
});
}
void
paint
(
PaintingCanvas
canvas
,
Size
size
)
{
Point
center
=
size
.
center
(
Point
.
origin
)
+
_offset
*
_zoom
;
double
radius
=
size
.
width
/
2.0
*
_zoom
;
Gradient
gradient
=
new
RadialGradient
(
center:
center
,
radius:
radius
,
colors:
[
colors
.
Blue
[
200
],
colors
.
Blue
[
800
]]
);
Paint
paint
=
new
Paint
()
..
shader
=
gradient
.
createShader
();
canvas
.
drawCircle
(
center
,
radius
,
paint
);
}
Widget
build
()
{
return
new
Theme
(
data:
new
ThemeData
.
dark
(),
child:
new
Scaffold
(
toolbar:
new
ToolBar
(
center:
new
Text
(
'Scale Demo'
)),
body:
new
Material
(
type:
MaterialType
.
canvas
,
child:
new
GestureDetector
(
onScaleStart:
_handleScaleStart
,
onScaleUpdate:
_handleScaleUpdate
,
child:
new
CustomPaint
(
callback:
paint
,
token:
"
$_zoom
$_offset
"
)
)
)
)
);
}
}
void
main
(
)
=>
runApp
(
new
ScaleApp
());
packages/flutter/lib/gestures/constants.dart
View file @
97b25712
...
...
@@ -18,7 +18,7 @@ const double kTouchSlop = 8.0; // Logical pixels
const
double
kDoubleTapTouchSlop
=
kTouchSlop
;
// Logical pixels
const
double
kPagingTouchSlop
=
kTouchSlop
*
2.0
;
// Logical pixels
const
double
kPanSlop
=
kTouchSlop
*
2.0
;
// Logical pixels
const
double
k
Pinch
Slop
=
kTouchSlop
;
// Logical pixels
const
double
k
Scale
Slop
=
kTouchSlop
;
// Logical pixels
const
double
kDoubleTapSlop
=
100.0
;
// Logical pixels
const
double
kWindowTouchSlop
=
16.0
;
// Logical pixels
const
double
kMinFlingVelocity
=
50.0
;
// Logical pixels / second
...
...
packages/flutter/lib/gestures/drag.dart
View file @
97b25712
...
...
@@ -100,7 +100,6 @@ abstract class _DragGestureRecognizer<T extends dynamic> extends GestureRecogniz
sky
.
Offset
velocity
=
sky
.
Offset
.
zero
;
if
(
_isFlingGesture
(
gestureVelocity
))
velocity
=
new
sky
.
Offset
(
gestureVelocity
.
x
,
gestureVelocity
.
y
);
resolve
(
GestureDisposition
.
accepted
);
onEnd
(
velocity
);
}
_velocityTracker
.
reset
();
...
...
packages/flutter/lib/gestures/
pinch
.dart
→
packages/flutter/lib/gestures/
scale
.dart
View file @
97b25712
...
...
@@ -9,37 +9,37 @@ import 'package:sky/gestures/arena.dart';
import
'package:sky/gestures/recognizer.dart'
;
import
'package:sky/gestures/constants.dart'
;
enum
Pinch
State
{
enum
Scale
State
{
ready
,
possible
,
star
ted
,
end
ed
accep
ted
,
start
ed
}
typedef
void
Gesture
PinchStartCallback
(
);
typedef
void
Gesture
PinchUpdateCallback
(
double
scale
);
typedef
void
Gesture
Pinch
EndCallback
(
);
typedef
void
Gesture
ScaleStartCallback
(
sky
.
Point
focalPoint
);
typedef
void
Gesture
ScaleUpdateCallback
(
double
scale
,
sky
.
Point
focalPoint
);
typedef
void
Gesture
Scale
EndCallback
(
);
class
Pinch
GestureRecognizer
extends
GestureRecognizer
{
Pinch
GestureRecognizer
({
PointerRouter
router
,
this
.
onStart
,
this
.
onUpdate
,
this
.
onEnd
})
class
Scale
GestureRecognizer
extends
GestureRecognizer
{
Scale
GestureRecognizer
({
PointerRouter
router
,
this
.
onStart
,
this
.
onUpdate
,
this
.
onEnd
})
:
super
(
router:
router
);
Gesture
Pinch
StartCallback
onStart
;
Gesture
Pinch
UpdateCallback
onUpdate
;
Gesture
Pinch
EndCallback
onEnd
;
Gesture
Scale
StartCallback
onStart
;
Gesture
Scale
UpdateCallback
onUpdate
;
Gesture
Scale
EndCallback
onEnd
;
PinchState
_state
=
Pinch
State
.
ready
;
ScaleState
_state
=
Scale
State
.
ready
;
double
_initialSpan
;
double
_currentSpan
;
Map
<
int
,
sky
.
Point
>
_pointerLocations
;
double
get
_scaleFactor
=>
_initialSpan
>
0
?
_currentSpan
/
_initialSpan
:
1.0
;
double
get
_scaleFactor
=>
_initialSpan
>
0
.0
?
_currentSpan
/
_initialSpan
:
1.0
;
void
addPointer
(
sky
.
PointerEvent
event
)
{
startTrackingPointer
(
event
.
pointer
);
if
(
_state
==
Pinch
State
.
ready
)
{
_state
=
Pinch
State
.
possible
;
if
(
_state
==
Scale
State
.
ready
)
{
_state
=
Scale
State
.
possible
;
_initialSpan
=
0.0
;
_currentSpan
=
0.0
;
_pointerLocations
=
new
Map
<
int
,
sky
.
Point
>();
...
...
@@ -47,7 +47,7 @@ class PinchGestureRecognizer extends GestureRecognizer {
}
void
handleEvent
(
sky
.
PointerEvent
event
)
{
assert
(
_state
!=
Pinch
State
.
ready
);
assert
(
_state
!=
Scale
State
.
ready
);
bool
configChanged
=
false
;
switch
(
event
.
type
)
{
case
'pointerup'
:
...
...
@@ -63,6 +63,12 @@ class PinchGestureRecognizer extends GestureRecognizer {
break
;
}
_update
(
configChanged
);
stopTrackingIfPointerNoLongerDown
(
event
);
}
void
_update
(
bool
configChanged
)
{
int
count
=
_pointerLocations
.
keys
.
length
;
// Compute the focal point
...
...
@@ -79,58 +85,53 @@ class PinchGestureRecognizer extends GestureRecognizer {
if
(
configChanged
)
{
_initialSpan
=
_currentSpan
;
if
(
_state
==
PinchState
.
started
)
{
_state
=
PinchState
.
ended
;
if
(
_state
==
ScaleState
.
started
)
{
if
(
onEnd
!=
null
)
onEnd
();
_state
=
ScaleState
.
accepted
;
}
}
if
(
_state
==
Pinch
State
.
ready
)
_state
=
Pinch
State
.
possible
;
if
(
_state
==
Scale
State
.
ready
)
_state
=
Scale
State
.
possible
;
if
(
_state
==
Pinch
State
.
possible
&&
(
_currentSpan
-
_initialSpan
).
abs
()
>
k
Pinch
Slop
)
{
if
(
_state
==
Scale
State
.
possible
&&
(
_currentSpan
-
_initialSpan
).
abs
()
>
k
Scale
Slop
)
{
resolve
(
GestureDisposition
.
accepted
);
}
if
(
_state
==
PinchState
.
ended
&&
_currentSpan
!=
_initialSpan
)
{
_state
=
Pinch
State
.
started
;
if
(
_state
==
ScaleState
.
accepted
&&
!
configChanged
)
{
_state
=
Scale
State
.
started
;
if
(
onStart
!=
null
)
onStart
();
onStart
(
focalPoint
);
}
if
(
_state
==
PinchState
.
started
&&
onUpdate
!=
null
)
onUpdate
(
_scaleFactor
);
stopTrackingIfPointerNoLongerDown
(
event
);
if
(
_state
==
ScaleState
.
started
&&
onUpdate
!=
null
)
onUpdate
(
_scaleFactor
,
focalPoint
);
}
void
acceptGesture
(
int
pointer
)
{
if
(
_state
!=
PinchState
.
started
)
{
_state
=
PinchState
.
started
;
if
(
onStart
!=
null
)
onStart
();
if
(
onUpdate
!=
null
)
onUpdate
(
_scaleFactor
);
if
(
_state
!=
ScaleState
.
accepted
)
{
_state
=
ScaleState
.
accepted
;
_update
(
false
);
}
}
void
didStopTrackingLastPointer
(
int
pointer
)
{
switch
(
_state
)
{
case
Pinch
State
.
possible
:
case
Scale
State
.
possible
:
resolve
(
GestureDisposition
.
rejected
);
break
;
case
Pinch
State
.
ready
:
assert
(
false
);
case
Scale
State
.
ready
:
assert
(
false
);
// We should have not seen a pointer yet
break
;
case
PinchState
.
started
:
assert
(
false
);
case
ScaleState
.
accepted
:
break
;
case
PinchState
.
ended
:
case
ScaleState
.
started
:
assert
(
false
);
// We should be in the accepted state when user is done
break
;
}
_state
=
Pinch
State
.
ready
;
_state
=
Scale
State
.
ready
;
}
void
dispose
()
{
...
...
packages/flutter/lib/src/widgets/gesture_detector.dart
View file @
97b25712
...
...
@@ -6,7 +6,7 @@ import 'dart:sky' as sky;
import
'package:sky/gestures/drag.dart'
;
import
'package:sky/gestures/long_press.dart'
;
import
'package:sky/gestures/
pinch
.dart'
;
import
'package:sky/gestures/
scale
.dart'
;
import
'package:sky/gestures/recognizer.dart'
;
import
'package:sky/gestures/show_press.dart'
;
import
'package:sky/gestures/tap.dart'
;
...
...
@@ -29,9 +29,9 @@ class GestureDetector extends StatefulComponent {
this
.
onPanStart
,
this
.
onPanUpdate
,
this
.
onPanEnd
,
this
.
on
Pinch
Start
,
this
.
on
Pinch
Update
,
this
.
on
Pinch
End
this
.
on
Scale
Start
,
this
.
on
Scale
Update
,
this
.
on
Scale
End
})
:
super
(
key:
key
);
Widget
child
;
...
...
@@ -51,9 +51,9 @@ class GestureDetector extends StatefulComponent {
GesturePanUpdateCallback
onPanUpdate
;
GesturePanEndCallback
onPanEnd
;
Gesture
PinchStartCallback
onPinch
Start
;
Gesture
PinchUpdateCallback
onPinch
Update
;
Gesture
PinchEndCallback
onPinch
End
;
Gesture
ScaleStartCallback
onScale
Start
;
Gesture
ScaleUpdateCallback
onScale
Update
;
Gesture
ScaleEndCallback
onScale
End
;
void
syncConstructorArguments
(
GestureDetector
source
)
{
child
=
source
.
child
;
...
...
@@ -69,9 +69,9 @@ class GestureDetector extends StatefulComponent {
onPanStart
=
source
.
onPanStart
;
onPanUpdate
=
source
.
onPanUpdate
;
onPanEnd
=
source
.
onPanEnd
;
on
PinchStart
=
source
.
onPinch
Start
;
on
PinchUpdate
=
source
.
onPinch
Update
;
on
PinchEnd
=
source
.
onPinch
End
;
on
ScaleStart
=
source
.
onScale
Start
;
on
ScaleUpdate
=
source
.
onScale
Update
;
on
ScaleEnd
=
source
.
onScale
End
;
_syncGestureListeners
();
}
...
...
@@ -114,16 +114,18 @@ class GestureDetector extends StatefulComponent {
PanGestureRecognizer
_pan
;
PanGestureRecognizer
_ensurePan
()
{
assert
(
_scale
==
null
);
// Scale is a superset of pan; just use scale
if
(
_pan
==
null
)
_pan
=
new
PanGestureRecognizer
(
router:
_router
);
return
_pan
;
}
PinchGestureRecognizer
_pinch
;
PinchGestureRecognizer
_ensurePinch
()
{
if
(
_pinch
==
null
)
_pinch
=
new
PinchGestureRecognizer
(
router:
_router
);
return
_pinch
;
ScaleGestureRecognizer
_scale
;
ScaleGestureRecognizer
_ensureScale
()
{
assert
(
_pan
==
null
);
// Scale is a superset of pan; just use scale
if
(
_scale
==
null
)
_scale
=
new
ScaleGestureRecognizer
(
router:
_router
);
return
_scale
;
}
void
didMount
()
{
...
...
@@ -139,7 +141,7 @@ class GestureDetector extends StatefulComponent {
_verticalDrag
=
_ensureDisposed
(
_verticalDrag
);
_horizontalDrag
=
_ensureDisposed
(
_horizontalDrag
);
_pan
=
_ensureDisposed
(
_pan
);
_
pinch
=
_ensureDisposed
(
_pinch
);
_
scale
=
_ensureDisposed
(
_scale
);
}
void
_syncGestureListeners
()
{
...
...
@@ -149,7 +151,7 @@ class GestureDetector extends StatefulComponent {
_syncVerticalDrag
();
_syncHorizontalDrag
();
_syncPan
();
_sync
Pinch
();
_sync
Scale
();
}
void
_syncTap
()
{
...
...
@@ -206,14 +208,14 @@ class GestureDetector extends StatefulComponent {
}
}
void
_sync
Pinch
()
{
if
(
on
PinchStart
==
null
&&
onPinchUpdate
==
null
&&
onPinch
End
==
null
)
{
_
pinch
=
_ensureDisposed
(
_pan
);
void
_sync
Scale
()
{
if
(
on
ScaleStart
==
null
&&
onScaleUpdate
==
null
&&
onScale
End
==
null
)
{
_
scale
=
_ensureDisposed
(
_pan
);
}
else
{
_ensure
Pinch
()
..
onStart
=
on
Pinch
Start
..
onUpdate
=
on
Pinch
Update
..
onEnd
=
on
Pinch
End
;
_ensure
Scale
()
..
onStart
=
on
Scale
Start
..
onUpdate
=
on
Scale
Update
..
onEnd
=
on
Scale
End
;
}
}
...
...
@@ -235,8 +237,8 @@ class GestureDetector extends StatefulComponent {
_horizontalDrag
.
addPointer
(
event
);
if
(
_pan
!=
null
)
_pan
.
addPointer
(
event
);
if
(
_
pinch
!=
null
)
_
pinch
.
addPointer
(
event
);
if
(
_
scale
!=
null
)
_
scale
.
addPointer
(
event
);
return
EventDisposition
.
processed
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment