getJibba - Tutorial

4.GraphicsWindow & Subroutines

Think of the GraphicsWindow as a canvas on which we can draw and place controls on top of.

Properties & Operations

GraphicsWindow.BackgroundColor = "Yellow"
GraphicsWindow.DrawText(10, 10, "Hello World")

You may have noticed that the ojects we've been using have properties and operations. A property is something that the object has and an operation is something the object can do. e.g. this GraphicsWindow has a Yellow background and we can write hello world on it.

GraphicsWindow.BackgroundColor = "Yellow"
GraphicsWindow.DrawText(10, 10, "Hello World")

imgPath = "http://www.getjibba.com/assets/my-logo-sml.png"

myLogoImage = ImageList.LoadImage(imgPath)
'Draws image on the graphicsWindow
GraphicsWindow.DrawImage(myLogoImage, 10, 40)

'Places shape on top of graphicsWindow
myLogo = Shapes.AddImage(myLogoImage)

'Places a Control (button) on top of graphicsWindow
startButton = Controls.AddButton("Move shape Image", 10, 90)

'Register ButtonClicked Event
Controls.ButtonClicked = OnButtonClicked

'Event Handler
Sub OnButtonClicked
  Shapes.Move(myLogo, GraphicsWindow.Width /2, 0)
EndSub

In the sample I've drawn my logo on the GraphicsWindow, GraphicsWindow.DrawImage then placed my logo on top of the GraphicsWindow, Shapes.AddImage. Notice that when it's added on top as a shape it can easily be moved.

I've also added a Control on top of the GW. In this case a button. Then I register an ButtonClicked event and wire it to the Subroutine OnButtonClicked. When the button is clicked the special subroutine (OnButtonClicked) is called and the code inside it is executed, in this case it moves the shape to the top centre of screen.

Subroutines

'Calling the subroutine
Initialise()

Sub Initialise
  GraphicsWindow.BackgroundColor = "Black"
  GraphicsWindow.Title = "My Program"
EndSub

Normal Subroutines are called by the program and event handler subroutines are called indirectly by the OS. Event subroutines are Asyncronous, i.e. they happen independently of the program. They are hardware events like a mouse click, key pressed or timer tick.

A good subroutine is ussually a specific task that is performed more than once. Sometimes they are used to organise code.