[aseprite] 146/250: Refactor Skia/OSX port

Tobias Hansen thansen at moszumanska.debian.org
Sun Dec 20 15:27:22 UTC 2015


This is an automated email from the git hooks/post-receive script.

thansen pushed a commit to branch master
in repository aseprite.

commit f38fd4eb5e8395d1525d67cdd27a9ab60680b35a
Author: David Capello <davidcapello at gmail.com>
Date:   Wed Oct 7 17:56:30 2015 -0300

    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(-)

diff --git a/src/she/osx/window.h b/src/she/osx/window.h
index 03372f4..4cc7513 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 aa0d949..f7ddcdb 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"
-
- at 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;
- at end
-
- at 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
-{
-}
-
- at 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
-{
-  [super dealloc];
-}
-
-- (CloseDelegate*)closeDelegate
-{
-  return closeDelegate;
-}
-
-- (void)setCloseDelegate:(CloseDelegate*)aDelegate
+- (OSXWindowImpl*)impl
 {
-  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 0000000..4bc82f6
--- /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.
+
+ at 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;
+ at end
+
+ at 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
+{
+}
+
+ at end
diff --git a/src/she/skia/skia_window_osx.mm b/src/she/skia/skia_window_osx.mm
index a684919..be7e8f3 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;
   }
 };

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/aseprite.git



More information about the Pkg-games-commits mailing list