Global.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. #ifdef WIN32
  2. # include <GdiPlus.h>
  3. # include <Windows.h>
  4. # pragma comment(lib, "gdiplus.lib")
  5. # include "Fenster.h"
  6. # include "Maus.h"
  7. #endif
  8. #define Global
  9. #include "Datei.h"
  10. #include "DLLRegister.h"
  11. #include "Fenster.h"
  12. #include "Globals.h"
  13. #include "Model3DList.h"
  14. #include "TexturList.h"
  15. #include "Thread.h"
  16. #include "Zeit.h"
  17. void Framework::initFramework(HINSTANCE__* hInst)
  18. {
  19. if (istInitialisiert) return;
  20. thRegister = new ThreadRegister();
  21. #ifdef WIN32
  22. Gdiplus::GdiplusStartupInput gdiplusStartupInput;
  23. ULONG_PTR gdiplusToken;
  24. Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, 0);
  25. msgExit = 0;
  26. MausTrack = 1;
  27. #endif
  28. for (int i = 0; i < 3; ++i)
  29. MausStand[i] = 0;
  30. TexturList::init();
  31. dlls = new DLLRegister();
  32. logEnabled = 0;
  33. logFile = 0;
  34. _hinst = hInst;
  35. istInitialisiert = 1;
  36. debugDX = 0;
  37. }
  38. void Framework::releaseFramework()
  39. {
  40. if (!istInitialisiert) return;
  41. thRegister->cleanUpClosedThreads();
  42. dlls->release();
  43. TexturList::destroy();
  44. if (logFile) logFile->release();
  45. delete thRegister;
  46. istInitialisiert = 0;
  47. }
  48. bool Framework::istThreadOk(Thread* t)
  49. {
  50. return thRegister->isThread(t);
  51. }
  52. // Gibt das Thread Register des Frameworks zurück
  53. Framework::ThreadRegister* Framework::getThreadRegister()
  54. {
  55. return thRegister;
  56. }
  57. #ifdef WIN32
  58. Framework::Punkt Framework::getMausPos()
  59. {
  60. POINT point;
  61. GetCursorPos(&point);
  62. return {point.x, point.y};
  63. }
  64. //! Setzt die Position der Maus auf dem Bildschirm
  65. void Framework::setMausPos(const Punkt& pos)
  66. {
  67. SetCursorPos(pos.x, pos.y);
  68. }
  69. #endif
  70. bool Framework::getMausStand(int taste)
  71. {
  72. return MausStand[taste];
  73. }
  74. bool Framework::getTastenStand(unsigned char taste)
  75. {
  76. #ifdef WIN32
  77. return GetKeyState(taste) & 0x8000;
  78. #else
  79. return 0;
  80. #endif
  81. }
  82. // Legt fest ob Log Nachrichten gespeichert werden sollen
  83. void Framework::setLogEnabled(bool le)
  84. {
  85. logEnabled = le;
  86. }
  87. // Speichert eine Zeile in die Logdatei
  88. // txt: die zu Speichernde Nachricht
  89. void Framework::logLine(char* txt)
  90. {
  91. if (logEnabled)
  92. {
  93. logC.lock();
  94. if (!logFile)
  95. {
  96. Zeit* z = getZeit();
  97. logFile = new Datei();
  98. logFile->setDatei(z->getZeit("y-m-d h-i-s.log"));
  99. logFile->erstellen();
  100. z->release();
  101. }
  102. logFile->open(
  103. Datei::Style::schreiben | Datei::Style::lesen | Datei::Style::ende);
  104. Uhrzeit* uz = getUhrzeit();
  105. Text* time = uz->getUhrzeit("h:i:s");
  106. time->append("_");
  107. time->append((int)GetThreadId(GetCurrentThread()));
  108. time->append(": ");
  109. logFile->schreibe(time->getText(), time->getLength());
  110. time->release();
  111. logFile->schreibe(txt, textLength(txt));
  112. logFile->schreibe("\n", 1);
  113. logFile->close();
  114. logC.unlock();
  115. }
  116. }
  117. // Gibt das DLL Register zurück, in dem alle zurzeit dynamisch geladenen DLL
  118. // Dateien hinterlegt sind
  119. Framework::DLLRegister* Framework::getDLLRegister()
  120. {
  121. return Framework::dlls;
  122. }
  123. //! Versetzt DirectX in den Debug modus
  124. void Framework::setDebugDX(bool debug)
  125. {
  126. debugDX = debug;
  127. }
  128. #ifdef WIN32
  129. // gibt eine Referenz auf die Maus zurück
  130. Framework::Maus& Framework::getMaus()
  131. {
  132. return Framework::MausZeiger;
  133. }
  134. //! setzt den Zustand der Maus auf sichtbar oder unsichtbar
  135. void Framework::setShowCursor(bool visible)
  136. {
  137. CURSORINFO info = {0};
  138. info.cbSize = sizeof(CURSORINFO);
  139. GetCursorInfo(&info);
  140. if ((info.flags != 0) == (visible == 0)) ShowCursor(visible);
  141. }
  142. #endif