Browse Source

add util function to set mouse visibility

Kolja Strohm 2 years ago
parent
commit
110babd4cf
2 changed files with 144 additions and 131 deletions
  1. 81 70
      Global.cpp
  2. 63 61
      Globals.h

+ 81 - 70
Global.cpp

@@ -16,131 +16,142 @@
 #include "Zeit.h"
 #include "DLLRegister.h"
 
-void Framework::initFramework( HINSTANCE__* hInst )
+void Framework::initFramework(HINSTANCE__* hInst)
 {
-    if( istInitialisiert )
-        return;
-    thRegister = new ThreadRegister();
+	if (istInitialisiert)
+		return;
+	thRegister = new ThreadRegister();
 #ifdef WIN32
-    Gdiplus::GdiplusStartupInput gdiplusStartupInput;
-    ULONG_PTR gdiplusToken;
-    Gdiplus::GdiplusStartup( &gdiplusToken, &gdiplusStartupInput, 0 );
-    msgExit = 0;
-    MausTrack = 1;
+	Gdiplus::GdiplusStartupInput gdiplusStartupInput;
+	ULONG_PTR gdiplusToken;
+	Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, 0);
+	msgExit = 0;
+	MausTrack = 1;
 #endif
-    for( int i = 0; i < 255; ++i )
-        TastenStand[ i ] = 0;
-    for( int i = 0; i < 3; ++i )
-        MausStand[ i ] = 0;
-    TexturList::init();
-    dlls = new DLLRegister();
-    logEnabled = 0;
-    logFile = 0;
-    _hinst = hInst;
-    istInitialisiert = 1;
-    debugDX = 0;
+	for (int i = 0; i < 255; ++i)
+		TastenStand[i] = 0;
+	for (int i = 0; i < 3; ++i)
+		MausStand[i] = 0;
+	TexturList::init();
+	dlls = new DLLRegister();
+	logEnabled = 0;
+	logFile = 0;
+	_hinst = hInst;
+	istInitialisiert = 1;
+	debugDX = 0;
 }
 
 void Framework::releaseFramework()
 {
-    if( !istInitialisiert )
-        return;
-    thRegister->cleanUpClosedThreads();
-    dlls->release();
-    TexturList::destroy();
-    if( logFile )
-        logFile->release();
-    delete thRegister;
-    istInitialisiert = 0;
+	if (!istInitialisiert)
+		return;
+	thRegister->cleanUpClosedThreads();
+	dlls->release();
+	TexturList::destroy();
+	if (logFile)
+		logFile->release();
+	delete thRegister;
+	istInitialisiert = 0;
 }
 
-bool Framework::istThreadOk( Thread* t )
+bool Framework::istThreadOk(Thread* t)
 {
-    return thRegister->isThread( t );
+	return thRegister->isThread(t);
 }
 
 // Gibt das Thread Register des Frameworks zurück
 Framework::ThreadRegister* Framework::getThreadRegister()
 {
-    return thRegister;
+	return thRegister;
 }
 
 #ifdef WIN32
 
 const Framework::Punkt& Framework::getMausPos()
 {
-    return mausPos;
+	return mausPos;
 }
 
 #endif
 
-bool Framework::getMausStand( int taste )
+bool Framework::getMausStand(int taste)
 {
-    return MausStand[ taste ];
+	return MausStand[taste];
 }
 
-void Framework::setTastenStand( unsigned char taste, bool st )
+void Framework::setTastenStand(unsigned char taste, bool st)
 {
-    TastenStand[ taste ] = st;
+	TastenStand[taste] = st;
 }
 
-bool Framework::getTastenStand( unsigned char taste )
+bool Framework::getTastenStand(unsigned char taste)
 {
-    return TastenStand[ taste ];
+	return TastenStand[taste];
 }
 
 // Legt fest ob Log Nachrichten gespeichert werden sollen
-void Framework::setLogEnabled( bool le )
+void Framework::setLogEnabled(bool le)
 {
-    logEnabled = le;
+	logEnabled = le;
 }
 
 // Speichert eine Zeile in die Logdatei
 //  txt: die zu Speichernde Nachricht
-void Framework::logLine( char* txt )
+void Framework::logLine(char* txt)
 {
-    if( logEnabled )
-    {
-        logC.lock();
-        if( !logFile )
-        {
-            Zeit* z = getZeit();
-            logFile = new Datei();
-            logFile->setDatei( z->getZeit( "y-m-d h-i-s.log" ) );
-            logFile->erstellen();
-            z->release();
-        }
-        logFile->open( Datei::Style::schreiben | Datei::Style::lesen | Datei::Style::ende );
-        Uhrzeit* uz = getUhrzeit();
-        Text* time = uz->getUhrzeit( "h:i:s" );
-        time->append( "_" );
-        time->append( (int)GetThreadId( GetCurrentThread() ) );
-        time->append( ": " );
-        logFile->schreibe( time->getText(), time->getLength() );
-        time->release();
-        logFile->schreibe( txt, textLength( txt ) );
-        logFile->schreibe( (char*)"\n", 1 );
-        logFile->close();
-        logC.unlock();
-    }
+	if (logEnabled)
+	{
+		logC.lock();
+		if (!logFile)
+		{
+			Zeit* z = getZeit();
+			logFile = new Datei();
+			logFile->setDatei(z->getZeit("y-m-d h-i-s.log"));
+			logFile->erstellen();
+			z->release();
+		}
+		logFile->open(Datei::Style::schreiben | Datei::Style::lesen | Datei::Style::ende);
+		Uhrzeit* uz = getUhrzeit();
+		Text* time = uz->getUhrzeit("h:i:s");
+		time->append("_");
+		time->append((int)GetThreadId(GetCurrentThread()));
+		time->append(": ");
+		logFile->schreibe(time->getText(), time->getLength());
+		time->release();
+		logFile->schreibe(txt, textLength(txt));
+		logFile->schreibe((char*)"\n", 1);
+		logFile->close();
+		logC.unlock();
+	}
 }
 
 // Gibt das DLL Register zurück, in dem alle zurzeit dynamisch geladenen DLL Dateien hinterlegt sind
 Framework::DLLRegister* Framework::getDLLRegister()
 {
-    return Framework::dlls;
+	return Framework::dlls;
 }
 
 //! Versetzt DirectX in den Debug modus
-void Framework::setDebugDX( bool debug )
+void Framework::setDebugDX(bool debug)
 {
-    debugDX = debug;
+	debugDX = debug;
 }
 
 #ifdef WIN32
 // gibt eine Referenz auf die Maus zurück
 Framework::Maus& Framework::getMaus()
 {
-    return Framework::MausZeiger;
+	return Framework::MausZeiger;
 }
+
+//! setzt den Zustand der Maus auf sichtbar oder unsichtbar
+void Framework::setShowCursor(bool visible)
+{
+	CURSORINFO info = { 0 };
+	info.cbSize = sizeof(CURSORINFO);
+	GetCursorInfo(&info);
+	if ((info.flags != 0) == (visible == 0))
+		ShowCursor(visible);
+}
+
 #endif

+ 63 - 61
Globals.h

@@ -12,75 +12,77 @@ struct HINSTANCE__; //! windows.h
 
 namespace Framework
 {
-    class ThreadRegister; //! Thread.h
-    class Thread; //! Thread.h
-    class Model3DList; //! Model3DList.h
-    class TexturList; //! TexturList.h
-    class Datei; //! Datei.h
-    class DLLRegister; //! DLLRegister.h
+	class ThreadRegister; //! Thread.h
+	class Thread; //! Thread.h
+	class Model3DList; //! Model3DList.h
+	class TexturList; //! TexturList.h
+	class Datei; //! Datei.h
+	class DLLRegister; //! DLLRegister.h
 
 #ifdef WIN32
-    class Maus; //! Maus.h
-    class WFensterArray; //! Fenster.h
+	class Maus; //! Maus.h
+	class WFensterArray; //! Fenster.h
 
-    Global WFensterArray WFensterA;
-    Global bool MausTrack;
-    Global Maus MausZeiger;
-    Global bool msgExit;
-    Global Punkt mausPos;
+	Global WFensterArray WFensterA;
+	Global bool MausTrack;
+	Global Maus MausZeiger;
+	Global bool msgExit;
+	Global Punkt mausPos;
 #endif
-    Global bool TastenStand[ 255 ];
-    Global bool MausStand[ 3 ];
-    Global bool istInitialisiert;
-    Global ThreadRegister* thRegister;
-    Global bool logEnabled;
-    Global Datei* logFile;
-    Global Critical logC;
-    Global HINSTANCE__* _hinst;
-    Global DLLRegister* dlls;
-    Global bool debugDX;
+	Global bool TastenStand[255];
+	Global bool MausStand[3];
+	Global bool istInitialisiert;
+	Global ThreadRegister* thRegister;
+	Global bool logEnabled;
+	Global Datei* logFile;
+	Global Critical logC;
+	Global HINSTANCE__* _hinst;
+	Global DLLRegister* dlls;
+	Global bool debugDX;
 
 #ifdef WIN32
-    //! Gibt die Koordinaten der Maus auf dem Bildschirm zurück
-    DLLEXPORT const Punkt& getMausPos();
+	//! Gibt die Koordinaten der Maus auf dem Bildschirm zurück
+	DLLEXPORT const Punkt& getMausPos();
 #endif
-    //! Gibt zurück, ob eine Taste der Maus momentan gedrückt wird
-    //! \param taste Die Taste, die geprüft werden soll
-    //! Beispiel: getMausStand( M_Links ); (Benötigt include <MausEreignis.h>
-    DLLEXPORT bool getMausStand( int taste );
-    //! Gibt zurück, ob eine Taste auf der tastatur momentan gedrückt wird
-    //! \param taste Die Taste, die überprüft werden soll
-    //! Beispiel: getTastenStand( T_Enter ); (Benötogt include <TastaturEreignis.h>
-    DLLEXPORT bool getTastenStand( unsigned char taste );
-    //! Legt fest, ob eine Taste auf der tastatur momentan gedrückt wird
-    //! Der Tastenstand wird vom Framework selbst verwaltet und muss nicht mit dieser Funktion gesetzt werden
-    //! \param taste Die Taste, deren Status gesetzt werden soll
-    //! \param st Ob die Taste momentan gedrückt wird. (true), wenn ja. (false) sonnst.
-    DLLEXPORT void setTastenStand( unsigned char taste, bool st );
-    //! Initialisiert das Framework
-    //! Wird in der (WinMain) des Frameworks automatisch aufgerufen
-    DLLEXPORT void initFramework( HINSTANCE__* hInst = 0 );
-    //! Gibt den duch (initFramework) benutzten Arbeitsspeicher wieder frei
-    //! Wird in der (WinMain) des Frameworks automatisch aufgerufen
-    DLLEXPORT void releaseFramework();
-    //! Überprüft, ob ein bestimmter Zeiger auf ein Gültiges Thread Objekt zeigt
-    //! \param t Der zeiger, der überprüft werden soll
-    //! \return 1, falls der Zeiger in Ordnung ist. 0, falls der Zeiger auf kein existentes Thread Objekt zeigt
-    DLLEXPORT bool istThreadOk( Thread* t );
-    //! Gibt das Thread Register des Frameworks zurück
-    DLLEXPORT ThreadRegister* getThreadRegister();
-    //! Legt fest ob Log Nachrichten gespeichert werden sollen
-    DLLEXPORT void setLogEnabled( bool le );
-    //! Speichert eine Zeile in die Logdatei
-    //! \param txt die zu Speichernde Nachricht
-    DLLEXPORT void logLine( char* txt );
-    //! Gibt das DLL Register zurück, in dem alle zurzeit dynamisch geladenen DLL Dateien hinterlegt sind
-    DLLEXPORT DLLRegister* getDLLRegister();
-    //! Versetzt DirectX in den Debug modus
-    DLLEXPORT void setDebugDX( bool debug );
+	//! Gibt zurück, ob eine Taste der Maus momentan gedrückt wird
+	//! \param taste Die Taste, die geprüft werden soll
+	//! Beispiel: getMausStand( M_Links ); (Benötigt include <MausEreignis.h>
+	DLLEXPORT bool getMausStand(int taste);
+	//! Gibt zurück, ob eine Taste auf der tastatur momentan gedrückt wird
+	//! \param taste Die Taste, die überprüft werden soll
+	//! Beispiel: getTastenStand( T_Enter ); (Benötogt include <TastaturEreignis.h>
+	DLLEXPORT bool getTastenStand(unsigned char taste);
+	//! Legt fest, ob eine Taste auf der tastatur momentan gedrückt wird
+	//! Der Tastenstand wird vom Framework selbst verwaltet und muss nicht mit dieser Funktion gesetzt werden
+	//! \param taste Die Taste, deren Status gesetzt werden soll
+	//! \param st Ob die Taste momentan gedrückt wird. (true), wenn ja. (false) sonnst.
+	DLLEXPORT void setTastenStand(unsigned char taste, bool st);
+	//! Initialisiert das Framework
+	//! Wird in der (WinMain) des Frameworks automatisch aufgerufen
+	DLLEXPORT void initFramework(HINSTANCE__* hInst = 0);
+	//! Gibt den duch (initFramework) benutzten Arbeitsspeicher wieder frei
+	//! Wird in der (WinMain) des Frameworks automatisch aufgerufen
+	DLLEXPORT void releaseFramework();
+	//! Überprüft, ob ein bestimmter Zeiger auf ein Gültiges Thread Objekt zeigt
+	//! \param t Der zeiger, der überprüft werden soll
+	//! \return 1, falls der Zeiger in Ordnung ist. 0, falls der Zeiger auf kein existentes Thread Objekt zeigt
+	DLLEXPORT bool istThreadOk(Thread* t);
+	//! Gibt das Thread Register des Frameworks zurück
+	DLLEXPORT ThreadRegister* getThreadRegister();
+	//! Legt fest ob Log Nachrichten gespeichert werden sollen
+	DLLEXPORT void setLogEnabled(bool le);
+	//! Speichert eine Zeile in die Logdatei
+	//! \param txt die zu Speichernde Nachricht
+	DLLEXPORT void logLine(char* txt);
+	//! Gibt das DLL Register zurück, in dem alle zurzeit dynamisch geladenen DLL Dateien hinterlegt sind
+	DLLEXPORT DLLRegister* getDLLRegister();
+	//! Versetzt DirectX in den Debug modus
+	DLLEXPORT void setDebugDX(bool debug);
 #ifdef WIN32
-    //! gibt eine Referenz auf die Maus zurück
-    DLLEXPORT Maus& getMaus();
+	//! gibt eine Referenz auf die Maus zurück
+	DLLEXPORT Maus& getMaus();
+	//! setzt den Zustand der Maus auf sichtbar oder unsichtbar
+	DLLEXPORT void setShowCursor(bool visible);
 #endif
 }