Debian Codegraph @

src/plan/KeyConsole.cpp

raw
1 /*
2 * Copyright (C) 2004 Ivo Danihelka ([email protected])
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 */
9 #include "KeyConsole.h"
10
11 #include "Font.h"
12 #include "ConsoleInput.h"
13
14 #include "Log.h"
15 #include "Name.h"
16 #include "StringMsg.h"
17 #include "MessagerAgent.h"
18 #include "BaseException.h"
19 #include "Path.h"
20
21 //-----------------------------------------------------------------
22 /**
23 * Console starts as deactivated.
24 */
25 KeyConsole::KeyConsole()
26 : m_color(0, 200, 0)
27 {
28 m_font = new Font(Path::dataReadPath("font/font_console.ttf"), 16);
29 takeHandler(new ConsoleInput(this));
30 registerDrawable(this);
31 }
32 //-----------------------------------------------------------------
33 KeyConsole::~KeyConsole()
34 {
35 delete m_font;
36 }
37 //-----------------------------------------------------------------
38 /**
39 * Send console input to scriptAgent.
40 * NOTE: debug script fail is not critical
41 * @return true for success
42 */
43 bool
44 KeyConsole::sendCommand()
45 {
46 bool result = false;
47 try {
48 StringMsg *msg = new StringMsg(Name::SCRIPT_NAME,
49 "dostring", m_input);
50 MessagerAgent::agent()->forwardNewMsg(msg);
51 result = true;
52 }
53 catch (BaseException &e) {
54 LOG_WARNING(e.info());
55 }
56 return result;
57 }
58 //-----------------------------------------------------------------
59 /**
60 * Draw console.
61 */
62 void
63 KeyConsole::drawOn(SDL_Surface *screen)
64 {
65 SDL_Rect rect;
66 rect.x = 10;
67 rect.y = 10;
68
69 SDL_Surface *surface = m_font->renderText("console] " + m_input, m_color);
70 SDL_BlitSurface(surface, NULL, screen, &rect);
71 SDL_FreeSurface(surface);
72 }
73