Main Page | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Globals

/Users/blackie/Documents/myRepository/phobosengine-vc2005/phobosengine/phobosengine/Console.cpp

Go to the documentation of this file.
00001 
00002 
00003 #include "Console.h"
00004 
00005 #include "Camera.h"
00006 #include "CoreEngine.h"
00007 #include "Renderer.h"
00008 #include "TextEdit.h"
00009 #include "TextBox.h"
00010 #include "World.h"
00011 
00012 
00013 namespace pge {
00014         namespace gui {
00015 
00016 
00017                 //****************************************************************************
00018                 //
00019                 //
00020                 //
00021                 //****************************************************************************
00022                 Console::Console(int x, int y, int width, int height) {
00023                         m_backgroundColor = Vector4f(0.1f, 0.1f, 0.1f, 0.6f);
00024                         m_xOff = x;
00025                         m_yOff = y;
00026                         m_width = width;
00027                         m_height = height;
00028 
00029                         // Console animation
00030                         m_aniHeight = 0;
00031                         m_animate = false;
00032 
00033                         // Output textbox
00034                         m_output = new TextBox(m_xOff + 10, m_yOff + 10, m_width - 20, m_height - 50);
00035                         m_output->setBackgroundColor(Vector4f(0.4f, 0.4f, 0.4f, 0.5f));
00036                         m_output->setBackgroundEnabled(true);
00037 
00038                         m_output->addLine("Phobosengine version 0.1alpha");
00039                         m_output->addLine("Console system, type help for commands.");
00040 
00041                         // Input textedit
00042                         m_input = new TextEdit(m_xOff + 10, m_yOff + m_height - 30, m_width - 20, 20);
00043                         m_input->setBackgroundColor(Vector4f(0.6f, 0.4f, 0.4f, 0.5f));
00044                         m_input->setBackgroundEnabled(true);
00045 
00046                 }
00047 
00048 
00049                 //****************************************************************************
00050                 //
00051                 //
00052                 //
00053                 //****************************************************************************
00054                 Console::~Console(void) {
00055                 }
00056 
00057 
00058                 //****************************************************************************
00059                 //
00060                 //
00061                 //
00062                 //****************************************************************************
00063                 bool Console::init(void) {
00064                         return true;
00065                 }
00066 
00067 
00068                 //****************************************************************************
00069                 //
00070                 //
00071                 //
00072                 //****************************************************************************
00073                 void Console::render(void) {
00074                         renderer::setTextureUnitEnabled(GL_TEXTURE0, false);
00075                         renderer::setBlendingEnabled(true);
00076                         renderer::setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
00077 
00078                         renderer::color4f(m_backgroundColor);
00079                         glBegin(GL_QUADS);
00080                         renderer::vertex2i(m_xOff, CoreEngine::getInstance()->getResolutionHeight() - m_yOff);
00081                         renderer::vertex2i(m_yOff, CoreEngine::getInstance()->getResolutionHeight() - m_yOff - m_aniHeight);
00082                         renderer::vertex2i(m_width, CoreEngine::getInstance()->getResolutionHeight() - m_yOff - m_aniHeight);
00083                         renderer::vertex2i(m_width, CoreEngine::getInstance()->getResolutionHeight() - m_yOff);
00084                         glEnd();
00085 
00086                         renderer::setBlendingEnabled(false);
00087 
00088                         if(!m_animate) {
00089                                 m_output->render();
00090                                 m_input->render();
00091                         }
00092                 }
00093 
00094 
00095                 //****************************************************************************
00096                 //
00097                 //
00098                 //
00099                 //****************************************************************************
00100                 void Console::timer(unsigned int delay) {
00101                         if(m_animate) {
00102                                 if(m_aniHeight < m_height) {
00103                                         m_aniHeight += 20;
00104                                 } else {
00105                                         // Set to m_height so a possible greater value after the above
00106                                         // statement is corrected.
00107                                         m_aniHeight = m_height;
00108                                         m_animate = false;
00109                                 }
00110                         }
00111                 }
00112 
00113 
00114                 //****************************************************************************
00115                 //
00116                 //
00117                 //
00118                 //****************************************************************************
00119                 void Console::show(void) {
00120                         m_animate = true;
00121                 }
00122 
00123 
00124                 //****************************************************************************
00125                 //
00126                 //
00127                 //
00128                 //****************************************************************************
00129                 void Console::hide(void) {
00130                         m_animate = false;
00131                         m_aniHeight = 0;
00132                 }
00133 
00134 
00135                 //****************************************************************************
00136                 //
00137                 //
00138                 //
00139                 //****************************************************************************
00140                 void Console::keyTypeCall(int keyCode) {
00141                         // Handle backspace
00142                         if(keyCode == 8) {
00143                                 if(m_input->getText().length() > 0) {
00144                                         //m_input->setText(m_input->getText().substring(0, m_input.getText().length() - 1));
00145                                 }
00146 
00147                                 // Handle return
00148                         } else if (keyCode == 10) {
00149 
00150                                 m_output->addLine(">" + m_input->getText());
00151                                 // TODO: send text to console system, get result and put it in textbox!
00152                                 //if(m_input->getText() == "camera") {
00153                                 //m_output->addLine(std::string(">") + m_input->getText());
00154                                 //m_output->addLine("> Camera position: " + CoreEngine::getInstance()->getCurrentWorld()->getCamera()->getPosition());
00155                                 //}
00156                                 m_input->setText("");
00157 
00158                         } else {
00159                                 //m_input->setText(m_input->getText() + KeyCode.getKeyCharAlphaNumeric(keyCode));
00160                         }
00161                 }
00162         };
00163 };

Generated on Mon Oct 16 12:08:10 2006 for Phobosengine by doxygen 1.3.4