2009-05-08 13:28:41 +00:00
|
|
|
/*
|
|
|
|
* OpenClonk, http://www.openclonk.org
|
|
|
|
*
|
2009-06-05 13:41:20 +00:00
|
|
|
* Copyright (c) 2006 Julian Raschke
|
|
|
|
* Copyright (c) 2008-2009 Günther Brammer
|
2010-12-23 00:01:24 +00:00
|
|
|
* Copyright (c) 2009 Mortimer
|
|
|
|
* Copyright (c) 2010 Benjamin Herr
|
|
|
|
* Copyright (c) 2010 Peter Wortmann
|
2009-05-08 13:28:41 +00:00
|
|
|
* Copyright (c) 2005-2009, RedWolf Design GmbH, http://www.clonk.de
|
|
|
|
*
|
|
|
|
* Portions might be copyrighted by other authors who have contributed
|
|
|
|
* to OpenClonk.
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
* See isc_license.txt for full license and disclaimer.
|
|
|
|
*
|
|
|
|
* "Clonk" is a registered trademark of Matthes Bender.
|
|
|
|
* See clonk_trademark_license.txt for full license.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* A wrapper class to OS dependent event and window interfaces, SDL version */
|
|
|
|
|
2010-03-04 21:12:35 +00:00
|
|
|
#include <C4Include.h>
|
2009-05-08 13:28:41 +00:00
|
|
|
#include <StdWindow.h>
|
|
|
|
#include <StdGL.h>
|
|
|
|
#include <StdDDraw2.h>
|
|
|
|
#include <StdFile.h>
|
|
|
|
#include <StdBuf.h>
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <sstream>
|
|
|
|
#include <sys/select.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
/* CStdApp */
|
|
|
|
|
|
|
|
CStdApp::CStdApp(): Active(false), fQuitMsgReceived(false),
|
2010-03-28 18:58:01 +00:00
|
|
|
Location(""), DoNotDelay(false), MainThread(pthread_self()), fDspModeSet(false)
|
2009-05-08 13:28:41 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-03-28 18:58:01 +00:00
|
|
|
CStdApp::~CStdApp()
|
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
}
|
|
|
|
|
2010-03-28 18:58:01 +00:00
|
|
|
bool CStdApp::Init(int argc, char * argv[])
|
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
// Set locale
|
|
|
|
setlocale(LC_ALL,"");
|
|
|
|
|
|
|
|
// SDLmain.m copied the executable path into argv[0];
|
2009-05-12 21:41:45 +00:00
|
|
|
// just copy it (not sure if original buffer is guaranteed
|
|
|
|
// to be permanent).
|
2009-05-08 13:28:41 +00:00
|
|
|
static char dir[PATH_MAX];
|
|
|
|
SCopy(argv[0], dir);
|
|
|
|
Location = dir;
|
|
|
|
|
2011-01-08 01:18:36 +00:00
|
|
|
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_NOPARACHUTE) < 0)
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
|
|
|
Log("Error initializing SDL.");
|
2009-05-08 13:28:41 +00:00
|
|
|
return false;
|
2009-05-12 21:41:45 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
2009-05-12 21:41:45 +00:00
|
|
|
SDL_EnableUNICODE(1);
|
2009-08-12 12:16:35 +00:00
|
|
|
SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
// Custom initialization
|
2010-10-04 19:39:19 +00:00
|
|
|
return DoInit (argc, argv);
|
2009-05-08 13:28:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-28 18:58:01 +00:00
|
|
|
void CStdApp::Clear()
|
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
SDL_Quit();
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
2010-03-28 18:58:01 +00:00
|
|
|
void CStdApp::Quit()
|
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
fQuitMsgReceived = true;
|
|
|
|
}
|
|
|
|
|
2010-03-28 18:58:01 +00:00
|
|
|
bool CStdApp::FlushMessages()
|
|
|
|
{
|
2009-05-12 21:41:45 +00:00
|
|
|
// Always fail after quit message
|
2010-03-28 18:58:01 +00:00
|
|
|
if (fQuitMsgReceived)
|
2009-05-12 21:41:45 +00:00
|
|
|
return false;
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
// Handle pending SDL messages
|
|
|
|
SDL_Event event;
|
2010-03-28 18:58:01 +00:00
|
|
|
while (SDL_PollEvent(&event))
|
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
HandleSDLEvent(event);
|
|
|
|
}
|
2009-05-12 21:41:45 +00:00
|
|
|
return true;
|
2009-05-08 13:28:41 +00:00
|
|
|
}
|
|
|
|
|
2010-03-28 18:58:01 +00:00
|
|
|
void CStdApp::HandleSDLEvent(SDL_Event& event)
|
|
|
|
{
|
|
|
|
// Directly handle QUIT messages.
|
|
|
|
switch (event.type)
|
|
|
|
{
|
|
|
|
case SDL_QUIT:
|
|
|
|
Quit();
|
|
|
|
break;
|
2009-05-08 13:28:41 +00:00
|
|
|
}
|
2010-03-28 18:58:01 +00:00
|
|
|
|
2009-08-12 12:30:48 +00:00
|
|
|
#ifdef __APPLE__
|
|
|
|
MacUtility::ensureWindowInFront();
|
|
|
|
#endif
|
2009-05-08 13:28:41 +00:00
|
|
|
|
2010-03-28 18:58:01 +00:00
|
|
|
// Everything else goes to the window.
|
2009-05-08 13:28:41 +00:00
|
|
|
if (pWindow)
|
|
|
|
pWindow->HandleMessage(event);
|
|
|
|
}
|
|
|
|
|
2011-01-24 22:32:51 +00:00
|
|
|
bool CStdApp::GetIndexedDisplayMode(int32_t iIndex, int32_t *piXRes, int32_t *piYRes, int32_t *piBitDepth, int32_t *piRefreshRate, uint32_t iMonitor)
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-12 21:41:45 +00:00
|
|
|
// No support for multiple monitors.
|
|
|
|
if (iMonitor != 0)
|
|
|
|
return false;
|
2009-05-08 13:28:41 +00:00
|
|
|
|
2009-05-12 21:41:45 +00:00
|
|
|
static SDL_Rect** modes = 0;
|
|
|
|
static unsigned modeCount = 0;
|
2010-03-28 18:58:01 +00:00
|
|
|
if (!modes)
|
|
|
|
{
|
2009-05-12 21:41:45 +00:00
|
|
|
modes = SDL_ListModes(NULL, SDL_OPENGL | SDL_FULLSCREEN);
|
|
|
|
// -1 means "all modes allowed". Clonk is not prepared
|
|
|
|
// for this; should probably give some random resolutions
|
|
|
|
// then.
|
|
|
|
assert(reinterpret_cast<intptr_t>(modes) != -1);
|
|
|
|
if (!modes)
|
|
|
|
modeCount = 0;
|
|
|
|
else
|
2010-03-28 18:58:01 +00:00
|
|
|
// Count available modes.
|
|
|
|
for (SDL_Rect** iter = modes; *iter; ++iter)
|
|
|
|
++modeCount;
|
2009-05-12 21:41:45 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
2009-05-12 21:41:45 +00:00
|
|
|
if (iIndex >= modeCount)
|
|
|
|
return false;
|
2009-05-08 13:28:41 +00:00
|
|
|
|
2009-05-12 21:41:45 +00:00
|
|
|
*piXRes = modes[iIndex]->w;
|
|
|
|
*piYRes = modes[iIndex]->h;
|
|
|
|
*piBitDepth = SDL_GetVideoInfo()->vfmt->BitsPerPixel;
|
|
|
|
return true;
|
2009-05-08 13:28:41 +00:00
|
|
|
}
|
|
|
|
|
2011-01-24 22:32:51 +00:00
|
|
|
bool CStdApp::SetVideoMode(unsigned int iXRes, unsigned int iYRes, unsigned int iColorDepth, unsigned int RefreshRate, unsigned int iMonitor, bool fFullScreen)
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2011-01-08 01:18:36 +00:00
|
|
|
//RECT r;
|
|
|
|
//pWindow->GetSize(&r);
|
|
|
|
// FIXME: optimize redundant calls away. maybe make all platforms implicitely call SetVideoMode in CStdWindow::Init?
|
2009-05-12 21:42:34 +00:00
|
|
|
// SDL doesn't support multiple monitors.
|
2010-03-28 18:58:01 +00:00
|
|
|
if (!SDL_SetVideoMode(iXRes, iYRes, iColorDepth, SDL_OPENGL | (fFullScreen ? SDL_FULLSCREEN : 0)))
|
|
|
|
{
|
2009-05-12 21:42:34 +00:00
|
|
|
sLastError.Copy(SDL_GetError());
|
|
|
|
return false;
|
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
SDL_ShowCursor(SDL_DISABLE);
|
2009-05-12 21:42:34 +00:00
|
|
|
pWindow->SetSize(iXRes, iYRes);
|
|
|
|
OnResolutionChanged(iXRes, iYRes);
|
|
|
|
return true;
|
2009-05-08 13:28:41 +00:00
|
|
|
}
|
|
|
|
|
2010-03-28 18:58:01 +00:00
|
|
|
void CStdApp::RestoreVideoMode()
|
|
|
|
{
|
2009-05-12 21:41:45 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
2010-02-11 13:19:13 +00:00
|
|
|
// For Max OS X, the implementation resides in StdMacApp.mm
|
|
|
|
#ifndef __APPLE__
|
2009-05-08 13:28:41 +00:00
|
|
|
|
2010-02-11 13:19:13 +00:00
|
|
|
// stubs
|
2010-11-04 01:08:02 +00:00
|
|
|
bool CStdApp::Copy(const StdStrBuf & text, bool fClipboard)
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
}
|
2009-08-12 12:17:36 +00:00
|
|
|
|
2010-03-28 18:58:01 +00:00
|
|
|
StdStrBuf CStdApp::Paste(bool fClipboard)
|
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
return StdStrBuf(0);
|
|
|
|
}
|
2009-08-12 12:17:36 +00:00
|
|
|
|
2010-03-28 18:58:01 +00:00
|
|
|
bool CStdApp::IsClipboardFull(bool fClipboard)
|
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
return false;
|
|
|
|
}
|
2009-08-12 12:17:36 +00:00
|
|
|
|
2010-03-28 18:58:01 +00:00
|
|
|
void CStdApp::ClearClipboard(bool fClipboard)
|
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
}
|
|
|
|
|
2009-08-12 12:17:36 +00:00
|
|
|
void CStdApp::MessageDialog(const char * message)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-02-11 13:19:13 +00:00
|
|
|
#endif
|