1: \ mini-oof example
2:
3: \ Copyright (C) 1998,2003 Free Software Foundation, Inc.
4:
5: \ This file is part of Gforth.
6:
7: \ Gforth is free software; you can redistribute it and/or
8: \ modify it under the terms of the GNU General Public License
9: \ as published by the Free Software Foundation, either version 3
10: \ of the License, or (at your option) any later version.
11:
12: \ This program is distributed in the hope that it will be useful,
13: \ but WITHOUT ANY WARRANTY; without even the implied warranty of
14: \ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: \ GNU General Public License for more details.
16:
17: \ You should have received a copy of the GNU General Public License
18: \ along with this program. If not, see http://www.gnu.org/licenses/.
19:
20: \ usage:
21:
22: object class
23: cell var text
24: cell var len
25: cell var x
26: cell var y
27: method init
28: method draw
29: end-class button
30:
31: :noname ( o -- ) >r
32: r@ x @ r@ y @ at-xy r@ text @ r> len @ type ;
33: button defines draw
34: :noname ( addr u o -- ) >r
35: 0 r@ x ! 0 r@ y ! r@ len ! r> text ! ;
36: button defines init
37:
38: \ interitance
39:
40: : bold 27 emit ." [1m" ;
41: : normal 27 emit ." [0m" ;
42:
43: button class end-class bold-button
44: :noname bold [ button :: draw ] normal ; bold-button defines draw
45:
46: \ Create and draw a button:
47:
48: button new Constant foo
49: s" thin foo" foo init
50: page
51: foo draw
52: bold-button new Constant bar
53: s" fat bar" bar init
54: 1 bar y !
55: bar draw
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>