Karuzo Posted August 1, 2014 Share Posted August 1, 2014 Hey Guys, I'm working on my phone script and i got some problems with checking the cursor position. It always draws the rectangle on the wrong cursor position. I want that the rectangle shows up when i'm over the image. But it shows up if i'm near the chat. Dunno why. Screen: My Code: local x, y = guiGetScreenSize() local w,h = 400,600 local px, py = x/2-w/2,y/1.5-h/1.5 data.renderTarget = dxCreateRenderTarget(w, h, true) function render() if data.open then dxSetRenderTarget(data.renderTarget) -- draw render dxDrawImage(0,0, w, h, "m7render.png", 0, 0, 0, tocolor(255, 255, 255, 255), false) -- Background dxDrawText(data.network, 75, 70, x, y, tocolor(254, 254, 254, 255), 1, "default-bold", "left", "top", false, false, false, false, false) -- network dxDrawText(data.batterycharge.." %", 400, 10, x, y, tocolor(254, 254, 254, 255), 1.10, "default-bold", "right", "top", false, false, false, false, false) -- batterycharge dxDrawText(("%s:%s Clock"):format(getRealTime().hour, getRealTime().minute), 200, 10, x, y, tocolor(255, 255, 255, 255), 1.00, "default-bld", "center", "center", false, false, false, false, false) -- realtime -- draw apps for index, value in pairs ( data.apps ) do local name, line, row, icon = unpack(data.apps[index]) if isAppValid(name) and icon then dxDrawImage((30)+line*50,100+(row*50),64,64,icon,0,0,0,tocolor(255,255,255,255),false) outputChatBox(line.." "..row) if isMouseWithinRangeOf((30)+line*50,64,100+(row*50),64) then -- this is the part outputChatBox("lol rec") dxDrawRectangle((30)+line*50,100+(row*50),64,64,tocolor(255,255,255,255),false) end end end dxSetRenderTarget() dxDrawImage(px, py, w, h, data.renderTarget, 0, 0, 0, tocolor(255, 255, 255, 255), false) end end function getFreeAppPosition() for index, value in pairs ( data.apps ) do if index == #data.apps then local name, line, row, icon = unpack(data.apps[index]) if line < 4 then return ( (line or 0) + 1 ), ( (row or 0) ) elseif line == 4 then return ( 1 ), ( (row or 1) + 1 ) else return false end end end end function newApp(name, icon) if #data.apps < data.maxApps+1 then local line, row = getFreeAppPosition() table.insert(data.apps, {name, line, row, icon}) end end newApp("Settings", "settings.png") function isAppValid(name) if name ~= "placeholder" then return true else return false end end function isMouseWithinRangeOf(psx,pssx,psy,pssy) if isCursorShowing() == false then return false end local cx,cy = getCursorPosition() cx,cy = cx*x,cy*y if cx >= psx and cx <= psx+pssx and cy >= psy and cy <= psy+pssy then return true,cx,cy else return false end end Link to comment
Bonsai Posted August 1, 2014 Share Posted August 1, 2014 Why are you using a render target? Link to comment
Karuzo Posted August 1, 2014 Author Share Posted August 1, 2014 Why not ? lol It's easier to work with. Link to comment
Bonsai Posted August 1, 2014 Share Posted August 1, 2014 True, but a render target creation can fail due to memory, so I avoid using them as much as possible. And I also think this is causing your problem. e.g. 0 in rendertarget isn't equal to 0 on screen. Link to comment
Karuzo Posted August 1, 2014 Author Share Posted August 1, 2014 I know that. That's why i'm asking how i can calculate that position. Link to comment
Bonsai Posted August 1, 2014 Share Posted August 1, 2014 Well try, render target start + position inside of the render target. Link to comment
Karuzo Posted August 1, 2014 Author Share Posted August 1, 2014 Well try, render target start + position inside of the render target. Huh yeah was that easy, idk why i didn't come up to this. Thanks Link to comment
iAxel Posted January 27, 2015 Share Posted January 27, 2015 How to do? I need the same thing. To calculate position of the cursor inside RenderTarget Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now