Skip to content

Commit

Permalink
Merge pull request #10 from roipeker/dev
Browse files Browse the repository at this point in the history
update 0.9.7
  • Loading branch information
roipeker authored Jan 15, 2021
2 parents 0e4bf80 + 9eef4b0 commit 3841d35
Show file tree
Hide file tree
Showing 11 changed files with 130 additions and 14 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## [0.9.7]
- added `MovieClip.gotoAndPlay` lastFrame for animation.
- exposed the `GifAtlas::textureFrames` so they can be used in MovieClips.
- added several methods from Flutters Path in `Graphics`... (conicCurveTo(), arcToPoint(), arc()) with some new optional parameters for relative drawing.
- added new signals for `stage.onMouseEnter`, `stage.onMouseLeave` to detect touch positions when it leaves the Widget area... ( useful for scene with buttons).

## [0.9.6+2]
- change `flutter_svg` version to be compatible with stable branch.

Expand Down
5 changes: 4 additions & 1 deletion lib/src/core/scene_painter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,9 @@ class ScenePainter with EventDispatcherMixin {

void _mouseInputHandler(MouseInputData input) {
input.time = $accumulatedFrameDeltaTime;

// if (input.type != MouseInputType.still) {
// trace(input.type);
// }
/// process it.
if (input.type == MouseInputType.move ||
input.type == MouseInputType.exit) {
Expand All @@ -180,6 +182,7 @@ class ScenePainter with EventDispatcherMixin {
_lastMouseY = input.stageY;
}
_lastMouseInput = input;

stage.captureMouseInput(input);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/src/display/bitmap.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class Bitmap extends DisplayObject {
return out;
}

final _paint = Paint();
final _paint = Paint()..filterQuality = FilterQuality.high;

Paint get nativePaint => _paint;

Expand Down
24 changes: 23 additions & 1 deletion lib/src/display/stage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import 'display_object.dart';
/// they will always contain default values:
/// x, y, width, height, stageWidth, stageHeight, mask, name, filter.
class Stage extends DisplayObjectContainer
with ResizeSignalMixin, TickerSignalMixin {
with ResizeSignalMixin, TickerSignalMixin, StageMouseSignalsMixin {
final ScenePainter scene;

static final _sMatrix = GxMatrix();
Expand Down Expand Up @@ -162,6 +162,27 @@ class Stage extends DisplayObjectContainer
return super.hitTest(localPoint) ?? this;
}

bool _isMouseInside = false;

/// tells if the pointer is inside the stage area (available to detect
/// events).
bool get isMouseInside => _isMouseInside;

/// capture context mouse inputs.
@override
void captureMouseInput(MouseInputData input) {
if (input.type == MouseInputType.exit) {
_isMouseInside = false;
var mouseInput = input.clone(this, this, input.type);
$onMouseLeave?.dispatch(mouseInput);
} else if (input.type == MouseInputType.unknown && !_isMouseInside) {
_isMouseInside = true;
$onMouseEnter?.dispatch(input.clone(this, this, MouseInputType.enter));
} else {
super.captureMouseInput(input);
}
}

GxRect getStageBounds(DisplayObject targetSpace, [GxRect out]) {
out ??= GxRect();
out.setTo(0, 0, stageWidth, stageHeight);
Expand Down Expand Up @@ -190,6 +211,7 @@ class Stage extends DisplayObjectContainer
$disposeDisplayListSignals();
$disposeResizeSignals();
$disposeTickerSignals();
$disposeStagePointerSignals();
super.dispose();
}

Expand Down
16 changes: 16 additions & 0 deletions lib/src/events/mixins.dart
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,22 @@ mixin RenderSignalMixin {
}
}

/// use mouse signal for now.
mixin StageMouseSignalsMixin<T extends MouseInputData> {
EventSignal<T> $onMouseLeave;
EventSignal<T> $onMouseEnter;

EventSignal<T> get onMouseLeave => $onMouseLeave ??= EventSignal();
EventSignal<T> get onMouseEnter => $onMouseEnter ??= EventSignal();

void $disposeStagePointerSignals() {
$onMouseLeave?.removeAll();
$onMouseLeave = null;
$onMouseEnter?.removeAll();
$onMouseEnter = null;
}
}

/// use mouse signal for now.
mixin MouseSignalsMixin<T extends MouseInputData> {
EventSignal<T> $onRightMouseDown;
Expand Down
1 change: 1 addition & 0 deletions lib/src/events/pointer_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ enum MouseInputType {
move,
down,
exit,
enter,
up,
click,
still,
Expand Down
2 changes: 1 addition & 1 deletion lib/src/geom/gxrect.dart
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class GxRect {

GxRect intersection(GxRect rect) {
GxRect result;
var x0 = x < rect.x ? rect.x : 0;
var x0 = x < rect.x ? rect.x : 0.0;
var x1 = right > rect.right ? rect.right : right;
if (x1 <= 0) {
result = GxRect();
Expand Down
68 changes: 60 additions & 8 deletions lib/src/render/graphics.dart
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,17 @@ class Graphics with RenderUtilMixin implements GxRenderable {
return this;
}

Graphics conicCurveTo(double controlX, double controlY, double anchorX,
double anchorY, double weight,
[bool relative = false]) {
if (!relative) {
_path.conicTo(controlX, controlY, anchorX, anchorY, weight);
} else {
_path.relativeConicTo(controlX, controlY, anchorX, anchorY, weight);
}
return this;
}

Graphics drawCircle(double x, double y, double radius) {
final pos = Offset(x, y);
final circ = Rect.fromCircle(center: pos, radius: radius);
Expand Down Expand Up @@ -541,15 +552,56 @@ class Graphics with RenderUtilMixin implements GxRenderable {
return this;
}

Graphics arc(double cx, double cy, double radius, double startAngle,
double sweepAngle) {
Graphics arc(
double cx, double cy, double radius, double startAngle, double sweepAngle,
[bool moveTo = false]) {
if (sweepAngle == 0) return this;
// _path.arcToPoint(arcEnd)
_path.addArc(
Rect.fromCircle(center: Offset(cx, cy), radius: radius),
startAngle,
sweepAngle,
);
if (!moveTo) {
_path.arcTo(
Rect.fromCircle(center: Offset(cx, cy), radius: radius),
startAngle,
sweepAngle,
false,
);
} else {
_path.addArc(
Rect.fromCircle(center: Offset(cx, cy), radius: radius),
startAngle,
sweepAngle,
);
}

return this;
}

Graphics arcToPoint(
double endX,
double endY,
double radius, [
double rotation = 0.0,
bool largeArc = false,
bool clockwise = true,
bool relativeMoveTo = false,
]) {
if (radius == 0) return this;
if (relativeMoveTo) {
_path.arcToPoint(
Offset(endX, endY),
radius: Radius.circular(radius),
clockwise: clockwise,
largeArc: largeArc,
rotation: rotation,
);
} else {
_path.relativeArcToPoint(
Offset(endX, endY),
radius: Radius.circular(radius),
clockwise: clockwise,
largeArc: largeArc,
rotation: rotation,
);
}

return this;
}

Expand Down
14 changes: 13 additions & 1 deletion lib/src/render/movie_clip.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ class MovieClip extends Bitmap {
/// render into what
int frameCount = 0;
int currentFrame = -1;

/// stops the playback when reaching this frame.
int targetFrame = -1;
Bitmap bitmap;

Signal _onFramesComplete;
Expand Down Expand Up @@ -51,8 +54,14 @@ class MovieClip extends Bitmap {
texture = _frameTextures[currentFrame];
}

void gotoAndPlay(int frame) {
void gotoAndPlay(int frame, {int lastFrame = -1}) {
gotoFrame(frame);
if (lastFrame > frameCount) {
lastFrame %= frameCount;
} else if (lastFrame > -1 && lastFrame < frame) {
/// TODO: add repeatable logic?
}
targetFrame = lastFrame;
play();
}

Expand Down Expand Up @@ -93,6 +102,9 @@ class MovieClip extends Bitmap {
return;
}
}
if (targetFrame > -1 && currentFrame == targetFrame) {
playing = false;
}
texture = _frameTextures[currentFrame];
}
accumulatedTime %= speed;
Expand Down
4 changes: 4 additions & 0 deletions lib/src/textures/gif_atlas.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ class GifFrame {
class GifAtlas extends GTexture {
final List<GifFrame> _frames = [];

List<GTexture> get textureFrames {
return _frames.map((e) => e.texture).toList();
}

void addFrame(GifFrame frame) {
_frames.add(frame);
if (_frames.length == 1) {
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: graphx
description: Render API on top of CustomPainter to power-up your Flutter apps to the next level.
version: 0.9.6+2
version: 0.9.7
homepage: https://github.com/roipeker/graphx

environment:
Expand Down

0 comments on commit 3841d35

Please sign in to comment.