import("guilib")
class SampleCanvas
{
inject(System.GUI)
method resize (canvas)
{
@dc.activate()
}
method redraw (canvas)
{
@dc.set_bgcolor(DrawCanvas.WHITE)
@dc.clear()
@dc.set_fgcolor(DrawCanvas.BLUE)
@dc.set_text_font({"typeface":"Verdana", "style":DrawCanvas.UNDERLINE, "size":24})
@dc.draw_text(100, 100, "Hello World!")
@dc.draw_image(@image, 58, 150)
}
method map (canvas)
{
@dc = DrawCanvas.new(canvas)
@image = DrawImage.load_image("c:/nexus/samples/images/price.jpg")
}
method create_canvas ()
{
canvas = Canvas.new()
canvas.set_event(Event.RESIZE, EventHandler.new(get_method("resize"), self))
canvas.set_event(Event.ACTION, EventHandler.new(get_method("redraw"), self))
canvas.set_event(Event.MAP, EventHandler.new(get_method("map"), self))
@canvas = canvas
}
public method show ()
{
@dialog.show()
System.GUI.main_loop()
}
method initialize ()
{
field @dialog
field @canvas
field @dc
field @image
attr =
{Attribute.TITLE : "Sample Canvas",
Attribute.RASTERSIZE : {"width":400, "height":400},
Attribute.OPACITY : 255}
@dialog = Dialog.new(create_canvas(), attr)
}
}
method main ()
{
dialog = SampleCanvas.new()
dialog.show()
}
main()