FIFE  2008.0
console.h
1 /***************************************************************************
2  * Copyright (C) 2005-2008 by the FIFE team *
3  * http://www.fifengine.de *
4  * This file is part of FIFE. *
5  * *
6  * FIFE is free software; you can redistribute it and/or *
7  * modify it under the terms of the GNU Lesser General Public *
8  * License as published by the Free Software Foundation; either *
9  * version 2.1 of the License, or (at your option) any later version. *
10  * *
11  * This library is distributed in the hope that it will be useful, *
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
14  * Lesser General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU Lesser General Public *
17  * License along with this library; if not, write to the *
18  * Free Software Foundation, Inc., *
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
20  ***************************************************************************/
21 
22 #ifndef FIFE_GUICHAN_ADDON_CONSOLE_H
23 #define FIFE_GUICHAN_ADDON_CONSOLE_H
24 
25 // Standard C++ library includes
26 #include <string>
27 
28 // 3rd party library includes
29 #include <guichan.hpp>
30 
31 // FIFE includes
32 // These includes are split up in two parts, separated by one empty line
33 // First block: files included from the FIFE root src directory
34 // Second block: files included from the same folder
35 #include "util/time/timer.h"
36 
37 namespace FIFE {
38 
39  class CommandLine;
40  class GuiFont;
41 
46  public:
49  virtual ~ConsoleExecuter() {}
50 
53  virtual void onToolsClick() = 0;
54 
58  virtual std::string onConsoleCommand(const std::string& command) = 0;
59  };
60 
61 
64  class Console : public gcn::Container, public gcn::ActionListener, public gcn::FocusListener {
65  public:
68  Console();
69 
72  virtual ~Console();
73 
76  void println(const std::string & s);
77 
83  void show();
84 
89  void hide();
90 
93  void clear();
94 
99  void toggleShowHide();
100 
109  void execute(std::string cmd);
110 
114  void updateCaption();
115 
119  void updateAnimation();
120 
123  void action(const gcn::ActionEvent & event);
124 
127  void setConsoleExecuter(ConsoleExecuter* const consoleexec);
128 
131  void removeConsoleExecuter();
132 
135  void reLayout();
136 
139  void setIOFont(GuiFont* font);
140 
143  void focusLost(const gcn::Event& event);
144  private:
145 
146  bool m_isAttached;
147  ConsoleExecuter* m_consoleexec;
148 
149  CommandLine* m_input;
150  gcn::TextBox* m_output;
151  gcn::ScrollArea* m_outputscrollarea;
152  gcn::Label* m_status;
153  gcn::Button* m_toolsbutton;
154  static const unsigned m_maxOutputRows;
155 
156  std::string m_prompt;
157 
158  int32_t m_hiddenPos;
159  int32_t m_animationDelta;
160 
161  bool m_hiding;
162 
163  Timer m_fpsTimer;
164  Timer m_animationTimer;
165 
166  void doShow();
167  void doHide();
168  };
169 }
170 #endif
171 /* vim: set noexpandtab: set shiftwidth=2: set tabstop=2: */
virtual void onToolsClick()=0
void setConsoleExecuter(ConsoleExecuter *const consoleexec)
Definition: console.cpp:289
virtual std::string onConsoleCommand(const std::string &command)=0
void execute(std::string cmd)
Definition: console.cpp:228
void hide()
Definition: console.cpp:214
void updateAnimation()
Definition: console.cpp:166
void setIOFont(GuiFont *font)
Definition: console.cpp:297
void removeConsoleExecuter()
Definition: console.cpp:293
void focusLost(const gcn::Event &event)
Definition: console.cpp:302
virtual ~ConsoleExecuter()
Definition: console.h:49
void println(const std::string &s)
Definition: console.cpp:251
void show()
Definition: console.cpp:206
void toggleShowHide()
Definition: console.cpp:221
virtual ~Console()
Definition: console.cpp:145
void updateCaption()
Definition: console.cpp:159
void reLayout()
Definition: console.cpp:90
void action(const gcn::ActionEvent &event)
Definition: console.cpp:281
credit to phoku for his NodeDisplay example which the visitor code is adapted from ( he coded the qua...
Definition: soundclip.cpp:39
void clear()
Definition: console.cpp:182