Jump to content

[Not Sloved Yet !]Scrollbar HELP !


3B00DG4MER

Recommended Posts

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 by Guest
Link to comment

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

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
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 :P

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
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 :P

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

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 :P

Link to comment

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 by Guest
Link to comment

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...