intermediate commit: restructuring view states
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <queue>
|
||||
#include <stack>
|
||||
#include <bitset>
|
||||
|
||||
#include "Module.h"
|
||||
|
||||
+97
-4
@@ -31,13 +31,9 @@ bool regionhit (int x, int y, int w, int h) {
|
||||
}
|
||||
|
||||
void DrawBlock (int x, int y, int w, int h) {
|
||||
const int d = 16;
|
||||
const float shading_dark = 0.5;
|
||||
const float shading_light = 1.3;
|
||||
|
||||
assert (h > d);
|
||||
assert (w > d);
|
||||
|
||||
float color[4];
|
||||
glGetFloatv (GL_CURRENT_COLOR, color);
|
||||
|
||||
@@ -413,6 +409,103 @@ bool LineEdit (int id, int x, int y, std::string &text_value, const int &maxleng
|
||||
return false;
|
||||
}
|
||||
|
||||
float VerticalSlider (int id, int x, int y, int w, int h, float min_value, float max_value, float &value) {
|
||||
const int knob_width = 16;
|
||||
const int knob_height = h * 2;
|
||||
|
||||
int slider_pos = (w * value) / max_value - knob_width / 2;
|
||||
|
||||
// Check for hotness
|
||||
if (regionhit (x, y + h * 0.5 - knob_height * 0.5, w, knob_height)) {
|
||||
controller->uistate.hotitem = id;
|
||||
if (controller->uistate.activeitem == 0
|
||||
&& controller->GetButtonState(MouseButtonLeft)) {
|
||||
controller->uistate.activeitem = id;
|
||||
}
|
||||
}
|
||||
|
||||
// If nothing is selected
|
||||
if (controller->uistate.hotitem != 0) {
|
||||
controller->uistate.kbditem = controller->uistate.hotitem;
|
||||
}
|
||||
|
||||
if (controller->uistate.kbditem == 0) {
|
||||
controller->uistate.hotitem = id;
|
||||
controller->uistate.kbditem = id;
|
||||
}
|
||||
|
||||
// If we have keyboard focus, we highlight the widget
|
||||
if ( controller->uistate.kbditem == id) {
|
||||
if (controller->uistate.activeitem == id) {
|
||||
glColor3f (0.6, 0.6, 0.6);
|
||||
DrawBlock (x, y, w, h);
|
||||
glColor3f (0.8, 0.8, 0.8);
|
||||
DrawBlock (x + slider_pos, y + h * 0.5 - knob_height * 0.5, knob_width, knob_height);
|
||||
} else {
|
||||
glColor3f (0.6, 0.6, 0.6);
|
||||
DrawBlock (x, y, w, h);
|
||||
glColor3f (0.7, 0.7, 0.7);
|
||||
DrawBlock (x + slider_pos, y + h * 0.5 - knob_height * 0.5, knob_width, knob_height);
|
||||
}
|
||||
} else {
|
||||
glColor3f (0.4, 0.4, 0.4);
|
||||
DrawBlock (x, y, w, h);
|
||||
glColor3f (0.5, 0.5, 0.5);
|
||||
DrawBlock (x + slider_pos, y + h * 0.5 - knob_height * 0.5, knob_width, knob_height);
|
||||
}
|
||||
|
||||
if (controller->uistate.kbditem == id) {
|
||||
switch (controller->uistate.last_keysym) {
|
||||
case SDLK_DOWN:
|
||||
controller->uistate.kbditem = 0;
|
||||
controller->uistate.hotitem = 0;
|
||||
controller->uistate.last_keysym = SDLK_CLEAR;
|
||||
break;
|
||||
case SDLK_UP:
|
||||
controller->uistate.kbditem = controller->uistate.lastwidget;
|
||||
controller->uistate.hotitem = controller->uistate.lastwidget;
|
||||
controller->uistate.last_keysym = SDLK_CLEAR;
|
||||
break;
|
||||
case SDLK_LEFT:
|
||||
value -= (max_value - min_value) * 0.1;
|
||||
if ( value < min_value)
|
||||
value = min_value;
|
||||
controller->uistate.last_keysym = SDLK_CLEAR;
|
||||
return true;
|
||||
break;
|
||||
case SDLK_RIGHT:
|
||||
value += (max_value - min_value) * 0.1;
|
||||
if ( value > max_value)
|
||||
value = max_value;
|
||||
controller->uistate.last_keysym = SDLK_CLEAR;
|
||||
return true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
controller->uistate.lastwidget = id;
|
||||
|
||||
if (controller->uistate.activeitem == id) {
|
||||
int mouse_pos[2];
|
||||
controller->GetMouseScreenPosition(mouse_pos);
|
||||
int rel_mouse_pos = mouse_pos[0] - x;
|
||||
if (rel_mouse_pos < 0)
|
||||
rel_mouse_pos = 0;
|
||||
if (rel_mouse_pos > w)
|
||||
rel_mouse_pos = w;
|
||||
|
||||
float mouse_value = rel_mouse_pos * max_value / static_cast<float>(w);
|
||||
|
||||
if (mouse_value != value) {
|
||||
value = mouse_value;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CheckKeyPress (int keycode) {
|
||||
if (controller->uistate.last_keysym == keycode)
|
||||
return true;
|
||||
|
||||
@@ -34,6 +34,8 @@ bool Button (int id, const char* caption, int x, int y, int w, int h);
|
||||
|
||||
bool LineEdit (int id, int x, int y, std::string &text_value, const int &maxlength);
|
||||
|
||||
float VerticalSlider (int id, int x, int y, int w, int h, float min_value, float max_value, float &value);
|
||||
|
||||
/** \brief Checks whether a given key was pressed
|
||||
*
|
||||
* This function can be used to check whether a single key (e.g. ESC) was
|
||||
|
||||
@@ -233,5 +233,36 @@ void HaltSoundLoop (const std::string &sound_name) {
|
||||
SoundInstance->HaltSoundLoop(sound_name);
|
||||
}
|
||||
|
||||
void SetMusicVolume (const float &music_volume) {
|
||||
if (!SoundInstance) {
|
||||
LogError("Could set music volume: sound system not initialized!");
|
||||
}
|
||||
|
||||
SoundInstance->SetMusicVolume(music_volume);
|
||||
}
|
||||
|
||||
float GetMusicVolume () {
|
||||
if (!SoundInstance) {
|
||||
LogError("Could get music volume: sound system not initialized!");
|
||||
}
|
||||
|
||||
return SoundInstance->GetMusicVolume();
|
||||
}
|
||||
|
||||
void SetEffectsVolume (const float &effects_volume) {
|
||||
if (!SoundInstance) {
|
||||
LogError("Could set effects volume: sound system not initialized!");
|
||||
}
|
||||
|
||||
SoundInstance->SetEffectsVolume(effects_volume);
|
||||
}
|
||||
|
||||
float GetEffectsVolume () {
|
||||
if (!SoundInstance) {
|
||||
LogError("Could get effects volume: sound system not initialized!");
|
||||
}
|
||||
|
||||
return SoundInstance->GetEffectsVolume();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
@@ -8,6 +8,21 @@ void PlaySoundLoop (const std::string &sound_name, int count);
|
||||
void HaltSoundLoop (const std::string &sound_name);
|
||||
void PlayMusic (const std::string &music_name);
|
||||
|
||||
/** \brief Sets the volume of the music channel to the given value
|
||||
*
|
||||
* \param music_value is a value from 0. (no music) to 1. (maximum volume)
|
||||
*/
|
||||
void SetMusicVolume (const float &music_volume);
|
||||
/** \brief Returns the value of the music (0. - 1.) */
|
||||
float GetMusicVolume ();
|
||||
/** \brief Sets the volume of the music channel to the given value
|
||||
*
|
||||
* \param music_value is a value from 0. (no music) to 1. (maximum volume)
|
||||
*/
|
||||
void SetEffectsVolume (const float &effects_volume);
|
||||
/** \brief Returns the value of the effects (0. - 1.) */
|
||||
float GetEffectsVolume ();
|
||||
|
||||
}
|
||||
|
||||
#endif /* _SOUNDGLOBAL_H */
|
||||
|
||||
Reference in New Issue
Block a user