- fix listener prompt display after presentation commands invoked\r
- tutorial: clickable code snippets\r
- theme abstraction in ui\r
+- stray gesture son stack\r
\r
+ misc\r
\r
USING: gadgets generic kernel lists math namespaces sdl
sequences vectors words ;
+SYMBOL: x
+SYMBOL: y
+
! A frame arranges left/right/top/bottom gadgets around a
! center gadget, which gets any leftover space.
TUPLE: frame left right top bottom center ;
: var-frame-top \ frame-top var-frame-y ;
: var-frame-right
dup \ frame-right var-frame-x
- swap shape-w \ frame-right [ - ] change
+ swap rectangle-dim first \ frame-right [ - ] change
\ frame-right get \ frame-left get - frame-right-run set ;
: var-frame-bottom
dup \ frame-bottom var-frame-y
- swap shape-h \ frame-bottom [ - ] change
+ swap rectangle-dim second \ frame-bottom [ - ] change
\ frame-bottom get \ frame-top get - frame-bottom-run set ;
: setup-frame ( frame -- )
USING: generic hashtables kernel lists math matrices namespaces
sequences styles vectors ;
-! 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.
+SYMBOL: origin
+
+global [ { 0 0 0 } origin set ] bind
+
+TUPLE: rectangle loc dim ;
+
+GENERIC: inside? ( loc shape -- ? )
+
+: shape-bounds ( shape -- loc dim )
+ dup rectangle-loc swap rectangle-dim ;
+
+: shape-extent ( shape -- loc dim )
+ dup rectangle-loc dup rot rectangle-dim v+ ;
+
+: screen-bounds ( shape -- rect )
+ shape-bounds >r origin get v+ r> <rectangle> ;
+
+M: rectangle inside? ( loc rect -- ? )
+ screen-bounds shape-bounds { 1 1 1 } v- { 0 0 0 } vmax
+ >r v- { 0 0 0 } r> vbetween? conj ;
+
+: intersect ( shape shape -- rect )
+ >r shape-extent r> shape-extent
+ swapd vmin >r vmax dup r> swap v- { 0 0 0 } vmax
+ <rectangle> ;
+
+! A gadget is a rectangle, a paint, a mapping of gestures to
+! actions, and a reference to the gadget's parent.
TUPLE: gadget
paint gestures visible? relayout? root?
parent children ;
USING: kernel parser sequences io ;
[
- "/library/ui/shapes.factor"
"/library/ui/gadgets.factor"
"/library/ui/hierarchy.factor"
"/library/ui/paint.factor"
: draw-gadget ( gadget -- )
dup gadget-visible? [
dup [
- dup [
- dup draw-gadget*
- gadget-children [ draw-gadget ] each
- ] with-trans
+ dup rectangle-loc origin [ v+ ] change
+ dup draw-gadget*
+ gadget-children [ draw-gadget ] each
] with-clip
] [ drop ] ifte ;
TUPLE: solid ;
: rect>screen ( shape -- x1 y1 x2 y2 )
- >r origin dup r> rectangle-dim v+ >r 2unseq r> 2unseq ;
+ >r origin get dup r> rectangle-dim v+ >r 2unseq r> 2unseq ;
! Solid pen
M: solid draw-interior
: (gradient-x) ( gradient dim y -- x1 x2 y color )
dup pick second / >r rot r> gradient-color >r
- >r >r x get r> first x get + r> y get + r> ;
+ >r >r origin get first r> origin get v+ first
+ r> origin get second + r> ;
: gradient-x ( gradient dim y -- )
>r >r >r surface get r> r> r> (gradient-x) rgb hlineColor ;
: (gradient-y) ( gradient dim x -- x y1 y2 color )
dup pick first / >r rot r> gradient-color
- >r x get + y get rot second y get + r> ;
+ >r origin get first + origin get second rot
+ origin get v+ second r> ;
: gradient-y ( gradient dim x -- )
>r >r >r surface get r> r> r> (gradient-y) rgb vlineColor ;
#! Ugly code.
bevel-width [
[
- >r origin over rectangle-dim over v+ r>
+ >r origin get over rectangle-dim over v+ r>
{ 1 1 0 } n*v tuck v- { 1 1 0 } v- >r v+ r>
rot draw-bevel
] 2keep
+++ /dev/null
-! Copyright (C) 2005 Slava Pestov.
-! See http://factor.sf.net/license.txt for BSD license.
-IN: gadgets
-USING: generic kernel lists math matrices namespaces sdl
-sequences vectors ;
-
-SYMBOL: x
-SYMBOL: y
-
-: origin ( -- loc ) x get y get 0 3vector ;
-
-TUPLE: rectangle loc dim ;
-
-GENERIC: inside? ( loc shape -- ? )
-
-: shape-x rectangle-loc first ;
-: shape-y rectangle-loc second ;
-: shape-w rectangle-dim first ;
-: shape-h rectangle-dim second ;
-
-: with-trans ( shape quot -- )
- #! All drawing done inside the quotation is translated
- #! relative to the shape's origin.
- [
- >r dup
- shape-x x [ + ] change
- shape-y y [ + ] change
- r> call
- ] with-scope ; inline
-
-: shape-bounds ( shape -- loc dim )
- dup rectangle-loc swap rectangle-dim ;
-
-: shape-extent ( shape -- loc dim )
- dup rectangle-loc dup rot rectangle-dim v+ ;
-
-: screen-bounds ( shape -- rect )
- shape-bounds >r origin v+ r> <rectangle> ;
-
-M: rectangle inside? ( loc rect -- ? )
- screen-bounds shape-bounds { 1 1 1 } v- { 0 0 0 } vmax
- >r v- { 0 0 0 } r> vbetween? conj ;
-
-: intersect ( shape shape -- rect )
- >r shape-extent r> shape-extent
- swapd vmin >r vmax dup r> swap v- { 0 0 0 } vmax
- <rectangle> ;
>r [ gadget-font ] keep r> swap
fg 3unlist make-color
TTF_RenderUNICODE_Blended
- [ >r origin 2unseq r> draw-surface ] keep
+ [ >r origin get 2unseq r> draw-surface ] keep
SDL_FreeSurface
] ifte ;
ttf-init
?init-world
world get rectangle-dim 2unseq 0 SDL_RESIZABLE [
- 0 x set 0 y set [
+ [
"Factor " version append dup SDL_WM_SetCaption
start-world
run-world