Convert from mojo1 to mojo2 question

Monkey Forums/Monkey Programming/Convert from mojo1 to mojo2 question

GC-Martijn(Posted 2015) [#1]
I'm trying to convert some mojo1 code to mojo2 code.
Because what I think is that MX2 will use the same mojo2 structure etc.

In mojo2 is every drawing function inside the Canvas class And/Or in the DrawList class.

What is then the best thing to do, in a situation that you have multiple classes in several files that are drawing/creating something on the window (canvas) now.

Just make one Global canvas variable an use that in all my other classes ?
(I did read that you have to avoid Globals...)

- Or do I have to create more then one canvas ?
(1 for the gui, one for the images, one for the font, etc)

- Or do I have to create one field canvas inside the App, and pass that variable in each New(_canvas:Canvas) to each other Class. (think this is the best)

- Or do I have to Extends DrawList for all the classes that need that functions ?
(but that conflicts with some classes that already have a extend Class)

2.)
For example i'm using this gui class
http://www.monkey-x.com/Community/posts.php?topic=8619

mojo
Class GUI_Colors
	Private
	Method Reset:Void(); SetColor 255, 255, 255; End Method
	Method Base:Void(); SetColor 68, 134, 250; End Method
	Method Dark:Void(); SetColor 39, 59, 155; End Method
	Method Lite:Void(); SetColor 100, 200, 255; End Method
End Class

mojo2
Class GUI_Colors Extends DrawList
Private
	Method Reset:Void(); SetColor 255, 255, 255; End Method
	Method Base:Void(); SetColor 68, 134, 250; End Method
	Method Dark:Void(); SetColor 39, 59, 155; End Method
	Method Lite:Void(); SetColor 100, 200, 255; End Method
End Class


that works I think, but then the next error:

Error : Expression has no scope

Class GUI_Shapes Extends Canvas
 SetBlendMode BlendMode.Additive ' <-- error line
 DrawText text, x, y
 SetBlendMode BlendMode.Alpha
End Class


So before i'm going to convert, I would more info about this.


Shinkiro1(Posted 2015) [#2]
I would like to know this as well.

Another option would be that the Render Method returns a DrawList.


Richard Betson(Posted 2015) [#3]
@GC-Martijn
Right now I am using 'one' canvas for my GUI. I am not sure if I will keep it this way but it is probably the most efficient way to go. The issue for me comes down to things like in-window rotation of the canvas and other canvas features. I am thinking that (at least the way I am approaching it ) it will work with one canvas based in my window class (which essentially is a canvas). My setup is based on OddMod and Col's DX11 driver (BlitzMax). Both allow me to rotate the display (images) and with the use of SetViewPort() I just set the view port and rotate display on a window image draw. I plan to do the same for mojo2 where I will just use one canvas and SetScissors()/Matrix and rotate the canvas (if needed) then draw images for each image in my window draw list and then reset after window image draws are done. Essentially all I am doing is using one canvas, setting view port and then drawing for each window in the window list. It works great in BltzMax and should work well for mojo2.

Edit - You can see my little GUI test of my mojo2 conversion here using one canvas.
http://www.monkey-x.com/Community/posts.php?topic=9788


GC-Martijn(Posted 2015) [#4]
But what do you do with to object Canvas?
Did you make it a global, so you can access,update it in all classes ?
Or do you pass the canvas reference to each class, where you need it.

My game is only one window canvas at the moment, but severall classes and methods etc.


ziggy(Posted 2015) [#5]
You can have a DrawingList property in each class, and set a reference to your canvas there. Or pass it in each class constructor and keep it, so you avoid having a global and having to pass it every time


Richard Betson(Posted 2015) [#6]
@GC-Martijn
I pass the reference to a method within a class at the moment. So for example when using OpenWindow() in my window class I pass along the canvas object. All other window class methods can access the canvas object via a field.

As far as a canvas global I prefer to use a field within a class that extends the App class. So in my case the Monkey program using my GUI framework is responsible for constructing/initializing the canvas object and passing it to the GUI framework. Whether the canvas is a global or a field is up to the Monkey program using the GUI framework. What I was describing is what I do to support realtime dynamic windows (drawing lots of images every frame) in a GUI window. So the GUI you list would have to allow a canvas to be passed to it (edit- or perhaps wrap the GUI into a class that contains the canvas object).

As a rule I avoid adding to lists and thus extending searches or iterations through them. It is costly and can be avoided with good architecture and design, Mojo2 is no different in that the draw list class keeps a list of canvases (I think :) ) which in turn has a list of images associated. So compounding all those list iterations adds up quickly and should be avoided. Using on one canvas can reduce this overhead.