Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Locate command on the ttf graphical screens
#1
I have been learning to use the graphical screen 12 along with a ttf font.   I have noticed that the locate command behaves differently here. 
if you have locate 5,1 that works and it calculates for the given font where line 5 would be, but the x =1 moves it over 1 pixel.  Seems like it should move over a space.   It does work in that if I say locate 5, 35 it moves over 35 pixels,      It would be more intuitive if it got the width of a space in the font and moved it over that much.  Anyway comments and criticism welcome.  If there is a reason for it working this way I would be interested in knowing it.
Thanks,
John
Reply
#2
Locate command moves character cell: lines/rows and columns, according to font you use, 8x16 pixels character cell size in pixels for default.

If your font is 15X20 the screen will be divided by 20 pixels going down for row and width divided by 15 for columnns numbers (assuming a graphics <> 0 screen).

To go pinpoint pixel by pixel use _PrintString(x_pix, y_pix), text$ in graphics screen =non 0 for top left location of first print cell.
Code: (Select All)
Screen 12

_PrintString (10, 15), "Hello"
Locate 10, 15: Print "World"

   

LOCATE came from original BASIC back in days where everything was printed on paper so locating a print item made sense to find print row first then tab over to print column, in graphics all is x, y pixels and that came when screens were being used in place of paper for output.
b = b + ...
Reply
#3
@bplus has misdiagnosed your problem as you have left out several important pieces of information for him and no working code to run to showcase the issue in discussion.

The issue you are seeing stems down to this:

LOCATE has two separate methods to move text to a certain position on the screen.   
1) With a monospaced font, text will locate by column and row according to _FontWidth and _FontHeight.
2) With a variable-width font, there is no set _FontWidth so you can't just move X characters to the right.  Instead, it moves by PIXELS for positioning to the right.  The up/down row position is the same as always, as you still have a _FontHeight, but there is no valid _FontWidth for left/right position so pixels are used instead.

Solution?

1) Load a monospace font:  _LOADFONT(fontname$, fontsize, "monospace")     <-- This will give you a valid _FontWidth and allow proper LOCATE positioning based on the width.

2) Swap over to using pixel coordinates for the left/right.  Instead of moving 1 pixel, move.. 8 or so per character, for your font (or whatever you choose to be a reasonable guesstimate for a midpoint of your font sizes)

Anywho... that's the issue you're seeing in a nutshell.  Wink
Reply
#4
True, I missed how Locate works with variable width font @SMcNeill

I did not diagnose any problem, merely stated facts.
b = b + ...
Reply
#5
A quick example of the issue:

Code: (Select All)
Screen 12
$Color:0
f = _LoadFont("courbd.ttf", 16)
g = _LoadFont("courbd.ttf", 16, "MONOSPACE")

Print "First, I'm going to put some text on screen in RED, using variable width font.": Sleep 2
Color Red
_Font f
Locate 10, 10: Print "Hello (10, 10)": Sleep 2
Locate 5, 15: Print "World (5, 15)": Sleep 2

Locate 3
Color BrightWhite
Print "Now, I'm going to put some text on screen in GREEN, using a monospaced font.": Sleep 2
Color Green
_Font g
Locate 10, 10: Print "Hello (10,10)": Sleep 2
Locate 5, 15: Print "World (5, 15)": Sleep 2

Color White
Locate 7
Print "See the difference in the positions?"
Reply
#6
As I mentioned, it all steps back to this:

Code: (Select All)
Screen 12
$Color:0
f = _LoadFont("courbd.ttf", 16)
g = _LoadFont("courbd.ttf", 16, "MONOSPACE")

_Font f
Print _FontWidth, _FontHeight, "notice the fontwidth with variable width?"
_Font g
Locate 2: Print _FontWidth, _FontHeight; " vs monospaced"

Variable width fonts have no set fontwidth, so you can't just move character width left/right, so it moves by pixels instead.
Reply




Users browsing this thread: 5 Guest(s)