GetGraphics:TGraphics() function

BlitzMax Forums/MaxGUI Module/GetGraphics:TGraphics() function

Kistjes(Posted 2009) [#1]
Hello,

In my current MaxGUI project I have to deal with multiply canvas.
I have a list of sprites (let's say simple white rectangles) that need to be drawn in the correct canvas.
Now I can add a TList of all related sprites to the canvas but I can also add a reference to the correct CanvasGraphics to every sprite. I prefer the second approach.

Each sprite has a container and it's location is relative to it's container. The container can be another sprite or can be null. If the sprite's container is null the location is relative to the graphical object: in non MaxGUI apps it is the Graphics() object but in a MaxGUI app it's CanvasGraphics(canvas).
When the Draw() method of the sprite is called, the sprite needs to know if it's container is currently active (with the setGraphics(CanvasGraphics(canvas)) function).
There is no GetGraphics() function. How can I get the currenty active TGraphics object?

I hope the example code below helps to clarify my question...



Kistjes(Posted 2009) [#2]
Same question but without all the explanation...

To set a TGraphics object I use SetGraphics()
How do I get the active TGraphics object? There is no such command like GetGraphics:TGraphics()


kfprimm(Posted 2009) [#3]
No there is not. Add the following to BRL.Graphics,
Function GetGraphics:TGraphics()
	Return _graphics
End Function

Alternatively, you could just store the Graphics object in a global variable and modify it each time you call SetGraphics.

That would most easily be accomplished with,
Function SetGraphics(g:TGraphics)
	Global _graphics:TGraphics
	_graphics=g
	Return brl.graphics.SetGraphics(_graphics)
End Function

Just stick this into your source.

All of this code is untested but it should function properly.


Kistjes(Posted 2009) [#4]
Thanks! I'll try that.


kfprimm(Posted 2009) [#5]
Ha. Sorry, I was tired when I wrote that code.
The following should be used instead of just the SetGraphics function.

Private
Global _graphics:TGraphics

Public
Function SetGraphics(g:TGraphics)
	_graphics=g
	Return brl.graphics.SetGraphics(_graphics)
End Function

Function GetGraphics:TGraphics()
	Return _graphics
End Function



Kistjes(Posted 2009) [#6]
The getGraphics() functions should work in all circumstances. In a non-maxGUI project I only use the Graphics(x,y,d,hz) function. This functions does not call my own SetGraphics() function and will therefor not set the global _graphics.

That's why I decided to add a GetGraphics() function to brl.Graphics (your first suggestion, Khomy).


kfprimm(Posted 2009) [#7]
Alright cool. What I was saying with the SetGraphics function is that originally, the _graphics was set as global in the function and therefore inaccessible outside the function. That snippet corrects the original. When calling brl.graphics.SetGraphics, the _graphics variable in BRL.Graphics is set.