stylized the butons

main
Martin Felis (schakeline) 2010-10-30 11:39:59 +02:00
parent 3d7fc1d641
commit 6f3d78dab0
1 changed files with 61 additions and 9 deletions

View File

@ -30,6 +30,58 @@ bool regionhit (int x, int y, int w, int h) {
return true; return true;
} }
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);
glBegin(GL_QUADS);
// lower part
glVertex3f (x, y, 0.);
glVertex3f (x, y + d, 0.);
glVertex3f (x + w, y + d, 0.);
glVertex3f (x + w - d, y, 0.);
// middle part
glVertex3f (x, y + d, 0.);
glVertex3f (x, y + d + h - 2 * d, 0.);
glVertex3f (x + w, y + d + h - 2 * d, 0.);
glVertex3f (x + w, y + d, 0.);
// bottom part
glVertex3f (x, y + h - d, 0.);
glVertex3f (x + d, y + h, 0.);
glVertex3f (x + w, y + h, 0.);
glVertex3f (x + w, y + h - d, 0.);
glEnd();
// "Shading"
float color[4];
glGetFloatv (GL_CURRENT_COLOR, color);
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 -d, 0.);
glVertex3f (x + d, y + h, 0.);
glVertex3f (x + w - 2, y + h, 0.);
glEnd();
glColor3f (color[0] * shading_light, color[1] * shading_light, color[2] * shading_light);
glBegin(GL_LINE_STRIP);
glVertex3f (x + w - d, y, 0.);
glVertex3f (x + w, y + d, 0.);
glEnd();
glColor4fv (color);
}
/** \brief Draws a label with a given caption at the position (vertically centered) /** \brief Draws a label with a given caption at the position (vertically centered)
* *
* This function draws the label at the horizontal x position and centers the * This function draws the label at the horizontal x position and centers the
@ -85,20 +137,20 @@ bool Button (int id, const char* caption, int x, int y, int w, int h) {
// Render // Render
glColor3f (0.2, 0.2, 0.2); glColor3f (0.2, 0.2, 0.2);
DrawRect2D (x + 4, y + 4, w, h); // DrawBlock (x + 4, y + 4, w, h);
if (controller->uistate.hotitem == id if (controller->uistate.hotitem == id
|| controller->uistate.kbditem == id) { || controller->uistate.kbditem == id) {
if (controller->uistate.activeitem == id) { if (controller->uistate.activeitem == id) {
glColor3f (0.8, 0.8, 0.8); glColor3f (0.8, 0.8, 0.8);
DrawRect2D (x, y, w, h); DrawBlock (x, y, w, h);
} else { } else {
glColor3f (0.7, 0.7, 0.7); glColor3f (0.7, 0.7, 0.7);
DrawRect2D (x, y, w, h); DrawBlock (x, y, w, h);
} }
} else { } else {
glColor3f (0.4, 0.4, 0.4); glColor3f (0.4, 0.4, 0.4);
DrawRect2D (x, y, w, h); DrawBlock (x, y, w, h);
} }
// Caption // Caption
@ -166,7 +218,7 @@ bool LineEdit (int id, int x, int y, std::string &text_value, const int &maxleng
assert (controller); assert (controller);
int w = maxlength * 16; int w = maxlength * 16;
int h = 16; int h = 20;
// 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)); // 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));
@ -188,20 +240,20 @@ bool LineEdit (int id, int x, int y, std::string &text_value, const int &maxleng
// Render // Render
glColor3f (0.2, 0.2, 0.2); glColor3f (0.2, 0.2, 0.2);
DrawRect2D (x + 4, y + 4, w, h); DrawBlock (x + 4, y + 4, w, h);
// If we have keyboard focus, we highlight the widget // If we have keyboard focus, we highlight the widget
if ( controller->uistate.kbditem == id) { if ( controller->uistate.kbditem == id) {
if (controller->uistate.activeitem == id) { if (controller->uistate.activeitem == id) {
glColor3f (0.8, 0.8, 0.8); glColor3f (0.8, 0.8, 0.8);
DrawRect2D (x, y, w, h); DrawBlock (x, y, w, h);
} else { } else {
glColor3f (0.7, 0.7, 0.7); glColor3f (0.7, 0.7, 0.7);
DrawRect2D (x, y, w, h); DrawBlock (x, y, w, h);
} }
} else { } else {
glColor3f (0.4, 0.4, 0.4); glColor3f (0.4, 0.4, 0.4);
DrawRect2D (x, y, w, h); DrawBlock (x, y, w, h);
} }
// Rendering of the current value // Rendering of the current value