2011-03-19 21:09:10 +00:00
|
|
|
/*
|
|
|
|
* OpenClonk, http://www.openclonk.org
|
|
|
|
*
|
2013-01-09 23:23:06 +00:00
|
|
|
* Copyright (c) 2005-2006, 2010-2012 Günther Brammer
|
2011-03-19 21:09:10 +00:00
|
|
|
* Copyright (c) 2005 Sven Eberhardt
|
|
|
|
* Copyright (c) 2006 Armin Burgmeier
|
|
|
|
* Copyright (c) 2009 Peter Wortmann
|
2011-09-01 10:47:54 +00:00
|
|
|
* Copyright (c) 2010 Martin Plicht
|
2011-03-19 21:09:10 +00:00
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef INC_STDAPP
|
|
|
|
#define INC_STDAPP
|
|
|
|
|
|
|
|
#include <StdScheduler.h>
|
|
|
|
#include <StdSync.h>
|
2012-11-30 17:30:00 +00:00
|
|
|
#include <C4StdInProc.h>
|
2011-03-19 21:09:10 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_PTHREAD
|
|
|
|
#include <pthread.h>
|
|
|
|
#endif
|
|
|
|
|
2012-03-23 21:53:56 +00:00
|
|
|
#if defined(USE_X11)
|
2011-03-19 21:09:10 +00:00
|
|
|
// from X.h:
|
|
|
|
//#define ShiftMask (1<<0)
|
|
|
|
//#define ControlMask (1<<2)
|
|
|
|
#define MK_CONTROL (1<<2)
|
|
|
|
#define MK_SHIFT (1<<0)
|
2012-03-22 20:08:19 +00:00
|
|
|
#define MK_ALT (1<<3)
|
2011-03-19 21:09:10 +00:00
|
|
|
#elif defined(USE_SDL_MAINLOOP)
|
|
|
|
#include <SDL.h>
|
|
|
|
#define MK_SHIFT (KMOD_LSHIFT | KMOD_RSHIFT)
|
|
|
|
#define MK_CONTROL (KMOD_LCTRL | KMOD_RCTRL)
|
2012-03-22 20:08:19 +00:00
|
|
|
#define MK_ALT (KMOD_LALT | KMOD_RALT)
|
2011-03-19 21:09:10 +00:00
|
|
|
#elif defined(USE_CONSOLE)
|
2012-11-15 22:01:24 +00:00
|
|
|
#ifndef _WIN32
|
2011-03-19 21:09:10 +00:00
|
|
|
#define MK_SHIFT 0
|
|
|
|
#define MK_CONTROL 0
|
2012-11-15 22:01:24 +00:00
|
|
|
#endif
|
2012-03-22 20:08:19 +00:00
|
|
|
#define MK_ALT 0
|
2011-03-19 21:09:10 +00:00
|
|
|
#elif defined(USE_COCOA)
|
|
|
|
// declare as extern variables and initialize them in StdMacWindow.mm so as to not include objc headers
|
|
|
|
extern int MK_SHIFT;
|
|
|
|
extern int MK_CONTROL;
|
2012-03-22 20:08:19 +00:00
|
|
|
extern int MK_ALT;
|
2012-03-23 21:53:56 +00:00
|
|
|
#elif defined(USE_WIN32_WINDOWS)
|
|
|
|
#include <C4windowswrapper.h>
|
2013-04-01 10:48:02 +00:00
|
|
|
#ifndef MK_ALT
|
|
|
|
#define MK_ALT 0x20 // as defined in oleidl.h
|
|
|
|
#endif
|
2011-03-19 21:09:10 +00:00
|
|
|
#endif
|
|
|
|
|
2012-03-23 21:53:56 +00:00
|
|
|
#ifdef USE_WIN32_WINDOWS
|
2011-03-19 21:09:10 +00:00
|
|
|
class CStdMessageProc : public StdSchedulerProc
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CStdMessageProc() : pApp(NULL) { }
|
|
|
|
~CStdMessageProc() { }
|
|
|
|
|
|
|
|
private:
|
2011-08-27 14:20:39 +00:00
|
|
|
C4AbstractApp *pApp;
|
2011-03-19 21:09:10 +00:00
|
|
|
|
|
|
|
public:
|
2011-08-27 14:20:39 +00:00
|
|
|
void SetApp(C4AbstractApp *pnApp) { pApp = pnApp; }
|
2011-03-19 21:09:10 +00:00
|
|
|
|
|
|
|
// StdSchedulerProc overrides
|
|
|
|
virtual bool Execute(int iTimeout = -1, pollfd *dummy=0);
|
|
|
|
virtual HANDLE GetEvent() { return STDSCHEDULER_EVENT_MESSAGE; }
|
|
|
|
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2011-08-27 14:20:39 +00:00
|
|
|
class C4AbstractApp : public StdScheduler
|
2011-03-19 21:09:10 +00:00
|
|
|
{
|
|
|
|
public:
|
2011-08-27 14:20:39 +00:00
|
|
|
C4AbstractApp ();
|
|
|
|
virtual ~C4AbstractApp ();
|
2011-03-19 21:09:10 +00:00
|
|
|
|
|
|
|
bool Active;
|
|
|
|
|
|
|
|
virtual void Clear();
|
|
|
|
|
|
|
|
bool Init(int argc, char * argv[]);
|
|
|
|
void Run();
|
|
|
|
virtual void Quit();
|
|
|
|
|
|
|
|
bool GetIndexedDisplayMode(int32_t iIndex, int32_t *piXRes, int32_t *piYRes, int32_t *piBitDepth, int32_t *piRefreshRate, uint32_t iMonitor);
|
|
|
|
bool SetVideoMode(unsigned int iXRes, unsigned int iYRes, unsigned int iColorDepth, unsigned int iRefreshRate, unsigned int iMonitor, bool fFullScreen);
|
|
|
|
void RestoreVideoMode();
|
2012-02-28 19:40:19 +00:00
|
|
|
// Gamma
|
2013-10-29 13:27:18 +00:00
|
|
|
virtual bool ApplyGammaRamp(struct _GAMMARAMP &ramp, bool fForce);
|
|
|
|
virtual bool SaveDefaultGammaRamp(struct _GAMMARAMP &ramp);
|
2011-03-19 21:09:10 +00:00
|
|
|
bool ScheduleProcs(int iTimeout = -1);
|
|
|
|
bool FlushMessages();
|
2011-08-27 21:12:01 +00:00
|
|
|
C4Window * pWindow;
|
2011-03-19 21:09:10 +00:00
|
|
|
bool fQuitMsgReceived; // if true, a quit message has been received and the application should terminate
|
|
|
|
|
|
|
|
// Copy the text to the clipboard or the primary selection
|
|
|
|
bool Copy(const StdStrBuf & text, bool fClipboard = true);
|
|
|
|
// Paste the text from the clipboard or the primary selection
|
|
|
|
StdStrBuf Paste(bool fClipboard = true);
|
|
|
|
// Is there something in the clipboard?
|
|
|
|
bool IsClipboardFull(bool fClipboard = true);
|
|
|
|
// a command from stdin
|
|
|
|
virtual void OnCommand(const char *szCmd) = 0; // callback
|
|
|
|
// Callback from SetVideoMode
|
|
|
|
virtual void OnResolutionChanged(unsigned int iXRes, unsigned int iYRes) = 0;
|
2012-10-08 22:54:34 +00:00
|
|
|
// Keyboard layout changed
|
|
|
|
virtual void OnKeyboardLayoutChanged() = 0;
|
2011-03-19 21:09:10 +00:00
|
|
|
// notify user to get back to the program
|
|
|
|
void NotifyUserIfInactive();
|
|
|
|
void MessageDialog(const char * message);
|
|
|
|
const char *GetLastError() { return sLastError.getData(); }
|
|
|
|
void Error(const char * m) { sLastError.Copy(m); }
|
|
|
|
|
2012-03-23 21:53:56 +00:00
|
|
|
#ifdef _WIN32
|
2011-03-19 21:09:10 +00:00
|
|
|
private:
|
|
|
|
HINSTANCE hInstance;
|
|
|
|
HANDLE hMainThread; // handle to main thread that initialized the app
|
|
|
|
|
2012-08-27 22:00:29 +00:00
|
|
|
void SetLastErrorFromOS();
|
|
|
|
|
2011-03-19 21:09:10 +00:00
|
|
|
public:
|
|
|
|
void SetInstance(HINSTANCE hInst) { hInstance = hInst; }
|
|
|
|
HINSTANCE GetInstance() const { return hInstance; }
|
|
|
|
bool AssertMainThread()
|
|
|
|
{
|
|
|
|
# ifdef _DEBUG
|
|
|
|
if (hMainThread && hMainThread != ::GetCurrentThread())
|
|
|
|
{
|
|
|
|
assert(false);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
# endif
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
bool AssertMainThread()
|
|
|
|
{
|
|
|
|
assert(MainThread == pthread_self());
|
|
|
|
return MainThread == pthread_self();
|
|
|
|
}
|
2012-03-23 21:53:56 +00:00
|
|
|
pthread_t MainThread;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(USE_X11)
|
2011-03-19 21:09:10 +00:00
|
|
|
protected:
|
2011-08-27 20:05:22 +00:00
|
|
|
class C4X11AppImpl * Priv;
|
2012-03-23 21:53:56 +00:00
|
|
|
|
|
|
|
#elif defined(USE_SDL_MAINLOOP)
|
|
|
|
public:
|
|
|
|
void HandleSDLEvent(SDL_Event& event);
|
|
|
|
|
|
|
|
#elif defined(USE_COCOA)
|
|
|
|
public:
|
|
|
|
StdStrBuf GetGameDataPath();
|
|
|
|
|
|
|
|
#elif defined(USE_CONSOLE)
|
2011-03-19 21:09:10 +00:00
|
|
|
protected:
|
2012-11-30 17:30:00 +00:00
|
|
|
C4StdInProc InProc;
|
2011-03-19 21:09:10 +00:00
|
|
|
#endif
|
2012-03-23 21:53:56 +00:00
|
|
|
|
|
|
|
#ifdef USE_WIN32_WINDOWS
|
|
|
|
private:
|
|
|
|
CStdMessageProc MessageProc;
|
|
|
|
public:
|
2012-04-22 20:09:06 +00:00
|
|
|
/* bool IsShiftDown() { return GetKeyState(VK_SHIFT) < 0; }
|
2012-03-23 21:53:56 +00:00
|
|
|
bool IsControlDown() { return GetKeyState(VK_CONTROL) < 0; }
|
2012-04-22 20:09:06 +00:00
|
|
|
bool IsAltDown() { return GetKeyState(VK_MENU) < 0; }*/
|
2012-03-23 21:53:56 +00:00
|
|
|
PIXELFORMATDESCRIPTOR &GetPFD() { return pfd; }
|
|
|
|
HMONITOR hMon; // monitor handle of used monitor
|
|
|
|
RECT MonitorRect; // output window rect
|
|
|
|
protected:
|
|
|
|
PIXELFORMATDESCRIPTOR pfd; // desired pixel format
|
|
|
|
DEVMODEW dspMode, OldDspMode;// display mode for fullscreen
|
|
|
|
#else
|
|
|
|
public:
|
2012-04-22 20:09:06 +00:00
|
|
|
/* bool IsShiftDown() { return KeyMask & MK_SHIFT; }
|
2012-03-23 21:53:56 +00:00
|
|
|
bool IsControlDown() { return KeyMask & MK_CONTROL; }
|
|
|
|
bool IsAltDown() { return KeyMask & MK_ALT; }
|
2012-04-22 20:09:06 +00:00
|
|
|
unsigned int KeyMask;*/
|
2012-03-23 21:53:56 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
protected:
|
2011-03-19 21:09:10 +00:00
|
|
|
StdStrBuf sLastError;
|
|
|
|
bool fDspModeSet; // true if display mode was changed
|
2012-04-10 21:39:16 +00:00
|
|
|
virtual bool DoInit(int argc, char * argv[]) = 0;
|
2011-03-19 21:09:10 +00:00
|
|
|
|
|
|
|
friend class CStdGL;
|
|
|
|
friend class CStdGLCtx;
|
2011-08-27 21:12:01 +00:00
|
|
|
friend class C4Window;
|
|
|
|
friend class C4GtkWindow;
|
2011-03-19 21:09:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // INC_STDAPP
|