00001 #include "global.h"
00002 #include <stdio.h>
00003 #include <stdlib.h>
00004 #include <string.h>
00005 #include "MercuryWindow.h"
00006 #include "MercuryInput.h"
00007 #include "MercuryINI.h"
00008 #include "MercuryUtil.h"
00009
00010 #define MC_INPUTMAPPED 1 //convention: MESSAGE CODE
00011 #define MC_INPUTUNMAPPED 2
00012
00013 KeyMappingWithCode( button_alt, "0-18" );
00014 KeyMappingWithCode( button_enter, "0-13" );
00015
00016 MercuryWindow::MercuryWindow(int width, int height, bool fullscreen)
00017 {
00018 m_title = NULL;
00019 m_width = width;
00020 m_height = height;
00021 m_fullscreen = fullscreen;
00022 m_minimized = false;
00023 m_alt_held = false;
00024 this->RegisterMessage( MC_INPUTMAPPED, "mappedinput" );
00025
00026 m_fSimFramerate = PREFSMAN->GetValueF( "Rendering", "SimFramerate", 60, true );
00027 m_bEnableFrameTimer = PREFSMAN->GetValueB( "Rendering", "EnableFrameTimer", false, true );
00028
00029 }
00030
00031 MercuryWindow::~MercuryWindow()
00032 {
00033 ClearTitle();
00034 }
00035
00036 void MercuryWindow::SetDemensions(int width, int height)
00037 {
00038 m_width = width;
00039 m_height = height;
00040 }
00041
00042 void MercuryWindow::SetTitle(const char* title)
00043 {
00044 int length = strlen(title) + 1;
00045
00046 ClearTitle();
00047
00048 m_title = new char[length];
00049 memcpy(m_title, title, length-1);
00050 m_title[length-1] = char(NULL);
00051 }
00052
00053 void MercuryWindow::ClearTitle()
00054 {
00055 SAFE_DELETE_ARRAY(m_title);
00056 if (m_title != NULL)
00057 {
00058 memset(m_title, 0, strlen(m_title) + 1);
00059 SAFE_DELETE_ARRAY(m_title);
00060 }
00061 }
00062
00063 void MercuryWindow::SwapBuffers()
00064 {
00065 if ( m_bEnableFrameTimer )
00066 {
00067 float TTG = (1000/m_fSimFramerate) - float(m_tFrameTimer.Age()) * 1000 - 1;
00068 if ( TTG > 0 )
00069 Sleep( (float)TTG );
00070 }
00071 SwapBuffersInternal();
00072 if ( m_bEnableFrameTimer )
00073 m_tFrameTimer.Touch();
00074 }
00075
00076
00077 void MercuryWindow::Message( int Message, PStack & data, const MString & name )
00078 {
00079 switch ( Message )
00080 {
00081 case MC_INPUTMAPPED:
00082 {
00083 InputMessageStruct c(data);
00084 if ( c.code == button_alt )
00085 {
00086 if ( c.type == IET_DOWN )
00087 m_alt_held = true;
00088
00089 if ( c.type == IET_RELEASE )
00090 m_alt_held = false;
00091
00092 }
00093 if (c.code == button_enter)
00094 {
00095 if ( c.type == IET_RELEASE )
00096 {
00097 if (m_alt_held)
00098 {
00099 MString tmp = m_title;
00100 DestroyWindow();
00101 m_fullscreen = !m_fullscreen;
00102 MakeWindow(tmp, m_width, m_height, m_bits, m_fullscreen);
00103 RestoreDevice();
00104 }
00105 }
00106 }
00107 }
00108 break;
00109 };
00110 }
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138