Merge branch 'master' of git://factorcode.org/git/factor
commit
302930fa43
|
@ -60,6 +60,7 @@ SYNTAX: IMPORT: scan [ ] import-objc-class ;
|
||||||
"NSOpenGLPixelFormat"
|
"NSOpenGLPixelFormat"
|
||||||
"NSOpenGLView"
|
"NSOpenGLView"
|
||||||
"NSOpenPanel"
|
"NSOpenPanel"
|
||||||
|
"NSPanel"
|
||||||
"NSPasteboard"
|
"NSPasteboard"
|
||||||
"NSPropertyListSerialization"
|
"NSPropertyListSerialization"
|
||||||
"NSResponder"
|
"NSResponder"
|
||||||
|
|
|
@ -4,36 +4,37 @@ USING: arrays kernel math cocoa cocoa.messages cocoa.classes
|
||||||
sequences math.bitwise ;
|
sequences math.bitwise ;
|
||||||
IN: cocoa.windows
|
IN: cocoa.windows
|
||||||
|
|
||||||
|
! Window styles
|
||||||
CONSTANT: NSBorderlessWindowMask 0
|
CONSTANT: NSBorderlessWindowMask 0
|
||||||
CONSTANT: NSTitledWindowMask 1
|
CONSTANT: NSTitledWindowMask 1
|
||||||
CONSTANT: NSClosableWindowMask 2
|
CONSTANT: NSClosableWindowMask 2
|
||||||
CONSTANT: NSMiniaturizableWindowMask 4
|
CONSTANT: NSMiniaturizableWindowMask 4
|
||||||
CONSTANT: NSResizableWindowMask 8
|
CONSTANT: NSResizableWindowMask 8
|
||||||
|
|
||||||
|
! Additional panel-only styles
|
||||||
|
CONSTANT: NSUtilityWindowMask 16
|
||||||
|
CONSTANT: NSDocModalWindowMask 64
|
||||||
|
CONSTANT: NSNonactivatingPanelMask 128
|
||||||
|
CONSTANT: NSHUDWindowMask HEX: 1000
|
||||||
|
|
||||||
CONSTANT: NSBackingStoreRetained 0
|
CONSTANT: NSBackingStoreRetained 0
|
||||||
CONSTANT: NSBackingStoreNonretained 1
|
CONSTANT: NSBackingStoreNonretained 1
|
||||||
CONSTANT: NSBackingStoreBuffered 2
|
CONSTANT: NSBackingStoreBuffered 2
|
||||||
|
|
||||||
: standard-window-type ( -- n )
|
: <NSWindow> ( rect style class -- window )
|
||||||
{
|
[ -> alloc ] curry 2dip NSBackingStoreBuffered 1
|
||||||
NSTitledWindowMask
|
|
||||||
NSClosableWindowMask
|
|
||||||
NSMiniaturizableWindowMask
|
|
||||||
NSResizableWindowMask
|
|
||||||
} flags ; inline
|
|
||||||
|
|
||||||
: <NSWindow> ( rect -- window )
|
|
||||||
NSWindow -> alloc swap
|
|
||||||
standard-window-type NSBackingStoreBuffered 1
|
|
||||||
-> initWithContentRect:styleMask:backing:defer: ;
|
-> initWithContentRect:styleMask:backing:defer: ;
|
||||||
|
|
||||||
: <ViewWindow> ( view rect -- window )
|
: class-for-style ( style -- NSWindow/NSPanel )
|
||||||
<NSWindow> [ swap -> setContentView: ] keep
|
HEX: 1ff0 bitand zero? NSWindow NSPanel ? ;
|
||||||
|
|
||||||
|
: <ViewWindow> ( view rect style -- window )
|
||||||
|
dup class-for-style <NSWindow> [ swap -> setContentView: ] keep
|
||||||
dup dup -> contentView -> setInitialFirstResponder:
|
dup dup -> contentView -> setInitialFirstResponder:
|
||||||
dup 1 -> setAcceptsMouseMovedEvents:
|
dup 1 -> setAcceptsMouseMovedEvents:
|
||||||
dup 0 -> setReleasedWhenClosed: ;
|
dup 0 -> setReleasedWhenClosed: ;
|
||||||
|
|
||||||
: window-content-rect ( window -- rect )
|
: window-content-rect ( window -- rect )
|
||||||
[ NSWindow ] dip
|
dup -> class swap
|
||||||
[ -> frame ] [ -> styleMask ] bi
|
[ -> frame ] [ -> styleMask ] bi
|
||||||
-> contentRectForFrameRect:styleMask: ;
|
-> contentRectForFrameRect:styleMask: ;
|
||||||
|
|
|
@ -190,7 +190,7 @@ TUPLE: window-rect < rect window-loc ;
|
||||||
DBT_DEVTYP_DEVICEINTERFACE over set-DEV_BROADCAST_DEVICEW-dbcc_devicetype ;
|
DBT_DEVTYP_DEVICEINTERFACE over set-DEV_BROADCAST_DEVICEW-dbcc_devicetype ;
|
||||||
|
|
||||||
: create-device-change-window ( -- )
|
: create-device-change-window ( -- )
|
||||||
<zero-window-rect> create-window
|
<zero-window-rect> WS_OVERLAPPEDWINDOW 0 create-window
|
||||||
[
|
[
|
||||||
(device-notification-filter)
|
(device-notification-filter)
|
||||||
DEVICE_NOTIFY_WINDOW_HANDLE DEVICE_NOTIFY_ALL_INTERFACE_CLASSES bitor
|
DEVICE_NOTIFY_WINDOW_HANDLE DEVICE_NOTIFY_ALL_INTERFACE_CLASSES bitor
|
||||||
|
|
|
@ -19,3 +19,7 @@ PRIVATE>
|
||||||
SYNTAX: $ scan-word expand-literal >vector ;
|
SYNTAX: $ scan-word expand-literal >vector ;
|
||||||
SYNTAX: $[ parse-quotation with-datastack >vector ;
|
SYNTAX: $[ parse-quotation with-datastack >vector ;
|
||||||
SYNTAX: ${ \ } [ expand-literals ] parse-literal ;
|
SYNTAX: ${ \ } [ expand-literals ] parse-literal ;
|
||||||
|
|
||||||
|
SYNTAX: $$
|
||||||
|
scan-word execute( accum -- accum ) dup pop [ >quotation ] keep
|
||||||
|
[ output>sequence ] 2curry call( -- object ) parsed ;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
! Copyright (C) 2008 Doug Coleman.
|
! Copyright (C) 2008 Doug Coleman.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: help.markup help.syntax math sequences ;
|
USING: assocs help.markup help.syntax math sequences ;
|
||||||
IN: math.bitwise
|
IN: math.bitwise
|
||||||
|
|
||||||
HELP: bitfield
|
HELP: bitfield
|
||||||
|
@ -145,6 +145,25 @@ HELP: flags
|
||||||
}
|
}
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
|
HELP: symbols>flags
|
||||||
|
{ $values { "symbols" sequence } { "assoc" assoc } { "flag-bits" integer } }
|
||||||
|
{ $description "Constructs an integer value by mapping the values in the " { $snippet "symbols" } " sequence to integer values using " { $snippet "assoc" } " and " { $link bitor } "ing the values together." }
|
||||||
|
{ $examples
|
||||||
|
{ $example "USING: math.bitwise prettyprint ui.gadgets.worlds ;"
|
||||||
|
"IN: scratchpad"
|
||||||
|
"CONSTANT: window-controls>flags H{"
|
||||||
|
" { close-button 1 }"
|
||||||
|
" { minimize-button 2 }"
|
||||||
|
" { maximize-button 4 }"
|
||||||
|
" { resize-handles 8 }"
|
||||||
|
" { small-title-bar 16 }"
|
||||||
|
" { normal-title-bar 32 }"
|
||||||
|
"}"
|
||||||
|
"{ resize-handles close-button small-title-bar } window-controls>flags symbols>flags ."
|
||||||
|
"25"
|
||||||
|
}
|
||||||
|
} ;
|
||||||
|
|
||||||
HELP: mask
|
HELP: mask
|
||||||
{ $values
|
{ $values
|
||||||
{ "x" integer } { "n" integer }
|
{ "x" integer } { "n" integer }
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
! Copyright (C) 2007, 2008 Slava Pestov, Doug Coleman.
|
! Copyright (C) 2007, 2008 Slava Pestov, Doug Coleman.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: arrays kernel math sequences accessors math.bits
|
USING: arrays assocs kernel math sequences accessors
|
||||||
sequences.private words namespaces macros hints
|
math.bits sequences.private words namespaces macros
|
||||||
combinators fry io.binary combinators.smart ;
|
hints combinators fry io.binary combinators.smart ;
|
||||||
IN: math.bitwise
|
IN: math.bitwise
|
||||||
|
|
||||||
! utilities
|
! utilities
|
||||||
|
@ -44,6 +44,10 @@ IN: math.bitwise
|
||||||
MACRO: flags ( values -- )
|
MACRO: flags ( values -- )
|
||||||
[ 0 ] [ [ ?execute bitor ] curry compose ] reduce ;
|
[ 0 ] [ [ ?execute bitor ] curry compose ] reduce ;
|
||||||
|
|
||||||
|
: symbols>flags ( symbols assoc -- flag-bits )
|
||||||
|
[ at ] curry map
|
||||||
|
0 [ bitor ] reduce ;
|
||||||
|
|
||||||
! bitfield
|
! bitfield
|
||||||
<PRIVATE
|
<PRIVATE
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@ IN: opengl
|
||||||
{ HEX: 0503 "Stack overflow" }
|
{ HEX: 0503 "Stack overflow" }
|
||||||
{ HEX: 0504 "Stack underflow" }
|
{ HEX: 0504 "Stack underflow" }
|
||||||
{ HEX: 0505 "Out of memory" }
|
{ HEX: 0505 "Out of memory" }
|
||||||
|
{ HEX: 0506 "Invalid framebuffer operation" }
|
||||||
} at "Unknown error" or ;
|
} at "Unknown error" or ;
|
||||||
|
|
||||||
TUPLE: gl-error code string ;
|
TUPLE: gl-error code string ;
|
||||||
|
@ -190,4 +191,4 @@ MACRO: set-draw-buffers ( buffers -- )
|
||||||
GL_PROJECTION glMatrixMode
|
GL_PROJECTION glMatrixMode
|
||||||
glLoadIdentity
|
glLoadIdentity
|
||||||
GL_MODELVIEW glMatrixMode
|
GL_MODELVIEW glMatrixMode
|
||||||
glLoadIdentity ;
|
glLoadIdentity ;
|
||||||
|
|
|
@ -61,10 +61,21 @@ PREDICATE: fragment-shader < gl-shader (fragment-shader?) ;
|
||||||
|
|
||||||
! Programs
|
! Programs
|
||||||
|
|
||||||
|
: <mrt-gl-program> ( shaders frag-data-locations -- program )
|
||||||
|
glCreateProgram
|
||||||
|
[
|
||||||
|
[ swap [ glAttachShader ] with each ]
|
||||||
|
[ swap [ first2 swap glBindFragDataLocationEXT ] with each ] bi-curry bi*
|
||||||
|
]
|
||||||
|
[ glLinkProgram ]
|
||||||
|
[ ] tri
|
||||||
|
gl-error ;
|
||||||
|
|
||||||
: <gl-program> ( shaders -- program )
|
: <gl-program> ( shaders -- program )
|
||||||
glCreateProgram swap
|
glCreateProgram
|
||||||
[ dupd glAttachShader ] each
|
[ swap [ glAttachShader ] with each ]
|
||||||
[ glLinkProgram ] keep
|
[ glLinkProgram ]
|
||||||
|
[ ] tri
|
||||||
gl-error ;
|
gl-error ;
|
||||||
|
|
||||||
: (gl-program?) ( object -- ? )
|
: (gl-program?) ( object -- ? )
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
! Copyright (C) 2007 Doug Coleman.
|
! Copyright (C) 2007 Doug Coleman.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: accessors arrays assocs fry generalizations grouping
|
USING: accessors arrays assocs effects fry generalizations
|
||||||
kernel lexer macros make math math.order math.vectors
|
grouping kernel lexer macros math math.order math.vectors
|
||||||
namespaces parser quotations sequences sequences.private
|
namespaces parser quotations sequences sequences.private
|
||||||
splitting.monotonic stack-checker strings unicode.case
|
splitting.monotonic stack-checker strings unicode.case words ;
|
||||||
words effects ;
|
|
||||||
IN: roman
|
IN: roman
|
||||||
|
|
||||||
<PRIVATE
|
<PRIVATE
|
||||||
|
@ -17,23 +16,18 @@ CONSTANT: roman-values
|
||||||
|
|
||||||
ERROR: roman-range-error n ;
|
ERROR: roman-range-error n ;
|
||||||
|
|
||||||
: roman-range-check ( n -- )
|
: roman-range-check ( n -- n )
|
||||||
dup 1 3999 between? [ drop ] [ roman-range-error ] if ;
|
dup 1 3999 between? [ roman-range-error ] unless ;
|
||||||
|
|
||||||
: roman-digit-index ( ch -- n )
|
: roman-digit-index ( ch -- n )
|
||||||
1string roman-digits index ; inline
|
1string roman-digits index ; inline
|
||||||
|
|
||||||
: roman<= ( ch1 ch2 -- ? )
|
: roman>= ( ch1 ch2 -- ? )
|
||||||
[ roman-digit-index ] bi@ >= ;
|
[ roman-digit-index ] bi@ >= ;
|
||||||
|
|
||||||
: roman>n ( ch -- n )
|
: roman>n ( ch -- n )
|
||||||
roman-digit-index roman-values nth ;
|
roman-digit-index roman-values nth ;
|
||||||
|
|
||||||
: (>roman) ( n -- )
|
|
||||||
roman-values roman-digits [
|
|
||||||
[ /mod swap ] dip <repetition> concat %
|
|
||||||
] 2each drop ;
|
|
||||||
|
|
||||||
: (roman>) ( seq -- n )
|
: (roman>) ( seq -- n )
|
||||||
[ [ roman>n ] map ] [ all-eq? ] bi
|
[ [ roman>n ] map ] [ all-eq? ] bi
|
||||||
[ sum ] [ first2 swap - ] if ;
|
[ sum ] [ first2 swap - ] if ;
|
||||||
|
@ -41,12 +35,15 @@ ERROR: roman-range-error n ;
|
||||||
PRIVATE>
|
PRIVATE>
|
||||||
|
|
||||||
: >roman ( n -- str )
|
: >roman ( n -- str )
|
||||||
dup roman-range-check [ (>roman) ] "" make ;
|
roman-range-check
|
||||||
|
roman-values roman-digits [
|
||||||
|
[ /mod swap ] dip <repetition> concat
|
||||||
|
] 2map "" concat-as nip ;
|
||||||
|
|
||||||
: >ROMAN ( n -- str ) >roman >upper ;
|
: >ROMAN ( n -- str ) >roman >upper ;
|
||||||
|
|
||||||
: roman> ( str -- n )
|
: roman> ( str -- n )
|
||||||
>lower [ roman<= ] monotonic-split [ (roman>) ] sigma ;
|
>lower [ roman>= ] monotonic-split [ (roman>) ] sigma ;
|
||||||
|
|
||||||
<PRIVATE
|
<PRIVATE
|
||||||
|
|
||||||
|
@ -57,11 +54,13 @@ MACRO: binary-roman-op ( quot -- quot' )
|
||||||
PRIVATE>
|
PRIVATE>
|
||||||
|
|
||||||
<<
|
<<
|
||||||
|
|
||||||
SYNTAX: ROMAN-OP:
|
SYNTAX: ROMAN-OP:
|
||||||
scan-word [ name>> "roman" prepend create-in ] keep
|
scan-word [ name>> "roman" prepend create-in ] keep
|
||||||
1quotation '[ _ binary-roman-op ]
|
1quotation '[ _ binary-roman-op ]
|
||||||
dup infer [ in>> ] [ out>> ] bi
|
dup infer [ in>> ] [ out>> ] bi
|
||||||
[ "string" <repetition> ] bi@ <effect> define-declared ;
|
[ "string" <repetition> ] bi@ <effect> define-declared ;
|
||||||
|
|
||||||
>>
|
>>
|
||||||
|
|
||||||
ROMAN-OP: +
|
ROMAN-OP: +
|
||||||
|
|
|
@ -6,7 +6,7 @@ cocoa.pasteboard cocoa.runtime cocoa.subclassing cocoa.types
|
||||||
cocoa.views cocoa.windows combinators command-line
|
cocoa.views cocoa.windows combinators command-line
|
||||||
core-foundation core-foundation.run-loop core-graphics
|
core-foundation core-foundation.run-loop core-graphics
|
||||||
core-graphics.types destructors fry generalizations io.thread
|
core-graphics.types destructors fry generalizations io.thread
|
||||||
kernel libc literals locals math math.rectangles memory
|
kernel libc literals locals math math.bitwise math.rectangles memory
|
||||||
namespaces sequences specialized-arrays.int threads ui
|
namespaces sequences specialized-arrays.int threads ui
|
||||||
ui.backend ui.backend.cocoa.views ui.clipboards ui.gadgets
|
ui.backend ui.backend.cocoa.views ui.clipboards ui.gadgets
|
||||||
ui.gadgets.worlds ui.pixel-formats ui.pixel-formats.private
|
ui.gadgets.worlds ui.pixel-formats ui.pixel-formats.private
|
||||||
|
@ -109,10 +109,23 @@ M: cocoa-ui-backend (set-fullscreen) ( world ? -- )
|
||||||
M: cocoa-ui-backend (fullscreen?) ( world -- ? )
|
M: cocoa-ui-backend (fullscreen?) ( world -- ? )
|
||||||
handle>> view>> -> isInFullScreenMode zero? not ;
|
handle>> view>> -> isInFullScreenMode zero? not ;
|
||||||
|
|
||||||
|
CONSTANT: window-control>styleMask
|
||||||
|
H{
|
||||||
|
{ close-button $ NSClosableWindowMask }
|
||||||
|
{ minimize-button $ NSMiniaturizableWindowMask }
|
||||||
|
{ maximize-button 0 }
|
||||||
|
{ resize-handles $ NSResizableWindowMask }
|
||||||
|
{ small-title-bar $[ NSTitledWindowMask NSUtilityWindowMask bitor ] }
|
||||||
|
{ normal-title-bar $ NSTitledWindowMask }
|
||||||
|
}
|
||||||
|
|
||||||
|
: world>styleMask ( world -- n )
|
||||||
|
window-controls>> window-control>styleMask symbols>flags ;
|
||||||
|
|
||||||
M:: cocoa-ui-backend (open-window) ( world -- )
|
M:: cocoa-ui-backend (open-window) ( world -- )
|
||||||
world [ [ dim>> ] dip <FactorView> ]
|
world [ [ dim>> ] dip <FactorView> ]
|
||||||
with-world-pixel-format :> view
|
with-world-pixel-format :> view
|
||||||
view world world>NSRect <ViewWindow> :> window
|
view world [ world>NSRect ] [ world>styleMask ] bi <ViewWindow> :> window
|
||||||
view -> release
|
view -> release
|
||||||
world view register-window
|
world view register-window
|
||||||
window world window-loc>> auto-position
|
window world window-loc>> auto-position
|
||||||
|
@ -145,7 +158,7 @@ M: cocoa-ui-backend (ungrab-input) ( handle -- )
|
||||||
M: cocoa-ui-backend close-window ( gadget -- )
|
M: cocoa-ui-backend close-window ( gadget -- )
|
||||||
find-world [
|
find-world [
|
||||||
handle>> [
|
handle>> [
|
||||||
window>> f -> performClose:
|
window>> -> close
|
||||||
] when*
|
] when*
|
||||||
] when* ;
|
] when* ;
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ windows.kernel32 windows.gdi32 windows.user32 windows.opengl32
|
||||||
windows.messages windows.types windows.offscreen windows.nt
|
windows.messages windows.types windows.offscreen windows.nt
|
||||||
threads libc combinators fry combinators.short-circuit continuations
|
threads libc combinators fry combinators.short-circuit continuations
|
||||||
command-line shuffle opengl ui.render math.bitwise locals
|
command-line shuffle opengl ui.render math.bitwise locals
|
||||||
accessors math.rectangles math.order calendar ascii
|
accessors math.rectangles math.order calendar ascii sets
|
||||||
io.encodings.utf16n windows.errors literals ui.pixel-formats
|
io.encodings.utf16n windows.errors literals ui.pixel-formats
|
||||||
ui.pixel-formats.private memoize classes struct-arrays ;
|
ui.pixel-formats.private memoize classes struct-arrays ;
|
||||||
IN: ui.backend.windows
|
IN: ui.backend.windows
|
||||||
|
@ -223,8 +223,40 @@ M: pasteboard set-clipboard-contents drop copy ;
|
||||||
|
|
||||||
SYMBOLS: msg-obj class-name-ptr mouse-captured ;
|
SYMBOLS: msg-obj class-name-ptr mouse-captured ;
|
||||||
|
|
||||||
: style ( -- n ) WS_OVERLAPPEDWINDOW ; inline
|
CONSTANT: window-control>style
|
||||||
: ex-style ( -- n ) WS_EX_APPWINDOW WS_EX_WINDOWEDGE bitor ; inline
|
H{
|
||||||
|
{ close-button 0 }
|
||||||
|
{ minimize-button $ WS_MINIMIZEBOX }
|
||||||
|
{ maximize-button $ WS_MAXIMIZEBOX }
|
||||||
|
{ resize-handles $ WS_THICKFRAME }
|
||||||
|
{ small-title-bar $ WS_CAPTION }
|
||||||
|
{ normal-title-bar $ WS_CAPTION }
|
||||||
|
}
|
||||||
|
|
||||||
|
CONSTANT: window-control>ex-style
|
||||||
|
H{
|
||||||
|
{ close-button 0 }
|
||||||
|
{ minimize-button 0 }
|
||||||
|
{ maximize-button 0 }
|
||||||
|
{ resize-handles $ WS_EX_WINDOWEDGE }
|
||||||
|
{ small-title-bar $ WS_EX_TOOLWINDOW }
|
||||||
|
{ normal-title-bar $ WS_EX_APPWINDOW }
|
||||||
|
}
|
||||||
|
|
||||||
|
: needs-sysmenu? ( controls -- ? )
|
||||||
|
{ close-button minimize-button maximize-button } intersects? ;
|
||||||
|
|
||||||
|
: has-titlebar? ( controls -- ? )
|
||||||
|
{ small-title-bar normal-title-bar } intersects? ;
|
||||||
|
|
||||||
|
: world>style ( world -- n )
|
||||||
|
window-controls>>
|
||||||
|
[ window-control>style symbols>flags ]
|
||||||
|
[ needs-sysmenu? [ WS_SYSMENU bitor ] when ]
|
||||||
|
[ has-titlebar? [ WS_POPUP bitor ] unless ] tri ;
|
||||||
|
|
||||||
|
: world>ex-style ( world -- n )
|
||||||
|
window-controls>> window-control>ex-style symbols>flags ;
|
||||||
|
|
||||||
: get-RECT-top-left ( RECT -- x y )
|
: get-RECT-top-left ( RECT -- x y )
|
||||||
[ RECT-left ] keep RECT-top ;
|
[ RECT-left ] keep RECT-top ;
|
||||||
|
@ -242,12 +274,12 @@ SYMBOLS: msg-obj class-name-ptr mouse-captured ;
|
||||||
: handle-wm-size ( hWnd uMsg wParam lParam -- )
|
: handle-wm-size ( hWnd uMsg wParam lParam -- )
|
||||||
2nip
|
2nip
|
||||||
[ lo-word ] keep hi-word 2array
|
[ lo-word ] keep hi-word 2array
|
||||||
dup { 0 0 } = [ 2drop ] [ swap window (>>dim) ] if ;
|
dup { 0 0 } = [ 2drop ] [ swap window [ (>>dim) ] [ drop ] if* ] if ;
|
||||||
|
|
||||||
: handle-wm-move ( hWnd uMsg wParam lParam -- )
|
: handle-wm-move ( hWnd uMsg wParam lParam -- )
|
||||||
2nip
|
2nip
|
||||||
[ lo-word ] keep hi-word 2array
|
[ lo-word ] keep hi-word 2array
|
||||||
swap window (>>window-loc) ;
|
swap window [ (>>window-loc) ] [ drop ] if* ;
|
||||||
|
|
||||||
CONSTANT: wm-keydown-codes
|
CONSTANT: wm-keydown-codes
|
||||||
H{
|
H{
|
||||||
|
@ -571,8 +603,8 @@ M: windows-ui-backend do-events
|
||||||
RegisterClassEx win32-error=0/f
|
RegisterClassEx win32-error=0/f
|
||||||
] [ drop ] if ;
|
] [ drop ] if ;
|
||||||
|
|
||||||
: adjust-RECT ( RECT -- )
|
: adjust-RECT ( RECT style ex-style -- )
|
||||||
style 0 ex-style AdjustWindowRectEx win32-error=0/f ;
|
[ 0 ] dip AdjustWindowRectEx win32-error=0/f ;
|
||||||
|
|
||||||
: make-RECT ( world -- RECT )
|
: make-RECT ( world -- RECT )
|
||||||
[ window-loc>> ] [ dim>> ] bi <RECT> ;
|
[ window-loc>> ] [ dim>> ] bi <RECT> ;
|
||||||
|
@ -584,10 +616,12 @@ M: windows-ui-backend do-events
|
||||||
CW_USEDEFAULT over set-RECT-left
|
CW_USEDEFAULT over set-RECT-left
|
||||||
CW_USEDEFAULT swap set-RECT-top ;
|
CW_USEDEFAULT swap set-RECT-top ;
|
||||||
|
|
||||||
: make-adjusted-RECT ( rect -- RECT )
|
: make-adjusted-RECT ( rect style ex-style -- RECT )
|
||||||
make-RECT
|
[
|
||||||
dup get-RECT-top-left [ zero? ] both? swap
|
make-RECT
|
||||||
dup adjust-RECT
|
dup get-RECT-top-left [ zero? ] both? swap
|
||||||
|
dup
|
||||||
|
] 2dip adjust-RECT
|
||||||
swap [ dup default-position-RECT ] when ;
|
swap [ dup default-position-RECT ] when ;
|
||||||
|
|
||||||
: get-window-class ( -- class-name )
|
: get-window-class ( -- class-name )
|
||||||
|
@ -597,12 +631,12 @@ M: windows-ui-backend do-events
|
||||||
dup
|
dup
|
||||||
] change-global ;
|
] change-global ;
|
||||||
|
|
||||||
: create-window ( rect -- hwnd )
|
:: create-window ( rect style ex-style -- hwnd )
|
||||||
make-adjusted-RECT
|
rect style ex-style make-adjusted-RECT
|
||||||
[ get-window-class f ] dip
|
[ get-window-class f ] dip
|
||||||
[
|
[
|
||||||
[ ex-style ] 2dip
|
[ ex-style ] 2dip
|
||||||
{ WS_CLIPSIBLINGS WS_CLIPCHILDREN style } flags
|
WS_CLIPSIBLINGS WS_CLIPCHILDREN bitor style bitor
|
||||||
] dip get-RECT-dimensions
|
] dip get-RECT-dimensions
|
||||||
f f f GetModuleHandle f CreateWindowEx dup win32-error=0/f ;
|
f f f GetModuleHandle f CreateWindowEx dup win32-error=0/f ;
|
||||||
|
|
||||||
|
@ -636,8 +670,21 @@ M: windows-ui-backend do-events
|
||||||
[ swap [ handle>> hDC>> set-pixel-format ] [ get-rc ] bi ]
|
[ swap [ handle>> hDC>> set-pixel-format ] [ get-rc ] bi ]
|
||||||
with-world-pixel-format ;
|
with-world-pixel-format ;
|
||||||
|
|
||||||
|
: disable-close-button ( hwnd -- )
|
||||||
|
0 GetSystemMenu
|
||||||
|
SC_CLOSE MF_BYCOMMAND MF_GRAYED bitor EnableMenuItem drop ;
|
||||||
|
|
||||||
|
: ?disable-close-button ( world hwnd -- )
|
||||||
|
swap window-controls>> close-button swap member? not
|
||||||
|
[ disable-close-button ] [ drop ] if ;
|
||||||
|
|
||||||
M: windows-ui-backend (open-window) ( world -- )
|
M: windows-ui-backend (open-window) ( world -- )
|
||||||
[ dup create-window [ f f ] dip f f <win> >>handle setup-gl ]
|
[
|
||||||
|
dup
|
||||||
|
[ ] [ world>style ] [ world>ex-style ] tri create-window
|
||||||
|
[ ?disable-close-button ]
|
||||||
|
[ [ f f ] dip f f <win> >>handle setup-gl ] 2bi
|
||||||
|
]
|
||||||
[ dup handle>> hWnd>> register-window ]
|
[ dup handle>> hWnd>> register-window ]
|
||||||
[ handle>> hWnd>> show-window ] tri ;
|
[ handle>> hWnd>> show-window ] tri ;
|
||||||
|
|
||||||
|
@ -743,13 +790,9 @@ M: windows-ui-backend (ungrab-input) ( handle -- )
|
||||||
} cleave ;
|
} cleave ;
|
||||||
|
|
||||||
: exit-fullscreen ( world -- )
|
: exit-fullscreen ( world -- )
|
||||||
handle>> hWnd>>
|
dup handle>> hWnd>>
|
||||||
{
|
{
|
||||||
[
|
[ GWL_STYLE rot world>style SetWindowLong win32-error=0/f ]
|
||||||
GWL_STYLE GetWindowLong
|
|
||||||
fullscreen-flags bitor
|
|
||||||
]
|
|
||||||
[ GWL_STYLE rot SetWindowLong win32-error=0/f ]
|
|
||||||
[
|
[
|
||||||
f
|
f
|
||||||
over hwnd>RECT get-RECT-dimensions
|
over hwnd>RECT get-RECT-dimensions
|
||||||
|
|
|
@ -56,6 +56,7 @@ HELP: world
|
||||||
{ { $snippet "grab-input?" } " - if set to " { $link t } ", the world will hide the mouse cursor and disable normal mouse input while focused. Use " { $link grab-input } " and " { $link ungrab-input } " to change this setting." }
|
{ { $snippet "grab-input?" } " - if set to " { $link t } ", the world will hide the mouse cursor and disable normal mouse input while focused. Use " { $link grab-input } " and " { $link ungrab-input } " to change this setting." }
|
||||||
{ { $snippet "handle" } " - a backend-specific native handle representing the native window containing the world, or " { $link f } " if the world is not grafted." }
|
{ { $snippet "handle" } " - a backend-specific native handle representing the native window containing the world, or " { $link f } " if the world is not grafted." }
|
||||||
{ { $snippet "window-loc" } " - the on-screen location of the native window containing the world. The co-ordinate system here is backend-specific." }
|
{ { $snippet "window-loc" } " - the on-screen location of the native window containing the world. The co-ordinate system here is backend-specific." }
|
||||||
|
{ { $snippet "window-controls" } " - the set of " { $link "ui.gadgets.worlds-window-controls" } " with which the world window was created." }
|
||||||
}
|
}
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
|
@ -113,3 +114,4 @@ $nl
|
||||||
{ $subsection "ui.gadgets.worlds-subclassing" }
|
{ $subsection "ui.gadgets.worlds-subclassing" }
|
||||||
{ $subsection "gl-utilities" }
|
{ $subsection "gl-utilities" }
|
||||||
{ $subsection "text-rendering" } ;
|
{ $subsection "text-rendering" } ;
|
||||||
|
|
||||||
|
|
|
@ -7,16 +7,34 @@ ui.gadgets ui.gestures ui.render ui.backend ui.gadgets.tracks
|
||||||
ui.pixel-formats destructors literals strings ;
|
ui.pixel-formats destructors literals strings ;
|
||||||
IN: ui.gadgets.worlds
|
IN: ui.gadgets.worlds
|
||||||
|
|
||||||
|
SYMBOLS:
|
||||||
|
close-button
|
||||||
|
minimize-button
|
||||||
|
maximize-button
|
||||||
|
resize-handles
|
||||||
|
small-title-bar
|
||||||
|
normal-title-bar ;
|
||||||
|
|
||||||
CONSTANT: default-world-pixel-format-attributes
|
CONSTANT: default-world-pixel-format-attributes
|
||||||
{ windowed double-buffered T{ depth-bits { value 16 } } }
|
{ windowed double-buffered T{ depth-bits { value 16 } } }
|
||||||
|
|
||||||
|
CONSTANT: default-world-window-controls
|
||||||
|
{
|
||||||
|
normal-title-bar
|
||||||
|
close-button
|
||||||
|
minimize-button
|
||||||
|
maximize-button
|
||||||
|
resize-handles
|
||||||
|
}
|
||||||
|
|
||||||
TUPLE: world < track
|
TUPLE: world < track
|
||||||
active? focused? grab-input?
|
active? focused? grab-input?
|
||||||
layers
|
layers
|
||||||
title status status-owner
|
title status status-owner
|
||||||
text-handle handle images
|
text-handle handle images
|
||||||
window-loc
|
window-loc
|
||||||
pixel-format-attributes ;
|
pixel-format-attributes
|
||||||
|
window-controls ;
|
||||||
|
|
||||||
TUPLE: world-attributes
|
TUPLE: world-attributes
|
||||||
{ world-class initial: world }
|
{ world-class initial: world }
|
||||||
|
@ -24,7 +42,8 @@ TUPLE: world-attributes
|
||||||
{ title string initial: "Factor Window" }
|
{ title string initial: "Factor Window" }
|
||||||
status
|
status
|
||||||
gadgets
|
gadgets
|
||||||
{ pixel-format-attributes initial: $ default-world-pixel-format-attributes } ;
|
{ pixel-format-attributes initial: $ default-world-pixel-format-attributes }
|
||||||
|
{ window-controls initial: $ default-world-window-controls } ;
|
||||||
|
|
||||||
: <world-attributes> ( -- world-attributes )
|
: <world-attributes> ( -- world-attributes )
|
||||||
world-attributes new ; inline
|
world-attributes new ; inline
|
||||||
|
@ -86,6 +105,7 @@ M: world request-focus-on ( child gadget -- )
|
||||||
[ title>> >>title ]
|
[ title>> >>title ]
|
||||||
[ status>> >>status ]
|
[ status>> >>status ]
|
||||||
[ pixel-format-attributes>> >>pixel-format-attributes ]
|
[ pixel-format-attributes>> >>pixel-format-attributes ]
|
||||||
|
[ window-controls>> >>window-controls ]
|
||||||
[ grab-input?>> >>grab-input? ]
|
[ grab-input?>> >>grab-input? ]
|
||||||
[ gadgets>> [ 1 track-add ] each ]
|
[ gadgets>> [ 1 track-add ] each ]
|
||||||
} cleave ;
|
} cleave ;
|
||||||
|
|
|
@ -14,6 +14,10 @@ HELP: open-window
|
||||||
{ $values { "gadget" gadget } { "title/attributes" { "a " { $link string } " or a " { $link world-attributes } " tuple" } } }
|
{ $values { "gadget" gadget } { "title/attributes" { "a " { $link string } " or a " { $link world-attributes } " tuple" } } }
|
||||||
{ $description "Opens a native window containing " { $snippet "gadget" } " with the specified attributes. If a string is provided, it is used as the window title; otherwise, the window attributes are specified in a " { $link world-attributes } " tuple." } ;
|
{ $description "Opens a native window containing " { $snippet "gadget" } " with the specified attributes. If a string is provided, it is used as the window title; otherwise, the window attributes are specified in a " { $link world-attributes } " tuple." } ;
|
||||||
|
|
||||||
|
HELP: close-window
|
||||||
|
{ $values { "gadget" gadget } }
|
||||||
|
{ $description "Close the native window containing " { $snippet "gadget" } "." } ;
|
||||||
|
|
||||||
HELP: world-attributes
|
HELP: world-attributes
|
||||||
{ $values { "world-class" class } { "title" string } { "status" gadget } { "gadgets" sequence } { "pixel-format-attributes" sequence } }
|
{ $values { "world-class" class } { "title" string } { "status" gadget } { "gadgets" sequence } { "pixel-format-attributes" sequence } }
|
||||||
{ $class-description "Tuples of this class can be passed to " { $link open-window } " to control attributes of the window opened. The following attributes can be set:" }
|
{ $class-description "Tuples of this class can be passed to " { $link open-window } " to control attributes of the window opened. The following attributes can be set:" }
|
||||||
|
@ -23,6 +27,7 @@ HELP: world-attributes
|
||||||
{ { $snippet "status" } ", if specified, is a gadget that will be used as the window's status bar." }
|
{ { $snippet "status" } ", if specified, is a gadget that will be used as the window's status bar." }
|
||||||
{ { $snippet "gadgets" } " is a sequence of gadgets that will be placed inside the window." }
|
{ { $snippet "gadgets" } " is a sequence of gadgets that will be placed inside the window." }
|
||||||
{ { $snippet "pixel-format-attributes" } " is a sequence of " { $link "ui.pixel-formats-attributes" } " that the window will request for its OpenGL pixel format." }
|
{ { $snippet "pixel-format-attributes" } " is a sequence of " { $link "ui.pixel-formats-attributes" } " that the window will request for its OpenGL pixel format." }
|
||||||
|
{ { $snippet "window-controls" } " is a sequence of " { $link "ui.gadgets.worlds-window-controls" } " that will be placed in the window." }
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
HELP: set-fullscreen
|
HELP: set-fullscreen
|
||||||
|
@ -262,3 +267,31 @@ ARTICLE: "ui" "UI framework"
|
||||||
{ $subsection "ui-backend" } ;
|
{ $subsection "ui-backend" } ;
|
||||||
|
|
||||||
ABOUT: "ui"
|
ABOUT: "ui"
|
||||||
|
|
||||||
|
HELP: close-button
|
||||||
|
{ $description "Asks for a close button to be available for a window. Without a close button, a window cannot be closed by the user and must be closed by the program using " { $link close-window } "." } ;
|
||||||
|
|
||||||
|
HELP: minimize-button
|
||||||
|
{ $description "Asks for a minimize button to be available for a window." } ;
|
||||||
|
|
||||||
|
HELP: maximize-button
|
||||||
|
{ $description "Asks for a maximize button to be available for a window." } ;
|
||||||
|
|
||||||
|
HELP: resize-handles
|
||||||
|
{ $description "Asks for resize controls to be available for a window. Without resize controls, the window size will not be changeable by the user." } ;
|
||||||
|
|
||||||
|
HELP: small-title-bar
|
||||||
|
{ $description "Asks for a window to have a small title bar. Without a title bar, the " { $link close-button } ", " { $link minimize-button } ", and " { $link maximize-button } " controls will not be available. A small title bar may have other side effects in the window system, such as causing the window to not show up in the system task switcher and to float over other Factor windows." } ;
|
||||||
|
|
||||||
|
HELP: normal-title-bar
|
||||||
|
{ $description "Asks for a window to have a title bar. Without a title bar, the " { $link close-button } ", " { $link minimize-button } ", and " { $link maximize-button } " controls will not be available." } ;
|
||||||
|
|
||||||
|
ARTICLE: "ui.gadgets.worlds-window-controls" "Window controls"
|
||||||
|
"The following window controls can be placed in a " { $link world } " window:"
|
||||||
|
{ $subsection close-button }
|
||||||
|
{ $subsection minimize-button }
|
||||||
|
{ $subsection maximize-button }
|
||||||
|
{ $subsection resize-handles }
|
||||||
|
{ $subsection small-title-bar }
|
||||||
|
{ $subsection normal-title-bar }
|
||||||
|
"Provide a sequence of these values in the " { $snippet "window-controls" } " slot of the " { $link world-attributes } " tuple you pass to " { $link open-window } "." ;
|
||||||
|
|
|
@ -582,6 +582,28 @@ CONSTANT: SWP_NOREPOSITION SWP_NOOWNERZORDER
|
||||||
CONSTANT: SWP_DEFERERASE 8192
|
CONSTANT: SWP_DEFERERASE 8192
|
||||||
CONSTANT: SWP_ASYNCWINDOWPOS 16384
|
CONSTANT: SWP_ASYNCWINDOWPOS 16384
|
||||||
|
|
||||||
|
CONSTANT: MF_ENABLED HEX: 0000
|
||||||
|
CONSTANT: MF_GRAYED HEX: 0001
|
||||||
|
CONSTANT: MF_DISABLED HEX: 0002
|
||||||
|
CONSTANT: MF_STRING HEX: 0000
|
||||||
|
CONSTANT: MF_BITMAP HEX: 0004
|
||||||
|
CONSTANT: MF_UNCHECKED HEX: 0000
|
||||||
|
CONSTANT: MF_CHECKED HEX: 0008
|
||||||
|
CONSTANT: MF_POPUP HEX: 0010
|
||||||
|
CONSTANT: MF_MENUBARBREAK HEX: 0020
|
||||||
|
CONSTANT: MF_MENUBREAK HEX: 0040
|
||||||
|
CONSTANT: MF_UNHILITE HEX: 0000
|
||||||
|
CONSTANT: MF_HILITE HEX: 0080
|
||||||
|
CONSTANT: MF_OWNERDRAW HEX: 0100
|
||||||
|
CONSTANT: MF_USECHECKBITMAPS HEX: 0200
|
||||||
|
CONSTANT: MF_BYCOMMAND HEX: 0000
|
||||||
|
CONSTANT: MF_BYPOSITION HEX: 0400
|
||||||
|
CONSTANT: MF_SEPARATOR HEX: 0800
|
||||||
|
CONSTANT: MF_DEFAULT HEX: 1000
|
||||||
|
CONSTANT: MF_SYSMENU HEX: 2000
|
||||||
|
CONSTANT: MF_HELP HEX: 4000
|
||||||
|
CONSTANT: MF_RIGHTJUSTIFY HEX: 4000
|
||||||
|
CONSTANT: MF_MOUSESELECT HEX: 8000
|
||||||
|
|
||||||
LIBRARY: user32
|
LIBRARY: user32
|
||||||
|
|
||||||
|
@ -807,7 +829,7 @@ FUNCTION: BOOL DrawIcon ( HDC hDC, int X, int Y, HICON hIcon ) ;
|
||||||
! FUNCTION: DrawTextW
|
! FUNCTION: DrawTextW
|
||||||
! FUNCTION: EditWndProc
|
! FUNCTION: EditWndProc
|
||||||
FUNCTION: BOOL EmptyClipboard ( ) ;
|
FUNCTION: BOOL EmptyClipboard ( ) ;
|
||||||
! FUNCTION: EnableMenuItem
|
FUNCTION: BOOL EnableMenuItem ( HMENU hMenu, UINT uIDEnableItem, UINT uEnable ) ;
|
||||||
! FUNCTION: EnableScrollBar
|
! FUNCTION: EnableScrollBar
|
||||||
! FUNCTION: EnableWindow
|
! FUNCTION: EnableWindow
|
||||||
! FUNCTION: EndDeferWindowPos
|
! FUNCTION: EndDeferWindowPos
|
||||||
|
@ -975,7 +997,7 @@ FUNCTION: int GetPriorityClipboardFormat ( UINT* paFormatPriorityList, int cForm
|
||||||
! FUNCTION: GetSubMenu
|
! FUNCTION: GetSubMenu
|
||||||
! FUNCTION: GetSysColor
|
! FUNCTION: GetSysColor
|
||||||
FUNCTION: HBRUSH GetSysColorBrush ( int nIndex ) ;
|
FUNCTION: HBRUSH GetSysColorBrush ( int nIndex ) ;
|
||||||
! FUNCTION: GetSystemMenu
|
FUNCTION: HMENU GetSystemMenu ( HWND hWnd, BOOL bRevert ) ;
|
||||||
! FUNCTION: GetSystemMetrics
|
! FUNCTION: GetSystemMetrics
|
||||||
! FUNCTION: GetTabbedTextExtentA
|
! FUNCTION: GetTabbedTextExtentA
|
||||||
! FUNCTION: GetTabbedTextExtentW
|
! FUNCTION: GetTabbedTextExtentW
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
USING: kernel help.markup help.syntax sequences quotations assocs ;
|
USING: assocs hashtables help.markup help.syntax kernel
|
||||||
|
quotations sequences ;
|
||||||
IN: sets
|
IN: sets
|
||||||
|
|
||||||
ARTICLE: "sets" "Set-theoretic operations on sequences"
|
ARTICLE: "sets" "Set-theoretic operations on sequences"
|
||||||
|
@ -19,6 +20,13 @@ $nl
|
||||||
{ $subsection set= }
|
{ $subsection set= }
|
||||||
"A word used to implement the above:"
|
"A word used to implement the above:"
|
||||||
{ $subsection unique }
|
{ $subsection unique }
|
||||||
|
"Counting elements in a sequence:"
|
||||||
|
{ $subsection histogram }
|
||||||
|
{ $subsection histogram* }
|
||||||
|
"Combinators for implementing histogram:"
|
||||||
|
{ $subsection sequence>assoc }
|
||||||
|
{ $subsection sequence>assoc* }
|
||||||
|
{ $subsection sequence>hashtable }
|
||||||
"Adding elements to sets:"
|
"Adding elements to sets:"
|
||||||
{ $subsection adjoin }
|
{ $subsection adjoin }
|
||||||
{ $subsection conjoin }
|
{ $subsection conjoin }
|
||||||
|
@ -125,3 +133,73 @@ HELP: gather
|
||||||
{ "seq" sequence } { "quot" quotation }
|
{ "seq" sequence } { "quot" quotation }
|
||||||
{ "newseq" sequence } }
|
{ "newseq" sequence } }
|
||||||
{ $description "Maps a quotation onto a sequence, concatenates the results of the mapping, and removes duplicates." } ;
|
{ $description "Maps a quotation onto a sequence, concatenates the results of the mapping, and removes duplicates." } ;
|
||||||
|
|
||||||
|
HELP: histogram
|
||||||
|
{ $values
|
||||||
|
{ "seq" sequence }
|
||||||
|
{ "hashtable" hashtable }
|
||||||
|
}
|
||||||
|
{ $examples
|
||||||
|
{ $example "! Count the number of times an element appears in a sequence."
|
||||||
|
"USING: prettyprint sets ;"
|
||||||
|
"\"aaabc\" histogram ."
|
||||||
|
"H{ { 97 3 } { 98 1 } { 99 1 } }"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
{ $description "Returns a hashtable where the keys are the elements of the sequence and the values are the number of times they appeared in that sequence." } ;
|
||||||
|
|
||||||
|
HELP: histogram*
|
||||||
|
{ $values
|
||||||
|
{ "hashtable" hashtable } { "seq" sequence }
|
||||||
|
{ "hashtable" hashtable }
|
||||||
|
}
|
||||||
|
{ $examples
|
||||||
|
{ $example "! Count the number of times the elements of two sequences appear."
|
||||||
|
"USING: prettyprint sets ;"
|
||||||
|
"\"aaabc\" histogram \"aaaaaabc\" histogram* ."
|
||||||
|
"H{ { 97 9 } { 98 2 } { 99 2 } }"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
{ $description "Takes an existing hashtable and uses " { $link histogram } " to continue counting the number of occurences of each element." } ;
|
||||||
|
|
||||||
|
HELP: sequence>assoc
|
||||||
|
{ $values
|
||||||
|
{ "seq" sequence } { "quot" quotation } { "exemplar" "an exemplar assoc" }
|
||||||
|
{ "assoc" assoc }
|
||||||
|
}
|
||||||
|
{ $examples
|
||||||
|
{ $example "! Iterate over a sequence and increment the count at each element"
|
||||||
|
"USING: assocs prettyprint sets ;"
|
||||||
|
"\"aaabc\" [ inc-at ] H{ } sequence>assoc ."
|
||||||
|
"H{ { 97 3 } { 98 1 } { 99 1 } }"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
{ $description "Iterates over a sequence, allowing elements of the sequence to be added to a newly created " { $snippet "assoc" } " according to the passed quotation." } ;
|
||||||
|
|
||||||
|
HELP: sequence>assoc*
|
||||||
|
{ $values
|
||||||
|
{ "assoc" assoc } { "seq" sequence } { "quot" quotation }
|
||||||
|
{ "assoc" assoc }
|
||||||
|
}
|
||||||
|
{ $examples
|
||||||
|
{ $example "! Iterate over a sequence and add the counts to an existing assoc"
|
||||||
|
"USING: assocs prettyprint sets kernel ;"
|
||||||
|
"H{ { 97 2 } { 98 1 } } clone \"aaabc\" [ inc-at ] sequence>assoc* ."
|
||||||
|
"H{ { 97 5 } { 98 2 } { 99 1 } }"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
{ $description "Iterates over a sequence, allowing elements of the sequence to be added to an existing " { $snippet "assoc" } " according to the passed quotation." } ;
|
||||||
|
|
||||||
|
HELP: sequence>hashtable
|
||||||
|
{ $values
|
||||||
|
{ "seq" sequence } { "quot" quotation }
|
||||||
|
{ "hashtable" hashtable }
|
||||||
|
}
|
||||||
|
{ $examples
|
||||||
|
{ $example "! Count the number of times an element occurs in a sequence"
|
||||||
|
"USING: assocs prettyprint sets ;"
|
||||||
|
"\"aaabc\" [ inc-at ] sequence>hashtable ."
|
||||||
|
"H{ { 97 3 } { 98 1 } { 99 1 } }"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
{ $description "Iterates over a sequence, allowing elements of the sequence to be added to a hashtable according to the passed quotation." } ;
|
||||||
|
|
|
@ -29,3 +29,13 @@ IN: sets.tests
|
||||||
[ f ] [ { } { 1 } intersects? ] unit-test
|
[ f ] [ { } { 1 } intersects? ] unit-test
|
||||||
|
|
||||||
[ f ] [ { 1 } { } intersects? ] unit-test
|
[ f ] [ { 1 } { } intersects? ] unit-test
|
||||||
|
|
||||||
|
[
|
||||||
|
H{
|
||||||
|
{ 97 2 }
|
||||||
|
{ 98 2 }
|
||||||
|
{ 99 2 }
|
||||||
|
}
|
||||||
|
] [
|
||||||
|
"aabbcc" histogram
|
||||||
|
] unit-test
|
||||||
|
|
|
@ -54,3 +54,25 @@ PRIVATE>
|
||||||
|
|
||||||
: set= ( seq1 seq2 -- ? )
|
: set= ( seq1 seq2 -- ? )
|
||||||
[ unique ] bi@ = ;
|
[ unique ] bi@ = ;
|
||||||
|
|
||||||
|
<PRIVATE
|
||||||
|
|
||||||
|
: (sequence>assoc) ( seq quot assoc -- assoc )
|
||||||
|
[ swap curry each ] keep ; inline
|
||||||
|
|
||||||
|
PRIVATE>
|
||||||
|
|
||||||
|
: sequence>assoc* ( assoc seq quot: ( obj assoc -- ) -- assoc )
|
||||||
|
rot (sequence>assoc) ; inline
|
||||||
|
|
||||||
|
: sequence>assoc ( seq quot: ( obj assoc -- ) exemplar -- assoc )
|
||||||
|
clone (sequence>assoc) ; inline
|
||||||
|
|
||||||
|
: sequence>hashtable ( seq quot: ( obj hashtable -- ) -- hashtable )
|
||||||
|
H{ } sequence>assoc ; inline
|
||||||
|
|
||||||
|
: histogram* ( hashtable seq -- hashtable )
|
||||||
|
[ inc-at ] sequence>assoc* ;
|
||||||
|
|
||||||
|
: histogram ( seq -- hashtable )
|
||||||
|
[ inc-at ] sequence>hashtable ;
|
||||||
|
|
|
@ -25,7 +25,7 @@ IN: half-floats.tests
|
||||||
[ -1.5 ] [ HEX: be00 bits>half ] unit-test
|
[ -1.5 ] [ HEX: be00 bits>half ] unit-test
|
||||||
[ 1/0. ] [ HEX: 7c00 bits>half ] unit-test
|
[ 1/0. ] [ HEX: 7c00 bits>half ] unit-test
|
||||||
[ -1/0. ] [ HEX: fc00 bits>half ] unit-test
|
[ -1/0. ] [ HEX: fc00 bits>half ] unit-test
|
||||||
[ t ] [ HEX: 7e00 bits>half fp-nan? ] unit-test
|
[ t ] [ HEX: 7e00 bits>half fp-nan? ] unit-test
|
||||||
|
|
||||||
C-STRUCT: halves
|
C-STRUCT: halves
|
||||||
{ "half" "tom" }
|
{ "half" "tom" }
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Joe Groff
|
|
@ -0,0 +1 @@
|
||||||
|
Open windows with different control sets
|
|
@ -0,0 +1,43 @@
|
||||||
|
! (c)2009 Joe Groff bsd license
|
||||||
|
USING: accessors assocs kernel locals sequences ui
|
||||||
|
ui.gadgets ui.gadgets.worlds ;
|
||||||
|
IN: window-controls-demo
|
||||||
|
|
||||||
|
CONSTANT: window-control-sets-to-test
|
||||||
|
H{
|
||||||
|
{ "No controls" { } }
|
||||||
|
{ "Normal title bar" { normal-title-bar } }
|
||||||
|
{ "Small title bar" { small-title-bar close-button } }
|
||||||
|
{ "Close button" { normal-title-bar close-button } }
|
||||||
|
{ "Close and minimize buttons" { normal-title-bar close-button minimize-button } }
|
||||||
|
{ "Minimize button" { normal-title-bar minimize-button } }
|
||||||
|
{ "Close, minimize, and maximize buttons" { normal-title-bar close-button minimize-button maximize-button } }
|
||||||
|
{ "Resizable" { normal-title-bar close-button minimize-button maximize-button resize-handles } }
|
||||||
|
}
|
||||||
|
|
||||||
|
TUPLE: window-controls-demo-world < world
|
||||||
|
windows ;
|
||||||
|
|
||||||
|
M: window-controls-demo-world end-world
|
||||||
|
windows>> [ close-window ] each ;
|
||||||
|
|
||||||
|
M: window-controls-demo-world pref-dim*
|
||||||
|
drop { 400 400 } ;
|
||||||
|
|
||||||
|
: attributes-template ( -- x )
|
||||||
|
T{ world-attributes
|
||||||
|
{ world-class window-controls-demo-world }
|
||||||
|
} clone ;
|
||||||
|
|
||||||
|
: window-controls-demo ( -- )
|
||||||
|
attributes-template V{ } clone window-control-sets-to-test
|
||||||
|
[| title attributes windows controls |
|
||||||
|
f attributes
|
||||||
|
title >>title
|
||||||
|
controls >>window-controls
|
||||||
|
open-window*
|
||||||
|
windows >>windows
|
||||||
|
windows push
|
||||||
|
] with with assoc-each ;
|
||||||
|
|
||||||
|
MAIN: window-controls-demo
|
Loading…
Reference in New Issue