1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
GUI::VScrollBar::VScrollBar()
{
wY = 100;
windowSize = 100;
contentSize = 200;
minGripSize = 5;
pos = 0;
*(mousepos) = 0;
*(mousepos + 1) = 0;
mousedown = false;
}
float GUI::VScrollBar::CalculateGripRatio()
{
if ( contentSize == 0.f )
return 0.f;
return windowSize/contentSize;
}
float GUI::VScrollBar::CalculateGripSize()
{
float tmp = wY * CalculateGripRatio();
tmp = tmp < 3?3:tmp;
return tmp<minGripSize?minGripSize:tmp;
}
float GUI::VScrollBar::CalculateScrollSize()
{
return wY - CalculateGripSize();
}
float GUI::VScrollBar::CalculateScrollRatio()
{
return pos/contentSize;
}
void GUI::VScrollBar::ValidatePos()
{
if ( pos < 0 ) pos = 0;
float gripPos = CalculateScrollSize() * CalculateScrollRatio();
while ( gripPos > CalculateScrollSize() )
{
pos--;
gripPos = CalculateScrollSize() * CalculateScrollRatio();
}
}
void GUI::VScrollBar::Draw(sf::RenderWindow* RENW)
{
ValidatePos();
int gripSize = (int) CalculateGripSize();
gripSize = gripSize < minGripSize?minGripSize:gripSize;
float gripPos = CalculateScrollSize() * CalculateScrollRatio();
sf::Shape grip = sf::Shape::Rectangle(pX+2, pY + gripPos, pX+wX-1,pY+gripPos+gripSize,sf::Color(70,70,70),true,sf::Color(200,200,200));
sf::Shape track = sf::Shape::Rectangle(pX+1, pY, pX+wX,pY+wY,sf::Color(200,200,200),true,sf::Color(70,70,70));
RENW->Draw(track);
RENW->Draw(grip);
}
|