midhandle images & scale

Monkey Forums/Monkey Programming/midhandle images & scale

Supertino(Posted 2011) [#1]
In Blitz Max if you use midhandle on an image and then use Scale the image will scale from the middle outwards (grows in all four directions), in Monkey a midhandled image will still scale from the top left (grows to the right and down).

Is this by design or a bug? Here's some code.

Import mojo
Import monkey

Global img_but:Image
Global Width:Int
Global Height:Int
Global X:Int
Global Y:Int
Global Size:Float

'... Main Function
Function Main:Int() ; New MyApp ; End

'... Main Class
Class MyApp Extends App

	Method OnCreate()	
		SetUpdateRate 60
		img_but = LoadImage("quit.png",1,img_but.MidHandle)
		Width 	= img_but.Width
		Height 	= img_but.Height
		X = 100
		Y = 100
		Size = 1.0
	End
	
	Method OnUpdate()	
		Local Mx:Int = MouseX() + Width/2
		Local My:Int = MouseY() + Height/2
		If Mx > X And Mx < Width + X And My > Y And My < Height + Y
			Size = Size + 0.025
			If Size > 1.2 Then Size = 1.2
		Else
			Size = Size - 0.025
			If Size <= 1.0 Then Size = 1.0
		Endif
	End
	
	Method OnRender()
	Cls	
		Scale Size , Size
		DrawImage img_but , X , Y
		Scale 1.0 , 1.0
	End
	
End




MikeHart(Posted 2011) [#2]
With the Scale, Rotate and Translate Commands you act on the total canvas and not the image.


MonkeyPig(Posted 2011) [#3]
I haven't tried your code but I'm pretty sure the line

img_but = LoadImage("quit.png",1,img_but.MidHandle)


should be

img_but = LoadImage("quit.png",1, Image.MidHandle)


That is to say not your object "img_but" but the Const within the class Image of which your object "img_but" is a instance of.

Horrible explantion. Make sense?


MikeHart(Posted 2011) [#4]
There is a variation of Drawimage that uses its own scale and rotation parameters.


MonkeyPig(Posted 2011) [#5]
The MidHandle in Monkey works perfectly. But as Mike says there's a Draw method for scaling and rotating.

That said - you still need to correctly set the Position (MidHandle) if you want to rotate about centre.

You can do it at Load or you can do it with the image. In this case your object - img_but.SetHandle(...)


Supertino(Posted 2011) [#6]
Thanks for the quick answers guys, didn't realise there were two different DrawImage commands - applying my Scale to the alternative solved the issue.

Seems either;

img_but = LoadImage("quit.png",1,img_but.MidHandle)
img_but = LoadImage("quit.png",1,Image.MidHandle)


Works.. but

img_but = LoadImage("quit.png")
img_but.MidHandle


Does not work? Throws an error.

But I guess img_but.SetHandle(Width/2,Height/2) will work.


MikeHart(Posted 2011) [#7]
img_but.MidHandle


It is just a constant value. Have a look at the image class of mojo.

If you want to set the handle after you have loaded the image, you have to do it with SetHandle.


Shinkiro1(Posted 2011) [#8]
Or you can use this function:

Function MidHandle:Void( image:Image )
	image.SetHandle( Floor(image.Width() * 0.5), Floor(image.Height() * 0.5) )
End