|
|
@@ -473,88 +473,6 @@ int CToggleGroup::getSelected() const
|
|
|
return selectedID;
|
|
|
}
|
|
|
|
|
|
-CVolumeSlider::CVolumeSlider(const Point & position, const std::string & defName, const int value, ETooltipMode mode)
|
|
|
- : CIntObject(LCLICK | RCLICK | WHEEL),
|
|
|
- value(value),
|
|
|
- mode(mode)
|
|
|
-{
|
|
|
- OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
|
|
|
- animImage = std::make_shared<CAnimImage>(std::make_shared<CAnimation>(defName), 0, 0, position.x, position.y),
|
|
|
- pos.x += position.x;
|
|
|
- pos.y += position.y;
|
|
|
- pos.w = (animImage->pos.w + 1) * (int)animImage->size();
|
|
|
- pos.h = animImage->pos.h;
|
|
|
- type |= REDRAW_PARENT;
|
|
|
- setVolume(value);
|
|
|
-}
|
|
|
-
|
|
|
-void CVolumeSlider::setVolume(int value_)
|
|
|
-{
|
|
|
- value = value_;
|
|
|
- moveTo((int)(value * static_cast<double>(animImage->size()) / 100.0));
|
|
|
-}
|
|
|
-
|
|
|
-void CVolumeSlider::moveTo(int id)
|
|
|
-{
|
|
|
- vstd::abetween<int>(id, 0, animImage->size() - 1);
|
|
|
- animImage->setFrame(id);
|
|
|
- animImage->moveTo(Point(pos.x + (animImage->pos.w + 1) * id, pos.y));
|
|
|
- if (isActive())
|
|
|
- redraw();
|
|
|
-}
|
|
|
-
|
|
|
-void CVolumeSlider::addCallback(std::function<void(int)> callback)
|
|
|
-{
|
|
|
- onChange += callback;
|
|
|
-}
|
|
|
-
|
|
|
-void CVolumeSlider::clickLeft(tribool down, bool previousState)
|
|
|
-{
|
|
|
- if (down)
|
|
|
- {
|
|
|
- double px = GH.getCursorPosition().x - pos.x;
|
|
|
- double rx = px / static_cast<double>(pos.w);
|
|
|
- // setVolume is out of 100
|
|
|
- setVolume((int)(rx * 100));
|
|
|
- // Volume config is out of 100, set to increments of 5ish roughly based on the half point of the indicator
|
|
|
- // 0.0 -> 0, 0.05 -> 5, 0.09 -> 5,...,
|
|
|
- // 0.1 -> 10, ..., 0.19 -> 15, 0.2 -> 20, ...,
|
|
|
- // 0.28 -> 25, 0.29 -> 30, 0.3 -> 30, ...,
|
|
|
- // 0.85 -> 85, 0.86 -> 90, ..., 0.87 -> 90,...,
|
|
|
- // 0.95 -> 95, 0.96 -> 100, 0.99 -> 100
|
|
|
- int volume = 5 * int(rx * (2 * animImage->size() + 1));
|
|
|
- onChange(volume);
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-void CVolumeSlider::clickRight(tribool down, bool previousState)
|
|
|
-{
|
|
|
- if (down)
|
|
|
- {
|
|
|
- double px = GH.getCursorPosition().x - pos.x;
|
|
|
- int index = static_cast<int>(px / static_cast<double>(pos.w) * animImage->size());
|
|
|
-
|
|
|
- size_t helpIndex = index + (mode == MUSIC ? 326 : 336);
|
|
|
- std::string helpBox = CGI->generaltexth->translate("core.help", helpIndex, "help" );
|
|
|
-
|
|
|
- if(!helpBox.empty())
|
|
|
- CRClickPopup::createAndPush(helpBox);
|
|
|
-
|
|
|
- GH.statusbar()->write(helpBox);
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-void CVolumeSlider::wheelScrolled(bool down, bool in)
|
|
|
-{
|
|
|
- if (in)
|
|
|
- {
|
|
|
- int volume = value + 3 * (down ? 1 : -1);
|
|
|
- vstd::abetween(volume, 0, 100);
|
|
|
- setVolume(volume);
|
|
|
- onChange(volume);
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
void CSlider::sliderClicked()
|
|
|
{
|
|
|
addUsedEvents(MOVE);
|