AutoMidHandle

BlitzMax Forums/BlitzMax Beginners Area/AutoMidHandle

Ant(Posted 2006) [#1]
Hi, I'm setting AutoMidHandle at the beginning of my code (after I have initiliased graphics) and yet when I rotate an image, its still rotating from the top left corner. However, if I put this command right before I create the image I am rotating, it rotates from the centre (which is what I'm after). Now - according to the docs -
'When auto midhandle mode is enabled, all images are automatically 'midhandled' (see MidHandleImage) when they are created. If auto midhandle mode is disabled, images are handled by their top left corner.'

So surely if I set this at the start of my code ALL images thereafter should be handled from the middle?
Thanks


tonyg(Posted 2006) [#2]
If you used automidhandle(enable) try changing it to Automidhandle(true)


Ant(Posted 2006) [#3]
excellent ;-) Thanks tonyg - was surprised by 'enable'...never encountered it before.

Thanks again!


JazzieB(Posted 2006) [#4]
AutoMidHandle doesn't automatically apply a mid handle to all images that have already been loaded or created. It does this WHEN you load or create any new ones.

The reason for this is that the TImage Type has HandleX# and HandleY# properties (they might be called something slightly different) that keep a record of the handle to use when it comes to drawing them. By default, this is set to 0,0, unless you have AutoMidHandle enabled, in which case, it will become the centre of the image.

For the behaviour you were expecting, it would either have to go through all your images and reset the handle (not a good idea) or over-ride any handle settings when it comes to drawing your images. But why would you change it for any image once it has been created? Surely you'd want the handle to remain in the same place. However, if you do want to change it, there are other commands that handle image handles.

I think you just misunderstood the docs, as the clue to its action is there...

'When auto midhandle mode is enabled, all images are automatically 'midhandled' (see MidHandleImage) when they are created. If auto midhandle mode is disabled, images are handled by their top left corner.'

Anyway, just a little explanation there. Can't remember if Blitz3D did things differently, which may have led to the confusion.


tonyg(Posted 2006) [#5]
JazzieB, I think the problem is the documentation states...

Function AutoMidHandle( enable )


when it should be AutoMidHandle (true).
Graphics 800,600
AutoMidHandle(enable)
image1:TImage=LoadImage("max.png")
AutoMidHandle(True)
image2:TImage=LoadImage("max.png")
While Not KeyHit(key_escape)
  Cls
  DrawImage image1,0,0
  DrawImage image2,0,ImageHeight(image1)
  Flip
Wend

In fact, I might report it as a bug.


Ant(Posted 2006) [#6]
All I was expecting was that if I put AutoMidHandle at the start of my code, all images created thereafter would abide by this (the instruction is right at the top of my code before any images are created or loaded). The docs state:

AutoMidHandle(enable)

..when as TonyG kindly pointed out to me, it should be

AutoMidHandle(true)

which works perfectly and as expected! Thanks for the help.


Grey Alien(Posted 2006) [#7]
there is nothing wrong with the docs. It is saying you need to pass the AutoMidHandle function an integer variable or constant (which they have chosen to call enable, it could be called foo). The integer variable plainly must be 0 or 1 (False or True if your prefer typing :-)).

When you called AutoMidHandle(enable) BlitzMax made a local variable called "enable", initialised it to 0 and passed it into AutoMidHandle thus switching it off (or doing nothing if it was already off)! If you had put Strict at the top of your code, it would have told you that "enable" was an undeclared variable, in fact it would have said "identifier Enable not found".

Hope this helps your understanding of the issue even though you've solved the problem.


tonyg(Posted 2006) [#8]

there is nothing wrong with the docs.


well, that's subjective.


It is saying you need to pass the AutoMidHandle function an integer variable or constant (which they have chosen to call enable, it could be called foo). The integer variable plainly must be 0 or 1 (False or True if your prefer typing :-)).


Sorry, which bit says or is saying that? If that's what it means then why isn't that what it says?
Isn't the documentation written for those who don't know how to use a command and would like to rather than those that already know?

When you called AutoMidHandle(enable) BlitzMax made a local variable called "enable", initialised it to 0 and passed it into AutoMidHandle thus switching it off (or doing nothing if it was already off)! If you had put Strict at the top of your code, it would have told you that "enable" was an undeclared variable, in fact it would have said "identifier Enable not found".


Yes, very good...and? but not the point. The point is the doc not saying the values are true/false. Simple as that.

I notice the doc doesn't say...

Function GetHandle( dogger# Var,Irish# Var )


and assume people realise dogger and Irish are simply float variables to hold the return from gethandle.


Grey Alien(Posted 2006) [#9]
Directly above the automidhandle definition in the docs is this definition
AutoImageFlags( flags )

Now you wouldn't type AutoImageFlags(flags) in your code, yet that is the equivalent of what Ant did because he didn't get that "enable" was an arbitrary parameter name for an Integer, and that the text implied it could be 0 or 1. Sure perhaps it could be made clearer by explictly saying "If enable is 1 (or True) then ... and If enabled is 0 (or False) etc ...) Ant just made a simple mistake witha simple function and I was trying to help him understand why, instead of just fixing it.


tonyg(Posted 2006) [#10]
AutoImageFlags goes on to say...

The auto image flags are used by LoadImage and CreateImage when no image flags are specified. See LoadImage for a full list of valid image flags. AutoImageFlags defaults to MASKEDIMAGE | FILTEREDIMAGE.


so explains what flags are and what they can be set to.
I think we're just going to have to disagree.


Grey Alien(Posted 2006) [#11]
ok then. Acutally I said they could be improved in my second post, but was making a point to help Ant understand WHY he went wrong.