Non-fill Draw Shapes

BlitzMax Forums/BlitzMax Beginners Area/Non-fill Draw Shapes

Sorry for all these noobish questions!

My latest one is, in Blitz Basic I could specify whether I wanted the shape (rectangle, circle etc) to be filled or hollow. Now it seems I can only draw fill shapes. Is it possible to draw hollow shapes?

Please
try
using
the
search
facility.
It
is
so
useful .
Hope
these
help
find
your
answer

^^ Wot TonyG said ^^

Thanks. However, I think it is poor that such a basic drawing feature is no longer easily available.

So do I.

One solution might be to draw a rectangle to a drawing thing, then draw another rectangle of a masking colour inside the first one but 1 pixel shorter around the edges, then save this as a masked image. But I think it would be too slow for on-the-fly size changing images.

I would go for something like this but adjust it to draw a standard rect.
<edit> Something like this (untested)
Function Drawrect1( x:Float, y:Float, w:Float,h:Float, fill:Int=True)
	Local origin_x:Float
	Local origin_y:Float
	GetOrigin origin_x,origin_y
	Local handle_x:Float
	Local handle_y:Float
	GetHandle handle_x,handle_y
	Local xy:Float[]=[x,y,x+w,y,x+w,y+h,x,y+h]
	If fill
		_max2dDriver.DrawPoly xy,..
		handle_x,handle_y,..
		x+origin_x,y+origin_y
	Else
		Local x1:Float=xy[xy.Length-2]
		Local y1:Float=xy[xy.Length-1]
		For Local i:Int=0 Until Len xy Step 2
			Local x2:Float=xy[i]
			Local y2:Float=xy[i+1]
			_max2dDriver.DrawLine..
			handle_x+x1,handle_y+y1,..
			handle_x+x2,handle_y+y2,..
			x+origin_x-0.5,y+origin_y-0.5
			x1=x2
			y1=y2
		Next

	EndIf
End Function
Graphics 800 , 600
drawrect1(100 , 100 , 100 , 100)
drawrect1(10,10,110,110,False)
Flip
WaitKey()


Thanks. I'm not familular with using drivers and stuff directly. Are the ".."s where I'm suppose to put something, or is it a way of telling BM to continue on the next line? (Therefore a cool feature I didn't know about!)

Cut and paste, then see if it runs, and you'll have your answer.

the '..' are line continuation if you haven't guessed yet.
Anyway, this seems to do the job using standard Bmax commands :
Function Drawrect1( x:Float, y:Float, w:Float,h:Float, fill:Int=True)
	Local origin_x:Float
	Local origin_y:Float
	GetOrigin origin_x,origin_y
	Local handle_x:Float
	Local handle_y:Float
	GetHandle handle_x,handle_y
	Local xy:Float[]=[x,y,x+w,y,x+w,y+h,x,y+h]
	If fill
		DrawPoly xy
	Else
		Local x1:Float=xy[xy.Length-2]
		Local y1:Float=xy[xy.Length-1]
		For Local i:Int=0 Until Len xy Step 2
			Local x2:Float=xy[i]
			Local y2:Float=xy[i+1]
			DrawLine (handle_x + x1 , handle_y + y1 , handle_x + x2 , handle_y + y2) 
			x1=x2
			y1=y2
		Next

	EndIf
End Function
Graphics 800 , 600
drawrect1(100 , 100 , 100 , 100)
drawrect1(10,10,110,110,False)
Flip
WaitKey()


The easiest way to draw a rectangle outline:
Function DrawOblong( x#, y#, w#, h# )
DrawLine( x , y , x + w , y)
DrawLine( x+w , y , x + w , y+h)
DrawLine( x+w , y+h , x , y+h)
DrawLine( x , y+h , x , y)
End Function

And to create a ellipse outline:
(X and Y are centre of oval, w & h are RADIUS.)
Function drawOvate( x# , y# , w# , h#)
For Local n% = 1 To 360
	Plot( x + w * Cos(n) , y + h * Sin(n) )
Next
End Function

Lastly an ellipse that fits within the specified rectangular area (in the same way that the blitzmax drawoval does)
Function drawEllipse( x# , y# , w# , h#)
Local rh% = h / 2
Local rw% = w/2
For Local n% = 1 To 360
	Plot( rw + x + rw * Cos(n) , rh + y + rh * Sin(n) )
Next
End Function


On a speed note:
It is 5 times quicker to draw a filled rectangle inside another filled rectangle using Blitzmax drawrect() than drawing the four lines to make to edges.

Drawing an oval with either of the latter two functions is about 20 times slower than the Blitzmax drawOval().

Hope this helps.

Thank you all for your code and suggestions. The speed issue is slightly worrying, but none of my games are particularly intensive so it shouldn't be a problem.

I'm curious... did non-fill shapes from earlier Blitz Basics become this slow?

In some of the links people talk about some kind of OpenGL stuff to do the same thing. Would this be as slow?

Thanks.

In most of the games and programs I've written I do not draw anything manually.

The most common way is to load .PNG files containing pre-drawn images and place them on the screen.