Don't center all windows on Cocoa

db4
Slava Pestov 2009-02-17 19:26:32 -06:00
parent 4641bfff2d
commit 4c7405f353
3 changed files with 33 additions and 30 deletions

View File

@ -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" }

View File

@ -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
<clipboard> selection set-global ;
: world>NSRect ( world -- NSRect )
[ window-loc>> ] [ dim>> ] bi [ first2 ] bi@ <CGRect> ;
[ 0 0 ] dip dim>> first2 <CGRect> ;
: gadget-window ( world -- )
dup <FactorView>
2dup swap world>NSRect <ViewWindow>
[ [ -> release ] [ install-window-delegate ] bi* ]
[ <window-handle> ] 2bi
>>handle drop ;
: auto-position ( window loc -- )
dup { 0 0 } = [
drop
windows get [ -> center ] [
peek second window-loc>>
dupd first2 <CGPoint> -> cascadeTopLeftFromPoint:
-> setFrameTopLeftPoint:
] if-empty
] [ first2 <CGPoint> -> setFrameTopLeftPoint: ] if ;
M: cocoa-ui-backend set-title ( string world -- )
handle>> window>> swap <NSString> -> 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>> <FactorView> :> view
view world world>NSRect <ViewWindow> :> window
view -> release
window world window-loc>> auto-position
world view register-window
world window save-position
window install-window-delegate
view window <window-handle> world (>>handle)
window f -> makeKeyAndOrderFront: ;
M: cocoa-ui-backend (close-window) ( handle -- )
window>> -> release ;

View File

@ -365,10 +365,11 @@ CLASS: {
-> openGLContext -> CGLContextObj NSOpenGLCPSwapInterval 1 <int>
CGLSetParameter drop ;
: <FactorView> ( world -- view )
FactorView over dim>> <GLView>
[ sync-refresh-to-screen ] keep
[ register-window ] keep ;
: <FactorView> ( dim -- view )
FactorView swap <GLView> [ 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
]
}