Refactor Skia/OSX port

- Moved OSXWindowDelegate to she/osx/window_delegate.h
- Renamed CloseDelegate to OSXWindowImpl
- Added m_ prefix to OSXWindow fields
This commit is contained in:
David Capello 2015-10-07 17:56:30 -03:00
parent 7bde73e2a3
commit f38fd4eb5e
4 changed files with 72 additions and 75 deletions

View File

@ -16,22 +16,20 @@
#include "gfx/size.h"
class CloseDelegate {
class OSXWindowImpl {
public:
virtual ~CloseDelegate() { }
virtual void notifyClose() = 0;
virtual ~OSXWindowImpl() { }
virtual void onClose() = 0;
};
@interface OSXWindow : NSWindow
{
CloseDelegate* closeDelegate;
gfx::Size clientSize;
gfx::Size restoredSize;
OSXWindowImpl* m_impl;
gfx::Size m_clientSize;
gfx::Size m_restoredSize;
}
- (OSXWindow*)init;
- (void)dealloc;
- (CloseDelegate*)closeDelegate;
- (void)setCloseDelegate:(CloseDelegate*)aDelegate;
- (OSXWindow*)initWithImpl:(OSXWindowImpl*)impl;
- (OSXWindowImpl*)impl;
- (gfx::Size)clientSize;
- (gfx::Size)restoredSize;
@end

View File

@ -13,60 +13,19 @@
#include "she/event.h"
#include "she/event_queue.h"
#include "she/osx/view.h"
#include "she/system.h"
@interface OSXWindowDelegate : NSObject
{
she::EventQueue* m_queue;
OSXWindow* m_window;
}
- (OSXWindowDelegate*)initWithWindow:(OSXWindow*)window;
- (BOOL)windowShouldClose:(id)sender;
- (void)windowWillClose:(NSNotification *)notification;
- (void)windowDidResize:(NSNotification*)notification;
- (void)windowDidMiniaturize:(NSNotification*)notification;
@end
@implementation OSXWindowDelegate
- (OSXWindowDelegate*)initWithWindow:(OSXWindow*)window
{
m_window = window;
m_queue = she::instance()->eventQueue();
return self;
}
- (BOOL)windowShouldClose:(id)sender
{
[m_window closeDelegate]->notifyClose();
return YES;
}
- (void)windowWillClose:(NSNotification*)notification
{
}
- (void)windowDidResize:(NSNotification*)notification
{
}
- (void)windowDidMiniaturize:(NSNotification*)notification
{
}
@end
#include "she/osx/window_delegate.h"
@implementation OSXWindow
- (OSXWindow*)init
- (OSXWindow*)initWithImpl:(OSXWindowImpl*)impl
{
closeDelegate = nullptr;
m_impl = impl;
NSRect rect = NSMakeRect(0, 0, 640, 480);
clientSize.w = restoredSize.w = rect.size.width;
clientSize.h = restoredSize.h = rect.size.height;
m_clientSize.w = m_restoredSize.w = rect.size.width;
m_clientSize.h = m_restoredSize.h = rect.size.height;
OSXView* view = [[[OSXView alloc] initWithFrame:rect] autorelease];
OSXView* view = [[OSXView alloc] initWithFrame:rect];
[view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
[super initWithContentRect:rect
@ -81,29 +40,19 @@
return self;
}
- (void)dealloc
- (OSXWindowImpl*)impl
{
[super dealloc];
}
- (CloseDelegate*)closeDelegate
{
return closeDelegate;
}
- (void)setCloseDelegate:(CloseDelegate*)aDelegate
{
closeDelegate = aDelegate;
return m_impl;
}
- (gfx::Size)clientSize
{
return clientSize;
return m_clientSize;
}
- (gfx::Size)restoredSize
{
return restoredSize;
return m_restoredSize;
}
@end

View File

@ -0,0 +1,48 @@
// SHE library
// Copyright (C) 2015 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
@interface OSXWindowDelegate : NSObject
{
OSXWindowImpl* m_impl;
}
- (OSXWindowDelegate*)initWithWindow:(OSXWindow*)window;
- (BOOL)windowShouldClose:(id)sender;
- (void)windowWillClose:(NSNotification *)notification;
- (void)windowDidResize:(NSNotification*)notification;
- (void)windowDidMiniaturize:(NSNotification*)notification;
@end
@implementation OSXWindowDelegate
- (OSXWindowDelegate*)initWithWindow:(OSXWindow*)window
{
m_impl = [window impl];
return self;
}
- (BOOL)windowShouldClose:(id)sender
{
she::Event ev;
ev.setType(she::Event::CloseDisplay);
//ev.setDisplay(nullptr); // TODO
she::queue_event(ev);
return NO;
}
- (void)windowWillClose:(NSNotification*)notification
{
m_impl->onClose();
}
- (void)windowDidResize:(NSNotification*)notification
{
}
- (void)windowDidMiniaturize:(NSNotification*)notification
{
}
@end

View File

@ -10,6 +10,7 @@
#include "she/skia/skia_window_osx.h"
#include "she/event.h"
#include "she/event_queue.h"
#include "she/osx/window.h"
#include "gfx/size.h"
@ -24,7 +25,7 @@
namespace she {
class SkiaWindow::Impl : public CloseDelegate {
class SkiaWindow::Impl : public OSXWindowImpl {
public:
bool closing;
int scale;
@ -40,11 +41,12 @@ public:
{
closing = false;
scale = 1;
window = [OSXWindow new];
[window setCloseDelegate:this];
window = [[OSXWindow alloc] initWithImpl:this];
}
void notifyClose() override {
// OSXWindowImpl impl
void onClose() override {
closing = true;
}
};