cleaned all trailing white space from source files.
[sdk] / samples / guiAndGfx / disablingMovingControls / form2.ec
1 import "ecere"
2
3 define app = ((GuiApplication)__thisModule);
4
5 struct WindowAsteroid {
6    Window win;
7    int dx, dy;
8
9    property int x {
10       get { return win.position.x; }
11       set { win.position.x = value; }
12    }
13    property int y {
14       get { return win.position.y; }
15       set { win.position.y = value; }
16    }
17    property int w {
18       get { return win.size.w; }
19       set { win.size.w = value; }
20    }
21    property int h {
22       get { return win.size.h; }
23       set { win.size.h = value; }
24    }
25 };
26
27 class WindowAsteroidField : struct {
28 public:
29    Window holder;
30    uint count;
31    WindowAsteroid *item;
32
33    void Initialize(uint wcount, Window win[]) {
34       uint i;
35       count = wcount;
36       delete item;
37       item = new WindowAsteroid[wcount];
38       for (i=0; i<wcount; i++) {
39          item[i].win = win[i];
40          do {
41             item[i].dx = GetRandom(-3,3);
42             item[i].dy = GetRandom(-3,3);
43          } while (!item[i].dx && !item[i].dy);
44       }
45    }
46
47    void Advance(void) {
48       WindowAsteroid *i = item;
49       uint d = count;
50       for (;d--;i++) {
51          i->x += i->dx;
52          i->y += i->dy;
53          if (i->x<0 && i->dx<0 || (i->x+i->w >= holder.clientSize.w && i->dx>0))
54             i->dx = -i->dx;
55          if (i->y<0 && i->dy<0 || (i->y+i->h >= holder.clientSize.h && i->dy>0))
56             i->dy = -i->dy;
57       }
58    }
59
60    ~WindowAsteroidField() {
61       delete item;
62    }
63 };
64
65 class Form2 : Window
66 {
67    text = "Enabled/Disabled";
68    background = activeBorder;
69    borderStyle = sizable;
70    hasMaximize = true;
71    hasMinimize = true;
72    hasClose = true;
73    tabCycle = true;
74    size = { 560, 184 };
75    anchor = { horz = -11, vert = -126 };
76
77    WindowAsteroidField astfield {this};
78    Timer asteroidTimer {
79       this, 0.03, false;
80       bool DelayExpired()
81       {
82          astfield.Advance();
83          return true;
84       }
85    };
86    int waste_direction;
87    waste_direction = -3;
88    Timer wasteCPUTimer {
89       this, 0.01, false;
90       bool DelayExpired()
91       {
92          Button button = button5;
93          button.position.x += waste_direction;
94          if (button.position.x < 0) {
95             button.position.x = 0;
96             if (waste_direction<0)
97                waste_direction = -waste_direction;
98          } else if (button.position.x > size.w-button.size.w) {
99             button.position.x = size.w-button.size.w;
100             if (waste_direction>0)
101                waste_direction = -waste_direction;
102          }
103          return true;
104       }
105    }
106
107    uint counter0, counter1;
108    Button button5
109    {
110       this, text = "Waste CPU cycles", size = { 135, 21 }, position = { 120, 120 }, isCheckbox = true;
111
112       bool NotifyClicked(Button button, int x, int y, Modifiers mods)
113       {
114          wasteCPUTimer.started = button.checked;
115          return true;
116       }
117    };
118    Button button6
119    {
120       this, text = "Asteroid Field", size = { 103, 21 }, position = { 416, 48 }, isCheckbox = true;
121
122       bool NotifyClicked(Button button, int x, int y, Modifiers mods)
123       {
124          asteroidTimer.started = button.checked;
125          return true;
126       }
127    };
128    Button button4
129    {
130       this, text = "Enabled", position = { 288, 88 }, isCheckbox = true, checked = true;
131
132       bool NotifyClicked(Button button, int x, int y, Modifiers mods)
133       {
134          button2.disabled = !button.checked;
135          return true;
136       }
137    };
138    EditBox editBox1 { this, text = "editBox1", contents = "0", position = { 96, 56 }, readOnly = true };
139    EditBox editBox2 { this, text = "editBox2", contents = "0", position = { 296, 56 }, readOnly = true };
140    Button button3
141    {
142       this, text = "Enabled", position = { 88, 88 }, isCheckbox = true, checked = true;
143
144       bool NotifyClicked(Button button, int x, int y, Modifiers mods)
145       {
146          button1.disabled = !button.checked;
147          return true;
148       }
149    };
150    Button button2
151    {
152       this, text = "Up Me", size = { 119, 21 }, position = { 280, 24 };
153
154       bool NotifyClicked(Button button, int x, int y, Modifiers mods)
155       {
156          counter1++;
157          editBox2.SetContents("%u\n", counter1);
158          return true;
159       }
160    };
161    Button button1
162    {
163       this, text = "Up Me", size = { 95, 21 }, position = { 88, 24 };
164
165       bool NotifyClicked(Button button, int x, int y, Modifiers mods)
166       {
167          counter0++;
168          editBox1.SetContents("%u\n", counter0);
169          return true;
170       }
171    };
172
173    bool OnCreate(void)
174    {
175       Window windows[] = {button5, button6, button4, editBox1, editBox2, button3, button2, button1};
176       astfield.Initialize(sizeof(windows)/sizeof(*windows), windows);
177       app.timerResolution = 100;
178       return true;
179    }
180 }
181
182 Form2 form2 {};