MenuItem.cpp

Go to the documentation of this file.
00001 
00005 /* Copyright © 2009 James Legg.
00006     This program is free software: you can redistribute it and/or modify
00007     it under the terms of the GNU General Public License as published by
00008     the Free Software Foundation, either version 3 of the License, or
00009     (at your option) any later version.
00010 */
00011 #include "MenuItem.h"
00012 #include "BasicFonts.h"
00013 #include "UITextures.h"
00014 
00015 #include <GL/gl.h>
00016 
00017 namespace UI
00018 {
00019 
00020 MenuItem::MenuItem(std::wstring label)
00021     : label(label)
00022 {
00023     set_state(S_NORMAL);
00024 }
00025 
00026 MenuItem::~MenuItem()
00027 {
00028 }
00029 
00030 void MenuItem::draw()
00031 {
00032     get_menu_texture().bind();
00033     glBegin(GL_QUADS);
00034         // the inward pointy bit on the left
00035         glTexCoord2f(0.0, tex_coord_y_start); glVertex2i(0, -32);
00036         glTexCoord2f(0.0, tex_coord_y_end); glVertex2i(0, 31);
00037         glTexCoord2f(0.40625, tex_coord_y_end); glVertex2i(103, 31);
00038         glTexCoord2f(0.40625, tex_coord_y_start); glVertex2i(103, -32);
00039         // body background
00040         glTexCoord2f(0.40625, tex_coord_y_start); glVertex2i(103, -32);
00041         glTexCoord2f(0.40625, tex_coord_y_end); glVertex2i(103, 31);
00042         glTexCoord2f(0.4765625, tex_coord_y_end); glVertex2i(103 + width, 31);
00043         glTexCoord2f(0.4765625, tex_coord_y_start); glVertex2i(103 + width, -32);
00044         // the pointy bit on the right.
00045         glTexCoord2f(0.4765625, tex_coord_y_start); glVertex2i(103 + width, -32);
00046         glTexCoord2f(0.4765625, tex_coord_y_end); glVertex2i(103 + width, 31);
00047         glTexCoord2f(0.625, tex_coord_y_end); glVertex2i(141 + width , 31);
00048         glTexCoord2f(0.625, tex_coord_y_start); glVertex2i(141 + width, -32);
00049     glEnd();
00050     // now draw the text
00051     glPushMatrix();
00052         glTranslatef(100.0, 0.0, 0.0);
00053         // shadow
00054         glColor4ub(0, 0, 0, 63);
00055         glPushMatrix();
00056             glTranslatef(1.0, 0.0, 0.0);
00057 #ifdef HAVE_FTGL_2_1_2
00058             // old version of ftgl messes with the matrix.
00059 # define push glPushMatrix()
00060 # define pop glPopMatrix()
00061 #else
00062 # define push
00063 # define pop
00064 #endif
00065             push;
00066             BasicFonts::get_instance().big_font.Render(label.c_str());
00067             pop; glTranslatef(-3.0, 0.0, 0.0); push;
00068             BasicFonts::get_instance().big_font.Render(label.c_str());
00069             pop; glTranslatef(1.0, -1.0, 0.0); push;
00070             BasicFonts::get_instance().big_font.Render(label.c_str());
00071             pop; glTranslatef(0.0, 3.0, 0.0); push;
00072             BasicFonts::get_instance().big_font.Render(label.c_str());
00073             pop;
00074 #undef push
00075 #undef pop
00076         glPopMatrix();
00077         glColor3ub(255, 255, 255);
00078         BasicFonts::get_instance().big_font.Render(label.c_str());
00079     glPopMatrix();
00080 }
00081 
00082 void MenuItem::activate()
00083 {
00084     set_state(S_ACTIVE);
00085 }
00086 
00087 void MenuItem::set_state(State state_in)
00088 {
00089     state = state_in;
00090     tex_coord_y_start = float(state) * 0.25;
00091     tex_coord_y_end = tex_coord_y_start + 0.25;
00092 }
00093 
00094 MenuItem::State MenuItem::get_state()
00095 {
00096     return state;
00097 }
00098 
00099 unsigned int MenuItem::get_min_width()
00100 {
00101     width = BasicFonts::get_instance().big_font.Advance(label.c_str());
00102     return width + 193;
00103 }
00104 
00105 void MenuItem::set_width(unsigned int width_in)
00106 {
00107     // we use width to determine the width of the text block, so deduct the frame
00108     width = width_in - 193;
00109 }
00110 
00111 }

Get Racer at SourceForge.net. Fast, secure and Free Open Source software downloads

Generated at Mon Sep 6 00:41:13 2010 by Doxygen version 1.4.7 for Racer version svn335.