/***********************************************************************************/ /** \file EditorHelp.cpp ** \brief Implementation zur Klasse EditorHelp ************************************************************************************* ** Autor: Christian Roesch ************************************************************************************* ** -tut nichts- ** *//*********************************************************************************/ // includes #include "EditorHelp.h" #include #include #include #include bool EditorHelp::m_KeyPressed[ 256 ]= { false }; bool EditorHelp::m_KeyDown[ 256 ]= { false }; HWND EditorHelp::m_hwnd= NULL; bool EditorHelp::m_bShowDebugData= true; LPD3DXFONT EditorHelp::m_pDebugFont= NULL; extern int c_iScreenSizeY; extern int c_iScreenSizeX; extern IDirect3DDevice9 *g_d3d_device; // Methoden-Definitionen EditorHelp::EditorHelp() { } EditorHelp::~EditorHelp() { } void EditorHelp::SetHWND( HWND hwnd ) { m_hwnd= hwnd; } void EditorHelp::CheckKeys() { if( m_hwnd == NULL ) { m_hwnd= GetForegroundWindow(); } if( m_hwnd == GetForegroundWindow() ) { for( int i= 0; i < 256; i++ ) { SHORT iKey= GetAsyncKeyState( i ); m_KeyPressed[ i ]= false; if( iKey & 0x8000 ) { if( m_KeyDown[ i ] == false ) { m_KeyPressed[ i ]= true; } m_KeyDown[ i ]= true; } else { m_KeyDown[ i ]= false; } } } else { for( int i= 0; i < 256; i++ ) { m_KeyPressed[ i ]= false; m_KeyDown[ i ]= false; } } } float EditorHelp::GetKeyDownVal( float fCurrent, int KeyAdd, int KeySub, float fDefault, float fSlow, float fFast ) { return GetKeyVal( fCurrent, m_KeyDown[ KeyAdd ], m_KeyDown[ KeySub ], fDefault, fSlow, fFast ); } float EditorHelp::GetKeyPressedVal( float fCurrent, int KeyAdd, int KeySub, float fDefault, float fSlow, float fFast ) { return GetKeyVal( fCurrent, m_KeyPressed[ KeyAdd ], m_KeyPressed[ KeySub ], fDefault, fSlow, fFast ); } float EditorHelp::GetKeyVal( float fCurrent, bool bAdd, bool bSub, float fDefault, float fSlow, float fFast ) { //Konventionen fuer Tastenbelegung eingehalten? assert( fSlow <= fDefault ); assert( fDefault <= fFast ); float fChange= fDefault; if( m_KeyDown[ VK_SHIFT ] ) { fChange= fFast; } if( m_KeyDown[ VK_CONTROL ] ) { fChange= fSlow; } int iVal= (int)Round( fCurrent / fChange ); if( bAdd ) { return (float)(iVal + 1 ) * fChange; } if( bSub ) { return (float)(iVal - 1 ) * fChange; } return fCurrent; } float EditorHelp::Round(float Val ) { return floor(Val + 0.5f); } void EditorHelp::PrintDebug( int iLine, int iColumn, char* pcData ) { PrintDebugPos( 2.0f + (float)iLine * 12.0f, 2.0f + (float)iColumn * 9.0f, pcData ); } void EditorHelp::PrintDebugPos( float fY, float fX, char* pcData ) { if( m_bShowDebugData ) { RECT r= { 0 + (int)fX, 0 + (int)fY, c_iScreenSizeX + (int)fX, c_iScreenSizeY + (int)fX }; m_pDebugFont->DrawText( NULL, pcData, strlen(pcData), &r, DT_TOP | DT_LEFT, 0xff000000 ); r.top-=1; r.left-=1; m_pDebugFont->DrawText( NULL, pcData, strlen(pcData), &r, DT_TOP | DT_LEFT, 0xffffffff ); } } std::string EditorHelp::GetDateString() { time_t t; struct tm ts; t = time(NULL); localtime_s( &ts, &t ); std::stringstream ss; ss << ts.tm_mon + 1 << "_"; ss << ts.tm_mday << "_"; ss << ts.tm_hour << "_"; ss << ts.tm_min << "_"; ss << ts.tm_sec; return ss.str(); } void EditorHelp::PreparePrint() { if( m_pDebugFont != NULL ) { return; } static D3DXFONT_DESC FontDescription= { 50, 20, 0, 8, FALSE, 0, 0, 5, // CLEARTYPE_QUALITY 0, "Courier" }; FontDescription.Height= 12; FontDescription.Width= 9; D3DXCreateFontIndirect( g_d3d_device, &FontDescription, &m_pDebugFont ); } /************************************************************************************ ** Ende der Datei: EditorHelp.cpp ************************************************************************************/