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

KeyConsole.cpp

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2004 Ivo Danihelka (ivo@danihelka.net)
00003  *
00004  * This program is free software; you can redistribute it and/or modify
00005  * it under the terms of the GNU General Public License as published by
00006  * the Free Software Foundation; either version 2 of the License, or
00007  * (at your option) any later version.
00008  */
00009 #include "KeyConsole.h"
00010 
00011 #include "Font.h"
00012 #include "ConsoleInput.h"
00013 
00014 #include "Log.h"
00015 #include "Name.h"
00016 #include "StringMsg.h"
00017 #include "MessagerAgent.h"
00018 #include "BaseException.h"
00019 #include "Path.h"
00020 
00021 //-----------------------------------------------------------------
00022 /**
00023  * Console starts as deactivated.
00024  */
00025     KeyConsole::KeyConsole()
00026 :  m_color(0, 200, 0)
00027 {
00028     m_font = new Font(Path::dataReadPath("font/font_console.ttf"), 16);
00029     takeHandler(new ConsoleInput(this));
00030     registerDrawable(this);
00031 }
00032 //-----------------------------------------------------------------
00033 KeyConsole::~KeyConsole()
00034 {
00035     delete m_font;
00036 }
00037 //-----------------------------------------------------------------
00038 /**
00039  * Send console input to scriptAgent.
00040  * NOTE: debug script fail is not critical
00041  * @return true for success
00042  */
00043 bool
00044 KeyConsole::sendCommand()
00045 {
00046     bool result = false;
00047     try {
00048         StringMsg *msg = new StringMsg(Name::SCRIPT_NAME,
00049                 "dostring", m_input);
00050         MessagerAgent::agent()->forwardNewMsg(msg);
00051         result = true;
00052     }
00053     catch (BaseException &e) {
00054         LOG_WARNING(e.info());
00055     }
00056     return result;
00057 }
00058 //-----------------------------------------------------------------
00059 /**
00060  * Draw console.
00061  */
00062     void
00063 KeyConsole::drawOn(SDL_Surface *screen)
00064 {
00065     SDL_Rect rect;
00066     rect.x = 10;
00067     rect.y = 10;
00068 
00069     SDL_Surface *surface = m_font->renderText("console] " + m_input, m_color);
00070     SDL_BlitSurface(surface, NULL, screen, &rect);
00071     SDL_FreeSurface(surface);
00072 }
00073 

Generated on Wed Jun 1 09:54:31 2005 for Fish Fillets - Next Generation by  doxygen 1.4.2