polished GUI

This commit is contained in:
2010-11-13 18:45:15 +01:00
parent cf2fe0e32d
commit 26087be9f3
10 changed files with 234 additions and 76 deletions
+3
View File
@@ -159,6 +159,9 @@ void ControllerBase::IMGUIFinish () {
if (uistate.activeitem == 0)
uistate.activeitem = -1;
}
// also reset the last keysym such that old values will not be reported
uistate.last_keysym = SDLK_FIRST;
}
/** \brief Keyboard processing */
+82 -12
View File
@@ -38,6 +38,40 @@ void DrawBlock (int x, int y, int w, int h) {
assert (h > d);
assert (w > d);
float color[4];
glGetFloatv (GL_CURRENT_COLOR, color);
glBegin(GL_QUADS);
// middle part
glVertex3f (x, y, 0.);
glVertex3f (x, y + h, 0.);
glVertex3f (x + w, y + h, 0.);
glVertex3f (x + w, y, 0.);
glEnd();
glColor4fv (color);
// "Shading"
glLineWidth(3);
glColor3f (color[0] * shading_dark, color[1] * shading_dark, color[2] * shading_dark);
glBegin(GL_LINE_STRIP);
glVertex3f (x,y + 2, 0.);
glVertex3f (x,y +h, 0.);
glVertex3f (x + w - 2, y + h, 0.);
glEnd();
}
void DrawRoundedBlock (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);
glBegin(GL_QUADS);
// lower part
glVertex3f (x, y, 0.);
@@ -103,6 +137,26 @@ void Label (int id, const char* caption, int x, int y) {
}
}
/** \brief Draws a label with a given caption centered at the position (vertically centered)
*
* This function draws the label at the horizontal x position and centers the
* label with regard to the height of the rendered caption.
*
* \TODO [med] The vertical alignment around the center of the vertical height
* of the string is rather unfortunate as different contents will be rendered
* at different vertical positions (e.g. "aaa" and "ggg")
*/
void LabelCentered (int id, const char* caption, int x, int y) {
if (caption != NULL) {
float width, height;
view = EngineGetView ();
assert (view);
view->DrawGLStringMeasure(caption, &width, &height);
view->DrawGLString(x - 0.5 * width, y + height * 0.5, caption);
}
}
/** \brief Draws a button at the given position
*
* The area defined by the parameters defines the clickable area. However
@@ -137,20 +191,20 @@ bool Button (int id, const char* caption, int x, int y, int w, int h) {
// Render
glColor3f (0.2, 0.2, 0.2);
// DrawBlock (x + 4, y + 4, w, h);
// DrawRoundedBlock (x + 4, y + 4, w, h);
if (controller->uistate.hotitem == id
|| controller->uistate.kbditem == id) {
if (controller->uistate.activeitem == id) {
glColor3f (0.8, 0.8, 0.8);
DrawBlock (x, y, w, h);
DrawRoundedBlock (x, y, w, h);
} else {
glColor3f (0.7, 0.7, 0.7);
DrawBlock (x, y, w, h);
DrawRoundedBlock (x, y, w, h);
}
} else {
glColor3f (0.4, 0.4, 0.4);
DrawBlock (x, y, w, h);
DrawRoundedBlock (x, y, w, h);
}
// Caption
@@ -159,9 +213,25 @@ bool Button (int id, const char* caption, int x, int y, int w, int h) {
view = EngineGetView ();
assert (view);
glColor3f (1., 1., 1.);
// we have to load the font prior to measuring it
SelectFont("console.ttf size=23");
view->DrawGLStringMeasure(caption, &width, &height);
view->DrawGLString(x + w * 0.5 - width * 0.5, y + h * 0.5 - height * 0.5, caption);
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
@@ -217,8 +287,12 @@ bool LineEdit (int id, int x, int y, std::string &text_value, const int &maxleng
controller = EngineGetController();
assert (controller);
int textpos_x = x + 8;
int textpos_y = y + 5;
y -= 16;
int w = maxlength * 16;
int h = 20;
int h = 30;
// LogMessage ("id = %d hotitem = %d activeitem = %d kbditem = %d key = %s", id, controller->uistate.hotitem, controller->uistate.activeitem, controller->uistate.kbditem, convert_keycode (controller->uistate.last_keysym));
@@ -238,10 +312,6 @@ bool LineEdit (int id, int x, int y, std::string &text_value, const int &maxleng
return false;
}
// Render
glColor3f (0.2, 0.2, 0.2);
DrawBlock (x + 4, y + 4, w, h);
// If we have keyboard focus, we highlight the widget
if ( controller->uistate.kbditem == id) {
if (controller->uistate.activeitem == id) {
@@ -269,7 +339,7 @@ bool LineEdit (int id, int x, int y, std::string &text_value, const int &maxleng
text_output += "_";
view->DrawGLStringMeasure(text_value.c_str(), &width, &height);
view->DrawGLString(x + 16, y + 12, text_output.c_str());
view->DrawGLString(textpos_x, textpos_y, text_output.c_str());
// Keyboard Logic
if (controller->uistate.kbditem == id) {
+3
View File
@@ -19,6 +19,9 @@ bool regionhit (int x, int y, int w, int h);
/** \brief Draws a label at the given position with vertical center at y */
void Label (int id, const char* caption, int x, int y);
/** \brief Draws a label centered at the given position with vertical center at y */
void LabelCentered (int id, const char* caption, int x, int y);
/** \brief Draws a button at the given position
*
+1 -1
View File
@@ -46,7 +46,7 @@ int SoundBase::OnInit(int argc, char* argv[]) {
int audio_rate = 22050;
Uint16 audio_format = AUDIO_S16;
int audio_channels = 2;
int audio_buffers = 4096;
int audio_buffers = 1024;
LogDebug("Sound Init");
if (Mix_OpenAudio (audio_rate, audio_format, audio_channels, audio_buffers)) {
+1
View File
@@ -339,6 +339,7 @@ void ViewBase::DrawGLStringMeasure (const char* str, float *width, float *height
OGLFT::BBox bbox = mCurrentFont->measure (str);
*width = bbox.x_max_ - bbox.x_min_;
*height = bbox.y_max_ - bbox.y_min_;
// LogDebug ("measure bbox '%s' = %f,%f %f,%f",str, bbox.x_min_, bbox.y_min_, bbox.x_max_, bbox.y_max_);
}
void ViewBase::GetCamereEye (float *eye_out) {