| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- /*
- * Slider.h, part of VCMI engine
- *
- * Authors: listed in file AUTHORS in main folder
- *
- * License: GNU General Public License v2.0 or later
- * Full text of license available in license.txt file, in main folder
- *
- */
- #pragma once
- #include "Scrollable.h"
- #include "../../lib/FunctionList.h"
- class CButton;
- /// A typical slider which can be orientated horizontally/vertically.
- class CSlider : public Scrollable
- {
- //if vertical then left=up
- std::shared_ptr<CButton> left;
- std::shared_ptr<CButton> right;
- std::shared_ptr<CButton> slider;
- std::optional<Rect> scrollBounds;
- /// how many elements are visible simultaneously
- int capacity;
- /// number of highest position, or 0 if there is only one
- int positions;
- /// total amount of elements in the list
- int amount;
- /// topmost vislble (first active) element
- int value;
- CFunctionList<void(int)> moved;
- void updateSliderPos();
- public:
- enum EStyle
- {
- BROWN,
- BLUE
- };
- void block(bool on);
- /// If set, mouse scroll will only scroll slider when inside of this area
- void setScrollBounds(const Rect & bounds );
- void clearScrollBounds();
- /// Value modifiers
- void scrollTo(int value);
- void scrollBy(int amount) override;
- void scrollToMin();
- void scrollToMax();
- /// Amount modifier
- void setAmount(int to);
- /// Accessors
- int getAmount() const;
- int getValue() const;
- int getCapacity() const;
- void addCallback(std::function<void(int)> callback);
- bool receiveEvent(const Point & position, int eventType) const override;
- void keyPressed(EShortcut key) override;
- void clickPressed(const Point & cursorPosition) override;
- void mouseDragged(const Point & cursorPosition, const Point & lastUpdateDistance) override;
- void gesturePanning(const Point & initialPosition, const Point & currentPosition, const Point & lastUpdateDistance) override;
- void showAll(Canvas & to) override;
- /// @param position coordinates of slider
- /// @param length length of slider ribbon, including left/right buttons
- /// @param Moved function that will be called whenever slider moves
- /// @param Capacity maximal number of visible at once elements
- /// @param Amount total amount of elements, including not visible
- /// @param Value starting position
- CSlider(Point position, int length, std::function<void(int)> Moved, int Capacity, int Amount,
- int Value, Orientation orientation, EStyle style = BROWN);
- ~CSlider();
- };
|