dialogs handle hotkeys on controls in containers
This commit is contained in:
@@ -914,17 +914,30 @@ void cDialog::process_keystroke(cKey keyHit){
|
|||||||
ctrlIter iter = controls.begin();
|
ctrlIter iter = controls.begin();
|
||||||
bool enterKeyHit = keyHit.spec && keyHit.k == key_enter;
|
bool enterKeyHit = keyHit.spec && keyHit.k == key_enter;
|
||||||
while(iter != controls.end()){
|
while(iter != controls.end()){
|
||||||
if((iter->second->isVisible() && iter->second->isClickable())
|
cControl* ctrl = iter->second;
|
||||||
&& (iter->second->getAttachedKey() == keyHit || (iter->second->isDefault() && enterKeyHit))){
|
if(ctrl->isVisible()){
|
||||||
|
if(ctrl->isClickable() &&
|
||||||
|
(ctrl->getAttachedKey() == keyHit || (ctrl->isDefault() && enterKeyHit))){
|
||||||
|
|
||||||
|
ctrl->handleKeyTriggered(*this);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(ctrl->isContainer()){
|
||||||
|
cContainer* container = dynamic_cast<cContainer*>(ctrl);
|
||||||
|
std::string child_hit;
|
||||||
|
container->forEach([&keyHit, &child_hit, enterKeyHit](std::string child_id, cControl& child_ctrl) {
|
||||||
|
if(child_ctrl.isClickable() &&
|
||||||
|
(child_ctrl.getAttachedKey() == keyHit || (child_ctrl.isDefault() && enterKeyHit))){
|
||||||
|
|
||||||
|
if(child_hit.empty()) child_hit = child_id;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if(!child_hit.empty()) {
|
||||||
|
findControl(child_hit)->handleKeyTriggered(*this);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
iter->second->setActive(true);
|
|
||||||
draw();
|
|
||||||
iter->second->playClickSound();
|
|
||||||
iter->second->setActive(false);
|
|
||||||
draw();
|
|
||||||
sf::sleep(sf::milliseconds(8));
|
|
||||||
iter->second->triggerClickHandler(*this,iter->first,mod_none);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
iter++;
|
iter++;
|
||||||
}
|
}
|
||||||
|
@@ -291,6 +291,16 @@ bool cControl::handleClick(location, cFramerateLimiter& fps_limiter){
|
|||||||
return clicked;
|
return clicked;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void cControl::handleKeyTriggered(cDialog& parent) {
|
||||||
|
setActive(true);
|
||||||
|
parent.draw();
|
||||||
|
playClickSound();
|
||||||
|
setActive(false);
|
||||||
|
parent.draw();
|
||||||
|
sf::sleep(sf::milliseconds(8));
|
||||||
|
triggerClickHandler(parent,name,mod_none);
|
||||||
|
}
|
||||||
|
|
||||||
std::string cControl::getAttachedKeyDescription() const {
|
std::string cControl::getAttachedKeyDescription() const {
|
||||||
std::string s;
|
std::string s;
|
||||||
if(key.spec) {
|
if(key.spec) {
|
||||||
|
@@ -340,6 +340,8 @@ public:
|
|||||||
/// should be hilited in some way while pressed and is cancelled by releasing the mouse
|
/// should be hilited in some way while pressed and is cancelled by releasing the mouse
|
||||||
/// button outside the control's bounds.
|
/// button outside the control's bounds.
|
||||||
virtual bool handleClick(location where, cFramerateLimiter& fps_limiter);
|
virtual bool handleClick(location where, cFramerateLimiter& fps_limiter);
|
||||||
|
/// Animate and play the sound of the control being "clicked", and call its click event
|
||||||
|
void handleKeyTriggered(cDialog& parent);
|
||||||
/// Specifies that another control acts as a label for this one.
|
/// Specifies that another control acts as a label for this one.
|
||||||
/// The practical effect of this is that hiding or showing this control automatically hides or shows the label as well.
|
/// The practical effect of this is that hiding or showing this control automatically hides or shows the label as well.
|
||||||
/// @param label A pointer to the control that acts as a label.
|
/// @param label A pointer to the control that acts as a label.
|
||||||
|
Reference in New Issue
Block a user