Skip to content

1. support long press like flutter #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
bf89458
Migrated to null safety and made another branch
IsmailAlamKhan Mar 6, 2021
0b79ae9
fixed the graphx_widget for the null_check operator error
IsmailAlamKhan Mar 13, 2021
b951329
another small fix for the graphx_widget converter
shariful2011 Mar 13, 2021
b512710
removed the trace when calling ContextUtils.getRenderObjectBounds
IsmailAlamKhan Mar 14, 2021
14f393c
Fix for the GText conflict
IsmailAlamKhan Mar 15, 2021
0f7662d
Another fix for GText confilct
IsmailAlamKhan Mar 15, 2021
6550a9e
same as previous commit
IsmailAlamKhan Mar 15, 2021
e416dbc
same as before
IsmailAlamKhan Mar 15, 2021
9edd3f9
Merge branch 'master' into null-safety
IsmailAlamKhan Mar 16, 2021
778fe9b
added the gtween addition
IsmailAlamKhan Mar 16, 2021
45292fc
fixed the duplicate prop on text
IsmailAlamKhan Mar 16, 2021
d86e186
Merge pull request #15 from IsmailAlamKhan/null-safety
roipeker Mar 18, 2021
c75233b
migrated the examples to null-safety
IsmailAlamKhan Mar 22, 2021
bc12fda
critical fixes for null-safety.
roipeker Mar 25, 2021
5eb611f
Merge pull request #20 from IsmailAlamKhan/null-safety
roipeker Mar 25, 2021
2bb46ec
Update graphics.dart
roipeker Mar 26, 2021
348a86b
1. support long press like flutter
May 27, 2021
21a3ced
fix bug: update event.type to long press
May 31, 2021
bb5dd6f
1. keep event signal stateless.
Jun 1, 2021
2ce2f3e
Merge remote-tracking branch 'origin/null-safety' into add-long-press…
Jul 18, 2021
edf5349
1. fix null-safety
Jul 18, 2021
cad4077
1. disable drag event to parent
Sep 1, 2021
1940d14
1. update keyboard
Sep 3, 2021
616a02c
1. add custom mouse cursor
Sep 13, 2021
f61877a
1. add custom mouse cursor
Sep 13, 2021
05d3ca4
1. support flutter 3.0
May 15, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## [0.9.10]
- start port to null-safety.
## [1.0.0-nullsafety.0]
- initial migration to null-safety
- fix non-working examples.
- fix a bug with GText layout.

## [0.9.9]
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ To get some extended, boring explanations, and eventually some sample codes, che

#### news!

- WIP Support for [null-safety](https://github.com/roipeker/graphx/tree/null-safety) in the other branch.
- WIP Support for [null-safety](https://github.com/roipeker/graphx/tree/null-safety)

- Support for HotReload

#### prototyping
Expand All @@ -33,6 +34,7 @@ GraphX is all about visuals, here you have some screen captures of random protot

For your GraphX scene to support **Hot Reload**, you should initialize your variables and DisplayObjects inside `addedToStage`, and optionally clean them in `dispose`.


[![artificial horizon](https://media.giphy.com/media/NMG8gfpJxFiu1eALZo/giphy.gif)](https://media.giphy.com/media/NMG8gfpJxFiu1eALZo/source.mp4)
[![parallax game](https://media.giphy.com/media/RIrvhfZoDtal41Tb4e/giphy-downsized.gif)](https://media.giphy.com/media/RIrvhfZoDtal41Tb4e/source.mp4)
[![charts pie color 2](https://media.giphy.com/media/pQdeurUOAqWdZuxxUK/giphy.gif)](https://media.giphy.com/media/pQdeurUOAqWdZuxxUK/source.mp4)
Expand Down
3 changes: 3 additions & 0 deletions example/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
analyzer:
errors:
todo: ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Modify this file to customize your launch splash screen -->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="?android:colorBackground" />

<!-- You can insert your own image assets here -->
<!-- <item>
<bitmap
android:gravity="center"
android:src="@mipmap/launch_image" />
</item> -->
</layer-list>
18 changes: 18 additions & 0 deletions example/android/app/src/main/res/values-night/styles.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Theme applied to the Android Window while the process is starting when the OS's Dark Mode setting is on -->
<style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar">
<!-- Show a splash screen on the activity. Automatically removed when
Flutter draws its first frame -->
<item name="android:windowBackground">@drawable/launch_background</item>
</style>
<!-- Theme applied to the Android Window as soon as the process has started.
This theme determines the color of the Android Window while your
Flutter UI initializes, as well as behind your Flutter UI while its
running.
This Theme is only used starting with V2 of Flutter's Android embedding. -->
<style name="NormalTheme" parent="@android:style/Theme.Black.NoTitleBar">
<item name="android:windowBackground">?android:colorBackground</item>
</style>
</resources>
48 changes: 25 additions & 23 deletions example/lib/demos/altitude_indicator/scene.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ class AltitudIndicatorScene extends GSprite {

/// inner circle.
GSprite rotatorCircle = GSprite();
GSprite movable;
GSprite? movable;

double innerCircSeparation = 50.0;
double outlineThickness1 = 18.0;
double outlineThickness2 = 10.0;
double meterSize;
late double meterSize;
final redColor = const Color(0xffDA5537);
double valueMeterGap = 34.0;
double innerCircleSize;
late double innerCircleSize;

double get minStageSize => Math.min(stage.stageWidth, stage.stageHeight);
double get minStageSize => Math.min(stage!.stageWidth, stage!.stageHeight);

@override
void addedToStage() {
Expand All @@ -43,12 +43,14 @@ class AltitudIndicatorScene extends GSprite {
.endFill();
addChild(mainMask);
mainContainer.mask = mainMask;

/// center pivot in the current bounding box of scene.
alignPivot();

stage.onResized.add(() {
stage!.onResized.add(() {
/// position the scene in the middle of screen.
setPosition(stage.stageWidth / 2, stage.stageHeight / 2);
setPosition(stage!.stageWidth / 2, stage!.stageHeight / 2);

/// scale % accordingly.
scale = minStageSize / meterSize;
});
Expand Down Expand Up @@ -85,10 +87,10 @@ class AltitudIndicatorScene extends GSprite {
createOutsideLines();

/// create some movement for the airplane!
stage.onEnterFrame.add(onEnterFrame);
stage!.onEnterFrame.add(onEnterFrame);
}

bool isPressed(LogicalKeyboardKey key) => stage.keyboard.isPressed(key);
bool isPressed(LogicalKeyboardKey key) => stage!.keyboard!.isPressed(key);

int getDirY() {
if (isPressed(LogicalKeyboardKey.arrowDown)) {
Expand All @@ -113,9 +115,9 @@ class AltitudIndicatorScene extends GSprite {
var dirX = getDirX();

if (dirY != 0) {
movable.y += 1.2 * dirY;
movable!.y += 1.2 * dirY;
} else {
movable.y += (-movable.y) / 20;
movable!.y += (-movable!.y) / 20;
}

if (dirX != 0) {
Expand All @@ -126,16 +128,16 @@ class AltitudIndicatorScene extends GSprite {
}

var maxRangeY = valueMeterGap * 2;
if (movable.y > maxRangeY) {
movable.y = maxRangeY;
} else if (movable.y < -maxRangeY) {
movable.y = -maxRangeY;
if (movable!.y > maxRangeY) {
movable!.y = maxRangeY;
} else if (movable!.y < -maxRangeY) {
movable!.y = -maxRangeY;
}

// rotatorCircle.rotation += .01;
}

GSprite drawRotator() {
GSprite? drawRotator() {
/// background first.
movable = GSprite();

Expand All @@ -150,9 +152,9 @@ class AltitudIndicatorScene extends GSprite {
ground.alignPivot(Alignment.topCenter);
line.alignPivot(Alignment.center);

movable.addChild(sky);
movable.addChild(ground);
movable.addChild(line);
movable!.addChild(sky);
movable!.addChild(ground);
movable!.addChild(line);

/// another option to draw background.
// var rotatorBackground = GShape();
Expand All @@ -173,12 +175,12 @@ class AltitudIndicatorScene extends GSprite {
// movable.addChild(rotatorBackground);

var elements = buildRotatorElements();
movable.addChild(elements);
rotatorCircle.addChild(movable);
movable!.addChild(elements);
rotatorCircle.addChild(movable!);

/// the red arrow should always stay in the same position...
/// re-parent the element to the rotator circle.
var arrow = elements.getChildByName('arrow');
var arrow = elements.getChildByName('arrow')!;
rotatorCircle.addChild(arrow);
return movable;
}
Expand Down Expand Up @@ -329,15 +331,15 @@ class AltitudIndicatorScene extends GSprite {

GShape _buildLine({
double thickness = 3.0,
double rotationDegrees,
required double rotationDegrees,
}) {
var line = GShape();
line.graphics.lineStyle(thickness, kColorWhite);
line.graphics.moveTo(0, 0);
line.graphics.lineTo((innerCircleSize + innerCircSeparation) / 2, 0);
line.pivotX = line.width;
line.rotation = deg2rad(rotationDegrees);
linesContainer?.addChild(line);
linesContainer.addChild(line);
return line;
}

Expand Down
14 changes: 7 additions & 7 deletions example/lib/demos/ball_line_collision/scene/ball.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@ import 'package:graphx/graphx.dart';

class Ball extends GShape {
double radius, vx, vy;
Color color;
Color? color;

Ball({
double x,
double y,
this.radius,
this.vx,
this.vy,
double? x,
double? y,
required this.radius,
required this.vx,
required this.vy,
this.color,
}) {
this.x = x;
this.y = y;
graphics
.beginFill(color.withOpacity(.8))
.beginFill(color!.withOpacity(.8))
.lineStyle(6, kColorBlack)
.drawCircle(0, 0, radius)
.endFill()
Expand Down
14 changes: 6 additions & 8 deletions example/lib/demos/ball_line_collision/scene/scene.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,15 @@
///
/// web demo: https://roi-graphx-balls-collision.surge.sh/#/


import 'package:flutter/material.dart';
import 'package:graphx/graphx.dart';

import 'ball.dart';

class CollisionScene extends GSprite {
double get sw => stage!.stageWidth;

double get sw => stage.stageWidth;

double get sh => stage.stageHeight;
double get sh => stage!.stageHeight;

/// lazy with the types :P
var lines = [];
Expand All @@ -37,12 +35,12 @@ class CollisionScene extends GSprite {
addChild(ball);
balls.add(ball);
});
stage.onMouseDown.add(_onMouseDown);
stage!.onMouseDown.add(_onMouseDown);
}

void _onMouseDown(input) {
stage.onMouseUp.addOnce((input) => stage.onMouseMove.removeAll());
stage.onMouseMove.add((input) => points.add([mouseX, mouseY, 0.0]));
stage!.onMouseUp.addOnce((input) => stage!.onMouseMove.removeAll());
stage!.onMouseMove.add((input) => points.add([mouseX, mouseY, 0.0]));
points = <List<double>>[
[mouseX, mouseY, 0.0]
];
Expand Down Expand Up @@ -133,4 +131,4 @@ class CollisionScene extends GSprite {
}
}
}
}
}
30 changes: 15 additions & 15 deletions example/lib/demos/bookmark_button/scene.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import 'package:flutter/material.dart';
import 'package:graphx/graphx.dart';

class BookmarkButton extends GSprite {
double get sw => stage.stageWidth;
double get sw => stage!.stageWidth;

double get sh => stage.stageHeight;
GShape bg;
GText label;
double get sh => stage!.stageHeight;
late GShape bg;
late GText label;
bool isOn = false;
static List<GTexture> _gifFrames;
GMovieClip bookmarkIco;
GDropShadowFilter shadow;
static List<GTexture>? _gifFrames;
late GMovieClip bookmarkIco;
GDropShadowFilter? shadow;

/// remove if not in debug? (hot reload).
@override
Expand All @@ -27,7 +27,7 @@ class BookmarkButton extends GSprite {

@override
void addedToStage() {
stage.color = Color(0xffEDEFFB);
stage!.color = Color(0xffEDEFFB);
bg = addChild(GShape()) as GShape;
shadow = GDropShadowFilter(
6,
Expand All @@ -37,7 +37,7 @@ class BookmarkButton extends GSprite {
Color(0xffA4AADB).withOpacity(.43),
);
bg.$useSaveLayerBounds = false;
bg.filters = [shadow];
bg.filters = [shadow!];
label = GText.build(
text: 'Bookmark',
color: Colors.black.withOpacity(.7),
Expand All @@ -49,10 +49,10 @@ class BookmarkButton extends GSprite {
label.setPosition(sw - label.textWidth - 32, (sh - label.textHeight) / 2);
_loadTexture();
onMouseDown.add((e) {
shadow.tween(duration: .3, blurX: 2, blurY: 2, distance: 1);
shadow!.tween(duration: .3, blurX: 2, blurY: 2, distance: 1);
bg.tween(duration: .3, scale: .95);
stage.onMouseUp.addOnce((e) {
shadow.tween(duration: .5, blurX: 6, blurY: 6, distance: 6);
stage!.onMouseUp.addOnce((e) {
shadow!.tween(duration: .5, blurX: 6, blurY: 6, distance: 6);
bg.tween(duration: .5, scale: 1);
});
});
Expand All @@ -69,14 +69,14 @@ class BookmarkButton extends GSprite {

Future<void> _loadTexture() async {
if (_gifFrames == null) {
var atlas = await ResourceLoader.loadGif(
var atlas = await (ResourceLoader.loadGif(
'assets/bookmark_button/bookmark.gif',
resolution: 2,
cacheId: 'bookmark');
cacheId: 'bookmark') as Future<GifAtlas>);
_gifFrames = atlas.textureFrames;
}
bookmarkIco =
addChild(GMovieClip(frames: _gifFrames, fps: 50)) as GMovieClip;
addChild(GMovieClip(frames: _gifFrames!, fps: 50)) as GMovieClip;
bookmarkIco.repeatable = false;
bookmarkIco.alignPivot();
bookmarkIco.setPosition(label.x / 2 + 2, sh / 2);
Expand Down
Loading