Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Making my own GUI and need me some help!

Author
Message
Yodaman Jer
User Banned
Posted: 31st Jan 2016 15:47
I have been wracking my brain for a couple of days with this now, and I have done tons of Googling but nothing I find has helped me

I am trying to make a slider or scrollbar GUI element. I want it so that when you drag the slider to the right, it increases a value, say for volume. When you drag it to the left I want it to decrease.

I want it to stay in proportion to the size of the slider, as well. Say the slider is 300px wide but the maximum value is only 100. I want it so that the value only gets updated to 100 when the slider is all the way to the right. This should also work if the slider is only 50px wide and the value is still 100 .

So what's the best way of doing this? I have it so that the scrollbar updates its position based on the x position of the mouse, but I have no idea what math to use to figure out how to update the value of the scrollbar/slider. Any ideas?

This is the code I have for updating the position of the scrollbar:
Slowly compiling code, one byte at a time.
Follow meh blague for more zany thoughts and possibly offensive programming!
Hockeykid
DBPro Tool Maker
17
Years of Service
User Offline
Joined: 26th Sep 2007
Location:
Posted: 31st Jan 2016 16:35
The amount of pixels that the scrollbar slides along is s.scrollbar.width, if you find the current slider position relative to the width then you can calculate a percentage. Therefore s.curValue = (sliderPositionX - scrollBarPositionX) / (s.scrollbar.width * 1.0) (using *1.0 to force float division).


For example if the scrollbar position is x = 300 and the scrollbar width is = 100. If the slider is at 350 you would get s.curValue = (350 - 300) / 100.0 which is 0.5.


Sean
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 31st Jan 2016 17:00
This code makes horizontal and vertical sliders, with any range of values you specify. You have to InitSliders() to get it going. Then you SliderCreate() and SliderShow(). You can also set the slider background image.There are a host of other supporting functions. If you want to use it, I would suggest reading it, then asking any questions you may have.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
Yodaman Jer
User Banned
Posted: 1st Feb 2016 02:16
@Hockeykid:

That seems to have done the trick!

Although, when you first drag the slider from the left to the right it will go about one tenth of the width of the background of the slider before it starts updating the number... any ideas on how to fix that?

This is what my code looks like right now...

Slowly compiling code, one byte at a time.
Follow meh blague for more zany thoughts and possibly offensive programming!
Yodaman Jer
User Banned
Posted: 1st Feb 2016 17:14
After some experimentation I managed to get it working last night!

Final code, in my UpdateScrollbar function:


The bit I worked out to solve my problem yesterday...


Thanks for the help and the guidance! BatViink thank you for that code snippet it looks very informative!
Slowly compiling code, one byte at a time.
Follow meh blague for more zany thoughts and possibly offensive programming!
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 2nd Feb 2016 03:48
I have a GUI tutorial that might help you in your project.

http://dbcc.zimnox.com/?page=tutorials

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds

Login to post a reply

Server time is: 2024-11-25 11:27:33
Your offset time is: 2024-11-25 11:27:33