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.

DarkBASIC Discussion / ScrollBar Calculations

Author
Message
Caleb1994
15
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 26th Sep 2009 19:33
Ok, i got the Scroller height(if you read my old post) with this equation:

DocumentHeight/ViewHeight = ScrollBarHeight/ScrollerHeight

So Scroller Height is easy to find:

ViewHeight * ScrollBarHeight = DocumentHeight * ScrollerHeight

With the other three as known variables it's easy.

anyways. what i am trying to do is find out how much to move the scroller in proportion to the document when you press the button. so i need to find how many pixels to move the document when i move the scrollbar one. or vice versa.

I found one thing that said this:

if dh = DocumentHeight-ViewHeight and sh = ScrollbarHeight-ScrollerHeight

ScrollbarIncrement = sh/dh
DocumentIncrement = dh/sh

but when shown like this:

sh/dh = dh/sh

it isn't proportional. because dh * dh != sh * sh, and plus the ScrollBar gives a float back because its so small compared to the Document and pixels don't work with floats.

This boggled my mind till 130 last night. i finally had to go to bed. lol any help? i have given you all the info i know/have found on the internet.

New Site! Check it out \/
Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 27th Sep 2009 02:00 Edited at: 27th Sep 2009 02:02
I think I put my scrollbar in with my "bonanza" thread, can't remember.

I don't think that formula will work (barheight = docheight / viewheight).
On a scrollbar the frame represents the length of the document and the bar height (or size) represents the section of document shown in the current view.
So barsize = (viewsize / docsize) * framesize, viewsize and docsize being given in number of lines.
Now to get the position of the bar we take the first line of the viewport (which I'll call viewy) and put it through the same equation
bary = (viewy / docsize) * framesize

The nice thing about this is that as long as you stop the view going past the last line the bar will also stay within it's frame.

TGC Forum - converting error messages into sarcasm since 2002.
Caleb1994
15
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 27th Sep 2009 02:44 Edited at: 27th Sep 2009 02:46
Thanks obese! although i am not going by lines because these are for gui functions and are not necessarly going to be used with text and could be used for a general window.

I will test this out right now!

edit:

bary = (viewy / docsize) * framesize

also with this if you know the bary you can find viewy and vice versa! i know quite obvious but still

New Site! Check it out \/
Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 27th Sep 2009 05:33
Quote: "also with this if you know the bary you can find viewy and vice versa! i know quite obvious but still"

You mean like:
viewy = (bary / framesize) * docsize
If we didn't examine obvious things we'd miss the simplest solutions
I had to get a pen and paper to work out how to swap that around

TGC Forum - converting error messages into sarcasm since 2002.
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 27th Sep 2009 07:39 Edited at: 27th Sep 2009 07:44


i# = (Y - A) / (T - H)

That should give you a number from 0.0 - 1.0.

Multiply the size of the component you're scrolling by i# and you'll end up with the pixel offset for that component's view.

Let's say you have a document that's 4200 pixel in height, but you can only see 400 pixels at a time in the view. So you have the content(C) and the viewport(V). Subtract the two first then multiple, like this:

pixelOffset = (C - V)*i#

You subtract the two so you can prevent the appearence of scrolling passed the available content.

Attachments

Login to view attachments
Caleb1994
15
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 27th Sep 2009 16:23
Hmmm interesting. I will try this one out too as soon as i get my computer up again. my battery has been going out and now it did completely and my cord wont work ]


Quote: "If we didn't examine obvious things we'd miss the simplest solutions "


True.
Quote: "
I had to get a pen and paper to work out how to swap that around
"


Same here haha

New Site! Check it out \/
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 27th Sep 2009 23:03
If the cord doesn't work that's probably why the battery went out, it's not getting charged.

Caleb1994
15
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 28th Sep 2009 01:33
This would be true except the cord was working and it did get charged just when you took it off(with full charge) it would last MAYBE 20 minutes

New Site! Check it out \/
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 28th Sep 2009 08:39
Oh gotcha, my laptop does that too. Stupid old batteries.

Caleb1994
15
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 29th Sep 2009 19:42 Edited at: 29th Sep 2009 19:44
Haha, ya well bought a new battery and have been testing my chargers and it seems they both have the same problem. i got power tester thing and it has power in the cord going TO the ac adapter but not coming out and thats the expensive part

Oh Wow never mind just checked ebay. 10 to 15 bucks for a new one haha

New Site! Check it out \/
Caleb1994
15
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 13th Oct 2009 22:30 Edited at: 13th Oct 2009 22:32
Oh forgot to post back, I got a scroll bar working, i am currently trying to get it into my GUI functions, but here is the test i used. you can rem out the up and down key controls and unrem the mouse controls. either way works but both together doesn't


New Site! Check it out \/
Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 14th Oct 2009 01:43 Edited at: 14th Oct 2009 02:59
Couple of tricks for you...

I see you've used float variables so you get a float from division, you can however, use integer variables and cheat. Only the denominator needs to be a float and you can turn any integer into a float by multiplying it by a float.

I don't know what the last line does, it just occured to me that it might be quicker if it works.

Another thing is you can simplify your sentence generator. I've removed the check which should speed it up, remember it will be doing that check every loop. I also got rid of the calculation in the first line (1000/20-1), for the same reason it's best to do any calculations outside of the loop that you can in order to save cpu time.

Believe it or not x is like any other variable and retains its value after the for loop. I've used the exit value of x to position the last line.

TGC Forum - converting error messages into sarcasm since 2002.
Caleb1994
15
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 14th Oct 2009 02:21
Yes, i have actually realized as i was trying to input this in my functions, that it doesn't need floats. it works fine without em.

although i do use the "var + 0.0" in functions that take floats, which essentially "tricks" dbc into thinking it's a float lol

Oh and btw a/b*1.0 just prints 0. think about it, because / and * have the same presadence(wrong spelling and maybe the wrong word???) so it does integer a divided by integer b and takes that value times 1.0 which in turn returns 0 lol

the last on is correct though

New Site! Check it out \/
Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 14th Oct 2009 02:58
Quote: "Oh and btw a/b*1.0 just prints 0. think about it, because / and * have the same presadence(wrong spelling and maybe the wrong word???) so it does integer a divided by integer b and takes that value times 1.0 which in turn returns 0 lol"

Oh sorry I thought * took precedence over /, I usually use brackets just in case with my own programs hehe.
Good to hear +.0 works, that should be a bit quicker.

TGC Forum - converting error messages into sarcasm since 2002.
demons breath
20
Years of Service
User Offline
Joined: 4th Oct 2003
Location: Surrey, UK
Posted: 14th Oct 2009 04:08
anything times 1.0 should still return the original value though - a*1.0=a*1=a

If it's returning 0, either something's gone wrong in the code or the value it came out with was 0 anyway. Which is rather odd unless a=0 in the first place.

"A West Texas girl, just like me"
-Bush
Caleb1994
15
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 14th Oct 2009 06:55
It's not odd when you think about it. here is what it is doing

a / b

which because dbc is doing integer division it's returning a integer so it returns 0 then it does the second part

* 1.0

and 0 * 1.0 is 0. it's the same as doing this

(a/b)*1.0

hope that clears it up

New Site! Check it out \/
TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 17th Oct 2009 22:28
Quote: "pixels don't work with floats"


Correct... and incorrect!

Pixel positions are indeed integers, You can't turn on a pixel 33.7 pixels across the screen.

But if you did use float variables when referencing a screen location like:

Text 100.5,200.5,"Hello"

...DB would simply convert them to integers before using them. This, and the fact that floats are not as fast as integers means that normally you should only use integers.

However, you often need to use floats when calculating a screen location - converting it to an integer after the value has been calculated.

A slider bar is one such occasion.

For example, calculating the pixel Y position with floats:

Y = INT(24.2 + 18.7 + 30.3 + 17.6) ... Pixel Result: Y = 90

The same calculation using integers:

Y = 24 + 18 + 30 + 17 ... Pixel Result: Y = 89

As you can see, it's 1 pixel out with integers. But the more values used for calculating, the more the result will be out.

TDK

Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 18th Oct 2009 21:55
To simplify, when calculating dynamic screen coordinates, use floats for increased precision

Caleb1994
15
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 20th Oct 2009 18:29
Oh i see your point thanks!

New Site! Check it out \/

Login to post a reply

Server time is: 2024-05-04 02:08:53
Your offset time is: 2024-05-04 02:08:53