Dilema...

BlitzMax Forums/BlitzMax Programming/Dilema...

Brucey(Posted 2007) [#1]
I have a graphics driver independent module which uses Max2D to draw graphs (ie. Graphviz).

It generally works great :-)

However, to provide some device-specific functionality (line stippling/anti-aliasing) I needed to come up with a way to do it without including any device-specific code in the module.

I came up with a form of delegation, in which my graph renderer can have an optional parameter passed to it which will later be used to provide this device-specific functionality...
Function Create:TGVGraphviz(width:Int, height:Int, rendererSupport:TGVRenderSupport = Null)

By default you don't get any device-specific functionality. So it works, but some of the extra features are disabled.

TGVRenderSupport is defined as
Type TGVRenderSupport Abstract
	Method Init() Abstract
	Method setDotted() Abstract
	Method setDashed() Abstract
	Method setSolid() Abstract
End Type


and an example of using it :
Local renderSupport:TGVRenderSupport

?linux
renderSupport = New TOpenGLRenderSupport
?

Local renderer:TGVGraphviz = TGVGraphviz.Create(800, 480, renderSupport)


When I need to draw dashed lines, it calls the instance of TGVRenderSupport.setDashed() - if available - and makes the lines dashed.

So, is this the best way to go about this?
I just feel that doing all that object creation at the start is a bit clunky, but I can't think of better way to handle it.

I *could* say, this is OpenGL only, and hardcode it all... but I hate locking people into something like that.

Perhaps, since it's optional, the developer won't mind having the clunky stuff there if they really want that extra functionality...

Any ideas?