Starchasers / OCGlasses

mod for minecraft and addon for Open Computers
zlib License
31 stars 17 forks source link

Off-set coordinates #36

Closed Shazuli closed 6 years ago

Shazuli commented 6 years ago

Hi!

I've been working on a button API for your mod OpenGlasses in latest (OpenGlasses-MC1.12.1-1.5.4) version of it. I was done with the graphics, so I was going to add functionality to the buttons now. So I made a event test for click on the screen. Seems to be working fine but I noticed when I had a small square to be placed on the x and y values that it was incorrect. The higher up I went on the axis the more off it was. At 0,0 it was right on spot, but the more the values grew the more off they were. I made a small gif to show the effect. Gif

Script:

component = require("component")
event = require("event")
glasses = component.glasses

local box = glasses.addRect()
box.setSize(10,10)
box.setColor(1,1,1)
box.setAlpha(0.8)
while true do

local _,_,_,x,y = event.pull("interact_overlay")

box.setPosition(x,y)
print(x,y)

end
ben-mkiv commented 6 years ago

well... this should work now ;)

component = require("component")
event = require("event")
glasses = component.glasses

glasses.removeAll()

local box = glasses.addRect()
box.setSize(10,10)
box.setColor(1,1,1)
box.setAlpha(0.8)

function clickEvent(id, device, user, x, y, button, maxX, maxY)
  fX = x * (512 / maxX)
  fY = y * (288 / maxY)
  box.setPosition(fX, fY)
  print(fX, fY)
end

event.listen("interact_overlay", clickEvent)

event.pull("interrupted")

event.ignore("interact_overlay", clickEvent)
marcin212 commented 6 years ago

Fixed