3B00DG4MER Posted January 21, 2015 Share Posted January 21, 2015 (edited) I've a question about dragging mouse while it's click so i need to make a scrollbar goes up and down or left and right function __scrollbar(button,state,absoluteX,absoluteY,worldX,worldY,worldZ,clickedWorld) local scrollbar = source if (button == "left" and state == "down") then local x,y = dxGetPosition(scrollbar) local w,h = dxGetSize(scrollbar) local progress = dxScrollBarGetScroll(scrollbar) local type = getElementData(scrollbar,"type") if type == "Vertical" then if isMouseWithinRangeOf(x, y + progress/100*(h-100), w, 100) then -- Here check if is hold the mouse in scrollbar in (in Vert Only !!) end elseif type == "Horizontal" then if isMouseWithinRangeOf(x + progress/100*(w-100), y, 100, h) then -- Here check if is hold the mouse in scrollbar in (in Horizontal Only !!) end end end end Help !! Edited January 25, 2015 by Guest Link to comment
3B00DG4MER Posted January 22, 2015 Author Share Posted January 22, 2015 i make it but i have another problem when i drag there's a place only where to drag i made it only for Vertical ! addEventHandler("onClientClick",root,function(button, state, absoluteX, absoluteY, worldX, worldY, worldZ, clickedWorld) for i,sb in ipairs(getElementsByType("dxScrollBar")) do if getElementData(sb,"hover") == true then triggerEvent("onClientDXSBClick",sb,button, state, absoluteX, absoluteY, worldX, worldY, worldZ, clickedWorld) end end end) addEvent("onClientDXSBClick",true) function dxScrollBarMove(element) if (isCursorShowing()) and getElementData(element,"isMoving") then local x,y = getCursorAbsolute() --setElementData(element,"x",x-getElementData(element,"Move:x")) dxScrollBarSetScroll(element,(y-getElementData(element,"Move:y"))) outputChatBox(y) end end function __scrollbar(button,state,absoluteX,absoluteY,worldX,worldY,worldZ,clickedWorld) local scrollbar = source if (button == "left" and state == "down") then setElementData(scrollbar,"isMoving",false) local x,y = dxGetPosition(scrollbar) local w,h = dxGetSize(scrollbar) local progress = dxScrollBarGetScroll(scrollbar) local type = getElementData(scrollbar,"type") if type == "Vertical" then if (intersect(x, y + dxScrollBarGetScroll(scrollbar), x + w, h ,absoluteX,absoluteY)) then outputChatBox(progress/100*(h-100)) setElementData(scrollbar,"isMoving",true) setElementData(scrollbar,"Move:y",absoluteY-y) end elseif type == "Horizontal" then if (intersect(x + progress/100*(w-100), y, 100, h)) then setElementData(scrollbar,"isMoving",true) end end end end addEventHandler("onClientClick",getRootElement(),function(button,state,absoluteX,absoluteY,worldX,worldY,worldZ,clickedWorld) if (button=="left" and state=="up") then for _,scrollbar in ipairs(getElementsByType("dxScrollBar")) do setElementData(scrollbar,"isMoving",false) end end end) Link to comment
3B00DG4MER Posted January 23, 2015 Author Share Posted January 23, 2015 200 Views And No HELP Link to comment
3B00DG4MER Posted January 27, 2015 Author Share Posted January 27, 2015 WHY DAFUCK NO ONE HELPS !?? Link to comment
Dealman Posted January 28, 2015 Share Posted January 28, 2015 Could you be more detailed? Not sure what you mean; does it stop scrolling at a specific location or what? Link to comment
3B00DG4MER Posted January 28, 2015 Author Share Posted January 28, 2015 i want when Client is draging his mouse and it's in the scrollbar then set Scrollbar Position as Mouse Position ! what do i mean is , i want it like GUI MTA:SA Scrollbar Link to comment
Dealman Posted January 29, 2015 Share Posted January 29, 2015 So use onClientClick and getKeyState to make sure the player clicked the scrollbar and left mouse button is being held down. Then you can use either onClientCursorMove or getCursorPosition. Whichever floats your boat. Use those values to manipulate the offset value. Link to comment
3B00DG4MER Posted January 29, 2015 Author Share Posted January 29, 2015 i did now, Can u fix it ?! it's in the second Reply Link to comment
Dealman Posted January 29, 2015 Share Posted January 29, 2015 I might take a look at it later buddy, but there's a lot to go through, and when people merge their functions into the event handlers like that it just gives me a headache to read. You're really better of just naming the functions Does it do anything or is it not working at all? Link to comment
Et-win Posted January 29, 2015 Share Posted January 29, 2015 Just check if the bar is clicked, then just check while moving the mouse if the bar is between the possible sizes where it can move... Link to comment
3B00DG4MER Posted January 29, 2015 Author Share Posted January 29, 2015 i tried 100 WAY to do it But all goes wrong Need Help PLZ Link to comment
3B00DG4MER Posted January 29, 2015 Author Share Posted January 29, 2015 Mod, Lock this topic no one Knows i'll make it with another way maybe if I found Link to comment
Dealman Posted January 30, 2015 Share Posted January 30, 2015 addEvent("onClientDXSBClick",true) function dxScrollBarMove(element) if (isCursorShowing()) and getElementData(element,"isMoving") then local x,y = getCursorAbsolute() --setElementData(element,"x",x-getElementData(element,"Move:x")) dxScrollBarSetScroll(element,(y-getElementData(element,"Move:y"))) outputChatBox(y) end end Is it this part that doesn't work? We can't really help you when you're barely giving us any detail. Are you sure getCursorAbsolute works? What does it output? You're telling us nothing other than "it doesn't work". You need to help us, for us to help you You can't expect us to magically understand how your code would behave in-game. Just be patient, you'll get help eventually. Link to comment
Et-win Posted January 30, 2015 Share Posted January 30, 2015 You also can just place an invisible GUI Scrollbar behind it and get those positions.. Why you want the hard way Link to comment
Saml1er Posted January 30, 2015 Share Posted January 30, 2015 I created a vertical scroll bar script with dx functions. You can take a look if you want. Link to comment
iAxel Posted January 30, 2015 Share Posted January 30, 2015 I created a vertical scroll bar script with dx functions. You can take a look if you want. I'd like to look Link to comment
3B00DG4MER Posted January 30, 2015 Author Share Posted January 30, 2015 addEvent("onClientDXSBClick",true) function dxScrollBarMove(element) if (isCursorShowing()) and getElementData(element,"isMoving") then local x,y = getCursorAbsolute() --setElementData(element,"x",x-getElementData(element,"Move:x")) dxScrollBarSetScroll(element,(y-getElementData(element,"Move:y"))) outputChatBox(y) end end Is it this part that doesn't work? We can't really help you when you're barely giving us any detail. Are you sure getCursorAbsolute works? What does it output? You're telling us nothing other than "it doesn't work". You need to help us, for us to help you You can't expect us to magically understand how your code would behave in-game. Just be patient, you'll get help eventually. I debugged getCursorAbsolute() and Works as it is !! I have no problem I just wanted you guys to finnish it it's hard, the problem is in the _scrollbar function ! Link to comment
3B00DG4MER Posted January 30, 2015 Author Share Posted January 30, 2015 I created a vertical scroll bar script with dx functions. You can take a look if you want. Where is it ?! Link to comment
Dealman Posted January 30, 2015 Share Posted January 30, 2015 I debugged getCursorAbsolute() and Works as it is !! I have no problem I just wanted you guys to finnish it it's hard, the problem is in the _scrollbar function ! So basically, you don't want to learn how to solve it - you just want us to do it for you...? In that case, good luck Link to comment
3B00DG4MER Posted January 30, 2015 Author Share Posted January 30, 2015 I swear, i want to learn how to do it !!! He told me he made it in Vertical, So, if i know how to do it in vert i'll do it in Horzontal ! and i need it to make dX Windows Move ! Link to comment
Dealman Posted January 31, 2015 Share Posted January 31, 2015 (edited) Okay here's a quick example I made, it was made using absolute values for 1920x1080 so if you use a smaller resolution you'll probably have to make it relative. This is only to serve as an example, therefore, things are not working optimally, there's a lot of things to still do, but it will demonstrate how to do the basics of a scrollbar. -- Variables local screenW, screenH = guiGetScreenSize(); local theSuperLongMessage = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. In ut diam bibendum, interdum odio et, hendrerit libero. Maecenas hendrerit sem ac orci mattis, vitae consectetur dui tincidunt. Cras fermentum nulla ac velit accumsan, dignissim finibus urna placerat. Morbi suscipit metus nisl, non pulvinar erat fermentum vitae. Fusce maximus risus non tortor molestie, et sagittis sem ullamcorper. Mauris ac ante facilisis, posuere neque sed, pretium ipsum. Quisque maximus porta mi. Praesent malesuada eleifend turpis sed faucibus. Etiam nec rutrum nisl, ac scelerisque magna. Donec finibus nulla mi, at gravida libero maximus et. Nulla auctor, erat vel fringilla efficitur, sem dolor condimentum erat, nec eleifend nisl orci et diam. Morbi pellentesque maximus tempus. Mauris pretium nec nisi id faucibus. Duis auctor odio vulputate maximus viverra. Nam consequat sapien a justo elementum, nec porttitor nulla bibendum.\n\nUt dictum scelerisque elementum. Donec sollicitudin dui id rhoncus consectetur. Etiam gravida libero ipsum, at varius velit pulvinar eleifend. Etiam at felis porta, varius est nec, fringilla lorem. Nullam eu sapien quis risus venenatis congue. Cras ac lacus sit amet odio faucibus pretium at non tortor. Interdum et malesuada fames ac ante ipsum primis in faucibus. Pellentesque sit amet libero eu urna lobortis laoreet.\n\nVestibulum posuere faucibus gravida. Vivamus ligula urna, dictum a aliquam eu, pretium id felis. Sed non risus facilisis, ultrices elit eu, hendrerit sem. Sed varius tortor sed sapien dictum, sed aliquam ipsum viverra. Vivamus quis dictum eros. Curabitur et accumsan leo. Vivamus et lectus nunc. Sed euismod tincidunt consectetur. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla facilisi. Aenean euismod interdum ex at ullamcorper. Duis tincidunt gravida nisi eget egestas.\n\nNam id nunc nec ante venenatis vestibulum. Aliquam bibendum nulla tellus, a dapibus mi pharetra nec. Ut nec gravida dui, sit amet lacinia ex. Etiam sed maximus sapien, eget congue nisi. Maecenas non accumsan ipsum. Mauris condimentum interdum est et hendrerit. Phasellus convallis porta venenatis. Nullam viverra lacus justo, id tincidunt ipsum efficitur at.\n\nNulla eget consectetur lectus. In tincidunt pellentesque pellentesque. Aliquam posuere, purus id tristique congue, ligula ligula viverra ex, quis fermentum lorem ipsum in purus. Cras a odio interdum, porttitor diam vitae, vehicula leo. Nullam ante dolor, interdum in bibendum egestas, tempus sed ligula. Vivamus at odio convallis, porta ligula ut, tempor dui. Praesent eget facilisis risus. Nullam non ipsum eros. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer dictum dapibus lectus, vel pharetra libero luctus sed. Nam mollis ultrices varius. Praesent ornare, sapien id posuere placerat, urna odio facilisis sem, at malesuada risus lorem ac quam. Donec pharetra lectus eget egestas molestie. Suspendisse ipsum augue, ultricies at ultricies quis, tempor eget velit. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas."; local textSafeBox = dxCreateRenderTarget(570, 470, true); local isClientHoveringScroll = false; local isScrollBarClicked = false; local textOffset = 0; local scrollerPos = 662; -- Functions function isCursorWithin(posX, posY, theWidth, theHeight) if(not isCursorShowing()) then return false; end local cX, cY = getCursorPosition(); local cX, cY = (cX*screenW), (cY*screenH); if(cX >= posX and cX <= posX+theWidth) and (cY >= posY and cY <= posY+theHeight) then return true; else return false; end end function onStart_Handler() showCursor(true); if(textSafeBox) then outputChatBox("Render Target was successfully created!", 0, 187, 0, true); addEventHandler("onClientRender", root, draw_Stuff); elseif(textSafeBox == false) then outputChatBox("Render Target returned false!", 187, 0, 0, true); end end addEventHandler("onClientResourceStart", resourceRoot, onStart_Handler); function draw_Stuff() if(textSafeBox) then dxSetRenderTarget(textSafeBox, false); dxDrawText(theSuperLongMessage, (10-textOffset), 20, 570, 470, tocolor(255, 255, 255, 200), 1.0, "default-bold"); dxSetRenderTarget(); dxDrawRectangle(660, 290, 600, 500, tocolor(0, 30, 30, 200), false); dxDrawRectangle(660, 747, 600, 43, tocolor(0, 30, 30, 200), false) dxDrawLine(660, 746, 1260, 746, tocolor(255, 255, 255, 255), 1, false) dxDrawLine(660, 290, 1260, 290); dxDrawLine(660, 790, 1260, 790); dxDrawLine(660, 290, 660, 790); dxDrawLine(1260, 290, 1260, 790); dxDrawImage(675, 305, 570, 470, textSafeBox); dxDrawRectangle(scrollerPos, 748, 32, 41, tocolor(255, 255, 255, 255), false) end if(isCursorWithin(scrollerPos, 748, 32, 41)) then isClientHoveringScroll = true; else isClientHoveringScroll = false; end if(isScrollBarClicked == true) then if(isCursorWithin(660, 747, 600, 41)) then local cX, cY = getCursorPosition(); local cX, cY = (cX*screenW), (cY*screenH); textOffset = (660-cX); dxSetRenderTarget(textSafeBox, true); dxDrawText(theSuperLongMessage, (10-textOffset), 20, 570, 470, tocolor(255, 255, 255, 200), 1.0, "default-bold"); dxSetRenderTarget(); scrollerPos = cX; end end end function detect_ScrollBarClick(theButton, theState) if(theButton == "left" and theState == "down" and isClientHoveringScroll == true) then isScrollBarClicked = true; elseif(theButton == "left" and theState == "up" and isScrollBarClicked == true) then isScrollBarClicked = false; end end addEventHandler("onClientClick", root, detect_ScrollBarClick) Edited January 31, 2015 by Guest Link to comment
3B00DG4MER Posted January 31, 2015 Author Share Posted January 31, 2015 Oh !! Finally, THANKS !! i'm gonig to try it later and i'll try to make it on Vertical ! 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