Pyrogenesis  13997
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CConsole.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2013 Wildfire Games.
2  * This file is part of 0 A.D.
3  *
4  * 0 A.D. 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  * 0 A.D. is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 /*
19  * Implements the in-game console with scripting support.
20  */
21 
22 #include "precompiled.h"
23 #include <wctype.h>
24 
25 #include "CConsole.h"
26 
27 #include "graphics/ShaderManager.h"
28 #include "graphics/TextRenderer.h"
29 #include "gui/GUIutil.h"
30 #include "lib/ogl.h"
31 #include "lib/sysdep/clipboard.h"
32 #include "lib/timer.h"
33 #include "maths/MathUtil.h"
34 #include "network/NetClient.h"
35 #include "network/NetServer.h"
36 #include "ps/CLogger.h"
37 #include "ps/Filesystem.h"
38 #include "ps/Font.h"
39 #include "ps/Globals.h"
40 #include "ps/Hotkey.h"
41 #include "ps/Pyrogenesis.h"
42 #include "renderer/Renderer.h"
45 
47 
49 {
50  m_bToggle = false;
51  m_bVisible = false;
52 
53  m_fVisibleFrac = 0.0f;
54 
55  m_szBuffer = new wchar_t[CONSOLE_BUFFER_SIZE];
56  FlushBuffer();
57 
58  m_iMsgHistPos = 1;
59  m_charsPerPage = 0;
60 
61  m_prevTime = 0.0;
62  m_bCursorVisState = true;
63  m_cursorBlinkRate = 0.5;
64 
65  InsertMessage(L"[ 0 A.D. Console v0.14 ]");
66  InsertMessage(L"");
67 }
68 
70 {
71  delete[] m_szBuffer;
72 }
73 
74 
75 void CConsole::SetSize(float X, float Y, float W, float H)
76 {
77  m_fX = X;
78  m_fY = Y;
79  m_fWidth = W;
80  m_fHeight = H;
81 }
82 
83 void CConsole::UpdateScreenSize(int w, int h)
84 {
85  float height = h * 0.6f;
86  SetSize(0, 0, (float)w, height);
87 }
88 
89 
91 {
92  m_bToggle = true;
94 }
95 
96 void CConsole::SetVisible(bool visible)
97 {
98  if (visible != m_bVisible)
99  m_bToggle = true;
100  m_bVisible = visible;
101  if (visible)
102  {
103  m_prevTime = 0.0;
104  m_bCursorVisState = false;
105  }
106 }
107 
109 {
110  m_cursorBlinkRate = rate;
111 }
112 
114 {
115  // Clear the buffer and set the cursor and length to 0
116  memset(m_szBuffer, '\0', sizeof(wchar_t) * CONSOLE_BUFFER_SIZE);
118 }
119 
120 
121 void CConsole::ToLower(wchar_t* szMessage, size_t iSize)
122 {
123  size_t L = (size_t)wcslen(szMessage);
124 
125  if (L <= 0) return;
126 
127  if (iSize && iSize < L) L = iSize;
128 
129  for(size_t i = 0; i < L; i++)
130  szMessage[i] = towlower(szMessage[i]);
131 }
132 
133 
134 void CConsole::Trim(wchar_t* szMessage, const wchar_t cChar, size_t iSize)
135 {
136  size_t L = wcslen(szMessage);
137  if(!L)
138  return;
139 
140  if (iSize && iSize < L) L = iSize;
141 
142  wchar_t szChar[2] = { cChar, 0 };
143 
144  // Find the first point at which szChar does not
145  // exist in the message
146  size_t ofs = wcsspn(szMessage, szChar);
147  if(ofs == 0) // no leading <cChar> chars - we're done
148  return;
149 
150  // move everything <ofs> chars left, replacing leading cChar chars
151  L -= ofs;
152  memmove(szMessage, szMessage+ofs, L*sizeof(wchar_t));
153 
154  for(ssize_t i = (ssize_t)L; i >= 0; i--)
155  {
156  szMessage[i] = '\0';
157  if (szMessage[i - 1] != cChar) break;
158  }
159 }
160 
161 
162 void CConsole::Update(const float deltaRealTime)
163 {
164  if(m_bToggle)
165  {
166  const float AnimateTime = .30f;
167  const float Delta = deltaRealTime / AnimateTime;
168  if(m_bVisible)
169  {
170  m_fVisibleFrac += Delta;
171  if(m_fVisibleFrac > 1.0f)
172  {
173  m_fVisibleFrac = 1.0f;
174  m_bToggle = false;
175  }
176  }
177  else
178  {
179  m_fVisibleFrac -= Delta;
180  if(m_fVisibleFrac < 0.0f)
181  {
182  m_fVisibleFrac = 0.0f;
183  m_bToggle = false;
184  }
185  }
186  }
187 }
188 
189 //Render Manager.
191 {
192  if (! (m_bVisible || m_bToggle) ) return;
193 
194  PROFILE3_GPU("console");
195 
196  glEnable(GL_BLEND);
197  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
198 
199  CShaderTechniquePtr solidTech = g_Renderer.GetShaderManager().LoadEffect(str_gui_solid);
200  solidTech->BeginPass();
201  CShaderProgramPtr solidShader = solidTech->GetShader();
202 
203  CMatrix3D transform = GetDefaultGuiMatrix();
204 
205  // animation: slide in from top of screen
206  const float DeltaY = (1.0f - m_fVisibleFrac) * m_fHeight;
207  transform.PostTranslate(m_fX, m_fY - DeltaY, 0.0f); // move to window position
208  solidShader->Uniform(str_transform, transform);
209 
210  DrawWindow(solidShader);
211 
212  solidTech->EndPass();
213 
214  CShaderTechniquePtr textTech = g_Renderer.GetShaderManager().LoadEffect(str_gui_text);
215  textTech->BeginPass();
216  CTextRenderer textRenderer(textTech->GetShader());
217  textRenderer.Font(CONSOLE_FONT);
218  textRenderer.SetTransform(transform);
219 
220  DrawHistory(textRenderer);
221  DrawBuffer(textRenderer);
222 
223  textRenderer.Render();
224 
225  textTech->EndPass();
226 
227  glDisable(GL_BLEND);
228 }
229 
230 
232 {
233  float boxVerts[] = {
234  m_fWidth, 0.0f,
235  1.0f, 0.0f,
236  1.0f, m_fHeight-1.0f,
237  m_fWidth, m_fHeight-1.0f
238  };
239 
240  shader->VertexPointer(2, GL_FLOAT, 0, boxVerts);
241 
242  // Draw Background
243  // Set the color to a translucent blue
244  shader->Uniform(str_color, 0.0f, 0.0f, 0.5f, 0.6f);
245  shader->AssertPointersBound();
246  glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
247 
248  // Draw Border
249  // Set the color to a translucent yellow
250  shader->Uniform(str_color, 0.5f, 0.5f, 0.0f, 0.6f);
251  shader->AssertPointersBound();
252  glDrawArrays(GL_LINE_LOOP, 0, 4);
253 
254  if (m_fHeight > m_iFontHeight + 4)
255  {
256  float lineVerts[] = {
257  0.0f, m_fHeight - (float)m_iFontHeight - 4.0f,
258  m_fWidth, m_fHeight - (float)m_iFontHeight - 4.0f
259  };
260  shader->VertexPointer(2, GL_FLOAT, 0, lineVerts);
261  shader->AssertPointersBound();
262  glDrawArrays(GL_LINES, 0, 2);
263  }
264 }
265 
266 
268 {
269  int i = 1;
270 
271  std::deque<std::wstring>::iterator Iter; //History iterator
272 
273  CScopeLock lock(m_Mutex); // needed for safe access to m_deqMsgHistory
274 
275  textRenderer.Color(1.0f, 1.0f, 1.0f);
276 
277  for (Iter = m_deqMsgHistory.begin();
278  Iter != m_deqMsgHistory.end()
279  && (((i - m_iMsgHistPos + 1) * m_iFontHeight) < m_fHeight);
280  ++Iter)
281  {
282  if (i >= m_iMsgHistPos)
283  textRenderer.Put(9.0f, m_fHeight - (float)m_iFontOffset - (float)m_iFontHeight * (i - m_iMsgHistPos + 1), Iter->c_str());
284 
285  i++;
286  }
287 }
288 
289 // Renders the buffer to the screen.
291 {
292  if (m_fHeight < m_iFontHeight)
293  return;
294 
295  CMatrix3D savedTransform = textRenderer.GetTransform();
296 
297  textRenderer.Translate(2.0f, m_fHeight - (float)m_iFontOffset + 1.0f, 0.0f);
298 
299  textRenderer.Color(1.0f, 1.0f, 0.0f);
300  textRenderer.PutAdvance(L"]");
301 
302  textRenderer.Color(1.0f, 1.0f, 1.0f);
303 
304  if (m_iBufferPos == 0)
305  DrawCursor(textRenderer);
306 
307  for (int i = 0; i < m_iBufferLength; i++)
308  {
309  textRenderer.PrintfAdvance(L"%lc", m_szBuffer[i]);
310  if (m_iBufferPos-1 == i)
311  DrawCursor(textRenderer);
312  }
313 
314  textRenderer.SetTransform(savedTransform);
315 }
316 
318 {
319  if (m_cursorBlinkRate > 0.0)
320  {
321  // check if the cursor visibility state needs to be changed
322  double currTime = timer_Time();
323  if ((currTime - m_prevTime) >= m_cursorBlinkRate)
324  {
326  m_prevTime = currTime;
327  }
328  }
329  else
330  {
331  // Should always be visible
332  m_bCursorVisState = true;
333  }
334 
336  {
337  // Slightly translucent yellow
338  textRenderer.Color(1.0f, 1.0f, 0.0f, 0.8f);
339 
340  // Cursor character is chosen to be an underscore
341  textRenderer.Put(0.0f, 0.0f, L"_");
342 
343  // Revert to the standard text colour
344  textRenderer.Color(1.0f, 1.0f, 1.0f);
345  }
346 }
347 
348 
349 //Inserts a character into the buffer.
350 void CConsole::InsertChar(const int szChar, const wchar_t cooked)
351 {
352  static int iHistoryPos = -1;
353 
354  if (!m_bVisible) return;
355 
356  switch (szChar){
357  case SDLK_RETURN:
358  iHistoryPos = -1;
359  m_iMsgHistPos = 1;
361  FlushBuffer();
362  return;
363 
364  case SDLK_TAB:
365  // Auto Complete
366  return;
367 
368  case SDLK_BACKSPACE:
369  if (IsEmpty() || IsBOB()) return;
370 
372  m_szBuffer[m_iBufferPos - 1] = '\0';
373  else
374  {
375  for (int j = m_iBufferPos-1; j < m_iBufferLength-1; j++)
376  m_szBuffer[j] = m_szBuffer[j+1]; // move chars to left
377  m_szBuffer[m_iBufferLength-1] = '\0';
378  }
379 
380  m_iBufferPos--;
381  m_iBufferLength--;
382  return;
383 
384  case SDLK_DELETE:
385  if (IsEmpty() || IsEOB()) return;
386 
387  if (m_iBufferPos == m_iBufferLength-1)
388  {
389  m_szBuffer[m_iBufferPos] = '\0';
390  m_iBufferLength--;
391  }
392  else
393  {
394  if (g_keys[SDLK_RCTRL] || g_keys[SDLK_LCTRL])
395  {
396  // Make Ctrl-Delete delete up to end of line
397  m_szBuffer[m_iBufferPos] = '\0';
399  }
400  else
401  {
402  // Delete just one char and move the others left
403  for(int j=m_iBufferPos; j<m_iBufferLength-1; j++)
404  m_szBuffer[j] = m_szBuffer[j+1];
405  m_szBuffer[m_iBufferLength-1] = '\0';
406  m_iBufferLength--;
407  }
408  }
409 
410  return;
411 
412  case SDLK_HOME:
413  if (g_keys[SDLK_RCTRL] || g_keys[SDLK_LCTRL])
414  {
415  CScopeLock lock(m_Mutex); // needed for safe access to m_deqMsgHistory
416 
417  int linesShown = (int)m_fHeight/m_iFontHeight - 4;
418  m_iMsgHistPos = clamp((int)m_deqMsgHistory.size() - linesShown, 1, (int)m_deqMsgHistory.size());
419  }
420  else
421  {
422  m_iBufferPos = 0;
423  }
424  return;
425 
426  case SDLK_END:
427  if (g_keys[SDLK_RCTRL] || g_keys[SDLK_LCTRL])
428  {
429  m_iMsgHistPos = 1;
430  }
431  else
432  {
434  }
435  return;
436 
437  case SDLK_LEFT:
438  if (m_iBufferPos) m_iBufferPos--;
439  return;
440 
441  case SDLK_RIGHT:
443  return;
444 
445  // BEGIN: Buffer History Lookup
446  case SDLK_UP:
447  if (m_deqBufHistory.size() && iHistoryPos != (int)m_deqBufHistory.size() - 1)
448  {
449  iHistoryPos++;
450  SetBuffer(m_deqBufHistory.at(iHistoryPos).c_str());
452  }
453  return;
454 
455  case SDLK_DOWN:
456  if (m_deqBufHistory.size())
457  {
458  if (iHistoryPos > 0)
459  {
460  iHistoryPos--;
461  SetBuffer(m_deqBufHistory.at(iHistoryPos).c_str());
463  }
464  else if (iHistoryPos == 0)
465  {
466  iHistoryPos--;
467  FlushBuffer();
468  }
469  }
470  return;
471  // END: Buffer History Lookup
472 
473  // BEGIN: Message History Lookup
474  case SDLK_PAGEUP:
475  {
476  CScopeLock lock(m_Mutex); // needed for safe access to m_deqMsgHistory
477 
478  if (m_iMsgHistPos != (int)m_deqMsgHistory.size()) m_iMsgHistPos++;
479  return;
480  }
481 
482  case SDLK_PAGEDOWN:
483  if (m_iMsgHistPos != 1) m_iMsgHistPos--;
484  return;
485  // END: Message History Lookup
486 
487  default: //Insert a character
488  if (IsFull()) return;
489  if (cooked == 0) return;
490 
491  if (IsEOB()) //are we at the end of the buffer?
492  m_szBuffer[m_iBufferPos] = cooked; //cat char onto end
493  else{ //we need to insert
494  int i;
495  for(i=m_iBufferLength; i>m_iBufferPos; i--)
496  m_szBuffer[i] = m_szBuffer[i-1]; // move chars to right
497  m_szBuffer[i] = cooked;
498  }
499 
500  m_iBufferPos++;
501  m_iBufferLength++;
502 
503  return;
504  }
505 }
506 
507 
508 void CConsole::InsertMessage(const wchar_t* szMessage, ...)
509 {
510  va_list args;
511  wchar_t szBuffer[CONSOLE_MESSAGE_SIZE];
512 
513  va_start(args, szMessage);
514  if (vswprintf(szBuffer, CONSOLE_MESSAGE_SIZE, szMessage, args) == -1)
515  {
516  debug_printf(L"Error printfing console message (buffer size exceeded?)\n");
517 
518  // Make it obvious that the text was trimmed (assuming it was)
519  wcscpy(szBuffer+CONSOLE_MESSAGE_SIZE-4, L"...");
520  }
521  va_end(args);
522 
523  InsertMessageRaw(szBuffer);
524 }
525 
526 
527 void CConsole::InsertMessageRaw(const CStrW& message)
528 {
529  // (TODO: this text-wrapping is rubbish since we now use variable-width fonts)
530 
531  //Insert newlines to wraparound text where needed
532  CStrW wrapAround(message);
533  CStrW newline(L"\n");
534  size_t oldNewline=0;
535  size_t distance;
536 
537  //make sure everything has been initialized
538  if ( m_charsPerPage != 0 )
539  {
540  while ( oldNewline+m_charsPerPage < wrapAround.length() )
541  {
542  distance = wrapAround.find(newline, oldNewline) - oldNewline;
543  if ( distance > m_charsPerPage )
544  {
545  oldNewline += m_charsPerPage;
546  wrapAround.insert( oldNewline++, newline );
547  }
548  else
549  oldNewline += distance+1;
550  }
551  }
552  // Split into lines and add each one individually
553  oldNewline = 0;
554 
555  {
556  CScopeLock lock(m_Mutex); // needed for safe access to m_deqMsgHistory
557 
558  while ( (distance = wrapAround.find(newline, oldNewline)) != wrapAround.npos)
559  {
560  distance -= oldNewline;
561  m_deqMsgHistory.push_front(wrapAround.substr(oldNewline, distance));
562  oldNewline += distance+1;
563  }
564  m_deqMsgHistory.push_front(wrapAround.substr(oldNewline));
565  }
566 }
567 
568 const wchar_t* CConsole::GetBuffer()
569 {
571  return( m_szBuffer );
572 }
573 
574 void CConsole::SetBuffer(const wchar_t* szMessage)
575 {
576  int oldBufferPos = m_iBufferPos; // remember since FlushBuffer will set it to 0
577 
578  FlushBuffer();
579 
580  wcsncpy(m_szBuffer, szMessage, CONSOLE_BUFFER_SIZE);
582  m_iBufferLength = (int)wcslen(m_szBuffer);
583  m_iBufferPos = std::min(oldBufferPos, m_iBufferLength);
584 }
585 
586 void CConsole::UseHistoryFile(const VfsPath& filename, int max_history_lines)
587 {
588  m_MaxHistoryLines = max_history_lines;
589 
590  m_sHistoryFile = filename;
591  LoadHistory();
592 }
593 
594 void CConsole::ProcessBuffer(const wchar_t* szLine)
595 {
596  if (szLine == NULL) return;
597  if (wcslen(szLine) <= 0) return;
598 
599  ENSURE(wcslen(szLine) < CONSOLE_BUFFER_SIZE);
600 
601  m_deqBufHistory.push_front(szLine);
602  SaveHistory(); // Do this each line for the moment; if a script causes
603  // a crash it's a useful record.
604 
605  // Process it as JavaScript
606 
607  jsval rval = g_ScriptingHost.ExecuteScript(szLine, L"Console");
608  if (!JSVAL_IS_VOID(rval))
609  InsertMessage(L"%ls", g_ScriptingHost.GetScriptInterface().ToString(rval).c_str());
610 }
611 
613 {
614  // note: we don't care if this file doesn't exist or can't be read;
615  // just don't load anything in that case.
616 
617  // do this before LoadFile to avoid an error message if file not found.
619  return;
620 
621  shared_ptr<u8> buf; size_t buflen;
622  if (g_VFS->LoadFile(m_sHistoryFile, buf, buflen) < 0)
623  return;
624 
625  CStr bytes ((char*)buf.get(), buflen);
626 
627  CStrW str (bytes.FromUTF8());
628  size_t pos = 0;
629  while (pos != CStrW::npos)
630  {
631  pos = str.find('\n');
632  if (pos != CStrW::npos)
633  {
634  if (pos > 0)
635  m_deqBufHistory.push_front(str.Left(str[pos-1] == '\r' ? pos - 1 : pos));
636  str = str.substr(pos + 1);
637  }
638  else if (str.length() > 0)
639  m_deqBufHistory.push_front(str);
640  }
641 }
642 
644 {
645  WriteBuffer buffer;
646  const int linesToSkip = (int)m_deqBufHistory.size() - m_MaxHistoryLines;
647  std::deque<std::wstring>::reverse_iterator it = m_deqBufHistory.rbegin();
648  if(linesToSkip > 0)
649  std::advance(it, linesToSkip);
650  for (; it != m_deqBufHistory.rend(); ++it)
651  {
652  CStr8 line = CStrW(*it).ToUTF8();
653  buffer.Append(line.data(), line.length());
654  static const char newline = '\n';
655  buffer.Append(&newline, 1);
656  }
657  g_VFS->CreateFile(m_sHistoryFile, buffer.Data(), buffer.Size());
658 }
659 
660 void CConsole::ReceivedChatMessage(const wchar_t *szSender, const wchar_t *szMessage)
661 {
662  InsertMessage(L"%ls: %ls", szSender, szMessage);
663 }
664 
665 #if SDL_VERSION_ATLEAST(2, 0, 0)
666 static bool isUnprintableChar(SDL_Keysym key)
667 #else
669 #endif
670 {
671  // U+0000 to U+001F are control characters
672  if (key.unicode < 0x20)
673  {
674  switch (key.sym)
675  {
676  // We want to allow some, which are handled specially
677  case SDLK_RETURN: case SDLK_TAB:
678  case SDLK_BACKSPACE: case SDLK_DELETE:
679  case SDLK_HOME: case SDLK_END:
680  case SDLK_LEFT: case SDLK_RIGHT:
681  case SDLK_UP: case SDLK_DOWN:
682  case SDLK_PAGEUP: case SDLK_PAGEDOWN:
683  return false;
684 
685  // Ignore the others
686  default:
687  return true;
688  }
689  }
690 
691  return false;
692 }
693 
695 {
696  if ((int)ev->ev.type == SDL_HOTKEYDOWN)
697  {
698  std::string hotkey = static_cast<const char*>(ev->ev.user.data1);
699 
700  if (hotkey == "console.toggle")
701  {
702  g_Console->ToggleVisible();
703  return IN_HANDLED;
704  }
705  else if (g_Console->IsActive() && hotkey == "copy")
706  {
707  sys_clipboard_set(g_Console->GetBuffer());
708  return IN_HANDLED;
709  }
710  else if (g_Console->IsActive() && hotkey == "paste")
711  {
712  wchar_t* text = sys_clipboard_get();
713  if (text)
714  {
715  for (wchar_t* c = text; *c; c++)
716  g_Console->InsertChar(0, *c);
717 
718  sys_clipboard_free(text);
719  }
720  return IN_HANDLED;
721  }
722  }
723 
724  if (!g_Console->IsActive())
725  return IN_PASS;
726 
727  if (ev->ev.type != SDL_KEYDOWN)
728  return IN_PASS;
729 
730  int sym = ev->ev.key.keysym.sym;
731 
732  // Stop unprintable characters (ctrl+, alt+ and escape),
733  // also prevent ` and/or ~ appearing in console every time it's toggled.
734  if (!isUnprintableChar(ev->ev.key.keysym) &&
735  !HotkeyIsPressed("console.toggle"))
736  {
737  g_Console->InsertChar(sym, (wchar_t)ev->ev.key.keysym.unicode);
738  return IN_HANDLED;
739  }
740 
741  return IN_PASS;
742 }
Definition: Decompose.h:22
void Translate(float x, float y, float z)
std::deque< std::wstring > m_deqBufHistory
Definition: CConsole.h:110
CMatrix3D GetDefaultGuiMatrix()
Definition: GUIutil.cpp:253
size_t Size() const
Definition: write_buffer.h:42
void Append(const void *data, size_t size)
void ReceivedChatMessage(const wchar_t *pSender, const wchar_t *szMessage)
Definition: CConsole.cpp:660
SDL_KeyboardEvent key
Definition: wsdl.h:305
Definition: Decompose.h:22
bool IsBOB()
Definition: CConsole.h:137
Status sys_clipboard_set(const wchar_t *text)
Definition: android.cpp:30
int m_iFontOffset
Definition: CConsole.h:92
VfsPath m_sHistoryFile
Definition: CConsole.h:118
CMatrix3D GetTransform()
void PutAdvance(const wchar_t *buf)
Print text at (0,0) under the current transform, and advance the transform by the width of the text...
void FlushBuffer()
Definition: CConsole.cpp:113
float m_fY
Definition: CConsole.h:100
float m_fWidth
Definition: CConsole.h:103
Locks a CMutex over this object&#39;s lifetime.
Definition: ThreadUtil.h:73
double m_prevTime
Definition: CConsole.h:124
void DrawHistory(CTextRenderer &textRenderer)
Definition: CConsole.cpp:267
shared_ptr< CShaderTechnique > CShaderTechniquePtr
void DrawCursor(CTextRenderer &textRenderer)
Definition: CConsole.cpp:317
float m_fVisibleFrac
Definition: CConsole.h:107
Definition: Decompose.h:22
int m_iFontHeight
Definition: CConsole.h:90
bool IsActive()
Definition: CConsole.h:88
Status sys_clipboard_free(wchar_t *copy)
Definition: android.cpp:40
const wchar_t * GetBuffer()
Definition: CConsole.cpp:568
size_t m_charsPerPage
Definition: CConsole.h:93
void SetCursorBlinkRate(double rate)
Definition: CConsole.cpp:108
wchar_t * m_szBuffer
Definition: CConsole.h:114
#define g_Renderer
Definition: Renderer.h:61
#define CONSOLE_FONT
Definition: CConsole.h:43
Hotkey system.
void PostTranslate(float x, float y, float z)
Definition: Matrix3D.cpp:186
SDL_Event ev
Definition: libsdl.h:56
void SetSize(float X=300, float Y=0, float W=800, float H=600)
Definition: CConsole.cpp:75
static bool isUnprintableChar(SDL_keysym key)
Definition: CConsole.cpp:668
void ToggleVisible()
Definition: CConsole.cpp:90
CConsole()
Definition: CConsole.cpp:48
#define ENSURE(expr)
ensure the expression &lt;expr&gt; evaluates to non-zero.
Definition: debug.h:282
#define g_ScriptingHost
void Put(float x, float y, const wchar_t *buf)
Print text at (x,y) under the current transform, and advance the transform by the width of the text...
Uint8 type
Definition: wsdl.h:302
void Color(const CColor &color)
Set the color for subsequent print calls.
void PrintfAdvance(const wchar_t *fmt,...)
Print formatted text at (0,0) under the current transform, and advance the transform by the width of ...
CConsole * g_Console
Definition: CConsole.cpp:46
Definition: path.h:75
shared_ptr< u8 > Data() const
Definition: write_buffer.h:37
void UseHistoryFile(const VfsPath &filename, int historysize)
Definition: CConsole.cpp:586
InReaction
Definition: input.h:34
Definition: input.h:40
int m_iBufferPos
Definition: CConsole.h:115
pthread_key_t key
Definition: wpthread.cpp:140
void SetTransform(const CMatrix3D &transform)
bool m_bCursorVisState
Definition: CConsole.h:125
void Render()
Definition: CConsole.cpp:190
int m_iMsgHistPos
Definition: CConsole.h:112
~CConsole()
Definition: CConsole.cpp:69
u16 unicode
Definition: wsdl.h:189
void InsertMessageRaw(const CStrW &message)
Definition: CConsole.cpp:527
const int SDL_HOTKEYDOWN
Definition: Hotkey.h:41
double timer_Time()
Definition: timer.cpp:98
std::deque< std::wstring > m_deqMsgHistory
Definition: CConsole.h:109
wchar_t * sys_clipboard_get()
Definition: android.cpp:35
intptr_t ssize_t
Definition: wposix_types.h:82
void DrawWindow(CShaderProgramPtr &shader)
Definition: CConsole.cpp:231
void ProcessBuffer(const wchar_t *szLine)
Definition: CConsole.cpp:594
void Trim(wchar_t *szMessage, const wchar_t cChar=32, size_t iSize=0)
Definition: CConsole.cpp:134
void Update(const float deltaRealTime)
Definition: CConsole.cpp:162
void LoadHistory()
Definition: CConsole.cpp:612
bool IsEOB()
Definition: CConsole.h:136
int m_MaxHistoryLines
Definition: CConsole.h:119
void SaveHistory()
Definition: CConsole.cpp:643
void SetBuffer(const wchar_t *szMessage)
Definition: CConsole.cpp:574
bool m_bVisible
Definition: CConsole.h:122
#define CONSOLE_BUFFER_SIZE
Definition: CConsole.h:40
void Font(const CStrW &font)
Set the font for subsequent print calls.
In-game console.
Definition: CConsole.h:52
bool VfsFileExists(const VfsPath &pathname)
Definition: Filesystem.cpp:34
float m_fX
Definition: CConsole.h:99
void DrawBuffer(CTextRenderer &textRenderer)
Definition: CConsole.cpp:290
#define CONSOLE_MESSAGE_SIZE
Definition: CConsole.h:41
SDL_keysym keysym
Definition: wsdl.h:196
bool HotkeyIsPressed(const CStr &keyname)
Definition: Hotkey.cpp:400
#define PROFILE3_GPU(name)
Definition: Profile.h:204
SDL_UserEvent user
Definition: wsdl.h:312
double m_cursorBlinkRate
Definition: CConsole.h:126
float m_fHeight
Definition: CConsole.h:102
void ToLower(wchar_t *szMessage, size_t iSize=0)
Definition: CConsole.cpp:121
int m_iBufferLength
Definition: CConsole.h:116
CMutex m_Mutex
Definition: CConsole.h:97
PIVFS g_VFS
Definition: Filesystem.cpp:30
SDLKey sym
Definition: wsdl.h:188
void SetVisible(bool visible)
Definition: CConsole.cpp:96
shared_ptr< CShaderProgram > CShaderProgramPtr
void UpdateScreenSize(int w, int h)
Definition: CConsole.cpp:83
void InsertMessage(const wchar_t *szMessage,...) WPRINTF_ARGS(2)
Definition: CConsole.cpp:508
T clamp(T value, T min, T max)
Definition: MathUtil.h:32
void InsertChar(const int szChar, const wchar_t cooked)
Definition: CConsole.cpp:350
void debug_printf(const wchar_t *fmt,...)
write a formatted string to the debug channel, subject to filtering (see below).
Definition: debug.cpp:142
bool m_bToggle
Definition: CConsole.h:123
std::map< int32_t, bool > g_keys
g_keys: Key states, indexed by SDLK* constants.
Definition: Globals.cpp:29
InReaction conInputHandler(const SDL_Event_ *ev)
Definition: CConsole.cpp:694
void * data1
Definition: wsdl.h:282
bool IsFull()
Definition: CConsole.h:138
bool IsEmpty()
Definition: CConsole.h:139