Split CStdApp out of StdWindow.h into StdApp.h

Günther Brammer 2011-03-19 22:09:10 +01:00
parent 1b361bbcb7
commit 0f44b39ab9
16 changed files with 250 additions and 219 deletions

View File

@ -461,6 +461,8 @@ set(OC_CLONK_SOURCES
src/platform/C4windowswrapper.h
src/platform/GetTime.cpp
src/platform/PlatformAbstraction.h
src/platform/StdApp.h
src/platform/StdAppCommon.cpp
src/platform/StdConfig.cpp
src/platform/StdConfig.h
src/platform/StdD3D.cpp
@ -491,8 +493,6 @@ set(OC_CLONK_SOURCES
src/platform/StdVideo.cpp
src/platform/StdVideo.h
src/platform/StdWindow.h
src/platform/StdAppCommon.h
src/platform/StdAppCommon.cpp
src/script/C4Aul.cpp
src/script/C4AulExec.h
src/script/C4AulExec.cpp

View File

@ -464,8 +464,8 @@ src/platform/C4ViewportWindow.cpp \
src/platform/C4ViewportWindow.h \
src/platform/C4windowswrapper.h \
src/platform/PlatformAbstraction.h \
src/platform/StdApp.h \
src/platform/StdAppCommon.cpp \
src/platform/StdAppCommon.h \
src/platform/StdD3D.cpp \
src/platform/StdD3D.h \
src/platform/StdD3DShader.cpp \

View File

@ -28,7 +28,7 @@
#include <C4SoundSystem.h>
#include <C4Components.h>
#include <C4InteractiveThread.h>
#include <StdWindow.h>
#include <StdApp.h>
class CStdDDraw;
class C4ApplicationGameTimer;

View File

@ -0,0 +1,217 @@
/*
* OpenClonk, http://www.openclonk.org
*
* Copyright (c) 2005 Sven Eberhardt
* Copyright (c) 2005-2006, 2010-2011 Günther Brammer
* Copyright (c) 2006 Armin Burgmeier
* Copyright (c) 2009 Peter Wortmann
* Copyright (c) 2010 Mortimer
* 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>
#ifdef HAVE_PTHREAD
#include <pthread.h>
#endif
#ifdef _WIN32
#include <C4windowswrapper.h>
#elif defined(USE_X11)
// do not include xlib.h
typedef struct _XDisplay Display;
// from X.h:
//#define ShiftMask (1<<0)
//#define ControlMask (1<<2)
#define MK_CONTROL (1<<2)
#define MK_SHIFT (1<<0)
#elif defined(USE_SDL_MAINLOOP)
#include <SDL.h>
#define MK_SHIFT (KMOD_LSHIFT | KMOD_RSHIFT)
#define MK_CONTROL (KMOD_LCTRL | KMOD_RCTRL)
#elif defined(USE_CONSOLE)
#define MK_SHIFT 0
#define MK_CONTROL 0
#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;
#endif
#ifdef _WIN32
class CStdMessageProc : public StdSchedulerProc
{
public:
CStdMessageProc() : pApp(NULL) { }
~CStdMessageProc() { }
private:
CStdApp *pApp;
public:
void SetApp(CStdApp *pnApp) { pApp = pnApp; }
// StdSchedulerProc overrides
virtual bool Execute(int iTimeout = -1, pollfd *dummy=0);
virtual HANDLE GetEvent() { return STDSCHEDULER_EVENT_MESSAGE; }
};
#endif
#ifdef USE_CONSOLE
// A simple alertable proc
class CStdInProc : public StdSchedulerProc
{
public:
CStdInProc();
~CStdInProc();
// StdSchedulerProc override
virtual bool Execute(int iTimeout, pollfd *);
virtual void GetFDs(std::vector<struct pollfd> & checkfds)
{
pollfd pfd = { 0, POLLIN, 0 };
checkfds.push_back(pfd);
}
private:
// commands from stdin
StdCopyStrBuf CmdBuf;
};
#endif
class CStdApp : public StdScheduler
{
public:
CStdApp ();
virtual ~CStdApp ();
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();
bool ScheduleProcs(int iTimeout = -1);
bool FlushMessages();
CStdWindow * pWindow;
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);
// Give up Selection ownership
void ClearClipboard(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;
// 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); }
#ifdef _WIN32
private:
HINSTANCE hInstance;
HANDLE hMainThread; // handle to main thread that initialized the app
CStdMessageProc MessageProc;
public:
bool IsShiftDown() { return GetKeyState(VK_SHIFT) < 0; }
bool IsControlDown() { return GetKeyState(VK_CONTROL) < 0; }
bool IsAltDown() { return GetKeyState(VK_MENU) < 0; }
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;
}
PIXELFORMATDESCRIPTOR &GetPFD() { return pfd; }
HMONITOR hMon; // monitor handle of used monitor
RECT MonitorRect; // output window rect
protected:
PIXELFORMATDESCRIPTOR pfd; // desired pixel format
DEVMODE dspMode, OldDspMode;// display mode for fullscreen
#else
# if defined(USE_X11)
Display * dpy;
int xf86vmode_major_version, xf86vmode_minor_version;
int xrandr_major_version, xrandr_minor_version;
# endif
# if defined(USE_SDL_MAINLOOP)
void HandleSDLEvent(SDL_Event& event);
# endif
#ifdef USE_COCOA
void HandleNSEvent(/*NSEvent*/void* event);
#endif
const char * Location;
pthread_t MainThread;
bool DoNotDelay;
bool IsShiftDown() { return KeyMask & MK_SHIFT; }
bool IsControlDown() { return KeyMask & MK_CONTROL; }
bool IsAltDown() { return KeyMask & (1<<3); }
bool AssertMainThread()
{
assert(MainThread == pthread_self());
return MainThread == pthread_self();
}
// These must be public to be callable from callback functions from
// the glib main loop that are in an anonymous namespace in
// StdXApp.cpp.
void OnXInput();
protected:
# ifdef USE_X11
class CStdAppPrivate * Priv;
void HandleXMessage();
# endif
unsigned int KeyMask;
#endif
protected:
#ifdef USE_CONSOLE
CStdInProc InProc;
#endif
StdStrBuf sLastError;
bool fDspModeSet; // true if display mode was changed
virtual bool DoInit(int argc, char * argv[]) = 0;;
friend class CStdGL;
friend class CStdGLCtx;
friend class CStdWindow;
friend class CStdGtkWindow;
};
#endif // INC_STDAPP

View File

@ -1,6 +1,7 @@
/*
* OpenClonk, http://www.openclonk.org
*
* Copyright (c) 2007 Alex
* Copyright (c) 2010 Mortimer
* Portions might be copyrighted by other authors who have contributed
* to OpenClonk.
@ -15,11 +16,8 @@
*/
#include <C4Include.h>
#include "StdAppCommon.h"
#ifdef WITH_GLIB
#include <glib.h>
#endif
#include "StdApp.h"
#include "StdWindow.h"
void CStdApp::Run()
{
@ -60,3 +58,12 @@ bool EraseItemSafe(const char *szFilename)
void CStdWindow::PerformUpdate()
{
}
void CStdApp::NotifyUserIfInactive()
{
#ifdef _WIN32
if (!Active && pWindow) pWindow->FlashWindow();
#else
if (pWindow) pWindow->FlashWindow();
#endif
}

View File

@ -1,16 +0,0 @@
/*
* OpenClonk, http://www.openclonk.org
*
* 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.
*/
#include <StdWindow.h>

View File

@ -24,9 +24,10 @@
/* Direct3D implementation of NewGfx */
#include "C4Include.h"
#include <StdD3D.h>
#include <StdD3DShader.h>
#include <StdApp.h>
#include <StdMarkup.h>
#include <StdWindow.h>
#include <C4Config.h>

View File

@ -23,7 +23,9 @@
/* NewGfx interfaces */
#include "C4Include.h"
#include <StdDDraw2.h>
#include "StdApp.h"
#include <StdWindow.h>
#include <StdDDraw2.h>
#include <StdFacet.h>

View File

@ -23,6 +23,8 @@
#include "C4Include.h"
#include <StdGL.h>
#include <StdApp.h>
#include <StdSurface2.h>
#include <StdWindow.h>
#include <C4Config.h>

View File

@ -22,6 +22,7 @@
#include <C4Include.h>
#include <StdGtkWindow.h>
#include <StdApp.h>
#include "C4Version.h"
#include "C4Config.h"

View File

@ -23,6 +23,8 @@
/* A wrapper class to OS dependent event and window interfaces, SDL version */
#include <C4Include.h>
#include "StdApp.h"
#include <StdWindow.h>
#include <StdGL.h>
#include <StdDDraw2.h>

View File

@ -23,8 +23,11 @@
// a wrapper class to DirectDraw surfaces
#include "C4Include.h"
#include <StdSurface2.h>
#include <StdFile.h>
#include <CStdFile.h>
#include "StdApp.h"
#include <StdGL.h>
#include <StdWindow.h>
#include <StdRegistry.h>

View File

@ -27,6 +27,7 @@
#include "C4Include.h"
#include <StdWindow.h>
#include <StdApp.h>
#include <StdRegistry.h>
#include <C4Config.h>
#include <C4Rect.h>

View File

@ -28,12 +28,6 @@
#define INC_STDWINDOW
#include <StdBuf.h>
#include <StdScheduler.h>
#include <StdSync.h>
#ifdef HAVE_PTHREAD
#include <pthread.h>
#endif
#ifdef _WIN32
#include <C4windowswrapper.h>
@ -81,7 +75,6 @@
#define KEY_X ((WORD) 'X') // cut from GUI-editbox
#elif defined(USE_X11)
#include <X11/keysym.h>
#include <sys/time.h>
#define K_F1 XK_F1
#define K_F2 XK_F2
#define K_F3 XK_F3
@ -123,11 +116,6 @@
#define KEY_V XK_v // paste in GUI-editbox
#define KEY_W XK_w // console mode control key
#define KEY_X XK_x // cut from GUI-editbox
// from X.h:
//#define ShiftMask (1<<0)
//#define ControlMask (1<<2)
#define MK_CONTROL (1<<2)
#define MK_SHIFT (1<<0)
#elif defined(USE_SDL_MAINLOOP)
#include <SDL.h>
#define K_F1 SDLK_F1
@ -171,8 +159,6 @@
#define KEY_V SDLK_v
#define KEY_X SDLK_x
#define KEY_A SDLK_a
#define MK_SHIFT (KMOD_LSHIFT | KMOD_RSHIFT)
#define MK_CONTROL (KMOD_LCTRL | KMOD_RCTRL)
#elif defined(USE_CONSOLE)
#define K_F1 0
#define K_F2 0
@ -215,8 +201,6 @@
#define KEY_V 0
#define KEY_X 0
#define KEY_A 0
#define MK_SHIFT 0
#define MK_CONTROL 0
#elif defined(USE_COCOA)
// declare as extern variables and initialize them in StdMacWindow.mm so as to not include objc headers
const int CocoaKeycodeOffset = 300;
@ -261,19 +245,8 @@ extern int KEY_C;
extern int KEY_V;
extern int KEY_X;
extern int KEY_A;
extern int MK_SHIFT;
extern int MK_CONTROL;
#endif
enum C4AppHandleResult
{
HR_Timeout,
HR_Message, // handled a message
HR_Timer, // got timer event
HR_Failure // error, or quit message received
};
class CStdApp;
#ifdef USE_X11
// Forward declarations because xlib.h is evil
typedef union _XEvent XEvent;
@ -364,170 +337,4 @@ public:
friend class CStdGtkWindow;
};
#ifdef _WIN32
class CStdMessageProc : public StdSchedulerProc
{
public:
CStdMessageProc() : pApp(NULL) { }
~CStdMessageProc() { }
private:
CStdApp *pApp;
public:
void SetApp(CStdApp *pnApp) { pApp = pnApp; }
// StdSchedulerProc overrides
virtual bool Execute(int iTimeout = -1, pollfd *dummy=0);
virtual HANDLE GetEvent() { return STDSCHEDULER_EVENT_MESSAGE; }
};
#endif
#ifdef USE_CONSOLE
// A simple alertable proc
class CStdInProc : public StdSchedulerProc
{
public:
CStdInProc();
~CStdInProc();
// StdSchedulerProc override
virtual bool Execute(int iTimeout, pollfd *);
virtual void GetFDs(std::vector<struct pollfd> & checkfds)
{
pollfd pfd = { 0, POLLIN, 0 };
checkfds.push_back(pfd);
}
private:
// commands from stdin
StdCopyStrBuf CmdBuf;
};
#endif
class CStdApp : public StdScheduler
{
public:
CStdApp ();
virtual ~CStdApp ();
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();
bool ScheduleProcs(int iTimeout = -1);
bool FlushMessages();
CStdWindow * pWindow;
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);
// Give up Selection ownership
void ClearClipboard(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;
// notify user to get back to the program
void NotifyUserIfInactive()
{
#ifdef _WIN32
if (!Active && pWindow) pWindow->FlashWindow();
#else
if (pWindow) pWindow->FlashWindow();
#endif
}
void MessageDialog(const char * message);
const char *GetLastError() { return sLastError.getData(); }
void Error(const char * m) { sLastError.Copy(m); }
#ifdef _WIN32
private:
HINSTANCE hInstance;
HANDLE hMainThread; // handle to main thread that initialized the app
CStdMessageProc MessageProc;
public:
bool IsShiftDown() { return GetKeyState(VK_SHIFT) < 0; }
bool IsControlDown() { return GetKeyState(VK_CONTROL) < 0; }
bool IsAltDown() { return GetKeyState(VK_MENU) < 0; }
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;
}
PIXELFORMATDESCRIPTOR &GetPFD() { return pfd; }
HMONITOR hMon; // monitor handle of used monitor
RECT MonitorRect; // output window rect
protected:
PIXELFORMATDESCRIPTOR pfd; // desired pixel format
DEVMODE dspMode, OldDspMode;// display mode for fullscreen
#else
# if defined(USE_X11)
Display * dpy;
int xf86vmode_major_version, xf86vmode_minor_version;
int xrandr_major_version, xrandr_minor_version;
# endif
# if defined(USE_SDL_MAINLOOP)
void HandleSDLEvent(SDL_Event& event);
# endif
#ifdef USE_COCOA
void HandleNSEvent(/*NSEvent*/void* event);
#endif
const char * Location;
pthread_t MainThread;
bool DoNotDelay;
bool IsShiftDown() { return KeyMask & MK_SHIFT; }
bool IsControlDown() { return KeyMask & MK_CONTROL; }
bool IsAltDown() { return KeyMask & (1<<3); }
bool AssertMainThread()
{
assert(MainThread == pthread_self());
return MainThread == pthread_self();
}
// These must be public to be callable from callback functions from
// the glib main loop that are in an anonymous namespace in
// StdXApp.cpp.
void OnXInput();
protected:
# ifdef USE_X11
class CStdAppPrivate * Priv;
void HandleXMessage();
# endif
unsigned int KeyMask;
#endif
protected:
#ifdef USE_CONSOLE
CStdInProc InProc;
#endif
StdStrBuf sLastError;
bool fDspModeSet; // true if display mode was changed
virtual bool DoInit(int argc, char * argv[]) = 0;;
friend class CStdGL;
friend class CStdGLCtx;
friend class CStdWindow;
friend class CStdGtkWindow;
};
#endif // INC_STDWINDOW

View File

@ -24,6 +24,8 @@
# include <glib.h>
#endif
#include <StdApp.h>
class CX11Proc: public StdSchedulerProc
{

View File

@ -25,6 +25,8 @@
#ifdef USE_X11
#include <StdWindow.h>
#include <StdApp.h>
#include <StdGL.h>
#include <StdDDraw2.h>
#include <StdFile.h>