GLConsole.cpp

00001 // -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
00002 /* 
00003  * Copyright (C) 2008 Micha Hersch, EPFL
00004  * RobotCub Consortium, European Commission FP6 Project IST-004370
00005  * email:   micha.hersch@robotcub.org
00006  * website: www.robotcub.org
00007  * Permission is granted to copy, distribute, and/or modify this program
00008  * under the terms of the GNU General Public License, version 2 or any
00009  * later version published by the Free Software Foundation.
00010  *
00011  * A copy of the license can be found at
00012  * http://www.robotcub.org/icub/license/gpl.txt
00013  *
00014  * This program is distributed in the hope that it will be useful, but
00015  * WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
00017  * Public License for more details
00018  */
00019 #pragma warning( disable : 4786)
00020 
00021 #include <GL/glut.h>
00022 #include <math.h>
00023 #include <stdlib.h>
00024 #include <stdio.h>
00025 #include <vector>
00026 #include <string>
00027 #include <iostream>
00028 
00029 using namespace std;
00030 
00031 
00032 
00033 #include "GLConsole.h"
00034 #include "GLTools.h"
00035 
00036 GLConsole::GLConsole(pGLSubWindow parentWindow)
00037 : Console(),GLSubWindow(parentWindow){
00038   m_FontHeight    = 13;
00039   m_CursorStatus  = 1;
00040   m_CursorTimer.Start(500);
00041   SetMaxLines(20);
00042 
00043 }
00044 
00045 GLConsole::~GLConsole(){
00046 }
00047 
00048 int  GLConsole::AutoCompletion(){
00049   int nMatches = Console::AutoCompletion();
00050   if(nMatches>1){
00051     string s = "-->";    
00052     for(int i=0;i<nMatches;i++){
00053       s.append(" ");
00054       s.append(m_Commands[m_AutoMatches[i]]->m_Name);
00055     }
00056     Print(s);
00057   }
00058   return nMatches;
00059 }
00060 
00061 
00062 
00063 void GLConsole::Render(){
00064 
00065   Update();
00066 
00067         glColor4f(0.0,0.0,0.0,1.0);
00068         glBegin(GL_LINE_LOOP);
00069                 glVertex2i(   0, (m_MaxLines)*m_FontHeight+8);
00070                 glVertex2i( m_ClientRect.m_Width, (m_MaxLines)*m_FontHeight+8);
00071                 glVertex2i( m_ClientRect.m_Width, (m_MaxLines+1)*m_FontHeight+12);
00072                 glVertex2i(   0, (m_MaxLines+1)*m_FontHeight+12);
00073         glEnd();
00074 
00075         glDisable(GL_DEPTH_TEST);
00076 
00077   int y = m_FontHeight;
00078         int i;
00079         string s;
00080 
00081   y += m_FontHeight*(m_MaxLines-m_Lines.size());
00082         for(i=0;i<m_Lines.size();i++){
00083           s = "  ";
00084     s.append(m_Lines[i]);
00085     GLTools::DisplayText(1,y, s.c_str());
00086           y += m_FontHeight;
00087         }
00088 
00089   y = (m_MaxLines+1) * m_FontHeight+8;
00090   s = "> ";
00091   s.append(m_CurrCmd);
00092 
00093   if(m_HasFocus){
00094     if(m_CursorStatus==1){
00095       s.append("_");
00096     }
00097     if(m_CursorTimer.IsDone()){
00098       m_CursorStatus = 1-m_CursorStatus;
00099       m_CursorTimer.Start(500);
00100     }
00101   }
00102 
00103         GLTools::DisplayText(1,y, s.c_str());
00104 
00105         glEnable(GL_DEPTH_TEST);
00106 
00107 }
00108 
00109 void  GLConsole::OnNormalKey(char key){
00110   if(key==3) // Ctrl+C
00111     m_CurrCmd = "";
00112   
00113   if((key>=' ') && (key<'~')){
00114     AddChar(key);
00115   }
00116   if((key==8)||(key==127))
00117     EraseChar();
00118 
00119   if(key==13)
00120     Accept();
00121   
00122   if(key=='\t')
00123     AutoCompletion();
00124   
00125 }
00126 void  GLConsole::OnSpecialKey(int key){
00127   switch (key) {
00128   case GLUT_KEY_UP : 
00129     HistoryPrev(); break;
00130   case GLUT_KEY_DOWN : 
00131     HistoryNext(); break;
00132   }
00133 }
00134 
00135 void  GLConsole::Resize(int w, int h){
00136   int mlines = (h-12)/(m_FontHeight)-1;
00137   mlines = (mlines>1?mlines:1);
00138   SetMaxLines(mlines);
00139 }
 All Data Structures Functions Variables

Generated on Wed Sep 22 16:51:26 2010 for Body_Schema_Learning by  doxygen 1.6.1