Mercurial > fife-parpg
comparison engine/core/gui/guichan/commandline.cpp @ 697:ecaa4d98f05f tip
Abstracted the GUI code and refactored the GUIChan-specific code into its own module.
* Most of the GUIChan code has been refactored into its own gui/guichan module. However, references to the GuiFont class still persist in the Engine and GuiManager code and these will need further refactoring.
* GuiManager is now an abstract base class which specific implementations (e.g. GUIChan) should subclass.
* The GUIChan GUI code is now a concrete implementation of GuiManager, most of which is in the new GuiChanGuiManager class.
* The GUI code in the Console class has been refactored out of the Console and into the GUIChan module as its own GuiChanConsoleWidget class. The rest of the Console class related to executing commands was left largely unchanged.
* Existing client code may need to downcast the GuiManager pointer received from FIFE::Engine::getGuiManager() to GuiChanGuiManager, since not all functionality is represented in the GuiManager abstract base class. Python client code can use the new GuiChanGuiManager.castTo static method for this purpose.
author | M. George Hansen <technopolitica@gmail.com> |
---|---|
date | Sat, 18 Jun 2011 00:28:40 -1000 |
parents | engine/core/gui/console/commandline.cpp@64738befdf3b |
children |
comparison
equal
deleted
inserted
replaced
696:e201abd8c807 | 697:ecaa4d98f05f |
---|---|
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 // Standard C++ library includes | |
23 #include <cassert> | |
24 | |
25 // 3rd party library includes | |
26 #include <boost/bind.hpp> | |
27 | |
28 // FIFE includes | |
29 // These includes are split up in two parts, separated by one empty line | |
30 // First block: files included from the FIFE root src directory | |
31 // Second block: files included from the same folder | |
32 #include "util/time/timeevent.h" | |
33 #include "util/time/timemanager.h" | |
34 | |
35 #include "commandline.h" | |
36 | |
37 namespace FIFE { | |
38 using namespace gcn; | |
39 | |
40 | |
41 CommandLine::CommandLine() : gcn::UTF8TextField(), m_history_position(0) { | |
42 | |
43 m_blinkTimer.setInterval(500); | |
44 m_blinkTimer.setCallback(boost::bind(&CommandLine::toggleCaretVisible,this)); | |
45 m_blinkTimer.start(); | |
46 | |
47 m_suppressBlinkTimer.setInterval(2000); | |
48 m_suppressBlinkTimer | |
49 .setCallback(boost::bind(&CommandLine::startBlinking,this)); | |
50 } | |
51 | |
52 CommandLine::~CommandLine() { | |
53 } | |
54 | |
55 void CommandLine::toggleCaretVisible() { | |
56 m_caretVisible = !m_caretVisible; | |
57 } | |
58 | |
59 void CommandLine::stopBlinking() { | |
60 m_suppressBlinkTimer.start(); | |
61 m_blinkTimer.stop(); | |
62 m_caretVisible = true; | |
63 } | |
64 | |
65 void CommandLine::startBlinking() { | |
66 m_suppressBlinkTimer.stop(); | |
67 m_blinkTimer.start(); | |
68 } | |
69 | |
70 void CommandLine::keyPressed(gcn::KeyEvent &keyEvent) { | |
71 gcn::Key key = keyEvent.getKey(); | |
72 int keyType = key.getValue(); | |
73 | |
74 if (keyType == Key::LEFT && mCaretPosition > 0) | |
75 { | |
76 UTF8TextField::keyPressed(keyEvent); | |
77 } | |
78 else if (keyType == Key::RIGHT && mCaretPosition < mText.size()) | |
79 { | |
80 UTF8TextField::keyPressed(keyEvent); | |
81 } | |
82 else if (keyType == Key::DOWN && !m_history.empty()) | |
83 { | |
84 if( m_history_position < m_history.size() ) { | |
85 | |
86 if( ++m_history_position == m_history.size() ) { | |
87 setText( m_cmdline ); | |
88 } else { | |
89 setText( m_history[m_history_position] ); | |
90 } | |
91 }; | |
92 } | |
93 else if (keyType == Key::UP && !m_history.empty()) | |
94 { | |
95 if( m_history_position > 0 ) { | |
96 if( m_history_position == m_history.size() ) { | |
97 m_cmdline = mText; | |
98 } | |
99 --m_history_position; | |
100 setText( m_history[m_history_position] ); | |
101 }; | |
102 } | |
103 else if (keyType == Key::DELETE && mCaretPosition < mText.size()) | |
104 { | |
105 UTF8TextField::keyPressed(keyEvent); | |
106 } | |
107 else if (keyType == Key::BACKSPACE && mCaretPosition > 0) | |
108 { | |
109 UTF8TextField::keyPressed(keyEvent); | |
110 } | |
111 else if (keyType == Key::ENTER) | |
112 { | |
113 if( mText != "" ) { | |
114 if(m_callback) { | |
115 m_callback( mText ); | |
116 } | |
117 m_history.push_back( mText ); | |
118 m_history_position = m_history.size(); | |
119 setText(""); | |
120 } | |
121 } | |
122 else if (keyType == Key::HOME) | |
123 { | |
124 mCaretPosition = 0; | |
125 } | |
126 else if (keyType == Key::END) | |
127 { | |
128 mCaretPosition = mText.size(); | |
129 } | |
130 else if (key.isCharacter()) | |
131 { | |
132 UTF8TextField::keyPressed(keyEvent); | |
133 } | |
134 stopBlinking(); | |
135 fixScroll(); | |
136 } | |
137 | |
138 void CommandLine::drawCaret(gcn::Graphics * graphics, int x) { | |
139 if( !m_caretVisible ) | |
140 return; | |
141 | |
142 graphics->setColor(getForegroundColor()); | |
143 graphics->drawLine(x, getHeight() - 2, x, 1); | |
144 graphics->drawLine(x+1, getHeight() - 2, x+1, 1); | |
145 } | |
146 | |
147 | |
148 void CommandLine::setCallback(const type_callback& cb) { | |
149 m_callback = cb; | |
150 } | |
151 | |
152 } | |
153 /* vim: set noexpandtab: set shiftwidth=2: set tabstop=2: */ |