Origin of coordinates: print, printf vs the rest

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Origin of coordinates: print, printf vs the rest

Post by kikito »

This is a small thing that bugs me.

graphics.print & graphics.printf consider its x, y parameters as "bottom-left" but the rest of graphics functions use them as "top-left".

For example, I've done a function that prints a text with background color (using rectangle)

Code: Select all

function colorPrint(text, x, y, fontColor, backgroundColor, font, fontHeight)

  -- ... (fill fontColor, backGroundColor, font & fontHeight with default values)

  local width = font:getWidth(text)

  -- draw the rectangle
  love.graphics.setColor(unpack(backgroundColor))
  love.graphics.rectangle( "fill", x, y, width, fontHeight )
  love.graphics.print(text, x, y)

  -- print the text
  love.graphics.setFont(font, fontHeight)
  love.graphics.setColor(unpack(fontColor))
  love.graphics.print(text, x, y)

end
I got this:

Code: Select all

      My Sample Text
    +----------------+
    |                |
    +----------------+
So the rectangle appears *below* the text. I had to make this small change in order to alineate it correctly:

Code: Select all

love.graphics.print(text, x, y-fontHeight)
Shouldn't all the functions use x & y the same way? Or am I missing something?
When I write def I mean function.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Origin of coordinates: print, printf vs the rest

Post by bartbes »

Actually, people chose to keep their fonts bottom-left, there is a topic somewhere where they voted for it.

EDIT: oh, nvm, it appears the votes were for top-left, in that case I wonder why it hasn't been added yet, I'll add it to the feature tracker.
EDIT2: done, and, for completeness the url: Text Origin Decide-icidal
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: Origin of coordinates: print, printf vs the rest

Post by kikito »

In that case, it might be wise to rename the parameters in the documentation - I'm thinking top, left instead of x, y.

I volunteer to do this change, if you think it is worth it.
When I write def I mean function.
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 56 guests