Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
44 changes: 33 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,39 @@
# GraphX™
<div align="center">
<a>
<h3>🎨</h3>
<h1>GraphX™</h1>
</a>

GraphX™ rendering lib,
prototype code with a prototype lib
[![pub package](https://img.shields.io/pub/v/graphx.svg?label=graphx&color=blue)](https://pub.dev/packages/graphx)
[![style: effective dart](https://img.shields.io/badge/style-effective_dart-40c4ff.svg)](https://pub.dev/packages/effective_dart)
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)

> *WARNING:* this is WIP code, based on a few days of experimentation.

> *NOTE:* GraphX™ uses the `$` prefix convention to all "internal/private" members (properties and methods). __DO NOT__ call them in your code... is meant to be consumed internally by the lib.
> until I cleanup and organize the code for an alpha version, then will probably moved all as part of the package.
| rendering | prototype | design |



Making drawings and animations in Flutter extremely simple.

___
*WARNING:* this lib is on alfa stage, the api can change.

*NOTE:* GraphX™ uses the `$` prefix convention to all "internal/private" members (properties and methods). __DO NOT__ call them in your code... is meant to be consumed internally by the lib.
until I cleanup and organize the code for an alpha version, then will probably moved all as part of the package.
___


### wiki-tips.

To get some extended, boring explanations, and eventually some sample codes, check the [GraphX™ Wiki](https://github.com/roipeker/graphx/wiki/GraphX-tips-and-random%5BnextInt()%5D-stuffs.#graphx-general-tips)
___
<div align="left">




## Background.

## background.

GraphX™ is here to help you build custom drawing in your Flutter apps. Providing an amazing versatility to power those screen pixels to a different level.

Expand All @@ -29,7 +48,7 @@ It can be used to simple draw a line, a circle, a custom button, some splash eff

So, let your imagination fly.

## concept.
## Concept.

This repo is just a very early WIP to put something online...
still lacks support for loading remote images, 2.5D and some other nicities.
Expand All @@ -43,13 +62,15 @@ AssetLoader.loadJson(assetId)

And some basic "raw" support for Text rendering with the `StaticText` class.



-----------

GraphX™ drives a CustomPainter inside, the idea is to simplify the usage of Flutter's `Canvas`, plus adding the DisplayList concept, so you can manage and create more complex "scenes".

GraphX™ has it's own rendering cycle (no AnimationController), and input capture, even if it runs on the Widget tree, you can enable the flags to capture mouse/touch input (through the `stage.pointer`), or keystrokes events (if u wanna do some simple game).

### sample code.
### Sample code.

```dart
body: Center(
Expand Down Expand Up @@ -166,7 +187,7 @@ They all emit a `MouseInputData` with all the needed info inside, like stage coo

*I will keep adding further explanation in the upcoming days.*

### demos.
### Demos.

_Some demos are only using **GraphX™** partially, and might have big CPU impact_

Expand Down Expand Up @@ -203,10 +224,11 @@ _Some demos are only using **GraphX™** partially, and might have big CPU impac
Feel free to play around with the current API, even if it's still rough on edges and unoptimized, it might help you do things quicker.

SKIA is pretty powerful!

</div>
-------------

#### Donation

You can [buymeacoffee](https://www.buymeacoffee.com/roipeker) or support **GraphX™** via [Paypal](https://www.paypal.me/roipeker/)

[![Donate via PayPal](https://cdn.rawgit.com/twolfson/paypal-github-button/1.0.0/dist/button.svg)](https://www.paypal.me/roipeker/)
Expand Down
78 changes: 77 additions & 1 deletion analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1 +1,77 @@
include: package:pedantic/analysis_options.yaml

linter:
rules:
await_only_futures: true
# This one is desirable, but that's a lot of work for now
public_member_api_docs: false
# Desirable, but would be breaking changes:
avoid_positional_boolean_parameters: false
constant_identifier_names: false
include_file_not_found: false

# INCLUDE_FIX (copy of effective dart 1.2.0)
# STYLE
camel_case_types: true
camel_case_extensions: true
library_names: true
file_names: true
library_prefixes: true
non_constant_identifier_names: true
directives_ordering: true
lines_longer_than_80_chars: true # avoid
curly_braces_in_flow_control_structures: true

# DOCUMENTATION
slash_for_doc_comments: true
package_api_docs: true # prefer
#- comment_references # Unused because https://github.com/dart-lang/sdk/issues/36974

# USAGE
implementation_imports: true
avoid_relative_lib_imports: true # prefer
prefer_relative_imports: true # prefer
prefer_adjacent_string_concatenation: true
prefer_interpolation_to_compose_strings: true # prefer
unnecessary_brace_in_string_interps: true # avoid
prefer_collection_literals: true
avoid_function_literals_in_foreach_calls: true # avoid
prefer_iterable_whereType: true
prefer_function_declarations_over_variables: true
unnecessary_lambdas: true
prefer_equal_for_default_values: true
avoid_init_to_null: true
unnecessary_getters_setters: true
annotate_overrides: true
#- unnecessary_getters # prefer # Disabled pending fix: https://github.com/dart-lang/linter/issues/23
#- prefer_expression_function_bodies # consider
unnecessary_this: true
prefer_initializing_formals: true
type_init_formals: true
empty_constructor_bodies: true
unnecessary_new: true
unnecessary_const: true
avoid_catches_without_on_clauses: true # avoid
avoid_catching_errors: true
use_rethrow_when_possible: true

# DESIGN
use_to_and_as_if_applicable: true # prefer
one_member_abstracts: true # avoid
avoid_classes_with_only_static_members: true # avoid
prefer_mixin: true
prefer_final_fields: true # prefer
use_setters_to_change_properties: true
avoid_setters_without_getters: true
avoid_returning_null: true # avoid
avoid_returning_this: true # avoid
type_annotate_public_apis: true # prefer
#- prefer_typing_uninitialized_variables # consider
omit_local_variable_types: true # avoid
avoid_types_on_closure_parameters: true # avoid
avoid_return_types_on_setters: true # avoid
prefer_generic_function_type_aliases: true
avoid_private_typedef_functions: true # prefer
#- use_function_type_syntax_for_parameters # consider
hash_and_equals: true
avoid_equals_and_hash_code_on_mutable_classes: true # avoid
avoid_null_checks_in_equality_operators: true
2 changes: 1 addition & 1 deletion example/lib/demos/demos.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export 'simple_interactions/simple_interactions.dart';
export 'simple_shape/simple_shapes.dart';
export 'simple_tween/simple_tween.dart';
export 'svg_icons/svg_icons.dart';
export 'simple_interactions/simple_interactions.dart';
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:exampleGraphx/utils/utils.dart';
import '../../utils/utils.dart';

import 'simple_interactions_scene.dart';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ class SimpleInteractionsScene extends SceneRoot {
/// And also access the `rawEvent` dispatched by Flutter if we need to.
/// Most of the times you are ok using `LogicalKeyboardKey` to check
/// for the keyboard's keys constants.
/// Usually [onDown] fires keystrokes in constantly, although it depends on the
/// OS and keyboard, while you keep it pressed.
/// Usually [onDown] fires keystrokes in constantly, although it depends
/// on the OS and keyboard, while you keep it pressed.
void _onKeyboardDown(KeyboardEventData event) {
var pixelsToMove = 10.0;

/// for access modifiers keys, is better to check the raw event itself.
/// as multiple physical keys have the same behaviour (shift, command, alt, etc)
/// but different key codes.
/// as multiple physical keys have the same behaviour (shift, command,
/// alt, etc) but different key codes.
if (event.rawEvent.isShiftPressed) {
pixelsToMove = 30.0;
}
Expand All @@ -85,9 +85,9 @@ class SimpleInteractionsScene extends SceneRoot {
}
}

/// [onUp], unlike [onDown], dispatches only once, when you release a keystroke.
/// use the A for scale down the ball, and S to scale it up by 20% on each
/// event.
/// [onUp], unlike [onDown], dispatches only once, when you release a
/// keystroke. use the A for scale down the ball, and S to scale it up
/// by 20% on each event.
void _onKeyboardUp(KeyboardEventData event) {
if (event.isKey(LogicalKeyboardKey.keyS)) {
ball.scale += .2;
Expand Down
2 changes: 1 addition & 1 deletion example/lib/demos/simple_interactions/ui/my_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ class MyButton extends Sprite {
/// height
textY = textY.clamp(0.0, h - textH);
_fillText.y = textY;
_fillText.text = (_fillPercent * 100).toStringAsFixed(0) + '%';
_fillText.text = '${(_fillPercent * 100).toStringAsFixed(0)}%';
_fillText.alpha = _fillPercent.clamp(.3, 1.0);
}
}
2 changes: 1 addition & 1 deletion example/lib/demos/simple_shape/simple_shapes.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:exampleGraphx/utils/utils.dart';
import '../../utils/utils.dart';

import 'simple_shapes_scene.dart';

Expand Down
6 changes: 3 additions & 3 deletions example/lib/demos/simple_tween/simple_tween.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:exampleGraphx/demos/simple_tween/simple_tween_scene.dart';
import 'package:exampleGraphx/demos/simple_tween/tween_controller.dart';
import 'package:exampleGraphx/utils/utils.dart';
import '../../utils/utils.dart';
import 'simple_tween_scene.dart';
import 'tween_controller.dart';

class SimpleTweenMain extends StatelessWidget {
final controller = TweenSceneController();
Expand Down
2 changes: 1 addition & 1 deletion example/lib/demos/svg_icons/svg_icons.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:exampleGraphx/utils/utils.dart';
import '../../utils/utils.dart';
import 'svg_icons_scene.dart';

class DemoSvgIconsMain extends StatelessWidget {
Expand Down
5 changes: 3 additions & 2 deletions example/lib/demos/svg_icons/test_svg_scene.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import 'package:exampleGraphx/assets/svg_icons.dart';
import 'package:exampleGraphx/utils/svg_utils.dart';
import 'package:flutter/material.dart';
import 'package:graphx/graphx.dart';

import '../../assets/svg_icons.dart';
import '../../utils/svg_utils.dart';

class TestSvgScene extends Sprite {
final groundHeight = 100.0;
Sprite trees, ground;
Expand Down
4 changes: 2 additions & 2 deletions example/lib/utils/svg_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class SvgUtils {
bool clipCanvas = true,
Size scaleCanvasSize,
}) async {
final DrawableRoot svgRoot = await svg.fromSvgString(rawSvg, rawSvg);
final svgRoot = await svg.fromSvgString(rawSvg, rawSvg);
if (scaleCanvas) {
svgRoot.scaleCanvasToViewBox(canvas, scaleCanvasSize);
}
Expand All @@ -28,7 +28,7 @@ class SvgUtils {
}

static Future<SvgData> svgDataFromString(String rawSvg) async {
final DrawableRoot svgRoot = await svg.fromSvgString(rawSvg, rawSvg);
final svgRoot = await svg.fromSvgString(rawSvg, rawSvg);
var obj = SvgData();
obj.hasContent = svgRoot.hasDrawableContent;
obj.picture = svgRoot.toPicture();
Expand Down
3 changes: 2 additions & 1 deletion example/lib/utils/utils.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export 'demo_scene_widget.dart';
export 'package:flutter/material.dart';
export 'package:graphx/graphx.dart' show SceneBuilderWidget, SceneRoot;

export 'demo_scene_widget.dart';
6 changes: 3 additions & 3 deletions lib/src/animations/delayed_call.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ class GxDelayedCall with IUpdatable, JugglerSignalMixin {
// save objects cause they might be changed from event.
var $callback = target;

/// during callback, people might wanna call [reset] and read this to the
/// juggler, so the signal has to be dispatched *before* executing the
/// callback.
/// during callback, people might wanna call [reset] and read
/// this to the juggler, so the signal has to be dispatched *before*
/// executing the callback.
onRemovedFromJuggler.dispatch(_eventData);
$callback?.call();
}
Expand Down
4 changes: 2 additions & 2 deletions lib/src/render/render.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
export 'filters/blur_filter.dart';
export 'filters/color_filter.dart';
export 'filters/color_filter.dart';
export 'graphics.dart';
export 'gx_icon.dart';
export 'movie_clip.dart';
export 'particles/simple_particle.dart';
export 'particles/simple_particle_system.dart';
export 'svg_shape.dart';
export 'filters/blur_filter.dart';
export 'filters/color_filter.dart';
2 changes: 1 addition & 1 deletion lib/src/tween/src/gtween.dart
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ class GTween {
return v - start;
} else if (val is String) {
if (val.length > 2 && val[1] == '=') {
var multiplier = double.tryParse(val[0] + '1') ?? 1;
var multiplier = double.tryParse('${val[0]}1') ?? 1;
var factor = double.tryParse(val.substring(2));
return multiplier * factor;
} else {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/tween/src/mixins/tweenable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ mixin GTweenable {
final Map<String, GTweenLerpProp> _lerps = {};

@override
String toString() => '[GTweenable] ' + target?.toString();
String toString() => '[GTweenable] $target';

Map<Object, List<Function>> _accessors;

Expand Down
6 changes: 4 additions & 2 deletions lib/src/tween/src/wraps/common_wraps.dart
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ class GTweenableMap with GTweenable {

targetMap.removeWhere((k, v) => !value.containsKey(k));
if (targetMap.isEmpty) {
throw "tween(targetMap) Map can't be empty. Or there are no matching keys with the tweenable target.";
throw '''
tween(targetMap) Map can't be empty. Or there are no matching keys with the tweenable target.''';
}

return GTween.to(
Expand Down Expand Up @@ -169,7 +170,8 @@ class GTweenableList with GTweenable {
assert(targetList != null);
targetList.removeWhere((element) => element is! num);
if (targetList.isEmpty) {
throw "tween(targetList) List can't be empty. Or values inside of it where not a number type";
throw '''
tween(targetList) List can't be empty. Or values inside of it where not a number type''';
}
final targetMap = {};
for (var i = 0; i < targetList.length; ++i) {
Expand Down
3 changes: 2 additions & 1 deletion lib/src/tween/src/wraps/geom_wraps.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ class GTweenablePoint with GTweenable {
Map startAt,
}) {
if ((x != null || y != null) && to != null) {
throw "GTween Can't use 'x, y' AND 'to' arguments for GxPoint tween. Choose one";
throw '''
GTween Can't use 'x, y' AND 'to' arguments for GxPoint tween. Choose one''';
}
x = to?.x ?? x;
y = to?.y ?? y;
Expand Down
2 changes: 1 addition & 1 deletion lib/src/utils/mixins.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ mixin RenderUtilMixin {
final picture = createPicture(
!needsAdjust
? null
: (Canvas c) {
: (c) {
if (adjustOffset) {
c.translate(-rect.left, -rect.top);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/utils/pools.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import '../../graphx.dart';

abstract class Pool {
mixin Pool {
static final _points = <GxPoint>[];
static final _rectangles = <GxRect>[];
static final _matrices = <GxMatrix>[];
Expand Down
2 changes: 1 addition & 1 deletion lib/src/utils/texture_utils.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import '../../graphx.dart';

abstract class TextureUtils {
mixin TextureUtils {
static final Shape _helperShape = Shape();

static Graphics get _g => _helperShape.graphics;
Expand Down
Loading