doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ConsoleDlg.cpp
Go to the documentation of this file.
1 /*
2 ===========================================================================
3 
4 Doom 3 GPL Source Code
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
6 
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
8 
9 Doom 3 Source Code is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13 
14 Doom 3 Source Code is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18 
19 You should have received a copy of the GNU General Public License
20 along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
21 
22 In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
23 
24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
25 
26 ===========================================================================
27 */
28 
29 #include "../../idlib/precompiled.h"
30 #pragma hdrstop
31 
32 #include "qe3.h"
33 #include "Radiant.h"
34 #include "ConsoleDlg.h"
35 
36 
37 // CConsoleDlg dialog
38 
40 CConsoleDlg::CConsoleDlg(CWnd* pParent /*=NULL*/)
41  : CDialog(CConsoleDlg::IDD)
42 {
43  currentHistoryPosition = -1;
44  currentCommand = "";
45  saveCurrentCommand = true;
46 }
47 
49 {
50 }
51 
52 void CConsoleDlg::DoDataExchange(CDataExchange* pDX)
53 {
54  CDialog::DoDataExchange(pDX);
55  DDX_Control(pDX, IDC_EDIT_CONSOLE, editConsole);
56  DDX_Control(pDX, IDC_EDIT_INPUT, editInput);
57 }
58 
59 void CConsoleDlg::AddText( const char *msg ) {
60  idStr work;
61  CString work2;
62 
63  work = msg;
64  work.RemoveColors();
65  work = CEntityDlg::TranslateString( work.c_str() );
66  editConsole.GetWindowText( work2 );
67  int len = work2.GetLength();
68  if ( len + work.Length() > (int)editConsole.GetLimitText() ) {
69  work2 = work2.Right( editConsole.GetLimitText() * 0.75 );
70  len = work2.GetLength();
71  editConsole.SetWindowText(work2);
72  }
73  editConsole.SetSel( len, len );
74  editConsole.ReplaceSel( work );
75 }
76 
77 
78 BEGIN_MESSAGE_MAP(CConsoleDlg, CDialog)
79  ON_WM_SIZE()
80  ON_WM_SETFOCUS()
81  ON_WM_ACTIVATE()
82 END_MESSAGE_MAP()
83 
84 
85 // CConsoleDlg message handlers
86 
87 void CConsoleDlg::OnSize(UINT nType, int cx, int cy)
88 {
89  CDialog::OnSize(nType, cx, cy);
90 
91  if (editInput.GetSafeHwnd() == NULL) {
92  return;
93  }
94 
95  CRect rect, crect;
96  GetWindowRect(rect);
97  editInput.GetWindowRect(crect);
98 
99  editInput.SetWindowPos(NULL, 4, rect.Height() - 4 - crect.Height(), rect.Width() - 8, crect.Height(), SWP_SHOWWINDOW);
100  editConsole.SetWindowPos(NULL, 4, 4, rect.Width() - 8, rect.Height() - crect.Height() - 8, SWP_SHOWWINDOW);
101 }
102 
104 {
105 
106  if (pMsg->hwnd == editInput.GetSafeHwnd()) {
107  if (pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_ESCAPE ) {
108  Select_Deselect();
109  g_pParentWnd->SetFocus ();
110  return TRUE;
111  }
112 
113  if (pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_RETURN ) {
114  ExecuteCommand();
115  return TRUE;
116  }
117 
118  if (pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_ESCAPE ) {
119  if (pMsg->wParam == VK_ESCAPE) {
120  g_pParentWnd->GetCamera()->SetFocus();
121  Select_Deselect();
122  }
123 
124  return TRUE;
125  }
126 
127  if (pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_UP ) {
128  //save off the current in-progress command so we can get back to it
129  if ( saveCurrentCommand == true ) {
130  CString str;
131  editInput.GetWindowText ( str );
132  currentCommand = str.GetBuffer ( 0 );
133  saveCurrentCommand = false;
134  }
135 
136  if ( consoleHistory.Num () > 0 ) {
138 
139  int selLocation = consoleHistory[currentHistoryPosition].Length ();
140  editInput.SetSel ( selLocation , selLocation + 1);
141 }
142 
143  if ( currentHistoryPosition > 0) {
145  }
146 
147  return TRUE;
148  }
149 
150  if (pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_DOWN ) {
151  int selLocation = 0;
152  if ( currentHistoryPosition < consoleHistory.Num () - 1 ) {
155  selLocation = consoleHistory[currentHistoryPosition].Length ();
156  }
157  else {
158  editInput.SetWindowText ( currentCommand );
159  selLocation = currentCommand.Length ();
161  saveCurrentCommand = true;
162  }
163 
164  editInput.SetSel ( selLocation , selLocation + 1);
165 
166  return TRUE;
167  }
168  if (pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_TAB ) {
169  common->Printf ( "Command History\n----------------\n" );
170  for ( int i = 0 ; i < consoleHistory.Num ();i++ )
171 {
172  common->Printf ( "[cmd %d]: %s\n" , i , consoleHistory[i].c_str() );
173  }
174  common->Printf ( "----------------\n" );
175  }
176  if (pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_NEXT) {
177  editConsole.LineScroll ( 10 );
178  }
179 
180  if (pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_PRIOR ) {
181  editConsole.LineScroll ( -10 );
182  }
183 
184  if (pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_HOME ) {
185  editConsole.LineScroll ( -editConsole.GetLineCount() );
186  }
187 
188  if (pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_END ) {
189  editConsole.LineScroll ( editConsole.GetLineCount() );
190  }
191  }
192 
193  return CDialog::PreTranslateMessage(pMsg);
194 }
195 
196 void CConsoleDlg::OnSetFocus(CWnd* pOldWnd) {
197  CDialog::OnSetFocus(pOldWnd);
198  editInput.SetFocus();
199 }
200 
201 void CConsoleDlg::SetConsoleText ( const idStr& text ) {
202  editInput.Clear ();
203  editInput.SetWindowText ( text.c_str() );
204 }
205 
206 void CConsoleDlg::ExecuteCommand ( const idStr& cmd ) {
207  CString str;
208  if ( cmd.Length() > 0 ) {
209  str = cmd;
210  }
211  else {
212  editInput.GetWindowText(str);
213  }
214 
215  if ( str != "" ) {
216  editInput.SetWindowText("");
217  common->Printf("%s\n", str.GetBuffer(0));
218 
219  //avoid adding multiple identical commands in a row
220  int index = consoleHistory.Num ();
221 
222  if ( index == 0 || str.GetBuffer(0) != consoleHistory[index-1]) {
223  //keep the history to 16 commands, removing the oldest command
224  if ( consoleHistory.Num () > 16 ) {
226  }
227  currentHistoryPosition = consoleHistory.Append ( str.GetBuffer (0) );
228  }
229  else {
231  }
232 
234 
235  bool propogateCommand = true;
236 
237  //process some of our own special commands
238  if ( str.CompareNoCase ( "clear" ) == 0) {
239  editConsole.SetSel ( 0 , -1 );
240  editConsole.Clear ();
241  }
242  else if ( str.CompareNoCase ( "edit" ) == 0) {
243  propogateCommand = false;
244  }
245  if ( propogateCommand ) {
247  }
248 
249  Sys_UpdateWindows(W_ALL);
250  }
251 }
252 
253 void CConsoleDlg::OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized)
254 {
255  CDialog::OnActivate(nState, pWndOther, bMinimized);
256 
257  if ( nState == WA_ACTIVE || nState == WA_CLICKACTIVE )
258  {
259  editInput.SetFocus();
260  }
261 }
CMainFrame * g_pParentWnd
Definition: MainFrm.cpp:73
CEdit editConsole
Definition: ConsoleDlg.h:50
void WINAPI Sys_UpdateWindows(int nBits)
Definition: MainFrm.cpp:3974
virtual void DoDataExchange(CDataExchange *pDX)
Definition: ConsoleDlg.cpp:52
idStr currentCommand
Definition: ConsoleDlg.h:58
static const char * TranslateString(const char *p)
Definition: EntityDlg.cpp:285
CONST PIXELFORMATDESCRIPTOR UINT
Definition: win_qgl.cpp:47
int Length(void) const
Definition: Str.h:702
#define IDC_EDIT_CONSOLE
case const int
Definition: Callbacks.cpp:52
idCmdSystem * cmdSystem
Definition: CmdSystem.cpp:116
GLenum GLsizei len
Definition: glext.h:3472
int i
Definition: process.py:33
#define BOOL
Definition: mprintf.c:71
bool saveCurrentCommand
Definition: ConsoleDlg.h:60
virtual void BufferCommandText(cmdExecution_t exec, const char *text)=0
#define IDC_EDIT_INPUT
CCamWnd * GetCamera()
Definition: MainFrm.h:123
CEdit editInput
Definition: ConsoleDlg.h:51
GLuint index
Definition: glext.h:3476
virtual ~CConsoleDlg()
Definition: ConsoleDlg.cpp:48
afx_msg void OnSetFocus(CWnd *pOldWnd)
Definition: ConsoleDlg.cpp:196
idCommon * common
Definition: Common.cpp:206
#define NULL
Definition: Lib.h:88
void ExecuteCommand(const idStr &cmd="")
Definition: ConsoleDlg.cpp:206
void Clear(void)
Definition: Str.h:724
idStr & RemoveColors(void)
Definition: Str.h:849
virtual void Printf(const char *fmt,...) id_attribute((format(printf
int Append(const type &obj)
Definition: List.h:646
IMPLEMENT_DYNCREATE(CCamWnd, CWnd)
int Num(void) const
Definition: List.h:265
bool RemoveIndex(int index)
Definition: List.h:849
int currentHistoryPosition
Definition: ConsoleDlg.h:59
Definition: Str.h:116
const char * c_str(void) const
Definition: Str.h:487
afx_msg void OnActivate(UINT nState, CWnd *pWndOther, BOOL bMinimized)
Definition: ConsoleDlg.cpp:253
#define TRUE
Definition: mprintf.c:69
virtual BOOL PreTranslateMessage(MSG *pMsg)
Definition: ConsoleDlg.cpp:103
idStrList consoleHistory
Definition: ConsoleDlg.h:57
void SetConsoleText(const idStr &text)
Definition: ConsoleDlg.cpp:201
void AddText(const char *msg)
Definition: ConsoleDlg.cpp:59