Skip to content

Commit c4ae70b

Browse files
committed
Make the volume buttons light up once pressed
1 parent 517ed88 commit c4ae70b

File tree

3 files changed

+30
-9
lines changed

3 files changed

+30
-9
lines changed

source/code/MenuSystem.cpp

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -137,23 +137,36 @@ void ButtonWithAdjustment::drawToScreen(SDL_Renderer* target) const {
137137
// Draw left adjustment button (down arrow)
138138
int adjustSize = getAdjustButtonSize();
139139
int leftX = x - adjustSize - 10;
140-
int leftY = y + (standardButton.ysize - adjustSize) / 2; // Vertically center the small button
141-
globalData.spriteHolder->GetSprite("menu_unmarked").DrawScaled(globalData.screen, SDL_GetTicks(), leftX, leftY, adjustSize, adjustSize, &globalData.logicalResize);
142-
standardButton.getLabel("\u25c0", false)->Draw(globalData.screen, leftX+adjustSize/2, leftY+adjustSize/2,
140+
int leftY = y;
141+
Uint32 currentTime = SDL_GetTicks();
142+
bool leftMarked = (currentTime - leftButtonMarkTime) < MARK_DURATION;
143+
if (leftMarked) {
144+
globalData.spriteHolder->GetSprite("menu_marked").DrawScaled(globalData.screen, SDL_GetTicks(), leftX, leftY, adjustSize, adjustSize, &globalData.logicalResize);
145+
}
146+
else {
147+
globalData.spriteHolder->GetSprite("menu_unmarked").DrawScaled(globalData.screen, SDL_GetTicks(), leftX, leftY, adjustSize, adjustSize, &globalData.logicalResize);
148+
}
149+
standardButton.getLabel("\u25c0", leftMarked)->Draw(globalData.screen, leftX+adjustSize/2, leftY+adjustSize/2,
143150
sago::SagoTextField::Alignment::center, sago::SagoTextField::VerticalAlignment::center, &globalData.logicalResize);
144151

145152
// Draw right adjustment button (up arrow)
146153
int rightX = x + standardButton.xsize + 10;
147-
int rightY = y + (standardButton.ysize - adjustSize) / 2; // Vertically center the small button
148-
globalData.spriteHolder->GetSprite("menu_unmarked").DrawScaled(globalData.screen, SDL_GetTicks(), rightX, rightY, adjustSize, adjustSize, &globalData.logicalResize);
149-
standardButton.getLabel("\u25b6", false)->Draw(globalData.screen, rightX+adjustSize/2, rightY+adjustSize/2,
154+
int rightY = y;
155+
bool rightMarked = (currentTime - rightButtonMarkTime) < MARK_DURATION;
156+
if (rightMarked) {
157+
globalData.spriteHolder->GetSprite("menu_marked").DrawScaled(globalData.screen, SDL_GetTicks(), rightX, rightY, adjustSize, adjustSize, &globalData.logicalResize);
158+
}
159+
else {
160+
globalData.spriteHolder->GetSprite("menu_unmarked").DrawScaled(globalData.screen, SDL_GetTicks(), rightX, rightY, adjustSize, adjustSize, &globalData.logicalResize);
161+
}
162+
standardButton.getLabel("\u25b6", rightMarked)->Draw(globalData.screen, rightX+adjustSize/2, rightY+adjustSize/2,
150163
sago::SagoTextField::Alignment::center, sago::SagoTextField::VerticalAlignment::center, &globalData.logicalResize);
151164
}
152165

153166
bool ButtonWithAdjustment::isClickedAdjustLeft(int mx, int my) const {
154167
int adjustSize = getAdjustButtonSize();
155168
int leftX = x - adjustSize - 10;
156-
int leftY = y + (standardButton.ysize - adjustSize) / 2;
169+
int leftY = y;
157170
if (mx >= leftX && my >= leftY && mx <= leftX + adjustSize && my <= leftY + adjustSize) {
158171
return true;
159172
}
@@ -163,7 +176,7 @@ bool ButtonWithAdjustment::isClickedAdjustLeft(int mx, int my) const {
163176
bool ButtonWithAdjustment::isClickedAdjustRight(int mx, int my) const {
164177
int adjustSize = getAdjustButtonSize();
165178
int rightX = x + standardButton.xsize + 10;
166-
int rightY = y + (standardButton.ysize - adjustSize) / 2;
179+
int rightY = y;
167180
if (mx >= rightX && my >= rightY && mx <= rightX + adjustSize && my <= rightY + adjustSize) {
168181
return true;
169182
}

source/code/MenuSystem.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,11 @@ class ButtonWithAdjustment : public Button
112112
return adjustSize + 10 + standardButton.xsize + 10 + adjustSize;
113113
};
114114

115-
int getAdjustButtonSize() const { return standardButton.ysize / 2; };
115+
int getAdjustButtonSize() const { return standardButton.ysize; };
116+
117+
mutable Uint32 leftButtonMarkTime = 0;
118+
mutable Uint32 rightButtonMarkTime = 0;
119+
static const Uint32 MARK_DURATION = 200; // milliseconds
116120
};
117121

118122

source/code/menudef.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ void Button_soundVolume::doLeft() {
249249
newValue = 0;
250250
}
251251
Config::getInstance()->setInt("volume_sound", newValue);
252+
leftButtonMarkTime = SDL_GetTicks();
252253
}
253254

254255
void Button_soundVolume::doRight() {
@@ -258,6 +259,7 @@ void Button_soundVolume::doRight() {
258259
newValue = MIX_MAX_VOLUME;
259260
}
260261
Config::getInstance()->setInt("volume_sound", newValue);
262+
rightButtonMarkTime = SDL_GetTicks();
261263
}
262264

263265
const std::string& Button_soundVolume::getLabel() const {
@@ -297,6 +299,7 @@ void Button_musicVolume::doLeft() {
297299
newValue = 0;
298300
}
299301
Config::getInstance()->setInt("volume_music", newValue);
302+
leftButtonMarkTime = SDL_GetTicks();
300303
}
301304

302305
void Button_musicVolume::doRight() {
@@ -306,6 +309,7 @@ void Button_musicVolume::doRight() {
306309
newValue = MIX_MAX_VOLUME;
307310
}
308311
Config::getInstance()->setInt("volume_music", newValue);
312+
rightButtonMarkTime = SDL_GetTicks();
309313
}
310314

311315
const std::string& Button_musicVolume::getLabel() const {

0 commit comments

Comments
 (0)