UI cleanups

release
slava 2006-03-15 23:24:59 +00:00
parent 7df9b774e9
commit 240c12dfc8
8 changed files with 39 additions and 54 deletions

View File

@ -10,9 +10,8 @@ objc-NSNotificationCenter objc-NSObject objc-NSView threads ;
: with-cocoa ( quot -- ) : with-cocoa ( quot -- )
[ [
NSApplication [sharedApplication] drop NSApplication [sharedApplication] drop call
call ] with-autorelease-pool ;
] with-autorelease-pool ; inline
: <NSString> <CFString> [autorelease] ; : <NSString> <CFString> [autorelease] ;
@ -23,11 +22,8 @@ objc-NSNotificationCenter objc-NSObject objc-NSView threads ;
[nextEventMatchingMask:untilDate:inMode:dequeue:] ; [nextEventMatchingMask:untilDate:inMode:dequeue:] ;
: do-events ( app -- ) : do-events ( app -- )
dup next-event [ dup next-event
dupd [ [sendEvent:] ] with-autorelease-pool do-events [ dupd [sendEvent:] do-events ] [ drop ] if* ;
] [
drop
] if* ;
: event-loop ( -- ) : event-loop ( -- )
[ [

View File

@ -56,7 +56,9 @@ FUNCTION: void CFRelease ( void* cf ) ;
CFRelease ; CFRelease ;
: <CFBundle> ( string -- cf ) : <CFBundle> ( string -- cf )
t <CFFileSystemURL> f over CFBundleCreate swap CFRelease ; t <CFFileSystemURL> [
f swap CFBundleCreate
] keep CFRelease ;
: load-framework ( name -- ) : load-framework ( name -- )
dup <CFBundle> [ dup <CFBundle> [

View File

@ -141,7 +141,8 @@ IN: gadgets-cocoa
[initWithFrame:pixelFormat:] [initWithFrame:pixelFormat:]
dup 1 [setPostsBoundsChangedNotifications:] dup 1 [setPostsBoundsChangedNotifications:]
dup 1 [setPostsFrameChangedNotifications:] dup 1 [setPostsFrameChangedNotifications:]
dup "updateFactorGadgetSize:" add-resize-observer ; dup "updateFactorGadgetSize:" add-resize-observer
[autorelease] ;
: <FactorWindow> ( gadget title -- window ) : <FactorWindow> ( gadget title -- window )
over rect-dim first2 0 0 2swap <NSRect> <NSWindow> over rect-dim first2 0 0 2swap <NSRect> <NSWindow>
@ -149,14 +150,16 @@ IN: gadgets-cocoa
[ swap set-world-handle ] keep [ swap set-world-handle ] keep
dup 1 [setAcceptsMouseMovedEvents:] dup 1 [setAcceptsMouseMovedEvents:]
dup dup [contentView] [setInitialFirstResponder:] dup dup [contentView] [setInitialFirstResponder:]
dup f [makeKeyAndOrderFront:] ; dup f [makeKeyAndOrderFront:]
[autorelease] ;
IN: shells IN: shells
: ui : ui
[ [
[ [
init-world { 600 700 0 } <world> world set
<hand> hand set
world get ui-title <FactorWindow> world get ui-title <FactorWindow>

View File

@ -63,8 +63,6 @@ GENERIC: user-input* ( str gadget -- ? )
M: gadget user-input* 2drop t ; M: gadget user-input* 2drop t ;
DEFER: add-invalid
GENERIC: children-on ( rect/point gadget -- list ) GENERIC: children-on ( rect/point gadget -- list )
M: gadget children-on ( rect/point gadget -- list ) M: gadget children-on ( rect/point gadget -- list )

View File

@ -1,8 +1,8 @@
! Copyright (C) 2005, 2006 Slava Pestov. ! Copyright (C) 2005, 2006 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
IN: gadgets-layouts
USING: errors gadgets generic hashtables kernel lists math USING: errors gadgets generic hashtables kernel lists math
namespaces sequences ; namespaces queues sequences ;
IN: gadgets-layouts
: invalidate ( gadget -- ) t swap set-gadget-relayout? ; : invalidate ( gadget -- ) t swap set-gadget-relayout? ;
@ -10,6 +10,12 @@ namespaces sequences ;
: invalidate* ( gadget -- ) dup invalidate forget-pref-dim ; : invalidate* ( gadget -- ) dup invalidate forget-pref-dim ;
: invalid ( -- queue ) \ invalid global hash ;
<queue> \ invalid set-global
: add-invalid ( gadget -- ) invalid enque ;
: relayout ( gadget -- ) : relayout ( gadget -- )
#! Relayout and redraw a gadget and its parent before the #! Relayout and redraw a gadget and its parent before the
#! next iteration of the event loop. Should be used when the #! next iteration of the event loop. Should be used when the
@ -69,6 +75,10 @@ DEFER: layout
dup layout* dup layout-children dup layout* dup layout-children
] when drop ; ] when drop ;
: layout-queued ( -- )
invalid dup queue-empty?
[ drop ] [ deque layout layout-queued ] if ;
TUPLE: pack align fill gap ; TUPLE: pack align fill gap ;
: pref-dims ( gadget -- list ) [ pref-dim ] map ; : pref-dims ( gadget -- list ) [ pref-dim ] map ;

View File

@ -8,9 +8,9 @@ IN: gadgets
SYMBOL: clip SYMBOL: clip
: init-gl ( dim -- ) : init-gl ( dim -- )
0.0 0.0 0.0 0.0 glClearColor 1.0 1.0 1.0 1.0 glClearColor
{ 1.0 0.0 0.0 0.0 } gl-color
GL_COLOR_BUFFER_BIT glClear GL_COLOR_BUFFER_BIT glClear
{ 1.0 0.0 0.0 0.0 } gl-color
GL_PROJECTION glMatrixMode GL_PROJECTION glMatrixMode
glLoadIdentity glLoadIdentity
GL_MODELVIEW glMatrixMode GL_MODELVIEW glMatrixMode

View File

@ -1,7 +1,7 @@
! Copyright (C) 2005, 2006 Slava Pestov. ! Copyright (C) 2005, 2006 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
IN: gadgets IN: gadgets
USING: hashtables kernel math sequences ; USING: hashtables kernel math namespaces sequences ;
TUPLE: timer object delay last ; TUPLE: timer object delay last ;
@ -14,7 +14,9 @@ C: timer ( object delay -- timer )
GENERIC: tick ( ms object -- ) GENERIC: tick ( ms object -- )
DEFER: timers : timers \ timers global hash ;
H{ } clone \ timers set-global
: add-timer ( object delay -- ) : add-timer ( object delay -- )
over >r <timer> r> timers set-hash ; over >r <timer> r> timers set-hash ;

View File

@ -3,7 +3,8 @@
IN: gadgets IN: gadgets
USING: alien arrays errors freetype gadgets-layouts USING: alien arrays errors freetype gadgets-layouts
gadgets-theme generic io kernel lists math memory namespaces gadgets-theme generic io kernel lists math memory namespaces
opengl prettyprint sequences sequences strings styles threads ; opengl prettyprint queues sequences sequences strings styles
threads ;
DEFER: redraw-world DEFER: redraw-world
@ -11,28 +12,15 @@ DEFER: redraw-world
! gadgets are contained in. The current world is stored in the ! gadgets are contained in. The current world is stored in the
! world variable. The invalid slot is a list of gadgets that ! world variable. The invalid slot is a list of gadgets that
! need to be layout. ! need to be layout.
TUPLE: world glass status invalid timers handle ; TUPLE: world glass status handle ;
: timers ( -- hash ) world get world-timers ;
: add-layer ( gadget -- ) : add-layer ( gadget -- )
world get add-gadget ; world get add-gadget ;
C: world ( -- world ) C: world ( dim -- world )
<stack> over set-delegate <stack> over set-delegate
dup solid-interior [ set-gadget-dim ] keep
t over set-gadget-root? t over set-gadget-root? ;
H{ } clone over set-world-timers ;
: add-invalid ( gadget -- )
world get [ world-invalid cons ] keep set-world-invalid ;
: pop-invalid ( -- list )
world get [ world-invalid f ] keep set-world-invalid ;
: layout-world ( -- )
world get world-invalid
[ pop-invalid [ layout ] each layout-world ] when ;
: hide-glass ( -- ) : hide-glass ( -- )
f world get dup world-glass unparent set-world-glass ; f world get dup world-glass unparent set-world-glass ;
@ -84,19 +72,5 @@ M: f set-message 2drop ;
: world-step ( -- ) : world-step ( -- )
do-timers do-timers
world get world-invalid >r layout-world r> invalid queue-empty? >r layout-queued r>
[ update-hand world get redraw-world ] when ; [ update-hand world get redraw-world ] unless ;
SYMBOL: first-time
global [ first-time on ] bind
: init-world ( -- )
global [
first-time get [
<world> world set
{ 600 700 0 } world get set-gadget-dim
<hand> hand set
first-time off
] when
] bind ;