mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-25 22:42:04 +02:00
Implemented Scrollable class, to server as common base for such classes
This commit is contained in:
@@ -10,3 +10,85 @@
|
||||
|
||||
#include "StdInc.h"
|
||||
#include "Scrollable.h"
|
||||
|
||||
Scrollable::Scrollable(int used, Point position, Orientation orientation)
|
||||
: CIntObject(used | WHEEL | GESTURE_PANNING, position)
|
||||
, scrollStep(1)
|
||||
, panningDistanceSingle(32)
|
||||
, panningDistanceAccumulated(0)
|
||||
, orientation(orientation)
|
||||
{
|
||||
}
|
||||
|
||||
void Scrollable::panning(bool on)
|
||||
{
|
||||
panningDistanceAccumulated = 0;
|
||||
}
|
||||
|
||||
void Scrollable::wheelScrolled(int distance)
|
||||
{
|
||||
if (orientation == Orientation::HORIZONTAL)
|
||||
scrollBy(distance * 3);
|
||||
else
|
||||
scrollBy(-distance * 3);
|
||||
}
|
||||
|
||||
void Scrollable::gesturePanning(const Point & distanceDelta)
|
||||
{
|
||||
if (orientation == Orientation::HORIZONTAL)
|
||||
panningDistanceAccumulated += -distanceDelta.x;
|
||||
else
|
||||
panningDistanceAccumulated += distanceDelta.y;
|
||||
|
||||
if (-panningDistanceAccumulated > panningDistanceSingle )
|
||||
{
|
||||
int scrollAmount = (-panningDistanceAccumulated) / panningDistanceSingle;
|
||||
scrollBy(-scrollAmount);
|
||||
panningDistanceAccumulated += scrollAmount * panningDistanceSingle;
|
||||
}
|
||||
|
||||
if (panningDistanceAccumulated > panningDistanceSingle )
|
||||
{
|
||||
int scrollAmount = panningDistanceAccumulated / panningDistanceSingle;
|
||||
scrollBy(scrollAmount);
|
||||
panningDistanceAccumulated += -scrollAmount * panningDistanceSingle;
|
||||
}
|
||||
}
|
||||
|
||||
int Scrollable::getScrollStep() const
|
||||
{
|
||||
return scrollStep;
|
||||
}
|
||||
|
||||
Orientation Scrollable::getOrientation() const
|
||||
{
|
||||
return orientation;
|
||||
}
|
||||
|
||||
void Scrollable::scrollNext()
|
||||
{
|
||||
scrollBy(+1);
|
||||
}
|
||||
|
||||
void Scrollable::scrollPrev()
|
||||
{
|
||||
scrollBy(-1);
|
||||
}
|
||||
|
||||
void Scrollable::setScrollStep(int to)
|
||||
{
|
||||
scrollStep = to;
|
||||
}
|
||||
|
||||
void Scrollable::setPanningStep(int to)
|
||||
{
|
||||
panningDistanceSingle = to;
|
||||
}
|
||||
|
||||
void Scrollable::setScrollingEnabled(bool on)
|
||||
{
|
||||
if (on)
|
||||
addUsedEvents(WHEEL | GESTURE_PANNING);
|
||||
else
|
||||
removeUsedEvents(WHEEL | GESTURE_PANNING);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user