UnchiuDawg Posted October 17, 2017 Share Posted October 17, 2017 (edited) Hello, I am trying to make a scroll bar that can be dragged using the dx functions. Long story short, want to compare the absoluteY returned by onClientClick with the absoluteY of the current frame (by using onClientRender). The only way to get the current cursor location this way is by using getCursorPosition, which does not return an absolute position. I couldn't find any other function to do this and dividing the screen height by the float returned by getCursorPosition is not accurate. Is there any way to do this? Am I missing something? plz halp lol Edited October 17, 2017 by UnchiuDawg Link to comment
Scripting Moderators thisdp Posted October 17, 2017 Scripting Moderators Share Posted October 17, 2017 local scw,sch = guiGetScreenSize() local cursorX,cursorY = getCursorPosition() local absX,absY = cursorX*scw,cursorY*sch 1 Link to comment
UnchiuDawg Posted October 17, 2017 Author Share Posted October 17, 2017 (edited) 21 minutes ago, thisdp said: local scw,sch = guiGetScreenSize() local cursorX,cursorY = getCursorPosition() local absX,absY = cursorX*scw,cursorY*sch 42 minutes ago, UnchiuDawg said: dividing the screen height by the float returned by getCursorPosition is not accurate. I realised my typo, I meant to say that multiplying the float returned by getCursorPosition with the screen height is not accurate. I'd like to know if there is a way to get a more accurate position ^^ Thanks for replying anyway. Edited October 17, 2017 by UnchiuDawg Link to comment
Tails Posted October 17, 2017 Share Posted October 17, 2017 (edited) 2 hours ago, UnchiuDawg said: I couldn't find any other function to do this and dividing the screen height by the float returned by getCursorPosition is not accurate. Something else must be off in your script. For example the way you're drawing the GUI, the positions may be off, or you might have to adjust the mouse pos accordingly. Show us how you're drawing the stuff, in e.x. the positions. Multiplying the positions by the screen size makes it as accurate as it can be. The relative positions that getCursorPosition gives you are just values between 0 and 1, they're fixed they never change. Each pixel you move to will have the same float. It's not a matter of accuracy. Edited October 18, 2017 by Tails 1 Link to comment
Scripting Moderators thisdp Posted October 18, 2017 Scripting Moderators Share Posted October 18, 2017 (edited) 9 hours ago, Tails said: Something else must be off in your script. For example the way you're drawing the GUI, the positions may be off, or you might have to adjust the mouse pos accordingly. Show us how you're drawing the stuff, in e.x. the positions. Multiplying the positions by the screen size makes it as accurate as it can be. The relative positions that getCursorPosition gives you are just values between 0 and 1, they're fixed they never change. Each pixel you move to will have the same float. It's not a matter of accuracy. Refer to dgs. https://forum.multitheftauto.com/topic/95964-releasethisdps Edited October 18, 2017 by thisdp 1 Link to comment
idarrr Posted October 18, 2017 Share Posted October 18, 2017 local scw,sch = guiGetScreenSize() local cursorX,cursorY = getCursorPosition() local absX,absY = cursorX*scw,cursorY*sch Code above will always return correct absolute coordinate. Maybe you have some problem on client click event, because it's dragging. 1 Link to comment
Scripting Moderators thisdp Posted October 18, 2017 Scripting Moderators Share Posted October 18, 2017 Or try this. onClientCursorMove 1 Link to comment
Tails Posted October 18, 2017 Share Posted October 18, 2017 6 hours ago, thisdp said: Refer to dgs. https://forum.multitheftauto.com/topic/95964-releasethisdps What about it? Link to comment
Scripting Moderators thisdp Posted October 18, 2017 Scripting Moderators Share Posted October 18, 2017 1 hour ago, Tails said: What about it? Since the problem comes from dx scrollbar, DGS(a dx lib) can help him to solve the problem and give him a reference. 1 Link to comment
UnchiuDawg Posted October 18, 2017 Author Share Posted October 18, 2017 Thank you everybody, I managed to make it as accurate as possible by using onClientCursorMove. To answer a few questions: I would drag the scroll bar by comparing the absolute position clicked (by using onClientClick) with the float position returned by getCursorPosition multiplied by the screenHeight. I used math.ceil in order to move the scroll bar if there was even a slight difference to approximate the distance between those two positions to one unit. The "problem" was that sometimes the absolute position clicked and the float multiplied by the scren height would not be the same (even though I haven't moved the cursor yet) perhaps by a few pixels, which ended up moving the scroll bar as if I had moved the cursor. This wasn't a huge problem and I know I could have fixed it by not using math.ceil for any value between 0 and 1, but before trying that I was curious if there was any function/event I missed (and it turns out there was). So thanks again ^^ 1 Link to comment
idarrr Posted October 21, 2017 Share Posted October 21, 2017 (edited) mouseOverScrollbar = false addEventHandler("onClientClick", root, function (button, state, cx, cy) local x, y -- your scrollbar position local width, height -- your scrollbar with and height if button == "left" then if state == "down" then if ( cx >= x and cx <= x + width ) and ( cy >= y and cy <= y + height ) then mouseOverScrollbar = true else mouseOverScrollbar = false end elseif state == "up" then mouseOverScrollbar = false end end end ) addEventHandler( "onClientCursorMove", root, function () if mouseOverScrollbar then -- your calculation here end end ) Edited October 21, 2017 by idarrr 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