1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-08-13 19:54:17 +02:00

Added initial version of selection highlight

This commit is contained in:
Ivan Savenko
2023-07-19 19:19:21 +03:00
parent 816adecca0
commit e2ad8bbf58
11 changed files with 34 additions and 8 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 483 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 493 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.5 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 676 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 628 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 678 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 490 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 934 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 914 B

View File

@@ -23,9 +23,19 @@ RadialMenuItem::RadialMenuItem(const std::string & imageName, const std::string
{
OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
image = IImage::createFromFile("radialMenu/" + imageName, EImageBlitMode::COLORKEY);
picture = std::make_shared<CPicture>(image, Point(0, 0));
pos = picture->pos;
inactiveImage = std::make_shared<CPicture>("radialMenu/itemInactive", Point(0, 0));
selectedImage = std::make_shared<CPicture>("radialMenu/itemEmpty", Point(0, 0));
iconImage = std::make_shared<CPicture>("radialMenu/" + imageName, Point(0, 0));
pos = selectedImage->pos;
selectedImage->setEnabled(false);
}
void RadialMenuItem::setSelected(bool selected)
{
selectedImage->setEnabled(selected);
inactiveImage->setEnabled(!selected);
}
RadialMenu::RadialMenu(const Point & positionToCenter, const std::vector<RadialMenuConfig> & menuConfig)
@@ -33,10 +43,10 @@ RadialMenu::RadialMenu(const Point & positionToCenter, const std::vector<RadialM
OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
pos += positionToCenter;
addItem(Point(0,0), true, "itemEmpty", "", [](){});
Point itemSize = items.back()->pos.dimensions();
Point itemSize = Point(70, 80);
moveBy(-itemSize / 2);
pos.w = itemSize.x;
pos.h = itemSize.y;
for (auto const & item : menuConfig)
addItem(item.itemPosition, item.enabled, item.imageName, item.hoverText, item.callback);
@@ -87,6 +97,17 @@ void RadialMenu::gesturePanning(const Point & initialPosition, const Point & cur
{
auto item = findNearestItem(currentPosition);
GH.statusbar()->write(item->hoverText);
if (item != selectedItem)
{
if (selectedItem)
selectedItem->setSelected(false);
item->setSelected(true);
selectedItem = item;
GH.windows().totalRedraw();
}
}
void RadialMenu::gesture(bool on, const Point & initialPosition, const Point & finalPosition)

View File

@@ -37,13 +37,16 @@ class RadialMenuItem : public CIntObject
{
friend class RadialMenu;
std::shared_ptr<IImage> image;
std::shared_ptr<CPicture> picture;
std::shared_ptr<CPicture> iconImage;
std::shared_ptr<CPicture> selectedImage;
std::shared_ptr<CPicture> inactiveImage;
std::function<void()> callback;
std::string hoverText;
public:
RadialMenuItem(const std::string & imageName, const std::string & hoverText, const std::function<void()> & callback);
void setSelected(bool selected);
};
class RadialMenu : public CIntObject
@@ -52,6 +55,8 @@ class RadialMenu : public CIntObject
std::shared_ptr<CGStatusBar> statusBar;
std::shared_ptr<RadialMenuItem> selectedItem;
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;