# help me fix my scrollbar: brain fried cant do math

This topic is 3327 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I recently started finishing up my old opengl GUI library because I want to actually use it. The whole thing is a cluster of spaghetti code, but it's almost done and functional so I can't be bothered to start over from scratch. Anyway the scrollbar pretty much works perfectly except when I click on it to drag it it'll automatically scroll up exactly 1 line (unless it's already at the top or bottom). I've already been working for a while and my brain can't begin to process where to start on this for some reason so some help would be really appreciated.
    if( middledown )
{
parent->cached_lines.size() <= parent->lineHeight ? bar_size = 100 : ( bar_size = parent->lineHeight * 100 / parent->cached_lines.size() );

bar_height = _h * bar_size / 100;

bar_height = bar_height < skin->bar[1].h + skin->bar[3].h ? skin->bar[1].h + skin->bar[3].h : bar_height;

int scrolly = gui->mouse.y - gui->mouse.offy - _y - skin->button[0].h;

scrolly = scrolly < 0 ? 0 : scrolly;
scrolly = scrolly > _h-bar_height ? _h-bar_height : scrolly;

progress_pc = ( scrolly == 0 ) ? 0 : scrolly * 100 / (_h-bar_height);

int max_progress = parent->cached_lines.size()-parent->lineHeight;

progress = max_progress > 0 ? progress_pc * max_progress / 100 : 0;

/*explanation for you guys:
cached_lines = vector containing all text lines (viewed or not)
lineHeight = most amount of lines viewable on screen at once
bar_size = how much of allotted space scroll bar takes up, 0-100
bar_height = how tall scroll bar is, in pixels
gui->mouse.offy = how far away from the top of the scroll bar mouse was when clicked
skin->button[0].h = height of "scroll up" button
progress_pc = how far up or down the scroll bar should be from 0-100
progress = first line to render (offset from 0)*/
}

If you need to know anymore just ask, but I'm positive this is the problem area.
Quote:
 Original post by Etyrn The whole thing is a cluster of spaghetti code, but it's almost done and functional so I can't be bothered to start over from scratch.
quotin to reiterate dis