diff --git a/basis/core-graphics/types/types.factor b/basis/core-graphics/types/types.factor index 6e0b1001af..c7d86896c7 100644 --- a/basis/core-graphics/types/types.factor +++ b/basis/core-graphics/types/types.factor @@ -1,6 +1,6 @@ ! Copyright (C) 2009 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. -USING: alien.c-types alien.syntax kernel layouts ; +USING: alien.c-types alien.syntax kernel layouts math ; IN: core-graphics.types << cell 4 = "float" "double" ? "CGFloat" typedef >> @@ -59,7 +59,10 @@ C-STRUCT: CGRect [ set-CGRect-x ] keep ; : CGRect-x-y ( alien -- origin-x origin-y ) - [ CGRect-x ] keep CGRect-y ; + [ CGRect-x ] [ CGRect-y ] bi ; + +: CGRect-top-left ( alien -- x y ) + [ CGRect-x ] [ [ CGRect-y ] [ CGRect-h ] bi + ] bi ; C-STRUCT: CGAffineTransform { "CGFloat" "a" } diff --git a/basis/ui/backend/cocoa/cocoa.factor b/basis/ui/backend/cocoa/cocoa.factor index 59f78c242d..23b9351a20 100755 --- a/basis/ui/backend/cocoa/cocoa.factor +++ b/basis/ui/backend/cocoa/cocoa.factor @@ -3,12 +3,12 @@ USING: accessors math arrays assocs cocoa cocoa.application command-line kernel memory namespaces cocoa.messages cocoa.runtime cocoa.subclassing cocoa.pasteboard cocoa.types -cocoa.windows cocoa.classes cocoa.nibs sequences system ui +cocoa.windows cocoa.classes cocoa.nibs sequences ui ui.backend ui.clipboards ui.gadgets ui.gadgets.worlds ui.backend.cocoa.views core-foundation core-foundation.run-loop core-graphics.types threads math.rectangles fry libc generalizations alien.c-types cocoa.views -combinators io.thread ; +combinators io.thread locals ; IN: ui.backend.cocoa TUPLE: handle ; @@ -36,14 +36,17 @@ M: pasteboard set-clipboard-contents selection set-global ; : world>NSRect ( world -- NSRect ) - [ window-loc>> ] [ dim>> ] bi [ first2 ] bi@ ; + [ 0 0 ] dip dim>> first2 ; -: gadget-window ( world -- ) - dup - 2dup swap world>NSRect - [ [ -> release ] [ install-window-delegate ] bi* ] - [ ] 2bi - >>handle drop ; +: auto-position ( window loc -- ) + dup { 0 0 } = [ + drop + windows get [ -> center ] [ + peek second window-loc>> + dupd first2 -> cascadeTopLeftFromPoint: + -> setFrameTopLeftPoint: + ] if-empty + ] [ first2 -> setFrameTopLeftPoint: ] if ; M: cocoa-ui-backend set-title ( string world -- ) handle>> window>> swap -> setTitle: ; @@ -63,17 +66,16 @@ M: cocoa-ui-backend set-fullscreen* ( ? world -- ) M: cocoa-ui-backend fullscreen* ( world -- ? ) handle>> view>> -> isInFullScreenMode zero? not ; -: auto-position ( world -- ) - dup window-loc>> { 0 0 } = [ - handle>> window>> -> center - ] [ - drop - ] if ; - -M: cocoa-ui-backend (open-window) ( world -- ) - dup gadget-window - dup auto-position - handle>> window>> f -> makeKeyAndOrderFront: ; +M:: cocoa-ui-backend (open-window) ( world -- ) + world dim>> :> view + view world world>NSRect :> window + view -> release + window world window-loc>> auto-position + world view register-window + world window save-position + window install-window-delegate + view window world (>>handle) + window f -> makeKeyAndOrderFront: ; M: cocoa-ui-backend (close-window) ( handle -- ) window>> -> release ; diff --git a/basis/ui/backend/cocoa/views/views.factor b/basis/ui/backend/cocoa/views/views.factor index 42add9a23b..b189b31392 100644 --- a/basis/ui/backend/cocoa/views/views.factor +++ b/basis/ui/backend/cocoa/views/views.factor @@ -365,10 +365,11 @@ CLASS: { -> openGLContext -> CGLContextObj NSOpenGLCPSwapInterval 1 CGLSetParameter drop ; -: ( world -- view ) - FactorView over dim>> - [ sync-refresh-to-screen ] keep - [ register-window ] keep ; +: ( dim -- view ) + FactorView swap [ sync-refresh-to-screen ] keep ; + +: save-position ( world window -- ) + -> frame CGRect-top-left 2array >>window-loc drop ; CLASS: { { +superclass+ "NSObject" } @@ -377,10 +378,7 @@ CLASS: { { "windowDidMove:" "void" { "id" "SEL" "id" } [ - 2nip -> object - [ -> contentView window ] - [ window-content-rect CGRect-x-y 2array ] bi - >>window-loc drop + 2nip -> object [ -> contentView window ] keep save-position ] }