1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-28 08:48:48 +02:00

basic slider

This commit is contained in:
Laserlicht 2024-06-29 16:14:16 +02:00
parent 8444f7b330
commit 29d4cf274a
2 changed files with 34 additions and 5 deletions

View File

@ -452,7 +452,7 @@ int OptionsTab::SelectionWindow::calcLines(FactionID faction)
count++;
}
return std::ceil(std::max((double)count + additionalItems, (double)allowedFactions.size() + additionalItems) / (double)elementsPerLine);
return std::ceil(((double)count + additionalItems) / (double)elementsPerLine);
}
void OptionsTab::SelectionWindow::apply()
@ -492,6 +492,8 @@ void OptionsTab::SelectionWindow::recreate()
{
OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
sliderLine = slider ? slider->getValue() : 0;
int amountLines = 1;
if(type == SelType::BONUS)
elementsPerLine = allowedBonus.size();
@ -518,9 +520,9 @@ void OptionsTab::SelectionWindow::recreate()
}
int x = (elementsPerLine) * (ICON_BIG_WIDTH-1);
int y = (amountLines) * (ICON_BIG_HEIGHT-1);
int y = (std::min(amountLines, MAX_LINES)) * (ICON_BIG_HEIGHT-1);
pos = Rect(0, 0, x, y);
pos = Rect(0, 0, x + ((amountLines > MAX_LINES) ? 16 : 0), y);
backgroundTexture = std::make_shared<FilledTexturePlayerColored>(ImagePath::builtin("DiBoxBck"), pos);
backgroundTexture->playerColored(PlayerColor(1));
@ -532,7 +534,15 @@ void OptionsTab::SelectionWindow::recreate()
genContentHeroes();
if(type == SelType::BONUS)
genContentBonus();
genContentGrid(amountLines);
genContentGrid(std::min(amountLines, MAX_LINES));
if(amountLines > MAX_LINES)
{
slider = std::make_shared<CSlider>(Point(x, 0), y, std::bind(&OptionsTab::SelectionWindow::sliderMove, this, _1), MAX_LINES, amountLines, 0, Orientation::VERTICAL, CSlider::BLUE);
slider->setPanningStep(ICON_BIG_HEIGHT);
slider->setScrollBounds(Rect(0, 0, x, y));
slider->scrollTo(sliderLine);
}
center();
}
@ -741,6 +751,14 @@ void OptionsTab::SelectionWindow::setElement(int elem, bool doApply)
apply();
}
void OptionsTab::SelectionWindow::sliderMove(int slidPos)
{
if(!slider)
return; // ignore spurious call when slider is being created
recreate();
redraw();
}
bool OptionsTab::SelectionWindow::receiveEvent(const Point & position, int eventType) const
{
return true; // capture click also outside of window
@ -748,6 +766,9 @@ bool OptionsTab::SelectionWindow::receiveEvent(const Point & position, int event
void OptionsTab::SelectionWindow::clickReleased(const Point & cursorPosition)
{
if(slider && slider->pos.isInside(cursorPosition))
return;
if(!pos.isInside(cursorPosition))
{
close();
@ -761,7 +782,7 @@ void OptionsTab::SelectionWindow::clickReleased(const Point & cursorPosition)
void OptionsTab::SelectionWindow::showPopupWindow(const Point & cursorPosition)
{
if(!pos.isInside(cursorPosition))
if(!pos.isInside(cursorPosition) || (slider && slider->pos.isInside(cursorPosition)))
return;
int elem = getElement(cursorPosition);

View File

@ -26,6 +26,7 @@ class CAnimImage;
class CComponentBox;
class CTextBox;
class CButton;
class CSlider;
class FilledTexturePlayerColored;
@ -105,8 +106,13 @@ private:
const int TEXT_POS_X = 29;
const int TEXT_POS_Y = 56;
const int MAX_LINES = 6;
int elementsPerLine;
std::shared_ptr<CSlider> slider;
int sliderLine;
PlayerColor color;
SelType type;
@ -141,6 +147,8 @@ private:
int getElement(const Point & cursorPosition);
void setElement(int element, bool doApply);
void sliderMove(int slidPos);
bool receiveEvent(const Point & position, int eventType) const override;
void clickReleased(const Point & cursorPosition) override;
void showPopupWindow(const Point & cursorPosition) override;