make click sound handling DRY
This commit is contained in:
@@ -877,13 +877,7 @@ void cDialog::process_keystroke(cKey keyHit){
|
|||||||
if(iter->second->isVisible() && iter->second->isClickable() && iter->second->getAttachedKey() == keyHit){
|
if(iter->second->isVisible() && iter->second->isClickable() && iter->second->getAttachedKey() == keyHit){
|
||||||
iter->second->setActive(true);
|
iter->second->setActive(true);
|
||||||
draw();
|
draw();
|
||||||
if(get_bool_pref("PlaySounds", true)) {
|
iter->second->playClickSound();
|
||||||
if(typeid(iter->second) == typeid(cLed*))
|
|
||||||
play_sound(34);
|
|
||||||
else play_sound(37);
|
|
||||||
sf::sleep(time_in_ticks(6));
|
|
||||||
}
|
|
||||||
else sf::sleep(time_in_ticks(14));
|
|
||||||
iter->second->setActive(false);
|
iter->second->setActive(false);
|
||||||
draw();
|
draw();
|
||||||
sf::sleep(sf::milliseconds(8));
|
sf::sleep(sf::milliseconds(8));
|
||||||
|
|||||||
@@ -210,6 +210,16 @@ void cControl::redraw() {
|
|||||||
if(parent) parent->draw();
|
if(parent) parent->draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void cControl::playClickSound(){
|
||||||
|
if(get_bool_pref("PlaySounds", true)) {
|
||||||
|
if(typeid(this) == typeid(cLed*))
|
||||||
|
play_sound(34);
|
||||||
|
else play_sound(37);
|
||||||
|
sf::sleep(time_in_ticks(6));
|
||||||
|
}
|
||||||
|
else sf::sleep(time_in_ticks(14));
|
||||||
|
}
|
||||||
|
|
||||||
bool cControl::handleClick(location){
|
bool cControl::handleClick(location){
|
||||||
sf::Event e;
|
sf::Event e;
|
||||||
bool done = false, clicked = false;
|
bool done = false, clicked = false;
|
||||||
@@ -231,13 +241,8 @@ bool cControl::handleClick(location){
|
|||||||
depressed = frame.contains(toPos);
|
depressed = frame.contains(toPos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(get_bool_pref("PlaySounds", true)) {
|
playClickSound();
|
||||||
if(typeid(this) == typeid(cLed*))
|
|
||||||
play_sound(34);
|
|
||||||
else play_sound(37);
|
|
||||||
sf::sleep(time_in_ticks(6));
|
|
||||||
}
|
|
||||||
else sf::sleep(time_in_ticks(14));
|
|
||||||
redraw();
|
redraw();
|
||||||
return clicked;
|
return clicked;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -451,6 +451,8 @@ protected:
|
|||||||
/// Redraws the parent dialog, if any.
|
/// Redraws the parent dialog, if any.
|
||||||
/// Intended to be called from handleClick(), where there is usually a minor event loop happening.
|
/// Intended to be called from handleClick(), where there is usually a minor event loop happening.
|
||||||
void redraw();
|
void redraw();
|
||||||
|
/// Plays the proper sound for this control being clicked on
|
||||||
|
void playClickSound();
|
||||||
private:
|
private:
|
||||||
friend class cDialog; // TODO: This is only so it can access parseColour... hack!
|
friend class cDialog; // TODO: This is only so it can access parseColour... hack!
|
||||||
eControlType type;
|
eControlType type;
|
||||||
|
|||||||
Reference in New Issue
Block a user