1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-24 08:32:34 +02:00

handle double-click in Town Portal dialog

This commit is contained in:
Andrey Filipenkov 2023-01-23 15:43:55 +03:00
parent a19c9eccc4
commit 08b04a3527
3 changed files with 13 additions and 2 deletions

View File

@ -284,6 +284,8 @@ void CGuiHandler::handleCurrentEvent()
switch(current->button.button)
{
case SDL_BUTTON_LEFT:
{
auto doubleClicked = false;
if(lastClick == current->motion && (SDL_GetTicks() - lastClickTime) < 300)
{
std::list<CIntObject*> hlp = doubleClickInterested;
@ -293,6 +295,7 @@ void CGuiHandler::handleCurrentEvent()
if((*i)->pos.isInside(current->motion.x, current->motion.y))
{
(*i)->onDoubleClick();
doubleClicked = true;
}
}
@ -301,8 +304,10 @@ void CGuiHandler::handleCurrentEvent()
lastClick = current->motion;
lastClickTime = SDL_GetTicks();
handleMouseButtonClick(lclickable, EIntObjMouseBtnType::LEFT, true);
if(!doubleClicked)
handleMouseButtonClick(lclickable, EIntObjMouseBtnType::LEFT, true);
break;
}
case SDL_BUTTON_RIGHT:
handleMouseButtonClick(rclickable, EIntObjMouseBtnType::RIGHT, true);
break;

View File

@ -2039,7 +2039,7 @@ CThievesGuildWindow::CThievesGuildWindow(const CGObjectInstance * _owner):
}
CObjectListWindow::CItem::CItem(CObjectListWindow * _parent, size_t _id, std::string _text)
: CIntObject(LCLICK),
: CIntObject(LCLICK | DOUBLECLICK),
parent(_parent),
index(_id)
{
@ -2069,6 +2069,11 @@ void CObjectListWindow::CItem::clickLeft(tribool down, bool previousState)
parent->changeSelection(index);
}
void CObjectListWindow::CItem::onDoubleClick()
{
parent->elementSelected();
}
CObjectListWindow::CObjectListWindow(const std::vector<int> & _items, std::shared_ptr<CIntObject> titleWidget_, std::string _title, std::string _descr, std::function<void(int)> Callback, size_t initialSelection)
: CWindowObject(PLAYER_COLORED, "TPGATE"),
onSelect(Callback),

View File

@ -163,6 +163,7 @@ class CObjectListWindow : public CWindowObject
void select(bool on);
void clickLeft(tribool down, bool previousState) override;
void onDoubleClick() override;
};
std::function<void(int)> onSelect;//called when OK button is pressed, returns id of selected item.