How to center rotation (midhandle) a rect or oval?

BlitzMax Forums/BlitzMax Programming/How to center rotation (midhandle) a rect or oval?

Well, I think the simpliest way is to save the Rect or Oval in an Image. Maybe like this

Type TItem
Field X,Y:Int
Field W,H:Int

Field Image:TImage

Function create:TItem(x,y,w,h,Oval:Byte = False)
	Local Item:TItem = New TItem
	Item.X = X
	Item.Y = Y
	Item.W = W
	Item.H = H
	Item.Image = CreateImage(w,h)
	
	Cls
	If Oval = True Then
		DrawOval(0,0,w,h)
	Else
		DrawRect(0,0,w,h)
	EndIf
	GrabImage(Item.Image,0,0)
	
	Cls
	
	Return Item
End Function

Method Draw()
	DrawImage Image,x,y	
End Method

End Type

Graphics 800,600,0,-1

Global R:TItem = TItem.Create(400,300,100,100)

Global Rot# = 0
Global MidHandle:Byte = False

While Not KeyHit(Key_Escape)

Cls
SetRotation(Rot)

R.Draw()


If KeyHit(KEY_Space) Then 
	If MidHandle = False Then 
		MidHandleImage(R.Image)
		MidHandle = True
	Else
		SetImageHandle(R.Image,0,0)
		MidHandle = False
	EndIf
EndIf


If KeyDown(Key_A) Then Rot:+.1
If KeyDown(Key_Y) Then Rot:-.1

SetRotation 0

SetColor(255,0,0)
DrawOval 400,300,5,5
SetColor 255,255,255

Flip
Wend
	


Press Space to toggle between Midhandle and use A and Y
to Rotate