2012-11-26 18:58:24 +00:00
|
|
|
/*
|
|
|
|
===========================================================================
|
|
|
|
|
|
|
|
Doom 3 BFG Edition GPL Source Code
|
2012-11-28 15:47:07 +00:00
|
|
|
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
|
2012-11-26 18:58:24 +00:00
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
In addition, the Doom 3 BFG Edition 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 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below.
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
===========================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma hdrstop
|
|
|
|
#include "../idlib/precompiled.h"
|
|
|
|
|
|
|
|
#include "DeviceContext.h"
|
|
|
|
#include "Window.h"
|
|
|
|
#include "UserInterfaceLocal.h"
|
|
|
|
#include "SliderWindow.h"
|
|
|
|
#include "EditWindow.h"
|
|
|
|
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
bool idEditWindow::ParseInternalVar( const char* _name, idTokenParser* src )
|
|
|
|
{
|
|
|
|
if( idStr::Icmp( _name, "maxchars" ) == 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
maxChars = src->ParseInt();
|
|
|
|
return true;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( idStr::Icmp( _name, "numeric" ) == 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
numeric = src->ParseBool();
|
|
|
|
return true;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( idStr::Icmp( _name, "wrap" ) == 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
wrap = src->ParseBool();
|
|
|
|
return true;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( idStr::Icmp( _name, "readonly" ) == 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
readonly = src->ParseBool();
|
|
|
|
return true;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( idStr::Icmp( _name, "forceScroll" ) == 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
forceScroll = src->ParseBool();
|
|
|
|
return true;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( idStr::Icmp( _name, "source" ) == 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
ParseString( src, sourceFile );
|
|
|
|
return true;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( idStr::Icmp( _name, "password" ) == 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
password = src->ParseBool();
|
|
|
|
return true;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( idStr::Icmp( _name, "cvarMax" ) == 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
cvarMax = src->ParseInt();
|
|
|
|
return true;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
return idWindow::ParseInternalVar( _name, src );
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
idWinVar* idEditWindow::GetWinVarByName( const char* _name, bool fixup, drawWin_t** owner )
|
|
|
|
{
|
|
|
|
if( idStr::Icmp( _name, "cvar" ) == 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return &cvarStr;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( idStr::Icmp( _name, "password" ) == 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return &password;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( idStr::Icmp( _name, "liveUpdate" ) == 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return &liveUpdate;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( idStr::Icmp( _name, "cvarGroup" ) == 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return &cvarGroup;
|
|
|
|
}
|
|
|
|
return idWindow::GetWinVarByName( _name, fixup, owner );
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void idEditWindow::CommonInit()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
maxChars = 128;
|
|
|
|
numeric = false;
|
|
|
|
paintOffset = 0;
|
|
|
|
cursorPos = 0;
|
|
|
|
cursorLine = 0;
|
|
|
|
cvarMax = 0;
|
|
|
|
wrap = false;
|
|
|
|
sourceFile = "";
|
|
|
|
scroller = NULL;
|
|
|
|
sizeBias = 0;
|
|
|
|
lastTextLength = 0;
|
|
|
|
forceScroll = false;
|
|
|
|
password = NULL;
|
|
|
|
cvar = NULL;
|
|
|
|
liveUpdate = true;
|
|
|
|
readonly = false;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
scroller = new( TAG_OLD_UI ) idSliderWindow( gui );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
idEditWindow::idEditWindow( idUserInterfaceLocal* g ) : idWindow( g )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
gui = g;
|
|
|
|
CommonInit();
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
idEditWindow::~idEditWindow()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void idEditWindow::GainFocus()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
cursorPos = text.Length();
|
|
|
|
EnsureCursorVisible();
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void idEditWindow::Draw( int time, float x, float y )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
idVec4 color = foreColor;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
UpdateCvar( true );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
int len = text.Length();
|
2012-11-28 15:47:07 +00:00
|
|
|
if( len != lastTextLength )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
scroller->SetValue( 0.0f );
|
|
|
|
EnsureCursorVisible();
|
|
|
|
lastTextLength = len;
|
|
|
|
}
|
|
|
|
float scale = textScale;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
idStr pass;
|
|
|
|
const char* buffer;
|
2012-11-28 15:47:07 +00:00
|
|
|
if( password )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
const char* temp = text;
|
2012-11-28 15:47:07 +00:00
|
|
|
for( ; *temp; temp++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
pass += "*";
|
|
|
|
}
|
|
|
|
buffer = pass;
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
buffer = text;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( cursorPos > len )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
cursorPos = len;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
idRectangle rect = textRect;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
rect.x -= paintOffset;
|
|
|
|
rect.w += paintOffset;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( wrap && scroller->GetHigh() > 0.0f )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
float lineHeight = GetMaxCharHeight( ) + 5;
|
|
|
|
rect.y -= scroller->GetValue() * lineHeight;
|
|
|
|
rect.w -= sizeBias;
|
|
|
|
rect.h = ( breaks.Num() + 1 ) * lineHeight;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( hover && !noEvents && Contains( gui->CursorX(), gui->CursorY() ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
color = hoverColor;
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
hover = false;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( flags & WIN_FOCUS )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
color = hoverColor;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
dc->DrawText( buffer, scale, 0, color, rect, wrap, ( flags & WIN_FOCUS ) ? cursorPos : -1 );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=============
|
|
|
|
idEditWindow::HandleEvent
|
|
|
|
=============
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
const char* idEditWindow::HandleEvent( const sysEvent_t* event, bool* updateVisuals )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
static char buffer[ MAX_EDITFIELD ];
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( wrap )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// need to call this to allow proper focus and capturing on embedded children
|
2012-11-28 15:47:07 +00:00
|
|
|
const char* ret = idWindow::HandleEvent( event, updateVisuals );
|
|
|
|
if( ret != NULL && *ret != NULL )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( ( event->evType != SE_CHAR && event->evType != SE_KEY ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return "";
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
idStr::Copynz( buffer, text.c_str(), sizeof( buffer ) );
|
|
|
|
int key = event->evValue;
|
|
|
|
int len = text.Length();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( event->evType == SE_CHAR )
|
|
|
|
{
|
|
|
|
if( key == '`' )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return "";
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( updateVisuals )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
*updateVisuals = true;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( maxChars && len > maxChars )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
len = maxChars;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( readonly )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return "";
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// ignore any non printable chars (except enter when wrap is enabled)
|
|
|
|
//
|
|
|
|
if( wrap && ( key == K_ENTER || key == K_KP_ENTER ) )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
else if( !idStr::CharIsPrintable( key ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return "";
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( numeric )
|
|
|
|
{
|
|
|
|
if( ( key < '0' || key > '9' ) && key != '.' )
|
|
|
|
{
|
|
|
|
return "";
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( dc->GetOverStrike() )
|
|
|
|
{
|
|
|
|
if( maxChars && cursorPos >= maxChars )
|
|
|
|
{
|
|
|
|
return "";
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( ( len == MAX_EDITFIELD - 1 ) || ( maxChars && len >= maxChars ) )
|
|
|
|
{
|
|
|
|
return "";
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
memmove( &buffer[ cursorPos + 1 ], &buffer[ cursorPos ], len + 1 - cursorPos );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
buffer[ cursorPos ] = key;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
text = buffer;
|
|
|
|
UpdateCvar( false );
|
|
|
|
RunScript( ON_ACTION );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( cursorPos < len + 1 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
cursorPos++;
|
|
|
|
}
|
|
|
|
EnsureCursorVisible();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
else if( event->evType == SE_KEY && event->evValue2 )
|
|
|
|
{
|
|
|
|
|
|
|
|
if( updateVisuals )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
*updateVisuals = true;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( key == K_DEL )
|
|
|
|
{
|
|
|
|
if( readonly )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return "";
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( cursorPos < len )
|
|
|
|
{
|
|
|
|
memmove( &buffer[cursorPos], &buffer[cursorPos + 1], len - cursorPos );
|
2012-11-26 18:58:24 +00:00
|
|
|
text = buffer;
|
|
|
|
UpdateCvar( false );
|
|
|
|
RunScript( ON_ACTION );
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( key == K_BACKSPACE ) // ctrl-h is backspace
|
|
|
|
{
|
|
|
|
if( readonly )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return "";
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( cursorPos > 0 )
|
|
|
|
{
|
|
|
|
if( cursorPos >= len )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
buffer[len - 1] = 0;
|
|
|
|
cursorPos = len - 1;
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
memmove( &buffer[ cursorPos - 1 ], &buffer[ cursorPos ], len + 1 - cursorPos );
|
2012-11-26 18:58:24 +00:00
|
|
|
cursorPos--;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
text = buffer;
|
|
|
|
UpdateCvar( false );
|
|
|
|
RunScript( ON_ACTION );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
return "";
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
if( key == K_RIGHTARROW )
|
|
|
|
{
|
|
|
|
if( cursorPos < len )
|
|
|
|
{
|
|
|
|
if( ( idKeyInput::IsDown( K_LCTRL ) || idKeyInput::IsDown( K_RCTRL ) ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// skip to next word
|
2012-11-28 15:47:07 +00:00
|
|
|
while( ( cursorPos < len ) && ( buffer[ cursorPos ] != ' ' ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
cursorPos++;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
while( ( cursorPos < len ) && ( buffer[ cursorPos ] == ' ' ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
cursorPos++;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( cursorPos < len )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
cursorPos++;
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
EnsureCursorVisible();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
return "";
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( key == K_LEFTARROW )
|
|
|
|
{
|
|
|
|
if( ( idKeyInput::IsDown( K_LCTRL ) || idKeyInput::IsDown( K_RCTRL ) ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// skip to previous word
|
2012-11-28 15:47:07 +00:00
|
|
|
while( ( cursorPos > 0 ) && ( buffer[ cursorPos - 1 ] == ' ' ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
cursorPos--;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
while( ( cursorPos > 0 ) && ( buffer[ cursorPos - 1 ] != ' ' ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
cursorPos--;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( cursorPos > 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
cursorPos--;
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
EnsureCursorVisible();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
return "";
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( key == K_HOME )
|
|
|
|
{
|
|
|
|
if( ( idKeyInput::IsDown( K_LCTRL ) || idKeyInput::IsDown( K_RCTRL ) ) || cursorLine <= 0 || ( cursorLine >= breaks.Num() ) )
|
|
|
|
{
|
|
|
|
cursorPos = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
cursorPos = breaks[cursorLine];
|
|
|
|
}
|
|
|
|
EnsureCursorVisible();
|
|
|
|
return "";
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( key == K_END )
|
|
|
|
{
|
|
|
|
if( ( idKeyInput::IsDown( K_LCTRL ) || idKeyInput::IsDown( K_RCTRL ) ) || ( cursorLine < -1 ) || ( cursorLine >= breaks.Num() - 1 ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
cursorPos = len;
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
cursorPos = breaks[cursorLine + 1] - 1;
|
|
|
|
}
|
|
|
|
EnsureCursorVisible();
|
|
|
|
return "";
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( key == K_INS )
|
|
|
|
{
|
|
|
|
if( !readonly )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
dc->SetOverStrike( !dc->GetOverStrike() );
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( key == K_DOWNARROW )
|
|
|
|
{
|
|
|
|
if( ( idKeyInput::IsDown( K_LCTRL ) || idKeyInput::IsDown( K_RCTRL ) ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
scroller->SetValue( scroller->GetValue() + 1.0f );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( cursorLine < breaks.Num() - 1 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int offset = cursorPos - breaks[cursorLine];
|
|
|
|
cursorPos = breaks[cursorLine + 1] + offset;
|
|
|
|
EnsureCursorVisible();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( key == K_UPARROW )
|
|
|
|
{
|
|
|
|
if( ( idKeyInput::IsDown( K_LCTRL ) || idKeyInput::IsDown( K_RCTRL ) ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
scroller->SetValue( scroller->GetValue() - 1.0f );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( cursorLine > 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int offset = cursorPos - breaks[cursorLine];
|
|
|
|
cursorPos = breaks[cursorLine - 1] + offset;
|
|
|
|
EnsureCursorVisible();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( key == K_ENTER || key == K_KP_ENTER )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
RunScript( ON_ACTION );
|
|
|
|
RunScript( ON_ENTER );
|
|
|
|
return cmd;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( key == K_ESCAPE )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
RunScript( ON_ESC );
|
|
|
|
return cmd;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
else if( event->evType == SE_KEY && !event->evValue2 )
|
|
|
|
{
|
|
|
|
if( key == K_ENTER || key == K_KP_ENTER )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
RunScript( ON_ENTERRELEASE );
|
|
|
|
return cmd;
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
RunScript( ON_ACTIONRELEASE );
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void idEditWindow::PostParse()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
idWindow::PostParse();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( maxChars == 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
maxChars = 10;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( sourceFile.Length() )
|
|
|
|
{
|
|
|
|
void* buffer;
|
2012-11-26 18:58:24 +00:00
|
|
|
fileSystem->ReadFile( sourceFile, &buffer );
|
2012-11-28 15:47:07 +00:00
|
|
|
text = ( char* ) buffer;
|
2012-11-26 18:58:24 +00:00
|
|
|
fileSystem->FreeFile( buffer );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
InitCvar();
|
2012-11-28 15:47:07 +00:00
|
|
|
InitScroller( false );
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
EnsureCursorVisible();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
flags |= WIN_CANFOCUS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idEditWindow::InitScroller
|
|
|
|
|
|
|
|
This is the same as in idListWindow
|
|
|
|
================
|
|
|
|
*/
|
|
|
|
void idEditWindow::InitScroller( bool horizontal )
|
|
|
|
{
|
2012-11-28 15:47:07 +00:00
|
|
|
const char* thumbImage = "guis/assets/scrollbar_thumb.tga";
|
|
|
|
const char* barImage = "guis/assets/scrollbarv.tga";
|
|
|
|
const char* scrollerName = "_scrollerWinV";
|
|
|
|
|
|
|
|
if( horizontal )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
barImage = "guis/assets/scrollbarh.tga";
|
|
|
|
scrollerName = "_scrollerWinH";
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
const idMaterial* mat = declManager->FindMaterial( barImage );
|
2012-11-26 18:58:24 +00:00
|
|
|
mat->SetSort( SS_GUI );
|
|
|
|
sizeBias = mat->GetImageWidth();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
idRectangle scrollRect;
|
2012-11-28 15:47:07 +00:00
|
|
|
if( horizontal )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
sizeBias = mat->GetImageHeight();
|
|
|
|
scrollRect.x = 0;
|
2012-11-28 15:47:07 +00:00
|
|
|
scrollRect.y = ( clientRect.h - sizeBias );
|
2012-11-26 18:58:24 +00:00
|
|
|
scrollRect.w = clientRect.w;
|
|
|
|
scrollRect.h = sizeBias;
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
scrollRect.x = ( clientRect.w - sizeBias );
|
2012-11-26 18:58:24 +00:00
|
|
|
scrollRect.y = 0;
|
|
|
|
scrollRect.w = sizeBias;
|
|
|
|
scrollRect.h = clientRect.h;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
scroller->InitWithDefaults( scrollerName, scrollRect, foreColor, matColor, mat->GetName(), thumbImage, !horizontal, true );
|
|
|
|
InsertChild( scroller, NULL );
|
|
|
|
scroller->SetBuddy( this );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void idEditWindow::HandleBuddyUpdate( idWindow* buddy )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void idEditWindow::EnsureCursorVisible()
|
|
|
|
{
|
2012-11-28 15:47:07 +00:00
|
|
|
if( readonly )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
cursorPos = -1;
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else if( maxChars == 1 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
cursorPos = 0;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( !dc )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
SetFont();
|
2012-11-28 15:47:07 +00:00
|
|
|
if( !wrap )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int cursorX = 0;
|
2012-11-28 15:47:07 +00:00
|
|
|
if( password )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
cursorX = cursorPos * dc->CharWidth( '*', textScale );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int i = 0;
|
2012-11-28 15:47:07 +00:00
|
|
|
while( i < text.Length() && i < cursorPos )
|
|
|
|
{
|
|
|
|
if( idStr::IsColor( &text[i] ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
i += 2;
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
cursorX += dc->CharWidth( text[i], textScale );
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
int maxWidth = GetMaxCharWidth( );
|
|
|
|
int left = cursorX - maxWidth;
|
|
|
|
int right = ( cursorX - textRect.w ) + maxWidth;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( paintOffset > left )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// When we go past the left side, we want the text to jump 6 characters
|
|
|
|
paintOffset = left - maxWidth * 6;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( paintOffset < right )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
paintOffset = right;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( paintOffset < 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
paintOffset = 0;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
scroller->SetRange( 0.0f, 0.0f, 1.0f );
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// Word wrap
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
breaks.Clear();
|
|
|
|
idRectangle rect = textRect;
|
|
|
|
rect.w -= sizeBias;
|
2012-11-28 15:47:07 +00:00
|
|
|
dc->DrawText( text, textScale, textAlign, colorWhite, rect, true, ( flags & WIN_FOCUS ) ? cursorPos : -1, true, &breaks );
|
|
|
|
|
|
|
|
int fit = textRect.h / ( GetMaxCharHeight() + 5 );
|
|
|
|
if( fit < breaks.Num() + 1 )
|
|
|
|
{
|
|
|
|
scroller->SetRange( 0, breaks.Num() + 1 - fit, 1 );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// The text fits completely in the box
|
2012-11-28 15:47:07 +00:00
|
|
|
scroller->SetRange( 0.0f, 0.0f, 1.0f );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( forceScroll )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
scroller->SetValue( breaks.Num() - fit );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else if( readonly )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
cursorLine = 0;
|
2012-11-28 15:47:07 +00:00
|
|
|
for( int i = 1; i < breaks.Num(); i++ )
|
|
|
|
{
|
|
|
|
if( cursorPos >= breaks[i] )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
cursorLine = i;
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
int topLine = idMath::Ftoi( scroller->GetValue() );
|
2012-11-28 15:47:07 +00:00
|
|
|
if( cursorLine < topLine )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
scroller->SetValue( cursorLine );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else if( cursorLine >= topLine + fit )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
scroller->SetValue( ( cursorLine - fit ) + 1 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void idEditWindow::Activate( bool activate, idStr& act )
|
|
|
|
{
|
|
|
|
idWindow::Activate( activate, act );
|
|
|
|
if( activate )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
UpdateCvar( true, true );
|
|
|
|
EnsureCursorVisible();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
============
|
|
|
|
idEditWindow::InitCvar
|
|
|
|
============
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idEditWindow::InitCvar( )
|
|
|
|
{
|
|
|
|
if( cvarStr[0] == '\0' )
|
|
|
|
{
|
|
|
|
if( text.GetName() == NULL )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
common->Warning( "idEditWindow::InitCvar: gui '%s' window '%s' has an empty cvar string", gui->GetSourceFile(), name.c_str() );
|
|
|
|
}
|
|
|
|
cvar = NULL;
|
|
|
|
return;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
cvar = cvarSystem->Find( cvarStr );
|
2012-11-28 15:47:07 +00:00
|
|
|
if( !cvar )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
common->Warning( "idEditWindow::InitCvar: gui '%s' window '%s' references undefined cvar '%s'", gui->GetSourceFile(), name.c_str(), cvarStr.c_str() );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
============
|
|
|
|
idEditWindow::UpdateCvar
|
|
|
|
============
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idEditWindow::UpdateCvar( bool read, bool force )
|
|
|
|
{
|
|
|
|
if( force || liveUpdate )
|
|
|
|
{
|
|
|
|
if( cvar )
|
|
|
|
{
|
|
|
|
if( read )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
text = cvar->GetString();
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
cvar->SetString( text );
|
2012-11-28 15:47:07 +00:00
|
|
|
if( cvarMax && ( cvar->GetInteger() > cvarMax ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
cvar->SetInteger( cvarMax );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
============
|
|
|
|
idEditWindow::RunNamedEvent
|
|
|
|
============
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idEditWindow::RunNamedEvent( const char* eventName )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
idStr event, group;
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
if( !idStr::Cmpn( eventName, "cvar read ", 10 ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
event = eventName;
|
|
|
|
group = event.Mid( 10, event.Length() - 10 );
|
2012-11-28 15:47:07 +00:00
|
|
|
if( !group.Cmp( cvarGroup ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
UpdateCvar( true, true );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else if( !idStr::Cmpn( eventName, "cvar write ", 11 ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
event = eventName;
|
|
|
|
group = event.Mid( 11, event.Length() - 11 );
|
2012-11-28 15:47:07 +00:00
|
|
|
if( !group.Cmp( cvarGroup ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
UpdateCvar( false, true );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|