I was just catching up on Keith Peter’s blog and one of the posts that really caught my attention was on Toolkits vs Frameworks. The defining difference between the two, as Keith quotes Gamma, is “Toolkits do not attempt to take control for you…”.The Framework vs. Toolkit debate was in my mind when I started OpenPyro, but I feel I never stressed that enough so I felt it was worth a blog post.
OpenPyro was written in a way that it can be leveraged in either fashion. Lets take a few of examples:
The “Sprite” equivalent in OpenPyro is the UIControl, which does a few things like interpret percent based measurements, etc. It can also have a painter attached to it that can paint solid colors, gradients, stripes etc. So to create a gradient on a UIControl, all you have to do is:
var uic:UIControl = new UIControl();
var painter:GradientFillPainter = new GradientFillPainter([0xdddddd, 0xffffff]);
uic.backgroundPainter = painter
Now everytime the UIControl resizes, the painter repaints the gradient on its graphics context. However if you are not using a UIControl, and just plain sprites, you can leverage the painters again as so:
var sprite:Sprite = new Sprite(); var painter:GradientFillPainter = new GradientFillPainter([0xdddddd, 0xffffff]); painter.draw(sprite, 200,200);
Now the painter paints the gradient on the Sprite’s graphics context. Its up to the developer to decide when to repaint the Sprite.
Here is another example with the layouts package:
var container:UIContainer = new UIContainer(); container.skin = new AuroraContainerSkin(); container.size(600,100); container.layout = new VLayout(10); var c1:UIControl = new UIControl(); c1.size(100%, 60); container.addChild(c1); var c2:UIControl = new UIControl(); c2.size("100%", 60); container.addChild(c2);
In the above example, we have bought into the OpenPyro framework and just this code will let you create 2 control, position them vertically with a gap of 10px and automatically create a scrollbar since it will be needed ( The 2 children measure up to 60+10+60 pixels > 100px)
But the layouts package classes can be used for pure sprites too by using something like this:
var layout:VLayout = new VLayout(10) layout.layout(sprite1, sprite2);
Similar examples can be drawn from the effects package etc. Also, OpenPyro has a fairly complete controls package each of which can be instantiated in a few lines of code as well completely independent of any framework dependencies. In fact almost all my tests are pure AS3 classes applying the package classes to non OpenPyro classes.