MercuryWindow.cpp

Go to the documentation of this file.
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  * Copyright (c) 2005-2006, Joshua Allen
00114  * All rights reserved.
00115  *
00116  * Redistribution and use in source and binary forms, with or
00117  * without modification, are permitted provided that the following
00118  * conditions are met:
00119  *  -   Redistributions of source code must retain the above
00120  *      copyright notice, this list of conditions and the following disclaimer.
00121  *  -   Redistributions in binary form must reproduce the above copyright
00122  *      notice, this list of conditions and the following disclaimer in
00123  *      the documentation and/or other materials provided with the distribution.
00124  *  -   Neither the name of the Mercury Engine nor the names of its
00125  *      contributors may be used to endorse or promote products derived from
00126  *      this software without specific prior written permission.
00127  *
00128  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00129  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00130  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00131  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
00132  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00133  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00134  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00135  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00136  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
00137  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00138  */

Hosted by SourceForge.net Logo