guiConsoleEditCtrl.cpp
Engine/source/gui/controls/guiConsoleEditCtrl.cpp
Public Functions
ConsoleDocClass(GuiConsoleEditCtrl , "@brief Text entry element of <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">GuiConsole.\n\n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "<a href="/coding/file/tmm__on_8h/#tmm__on_8h_1a1ac41480eb2e4aadd52252ee550b630a">new</a> <a href="/coding/class/classguiconsoleeditctrl/">GuiConsoleEditCtrl</a>(ConsoleEntry)\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "{\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " profile = \"ConsoleTextEditProfile\";\n" " horizSizing = \"width\";\n" " vertSizing = \"top\";\n" " position = \"0 462\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " extent = \"640 18\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " minExtent = \"8 8\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " visible = \"1\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " altCommand = \"ConsoleEntry::eval();\";\n" " helpTag = \"0\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " maxLength = \"255\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " historySize = \"40\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " password = \"0\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " tabComplete = \"0\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " sinkAllKeyEvents = \"1\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " useSiblingScroller = \"1\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "};\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">endtsexample\n\n</a>" "@ingroup GuiCore" )
Detailed Description
Public Functions
ConsoleDocClass(GuiConsoleEditCtrl , "@brief Text entry element of <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">GuiConsole.\n\n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "<a href="/coding/file/tmm__on_8h/#tmm__on_8h_1a1ac41480eb2e4aadd52252ee550b630a">new</a> <a href="/coding/class/classguiconsoleeditctrl/">GuiConsoleEditCtrl</a>(ConsoleEntry)\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "{\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " profile = \"ConsoleTextEditProfile\";\n" " horizSizing = \"width\";\n" " vertSizing = \"top\";\n" " position = \"0 462\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " extent = \"640 18\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " minExtent = \"8 8\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " visible = \"1\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " altCommand = \"ConsoleEntry::eval();\";\n" " helpTag = \"0\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " maxLength = \"255\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " historySize = \"40\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " password = \"0\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " tabComplete = \"0\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " sinkAllKeyEvents = \"1\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " useSiblingScroller = \"1\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "};\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">endtsexample\n\n</a>" "@ingroup GuiCore" )
IMPLEMENT_CONOBJECT(GuiConsoleEditCtrl )
1 2//----------------------------------------------------------------------------- 3// Copyright (c) 2012 GarageGames, LLC 4// 5// Permission is hereby granted, free of charge, to any person obtaining a copy 6// of this software and associated documentation files (the "Software"), to 7// deal in the Software without restriction, including without limitation the 8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9// sell copies of the Software, and to permit persons to whom the Software is 10// furnished to do so, subject to the following conditions: 11// 12// The above copyright notice and this permission notice shall be included in 13// all copies or substantial portions of the Software. 14// 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21// IN THE SOFTWARE. 22//----------------------------------------------------------------------------- 23 24#include "console/consoleTypes.h" 25#include "console/console.h" 26#include "gui/core/guiCanvas.h" 27#include "gui/controls/guiConsoleEditCtrl.h" 28#include "core/frameAllocator.h" 29 30IMPLEMENT_CONOBJECT(GuiConsoleEditCtrl); 31 32ConsoleDocClass( GuiConsoleEditCtrl, 33 "@brief Text entry element of a GuiConsole.\n\n" 34 "@tsexample\n" 35 "new GuiConsoleEditCtrl(ConsoleEntry)\n" 36 "{\n" 37 " profile = \"ConsoleTextEditProfile\";\n" 38 " horizSizing = \"width\";\n" 39 " vertSizing = \"top\";\n" 40 " position = \"0 462\";\n" 41 " extent = \"640 18\";\n" 42 " minExtent = \"8 8\";\n" 43 " visible = \"1\";\n" 44 " altCommand = \"ConsoleEntry::eval();\";\n" 45 " helpTag = \"0\";\n" 46 " maxLength = \"255\";\n" 47 " historySize = \"40\";\n" 48 " password = \"0\";\n" 49 " tabComplete = \"0\";\n" 50 " sinkAllKeyEvents = \"1\";\n" 51 " useSiblingScroller = \"1\";\n" 52 "};\n" 53 "@endtsexample\n\n" 54 "@ingroup GuiCore" 55); 56 57GuiConsoleEditCtrl::GuiConsoleEditCtrl() 58{ 59 mSinkAllKeyEvents = true; 60 mSiblingScroller = NULL; 61 mUseSiblingScroller = true; 62} 63 64void GuiConsoleEditCtrl::initPersistFields() 65{ 66 addGroup("GuiConsoleEditCtrl"); 67 addField("useSiblingScroller", TypeBool, Offset(mUseSiblingScroller, GuiConsoleEditCtrl)); 68 endGroup("GuiConsoleEditCtrl"); 69 70 Parent::initPersistFields(); 71} 72 73bool GuiConsoleEditCtrl::onKeyDown(const GuiEvent &event) 74{ 75 setUpdate(); 76 77 if (event.keyCode == KEY_TAB) 78 { 79 // Get a buffer that can hold the completed text... 80 FrameTemp<UTF8> tmpBuff(GuiTextCtrl::MAX_STRING_LENGTH); 81 // And copy the text to be completed into it. 82 mTextBuffer.getCopy8(tmpBuff, GuiTextCtrl::MAX_STRING_LENGTH); 83 84 // perform the completion 85 bool forward = (event.modifier & SI_SHIFT) == 0; 86 mCursorPos = Con::tabComplete(tmpBuff, mCursorPos, GuiTextCtrl::MAX_STRING_LENGTH, forward); 87 88 // place results in our buffer. 89 mTextBuffer.set(tmpBuff); 90 return true; 91 } 92 else if ((event.keyCode == KEY_PAGE_UP) || (event.keyCode == KEY_PAGE_DOWN)) 93 { 94 // See if there's some other widget that can scroll the console history. 95 if (mUseSiblingScroller) 96 { 97 if (mSiblingScroller) 98 { 99 return mSiblingScroller->onKeyDown(event); 100 } 101 else 102 { 103 // Let's see if we can find it... 104 SimGroup* pGroup = getGroup(); 105 if (pGroup) 106 { 107 // Find the first scroll control in the same group as us. 108 for (SimSetIterator itr(pGroup); *itr; ++itr) 109 { 110 mSiblingScroller = dynamic_cast<GuiScrollCtrl*>(*itr); 111 if (mSiblingScroller != NULL) 112 { 113 return mSiblingScroller->onKeyDown(event); 114 } 115 } 116 } 117 118 // No luck... so don't try, next time. 119 mUseSiblingScroller = false; 120 } 121 } 122 } 123 else if( event.keyCode == KEY_RETURN || event.keyCode == KEY_NUMPADENTER ) 124 { 125 if ( event.modifier & SI_SHIFT && 126 mTextBuffer.length() + dStrlen("echo();") <= GuiTextCtrl::MAX_STRING_LENGTH ) 127 { 128 // Wrap the text with echo( %s ); 129 130 char buf[GuiTextCtrl::MAX_STRING_LENGTH]; 131 getText( buf ); 132 133 String text( buf ); 134 text.replace( ";", "" ); 135 136 text = String::ToString( "echo(%s);", text.c_str() ); 137 138 setText( text ); 139 } 140 141 return Parent::dealWithEnter(false); 142 } 143 144 return Parent::onKeyDown(event); 145} 146 147