mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-08-11 19:04:05 +02:00
Element scroll bar Improvement
Signed-off-by: xphere07 <xphere07@outlook.com>
This commit is contained in:
@@ -921,32 +921,49 @@ void GameView::updateToolButtonScroll()
|
|||||||
{
|
{
|
||||||
if (toolButtons.size())
|
if (toolButtons.size())
|
||||||
{
|
{
|
||||||
int x = currentMouse.X, y = currentMouse.Y;
|
int x = currentMouse.X;
|
||||||
|
int y = currentMouse.Y;
|
||||||
|
|
||||||
|
int offsetDelta = 0;
|
||||||
|
|
||||||
int newInitialX = WINDOWW - 56;
|
int newInitialX = WINDOWW - 56;
|
||||||
int totalWidth = (toolButtons[0]->Size.X + 1) * toolButtons.size();
|
int totalWidth = (toolButtons[0]->Size.X + 1) * toolButtons.size();
|
||||||
int scrollSize = (int)(((float)(XRES - BARSIZE))/((float)totalWidth) * ((float)XRES - BARSIZE));
|
int scrollSize = (int)(((float)(XRES - BARSIZE))/((float)totalWidth) * ((float)XRES - BARSIZE));
|
||||||
|
|
||||||
if (scrollSize > XRES - 1)
|
if (scrollSize > XRES - 1)
|
||||||
scrollSize = XRES - 1;
|
scrollSize = XRES - 1;
|
||||||
|
|
||||||
if (totalWidth > XRES - 15)
|
if (totalWidth > XRES - 15)
|
||||||
{
|
{
|
||||||
int mouseX = x;
|
int mouseX = x;
|
||||||
|
|
||||||
|
float overflow = 0;
|
||||||
|
float mouseLocation = 0;
|
||||||
|
|
||||||
if (mouseX > XRES)
|
if (mouseX > XRES)
|
||||||
mouseX = XRES;
|
mouseX = XRES;
|
||||||
|
|
||||||
// if (mouseX < 15) // makes scrolling a little nicer at edges but apparently if you put hundreds of elements in a menu it makes the end not show ...
|
// if (mouseX < 15) // makes scrolling a little nicer at edges but apparently if you put hundreds of elements in a menu it makes the end not show ...
|
||||||
// mouseX = 15;
|
// mouseX = 15;
|
||||||
|
|
||||||
scrollBar->Position.X = (int)(((float)mouseX/((float)XRES))*(float)(XRES-scrollSize));
|
scrollBar->Visible = true;
|
||||||
|
|
||||||
float overflow = float(totalWidth-(XRES-BARSIZE)), mouseLocation = float(XRES-3)/float((XRES-2)-mouseX); //mouseLocation adjusted slightly in case you have 200 elements in one menu
|
scrollBar->Position.X = (int)(((float)mouseX / (float)XRES) * (float)(XRES - scrollSize)) + 1;
|
||||||
|
|
||||||
newInitialX += int(overflow/mouseLocation);
|
overflow = (float)(totalWidth - (XRES - BARSIZE));
|
||||||
|
mouseLocation = (float)(XRES - 3)/(float)((XRES - 2) - mouseX); // mouseLocation adjusted slightly in case you have 200 elements in one menu
|
||||||
|
|
||||||
|
newInitialX += (int)(overflow/mouseLocation);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
scrollBar->Position.X = 1;
|
scrollBar->Visible = false;
|
||||||
}
|
}
|
||||||
scrollBar->Size.X=scrollSize;
|
|
||||||
int offsetDelta = toolButtons[0]->Position.X - newInitialX;
|
scrollBar->Size.X = scrollSize - 1;
|
||||||
|
|
||||||
|
offsetDelta = toolButtons[0]->Position.X - newInitialX;
|
||||||
|
|
||||||
for (auto *button : toolButtons)
|
for (auto *button : toolButtons)
|
||||||
{
|
{
|
||||||
button->Position.X -= offsetDelta;
|
button->Position.X -= offsetDelta;
|
||||||
|
Reference in New Issue
Block a user