Code cleanup: refactoring usages of rot and -rot to use newer idioms instead

db4
Slava Pestov 2008-11-30 17:47:29 -06:00
parent 9bba10c970
commit 3e25d14e54
27 changed files with 189 additions and 170 deletions

View File

@ -0,0 +1,19 @@
! Copyright (C) 2008 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: alien alien.c-types arrays assocs effects grouping kernel
parser sequences splitting words fry locals ;
IN: alien.parser
: parse-arglist ( parameters return -- types effect )
[ 2 group unzip [ "," ?tail drop ] map ]
[ [ { } ] [ 1array ] if-void ]
bi* <effect> ;
: function-quot ( return library function types -- quot )
'[ _ _ _ _ alien-invoke ] ;
:: define-function ( return library function parameters -- )
function create-in dup reset-generic
return library function
parameters return parse-arglist [ function-quot ] dip
define-declared ;

View File

@ -52,25 +52,21 @@ PREDICATE: slot-writer < word "writing" word-prop >boolean ;
[ (>>offset) ] [ type>> heap-size + ] 2bi [ (>>offset) ] [ type>> heap-size + ] 2bi
] reduce ; ] reduce ;
: define-struct-slot-word ( spec word quot -- ) : define-struct-slot-word ( word quot spec -- )
rot offset>> prefix define-inline ; offset>> prefix define-inline ;
: define-getter ( type spec -- ) : define-getter ( type spec -- )
[ set-reader-props ] keep [ set-reader-props ] keep
[ ]
[ reader>> ] [ reader>> ]
[ [
type>> type>>
[ c-getter ] [ c-type-boxer-quot ] bi append [ c-getter ] [ c-type-boxer-quot ] bi append
] tri ]
define-struct-slot-word ; [ ] tri define-struct-slot-word ;
: define-setter ( type spec -- ) : define-setter ( type spec -- )
[ set-writer-props ] keep [ set-writer-props ] keep
[ ] [ writer>> ] [ type>> c-setter ] [ ] tri define-struct-slot-word ;
[ writer>> ]
[ type>> c-setter ] tri
define-struct-slot-word ;
: define-field ( type spec -- ) : define-field ( type spec -- )
[ define-getter ] [ define-setter ] 2bi ; [ define-getter ] [ define-setter ] 2bi ;

View File

@ -1,6 +1,6 @@
IN: alien.syntax IN: alien.syntax
USING: alien alien.c-types alien.structs alien.syntax.private USING: alien alien.c-types alien.parser alien.structs
help.markup help.syntax ; alien.syntax.private help.markup help.syntax ;
HELP: DLL" HELP: DLL"
{ $syntax "DLL\" path\"" } { $syntax "DLL\" path\"" }
@ -54,12 +54,6 @@ HELP: TYPEDEF:
{ $description "Aliases the C type " { $snippet "old" } " under the name " { $snippet "new" } " if ." } { $description "Aliases the C type " { $snippet "old" } " under the name " { $snippet "new" } " if ." }
{ $notes "This word differs from " { $link typedef } " in that it runs at parse time, to ensure correct ordering of operations when loading source files. Words defined in source files are compiled before top-level forms are run, so if a source file defines C binding words and uses " { $link typedef } ", the type alias won't be available at compile time." } ; { $notes "This word differs from " { $link typedef } " in that it runs at parse time, to ensure correct ordering of operations when loading source files. Words defined in source files are compiled before top-level forms are run, so if a source file defines C binding words and uses " { $link typedef } ", the type alias won't be available at compile time." } ;
HELP: TYPEDEF-IF:
{ $syntax "TYPEDEF-IF: word old new" }
{ $values { "word" "a word with stack effect " { $snippet "( -- ? )" } } { "old" "a C type" } { "new" "a C type" } }
{ $description "Aliases the C type " { $snippet "old" } " under the name " { $snippet "new" } " if " { $snippet "word" } " evaluates to a true value." }
{ $notes "This word differs from " { $link typedef } " in that it runs at parse time, to ensure correct ordering of operations when loading source files. Words defined in source files are compiled before top-level forms are run, so if a source file defines C binding words and uses " { $link typedef } ", the type alias won't be available at compile time." } ;
HELP: C-STRUCT: HELP: C-STRUCT:
{ $syntax "C-STRUCT: name pairs... ;" } { $syntax "C-STRUCT: name pairs... ;" }
{ $values { "name" "a new C type name" } { "pairs" "C type / field name string pairs" } } { $values { "name" "a new C type name" } { "pairs" "C type / field name string pairs" } }
@ -88,7 +82,7 @@ HELP: typedef
{ $description "Alises the C type " { $snippet "old" } " under the name " { $snippet "new" } "." } { $description "Alises the C type " { $snippet "old" } " under the name " { $snippet "new" } "." }
{ $notes "Using this word in the same source file which defines C bindings can cause problems, because words are compiled before top-level forms are run. Use the " { $link POSTPONE: TYPEDEF: } " word instead." } ; { $notes "Using this word in the same source file which defines C bindings can cause problems, because words are compiled before top-level forms are run. Use the " { $link POSTPONE: TYPEDEF: } " word instead." } ;
{ POSTPONE: TYPEDEF-IF: POSTPONE: TYPEDEF: typedef } related-words { POSTPONE: TYPEDEF: typedef } related-words
HELP: c-struct? HELP: c-struct?
{ $values { "type" "a string" } { "?" "a boolean" } } { $values { "type" "a string" } { "?" "a boolean" } }

View File

@ -4,26 +4,9 @@ USING: accessors arrays alien alien.c-types alien.structs
alien.arrays alien.strings kernel math namespaces parser alien.arrays alien.strings kernel math namespaces parser
sequences words quotations math.parser splitting grouping sequences words quotations math.parser splitting grouping
effects prettyprint prettyprint.sections prettyprint.backend effects prettyprint prettyprint.sections prettyprint.backend
assocs combinators lexer strings.parser ; assocs combinators lexer strings.parser alien.parser ;
IN: alien.syntax IN: alien.syntax
<PRIVATE
: parse-arglist ( return seq -- types effect )
2 group dup keys swap values [ "," ?tail drop ] map
rot dup "void" = [ drop { } ] [ 1array ] if <effect> ;
: function-quot ( type lib func types -- quot )
[ alien-invoke ] 2curry 2curry ;
: define-function ( return library function parameters -- )
[ pick ] dip parse-arglist
pick create-in dup reset-generic
[ function-quot ] 2dip
-rot define-declared ;
PRIVATE>
: DLL" lexer get skip-blank parse-string dlopen parsed ; parsing : DLL" lexer get skip-blank parse-string dlopen parsed ; parsing
: ALIEN: scan string>number <alien> parsed ; parsing : ALIEN: scan string>number <alien> parsed ; parsing
@ -40,9 +23,6 @@ PRIVATE>
: TYPEDEF: : TYPEDEF:
scan scan typedef ; parsing scan scan typedef ; parsing
: TYPEDEF-IF:
scan-word execute scan scan rot [ typedef ] [ 2drop ] if ; parsing
: C-STRUCT: : C-STRUCT:
scan in get scan in get
parse-definition parse-definition

View File

@ -300,7 +300,7 @@ PREDICATE: callable < word register? not ;
GENERIC: MOV ( dst src -- ) GENERIC: MOV ( dst src -- )
M: immediate MOV swap (MOV-I) ; M: immediate MOV swap (MOV-I) ;
M: callable MOV 0 rot (MOV-I) rc-absolute-cell rel-word ; M: callable MOV [ 0 ] 2dip (MOV-I) rc-absolute-cell rel-word ;
M: operand MOV HEX: 88 2-operand ; M: operand MOV HEX: 88 2-operand ;
: LEA ( dst src -- ) swap HEX: 8d 2-operand ; : LEA ( dst src -- ) swap HEX: 8d 2-operand ;

View File

@ -93,11 +93,11 @@ M: dlist peek-front ( dlist -- obj )
M: dlist pop-front* ( dlist -- ) M: dlist pop-front* ( dlist -- )
[ [
dup front>> [ empty-dlist ] unless* [
dup next>> [ empty-dlist ] unless*
f rot (>>next) [ f ] change-next drop
f over set-prev-when f over set-prev-when
swap (>>front) ] change-front drop
] keep ] keep
normalize-back ; normalize-back ;
@ -106,11 +106,11 @@ M: dlist peek-back ( dlist -- obj )
M: dlist pop-back* ( dlist -- ) M: dlist pop-back* ( dlist -- )
[ [
dup back>> [ empty-dlist ] unless* [
dup prev>> [ empty-dlist ] unless*
f rot (>>prev) [ f ] change-prev drop
f over set-next-when f over set-next-when
swap (>>back) ] change-back drop
] keep ] keep
normalize-front ; normalize-front ;

View File

@ -1,6 +1,6 @@
USING: alien alien.syntax alien.syntax.private combinators USING: alien alien.syntax alien.parser combinators
kernel parser sequences system words namespaces hashtables init kernel parser sequences system words namespaces hashtables init
math arrays assocs continuations lexer ; math arrays assocs continuations lexer fry locals ;
IN: opengl.gl.extensions IN: opengl.gl.extensions
ERROR: unknown-gl-platform ; ERROR: unknown-gl-platform ;
@ -30,20 +30,22 @@ reset-gl-function-number-counter
: gl-function-pointer ( names n -- funptr ) : gl-function-pointer ( names n -- funptr )
gl-function-context 2array dup +gl-function-pointers+ get-global at gl-function-context 2array dup +gl-function-pointers+ get-global at
[ 2nip ] [ [ 2nip ] [
>r [ gl-function-address ] map [ ] find nip [
dup [ "OpenGL function not available" throw ] unless [ gl-function-address ] map [ ] find nip
dup r> dup [ "OpenGL function not available" throw ] unless
dup
] dip
+gl-function-pointers+ get-global set-at +gl-function-pointers+ get-global set-at
] if* ; ] if* ;
: indirect-quot ( function-ptr-quot return types abi -- quot ) : indirect-quot ( function-ptr-quot return types abi -- quot )
[ alien-indirect ] 3curry compose ; '[ @ _ _ _ alien-indirect ] ;
: define-indirect ( abi return function-ptr-quot function-name parameters -- ) :: define-indirect ( abi return function-ptr-quot function-name parameters -- )
[ pick ] dip parse-arglist function-name create-in dup reset-generic
rot create-in function-ptr-quot return
[ swapd roll indirect-quot ] 2dip parameters return parse-arglist [ abi indirect-quot ] dip
-rot define-declared ; define-declared ;
: GL-FUNCTION: : GL-FUNCTION:
gl-function-calling-convention gl-function-calling-convention

View File

@ -33,16 +33,13 @@ M: pasteboard set-clipboard-contents
<clipboard> selection set-global ; <clipboard> selection set-global ;
: world>NSRect ( world -- NSRect ) : world>NSRect ( world -- NSRect )
dup window-loc>> first2 rot rect-dim first2 <NSRect> ; [ window-loc>> ] [ dim>> ] bi [ first2 ] bi@ <NSRect> ;
: gadget-window ( world -- ) : gadget-window ( world -- )
[ dup <FactorView>
dup <FactorView> 2dup swap world>NSRect <ViewWindow>
dup rot world>NSRect <ViewWindow> [ [ -> release ] [ install-window-delegate ] bi* ] [ <handle> ] 2bi
dup install-window-delegate >>handle drop ;
over -> release
<handle>
] keep (>>handle) ;
M: cocoa-ui-backend set-title ( string world -- ) M: cocoa-ui-backend set-title ( string world -- )
handle>> window>> swap <NSString> -> setTitle: ; handle>> window>> swap <NSString> -> setTitle: ;

View File

@ -0,0 +1,15 @@
IN: ui.cocoa.views.tests
USING: ui.cocoa.views tools.test kernel math.geometry.rect
namespaces ;
[ t ] [
T{ rect
{ loc { 0 0 } }
{ dim { 1000 1000 } }
} "world" set
T{ rect
{ loc { 1.5 2.25 } }
{ dim { 13.0 14.0 } }
} dup "world" get rect>NSRect "world" get NSRect>rect =
] unit-test

View File

@ -77,18 +77,22 @@ IN: ui.cocoa.views
dup event-modifiers swap button ; dup event-modifiers swap button ;
: send-button-down$ ( view event -- ) : send-button-down$ ( view event -- )
[ mouse-event>gesture <button-down> ] [ nip mouse-event>gesture <button-down> ]
[ mouse-location rot window send-button-down ] 2bi ; [ mouse-location ]
[ drop window ]
2tri send-button-down ;
: send-button-up$ ( view event -- ) : send-button-up$ ( view event -- )
[ mouse-event>gesture <button-up> ] 2keep [ nip mouse-event>gesture <button-up> ]
mouse-location rot window send-button-up ; [ mouse-location ]
[ drop window ]
2tri send-button-up ;
: send-wheel$ ( view event -- ) : send-wheel$ ( view event -- )
[ [ nip [ -> deltaX ] [ -> deltaY ] bi [ sgn neg ] bi@ 2array ]
dup -> deltaX sgn neg over -> deltaY sgn neg 2array -rot [ mouse-location ]
mouse-location [ drop window ]
] [ drop window ] 2bi send-wheel ; 2tri send-wheel ;
: send-action$ ( view event gesture -- junk ) : send-action$ ( view event gesture -- junk )
[ drop window ] dip send-action f ; [ drop window ] dip send-action f ;
@ -103,21 +107,18 @@ IN: ui.cocoa.views
[ CF>string NSStringPboardType = ] [ t ] if* ; [ CF>string NSStringPboardType = ] [ t ] if* ;
: valid-service? ( gadget send-type return-type -- ? ) : valid-service? ( gadget send-type return-type -- ? )
over string-or-nil? over string-or-nil? and [ over string-or-nil? over string-or-nil? and
drop [ gadget-selection? ] [ drop t ] if [ drop [ gadget-selection? ] [ drop t ] if ] [ 3drop f ] if ;
] [
3drop f
] if ;
: NSRect>rect ( NSRect world -- rect ) : NSRect>rect ( NSRect world -- rect )
[ dup NSRect-x over NSRect-y ] dip [ [ [ NSRect-x ] [ NSRect-y ] bi ] [ dim>> second ] bi* swap - 2array ]
rect-dim second swap - 2array [ drop [ NSRect-w ] [ NSRect-h ] bi 2array ]
over NSRect-w rot NSRect-h 2array 2bi <rect> ;
<rect> ;
: rect>NSRect ( rect world -- NSRect ) : rect>NSRect ( rect world -- NSRect )
over rect-loc first2 rot rect-dim second swap - [ [ rect-loc first2 ] [ dim>> second ] bi* swap - ]
rot rect-dim first2 <NSRect> ; [ drop rect-dim first2 ]
2bi <NSRect> ;
CLASS: { CLASS: {
{ +superclass+ "NSOpenGLView" } { +superclass+ "NSOpenGLView" }
@ -342,7 +343,7 @@ CLASS: {
{ "initWithFrame:pixelFormat:" "id" { "id" "SEL" "NSRect" "id" } { "initWithFrame:pixelFormat:" "id" { "id" "SEL" "NSRect" "id" }
[ [
rot drop [ drop ] 2dip
SUPER-> initWithFrame:pixelFormat: SUPER-> initWithFrame:pixelFormat:
dup dup add-resize-observer dup dup add-resize-observer
] ]
@ -351,9 +352,10 @@ CLASS: {
{ "dealloc" "void" { "id" "SEL" } { "dealloc" "void" { "id" "SEL" }
[ [
drop drop
dup unregister-window [ unregister-window ]
dup remove-observer [ remove-observer ]
SUPER-> dealloc [ SUPER-> dealloc ]
tri
] ]
} ; } ;

View File

@ -97,14 +97,15 @@ SYMBOL: dpi
dup handle>> init-descent dup handle>> init-descent
dup [ ascent>> ] [ descent>> ] bi - ft-ceil >>height ; inline dup [ ascent>> ] [ descent>> ] bi - ft-ceil >>height ; inline
: set-char-size ( handle size -- ) : set-char-size ( open-font size -- open-font )
0 swap 6 shift dpi get-global dup FT_Set_Char_Size freetype-error ; [ dup handle>> 0 ] dip
6 shift dpi get-global dup FT_Set_Char_Size freetype-error ;
: <font> ( handle -- font ) : <font> ( font -- open-font )
font new font new
H{ } clone >>widths H{ } clone >>widths
over first2 open-face >>handle over first2 open-face >>handle
dup handle>> rot third set-char-size swap third set-char-size
init-font ; init-font ;
M: freetype-renderer open-font ( font -- open-font ) M: freetype-renderer open-font ( font -- open-font )
@ -120,7 +121,7 @@ M: freetype-renderer open-font ( font -- open-font )
] cache nip ; ] cache nip ;
M: freetype-renderer string-width ( open-font string -- w ) M: freetype-renderer string-width ( open-font string -- w )
0 -rot [ char-width + ] with each ; [ 0 ] 2dip [ char-width + ] with each ;
M: freetype-renderer string-height ( open-font string -- h ) M: freetype-renderer string-height ( open-font string -- h )
drop height>> ; drop height>> ;
@ -165,8 +166,9 @@ M: freetype-renderer string-height ( open-font string -- h )
] with-malloc ; ] with-malloc ;
: glyph-texture-loc ( glyph font -- loc ) : glyph-texture-loc ( glyph font -- loc )
over glyph-hori-bearing-x ft-floor -rot [ drop glyph-hori-bearing-x ft-floor ]
ascent>> swap glyph-hori-bearing-y - ft-floor 2array ; [ ascent>> swap glyph-hori-bearing-y - ft-floor ]
2bi 2array ;
: glyph-texture-size ( glyph -- dim ) : glyph-texture-size ( glyph -- dim )
[ glyph-bitmap-width next-power-of-2 ] [ glyph-bitmap-width next-power-of-2 ]

View File

@ -138,11 +138,8 @@ M: editor ungraft*
f >>focused? f >>focused?
relayout-1 ; relayout-1 ;
: (offset>x) ( font col# str -- x )
swap head-slice string-width ;
: offset>x ( col# line# editor -- x ) : offset>x ( col# line# editor -- x )
[ editor-line ] keep editor-font* -rot (offset>x) ; [ editor-line ] keep editor-font* spin head-slice string-width ;
: loc>x ( loc editor -- x ) [ first2 swap ] dip offset>x ; : loc>x ( loc editor -- x ) [ first2 swap ] dip offset>x ;

View File

@ -152,13 +152,6 @@ M: mock-gadget ungraft*
{ { f f } { f t } { t f } { t t } } [ notify-combo ] assoc-each { { f f } { f t } { t f } { t t } } [ notify-combo ] assoc-each
] with-string-writer print ] with-string-writer print
[ { { 10 30 } } ] [
<gadget> { 0 1 } >>orientation
{ { 10 20 } }
{ { 100 30 } }
orient
] unit-test
\ <gadget> must-infer \ <gadget> must-infer
\ unparent must-infer \ unparent must-infer
\ add-gadget must-infer \ add-gadget must-infer

View File

@ -86,15 +86,12 @@ M: gadget children-on nip children>> ;
: pick-up ( point gadget -- child/f ) : pick-up ( point gadget -- child/f )
2dup (pick-up) dup 2dup (pick-up) dup
[ nip [ rect-loc v- ] keep pick-up ] [ rot 2drop ] if ; [ nip [ rect-loc v- ] keep pick-up ] [ drop nip ] if ;
: max-dim ( dims -- dim ) { 0 0 } [ vmax ] reduce ; : max-dim ( dims -- dim ) { 0 0 } [ vmax ] reduce ;
: dim-sum ( seq -- dim ) { 0 0 } [ v+ ] reduce ; : dim-sum ( seq -- dim ) { 0 0 } [ v+ ] reduce ;
: orient ( gadget seq1 seq2 -- seq )
rot orientation>> '[ _ set-axis ] 2map ;
: each-child ( gadget quot -- ) : each-child ( gadget quot -- )
[ children>> ] dip each ; inline [ children>> ] dip each ; inline

View File

@ -18,14 +18,14 @@ grid
: <grid> ( children -- grid ) : <grid> ( children -- grid )
grid new-grid ; grid new-grid ;
: grid-child ( grid i j -- gadget ) rot grid>> nth nth ; :: grid-child ( grid i j -- gadget ) i j grid grid>> nth nth ;
:: grid-add ( grid child i j -- grid ) :: grid-add ( grid child i j -- grid )
grid i j grid-child unparent grid i j grid-child unparent
grid child add-gadget grid child add-gadget
child i j grid grid>> nth set-nth ; child i j grid grid>> nth set-nth ;
: grid-remove ( grid i j -- grid ) <gadget> -rot grid-add ; : grid-remove ( grid i j -- grid ) [ <gadget> ] 2dip grid-add ;
: pref-dim-grid ( grid -- dims ) : pref-dim-grid ( grid -- dims )
grid>> [ [ pref-dim ] map ] map ; grid>> [ [ pref-dim ] map ] map ;

View File

@ -48,9 +48,10 @@ TUPLE: closable-gadget < frame content ;
[ closable-gadget? ] find-parent ; [ closable-gadget? ] find-parent ;
: <closable-gadget> ( gadget title quot -- gadget ) : <closable-gadget> ( gadget title quot -- gadget )
closable-gadget new-frame [
-rot <title-bar> @top grid-add [ closable-gadget new-frame ] dip
swap >>content [ >>content ] [ @center grid-add ] bi
dup content>> @center grid-add ; ] 2dip
<title-bar> @top grid-add ;
M: closable-gadget focusable-child* content>> ; M: closable-gadget focusable-child* content>> ;

View File

@ -1,6 +1,7 @@
IN: ui.gadgets.packs.tests IN: ui.gadgets.packs.tests
USING: ui.gadgets.packs ui.gadgets.labels ui.gadgets ui.render USING: ui.gadgets.packs ui.gadgets.labels ui.gadgets ui.render
kernel namespaces tools.test math.parser sequences math.geometry.rect ; kernel namespaces tools.test math.parser sequences math.geometry.rect
accessors ;
[ t ] [ [ t ] [
{ 0 0 } { 100 100 } <rect> clip set { 0 0 } { 100 100 } <rect> clip set
@ -11,3 +12,10 @@ kernel namespaces tools.test math.parser sequences math.geometry.rect ;
visible-children [ label? ] all? visible-children [ label? ] all?
] unit-test ] unit-test
[ { { 10 30 } } ] [
{ { 10 20 } }
{ { 100 30 } }
<gadget> { 0 1 } >>orientation
orient
] unit-test

View File

@ -1,28 +1,30 @@
! Copyright (C) 2005, 2008 Slava Pestov. ! Copyright (C) 2005, 2008 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: sequences ui.gadgets kernel math math.functions USING: sequences ui.gadgets kernel math math.functions
math.vectors namespaces math.order accessors math.geometry.rect ; math.vectors math.order math.geometry.rect namespaces accessors
fry ;
IN: ui.gadgets.packs IN: ui.gadgets.packs
TUPLE: pack < gadget TUPLE: pack < gadget
{ align initial: 0 } { align initial: 0 } { fill initial: 0 } { gap initial: { 0 0 } } ;
{ fill initial: 0 }
{ gap initial: { 0 0 } } ;
: packed-dim-2 ( gadget sizes -- list ) : packed-dim-2 ( gadget sizes -- list )
[ over rect-dim over v- rot fill>> v*n v+ ] with map ; swap [ dim>> ] [ fill>> ] bi '[ _ over v- _ v*n v+ ] map ;
: orient ( seq1 seq2 gadget -- seq )
orientation>> '[ _ set-axis ] 2map ;
: packed-dims ( gadget sizes -- seq ) : packed-dims ( gadget sizes -- seq )
2dup packed-dim-2 swap orient ; [ packed-dim-2 ] [ nip ] [ drop ] 2tri orient ;
: gap-locs ( gap sizes -- seq ) : gap-locs ( gap sizes -- seq )
{ 0 0 } [ v+ over v+ ] accumulate 2nip ; { 0 0 } [ v+ over v+ ] accumulate 2nip ;
: aligned-locs ( gadget sizes -- seq ) : aligned-locs ( gadget sizes -- seq )
[ [ dup align>> swap rect-dim ] dip v- n*v ] with map ; [ [ [ align>> ] [ dim>> ] bi ] dip v- n*v ] with map ;
: packed-locs ( gadget sizes -- seq ) : packed-locs ( gadget sizes -- seq )
over gap>> over gap-locs [ dupd aligned-locs ] dip orient ; [ aligned-locs ] [ [ gap>> ] dip gap-locs ] [ drop ] 2tri orient ;
: round-dims ( seq -- newseq ) : round-dims ( seq -- newseq )
{ 0 0 } swap { 0 0 } swap
@ -45,12 +47,14 @@ TUPLE: pack < gadget
: <shelf> ( -- pack ) { 1 0 } <pack> ; : <shelf> ( -- pack ) { 1 0 } <pack> ;
: gap-dims ( gap sizes -- seeq ) : gap-dims ( sizes gadget -- seeq )
[ dim-sum ] keep length 1 [-] rot n*v v+ ; [ [ dim-sum ] [ length 1 [-] ] bi ] [ gap>> ] bi* n*v v+ ;
: pack-pref-dim ( gadget sizes -- dim ) : pack-pref-dim ( gadget sizes -- dim )
over gap>> over gap-dims [ max-dim ] dip [ nip max-dim ]
rot orientation>> set-axis ; [ swap gap-dims ]
[ drop orientation>> ]
2tri set-axis ;
M: pack pref-dim* M: pack pref-dim*
dup children>> pref-dims pack-pref-dim ; dup children>> pref-dims pack-pref-dim ;

View File

@ -1,7 +1,8 @@
! Copyright (C) 2005, 2007 Slava Pestov ! Copyright (C) 2005, 2008 Slava Pestov
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: accessors arrays ui.gadgets ui.gadgets.labels ui.render kernel math USING: accessors arrays ui.gadgets ui.gadgets.labels ui.render
namespaces sequences math.order math.geometry.rect ; kernel math namespaces sequences math.order math.geometry.rect
locals ;
IN: ui.gadgets.paragraphs IN: ui.gadgets.paragraphs
! A word break gadget ! A word break gadget
@ -46,12 +47,19 @@ SYMBOL: margin
dup line-height [ max ] change dup line-height [ max ] change
y get + max-y [ max ] change ; y get + max-y [ max ] change ;
: wrap-step ( quot child -- ) :: wrap-step ( quot child -- )
dup pref-dim [ child pref-dim
over word-break-gadget? [ [
dup first overrun? [ wrap-line ] when child
] unless drop wrap-pos rot call [
] keep first2 advance-y advance-x ; inline word-break-gadget?
[ drop ] [ first overrun? [ wrap-line ] when ] if
]
[ wrap-pos quot call ] bi
]
[ first advance-x ]
[ second advance-y ]
tri ; inline
: wrap-dim ( -- dim ) max-x get max-y get 2array ; : wrap-dim ( -- dim ) max-x get max-y get 2array ;

View File

@ -26,10 +26,11 @@ TUPLE: slider < frame elevator thumb saved line ;
: slider-max* ( gadget -- n ) model>> range-max-value* ; : slider-max* ( gadget -- n ) model>> range-max-value* ;
: thumb-dim ( slider -- h ) : thumb-dim ( slider -- h )
dup slider-page over slider-max 1 max / 1 min [
over elevator-length * min-thumb-dim max [ [ slider-page ] [ slider-max 1 max ] bi / 1 min ]
over elevator>> rect-dim [ elevator-length ] bi * min-thumb-dim max
rot orientation>> v. min ; ]
[ [ elevator>> dim>> ] [ orientation>> ] bi v. ] bi min ;
: slider-scale ( slider -- n ) : slider-scale ( slider -- n )
#! A scaling factor such that if x is a slider co-ordinate, #! A scaling factor such that if x is a slider co-ordinate,
@ -109,8 +110,8 @@ elevator H{
: layout-thumb-dim ( slider -- ) : layout-thumb-dim ( slider -- )
dup dup thumb-dim (layout-thumb) dup dup thumb-dim (layout-thumb)
[ [
[ dup rect-dim ] dip [ [ rect-dim ] dip ] [ drop orientation>> ] 2bi set-axis
rot orientation>> set-axis [ ceiling ] map [ ceiling ] map
] dip (>>dim) ; ] dip (>>dim) ;
: layout-thumb ( slider -- ) : layout-thumb ( slider -- )

View File

@ -1,7 +1,7 @@
! Copyright (C) 2005, 2008 Slava Pestov. ! Copyright (C) 2005, 2008 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: accessors arrays assocs continuations kernel math models USING: accessors arrays assocs continuations kernel math models
namespaces opengl sequences io combinators math.vectors namespaces opengl sequences io combinators fry math.vectors
ui.gadgets ui.gestures ui.render ui.backend ui.gadgets.tracks ui.gadgets ui.gestures ui.render ui.backend ui.gadgets.tracks
debugger math.geometry.rect ; debugger math.geometry.rect ;
IN: ui.gadgets.worlds IN: ui.gadgets.worlds
@ -67,9 +67,7 @@ M: world children-on nip children>> ;
: draw-world? ( world -- ? ) : draw-world? ( world -- ? )
#! We don't draw deactivated worlds, or those with 0 size. #! We don't draw deactivated worlds, or those with 0 size.
#! On Windows, the latter case results in GL errors. #! On Windows, the latter case results in GL errors.
dup active?>> [ active?>> ] [ handle>> ] [ dim>> [ 0 > ] all? ] tri and and ;
over handle>>
rot rect-dim [ 0 > ] all? and and ;
TUPLE: world-error error world ; TUPLE: world-error error world ;
@ -127,5 +125,4 @@ M: world handle-gesture ( gesture gadget -- ? )
] [ 2drop f ] if ; ] [ 2drop f ] if ;
: close-global ( world global -- ) : close-global ( world global -- )
dup get-global find-world rot eq? [ get-global find-world eq? ] keep '[ f _ set-global ] when ;
[ f swap set-global ] [ drop ] if ;

View File

@ -2,7 +2,7 @@
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: accessors arrays definitions kernel ui.commands USING: accessors arrays definitions kernel ui.commands
ui.gestures sequences strings math words generic namespaces make ui.gestures sequences strings math words generic namespaces make
hashtables help.markup quotations assocs ; hashtables help.markup quotations assocs fry ;
IN: ui.operations IN: ui.operations
SYMBOL: +keyboard+ SYMBOL: +keyboard+
@ -63,7 +63,7 @@ SYMBOL: operations
t >>listener? ; t >>listener? ;
: modify-operations ( operations hook translator -- operations ) : modify-operations ( operations hook translator -- operations )
rot [ modify-operation ] with with map ; '[ [ _ _ ] dip modify-operation ] map ;
: operations>commands ( object hook translator -- pairs ) : operations>commands ( object hook translator -- pairs )
[ object-operations ] 2dip modify-operations [ object-operations ] 2dip modify-operations

View File

@ -227,7 +227,7 @@ HOOK: free-fonts font-renderer ( world -- )
dup string? [ dup string? [
string-width string-width
] [ ] [
0 -rot [ string-width max ] with each [ 0 ] 2dip [ string-width max ] with each
] if ; ] if ;
: text-dim ( open-font text -- dim ) : text-dim ( open-font text -- dim )

View File

@ -117,5 +117,7 @@ deploy-gadget "toolbar" f {
dup com-revert ; dup com-revert ;
: deploy-tool ( vocab -- ) : deploy-tool ( vocab -- )
vocab-name dup <deploy-gadget> 10 <border> vocab-name
"Deploying \"" rot "\"" 3append open-window ; [ <deploy-gadget> 10 <border> ]
[ "Deploying \"" swap "\"" 3append ] bi
open-window ;

View File

@ -59,15 +59,15 @@ TUPLE: node value children ;
DEFER: (gadget-subtree) DEFER: (gadget-subtree)
: traverse-child ( frompath topath gadget -- ) : traverse-child ( frompath topath gadget -- )
[ -rot ] keep [ [ 2nip ] 3keep
[ rest-slice ] 2dip traverse-step (gadget-subtree) [ [ rest-slice ] 2dip traverse-step (gadget-subtree) ]
] make-node ; make-node ;
: (gadget-subtree) ( frompath topath gadget -- ) : (gadget-subtree) ( frompath topath gadget -- )
{ {
{ [ dup not ] [ 3drop ] } { [ dup not ] [ 3drop ] }
{ [ pick empty? pick empty? and ] [ 2nip , ] } { [ pick empty? pick empty? and ] [ 2nip , ] }
{ [ pick empty? ] [ rot drop traverse-to-path ] } { [ pick empty? ] [ traverse-to-path drop ] }
{ [ over empty? ] [ nip traverse-from-path ] } { [ over empty? ] [ nip traverse-from-path ] }
{ [ pick first pick first = ] [ traverse-child ] } { [ pick first pick first = ] [ traverse-child ] }
[ traverse-middle ] [ traverse-middle ]

View File

@ -296,8 +296,10 @@ SYMBOL: nc-buttons
key-modifiers swap message>button key-modifiers swap message>button
[ <button-down> ] [ <button-up> ] if ; [ <button-down> ] [ <button-up> ] if ;
: prepare-mouse ( hWnd uMsg wParam lParam -- button coordinate world ) :: prepare-mouse ( hWnd uMsg wParam lParam -- button coordinate world )
[ drop mouse-event>gesture ] dip >lo-hi rot window ; uMsg mouse-event>gesture
lParam >lo-hi
hWnd window ;
: set-capture ( hwnd -- ) : set-capture ( hwnd -- )
mouse-captured get [ mouse-captured get [
@ -435,7 +437,7 @@ M: windows-ui-backend do-events
style 0 ex-style AdjustWindowRectEx win32-error=0/f ; style 0 ex-style AdjustWindowRectEx win32-error=0/f ;
: make-RECT ( world -- RECT ) : make-RECT ( world -- RECT )
dup window-loc>> dup rot rect-dim v+ [ window-loc>> dup ] [ rect-dim ] bi v+
"RECT" <c-object> "RECT" <c-object>
over first over set-RECT-right over first over set-RECT-right
swap second over set-RECT-bottom swap second over set-RECT-bottom

View File

@ -95,8 +95,10 @@ M: world key-up-event
[ key-up-event>gesture ] dip world-focus propagate-gesture ; [ key-up-event>gesture ] dip world-focus propagate-gesture ;
: mouse-event>gesture ( event -- modifiers button loc ) : mouse-event>gesture ( event -- modifiers button loc )
dup event-modifiers over XButtonEvent-button [ event-modifiers ]
rot mouse-event-loc ; [ XButtonEvent-button ]
[ mouse-event-loc ]
tri ;
M: world button-down-event M: world button-down-event
[ mouse-event>gesture [ <button-down> ] dip ] dip [ mouse-event>gesture [ <button-down> ] dip ] dip
@ -222,8 +224,8 @@ M: x-clipboard paste-clipboard
utf8 encode dup length XChangeProperty drop ; utf8 encode dup length XChangeProperty drop ;
M: x11-ui-backend set-title ( string world -- ) M: x11-ui-backend set-title ( string world -- )
handle>> window>> swap dpy get -rot handle>> window>> swap
3dup set-title-old set-title-new ; [ dpy get ] 2dip [ set-title-old ] [ set-title-new ] 3bi ;
M: x11-ui-backend set-fullscreen* ( ? world -- ) M: x11-ui-backend set-fullscreen* ( ? world -- )
handle>> window>> "XClientMessageEvent" <c-object> handle>> window>> "XClientMessageEvent" <c-object>