doom3-bfg/neo/ui/BindWindow.cpp

148 lines
3.6 KiB
C++
Raw Normal View History

2012-11-26 18:58:24 +00:00
/*
===========================================================================
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
2012-11-26 18:58:24 +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 "precompiled.h"
2012-11-26 18:58:24 +00:00
#include "DeviceContext.h"
#include "Window.h"
#include "UserInterfaceLocal.h"
#include "BindWindow.h"
void idBindWindow::CommonInit()
{
2012-11-26 18:58:24 +00:00
bindName = "";
waitingOnKey = false;
}
idBindWindow::idBindWindow( idUserInterfaceLocal* g ) : idWindow( g )
{
2012-11-26 18:58:24 +00:00
gui = g;
CommonInit();
}
idBindWindow::~idBindWindow()
{
2012-11-26 18:58:24 +00:00
}
const char* idBindWindow::HandleEvent( const sysEvent_t* event, bool* updateVisuals )
{
2012-11-26 18:58:24 +00:00
static char ret[ 256 ];
if( !( event->evType == SE_KEY && event->evValue2 ) )
{
2012-11-26 18:58:24 +00:00
return "";
}
2012-11-26 18:58:24 +00:00
int key = event->evValue;
if( waitingOnKey )
{
2012-11-26 18:58:24 +00:00
waitingOnKey = false;
if( key == K_ESCAPE )
{
idStr::snPrintf( ret, sizeof( ret ), "clearbind \"%s\"", bindName.GetName() );
}
else
{
idStr::snPrintf( ret, sizeof( ret ), "bind %i \"%s\"", key, bindName.GetName() );
2012-11-26 18:58:24 +00:00
}
return ret;
}
else
{
if( key == K_MOUSE1 )
{
2012-11-26 18:58:24 +00:00
waitingOnKey = true;
gui->SetBindHandler( this );
2012-11-26 18:58:24 +00:00
return "";
}
}
2012-11-26 18:58:24 +00:00
return "";
}
idWinVar* idBindWindow::GetWinVarByName( const char* _name, bool fixup, drawWin_t** owner )
{
2012-11-26 18:58:24 +00:00
if( idStr::Icmp( _name, "bind" ) == 0 )
{
2012-11-26 18:58:24 +00:00
return &bindName;
}
return idWindow::GetWinVarByName( _name, fixup, owner );
2012-11-26 18:58:24 +00:00
}
void idBindWindow::PostParse()
{
2012-11-26 18:58:24 +00:00
idWindow::PostParse();
bindName.SetGuiInfo( gui->GetStateDict(), bindName );
bindName.Update();
//bindName = state.GetString("bind");
flags |= ( WIN_HOLDCAPTURE | WIN_CANFOCUS );
2012-11-26 18:58:24 +00:00
}
void idBindWindow::Draw( int time, float x, float y )
{
2012-11-26 18:58:24 +00:00
idVec4 color = foreColor;
2012-11-26 18:58:24 +00:00
idStr str;
if( waitingOnKey )
{
2012-11-26 18:58:24 +00:00
str = idLocalization::GetString( "#str_07000" );
}
else if( bindName.Length() )
{
2012-11-26 18:58:24 +00:00
str = bindName.c_str();
}
else
{
2012-11-26 18:58:24 +00:00
str = idLocalization::GetString( "#str_07001" );
}
if( waitingOnKey || ( hover && !noEvents && Contains( gui->CursorX(), gui->CursorY() ) ) )
{
2012-11-26 18:58:24 +00:00
color = hoverColor;
}
else
{
2012-11-26 18:58:24 +00:00
hover = false;
}
dc->DrawText( str, textScale, textAlign, color, textRect, false, -1 );
2012-11-26 18:58:24 +00:00
}
void idBindWindow::Activate( bool activate, idStr& act )
{
2012-11-26 18:58:24 +00:00
idWindow::Activate( activate, act );
bindName.Update();
}