From f38fd4eb5e8395d1525d67cdd27a9ab60680b35a Mon Sep 17 00:00:00 2001 From: David Capello Date: Wed, 7 Oct 2015 17:56:30 -0300 Subject: [PATCH] Refactor Skia/OSX port - Moved OSXWindowDelegate to she/osx/window_delegate.h - Renamed CloseDelegate to OSXWindowImpl - Added m_ prefix to OSXWindow fields --- src/she/osx/window.h | 18 ++++----- src/she/osx/window.mm | 71 +++++---------------------------- src/she/osx/window_delegate.h | 48 ++++++++++++++++++++++ src/she/skia/skia_window_osx.mm | 10 +++-- 4 files changed, 72 insertions(+), 75 deletions(-) create mode 100644 src/she/osx/window_delegate.h diff --git a/src/she/osx/window.h b/src/she/osx/window.h index 03372f424..4cc7513b1 100644 --- a/src/she/osx/window.h +++ b/src/she/osx/window.h @@ -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 diff --git a/src/she/osx/window.mm b/src/she/osx/window.mm index aa0d9494e..f7ddcdb91 100644 --- a/src/she/osx/window.mm +++ b/src/she/osx/window.mm @@ -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 diff --git a/src/she/osx/window_delegate.h b/src/she/osx/window_delegate.h new file mode 100644 index 000000000..4bc82f644 --- /dev/null +++ b/src/she/osx/window_delegate.h @@ -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 diff --git a/src/she/skia/skia_window_osx.mm b/src/she/skia/skia_window_osx.mm index a684919c8..be7e8f3b9 100644 --- a/src/she/skia/skia_window_osx.mm +++ b/src/she/skia/skia_window_osx.mm @@ -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; } };