something off the canvas, then scaled to be seen

Monkey Forums/Monkey Programming/something off the canvas, then scaled to be seen

C10B(Posted 2012) [#1]
Hi,

I'm knew to this so please treat me carefully :-)

I add some angeltext to the screen. My canvas is 480 high, and I write the text at 500, so it is off the screen. I also apply some scaling, say 0.5, so the actual position to display the text is 250. But, because the text was originally rendered off screen, it is not displayed at all, even after rescale.
I've tried setting the scissors to a huge area, but no joy. (PS I'm only playing with HTML5 at the moment, I haven't tested this on any other platform).

Is this by design? Any ideas how I can render text this way? (ie that is initially off screen until it is scaled into the correct place?)

Thanks

C10B


Halfdan(Posted 2012) [#2]
I'm not 100% sure, but if the angeltext behaves as an image, the position you specify is the upper left corner of the text.

This means if you set scale (which applies to the size of the image, not the position), its upper left corner is still out of the screen.

Try setting MidHandle to True if possible (the drawing position will become the center), or draw it with an offset.

[EDIT] I understand your mistake now. If you Scale(0.5,0.5) and draw something at an X 100, it won't be drawn at 50. The Scale just applies to the image size, not the position (this is by design).

Oh and welcome to monkey!


C10B(Posted 2012) [#3]
Thanks minke.
I think I might need to upload my code. It's definitely doing something weird, it might well be my coding and lack of understanding. It's about 500 lines at the moment so I'll try to strip out just the pertinent part and see if I can recreate the issue with just a few lines of code.

I wonder if the problem is the other way round. If my height is 480, but the overall scale is set to 0.5, and then I draw something at 480 it no longer sits at the bottom of the screen, but somewhere in the middle. So now with this scaling I still want to put something in the bottom half of the screen, I have to specify numbers greater than 480, and it's these objects at greater than 480 that are not visible. So with a scale of 0.5 I can only seem to draw things in the top half of the screen. Is that a better explanation?

Thanks


C10B(Posted 2012) [#4]
Here's a little demo

Import mojo
Import angelfont
Import simpleinput
Import simpletextbox

Class ScaleTest Extends App

Field font:AngelFont

Method New()
SetUpdateRate 30
End Method

Method OnCreate()
font = New AngelFont()
font.LoadFontXml("angel_verdana")
End


Method OnRender()
Cls 0,0,0
Scale 0.5,0.5

SetColor 0,0,255
DrawRect(0,0,640,480)
SetColor 255,255,255

'this text appears towards the bottom of the blue area,
'but in reality it is only half way down the screen
SimpleTextBox.DrawHTML("Some Text",200,450,300, AngelFont.ALIGN_CENTER)

'this text has to placed beyond 480 to get it displayed in the bottom half
'of the screen, but because it is beyond 480 it is not rendered!
'The 0.5 scale has prevented my drawing to the whole display area!
SimpleTextBox.DrawHTML("Some Text",200,580,300, AngelFont.ALIGN_CENTER)
End Method

Method OnUpdate:Int()

End Method
End

Function Main()
New ScaleTest
Return 0
End


Halfdan(Posted 2012) [#5]
Just tested it, you seem to be right, scale does affect position, sorry for that.

I'll check if I can produce your problem


Halfdan(Posted 2012) [#6]
I see, forget all what I said about the scale not affecting position, obviously it does

You are using SimpleTextBox to draw the Text, it seems like the problem is within that class.

It contains these lines in the drawing code:
If y+yOffset > DeviceHeight()
    Return
Endif
so super long texts won't be drawn outside the viewport, but it doesn't account for scale. You can try to patch that the SimpleTextBox or draw the font directly

Change
SimpleTextBox.DrawHTML("Some Text",200,580,300, AngelFont.ALIGN_CENTER)
To
font.DrawHTML("Some Text",200,580)



C10B(Posted 2012) [#7]
I'm looking at those last 2 lines where you say change one to the other, and the change must be too subtle for me to see!


Halfdan(Posted 2012) [#8]
Oh I'm really messing up today, fixed that


C10B(Posted 2012) [#9]
lol thanks.
I was using the SimpleTextBox because it allows me to align center.
I've tried editing the SimpleTextBox code and have just removed that check, and it works!
Thanks very much for your help :-)

PS Is this a bug? Should we report it somewhere?

Thanks


Halfdan(Posted 2012) [#10]
You can use
font.DrawHTML("Some Text",200,580,AngelFont.ALIGN_CENTER)
I think SimpleTextBox is just an example of how to use the AngelFont, so not really a monkey bug.