mirror of
https://github.com/vcmi/vcmi.git
synced 2025-02-15 13:33:36 +02:00
Do not activate radial wheel if cursor stays in the center
This commit is contained in:
parent
4a6d1d0f8b
commit
1acc936e51
@ -41,7 +41,8 @@ void RadialMenuItem::setSelected(bool selected)
|
|||||||
inactiveImage->setEnabled(!selected);
|
inactiveImage->setEnabled(!selected);
|
||||||
}
|
}
|
||||||
|
|
||||||
RadialMenu::RadialMenu(const Point & positionToCenter, const std::vector<RadialMenuConfig> & menuConfig)
|
RadialMenu::RadialMenu(const Point & positionToCenter, const std::vector<RadialMenuConfig> & menuConfig):
|
||||||
|
centerPosition(positionToCenter)
|
||||||
{
|
{
|
||||||
OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
|
OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
|
||||||
pos += positionToCenter;
|
pos += positionToCenter;
|
||||||
@ -78,6 +79,12 @@ void RadialMenu::addItem(const Point & offset, bool enabled, const std::string &
|
|||||||
|
|
||||||
std::shared_ptr<RadialMenuItem> RadialMenu::findNearestItem(const Point & cursorPosition) const
|
std::shared_ptr<RadialMenuItem> RadialMenu::findNearestItem(const Point & cursorPosition) const
|
||||||
{
|
{
|
||||||
|
static const int requiredDistanceFromCenter = 45;
|
||||||
|
|
||||||
|
// cursor is inside centeral area -> no selection
|
||||||
|
if ((centerPosition - cursorPosition).length() < requiredDistanceFromCenter)
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
int bestDistance = std::numeric_limits<int>::max();
|
int bestDistance = std::numeric_limits<int>::max();
|
||||||
std::shared_ptr<RadialMenuItem> bestItem;
|
std::shared_ptr<RadialMenuItem> bestItem;
|
||||||
|
|
||||||
@ -98,16 +105,23 @@ std::shared_ptr<RadialMenuItem> RadialMenu::findNearestItem(const Point & cursor
|
|||||||
|
|
||||||
void RadialMenu::gesturePanning(const Point & initialPosition, const Point & currentPosition, const Point & lastUpdateDistance)
|
void RadialMenu::gesturePanning(const Point & initialPosition, const Point & currentPosition, const Point & lastUpdateDistance)
|
||||||
{
|
{
|
||||||
auto item = findNearestItem(currentPosition);
|
auto newSelection = findNearestItem(currentPosition);
|
||||||
GH.statusbar()->write(item->hoverText);
|
|
||||||
|
|
||||||
if (item != selectedItem)
|
|
||||||
|
if (newSelection != selectedItem)
|
||||||
{
|
{
|
||||||
if (selectedItem)
|
if (selectedItem)
|
||||||
selectedItem->setSelected(false);
|
selectedItem->setSelected(false);
|
||||||
|
|
||||||
item->setSelected(true);
|
if (newSelection)
|
||||||
selectedItem = item;
|
{
|
||||||
|
GH.statusbar()->write(newSelection->hoverText);
|
||||||
|
newSelection->setSelected(true);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
GH.statusbar()->clear();
|
||||||
|
|
||||||
|
selectedItem = newSelection;
|
||||||
|
|
||||||
GH.windows().totalRedraw();
|
GH.windows().totalRedraw();
|
||||||
}
|
}
|
||||||
@ -122,5 +136,6 @@ void RadialMenu::gesture(bool on, const Point & initialPosition, const Point & f
|
|||||||
|
|
||||||
// we need to close this window first so if action spawns a new window it won't be closed instead
|
// we need to close this window first so if action spawns a new window it won't be closed instead
|
||||||
GH.windows().popWindows(1);
|
GH.windows().popWindows(1);
|
||||||
item->callback();
|
if (item)
|
||||||
|
item->callback();
|
||||||
}
|
}
|
||||||
|
@ -52,11 +52,11 @@ public:
|
|||||||
class RadialMenu : public CIntObject
|
class RadialMenu : public CIntObject
|
||||||
{
|
{
|
||||||
std::vector<std::shared_ptr<RadialMenuItem>> items;
|
std::vector<std::shared_ptr<RadialMenuItem>> items;
|
||||||
|
|
||||||
std::shared_ptr<CGStatusBar> statusBar;
|
std::shared_ptr<CGStatusBar> statusBar;
|
||||||
|
|
||||||
std::shared_ptr<RadialMenuItem> selectedItem;
|
std::shared_ptr<RadialMenuItem> selectedItem;
|
||||||
|
|
||||||
|
Point centerPosition;
|
||||||
|
|
||||||
void addItem(const Point & offset, bool enabled, const std::string & path, const std::string & hoverText, const std::function<void()> & callback);
|
void addItem(const Point & offset, bool enabled, const std::string & path, const std::string & hoverText, const std::function<void()> & callback);
|
||||||
|
|
||||||
std::shared_ptr<RadialMenuItem> findNearestItem(const Point & cursorPosition) const;
|
std::shared_ptr<RadialMenuItem> findNearestItem(const Point & cursorPosition) const;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user