major application architecture work

This commit is contained in:
Jack Andersen 2015-05-05 14:50:57 -10:00
parent df4c484489
commit de7f062944
36 changed files with 1231 additions and 424 deletions

View File

@ -1,11 +0,0 @@
#ifndef CINPUTDEFERREDRELAY_HPP
#define CINPUTDEFERREDRELAY_HPP
#include "IInputWaiter.hpp"
namespace boo
{
}
#endif // CINPUTDEFERREDRELAY_HPP

View File

@ -1,16 +0,0 @@
#ifndef CINPUTRELAY_HPP
#define CINPUTRELAY_HPP
#include "IInputWaiter.hpp"
namespace boo
{
class CInputRelay : IInputWaiter
{
};
}
#endif // CINPUTRELAY_HPP

View File

@ -1,36 +0,0 @@
#ifndef CQTOPENGLWINDOW_HPP
#define CQTOPENGLWINDOW_HPP
#include <QWindow>
#include <QOpenGLFunctions>
#include <ISurface.hpp>
class CQtOpenGLWindow : public QWindow, ISurface
{
Q_OBJECT
public:
explicit CQtOpenGLWindow(QWindow *parent = 0);
CQtOpenGLWindow();
virtual void render();
virtual void initialize();
public slots:
void renderLater();
void renderNow();
protected:
bool event(QEvent *event) Q_DECL_OVERRIDE;
void exposeEvent(QExposeEvent *event) Q_DECL_OVERRIDE;
private:
bool m_update_pending;
bool m_animating;
QOpenGLContext *m_context;
};
#endif // CQTOPENGLWINDOW_HPP

View File

@ -1,14 +0,0 @@
#ifndef CSURFACE_HPP
#define CSURFACE_HPP
#include "ISurface.hpp"
namespace boo
{
ISurface* CSurfaceNewWindow();
ISurface* CSurfaceNewQWidget();
}
#endif // CSURFACE_HPP

79
include/IApplication.hpp Normal file
View File

@ -0,0 +1,79 @@
#ifndef IRUNLOOP_HPP
#define IRUNLOOP_HPP
#include <string>
#include <vector>
#include "windowsys/IWindow.hpp"
#include "inputdev/CDeviceFinder.hpp"
namespace boo
{
class IApplication;
struct IApplicationCallback
{
virtual void appLaunched(IApplication* app) {(void)app;}
virtual void appQuitting(IApplication* app) {(void)app;}
virtual bool appFileOpen(IApplication* app, const std::string& path) {(void)app;(void)path;return true;}
};
class IApplication
{
friend class CWindowCocoa;
friend class CWindowWayland;
friend class CWindowXCB;
friend class CWindowWin32;
virtual void _deletedWindow(IWindow* window)=0;
public:
virtual ~IApplication() {}
enum EPlatformType
{
PLAT_AUTO = 0,
PLAT_WAYLAND = 1,
PLAT_XCB = 2,
PLAT_ANDROID = 3,
PLAT_COCOA = 4,
PLAT_COCOA_TOUCH = 5,
PLAT_WIN32 = 6,
PLAT_WINRT = 7,
PLAT_REVOLUTION = 8,
PLAT_CAFE = 9
};
virtual EPlatformType getPlatformType() const=0;
virtual void run()=0;
virtual void quit()=0;
virtual const std::string& getProcessName() const=0;
virtual const std::vector<std::string>& getArgs() const=0;
/* Constructors/initializers for sub-objects */
virtual IWindow* newWindow(const std::string& title)=0;
};
IApplication* IApplicationBootstrap(IApplication::EPlatformType platform,
IApplicationCallback& cb,
const std::string& friendlyName,
const std::string& pname,
const std::vector<std::string>& args);
extern IApplication* APP;
#define IApplicationInstance() APP
static inline IApplication* IApplicationBootstrap(IApplication::EPlatformType platform,
IApplicationCallback& cb,
const std::string& friendlyName,
int argc, char** argv)
{
if (APP)
return APP;
std::vector<std::string> args;
for (int i=1 ; i<argc ; ++i)
args.push_back(argv[i]);
return IApplicationBootstrap(platform, cb, friendlyName, argv[0], args);
}
}
#endif // IRUNLOOP_HPP

View File

@ -1,27 +0,0 @@
#ifndef IGRAPHICSCONTEXT_HPP
#define IGRAPHICSCONTEXT_HPP
#include <string>
namespace boo
{
class IGraphicsContext
{
public:
virtual ~IGraphicsContext() {}
virtual void setMinVersion (const int& min)=0;
virtual void setMajorVersion(const int& maj)=0;
virtual bool create()=0;
virtual const std::string version() const=0;
virtual const std::string name() const=0;
virtual int depthSize() const=0;
virtual int redDepth() const=0;
virtual int greenDepth() const=0;
virtual int blueDepth() const=0;
};
}
#endif // IGRAPHICSCONTEXT_HPP

View File

@ -1,14 +0,0 @@
#ifndef IINPUTWAITER_HPP
#define IINPUTWAITER_HPP
namespace boo
{
class IInputWaiter
{
};
}
#endif // IINPUTWAITER_HPP

View File

@ -1,14 +0,0 @@
#ifndef IRETRACEWAITER_HPP
#define IRETRACEWAITER_HPP
namespace boo
{
class IRetraceWaiter
{
};
}
#endif // IRETRACEWAITER_HPP

View File

@ -1,15 +0,0 @@
#ifndef ISURFACE_HPP
#define ISURFACE_HPP
namespace boo
{
class ISurface
{
public:
};
}
#endif // CSURFACE_HPP

View File

@ -1,6 +1,7 @@
#ifndef BOO_HPP #ifndef BOO_HPP
#define BOO_HPP #define BOO_HPP
#include "IApplication.hpp"
#include "windowsys/IWindow.hpp" #include "windowsys/IWindow.hpp"
#include "inputdev/CDeviceFinder.hpp" #include "inputdev/CDeviceFinder.hpp"
#include "inputdev/CDolphinSmashAdapter.hpp" #include "inputdev/CDolphinSmashAdapter.hpp"

View File

@ -1,19 +0,0 @@
#ifndef CWGLCONTEXT_HPP
#define CWGLCONTEXT_HPP
#ifdef _WIN32
#include "IGraphicsContext.hpp"
namespace boo
{
class CWGLContext : public IGraphicsContext
{
};
}
#endif // _WIN32
#endif // CWGLCONTEXT_HPP

View File

@ -50,8 +50,6 @@ public:
}; };
IGraphicsContext* IGraphicsContextNew(IGraphicsContext::EGraphicsAPI api);
} }
#endif // IGRAPHICSCONTEXT_HPP #endif // IGRAPHICSCONTEXT_HPP

View File

@ -123,6 +123,8 @@ public:
virtual bool isFullscreen() const=0; virtual bool isFullscreen() const=0;
virtual void setFullscreen(bool fs)=0; virtual void setFullscreen(bool fs)=0;
virtual void* getPlatformHandle() const=0;
enum ETouchType enum ETouchType
{ {
TOUCH_NONE = 0, TOUCH_NONE = 0,
@ -133,8 +135,6 @@ public:
}; };
IWindow* IWindowNew();
} }
#endif // IWINDOW_HPP #endif // IWINDOW_HPP

View File

@ -1,36 +0,0 @@
#ifndef CGLXCONTEXT_HPP
#define CGLXCONTEXT_HPP
#if !defined(__APPLE__) && (defined(__linux__) || defined(BSD))
#include <GL/glx.h>
#include "IGraphicsContext.hpp"
namespace boo
{
class CGLXContext final : public IGraphicsContext
{
public:
CGLXContext();
virtual ~CGLXContext() {}
bool create();
void setMajorVersion(const int& maj) override;
void setMinVersion(const int& min) override;
const std::string version() const override;
const std::string name() const override;
int depthSize() const override;
int redDepth() const override;
int greenDepth() const override;
int blueDepth() const override;
private:
int m_majVersion;
int m_minVersion;
Display* m_display;
};
}
#endif // !defined(__APPLE__) && (defined(__linux__) || defined(BSD))
#endif // CGLXCONTEXT_HPP

View File

@ -1,5 +1,6 @@
HEADERS += \ HEADERS += \
$$PWD/include/boo.hpp \ $$PWD/include/boo.hpp \
$$PWD/include/IApplication.hpp \
$$PWD/include/windowsys/IWindow.hpp \ $$PWD/include/windowsys/IWindow.hpp \
$$PWD/include/windowsys/IGraphicsContext.hpp \ $$PWD/include/windowsys/IGraphicsContext.hpp \
$$PWD/include/inputdev/CDolphinSmashAdapter.hpp \ $$PWD/include/inputdev/CDolphinSmashAdapter.hpp \
@ -16,10 +17,6 @@ HEADERS += \
SOURCES += \ SOURCES += \
$$PWD/InputDeviceClasses.cpp \ $$PWD/InputDeviceClasses.cpp \
$$PWD/src/CSurface.cpp \
$$PWD/src/CRetraceWaiter.cpp \
$$PWD/src/CInputRelay.cpp \
$$PWD/src/CInputDeferredRelay.cpp \
$$PWD/src/inputdev/CDolphinSmashAdapter.cpp \ $$PWD/src/inputdev/CDolphinSmashAdapter.cpp \
$$PWD/src/inputdev/CRevolutionPad.cpp \ $$PWD/src/inputdev/CRevolutionPad.cpp \
$$PWD/src/inputdev/CCafeProPad.cpp \ $$PWD/src/inputdev/CCafeProPad.cpp \
@ -29,10 +26,13 @@ SOURCES += \
$$PWD/src/inputdev/SDeviceSignature.cpp $$PWD/src/inputdev/SDeviceSignature.cpp
unix:!macx { unix:!macx {
HEADERS += \
$$PWD/include/x11/CGLXContext.hpp
SOURCES += \ SOURCES += \
$$PWD/src/x11/CGLXContext.cpp $$PWD/src/CApplicationXCB.cpp \
$$PWD/src/CApplicationWayland.cpp \
$$PWD/src/windowsys/CWindowXCB.cpp \
$$PWD/src/windowsys/CWindowWayland.cpp \
$$PWD/src/windowsys/CGraphicsContextXCB.cpp \
$$PWD/src/windowsys/CGraphicsContextWayland.cpp
} }
linux { linux {
@ -47,18 +47,19 @@ macx {
$$PWD/src/inputdev/CHIDDeviceIOKit.cpp \ $$PWD/src/inputdev/CHIDDeviceIOKit.cpp \
$$PWD/src/inputdev/CHIDListenerIOKit.cpp $$PWD/src/inputdev/CHIDListenerIOKit.cpp
OBJECTIVE_SOURCES += \ OBJECTIVE_SOURCES += \
$$PWD/src/CApplicationCocoa.mm \
$$PWD/src/windowsys/CWindowCocoa.mm \ $$PWD/src/windowsys/CWindowCocoa.mm \
$$PWD/src/windowsys/CGraphicsContextCocoa.mm $$PWD/src/windowsys/CGraphicsContextCocoa.mm
LIBS += -framework AppKit LIBS += -framework AppKit
} }
win32 { win32 {
HEADERS += \
$$PWD/include/win/CWGLContext.hpp
SOURCES += \ SOURCES += \
$$PWD/src/win/CWGLContext.cpp \ $$PWD/src/CApplicationWin32.cpp \
$$PWD/src/inputdev/CHIDListenerWinUSB.cpp \ $$PWD/src/inputdev/CHIDListenerWinUSB.cpp \
$$PWD/src/inputdev/CHIDDeviceWinUSB.cpp $$PWD/src/inputdev/CHIDDeviceWinUSB.cpp \
$$PWD/src/windowsys/CWindowWin32.cpp \
$$PWD/src/windowsys/CGraphicsContextWin32.cpp
} }
INCLUDEPATH += $$PWD/include INCLUDEPATH += $$PWD/include

180
src/CApplicationCocoa.mm Normal file
View File

@ -0,0 +1,180 @@
#include <AppKit/AppKit.h>
#include "IApplication.hpp"
@interface AppDelegate : NSObject <NSApplicationDelegate>
{
boo::IApplicationCallback* callback;
NSPanel* aboutPanel;
}
- (id)initWithCallback:(boo::IApplicationCallback*)cb;
@end
@implementation AppDelegate
- (id)initWithCallback:(boo::IApplicationCallback*)cb
{
self = [super init];
callback = cb;
return self;
}
- (void)applicationDidFinishLaunching:(NSNotification*)notification
{
(void)notification;
callback->appLaunched(boo::IApplicationInstance());
}
- (void)applicationWillTerminate:(NSNotification*)notification
{
(void)notification;
callback->appQuitting(boo::IApplicationInstance());
}
- (BOOL)application:(NSApplication*)sender openFile:(NSString*)filename
{
(void)sender;
return callback->appFileOpen(boo::IApplicationInstance(), [filename UTF8String]);
}
- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication*)sender {
(void)sender;
return YES;
}
- (IBAction)aboutApp:(id)sender
{
(void)sender;
NSRect screenFrame = [[aboutPanel screen] frame];
CGFloat xPos = NSWidth(screenFrame)/2 - 300/2;
CGFloat yPos = NSHeight(screenFrame)/2 - 220/2;
NSRect aboutCr = NSMakeRect(xPos, yPos, 300, 220);
[aboutPanel setFrame:aboutCr display:NO];
[aboutPanel makeKeyAndOrderFront:self];
}
- (IBAction)toggleFs:(id)sender
{
(void)sender;
[[NSApp keyWindow] toggleFullScreen:nil];
}
- (IBAction)quitApp:(id)sender
{
(void)sender;
[NSApp terminate:nil];
}
@end
namespace boo
{
IWindow* _CWindowCocoaNew(const std::string& title);
class CApplicationCocoa final : public IApplication
{
IApplicationCallback& m_callback;
const std::string m_friendlyName;
const std::string m_pname;
const std::vector<std::string> m_args;
NSPanel* aboutPanel;
void _deletedWindow(IWindow* window)
{
(void)window;
}
public:
CApplicationCocoa(IApplicationCallback& callback,
const std::string& friendlyName,
const std::string& pname,
const std::vector<std::string>& args)
: m_callback(callback),
m_friendlyName(friendlyName),
m_pname(pname),
m_args(args)
{}
EPlatformType getPlatformType() const
{
return PLAT_COCOA;
}
void run()
{
@autoreleasepool
{
NSApplication* app = [NSApplication sharedApplication];
[app setActivationPolicy:NSApplicationActivationPolicyRegular];
/* Delegate (OS X callbacks) */
AppDelegate* appDelegate = [[AppDelegate alloc] initWithCallback:&m_callback];
[app setDelegate:appDelegate];
/* App menu */
NSMenu* appMenu = [[NSMenu alloc] initWithTitle:@"main"];
NSMenu* rwkMenu = [[NSMenu alloc] initWithTitle:[[NSString stringWithUTF8String:m_friendlyName.c_str()] autorelease]];
[rwkMenu addItemWithTitle:[[NSString stringWithFormat:@"About %s", m_friendlyName.c_str()] autorelease]
action:@selector(aboutApp:)
keyEquivalent:@""];
NSMenuItem* fsItem = [rwkMenu addItemWithTitle:@"Toggle Full Screen"
action:@selector(toggleFs:)
keyEquivalent:@"f"];
[fsItem setKeyEquivalentModifierMask:NSCommandKeyMask];
[rwkMenu addItem:[NSMenuItem separatorItem]];
NSMenuItem* quit_item = [rwkMenu addItemWithTitle:[[NSString stringWithFormat:@"Quit %s", m_friendlyName.c_str()] autorelease]
action:@selector(quitApp:)
keyEquivalent:@"q"];
[quit_item setKeyEquivalentModifierMask:NSCommandKeyMask];
[[appMenu addItemWithTitle:[[NSString stringWithUTF8String:m_friendlyName.c_str()] autorelease]
action:nil keyEquivalent:@""] setSubmenu:rwkMenu];
[[NSApplication sharedApplication] setMainMenu:appMenu];
/* About panel */
NSRect aboutCr = NSMakeRect(0, 0, 300, 220);
aboutPanel = [[NSPanel alloc] initWithContentRect:aboutCr
styleMask:NSUtilityWindowMask|NSTitledWindowMask|NSClosableWindowMask
backing:NSBackingStoreBuffered defer:YES];
[aboutPanel setTitle:[[NSString stringWithFormat:@"About %s", m_friendlyName.c_str()] autorelease]];
NSText* aboutText = [[NSText alloc] initWithFrame:aboutCr];
[aboutText setEditable:NO];
[aboutText setAlignment:NSCenterTextAlignment];
[aboutText setString:@"\nRWK Authors\n\nJackoalan\nAntidote\n"];
[aboutPanel setContentView:aboutText];
[app run];
}
}
void quit()
{
[NSApp terminate:nil];
}
const std::string& getProcessName() const
{
return m_pname;
}
const std::vector<std::string>& getArgs() const
{
return m_args;
}
IWindow* newWindow(const std::string& title)
{
return _CWindowCocoaNew(title);
}
};
IApplication* APP = NULL;
IApplication* IApplicationBootstrap(IApplication::EPlatformType platform,
IApplicationCallback& cb,
const std::string& friendlyName,
const std::string& pname,
const std::vector<std::string>& args)
{
if (!APP)
{
if (platform != IApplication::PLAT_COCOA &&
platform != IApplication::PLAT_AUTO)
return NULL;
APP = new CApplicationCocoa(cb, friendlyName, pname, args);
}
return APP;
}
}

32
src/CApplicationUnix.cpp Normal file
View File

@ -0,0 +1,32 @@
/* Meta-implementation for dynamically-constructing user's preferred
* platform interface
*/
#define CAPPLICATION_UNIX_CPP
#include "CApplicationXCB.hpp"
#include "CApplicationWayland.hpp"
namespace boo
{
IApplication* APP = NULL;
IApplication* IApplicationBootstrap(IApplication::EPlatformType platform,
IApplicationCallback& cb,
const std::string& friendlyName,
const std::string& pname,
const std::vector<std::string>& args)
{
if (!APP)
{
if (platform == IApplication::PLAT_WAYLAND)
APP = new CApplicationWayland(cb, friendlyName, pname, args);
else if (platform == IApplication::PLAT_XCB ||
platform == IApplication::PLAT_AUTO)
APP = new CApplicationXCB(cb, friendlyName, pname, args);
else
return NULL;
}
return APP;
}
}

View File

@ -0,0 +1,61 @@
#ifndef CAPPLICATION_UNIX_CPP
#error This file may only be included from CApplicationUnix.cpp
#endif
#include "IApplication.hpp"
namespace boo
{
IWindow* _CWindowWaylandNew(const std::string& title);
class CApplicationWayland final : public IApplication
{
const IApplicationCallback& m_callback;
const std::string m_friendlyName;
const std::string m_pname;
const std::vector<std::string> m_args;
void _deletedWindow(IWindow* window)
{
(void)window;
}
public:
CApplicationWayland(const IApplicationCallback& callback,
const std::string& friendlyName,
const std::string& pname,
const std::vector<std::string>& args)
: m_callback(callback),
m_friendlyName(friendlyName),
m_pname(pname),
m_args(args)
{}
EPlatformType getPlatformType() const
{
return PLAT_WAYLAND;
}
void run()
{
}
const std::string& getProcessName() const
{
return m_pname;
}
const std::vector<std::string>& getArgs() const
{
return m_args;
}
IWindow* newWindow(const std::string& title)
{
return _CWindowWaylandNew(title);
}
};
}

162
src/CApplicationWin32.cpp Normal file
View File

@ -0,0 +1,162 @@
#define _CRT_SECURE_NO_WARNINGS 1 /* STFU MSVC */
#define _WIN32_LEAN_AND_MEAN 1
#include <windows.h>
#include <initguid.h>
#include <Usbiodef.h>
#include <unordered_map>
#include "IRunLoop.hpp"
#include "inputdev/CDeviceFinder.hpp"
namespace boo
{
IWindow* _CWindowWin32New(const std::string& title);
class CApplicationWin32 final : public IApplication
{
const IApplicationCallback& m_callback;
const std::string m_friendlyName;
const std::string m_pname;
const std::vector<std::string> m_args;
std::unordered_map<HWND, IWindow*> m_allWindows;
void _deletedWindow(IWindow* window)
{
m_allWindows.erase(window);
}
public:
CApplicationWin32(const IApplicationCallback& callback,
const std::string& friendlyName,
const std::string& pname,
const std::vector<std::string>& args)
: m_callback(callback),
m_friendlyName(friendlyName),
m_pname(pname),
m_args(args)
{}
EPlatformType getPlatformType() const
{
return PLAT_WIN32;
}
LRESULT winHwndHandler(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
/* Lookup boo window instance */
IWindow* window = m_allWindows[hwnd];
switch (uMsg)
{
case WM_CREATE:
return 0;
case WM_DEVICECHANGE:
return CDeviceFinder::winDevChangedHandler(wParam, lParam);
default:
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
}
void run()
{
/* Pump messages */
MSG msg = {0};
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
const std::string& getProcessName() const
{
return m_pname;
}
const std::vector<std::string>& getArgs() const
{
return m_args;
}
IWindow* newWindow(const std::string& title)
{
IWindow* window = _CWindowWin32New(title);
HWND hwnd = window->getPlatformHandle();
m_allWindows[hwnd] = window;
}
};
IApplication* APP = NULL;
IApplication* IApplicationBootstrap(IApplication::EPlatformType platform,
IApplicationCallback& cb,
const std::string& friendlyName,
const std::string& pname,
const std::vector<std::string>& args)
{
if (!APP)
{
if (platform != IApplication::PLAT_WIN32 &&
platform != IApplication::PLAT_AUTO)
return NULL;
APP = new CApplicationWin32(cb, friendlyName, pname, args);
}
return APP;
}
}
static const DEV_BROADCAST_DEVICEINTERFACE_A HOTPLUG_CONF =
{
sizeof(DEV_BROADCAST_DEVICEINTERFACE_A),
DBT_DEVTYP_DEVICEINTERFACE,
0,
GUID_DEVINTERFACE_USB_DEVICE
};
static bool HOTPLUG_REGISTERED = false;
static LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
if (!HOTPLUG_REGISTERED && hwnd == WM_CREATE)
{
/* Register hotplug notification with windows */
RegisterDeviceNotificationA(hwnd, (LPVOID)&HOTPLUG_CONF, DEVICE_NOTIFY_WINDOW_HANDLE);
HOTPLUG_REGISTERED = true;
}
return IRunLoopInstance()->winHwndHandler(hwnd, uMsg, wParam, lParam);
}
int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE, LPCWSTR lpCmdLine, int)
{
#if DEBUG
/* Debug console */
AllocConsole();
freopen("CONOUT$", "w", stdout);
#endif
/* One class for *all* boo windows */
WNDCLASS wndClass =
{
0,
WindowProc,
0,
0,
hInstance,
0,
0,
0,
0,
L"BooWindow"
};
RegisterClassW(&wndClass);
int argc = 0;
LPWSTR* argv = CommandLineToArgvW(lpCmdLine, &argc);
/* Call into the 'proper' entry point */
return main(argc, argv);
}

61
src/CApplicationXCB.hpp Normal file
View File

@ -0,0 +1,61 @@
#ifndef CAPPLICATION_UNIX_CPP
#error This file may only be included from CApplicationUnix.cpp
#endif
#include "IApplication.hpp"
namespace boo
{
IWindow* _CWindowXCBNew(const std::string& title);
class CApplicationXCB final : public IApplication
{
const IApplicationCallback& m_callback;
const std::string m_friendlyName;
const std::string m_pname;
const std::vector<std::string> m_args;
void _deletedWindow(IWindow* window)
{
(void)window;
}
public:
CApplicationXCB(const IApplicationCallback& callback,
const std::string& friendlyName,
const std::string& pname,
const std::vector<std::string>& args)
: m_callback(callback),
m_friendlyName(friendlyName),
m_pname(pname),
m_args(args)
{}
EPlatformType getPlatformType() const
{
return PLAT_XCB;
}
void run()
{
}
const std::string& getProcessName() const
{
return m_pname;
}
const std::vector<std::string>& getArgs() const
{
return m_args;
}
IWindow* newWindow(const std::string& title)
{
return _CWindowXCBNew(title);
}
};
}

View File

@ -1 +0,0 @@
#include "CInputDeferredRelay.hpp"

View File

@ -1 +0,0 @@
#include "CInputRelay.hpp"

View File

@ -1,3 +0,0 @@
#include "CQtOpenGLWindow.hpp"

View File

@ -1 +0,0 @@
#include "IRetraceWaiter.hpp"

View File

@ -1,16 +0,0 @@
#include "CSurface.hpp"
namespace boo
{
ISurface* CSurfaceNewWindow()
{
return nullptr;
}
ISurface* CSurfaceNewQWidget()
{
return nullptr;
}
}

View File

@ -1,4 +0,0 @@
#ifdef _WIN32
#include "win/CWGLContext.hpp"
#endif

View File

@ -4,6 +4,12 @@
#include "windowsys/IGraphicsContext.hpp" #include "windowsys/IGraphicsContext.hpp"
#include "windowsys/IWindow.hpp" #include "windowsys/IWindow.hpp"
/* AppKit applies OpenGL much differently than other platforms
* the NSOpenGLView class composes together all necessary
* OGL context members and provides the necessary event hooks
* for KB/Mouse/Touch events
*/
static const NSOpenGLPixelFormatAttribute PF_RGBA8_ATTRS[] = static const NSOpenGLPixelFormatAttribute PF_RGBA8_ATTRS[] =
{ {
NSOpenGLPFAAccelerated, NSOpenGLPFAAccelerated,
@ -70,17 +76,17 @@ class CGraphicsContextCocoa final : public IGraphicsContext
EGraphicsAPI m_api; EGraphicsAPI m_api;
EPixelFormat m_pf; EPixelFormat m_pf;
NSWindow* m_parentWindow; IWindow* m_parentWindow;
CGraphicsContextCocoaInternal* m_nsContext; CGraphicsContextCocoaInternal* m_nsContext;
NSOpenGLContext* m_nsShareContext; NSOpenGLContext* m_nsShareContext;
public: public:
IWindowCallback* m_callback; IWindowCallback* m_callback;
CGraphicsContextCocoa(EGraphicsAPI api) CGraphicsContextCocoa(EGraphicsAPI api, IWindow* parentWindow)
: m_api(api), : m_api(api),
m_pf(PF_RGBA8), m_pf(PF_RGBA8),
m_parentWindow(NULL), m_parentWindow(parentWindow),
m_nsContext(NULL), m_nsContext(NULL),
m_nsShareContext(NULL), m_nsShareContext(NULL),
m_callback(NULL) m_callback(NULL)
@ -114,17 +120,12 @@ public:
m_pf = pf; m_pf = pf;
} }
void setPlatformWindowHandle(void* handle)
{
m_parentWindow = (NSWindow*)handle;
}
void initializeContext() void initializeContext()
{ {
if (m_nsShareContext) if (m_nsShareContext)
return; return;
m_nsContext = [[CGraphicsContextCocoaInternal alloc] initWithBooContext:this]; m_nsContext = [[CGraphicsContextCocoaInternal alloc] initWithBooContext:this];
[m_parentWindow setContentView:m_nsContext]; [(NSWindow*)m_parentWindow->getPlatformHandle() setContentView:m_nsContext];
} }
IGraphicsContext* makeShareContext() const IGraphicsContext* makeShareContext() const
@ -144,7 +145,7 @@ public:
return NULL; return NULL;
if (!nsctx) if (!nsctx)
return NULL; return NULL;
CGraphicsContextCocoa* newCtx = new CGraphicsContextCocoa(m_api); CGraphicsContextCocoa* newCtx = new CGraphicsContextCocoa(m_api, NULL);
newCtx->m_nsShareContext = nsctx; newCtx->m_nsShareContext = nsctx;
return newCtx; return newCtx;
} }
@ -169,7 +170,8 @@ public:
}; };
IGraphicsContext* IGraphicsContextNew(IGraphicsContext::EGraphicsAPI api) IGraphicsContext* _CGraphicsContextCocoaNew(IGraphicsContext::EGraphicsAPI api,
IWindow* parentWindow)
{ {
if (api != IGraphicsContext::API_OPENGL_3_3 && api != IGraphicsContext::API_OPENGL_4_2) if (api != IGraphicsContext::API_OPENGL_3_3 && api != IGraphicsContext::API_OPENGL_4_2)
return NULL; return NULL;
@ -202,7 +204,7 @@ IGraphicsContext* IGraphicsContextNew(IGraphicsContext::EGraphicsAPI api)
if (api == IGraphicsContext::API_OPENGL_4_2) if (api == IGraphicsContext::API_OPENGL_4_2)
return NULL; return NULL;
return new CGraphicsContextCocoa(api); return new CGraphicsContextCocoa(api, parentWindow);
} }
} }

View File

@ -0,0 +1,87 @@
#include "windowsys/IGraphicsContext.hpp"
#include "windowsys/IWindow.hpp"
namespace boo
{
class CGraphicsContextWayland final : public IGraphicsContext
{
EGraphicsAPI m_api;
EPixelFormat m_pf;
IWindow* m_parentWindow;
public:
IWindowCallback* m_callback;
CGraphicsContextWayland(EGraphicsAPI api, IWindow* parentWindow)
: m_api(api),
m_pf(PF_RGBA8),
m_parentWindow(parentWindow)
{}
~CGraphicsContextWayland()
{
}
void _setCallback(IWindowCallback* cb)
{
m_callback = cb;
}
EGraphicsAPI getAPI() const
{
return m_api;
}
EPixelFormat getPixelFormat() const
{
return m_pf;
}
void setPixelFormat(EPixelFormat pf)
{
if (pf > PF_RGBAF32_Z24)
return;
m_pf = pf;
}
void setPlatformWindowHandle(void* handle)
{
}
void initializeContext()
{
}
IGraphicsContext* makeShareContext() const
{
}
void makeCurrent()
{
}
void clearCurrent()
{
}
void swapBuffer()
{
}
};
IGraphicsContext* _CGraphicsContextWaylandNew(IGraphicsContext::EGraphicsAPI api,
IWindow* parentWindow)
{
}
}

View File

@ -0,0 +1,87 @@
#include "windowsys/IGraphicsContext.hpp"
#include "windowsys/IWindow.hpp"
namespace boo
{
class CGraphicsContextWin32 final : public IGraphicsContext
{
EGraphicsAPI m_api;
EPixelFormat m_pf;
IWindow* m_parentWindow;
public:
IWindowCallback* m_callback;
CGraphicsContextWin32(EGraphicsAPI api, IWindow* parentWindow)
: m_api(api),
m_pf(PF_RGBA8),
m_parentWindow(parentWindow)
{}
~CGraphicsContextWin32()
{
}
void _setCallback(IWindowCallback* cb)
{
m_callback = cb;
}
EGraphicsAPI getAPI() const
{
return m_api;
}
EPixelFormat getPixelFormat() const
{
return m_pf;
}
void setPixelFormat(EPixelFormat pf)
{
if (pf > PF_RGBAF32_Z24)
return;
m_pf = pf;
}
void setPlatformWindowHandle(void* handle)
{
}
void initializeContext()
{
}
IGraphicsContext* makeShareContext() const
{
}
void makeCurrent()
{
}
void clearCurrent()
{
}
void swapBuffer()
{
}
};
IGraphicsContext* _CGraphicsContextWin32New(IGraphicsContext::EGraphicsAPI api,
IWindow* parentWindow)
{
}
}

View File

@ -0,0 +1,87 @@
#include "windowsys/IGraphicsContext.hpp"
#include "windowsys/IWindow.hpp"
namespace boo
{
class CGraphicsContextXCB final : public IGraphicsContext
{
EGraphicsAPI m_api;
EPixelFormat m_pf;
IWindow* m_parentWindow;
public:
IWindowCallback* m_callback;
CGraphicsContextXCB(EGraphicsAPI api, IWindow* parentWindow)
: m_api(api),
m_pf(PF_RGBA8),
m_parentWindow(parentWindow)
{}
~CGraphicsContextXCB()
{
}
void _setCallback(IWindowCallback* cb)
{
m_callback = cb;
}
EGraphicsAPI getAPI() const
{
return m_api;
}
EPixelFormat getPixelFormat() const
{
return m_pf;
}
void setPixelFormat(EPixelFormat pf)
{
if (pf > PF_RGBAF32_Z24)
return;
m_pf = pf;
}
void setPlatformWindowHandle(void* handle)
{
}
void initializeContext()
{
}
IGraphicsContext* makeShareContext() const
{
}
void makeCurrent()
{
}
void clearCurrent()
{
}
void swapBuffer()
{
}
};
IGraphicsContext* _CGraphicsContextXCBNew(IGraphicsContext::EGraphicsAPI api,
IWindow* parentWindow)
{
}
}

View File

@ -1,4 +1,5 @@
#import <AppKit/AppKit.h> #import <AppKit/AppKit.h>
#include "IApplication.hpp"
#include "windowsys/IWindow.hpp" #include "windowsys/IWindow.hpp"
#include "windowsys/IGraphicsContext.hpp" #include "windowsys/IGraphicsContext.hpp"
@ -7,12 +8,17 @@ namespace boo {class CWindowCocoa;}
{ {
boo::CWindowCocoa* booWindow; boo::CWindowCocoa* booWindow;
} }
- (id)initWithBooWindow:(boo::CWindowCocoa*)bw; - (id)initWithBooWindow:(boo::CWindowCocoa*)bw title:(const std::string&)title;
- (void)setFrameDefault;
- (NSRect)genFrameDefault;
@end @end
namespace boo namespace boo
{ {
IGraphicsContext* _CGraphicsContextCocoaNew(IGraphicsContext::EGraphicsAPI api,
IWindow* parentWindow);
class CWindowCocoa final : public IWindow class CWindowCocoa final : public IWindow
{ {
@ -21,19 +27,25 @@ class CWindowCocoa final : public IWindow
public: public:
CWindowCocoa() CWindowCocoa(const std::string& title)
{ {
m_nsWindow = [[CWindowCocoaInternal alloc] initWithBooWindow:this]; m_nsWindow = [[CWindowCocoaInternal alloc] initWithBooWindow:this title:title];
m_gfxCtx = IGraphicsContextNew(IGraphicsContext::API_OPENGL_3_3); m_gfxCtx = _CGraphicsContextCocoaNew(IGraphicsContext::API_OPENGL_3_3, this);
m_gfxCtx->_setPlatformWindowHandle(m_nsWindow); m_gfxCtx->_setPlatformWindowHandle(m_nsWindow);
m_gfxCtx->initializeContext(); m_gfxCtx->initializeContext();
} }
void _clearWindow()
{
m_nsWindow = NULL;
}
~CWindowCocoa() ~CWindowCocoa()
{ {
[m_nsWindow orderOut:nil]; [m_nsWindow orderOut:nil];
[m_nsWindow release]; [m_nsWindow release];
delete m_gfxCtx; delete m_gfxCtx;
IApplicationInstance()->_deletedWindow(this);
} }
void setCallback(IWindowCallback* cb) void setCallback(IWindowCallback* cb)
@ -58,7 +70,7 @@ public:
void setTitle(const std::string& title) void setTitle(const std::string& title)
{ {
[m_nsWindow setTitle:[NSString stringWithUTF8String:title.c_str()]]; [m_nsWindow setTitle:[[NSString stringWithUTF8String:title.c_str()] autorelease]];
} }
void setWindowFrameDefault() void setWindowFrameDefault()
@ -106,27 +118,64 @@ public:
return TOUCH_TRACKPAD; return TOUCH_TRACKPAD;
} }
void* getPlatformHandle() const
{
return m_nsWindow;
}
}; };
IWindow* IWindowNew() IWindow* _CWindowCocoaNew(const std::string& title)
{ {
return new CWindowCocoa; return new CWindowCocoa(title);
} }
} }
@implementation CWindowCocoaInternal @implementation CWindowCocoaInternal
- (id)initWithBooWindow:(boo::CWindowCocoa *)bw - (id)initWithBooWindow:(boo::CWindowCocoa *)bw title:(const std::string&)title
{ {
self = [self initWithContentRect:NSMakeRect(0, 0, 100, 100) self = [self initWithContentRect:[self genFrameDefault]
styleMask:NSTitledWindowMask| styleMask:NSTitledWindowMask|
NSClosableWindowMask| NSClosableWindowMask|
NSMiniaturizableWindowMask| NSMiniaturizableWindowMask|
NSResizableWindowMask NSResizableWindowMask
backing:NSBackingStoreBuffered backing:NSBackingStoreBuffered
defer:YES]; defer:YES];
self.title = [[NSString stringWithUTF8String:title.c_str()] autorelease];
booWindow = bw; booWindow = bw;
return self; return self;
} }
- (void)setFrameDefault
{
[self setFrame:[self genFrameDefault] display:NO];
}
- (NSRect)genFrameDefault
{
NSScreen* mainScreen = [NSScreen mainScreen];
NSRect scrFrame = mainScreen.frame;
float width = scrFrame.size.width * 2.0 / 3.0;
float height = scrFrame.size.height * 2.0 / 3.0;
return NSMakeRect((scrFrame.size.width - width) / 2.0,
(scrFrame.size.height - height) / 2.0,
width, height);
}
- (void)close
{
booWindow->_clearWindow();
[super close];
}
- (BOOL)acceptsFirstResponder
{
return YES;
}
- (BOOL)acceptsMouseMovedEvents
{
return YES;
}
- (NSWindowCollectionBehavior)collectionBehavior
{
return NSWindowCollectionBehaviorFullScreenPrimary;
}
@end @end

View File

@ -0,0 +1,93 @@
#include "windowsys/IWindow.hpp"
#include "windowsys/IGraphicsContext.hpp"
namespace boo
{
IGraphicsContext* _CGraphicsContextWaylandNew(IGraphicsContext::EGraphicsAPI api,
IWindow* parentWindow);
class CWindowWayland final : public IWindow
{
public:
CWindowWayland(const std::string& title)
{
}
~CWindowWayland()
{
}
void setCallback(IWindowCallback* cb)
{
}
void showWindow()
{
}
void hideWindow()
{
}
std::string getTitle()
{
}
void setTitle(const std::string& title)
{
}
void setWindowFrameDefault()
{
}
void getWindowFrame(float& xOut, float& yOut, float& wOut, float& hOut) const
{
}
void setWindowFrame(float x, float y, float w, float h)
{
}
float getVirtualPixelFactor() const
{
}
bool isFullscreen() const
{
}
void setFullscreen(bool fs)
{
}
ETouchType getTouchType() const
{
}
};
IWindow* _CWindowWaylandNew(const std::string& title)
{
return new CWindowWayland(title);
}
}

View File

@ -0,0 +1,96 @@
#include "windowsys/IWindow.hpp"
#include "windowsys/IGraphicsContext.hpp"
namespace boo
{
IGraphicsContext* _CGraphicsContextWin32New(IGraphicsContext::EGraphicsAPI api,
IWindow* parentWindow);
class CWindowWin32 final : public IWindow
{
HWND m_hwnd;
public:
CWindowWin32(const std::string& title)
{
m_hwnd = CreateWindowW(L"BooWindow", L"BooTest", WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, NULL);
}
~CWindowWin32()
{
}
void setCallback(IWindowCallback* cb)
{
}
void showWindow()
{
}
void hideWindow()
{
}
std::string getTitle()
{
}
void setTitle(const std::string& title)
{
}
void setWindowFrameDefault()
{
}
void getWindowFrame(float& xOut, float& yOut, float& wOut, float& hOut) const
{
}
void setWindowFrame(float x, float y, float w, float h)
{
}
float getVirtualPixelFactor() const
{
}
bool isFullscreen() const
{
}
void setFullscreen(bool fs)
{
}
ETouchType getTouchType() const
{
}
};
IWindow* _CWindowWin32New(const std::string& title)
{
return new CWindowWin32(title);
}
}

View File

@ -0,0 +1,93 @@
#include "windowsys/IWindow.hpp"
#include "windowsys/IGraphicsContext.hpp"
namespace boo
{
IGraphicsContext* _CGraphicsContextXCBNew(IGraphicsContext::EGraphicsAPI api,
IWindow* parentWindow);
class CWindowXCB final : public IWindow
{
public:
CWindowXCB(const std::string& title)
{
}
~CWindowXCB()
{
}
void setCallback(IWindowCallback* cb)
{
}
void showWindow()
{
}
void hideWindow()
{
}
std::string getTitle()
{
}
void setTitle(const std::string& title)
{
}
void setWindowFrameDefault()
{
}
void getWindowFrame(float& xOut, float& yOut, float& wOut, float& hOut) const
{
}
void setWindowFrame(float x, float y, float w, float h)
{
}
float getVirtualPixelFactor() const
{
}
bool isFullscreen() const
{
}
void setFullscreen(bool fs)
{
}
ETouchType getTouchType() const
{
}
};
IWindow* _CWindowXCBNew(const std::string& title)
{
return new CWindowXCB(title);
}
}

View File

@ -1,63 +0,0 @@
#if !defined(__APPLE__) && (defined(__linux__) || defined(BSD))
#include "x11/CGLXContext.hpp"
#include <iostream>
namespace boo
{
CGLXContext::CGLXContext()
: m_majVersion(3),
m_minVersion(3),
m_display(nullptr)
{
std::cout << "Hello from GLX" << std::endl;
}
bool CGLXContext::create()
{
return true;
}
void CGLXContext::setMinVersion(const int& min)
{
m_minVersion = min;
}
void CGLXContext::setMajorVersion(const int& maj)
{
m_majVersion = maj;
}
const std::string CGLXContext::version() const
{
return "Invalid version";
}
const std::string CGLXContext::name() const
{
return "GLX Context";
}
int CGLXContext::depthSize() const
{
return -1;
}
int CGLXContext::redDepth() const
{
return -1;
}
int CGLXContext::greenDepth() const
{
return -1;
}
int CGLXContext::blueDepth() const
{
return -1;
}
}
#endif // !defined(__APPLE__) && (defined(__linux__) || defined(BSD))

View File

@ -1,4 +1,3 @@
#define _CRT_SECURE_NO_WARNINGS 1
#if __APPLE__ #if __APPLE__
#include <CoreFoundation/CoreFoundation.h> #include <CoreFoundation/CoreFoundation.h>
@ -7,10 +6,7 @@
#include <stdio.h> #include <stdio.h>
#include <boo.hpp> #include <boo.hpp>
#if _WIN32 #if _WIN32
#define _WIN32_LEAN_AND_MEAN 1
#include <windows.h>
#include <initguid.h>
#include <Usbiodef.h>
#else #else
#include <unistd.h> #include <unistd.h>
#endif #endif
@ -59,103 +55,36 @@ public:
} }
}; };
}
#if _WIN32 struct CTestApplicationCallback : public IApplicationCallback
/* This simple 'test' console app needs a full windows
* message loop for receiving device connection events
*/
static const DEV_BROADCAST_DEVICEINTERFACE_A HOTPLUG_CONF =
{ {
sizeof(DEV_BROADCAST_DEVICEINTERFACE_A), IWindow* mainWindow = NULL;
DBT_DEVTYP_DEVICEINTERFACE, boo::CTestDeviceFinder devFinder;
0, void appLaunched(IApplication* app)
GUID_DEVINTERFACE_USB_DEVICE {
mainWindow = app->newWindow("YAY!");
mainWindow->showWindow();
devFinder.startScanning();
}
void appQuitting(IApplication*)
{
delete mainWindow;
}
bool appFileOpen(IApplication*, const std::string& path)
{
printf("OPENING: %s\n", path.c_str());
return true;
}
}; };
LRESULT CALLBACK WindowProc(
_In_ HWND hwnd,
_In_ UINT uMsg,
_In_ WPARAM wParam,
_In_ LPARAM lParam
)
{
switch (uMsg)
{
case WM_CREATE:
/* Register hotplug notification with windows */
RegisterDeviceNotificationA(hwnd, (LPVOID)&HOTPLUG_CONF, DEVICE_NOTIFY_WINDOW_HANDLE);
return 0;
case WM_DEVICECHANGE:
return boo::CDeviceFinder::winDevChangedHandler(wParam, lParam);
default:
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
} }
int APIENTRY wWinMain( int main(int argc, char** argv)
_In_ HINSTANCE hInstance,
_In_ HINSTANCE,
_In_ LPTSTR,
_In_ int
)
{ {
AllocConsole(); boo::CTestApplicationCallback appCb;
freopen("CONOUT$", "w", stdout); boo::IApplication* app = IApplicationBootstrap(boo::IApplication::PLAT_AUTO, appCb, "RWK", argc, argv);
app->run();
WNDCLASS wndClass = delete app;
{
0,
WindowProc,
0,
0,
hInstance,
0,
0,
0,
0,
L"BooTestWindow"
};
RegisterClassW(&wndClass);
boo::CTestDeviceFinder finder;
finder.startScanning();
HWND hwnd = CreateWindowW(L"BooTestWindow", L"BooTest", WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, NULL);
/* Pump messages */
MSG msg = {0};
while (GetMessage(&msg, hwnd, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
#else
int main(int, char**)
{
boo::CTestDeviceFinder finder;
finder.startScanning();
boo::IWindow* window = boo::IWindowNew();
(void)window;
#if __APPLE__
CFRunLoopRun();
#endif
//delete ctx;
return 0; return 0;
} }
#endif