Page 1 of 2
Mouse Coordinates vs. Graphics Coordinates.
Posted: Tue Oct 17, 2017 3:19 pm
by .rhavin
Code: Select all
function showTest()
party.party:addConnector('onDrawGui', self.go.id, "renderTest")
end
function renderTest(self,context)
local text = context.mouseX .. ", " .. context.mouseY
context.drawText(text, 50, 50)
end
As you can see, the text is always printed into graphic-context coordinates (50,50) regardless if u go fullscreen or not. But they have little to do with the coordinates returned from context.mouse[X/Y] - how do I convert them?
Re: Mouse Coordinates vs. Graphics Coordinates.
Posted: Tue Oct 17, 2017 10:15 pm
by .rhavin
They are BTW congruent if u are fullscreen but how do I get correct coordinates in th preview-window?
Re: Mouse Coordinates vs. Graphics Coordinates.
Posted: Tue Oct 17, 2017 10:22 pm
by minmay
The miniature preview window always reports its size (and the mouse position) incorrectly. You won't be able to make GUI code that works in it without a great deal of effort, and there's little purpose in doing so since the problem is limited to the preview window. Just press f to change it to fullscreen and back.
Re: Mouse Coordinates vs. Graphics Coordinates.
Posted: Tue Oct 17, 2017 10:33 pm
by Isaac
minmay wrote: Just press f to change it to fullscreen and back.
...And even then it's still slightly off.. because of the editor's title-bar.
One has to get it close, then look at it in-game.
I have found it useful take screenshots of the game, and load them into a graphics editor that can magnify to the point of pixel counting.
Re: Mouse Coordinates vs. Graphics Coordinates.
Posted: Tue Oct 17, 2017 10:47 pm
by .rhavin
This is a known problem? Why not just fix it? The button-function obviously does it right…
Re: Mouse Coordinates vs. Graphics Coordinates.
Posted: Wed Oct 18, 2017 1:21 am
by Isaac
.rhavin wrote:This is a known problem? Why not just fix it? The button-function obviously does it right…
On (grand) occasion Petri (the programmer) has logged in here, and implemented feature requests over a drink...on the spot, though it's rare; (and awesome). But I don't expect another patch for LoG1 or LoG2; certainly not soon. The studio is working on a new game; (and has technically changed their name to do it). The editor works fine for most users; the GUI stuff is esoteric.
**We could possibly get fullscreen for the editor if Petri does another one of his Gløgg sessions.
Re: Mouse Coordinates vs. Graphics Coordinates.
Posted: Wed Oct 18, 2017 2:41 am
by .rhavin
That not a missing feature, thats a simple bug. the intern coordinates are calculated correctly, thats why button() works with absolute coordinates. its just that mousex, mousey, width and height dont get the correct values when you're not in fullscreen.
Either mousex / mousey should get the scaled coordinates or they should get real pixels (they currently do) but then width and height must get the real screen size. currently, when you are in preview, width is negative and goes to zero if you resize the window to half the maxiumum size.
The best way would be if we could get this, wich is with absolute certaincy already known when we get access to the graphiccontext:
mouseX, mouseY : real pixels from top left
rectWindow : real pixels window area
for convenience, it would be also nice to have:
rectParty : coordinates of the the party area
rectControl : for applications with on screen movers: its area
Re: Mouse Coordinates vs. Graphics Coordinates.
Posted: Wed Oct 18, 2017 2:04 pm
by .rhavin
ContextUnfucker – gets real mouse coordinates and real width and height
Code: Select all
function showPanel()
party.party:addConnector('onDrawGui', self.go.id, "renderTest")
end
function contextUnfucker(maxw, maxh)
cufu = {}
function cufu.init(self, w, h)
self.x = 0
self.y = 0
self.w = w
self.h = h
self._w = w
self._h = h
end
function cufu.recurse(self, context)
if (self.w > 1) then
local cw = math.ceil(self.w / 2)
if (context.button("", self.x, self.y, cw, self.h) == nil) then
self.x = self.x + cw
end
self.w = cw
end
if (self.h > 1) then
local ch = math.ceil(self.h / 2)
if (context.button("", self.x, self.y, self.w, ch) == nil) then
self.y = self.y + ch
end
self.h = ch
else
if (self.w < 2) then return end
end
self:recurse(context)
end
function cufu.unfuck(self, context)
if (Editor.isRunning()) then
self.w = self._w
self.h = self._h
if (context.button("", 0, 0, self._w, self._h) == nil) then
context.realX = -1
context.realY = -1
context.realW = -1
context.realH = -1
return
else
self.x = 0
self.y = 0
self:recurse(context)
context.realX = self.x
context.realY = self.y
context.realW = context.mouseX + context.width - self.x
context.realH = context.mouseY + context.height - self.y
end
else
context.realX = context.mouseX
context.realY = context.mouseY
context.realW = context.width
context.realH = context.height
end
end
cufu:init(maxw, maxh)
return cufu
end
function renderTest(self, context)
local ufu = contextUnfucker(3000,2000)
ufu:unfuck(context)
local text = context.realX .. ", " .. context.realY
context.drawText(text, 50, 20)
text = context.realW .. ", " .. context.realH
context.drawText(text, 50, 40)
text = context.mouseX .. ", " .. context.mouseY
context.drawText(text, 50, 60)
text = context.width .. ", " .. context.height
context.drawText(text, 50, 80)
end
Re: Mouse Coordinates vs. Graphics Coordinates.
Posted: Wed Oct 18, 2017 5:21 pm
by Isaac
Seeing as there have been nine year old mappers here, and the general vibe of the game and forum is safe for 13+...
This could use an alternate version .rhavin:
Code: Select all
function showPanel()
party.party:addConnector('onDrawGui', self.go.id, "renderTest")
end
function contextUnfouler(maxw, maxh)
cufu = {}
function cufu.init(self, w, h)
self.x = 0
self.y = 0
self.w = w
self.h = h
self._w = w
self._h = h
end
function cufu.recurse(self, context)
if (self.w > 1) then
local cw = math.ceil(self.w / 2)
if (context.button("", self.x, self.y, cw, self.h) == nil) then
self.x = self.x + cw
end
self.w = cw
end
if (self.h > 1) then
local ch = math.ceil(self.h / 2)
if (context.button("", self.x, self.y, self.w, ch) == nil) then
self.y = self.y + ch
end
self.h = ch
else
if (self.w < 2) then return end
end
self:recurse(context)
end
function cufu.unfoul(self, context)
if (Editor.isRunning()) then
self.w = self._w
self.h = self._h
if (context.button("", 0, 0, self._w, self._h) == nil) then
context.realX = -1
context.realY = -1
context.realW = -1
context.realH = -1
return
else
self.x = 0
self.y = 0
self:recurse(context)
context.realX = self.x
context.realY = self.y
context.realW = context.mouseX + context.width - self.x
context.realH = context.mouseY + context.height - self.y
end
else
context.realX = context.mouseX
context.realY = context.mouseY
context.realW = context.width
context.realH = context.height
end
end
cufu:init(maxw, maxh)
return cufu
end
function renderTest(self, context)
local ufu = contextUnfouler(3000,2000)
ufu:unfoul(context)
local text = context.realX .. ", " .. context.realY
context.drawText(text, 50, 20)
text = context.realW .. ", " .. context.realH
context.drawText(text, 50, 40)
text = context.mouseX .. ", " .. context.mouseY
context.drawText(text, 50, 60)
text = context.width .. ", " .. context.height
context.drawText(text, 50, 80)
end
**Something else... I don't know if it was mentioned or not, but just so (and in case you don't) know... There is also good reason to define certain hooks in the object rather than use addConnector() for them. AddConnector() does not support returning True or False, and there are hooks that attach significance to that. Many will cancel actions when they return false; (the function they return to... that is); and consumable items get removed if their onUseItem hook returns true. The addConnector() function is a convenient (and dynamic) way to call hooks when you know that you will never need to use the return value.
Re: Mouse Coordinates vs. Graphics Coordinates.
Posted: Fri Oct 20, 2017 9:24 pm
by .rhavin
Isaac wrote: There is also good reason to define certain hooks in the object rather than use addConnector() for them.
Can you please post an example? I'm completely new to lua and still try to understand. A ›connector‹ in terms of GR seems like something i'd call a callback: if a certain event happens (onDrawAttackPanel), the object (party) looks in his callback table for the event onDrawAttackPanel and calls every id.function specified there – thats how I understand what i read without really having any useful dokumentation
"to define certain hooks in the object " - how?