"/library/vocabularies.factor"
"/library/errors.factor"
"/library/continuations.factor"
+ "/library/styles.factor"
"/library/io/stream.factor"
"/library/io/duplex-stream.factor"
"/library/io/files.factor"
"/library/threads.factor"
- "/library/styles.factor"
"/library/syntax/parse-numbers.factor"
"/library/syntax/parse-words.factor"
! Copyright (C) 2004, 2005 Slava Pestov.
! See http://factor.sf.net/license.txt for BSD license.
IN: html
-USING: generic kernel lists namespaces presentation sequences
-io strings unparser http ;
+USING: generic http io kernel lists namespaces presentation
+sequences strings styles unparser words ;
: html-entities ( -- alist )
[
[ dup html-entities assoc [ % ] [ , ] ?ifte ] each
] make-string ;
-: >hex-color ( triplet -- hex )
- [ CHAR: # , [ >hex 2 CHAR: 0 pad-left % ] each ] make-string ;
+: hex-color, ( triplet -- )
+ [ >hex 2 CHAR: 0 pad-left % ] each ;
: fg-css, ( color -- )
- "color: " , >hex-color , "; " , ;
+ "color: #" % hex-color, "; " % ;
-: bold-css, ( flag -- )
- [ "font-weight: bold; " , ] when ;
-
-: italics-css, ( flag -- )
- [ "font-style: italic; " , ] when ;
+: style-css, ( flag -- )
+ dup [ italic bold-italic ] contains?
+ [ "font-style: italic; " % ] when
+ [ bold bold-italic ] contains?
+ [ "font-weight: bold; " % ] when ;
: underline-css, ( flag -- )
- [ "text-decoration: underline; " , ] when ;
+ [ "text-decoration: underline; " % ] when ;
: size-css, ( size -- )
- "font-size: " , unparse , "; " , ;
+ "font-size: " % unparse % "; " % ;
: font-css, ( font -- )
- "font-family: " , , "; " , ;
+ "font-family: " % % "; " % ;
: css-style ( style -- )
[
[
- [ "fg" fg-css, ]
- [ "bold" bold-css, ]
- [ "italics" italics-css, ]
- [ "underline" underline-css, ]
- [ "size" size-css, ]
- [ "font" font-css, ]
+ [ foreground fg-css, ]
+ [ font font-css, ]
+ [ font-style style-css, ]
+ [ font-size size-css, ]
+ [ underline underline-css, ]
] assoc-apply
] make-string ;
] when* "/" ?tail drop ;
: file-link-href ( path -- href )
- [ "/" , resolve-file-link url-encode , ] make-string ;
+ [ "/" % resolve-file-link url-encode % ] make-string ;
: file-link-tag ( style quot -- )
over "file" swap assoc [
call
] ifte* ;
-: browser-link-href ( style -- href )
- dup "word" swap assoc url-encode
- swap "vocab" swap assoc url-encode
- [ "/responder/browser/?vocab=" , , "&word=" , , ] make-string ;
+: browser-link-href ( word -- href )
+ dup word-name swap word-vocabulary
+ [ "/responder/browser/?vocab=" % % "&word=" % % ] make-string ;
: browser-link-tag ( style quot -- style )
- over "word" swap assoc [
- <a href= over browser-link-href a> call </a>
+ over presented swap assoc dup word? [
+ <a href= browser-link-href a> call </a>
] [
- call
+ drop call
] ifte ;
: icon-tag ( string style quot -- )
- over "icon" swap assoc dup [
+ over icon swap assoc dup [
<img src= "/responder/resource/" swap append img/>
#! Ignore the quotation, since no further style
#! can be applied
#! written, and supports writing attributed strings with
#! the following attributes:
#!
- #! fg - an rgb triplet in a list
- #! bg - an rgb triplet in a list
- #! bold
- #! italics
+ #! foreground - an rgb triplet in a list
+ #! background - an rgb triplet in a list
+ #! font
+ #! font-style
+ #! font-size
#! underline
- #! size
#! icon
#! file
#! word
! Hyperlinked directory listings.
-: file-actions ( -- list )
- [
- [[ "Push" "" ]]
- [[ "Run file" "run-file" ]]
- [[ "List directory" "directory." ]]
- [[ "Change directory" "cd" ]]
- ] ;
-
: dir-icon "/library/icons/Folder.png" ;
- : file-icon "/library/icons/File.png" ;
- : file-icon. directory? dir-icon file-icon ? write-icon ;
+: file-icon "/library/icons/File.png" ;
+: file-icon. directory? dir-icon file-icon ? write-icon ;
: file-link. ( dir name -- )
- tuck "/" swap append3 dup "file" swons swap
- unparse file-actions <actions> "actions" swons
- 2list write-attr ;
+ tuck path+ "file" swons unit write-attr ;
: file. ( dir name -- )
#! If "doc-root" set, create links relative to it.
- 2dup "/" swap append3 file-icon. bl file-link. terpri ;
+ 2dup path+ file-icon. bl file-link. terpri ;
: directory. ( dir -- )
#! If "doc-root" set, create links relative to it.
dup directory [
- dup [ "." ".." ] contains? [
- 2drop
- ] [
- file.
- ] ifte
+ dup [ "." ".." ] contains? [ 2drop ] [ file. ] ifte
] each-with ;
! Copyright (C) 2003, 2005 Slava Pestov.
! See http://factor.sf.net/license.txt for BSD license.
IN: io
-USING: errors kernel lists namespaces generic strings ;
+USING: errors generic kernel lists namespaces strings styles ;
: flush ( -- ) stdio get stream-flush ;
: read-line ( -- string ) stdio get stream-readln ;
: write-icon ( resource -- )
#! Write an icon. Eg, /library/icons/File.png
- "icon" swons unit "" swap write-attr ;
+ icon swons unit "" swap write-attr ;
: with-stream ( stream quot -- )
#! Close the stream no matter what happends.
SYMBOL: italic
SYMBOL: bold-italic
+SYMBOL: underline
+
SYMBOL: presented
+
+SYMBOL: icon
GENERIC: prettyprint* ( indent obj -- indent )
M: object prettyprint* ( indent obj -- indent )
- unparse write ;
+ dup unparse swap presented swons unit write-attr ;
: word-attrs ( word -- style )
#! Return the style values for the HTML word browser
: button-update ( button -- )
dup dup mouse-over? rollover set-paint-prop
dup dup button-pressed? reverse-video set-paint-prop
- redraw ;
+ relayout ;
: button-clicked ( button -- )
#! If the mouse is released while still inside the button,
! A gadget is a shape, a paint, a mapping of gestures to
! actions, and a reference to the gadget's parent. A gadget
! delegates to its shape.
-TUPLE: gadget
- paint gestures
- relayout? redraw? root?
- parent children ;
+TUPLE: gadget paint gestures relayout? root? parent children ;
: gadget-child gadget-children car ;
: <plain-gadget> ( -- gadget ) 0 0 0 0 <plain-rect> <gadget> ;
-DEFER: relayout
DEFER: add-invalid
: invalidate ( gadget -- )
: relayout ( gadget -- )
#! Relayout and redraw a gadget and its parent before the
#! next iteration of the event loop.
- dup redraw
dup gadget-relayout? [
drop
] [
dup invalidate
dup gadget-root?
- [ world get add-invalid ]
+ [ add-invalid ]
[ gadget-parent [ relayout ] when* ] ifte
] ifte ;
+: (relayout-down)
+ dup invalidate gadget-children [ (relayout-down) ] each ;
+
: relayout-down ( gadget -- )
#! Relayout a gadget and its children.
- dup world get add-invalid
- dup invalidate gadget-children [ relayout-down ] each ;
+ dup add-invalid (relayout-down) ;
: move-gadget ( x y gadget -- )
>r 0 3vector r> set-shape-loc ;
click-loc click-rel clicked buttons
gadget focus ;
-: hand-click-pos hand-click-loc 3unseq drop rect> ;
-
C: hand ( world -- hand )
<empty-gadget>
over set-delegate
IN: gadgets
USING: generic io kernel listener math namespaces styles threads ;
-
-global [
- <world> world set
-
- {{
- [[ background [ 255 255 255 ] ]]
- [[ rollover-bg [ 255 255 204 ] ]]
- [[ foreground [ 0 0 0 ] ]]
- [[ reverse-video f ]]
- [[ font "Sans Serif" ]]
- [[ font-size 12 ]]
- [[ font-style plain ]]
- }} world get set-gadget-paint
+: init-world
+ global [
+ <world> world set
+
+ {{
+ [[ background [ 255 255 255 ] ]]
+ [[ rollover-bg [ 255 255 204 ] ]]
+ [[ foreground [ 0 0 0 ] ]]
+ [[ reverse-video f ]]
+ [[ font "Sans Serif" ]]
+ [[ font-size 12 ]]
+ [[ font-style plain ]]
+ }} world get set-gadget-paint
+
+ { 1024 768 0 } world get set-gadget-dim
+
+ <plain-gadget> add-layer
- { 1024 768 0 } world get set-gadget-dim
-
- <plain-gadget> add-layer
+ <pane> dup
+
+ <scroller> "Stack display goes here" <label> 3/4 <y-splitter> add-layer
+
+ dup [ [ clear print-banner listener ] in-thread ] with-stream
+
+ request-focus
+ ] bind ;
- <pane> dup
-
- <scroller> "Stack display goes here" <label> 3/4 <y-splitter> add-layer
-
- dup [ [ clear print-banner listener ] in-thread ] with-stream
-
- request-focus
-] bind
+SYMBOL: first-time
+
+global [ first-time on ] bind
+
+: ?init-world
+ first-time get [ init-world first-time off ] when ;
USING: generic hashtables kernel lists math namespaces sdl
io strings sequences ;
-: redraw ( gadget -- )
- #! Redraw a gadget before the next iteration of the event
- #! loop.
- drop t world get set-gadget-redraw? ;
-
! Clipping
SYMBOL: clip
#! All drawing done inside draw-shape is done with the
#! gadget's paint. If the gadget does not have any custom
#! paint, just call the quotation.
- f over set-gadget-redraw?
dup gadget-paint [
dup [
[
: ui ( -- )
#! Start the Factor graphics subsystem with the given screen
#! dimensions.
+ ?init-world
world get shape-size 0 SDL_RESIZABLE [
0 x set 0 y set [
"Factor " version append dup SDL_WM_SetCaption
t over set-gadget-root?
dup <hand> over set-world-hand ;
-: add-invalid ( gadget world -- )
- [ world-invalid cons ] keep set-world-invalid ;
+: add-invalid ( gadget -- )
+ world get [ world-invalid cons ] keep set-world-invalid ;
-: pop-invalid ( world -- list )
- [ world-invalid f ] keep set-world-invalid ;
+: pop-invalid ( -- list )
+ world get [ world-invalid f ] keep set-world-invalid ;
-: layout-world ( world -- )
- dup world-invalid [
- dup pop-invalid [ layout ] each layout-world
- ] [
- drop
- ] ifte ;
+: layout-world ( -- )
+ world get world-invalid
+ [ pop-invalid [ layout ] each layout-world ] when ;
: add-layer ( gadget -- )
world get add-gadget ;
: hand world get world-hand ;
: draw-world ( world -- )
- dup gadget-redraw? [
- [
- dup 0 0 width get height get <rectangle> clip set-paint-prop
- draw-gadget
- ] with-surface
- ] [
- drop
- ] ifte ;
+ [
+ dup 0 0 width get height get <rectangle> clip set-paint-prop
+ draw-gadget
+ ] with-surface ;
DEFER: handle-event
-: world-step ( world -- ? )
- world get dup world-running? [
- dup layout-world draw-world t
- ] [
- drop f
- ] ifte ;
+: world-step ( -- ? )
+ world get dup world-invalid >r layout-world r>
+ [ draw-world ] [ drop ] ifte ;
: next-event ( -- event ? )
<event> dup SDL_PollEvent ;
next-event [
handle-event run-world
] [
- drop world-step [ yield run-world ] when
+ drop world-step
+ world get world-running? [ yield run-world ] when
] ifte ;
: ensure-ui ( -- )