Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD

graphx™

graphx lib for flutter.

warning: this lib is on alpha stage, the api can change.

note: graphx™ uses the $ prefix convention for all internal and private members (properties and methods). do not call them in your code… is meant to be consumed internally by the lib, it will remain as it is, at least initially, while the package takes shape.

as graphx is about visuals, here you have some screen captures of random prototypes i’ve been doing, while developing and testing graphx.

68747470733a2f2f6d656469612e67697068792e636f6d2f6d656469612f4e4d47386766704a784669753165414c5a6f2f67697068792e676966

68747470733a2f2f6d656469612e67697068792e636f6d2f6d656469612f5249727668665a6f4474616c3431546234652f67697068792d646f776e73697a65642e676966

68747470733a2f2f6d656469612e67697068792e636f6d2f6d656469612f705164657572554f417157645a757878554b2f67697068792e676966

68747470733a2f2f6d656469612e67697068792e636f6d2f6d656469612f5659534a463675554f3332334656304e68682f67697068792e676966

background.

graphx™ is here to help you build custom drawings in your flutter apps. providing a great versatility to power those screen pixels to a different level.

it’s inspired by the good-old flash api, which forged my way into programming back in the days, and inspired many other rendering frameworks, in several languages through the years.

i was thinking how much i missed to "play" with code, to make things more organic, artistic, alive… i totally love flutter, but i always feel that it requires too much boilerplate to make things move around (compared to what i used to code).

even if graphx™ is not an animation library (although has a small tween engine), nor a game engine, it can help you build really awesome user experiences! it just runs on top of custompainter… using what flutter sdk exposes from the skia engine through the canvas, yet, gives you some "framework" to run isolated from the widget’s world.

can be used to simple draw a line, a circle, maybe a custom button, some splash effect on your ui, or even a full-blown game in a portion of the screen.

mix and match with flutter as you please, as graphx™ uses custompainter, it is part of your widget’s tree.

concept.

this repo is a very early wip … the library still lacks of support for loading remote assets, 2.5 transformation and some other niceties.

yet, it has a ver basic support for loading rootbundle assets:

assetloader.loadbinary(assetid)  
assetloader.loadgif(assetid)  
assetloader.loadtextureatlas(imagepath, xmlpath)  
assetloader.loadtexture(assetid)  
assetloader.loadimage(assetid)  
assetloader.loadstring(assetid)  
assetloader.loadjson(assetid)  

graphx™ also provides basic "raw" support for text rendering, using the statictext class.


how does it work?

graphx™ drives a custompainter inside. the idea is to simplify the usage of flutter’s canvas, plus adding the display list concept, very similar to the widget tree concept; so you can imperatively code, manage and create more complex "scenes".

the library has its own rendering cycle using flutter’s ticker (pretty much like animationcontroller does), and each scenewidgetbuilder does its own input capture and processing (mouse, keyboard, touches). even if it runs on the widget tree, you can enable the flags to capture mouse/touch input, or keystrokes events (if u wanna do some simple game, or desktop/web tool).

sample code.

  body: center(
    child: scenebuilderwidget( /// wrap any widget with scenebuilderwidget
      builder: () => scenecontroller.withlayers(
        back: gamesceneback(), /// optional provide the background layer
        front: gamescenefront(), /// optional provide the foreground layer
      ),
      child: column(
        mainaxisalignment: mainaxisalignment.center,
        children: <widget>[
          text(
            'you have pushed the button this many times:',
          ),
          text(
            '$_counter',
            style: theme.of(context).texttheme.headline4,
          ),
        ],
      ),
    ),
  ),

graphx™ is based on "scenes" layers, each scenebuilderwidget requires a scenecontroller.
this controller is the "initializer" of the scenes layers, which can be:

  • back (background painter),
  • front (foreground painter),
  • or both.

each "scene layer" has to extend sceneroot, which represents the starting point of that particular scene hierarchy. think of it as materialapp widget is to all other children widgets in the tree.

here we get into graphx™ world, no more widgets trees or immutable properties.

you can override init() to setup things needed for this current scene painter object, like if it needs keyboard/mouse/touch access, or if it requires a ticker and redraw the custompainter, cause it will animate.

override ready() as your entry point, here the engine is set up, and the glorified stage is available to use.

class gamescene extends sceneroot {
  gamescene(){
    config(autoupdateandrender: true, usepointer: true);
  }

  @override
  void addedtostage() {
    /// if you have to stop the ticker. will stop all
    /// tweens, jugglers objects in graphx.
    stage.scene.core.ticker.pause();
  }

for now, graphx™ has a couple of classes for rendering the display list:
shape and sprite ( which are displayobject, displayobjectcontainer are abstracts),

they both have a graphics property which is of type graphics and provides a simplistic api to paint on the flutter’s canvas.

by the way, sceneroot is a sprite as well!, and it’s your root node in the display tree, kinda where all starts to render, and where you need to add your own objects.

for instance, to create a simple purple circle:

@override
void addedtostage(){
    var circle = shape();
    circle.graphics.linestyle(2, colors.purple.value) /// access hex value of color
      ..drawcircle(0, 0, 20)
      ..endfill();
    addchild(circle); // add the child to the rootscene.
}

sceneroot is a sprite (which is a displayobjectcontainer) and can have children inside, yet shape is a displayobject, and can’t have children. but it makes it a little bit more performant on each painter step.

we could also use our root scene to draw things:

@override
addedtostage(){
  graphics.beginfill(0x0000ff, .6)
  ..drawroundrect(100, 100, 40, 40, 4)
  ..endfill();
...
}

scene setup sample in your sceneroot (in your constructor):

config(
  autoupdateandrender: true,
  usepointer: true,
  useticker: true,
  usekeyboard: false,
  sceneiscomplex: true,
);

pointer signals has been "simplified" as mouse events now… as it’s super easy to work with single touch / mouse interactions in displayobjects.
there’re a bunch of signals to listen on each element… taken from as3, and js.

  • onmousedoubleclick
  • onmouseclick
  • onmousedown
  • onmouseup
  • onmousemove
  • onmouseover
  • onmouseout
  • onmousescroll

they all emit a mouseinputdata with all the needed info inside, like stage coordinates, or translated local coordinates, which "mouse" button is pressed, etc.


i will keep adding further explanation in the upcoming days.

demos.

some demos are only using graphx™ partially, and might have big cpu impact

flutter widget mix

split rgb

input text particles

fisheye particles

fisheye particles (basic)

particles emitter

shapemaker clone

mouse follower

basic hit test

spritesheet rendering

displayobject pivot

simple solo-ping-pong game

first experimentation with rendering

screencast demos

68747470733a2f2f6d656469612e67697068792e636f6d2f6d656469612f5157487566494b3947794541494d3444636e2f67697068792e676966

68747470733a2f2f6d656469612e67697068792e636f6d2f6d656469612f4f7447706d64316641567a7733704b376b442f67697068792e676966

68747470733a2f2f6d656469612e67697068792e636f6d2f6d656469612f75564676464f5455494341735971623133722f67697068792e676966

68747470733a2f2f6d656469612e67697068792e636f6d2f6d656469612f7a316149517a59535347564b65576261624a2f67697068792e676966

68747470733a2f2f6d656469612e67697068792e636f6d2f6d656469612f4d6a58544b4a70656e3876494e33347266572f67697068792e676966

68747470733a2f2f6d656469612e67697068792e636f6d2f6d656469612f4559345268566f7148544b56424a554e7a572f67697068792e676966

68747470733a2f2f6d656469612e67697068792e636f6d2f6d656469612f6134527a64613875764678435076664932322f67697068792e676966

68747470733a2f2f6d656469612e67697068792e636f6d2f6d656469612f756c6948525657565735496c6c696c6949692f67697068792d646f776e73697a65642e676966

68747470733a2f2f6d656469612e67697068792e636f6d2f6d656469612f6636554a6a3336487146594a75656a7a354d2f67697068792e676966

68747470733a2f2f6d656469612e67697068792e636f6d2f6d656469612f4c643358495945724b736f794351747a63672f67697068792e676966

68747470733a2f2f6d656469612e67697068792e636f6d2f6d656469612f4b695372464e5951376b454431487a536c4a2f67697068792e676966

68747470733a2f2f6d656469612e67697068792e636f6d2f6d656469612f74305a634f555064437467386150744c32422f67697068792d646f776e73697a65642e676966

68747470733a2f2f6d656469612e67697068792e636f6d2f6d656469612f73694d4e7a66525754614b4b395077306e322f67697068792e676966

68747470733a2f2f6d656469612e67697068792e636f6d2f6d656469612f59667a4e4c6d6645316875745749313736652f67697068792d646f776e73697a65642e676966

68747470733a2f2f6d656469612e67697068792e636f6d2f6d656469612f67433934494f6475367631476f574a5a57592f67697068792e676966

68747470733a2f2f6d656469612e67697068792e636f6d2f6d656469612f31747362614f32385958587863316c7673642f67697068792d646f776e73697a65642e676966

68747470733a2f2f6d656469612e67697068792e636f6d2f6d656469612f45496e59334d4b5a3278766d594e6c33666d2f67697068792e676966

68747470733a2f2f6d656469612e67697068792e636f6d2f6d656469612f3453737075773352385264723274734534542f67697068792e676966

68747470733a2f2f6d656469612e67697068792e636f6d2f6d656469612f7861454e3632766d4551785452317a4670792f67697068792e676966

68747470733a2f2f6d656469612e67697068792e636f6d2f6d656469612f513263497355333443627a5a48664e41327a2f67697068792e676966

68747470733a2f2f6d656469612e67697068792e636f6d2f6d656469612f6439635154306d4f776762524a32666279642f67697068792e676966

68747470733a2f2f6d656469612e67697068792e636f6d2f6d656469612f484c647145517a65334c55446c444354426f2f67697068792e676966

68747470733a2f2f6d656469612e67697068792e636f6d2f6d656469612f5a394437627057716a58384b4a4d544d4d632f67697068792d646f776e73697a65642e676966

68747470733a2f2f6d656469612e67697068792e636f6d2f6d656469612f7579675a63515049653744703452484872422f67697068792e676966

68747470733a2f2f6d656469612e67697068792e636f6d2f6d656469612f6c56426b5a366f317142716e656b3932516a2f67697068792d646f776e73697a65642e676966

68747470733a2f2f6d656469612e67697068792e636f6d2f6d656469612f37543368716e48633763527271456a4534612f67697068792e676966

68747470733a2f2f6d656469612e67697068792e636f6d2f6d656469612f7a39464677743673505153717256754d79462f67697068792d646f776e73697a65642e676966

68747470733a2f2f6d656469612e67697068792e636f6d2f6d656469612f4c646a3769385869505a70595a3932574e4e2f67697068792e676966

68747470733a2f2f6d656469612e67697068792e636f6d2f6d656469612f4c46416843777737765649746566373876392f67697068792e676966

68747470733a2f2f6d656469612e67697068792e636f6d2f6d656469612f776b3873376a4a6e776664425166626476622f67697068792e676966

68747470733a2f2f6d656469612e67697068792e636f6d2f6d656469612f584e4f3551704a43796374644c5a594d43532f67697068792e676966

68747470733a2f2f6d656469612e67697068792e636f6d2f6d656469612f445762757452303168394c707363685644412f67697068792e676966

68747470733a2f2f6d656469612e67697068792e636f6d2f6d656469612f31746a586c574731496d5068493365696a342f67697068792e676966


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD

Comments are closed.