WARNING: Out of date.
Should be updated soon (december 2007)
Meanwhile, look at trunk/samples.
Hello, World!
Once you correctly set up Xinf, you can try to compile the examples. Respecting ancient traditions, I'll walk you thru the first Hello World here.
The HelloWorld? example can be found here, or in <your-haxelib-path>/xinf/<version>/samples/1-helloworld/App.hx:
import xinf.erno.Color;
import xinf.ony.Application;
import xinf.ony.Text;
class App extends Application {
private static var hello:Text;
public function new() :Void {
super();
hello = new Text( "Hello, World!", Color.WHITE );
root.attach( hello );
}
public static function main() :Void {
new App().run();
}
}
as you can surely see, we're defining a new class (App), deriving from xinf.ony.Application, and construct a main() function that instantiates one such App and run()s it. xinf.ony.Application takes care of all the lower-level xinferno runtime initialization.
In the constructor, we create a new xinf.ony.Text element to display a white "Hello, World!", and attach it to the "root", which is a member variable of Application and represents the root of the "main" window (there's no other windows with current XinfInity?...).
Compiling
For XinfInity?
Compiling the HelloWorld? sample for XinfInity? will currently simply result in a neko binary that uses the XinfInity? runtime. At some later date, there might be an option to compile to a special file format to be loaded by some XinfInity? player application, but currently you are basically "linking" against XinfInity?, producing a neko app:
haxe -main App -lib xinf -neko app.n neko app.n
Note that while you can create a "bootable" application with nekotools boot app.n , that will not be completely stand-alone. People are still required to have the support libs installed. We're looking for ways to produce a full-blown stand-alone executable.
For Flash (9)
Compiling for Flash9 (<9 is (currently) unsupported by Xinf) will produce a standalone SWF file:
haxe -main App -lib xinf -swf app.swf -swf-version 9 -swf-header 320:240:25:000000
For JavaScript?
As with any haXe project, compiling for JavaScript? produces a .js file for inclusion into your HTML page (for reference, see here):
haxe -main App -lib xinf -js app.js
Hello, Xinferno!
Of course you might want to do some more complex stuff than just print "Hello, World". The suggested path to display your own graphics is to derive from xinf.ony.Object and implement the drawContents() method. You're being passed a xinf.erno.Renderer instance, which you can use to draw all kinds of graphical primitives.
The second example allows you to draw simple shapes with the mouse. We're defining two new classes: Sketch (representing a single shape) and Sketcher (being the container for Sketches). We're registering MOUSE_DOWN, MOUSE_UP, MOUSE_MOVE and STAGE_SCALED events. Beware here that anything but MOUSE_DOWN and MOUSE_OVER/_OUT are not delivered to any specific xinf.ony.Object, so you'll have to register your listeners globally, on the "Runtime".
Furthermore, in this example, the Sketch class differentiates between JavaScript? and Flash/XinfInity code: as Xinf's JS implementation (currently) has no way to display arbitrary shapes, we'll just draw little rectangles at the individual points of the shape.
See /trunk/xinf/samples/2-sketcher/App.hx for the complete source code.
Using 'native' objects
In the last of these first three examples, we'll use the xinf.ony.Native class to embed "native content". It takes a native object (a js.HtmlDom? for JS, a flash.display.DisplayObject? for flash, or an Integer referencing a GL displaylist for XinfInity?) and displays it at the position where the Native object is inserted into the display hierarchy.
For JS, we're embedding a short snippet of HTML (with a simple event handler); for Flash, we're creating a new Sprite and draw a simple rectangle with the flash drawing API; and finally, for XinfInity?, we're defining a new displaylist that shows a rectangle rotated in 3d (as the viewport is not properly set up to some 'real' perspective, it will look a little strange).
See the source here: /trunk/xinf/samples/3-native/App.hx.
So much for now
I hope that these three example gave you a head-start into development with xinf. Please let me know on the MailingList if things go wrong or you need more pointers or help with specific problems.