! Colors are lists of three integers, 0..255.
SYMBOL: foreground ! Used for text and outline shapes.
SYMBOL: background ! Used for filled shapes.
+SYMBOL: rollover-bg
+SYMBOL: rollover
SYMBOL: reverse-video
-: fg reverse-video get background foreground ? get ;
-: bg reverse-video get foreground background ? get ;
+: fg ( -- color )
+ reverse-video get background foreground ? get ;
+
+: bg ( -- color )
+ reverse-video get [
+ foreground
+ ] [
+ rollover get rollover-bg background ?
+ ] ifte get ;
SYMBOL: font
SYMBOL: font-size
#! Return true if the mouse was clicked on the button, and
#! is currently over the button.
dup mouse-over? [
- 1 button-down? [
- hand hand-clicked child?
- ] [
- drop f
- ] ifte
+ 1 button-down?
+ [ hand hand-clicked child? ] [ drop f ] ifte
] [
drop f
] ifte ;
: button-update ( button -- )
- dup dup mouse-over? rollover? set-paint-prop
+ dup dup mouse-over? rollover set-paint-prop
dup dup button-pressed? reverse-video set-paint-prop
redraw ;
: button-clicked ( button -- )
#! If the mouse is released while still inside the button,
#! fire an action gesture.
- dup mouse-over? [
- [ action ] swap handle-gesture drop
- ] [
- drop
- ] ifte ;
+ dup mouse-over?
+ [ [ action ] swap handle-gesture drop ] [ drop ] ifte ;
: button-action ( action -- quot )
[ [ swap handle-gesture drop ] cons ] [ [ drop ] ] ifte* ;
: <button> ( label action -- button )
>r <label> line-border dup r> button-action button-gestures ;
-
-: roll-border ( child -- border )
- 0 0 0 0 <roll-rect> <gadget> 1 <border> ;
-
-: <roll-button> ( label quot -- gadget )
- #! Thinner border that is only visible when the mouse is
- #! over the button.
- >r <label> roll-border dup r> button-action button-gestures ;
set-gadget-children ;
: unparent ( gadget -- )
- dup gadget-parent dup [ remove-gadget ] [ 2drop ] ifte ;
+ [
+ dup gadget-parent dup
+ [ remove-gadget ] [ 2drop ] ifte
+ ] when* ;
: add-gadget ( gadget box -- )
#! Add a gadget to a box.
{{
[[ background [ 255 255 255 ] ]]
+ [[ rollover-bg [ 216 216 216 ] ]]
[[ foreground [ 0 0 0 ] ]]
[[ reverse-video f ]]
[[ font "Sans Serif" ]]
<plain-gadget> world get add-gadget
<console> "Stack display goes here" <label> <y-splitter>
- 3/4 over set-splitter-split
- world get add-gadget
+ 3/4 over set-splitter-split add-layer
] bind
M: label draw-shape ( label -- )
[ dup gadget-font swap label-text ] keep
[ draw-string ] with-trans ;
-
-: <styled-label> ( style text -- label )
- <label> swap alist>hash over set-gadget-paint ;
"/library/ui/editors.factor"
"/library/ui/menus.factor"
"/library/ui/splitters.factor"
+ "/library/ui/presentations.factor"
"/library/ui/panes.factor"
"/library/ui/init-world.factor"
"/library/ui/ui.factor"
: hide-menu ( -- )
world get
- dup world-menu [ unparent ] when* f swap set-world-menu ;
+ dup hide-glass
+ [ world-menu unparent f ] keep set-world-menu ;
: show-menu ( menu -- )
hide-menu
world get
2dup set-world-menu
2dup world-hand screen-pos >rect rot move-gadget
- add-gadget ;
+ show-glass ;
: menu-item-border ( child -- border )
<plain-gadget> 1 <border> ;
! Copyright (C) 2005 Slava Pestov.
! See http://factor.sf.net/license.txt for BSD license.
IN: gadgets
-USING: generic kernel line-editor listener lists math namespaces
-sequences io strings threads styles ;
+USING: generic hashtables io kernel line-editor listener lists
+math namespaces prettyprint sequences strings styles threads ;
! A pane is an area that can display text.
TUPLE: pane output active current input continuation ;
: add-output 2dup set-pane-output add-gadget ;
+
: add-input 2dup set-pane-input add-gadget ;
: <active-line> ( input current -- line )
<line-shelf> [ add-gadget ] keep [ add-gadget ] keep ;
: init-active-line ( pane -- )
- dup pane-active [ unparent ] when*
+ dup pane-active unparent
[ dup pane-input swap pane-current <active-line> ] keep
2dup set-pane-active add-gadget ;
! Panes are streams.
M: pane stream-flush ( stream -- ) relayout ;
+
M: pane stream-auto-flush ( stream -- ) stream-flush ;
M: pane stream-readln ( stream -- line )
--- /dev/null
+! Copyright (C) 2005 Slava Pestov.
+! See http://factor.sf.net/license.txt for BSD license.
+IN: gadgets
+USING: hashtables io kernel lists namespaces prettyprint ;
+
+: actions-menu ( -- )
+ "actions" get <menu> show-menu ;
+
+: init-actions ( gadget -- )
+ [ "actions" get actions-menu ] button-gestures ;
+
+: <styled-label> ( style text -- label )
+ <label> "actions" pick assoc [ dup init-actions ] when
+ swap alist>hash over set-gadget-paint ;
M: etched-rect draw-shape ( rect -- )
>r surface get r> 2dup plain-rect hollow-rect ;
-
-! A rectangle that has a visible outline only if the rollover
-! paint property is set.
-SYMBOL: rollover?
-
-TUPLE: roll-rect ;
-
-C: roll-rect ( x y w h -- rect )
- [ >r <rectangle> r> set-delegate ] keep ;
-
-M: roll-rect draw-shape ( rect -- )
- >r surface get r> 2dup
- plain-rect rollover? get [ hollow-rect ] [ 2drop ] ifte ;
! gadgets are contained in. The current world is stored in the
! world variable. The menu slot ensures that only one menu is
! open at any one time.
-TUPLE: world running? hand menu ;
+TUPLE: world running? hand menu glass ;
C: world ( -- world )
f <stack> over set-delegate
t over set-world-running?
dup <hand> over set-world-hand ;
+: add-layer ( gadget -- )
+ world get add-gadget ;
+
+: show-glass ( gadget world -- )
+ >r <empty-gadget> [ add-gadget ] keep
+ r> 2dup set-world-glass add-gadget ;
+
+: hide-glass ( world -- )
+ [ world-glass unparent f ] keep set-world-glass ;
+
M: world inside? ( point world -- ? ) 2drop t ;
: hand world get world-hand ;