small fixes to X11
[k8lst.git] / samples / x11 / x11test.st
blobaa506669b6585c0a41fdd55de660f311d9df158e
1 Requires [ x11 ]
4 X11Window subclass: MyX11Window [
5   | ox oy lineList |
7   centerText: y text: aText [
8     | x e |
9     e := font textExtents: aText.
10     y := y + (e at: 4).
11     x := (self width - (e at: 1) + (e at: 3)) / 2.
12     self drawTextAt: x @ y text: aText.
13   ]
15   init [
16     | btn |
17     super init.
18     '***MyX11Window init' printNl.
20     btn := X11Button new: self at: 2 @ 80 text: 'quit'.
21     '***button created' printNl.
22     btn onClick: [:btn | 'quit clicked!' printNl. self close ].
24     btn := X11Button new: self at: (2 + btn width + 4) @ 80 text: 'button 1'.
25     '***button created' printNl.
26     btn onClick: [:btn | 'button clicked!' printNl ].
28     self fontColor: 1.0 g: 1.0 b: 1.0.
29     self onExpose: [:w :full  :rc |
30       full ifTrue: [
31         rc := (w clientSizeRect) growX: 1 y: 1.
32         w;
33          fgColor: 0.0 g: 0.1 b: 0;
34          fillRect: rc;
35          fgColor: 1.0 g: 0 b: 0;
36          drawLine: 1 @ 1 to: 80 @ 60;
37          fgColor: 0 g: 1.0 b: 0;
38          drawLine: 1 @ 10 to: 80 @ 60;
39          fgColor: 0 g: 0 b: 1.0;
40          drawLine: 1 @ 20 to: 80 @ 60;
41          fgColor: 0.5 g: 0 b: 0;
42          drawLine: 1 @ 50 to: 80 @ 60;
43          fgColor: 1.0 g: 1.0 b: 0.
44         lineList ifNotNil: [ lineList do: [:i | w drawLine: (i at: 1) to: (i at: 2) ]].
45         w centerText: 5 text: 'Xft works!'.
46         w drawTextAt: 2 @ 2 text: 'drawText'.
47       ].
48     ].
49     self onButtonDown: [:w :bt :evt  :x :y |
50       x := evt at: 3.
51       y := evt at: 4.
52       bt = 3 ifTrue: [ ox := x. oy := y. lineList := List new. ].
53       bt = 1 ifTrue: [
54         ox ifNotNil: [
55           lineList << (Array with: ox @ oy with: x @ y).
56           w;
57            fgColor: 1.0 g: 1.0 b: 0;
58            drawLine: ox @ oy to: x @ y.
59           ox := x. oy := y.
60         ] ifNil: [
61           ox := x. oy := y. lineList := List new.
62         ]
63       ].
64     ].
65   ]
70   | w |
71   "X11Singleton dumpEvents: true."
72   X11Singleton initialize.
73   w := MyX11Window new: nil at: 0 @ 0 size: 200 @ 110 title: 'LST X11 test'.
74   w show.
75   X11Singleton eventLoop.
76   'quit' printNl.
77   X11Singleton deinitialize.
78   'done' printNl.