-
Notifications
You must be signed in to change notification settings - Fork 0
/
aaaaaabstract.cpp
348 lines (258 loc) · 6.6 KB
/
aaaaaabstract.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
#include "TXLib.h"
#include <math.h>
#define COORDx1 50
#define COORDy1 50
#define COORDx2 1000
#define COORDy2 550
#define SCALING 20
//to do:
//ïåðåïèñàòü êëàññ ñèñòåìû è êíîïêè
//ñòðêìï
//åäèíûé ñ÷åò÷èê
/*
ñèñòåìà
çàâèñèò îò ðàçìåðîâ îêíà
íà÷àëî êîîðäèíàò â öåíòðå
ðèñîâàíèå ñåòêè
íîðìàëüíûå ôóíêöèè ðèñîâàíèÿ ñèñòåìû ïîñëå ñòèðàíèÿ
êíîïêà
ïîëå - óêàçàòåëü íà ñèñòåìó
êîîðäèíàòû - òîëüêî öåíòð êíîïêè
ïàðàìåòð ñêåéë (êíîïêè)
ïîâòîðíîå íàæàòèå ñêåéëèò ôóíêöèþ
*/
typedef double (*func) (double);
void createSys (struct CoordSys);
void drawLine (double xscale, double yscale, double xvalues[10], double yvalues[10], CoordSys Coord);
struct CoordSys
{
CoordSys (int ax, int bx, int ay, int by) :
x0 (ax),
x1 (bx),
y0 (ay),
y1 (by) {}
CoordSys () :
x0 (COORDx1),
x1 (COORDx2),
y0 (COORDy1),
y1 (COORDy2) {}
int x0, y0;
int x1, y1;
double scalex;
double clearall (double a);
};
class KindaAbstract_button
{
protected:
double x0, y0;
double x1, y1;
int r, g, b;
public:
COLORREF buttonColor = RGB (r, g, b);
double getx()
{
return x0;
}
const char* text;
func fct;
RECT area = {x0, y0, x1, y1};
virtual bool if_triggered()
{
if (txGetPixel (txMouseX(), txMouseY()) == buttonColor)
{
return true;
}
else
{
return false;
}
}
virtual void drawButton()
{
txSetFillColor (buttonColor);
txSetColor (buttonColor);
txLine (area.left, area.top, area.right, area.bottom);
txLine (area.left, area.bottom, area.right, area.top);
txSetColor (TX_WHITE);
txTextOut (x0 + 30, y0 + 30, text);
}
void drawFunc (double arg)
{
double scale = SCALING;
double delta = 0.05;
if (fct (arg) == fct (arg + delta))
{
fct (arg);
return;
}
txBegin();
while (arg < COORDx2 - COORDx1)
{
if ( (COORDy2 - scale * fct (arg)) > 100)
{
txLine (COORDx1 + scale * arg, COORDy2 - scale * fct (arg), COORDx1 + scale * (arg + delta), COORDy2 - scale * fct (arg + delta));
}
arg += delta;
}
txEnd();
}
KindaAbstract_button (double x0, double y0, double x1, double y1,
func fct_, const char* text1, int r_, int g_, int b_) :
x0 (x0),
y0 (y0),
x1 (x1),
y1 (y1),
fct (fct_),
text (text1),
r (r_),
g (g_),
b (b_) {}
};
class RoundButton: public KindaAbstract_button
{
public:
RoundButton (double x0, double y0, double x1, double y1,
func fct_, const char* text1, int r_, int g_, int b_) :
KindaAbstract_button (x0, y0, x1, y1, fct_, text1, r_, g_, b_) {}
virtual void drawButton() override
{
txSetFillColor (buttonColor);
txSetColor (buttonColor);
txCircle (x0, y0, y1 - y0);
txSetColor (TX_WHITE);
txTextOut (x0 + 30, y0 + 30, text);
}
};
class EllipseButton: public KindaAbstract_button
{
public:
EllipseButton (double x0, double y0, double x1, double y1,
func fct_, const char* text1, int r_, int g_, int b_) :
KindaAbstract_button (x0, y0, x1, y1, fct_, text1, r_, g_, b_) {}
virtual void drawButton() override
{
txSetFillColor (buttonColor);
txSetColor (buttonColor);
txEllipse (area.left, area.bottom, area.right, area.top);
txSetColor (TX_WHITE);
txTextOut (x0 + 30, y0 + 30, text);
}
};
class RectButton: public KindaAbstract_button
{
public:
RectButton (double x0, double y0, double x1, double y1,
func fct_, const char* text1, int r_, int g_, int b_) :
KindaAbstract_button (x0, y0, x1, y1, fct_, text1, r_, g_, b_) {}
virtual void drawButton() override
{
txSetFillColor (buttonColor);
txSetColor (buttonColor);
txRectangle (x0, y0, x1, y1);
txSetColor (TX_WHITE);
txTextOut (x0 + 30, y0 + 30, text);
}
};
int count_ = 0;
const int max_count = 10;
class Manager
{
public:
KindaAbstract_button* Buttons [max_count];
void if_pressed()
{
for (int i = 0; (*Buttons[i]).getx() != 0; i++)
{
double x = 0;
if ( (*Buttons[i]).if_triggered())
{
txSetColor (TX_LIGHTBLUE);
(*Buttons[i]).drawFunc (x);
}
}
}
void drawButtons()
{
for (int i = 0; (*Buttons[i]).getx() != 0; i++)
{
(*Buttons[i]).drawButton();
}
}
/*double clear_reset (double nothing)
{
txSetFillColor (TX_BLACK);
txClear();
txSetColor (TX_LIGHTGREEN);
txLine (COORDx1, COORDy1, COORDx1, COORDy2);
txLine (COORDx1, COORDy2, COORDx2, COORDy2);
void drawButtons();
return 1;
}*/
void new_button (KindaAbstract_button* button)
{
if (count_ < max_count)
{
Buttons[count_] = button;
count_++;
}
};
Manager(){}
~Manager()
{
for (int i = count_; i > 0; i--)
{
delete Buttons[i];
}
}
};
void drawButtons (KindaAbstract_button Buttons_[])
{
for (int i = 0; Buttons_[i].getx() != 0; i++)
{
Buttons_[i].drawButton();
}
}
double clear_reset (double nothing)
{
txSetFillColor (TX_BLACK);
txClear();
txSetColor (TX_LIGHTGREEN);
txLine (COORDx1, COORDy1, COORDx1, COORDy2);
txLine (COORDx1, COORDy2, COORDx2, COORDy2);
return 1;
}
void createSys (CoordSys Coord)
{
txLine (Coord.x0, Coord.y0, Coord.x0, Coord.y1);
txLine (Coord.x0, Coord.y1, Coord.x1, Coord.y1);
}
double change_color(double nothing)
{
txSetColor (TX_LIGHTRED);
}
int main()
{
txCreateWindow (1000, 600);
txSetColor (TX_LIGHTGREEN);
CoordSys Sys1;
//CoordSys Sys2 (550, 50, 950, 550);
createSys (Sys1);
//createSys (Sys2);
txSetColor (TX_LIGHTBLUE);
Manager easy;
easy.new_button (new RoundButton (30 , 30, 210 , 60, sin , "ñèíóñ" , 255, 0 , 0 ));
easy.new_button (new EllipseButton (220 , 30, 420 , 60, cos , "êîñèíóñ", 0 , 255, 0 ));
easy.new_button (new RectButton (430 , 30, 630 , 60, tan , "òàíãåíñ", 0 , 0 , 255));
easy.new_button (new RectButton (430 , 330, 630 , 360, change_color , "color", 0 , 0 , 255));
easy.new_button (new KindaAbstract_button (860 , 30, 960 , 60, clear_reset, "óäîëè" , 255, 255, 0 ));
easy.new_button (new KindaAbstract_button (0 , 0 , 0 , 0 , 0 , "NULL" , 0 , 0 , 0 ));
easy.drawButtons();
while (txMouseButtons() != 3)
{
if (txMouseButtons() == 1)
{
easy.if_pressed();
}
}
return 0;
}