Ian Hickson a94999ba50 Clean up imports and exports.
Each layer is supposed to reexport the parts of the previous layer
that are part of its API.

- In painting.dart, export from dart:ui all the Canvas-related APIs
  that make sense to be used at higher levels, e.g. PaintingStyle.

- Delete painting/shadows.dart. It was dead code.

- In rendering/object.dart, export all of painting.dart.

- In widgets/basic.dart, export all of painting.dart and
  animation.dart. Some classes in animation/ are renamed to make this
  less disruptive and confusing to the namespace.

- Split out Stocks back into an import model rather than a part model,
  so that it's easier to manage its dependencies on a per-file basis.

- Move Ticker to scheduler library.

- Remove as many redundant imports as possible now.

- Some minor nit picking cleanup in various files.
2016-02-11 00:06:23 -08:00

63 lines
1.8 KiB
Dart

part of flutter_sprites;
class VirtualJoystick extends NodeWithSize {
VirtualJoystick() : super(new Size(160.0, 160.0)) {
userInteractionEnabled = true;
handleMultiplePointers = false;
position = new Point(160.0, -20.0);
pivot = new Point(0.5, 1.0);
_center = new Point(size.width / 2.0, size.height / 2.0);
_handlePos = _center;
_paintHandle = new Paint()
..color=new Color(0xffffffff);
_paintControl = new Paint()
..color=new Color(0xffffffff)
..strokeWidth = 1.0
..style = PaintingStyle.stroke;
}
Point _value = Point.origin;
Point get value => _value;
bool _isDown = false;
bool get isDown => _isDown;
Point _pointerDownAt;
Point _center;
Point _handlePos;
Paint _paintHandle;
Paint _paintControl;
bool handleEvent(SpriteBoxEvent event) {
if (event.type == PointerDownEvent) {
_pointerDownAt = event.boxPosition;
actions.stopAll();
_isDown = true;
}
else if (event.type == PointerUpEvent || event.type == PointerCancelEvent) {
_pointerDownAt = null;
_value = Point.origin;
ActionTween moveToCenter = new ActionTween((a) => _handlePos = a, _handlePos, _center, 0.4, Curves.elasticOut);
actions.run(moveToCenter);
_isDown = false;
} else if (event.type == PointerMoveEvent) {
Offset movedDist = event.boxPosition - _pointerDownAt;
_value = new Point(
(movedDist.dx / 80.0).clamp(-1.0, 1.0),
(movedDist.dy / 80.0).clamp(-1.0, 1.0));
_handlePos = _center + new Offset(_value.x * 40.0, _value.y * 40.0);
}
return true;
}
void paint(Canvas canvas) {
applyTransformForPivot(canvas);
canvas.drawCircle(_handlePos, 25.0, _paintHandle);
canvas.drawCircle(_center, 40.0, _paintControl);
}
}