[gforth] / gforth / moof-exm.fs  

gforth: gforth/moof-exm.fs


1 : anton 1.2 \ mini-oof example
2 :    
3 : anton 1.3 \ Copyright (C) 1998,2003 Free Software Foundation, Inc.
4 : anton 1.2
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 2
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, write to the Free Software
19 :     \ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
20 :    
21 : pazsan 1.1 \ usage:
22 :    
23 :     object class
24 :     cell var text
25 :     cell var len
26 :     cell var x
27 :     cell var y
28 :     method init
29 :     method draw
30 :     end-class button
31 :    
32 :     :noname ( o -- ) >r
33 :     r@ x @ r@ y @ at-xy r@ text @ r> len @ type ;
34 :     button defines draw
35 :     :noname ( addr u o -- ) >r
36 :     0 r@ x ! 0 r@ y ! r@ len ! r> text ! ;
37 :     button defines init
38 :    
39 :     \ interitance
40 :    
41 :     : bold 27 emit ." [1m" ;
42 :     : normal 27 emit ." [0m" ;
43 :    
44 :     button class end-class bold-button
45 :     :noname bold [ button :: draw ] normal ; bold-button defines draw
46 :    
47 :     \ Create and draw a button:
48 :    
49 :     button new Constant foo
50 :     s" thin foo" foo init
51 :     page
52 :     foo draw
53 :     bold-button new Constant bar
54 :     s" fat bar" bar init
55 :     1 bar y !
56 :     bar draw

CVS Admin

Powered by ViewCVS 1.0-dev
(Powered by ViewCVS)

ViewCVS and CVS Help