Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

Typer.cpp

Go to the documentation of this file.
00001 /*
00002 CS Senior Project 2003
00003 Team : Leftfield
00004 Project : ModernWarfare
00005 Members :
00006 - Russ Christensen              <rchriste@cs.utah.edu>
00007 - Todd Smith                    <tcsmith@cs.utah.edu>
00008 - Usit Duongsaa                 <duongsaa@cs.utah.edu>
00009 Copyright 2003 Russ Christensen, Usit Duongsaa, and Todd Smith. All rights reserved.
00010 
00011 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
00012 
00013 Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 
00014 Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 
00015 THIS SOFTWARE IS PROVIDED BY RUSS CHRISTENSEN, USIT DUONGSAA, AND TODD SMITH ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RUSS, USIT, TODD OR OTHER CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00016 */
00017 
00022 #include "Typer.h"
00023 
00024 
00025 //------------------------------------------------------------------------------------
00026 Typer::Typer()
00027 {
00028         *this = Typer("");
00029 }
00030 //------------------------------------------------------------------------------------
00031 Typer::Typer(string initialString)
00032 {
00033         if( typerCharSet.size()==0 )                            // init charSet once
00034         {
00035                 typerCharSet.push_back( Int3Tuple( KeyCodes::key_A, 1, (int)'A' ) );            
00036                 typerCharSet.push_back( Int3Tuple( KeyCodes::key_B, 1, (int)'B' ) );
00037                 typerCharSet.push_back( Int3Tuple( KeyCodes::key_C, 1, (int)'C' ) );
00038                 typerCharSet.push_back( Int3Tuple( KeyCodes::key_D, 1, (int)'D' ) );
00039                 typerCharSet.push_back( Int3Tuple( KeyCodes::key_E, 1, (int)'E' ) );
00040                 typerCharSet.push_back( Int3Tuple( KeyCodes::key_F, 1, (int)'F' ) );
00041                 typerCharSet.push_back( Int3Tuple( KeyCodes::key_G, 1, (int)'G' ) );
00042                 typerCharSet.push_back( Int3Tuple( KeyCodes::key_H, 1, (int)'H' ) );
00043                 typerCharSet.push_back( Int3Tuple( KeyCodes::key_I, 1, (int)'I' ) );
00044                 typerCharSet.push_back( Int3Tuple( KeyCodes::key_J, 1, (int)'J' ) );
00045                 typerCharSet.push_back( Int3Tuple( KeyCodes::key_K, 1, (int)'K' ) );
00046                 typerCharSet.push_back( Int3Tuple( KeyCodes::key_L, 1, (int)'L' ) );
00047                 typerCharSet.push_back( Int3Tuple( KeyCodes::key_M, 1, (int)'M' ) );
00048                 typerCharSet.push_back( Int3Tuple( KeyCodes::key_N, 1, (int)'N' ) );
00049                 typerCharSet.push_back( Int3Tuple( KeyCodes::key_O, 1, (int)'O' ) );
00050                 typerCharSet.push_back( Int3Tuple( KeyCodes::key_P, 1, (int)'P' ) );
00051                 typerCharSet.push_back( Int3Tuple( KeyCodes::key_Q, 1, (int)'Q' ) );
00052                 typerCharSet.push_back( Int3Tuple( KeyCodes::key_R, 1, (int)'R' ) );
00053                 typerCharSet.push_back( Int3Tuple( KeyCodes::key_S, 1, (int)'S' ) );
00054                 typerCharSet.push_back( Int3Tuple( KeyCodes::key_T, 1, (int)'T' ) );
00055                 typerCharSet.push_back( Int3Tuple( KeyCodes::key_U, 1, (int)'U' ) );
00056                 typerCharSet.push_back( Int3Tuple( KeyCodes::key_V, 1, (int)'V' ) );
00057                 typerCharSet.push_back( Int3Tuple( KeyCodes::key_W, 1, (int)'W' ) );
00058                 typerCharSet.push_back( Int3Tuple( KeyCodes::key_X, 1, (int)'X' ) );
00059                 typerCharSet.push_back( Int3Tuple( KeyCodes::key_Y, 1, (int)'Y' ) );
00060                 typerCharSet.push_back( Int3Tuple( KeyCodes::key_Z, 1, (int)'Z' ) );
00061                 typerCharSet.push_back( Int3Tuple( KeyCodes::key_A, 0, (int)'a' ) );            
00062                 typerCharSet.push_back( Int3Tuple( KeyCodes::key_B, 0, (int)'b' ) );
00063                 typerCharSet.push_back( Int3Tuple( KeyCodes::key_C, 0, (int)'c' ) );
00064                 typerCharSet.push_back( Int3Tuple( KeyCodes::key_D, 0, (int)'d' ) );
00065                 typerCharSet.push_back( Int3Tuple( KeyCodes::key_E, 0, (int)'e' ) );
00066                 typerCharSet.push_back( Int3Tuple( KeyCodes::key_F, 0, (int)'f' ) );
00067                 typerCharSet.push_back( Int3Tuple( KeyCodes::key_G, 0, (int)'g' ) );
00068                 typerCharSet.push_back( Int3Tuple( KeyCodes::key_H, 0, (int)'h' ) );
00069                 typerCharSet.push_back( Int3Tuple( KeyCodes::key_I, 0, (int)'i' ) );
00070                 typerCharSet.push_back( Int3Tuple( KeyCodes::key_J, 0, (int)'j' ) );
00071                 typerCharSet.push_back( Int3Tuple( KeyCodes::key_K, 0, (int)'k' ) );
00072                 typerCharSet.push_back( Int3Tuple( KeyCodes::key_L, 0, (int)'l' ) );
00073                 typerCharSet.push_back( Int3Tuple( KeyCodes::key_M, 0, (int)'m' ) );
00074                 typerCharSet.push_back( Int3Tuple( KeyCodes::key_N, 0, (int)'n' ) );
00075                 typerCharSet.push_back( Int3Tuple( KeyCodes::key_O, 0, (int)'o' ) );
00076                 typerCharSet.push_back( Int3Tuple( KeyCodes::key_P, 0, (int)'p' ) );
00077                 typerCharSet.push_back( Int3Tuple( KeyCodes::key_Q, 0, (int)'q' ) );
00078                 typerCharSet.push_back( Int3Tuple( KeyCodes::key_R, 0, (int)'r' ) );
00079                 typerCharSet.push_back( Int3Tuple( KeyCodes::key_S, 0, (int)'s' ) );
00080                 typerCharSet.push_back( Int3Tuple( KeyCodes::key_T, 0, (int)'t' ) );
00081                 typerCharSet.push_back( Int3Tuple( KeyCodes::key_U, 0, (int)'u' ) );
00082                 typerCharSet.push_back( Int3Tuple( KeyCodes::key_V, 0, (int)'v' ) );
00083                 typerCharSet.push_back( Int3Tuple( KeyCodes::key_W, 0, (int)'w' ) );
00084                 typerCharSet.push_back( Int3Tuple( KeyCodes::key_X, 0, (int)'x' ) );
00085                 typerCharSet.push_back( Int3Tuple( KeyCodes::key_Y, 0, (int)'y' ) );
00086                 typerCharSet.push_back( Int3Tuple( KeyCodes::key_Z, 0, (int)'z' ) );
00087                 typerCharSet.push_back( Int3Tuple( KeyCodes::key_0, 1, (int)')' ) );
00088                 typerCharSet.push_back( Int3Tuple( KeyCodes::key_1, 1, (int)'!' ) );
00089                 typerCharSet.push_back( Int3Tuple( KeyCodes::key_2, 1, (int)'@' ) );
00090                 typerCharSet.push_back( Int3Tuple( KeyCodes::key_3, 1, (int)'#' ) );
00091                 typerCharSet.push_back( Int3Tuple( KeyCodes::key_4, 1, (int)'$' ) );
00092                 typerCharSet.push_back( Int3Tuple( KeyCodes::key_5, 1, (int)'%' ) );
00093                 typerCharSet.push_back( Int3Tuple( KeyCodes::key_6, 1, (int)'^' ) );
00094                 typerCharSet.push_back( Int3Tuple( KeyCodes::key_7, 1, (int)'&' ) );
00095                 typerCharSet.push_back( Int3Tuple( KeyCodes::key_8, 1, (int)'*' ) );
00096                 typerCharSet.push_back( Int3Tuple( KeyCodes::key_9, 1, (int)'(' ) );
00097                 typerCharSet.push_back( Int3Tuple( KeyCodes::key_0, 0, (int)'0' ) );
00098                 typerCharSet.push_back( Int3Tuple( KeyCodes::key_1, 0, (int)'1' ) );
00099                 typerCharSet.push_back( Int3Tuple( KeyCodes::key_2, 0, (int)'2' ) );
00100                 typerCharSet.push_back( Int3Tuple( KeyCodes::key_3, 0, (int)'3' ) );
00101                 typerCharSet.push_back( Int3Tuple( KeyCodes::key_4, 0, (int)'4' ) );
00102                 typerCharSet.push_back( Int3Tuple( KeyCodes::key_5, 0, (int)'5' ) );
00103                 typerCharSet.push_back( Int3Tuple( KeyCodes::key_6, 0, (int)'6' ) );
00104                 typerCharSet.push_back( Int3Tuple( KeyCodes::key_7, 0, (int)'7' ) );
00105                 typerCharSet.push_back( Int3Tuple( KeyCodes::key_8, 0, (int)'8' ) );
00106                 typerCharSet.push_back( Int3Tuple( KeyCodes::key_9, 0, (int)'9' ) );
00107                 typerCharSet.push_back( Int3Tuple( KeyCodes::key_SPACE, 0, (int)' ' ) );
00108                 typerCharSet.push_back( Int3Tuple( KeyCodes::key_SPACE, 1, (int)' ' ) );
00109                 typerCharSet.push_back( Int3Tuple( KeyCodes::key_COMMA,   1, (int)'<' ) );
00110                 typerCharSet.push_back( Int3Tuple( KeyCodes::key_PERIOD,  1, (int)'>' ) );
00111                 typerCharSet.push_back( Int3Tuple( KeyCodes::key_COMMA,   0, (int)',' ) );
00112                 typerCharSet.push_back( Int3Tuple( KeyCodes::key_PERIOD,  0, (int)'.' ) );
00113                 typerCharSet.push_back( Int3Tuple( KeyCodes::key_SEMICOLON,  1, (int)':' ) );
00114                 typerCharSet.push_back( Int3Tuple( KeyCodes::key_SEMICOLON,  0, (int)';' ) );
00115                 typerCharSet.push_back( Int3Tuple( KeyCodes::key_MINUS,  1, (int)'_' ) );
00116                 typerCharSet.push_back( Int3Tuple( KeyCodes::key_MINUS,  0, (int)'-' ) );
00117                 typerCharSet.push_back( Int3Tuple( KeyCodes::key_EQUALS,  1, (int)'+' ) );
00118                 typerCharSet.push_back( Int3Tuple( KeyCodes::key_EQUALS,  0, (int)'-' ) );
00119                 typerCharSet.push_back( Int3Tuple( KeyCodes::key_APOSTROPHE,  1, (int)'"' ) );
00120                 typerCharSet.push_back( Int3Tuple( KeyCodes::key_APOSTROPHE,  0, (int)'\'' ) );
00121                 typerCharSet.push_back( Int3Tuple( KeyCodes::key_SLASH,  1, (int)'?' ) );
00122                 typerCharSet.push_back( Int3Tuple( KeyCodes::key_SLASH,  0, (int)'/' ) );
00123                 typerCharSet.push_back( Int3Tuple( KeyCodes::key_BACKSLASH,  1, (int)'|' ) );
00124                 typerCharSet.push_back( Int3Tuple( KeyCodes::key_BACKSLASH,  0, (int)'\\' ) );
00125                 typerCharSet.push_back( Int3Tuple( KeyCodes::key_LBRACKET,  1, (int)'{' ) );
00126                 typerCharSet.push_back( Int3Tuple( KeyCodes::key_LBRACKET,  0, (int)'[' ) );
00127                 typerCharSet.push_back( Int3Tuple( KeyCodes::key_RBRACKET,  1, (int)'}' ) );
00128                 typerCharSet.push_back( Int3Tuple( KeyCodes::key_RBRACKET,  0, (int)']' ) );
00129                 typerCharSet.push_back( Int3Tuple( 41,  1, (int)'~' ) );                // special keys : ~ , `
00130                 typerCharSet.push_back( Int3Tuple( 41,  0, (int)'`' ) );                //
00131         }
00132 
00133         m_string = initialString;
00134 }
00135 //------------------------------------------------------------------------------------
00136 string Typer::getString()
00137 {
00138         return m_string;
00139 }
00140 //------------------------------------------------------------------------------------
00141 void Typer::delLastChar()
00142 {
00143         if( m_string.size()>0 )
00144                 m_string = m_string.substr( 0, m_string.size()-1 );
00145 }
00146 //------------------------------------------------------------------------------------
00147 void Typer::input()
00148 {
00149         assert(typerCharSet.size() > 0);
00150         int shift = 0;
00151         if (input_isKeyDown(KeyCodes::key_LSHIFT) || input_isKeyDown(KeyCodes::key_RSHIFT))
00152                 shift = 1;
00153 
00154         for( int i=0; i<(int)typerCharSet.size(); i++ )
00155                 if( typerCharSet[i].b == shift )
00156                 {                       
00157                         int k = typerCharSet[i].a;                      // keycode to check             
00158                         if( input_isKeyPressed(k) )
00159                                 m_string += (char) typerCharSet[i].c;
00160                 }
00161 
00162         // deleting using BackSpace
00163         if( input_isKeyPressed(KeyCodes::key_BACK) )
00164         {
00165                 delLastChar();
00166                 m_lastDelMilliSec = sys_getMilliSec() + 400;            
00167         }
00168 
00169         if( input_isKeyDown(KeyCodes::key_BACK) && sys_getMilliSec() >= 90 + m_lastDelMilliSec )
00170         {
00171                 delLastChar();
00172                 m_lastDelMilliSec = sys_getMilliSec();
00173         }
00174 }
00175 //------------------------------------------------------------------------------------
00176 void Typer::clear()
00177 {
00178         m_string.clear();
00179 }
00180 //------------------------------------------------------------------------------------

Generated on Wed Apr 23 05:50:16 2003 for Modern Warfare by doxygen1.3-rc2