Jump to content

getCursorPosition in a rendertarget


Karuzo

Recommended Posts

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:

ka44v77b.png

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
  • 5 months later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...