-
Notifications
You must be signed in to change notification settings - Fork 0
/
userEntry.cpp
187 lines (168 loc) · 4.09 KB
/
userEntry.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
#include "userEntry.h"
#include "label.h"
#include <windows.h>
#include <GL/GL.h>
#include <cmath>
#include <fstream>
#include <cstdlib>
bool ue_txtBoxChanged(char *s)
{
//char * p=s;
//std::ofstream oFile("entry_txtchange.txt",std::ios::app);
//oFile << s << ' ';
//only allows numbers and '.' and '-'
if (*s == '-') s++;
while(*s)
{
//oFile << *s <<'(';
if ((*s != '.' ) && ((*s<48)||(*s>57)) ) *s = 0;
//oFile << *s << ")";
s++;
}
//oFile << " :: " << p << '\n';
//oFile.close();
return 0;
}
userEntry::userEntry()
{
active = false;
onChange = nullptr;
isFloat = false;
ptr = 0;
entryBox.location.x = 200;
entryBox.location.y = 260;
entryBox.size.x = 240;
entryBox.size.y = 25;
entryBox.l_name.alignment = ALIGN_RIGHT;
entryBox.l_name.txtSize = (float) entryBox.size.y;
entryBox.l_name.setString("Value: ");
entryBox.useLabelName = true;
entryBox.l_name.location.x = entryBox.location.x;
entryBox.l_name.location.y = entryBox.location.y;
entryBox.setOnChange(ue_txtBoxChanged);
l_ok.location.x = 229;
l_ok.location.y = 232;
l_ok.txtSize = 20;
l_ok.alignment = ALIGN_LEFT;
l_ok.setString(" OK ");
l_ok.maxSize = 100;
l_cancel.location.x = 332;
l_cancel.location.y = 232;
l_cancel.txtSize = 20;
l_cancel.alignment = ALIGN_LEFT;
l_cancel.setString(" CANCEL ");
l_cancel.maxSize = 100;
}
void userEntry::setActive()
{
active = true;
animState = 1;
onChange = nullptr;
}
void userEntry::draw()
{
// set blendmode
// draw bg
// draw textBox
// draw buttons
//std::ofstream oFile("entry_draw.txt",std::ios::app);
//oFile << entryBox.string << '\n';
if ((animState>=1) && (animState <10)) animState++;
else if ((animState<=-1) && (animState >-10)) animState++;
//calc drawrect
vec2D nTL;
vec2D nBR;
float per = ((float)animState) / 10;
if (per < 0) per = -per;
nTL.x = (int) ( (1-per) * initialTL.x);
nTL.y = (int) ((per * 480) + (1-per) * initialTL.y);
nBR.x = (int) ((per * 640) + (1-per) * initialBR.x);
nBR.y = (int) ( (1-per) * initialBR.y);
//oFile << "1: " << (int)animState << " TL: (" <<nTL.x<<','<<nTL.y<<") BR: ("<<nBR.x<<','<<nBR.y<<")\n";
glColor4f(0.4f,0.4f,0.4f,0.75f);
glBegin(GL_QUADS);
glVertex2f((GLfloat)nTL.x,(GLfloat)nTL.y);
glVertex2f((GLfloat)nTL.x,(GLfloat)nBR.y);
glVertex2f((GLfloat)nBR.x,(GLfloat)nBR.y);
glVertex2f((GLfloat)nBR.x,(GLfloat)nTL.y);
glEnd();
if (abs(animState) == 10)
{
entryBox.draw();
//draw txtBox / buttons, buttons can be fake
glColor4f(0.35f,0.35f,0.5f,0.8f);
//OK
glBegin(GL_QUADS);
glVertex2f(205,255);
glVertex2f(205,230);
glVertex2f(315,230);
glVertex2f(315,255);
glEnd();
//CANCEL
glBegin(GL_QUADS);
glVertex2f(325,255);
glVertex2f(325,230);
glVertex2f(435,230);
glVertex2f(435,255);
glEnd();
l_ok.draw();
l_cancel.draw();
}
if (abs(animState) == 1) active = false;
//oFile.close();
}
int userEntry::eventHandler(UINT message,WPARAM key,int mousex,int mousey)
{
if (animState == 10) // fully open only
{
if (message == WM_LBUTTONDOWN)
{
// check if in bounds of buttons
if (mousey >= 230 && mousey <= 255)
{
if (mousex >= 205 && mousex <= 315)
{
updateSlider();
beginShutDown();
}
else if (mousex >= 325 && mousex <= 435)
{
beginShutDown();
}
}
}
if (message == WM_KEYDOWN)
{
if (key == VK_ESCAPE) beginShutDown();
else if (key == VK_RETURN)
{
updateSlider();
beginShutDown();
}
else
{
entryBox.eventHandler(message,key,mousex,mousey);
}
}
}
return 0;
}
void userEntry::beginShutDown()
{
animState = -9; // start close
memset (entryBox.string,0,512);
}
void userEntry::updateSlider()
{
int value;
if (isFloat)
{
value = (int) (atof(entryBox.string) * 10000);
}
else
{
value = atoi(entryBox.string);
}
if (ptr) ptr->setValue_nochange(value);
if (onChange) onChange(value);
}