Remove most usages of the global 'world'
parent
278ab26fa5
commit
e046091ccf
|
@ -31,7 +31,12 @@
|
||||||
|
|
||||||
+ ui/help:
|
+ ui/help:
|
||||||
|
|
||||||
- unregister notifications in dealloc
|
- flickering incremental layout
|
||||||
|
- expired aliens in view hash
|
||||||
|
- try launchpad with bevel buttons replaced by buttons: there's
|
||||||
|
overpainting
|
||||||
|
- artifacts while resizing
|
||||||
|
- unregister notifications and the view in dealloc
|
||||||
- segfault when closing window
|
- segfault when closing window
|
||||||
- wheel mouse is a bit funny
|
- wheel mouse is a bit funny
|
||||||
- changelog in the UI
|
- changelog in the UI
|
||||||
|
|
|
@ -27,7 +27,8 @@ objc-NSNotificationCenter objc-NSObject objc-NSView threads ;
|
||||||
|
|
||||||
: event-loop ( -- )
|
: event-loop ( -- )
|
||||||
[
|
[
|
||||||
NSApplication [sharedApplication] do-events world-step
|
NSApplication [sharedApplication] do-events
|
||||||
|
world get world-step
|
||||||
] with-autorelease-pool 10 sleep event-loop ;
|
] with-autorelease-pool 10 sleep event-loop ;
|
||||||
|
|
||||||
: add-observer ( observer selector name object -- )
|
: add-observer ( observer selector name object -- )
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
! Copyright (C) 2006 Slava Pestov.
|
! Copyright (C) 2006 Slava Pestov.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: arrays cocoa freetype gadgets-layouts gadgets-listener
|
USING: arrays cocoa freetype gadgets-layouts
|
||||||
gadgets-panes hashtables kernel lists math namespaces objc
|
gadgets-listener gadgets-panes hashtables kernel lists math
|
||||||
objc-NSApplication objc-NSEvent objc-NSObject objc-NSOpenGLView
|
namespaces objc objc-NSApplication objc-NSEvent objc-NSObject
|
||||||
objc-NSView objc-NSWindow sequences threads ;
|
objc-NSOpenGLView objc-NSView objc-NSWindow sequences threads ;
|
||||||
|
|
||||||
! Cocoa backend for Factor UI
|
! Cocoa backend for Factor UI
|
||||||
|
|
||||||
|
@ -29,11 +29,6 @@ H{ } clone views set-global
|
||||||
|
|
||||||
: view ( handle -- world ) views get hash ;
|
: view ( handle -- world ) views get hash ;
|
||||||
|
|
||||||
: draw-view ( view -- )
|
|
||||||
dup [openGLContext] [
|
|
||||||
dup view-dim init-gl view draw-gadget
|
|
||||||
] with-gl-context ;
|
|
||||||
|
|
||||||
: mouse-location ( event view -- loc )
|
: mouse-location ( event view -- loc )
|
||||||
[
|
[
|
||||||
swap [locationInWindow] f [convertPoint:fromView:]
|
swap [locationInWindow] f [convertPoint:fromView:]
|
||||||
|
@ -85,7 +80,7 @@ H{ } clone views set-global
|
||||||
|
|
||||||
"NSOpenGLView" "FactorView" {
|
"NSOpenGLView" "FactorView" {
|
||||||
{ "drawRect:" "void" { "id" "SEL" "NSRect" }
|
{ "drawRect:" "void" { "id" "SEL" "NSRect" }
|
||||||
[ 2drop draw-view ]
|
[ 2drop [ view draw-world ] with-gl-view ]
|
||||||
}
|
}
|
||||||
|
|
||||||
{ "mouseMoved:" "void" { "id" "SEL" "id" }
|
{ "mouseMoved:" "void" { "id" "SEL" "id" }
|
||||||
|
@ -158,8 +153,9 @@ IN: shells
|
||||||
: ui
|
: ui
|
||||||
[
|
[
|
||||||
[
|
[
|
||||||
{ 600 700 0 } >r <listener> r> <world> world set
|
<listener>
|
||||||
world get ui-title <FactorWindow>
|
{ 600 700 0 } <world> world set
|
||||||
|
world get "Listener" <FactorWindow> drop
|
||||||
[ clear listener-thread ] in-thread
|
[ clear listener-thread ] in-thread
|
||||||
pane get request-focus
|
pane get request-focus
|
||||||
finish-launching
|
finish-launching
|
||||||
|
|
|
@ -16,6 +16,9 @@ objc-NSOpenGLView objc-NSView opengl sequences ;
|
||||||
[ [makeCurrentContext] call glFlush ] keep
|
[ [makeCurrentContext] call glFlush ] keep
|
||||||
[flushBuffer] ; inline
|
[flushBuffer] ; inline
|
||||||
|
|
||||||
|
: with-gl-view ( view quot -- | quot: view -- )
|
||||||
|
>r dup [openGLContext] r> with-gl-context ; inline
|
||||||
|
|
||||||
: view-dim [bounds] dup NSRect-w swap NSRect-h 0 3array ;
|
: view-dim [bounds] dup NSRect-w swap NSRect-h 0 3array ;
|
||||||
|
|
||||||
: NSViewFrameDidChangeNotification
|
: NSViewFrameDidChangeNotification
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
IN: gadgets-presentations
|
IN: gadgets-presentations
|
||||||
USING: compiler gadgets gadgets-buttons gadgets-listener
|
USING: arrays compiler gadgets gadgets-buttons gadgets-listener
|
||||||
gadgets-menus gadgets-panes generic hashtables inference
|
gadgets-menus gadgets-panes generic hashtables inference
|
||||||
inspector io jedit kernel lists namespaces parser prettyprint
|
inspector io jedit kernel lists namespaces parser prettyprint
|
||||||
sequences strings styles words ;
|
sequences strings styles words ;
|
||||||
|
@ -39,7 +39,7 @@ TUPLE: command-button object ;
|
||||||
|
|
||||||
: <command-menu-item> ( presented command -- item )
|
: <command-menu-item> ( presented command -- item )
|
||||||
[ command>quot [ drop ] swap append ] keep
|
[ command>quot [ drop ] swap append ] keep
|
||||||
command-name swons ;
|
command-name swap 2array ;
|
||||||
|
|
||||||
: <command-menu> ( presented -- menu )
|
: <command-menu> ( presented -- menu )
|
||||||
dup applicable
|
dup applicable
|
||||||
|
@ -47,7 +47,7 @@ TUPLE: command-button object ;
|
||||||
|
|
||||||
: command-menu ( command-button -- )
|
: command-menu ( command-button -- )
|
||||||
dup button-update
|
dup button-update
|
||||||
command-button-object <command-menu>
|
[ command-button-object <command-menu> ] keep
|
||||||
show-hand-menu ;
|
show-hand-menu ;
|
||||||
|
|
||||||
: command-button-actions ( gadget -- )
|
: command-button-actions ( gadget -- )
|
||||||
|
|
|
@ -74,13 +74,14 @@ TUPLE: editor line caret font color ;
|
||||||
dup screen-loc swap editor-caret rect-extent nip v+ ;
|
dup screen-loc swap editor-caret rect-extent nip v+ ;
|
||||||
|
|
||||||
: <completion-item> ( completion editor -- menu-item )
|
: <completion-item> ( completion editor -- menu-item )
|
||||||
dupd [ [ complete ] with-editor drop ] curry curry cons ;
|
dupd [ [ complete ] with-editor drop ] curry curry 2array ;
|
||||||
|
|
||||||
: <completion-menu> ( editor completions -- menu )
|
: <completion-menu> ( editor completions -- menu )
|
||||||
[ swap <completion-item> ] map-with <menu> ;
|
[ swap <completion-item> ] map-with <menu> ;
|
||||||
|
|
||||||
: completion-menu ( editor completions -- )
|
: completion-menu ( editor completions -- )
|
||||||
over >r <completion-menu> r> popup-location show-menu ;
|
over popup-location -rot
|
||||||
|
over >r <completion-menu> r> show-menu ;
|
||||||
|
|
||||||
: do-completion-1 ( editor completions -- )
|
: do-completion-1 ( editor completions -- )
|
||||||
swap [ first complete ] with-editor ;
|
swap [ first complete ] with-editor ;
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
IN: gadgets-launchpad
|
||||||
|
USING: gadgets-buttons gadgets-labels gadgets-layouts io kernel
|
||||||
|
memory namespaces sequences ;
|
||||||
|
|
||||||
|
: <launchpad> ( menu -- )
|
||||||
|
[ first2 >r <label> r> <bevel-button> ] map make-pile ;
|
||||||
|
|
||||||
|
: default-launchpad
|
||||||
|
{
|
||||||
|
{ "Listener" [ global [ "Hi" print ] bind drop ] }
|
||||||
|
{ "Browser" [ global [ "Hi" print ] bind drop ] }
|
||||||
|
{ "Inspector" [ global [ "Hi" print ] bind drop ] }
|
||||||
|
{ "Help" [ global [ "Hi" print ] bind drop ] }
|
||||||
|
{ "Tutorial" [ global [ "Hi" print ] bind drop ] }
|
||||||
|
{ "System" [ global [ "Hi" print ] bind drop ] }
|
||||||
|
{ "Save image" [ save ] }
|
||||||
|
{ "Exit" [ 0 exit ] }
|
||||||
|
} <launchpad> ;
|
|
@ -5,40 +5,36 @@ USING: gadgets gadgets-borders gadgets-buttons gadgets-layouts
|
||||||
gadgets-labels gadgets-theme generic kernel lists math
|
gadgets-labels gadgets-theme generic kernel lists math
|
||||||
namespaces sequences ;
|
namespaces sequences ;
|
||||||
|
|
||||||
: retarget-drag ( -- )
|
: retarget-drag ( gadget -- )
|
||||||
hand get [ hand-gadget ] keep 2dup hand-clicked eq?
|
hand get [ hand-gadget ] keep 2dup hand-clicked eq?
|
||||||
[ 2dup set-hand-clicked world get update-hand ] unless
|
[ 3drop ] [ set-hand-clicked update-hand ] if ;
|
||||||
2drop ;
|
|
||||||
|
|
||||||
: retarget-click ( -- )
|
: retarget-click ( gadget -- )
|
||||||
world get dup hide-glass update-hand-gadget update-clicked ;
|
find-world dup hide-glass update-hand-gadget
|
||||||
|
update-clicked ;
|
||||||
|
|
||||||
: menu-actions ( glass -- )
|
: menu-actions ( glass -- )
|
||||||
dup [ drop retarget-drag ] [ drag ] set-action
|
dup [ retarget-drag ] [ drag ] set-action
|
||||||
[ drop retarget-click ] [ button-down ] set-action ;
|
[ retarget-click ] [ button-down ] set-action ;
|
||||||
|
|
||||||
: fit-bounds ( loc dim max -- loc )
|
: menu-loc ( loc menu world -- loc )
|
||||||
#! Adjust loc to fit inside max.
|
[ rect-dim ] 2apply swap |v-| vmin ;
|
||||||
swap |v-| vmin ;
|
|
||||||
|
|
||||||
: menu-loc ( menu loc -- loc )
|
: show-menu ( loc menu gadget -- )
|
||||||
swap rect-dim world get rect-dim fit-bounds ;
|
find-world 2dup show-glass
|
||||||
|
dup world-glass dup menu-actions hand get set-hand-clicked
|
||||||
|
over >r menu-loc r> set-rect-loc ;
|
||||||
|
|
||||||
: show-menu ( menu loc -- )
|
: show-hand-menu ( menu gadget -- )
|
||||||
>r dup dup world get show-glass r>
|
hand get rect-loc -rot show-menu ;
|
||||||
menu-loc swap set-rect-loc
|
|
||||||
world get world-glass dup menu-actions
|
|
||||||
hand get set-hand-clicked ;
|
|
||||||
|
|
||||||
: show-hand-menu ( menu -- ) hand get rect-loc show-menu ;
|
: menu-item-quot ( quot -- quot )
|
||||||
|
[ keep find-world hide-glass ] curry ;
|
||||||
|
|
||||||
: menu-items ( assoc -- pile )
|
: menu-items ( assoc -- pile )
|
||||||
#! Given an association list mapping labels to quotations.
|
#! Given an association list mapping labels to quotations.
|
||||||
#! Prepend a call to hide-menu to each quotation.
|
#! Prepend a call to hide-menu to each quotation.
|
||||||
[
|
[ first2 menu-item-quot >r <label> r> <roll-button> ] map
|
||||||
uncons [ world get hide-glass ] swap append
|
|
||||||
>r <label> r> <roll-button>
|
|
||||||
] map
|
|
||||||
make-pile 1 over set-pack-fill ;
|
make-pile 1 over set-pack-fill ;
|
||||||
|
|
||||||
: <menu> ( assoc -- gadget )
|
: <menu> ( assoc -- gadget )
|
||||||
|
|
|
@ -8,9 +8,7 @@ IN: gadgets
|
||||||
SYMBOL: clip
|
SYMBOL: clip
|
||||||
|
|
||||||
: init-gl ( dim -- )
|
: init-gl ( dim -- )
|
||||||
1.0 1.0 1.0 1.0 glClearColor
|
{ 1.0 0.0 0.0 1.0 } gl-color
|
||||||
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
|
||||||
|
@ -22,7 +20,9 @@ SYMBOL: clip
|
||||||
GL_BLEND glEnable
|
GL_BLEND glEnable
|
||||||
GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA glBlendFunc
|
GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA glBlendFunc
|
||||||
GL_SCISSOR_TEST glEnable
|
GL_SCISSOR_TEST glEnable
|
||||||
GL_MODELVIEW glMatrixMode ;
|
GL_MODELVIEW glMatrixMode
|
||||||
|
1.0 1.0 1.0 1.0 glClearColor
|
||||||
|
GL_COLOR_BUFFER_BIT glClear ;
|
||||||
|
|
||||||
GENERIC: draw-gadget* ( gadget -- )
|
GENERIC: draw-gadget* ( gadget -- )
|
||||||
|
|
||||||
|
@ -46,9 +46,11 @@ DEFER: world
|
||||||
draw-gadget*
|
draw-gadget*
|
||||||
] keep vneg gl-translate ;
|
] keep vneg gl-translate ;
|
||||||
|
|
||||||
|
SYMBOL: world-dim
|
||||||
|
|
||||||
: gl-set-clip ( loc dim -- )
|
: gl-set-clip ( loc dim -- )
|
||||||
dup first2 1+ >r >r
|
dup first2 1+ >r >r
|
||||||
over second swap second + world get rect-dim second
|
over second swap second + world-dim get second
|
||||||
swap - >r first r> r> r> glScissor ;
|
swap - >r first r> r> r> glScissor ;
|
||||||
|
|
||||||
: do-clip ( gadget -- )
|
: do-clip ( gadget -- )
|
||||||
|
@ -64,6 +66,11 @@ DEFER: world
|
||||||
] with-scope
|
] with-scope
|
||||||
] when drop ;
|
] when drop ;
|
||||||
|
|
||||||
|
: draw-world ( world -- )
|
||||||
|
[
|
||||||
|
dup rect-dim dup world-dim set init-gl draw-gadget
|
||||||
|
] with-scope ;
|
||||||
|
|
||||||
! Pen paint properties
|
! Pen paint properties
|
||||||
M: f draw-interior 2drop ;
|
M: f draw-interior 2drop ;
|
||||||
M: f draw-boundary 2drop ;
|
M: f draw-boundary 2drop ;
|
||||||
|
|
|
@ -64,10 +64,14 @@ C: world ( gadget status dim -- world )
|
||||||
#! Called when a gadget is removed or added.
|
#! Called when a gadget is removed or added.
|
||||||
hand get rect-loc swap move-hand ;
|
hand get rect-loc swap move-hand ;
|
||||||
|
|
||||||
: ui-title
|
: world-step ( world -- )
|
||||||
[ "Factor " % version % " - " % image % ] "" make ;
|
do-timers invalid queue-empty? >r layout-queued r>
|
||||||
|
[ drop ] [ dup update-hand redraw-world ] if ;
|
||||||
|
|
||||||
: world-step ( -- )
|
GENERIC: find-world ( gadget -- world )
|
||||||
do-timers
|
|
||||||
invalid queue-empty? >r layout-queued r>
|
M: f find-world ;
|
||||||
[ world get update-hand world get redraw-world ] unless ;
|
|
||||||
|
M: gadget find-world gadget-parent find-world ;
|
||||||
|
|
||||||
|
M: world find-world ;
|
||||||
|
|
Loading…
Reference in New Issue