Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

Application.cpp

Go to the documentation of this file.
00001 
00007 #include "Application.h"
00008 
00009 /********************************************************************
00010  * Constructor
00011  */
00012 Application::Application() {
00013         memset(keys, 0, sizeof(keys));  // no keys pressed
00014 
00015         defaultFont = NULL;
00016 
00017         mouse.left = false;
00018         mouse.right = false;
00019         mouse.visible = true;
00020         mouse.capture = false;
00021         mouse.dx = mouse.dy = 0.0f;
00022 }
00023 
00024 /********************************************************************
00025  * Destructor
00026  */
00027 Application::~Application() {
00028 }
00029 
00030 /********************************************************************
00031  * Toggle fullscreen
00032  */
00033 void Application::toggleFullscreen() {
00034         PostMessage(hWnd, WM_TOGGLEFULLSCREEN, 0, 0);
00035 }
00036 
00037 /********************************************************************
00038  * Reset display mode
00039  */
00040 bool Application::resetDisplayMode() {
00041         return (ChangeDisplaySettings(NULL, 0) == DISP_CHANGE_SUCCESSFUL);
00042 }
00043 
00044 /********************************************************************
00045  * Set key
00046  */
00047 void Application::setKey(unsigned int key, bool value) {
00048         keys[key & 0xffff] = value;
00049 }
00050 
00051 /********************************************************************
00052  * Handle char
00053  */
00054 void Application::handleChar(char ch) {
00055         // some console and chat stuff?
00056 }
00057 
00058 /********************************************************************
00059  * Key down
00060  */
00061 void Application::keyDown(unsigned int key) {
00062         switch(key & 0xffff) {
00063                 case VK_ESCAPE:
00064                         PostMessage(hWnd, WM_CLOSE, 0, 0);
00065                         return;
00066 
00067                 case VK_F1:
00068                         toggleFullscreen();
00069                         return;
00070 
00071                 default:
00072                         setKey(key, true);
00073                         break;
00074         }
00075 }
00076 
00077 /********************************************************************
00078  * Set cursor pos
00079  */
00080 void Application::setCursorPos(int x, int y) {
00081         SetCursorPos(x, y);
00082 }
00083 
00084 /********************************************************************
00085  * Show cursor
00086  */
00087 void Application::showCursor(bool value) {
00088         if (value != mouse.visible) {
00089                 ShowCursor(value);
00090                 mouse.visible = value;
00091         }
00092 }
00093 
00094 /********************************************************************
00095  * Set mouse button
00096  */
00097 void Application::setMouseButton(unsigned int button, bool value) {
00098         if (button == MOUSE_LEFT)
00099                 mouse.left = value;
00100         else
00101                 mouse.right = value;
00102 }
00103 
00104 /********************************************************************
00105  * Capture mouse
00106  */
00107 void Application::captureMouse(bool value) {
00108         static bool curVisible;
00109 
00110         if (mouse.capture == value)
00111                 return;
00112 
00113         if (value) {
00114                 if (!mouse.capture)
00115                         setCursorPos(g_middleX, g_middleY);
00116 
00117                 curVisible = mouse.visible;
00118                 showCursor(false);
00119         }
00120         else {
00121                 showCursor(curVisible);
00122         }
00123 
00124         mouse.capture = value;
00125 }
00126 
00127 /********************************************************************
00128  * Check mouse
00129  */
00130 void Application::checkMouse() {
00131         if (mouse.capture) {
00132                 POINT point;
00133                 GetCursorPos(&point);
00134 
00135                 mouse.x = point.x;
00136                 mouse.y = point.y;
00137 
00138                 mouse.dx = mouse.x - g_middleX;
00139                 mouse.dy = mouse.y - g_middleY;
00140 
00141                 setCursorPos(g_middleX, g_middleY);
00142         }
00143 }

Generated on Sun Jun 5 15:47:03 2005 for Defacto by  doxygen 1.4.3