editor: highlighting the current mode

This commit is contained in:
2011-02-11 17:43:23 +01:00
parent 8daee27ed8
commit ad528f0c6f
3 changed files with 129 additions and 11 deletions
+115
View File
@@ -272,6 +272,121 @@ bool Button (int id, const char* caption, int x, int y, int w, int h) {
return false;
}
bool CheckButton (int id, const char* caption, bool checked, int x, int y, int w, int h) {
controller = EngineGetController();
assert (controller);
// LogMessage ("id = %d hotitem = %d activeitem = %d kbditem = %d", id, controller->uistate.hotitem, controller->uistate.activeitem, controller->uistate.kbditem);
// Check for hotness
if (regionhit (x, y, w, h)) {
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;
}
// Render
if (checked) {
glColor3f (0.91, 0.84, 0.);
DrawRoundedBlock (x - 2, y - 2, w + 4, h + 4);
}
glColor3f (0.2, 0.2, 0.2);
if (controller->uistate.hotitem == id
|| controller->uistate.kbditem == id) {
if (controller->uistate.activeitem == id) {
glColor3f (0.8, 0.8, 0.8);
DrawRoundedBlock (x, y, w, h);
} else {
glColor3f (0.7, 0.7, 0.7);
DrawRoundedBlock (x, y, w, h);
}
} else {
glColor3f (0.4, 0.4, 0.4);
DrawRoundedBlock (x, y, w, h);
}
// Caption
if (caption != NULL) {
float width, height;
view = EngineGetView ();
assert (view);
// we have to load the font prior to measuring it
SelectFont("console.ttf size=23");
view->DrawGLStringMeasure(caption, &width, &height);
float xpos = x + w * 0.5 - width * 0.5;
float ypos = y + h * 0.5 - height * 0.5;
// LogDebug ("measure '%s' width = %f height = %f", caption, width, height);
if (controller->uistate.hotitem == id || controller->uistate.kbditem == id) {
SelectFont("console.ttf size=23 color=#666666");
view->DrawGLString( xpos - 2., ypos + 2., caption);
SelectFont("console.ttf size=23 color=#ffffff");
view->DrawGLString( xpos, ypos, caption);
} else {
SelectFont("console.ttf size=23 color=#4d4d4d");
view->DrawGLString( xpos - 2., ypos + 2., caption);
SelectFont("console.ttf size=23 color=#b3b3b3");
view->DrawGLString( xpos, ypos, caption);
}
}
// Mouse Logic
if (controller->GetButtonState(MouseButtonLeft) == false
&& controller->uistate.hotitem == id
&& controller->uistate.activeitem == id) {
controller->uistate.lastwidget = id;
return true;
}
// Keyboard Logic
if (controller->uistate.kbditem == id) {
// Any unicode keys that were sent get cleared
controller->uistate.last_unicode = 0;
// We have to make sure, that we always clear the uistate.last_keysym
// value, otherwise the same action might be repeated over and over.
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_RETURN:
controller->uistate.last_keysym = SDLK_CLEAR;
// As we (probably) exit the current set of widgets, we have to clear
// the uistate.kbditem value.
controller->uistate.kbditem = 0;
return true;
break;
}
}
controller->uistate.lastwidget = id;
return false;
}
/** \brief An Edit widget that allows editing of a string consisting of one line
*
* \TODO [med] vertical alignment (especially of text) is a bit whacky
+2
View File
@@ -34,6 +34,8 @@ void LabelCentered (int id, const char* caption, int x, int y);
*/
bool Button (int id, const char* caption, int x, int y, int w, int h);
bool CheckButton (int id, const char* caption, bool state, 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);