Rev 9053 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
8178 | superturbo | 1 | package kernel |
2 | |||
3 | import "os" |
||
4 | import "colors" |
||
5 | |||
6 | const ( |
||
7 | Btn1=2; |
||
8 | Btn2=3; |
||
9 | BtnExit=1; |
||
10 | ) |
||
11 | |||
9063 | pavelyakov | 12 | type Button struct { // structure gui button |
13 | label string |
||
14 | x int |
||
15 | y int |
||
16 | id int |
||
17 | } |
||
18 | |||
19 | func NewButton() Button { |
||
20 | object := Button{"Text",0,0,Btn1} // default data |
||
21 | return object |
||
22 | } |
||
23 | |||
24 | func (button *Button) make() { |
||
25 | os.CreateButton(button.x, button.y, len(button.label)*15, 30, button.id, colors.Blue); |
||
26 | os.WriteText(button.x,button.y, 0x11000000 | colors.White, button.label) |
||
27 | } |
||
28 | |||
8178 | superturbo | 29 | func RedrawAll(bar_pos int){ |
9053 | pavelyakov | 30 | os.Redraw(1) |
9063 | pavelyakov | 31 | os.Window(500,250,420,200, "Example GoLang") |
8178 | superturbo | 32 | os.DrawLine(32, 80, 150, 80, colors.Green) |
9053 | pavelyakov | 33 | os.DrawBar(bar_pos, 90, 100, 30, colors.Red); |
9063 | pavelyakov | 34 | |
35 | b1 := NewButton() |
||
36 | b1.label = " <- " |
||
37 | b1.x = 32 |
||
38 | b1.y = 128 |
||
39 | b1.id = Btn1 |
||
40 | b1.make() |
||
41 | |||
42 | b2 := NewButton() |
||
43 | b2.label = " -> " |
||
44 | b2.x = 310 |
||
45 | b2.y = 128 |
||
46 | b2.id = Btn2 |
||
47 | b2.make() |
||
8178 | superturbo | 48 | } |
49 | |||
9063 | pavelyakov | 50 | func Main() { |
51 | var pos = 160; |
||
9053 | pavelyakov | 52 | //time := os.GetTime() |
53 | //os.DebugOutStr("Time: ") |
||
54 | //os.DebugOutHex(time) |
||
8178 | superturbo | 55 | for true { |
56 | switch os.Event() { |
||
9063 | pavelyakov | 57 | case os.EVENT_REDRAW: |
8178 | superturbo | 58 | RedrawAll(pos) |
59 | break |
||
60 | case os.EVENT_BUTTON: |
||
9063 | pavelyakov | 61 | switch os.GetButtonID() { |
62 | case Btn1: |
||
63 | pos-=32 |
||
64 | RedrawAll(pos) |
||
65 | break |
||
66 | case Btn2: |
||
67 | pos+=32 |
||
68 | RedrawAll(pos); |
||
69 | break |
||
70 | case BtnExit: |
||
71 | os.Exit() |
||
72 | } |
||
8178 | superturbo | 73 | } |
74 | } |
||
75 | }-> |