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
349
350
351
352
353
354
355
356
357
358
|
#include "stdafx.h"
#include "ScrolledSelectionList.h"
#include "Button.h"
#include "Tesselator.h"
#include "Textures.h"
#include "..\Minecraft.World\System.h"
ScrolledSelectionList::ScrolledSelectionList(Minecraft *minecraft, int width, int height, int y0, int y1, int itemHeight)
{
this->minecraft = minecraft;
this->width = width;
this->height = height;
this->y0 = y0;
this->y1 = y1;
this->itemHeight = itemHeight;
this->x0 = 0;
this->x1 = width;
// 4J Stu - Smoe default initialisers
upId = 0;
downId = 0;
yDrag = 0.0f;
yDragScale = 0.0f;
yo = 0.0f;
lastSelection = 0;
lastSelectionTime = 0;
renderSelection = false;
_renderHeader = false;
headerHeight = 0;
//End
}
void ScrolledSelectionList::setRenderSelection(bool renderSelection)
{
this->renderSelection = renderSelection;
}
void ScrolledSelectionList::setRenderHeader(bool renderHeader, int headerHeight)
{
this->_renderHeader = renderHeader;
this->headerHeight = headerHeight;
if (!_renderHeader)
{
this->headerHeight = 0;
}
}
int ScrolledSelectionList::getMaxPosition()
{
return getNumberOfItems() * itemHeight + headerHeight;
}
void ScrolledSelectionList::renderHeader(int x, int y, Tesselator *t)
{
}
void ScrolledSelectionList::clickedHeader(int headerMouseX, int headerMouseY)
{
}
void ScrolledSelectionList::renderDecorations(int mouseX, int mouseY)
{
}
int ScrolledSelectionList::getItemAtPosition(int x, int y)
{
int x0 = width / 2 - (92 + 16 + 2);
int x1 = width / 2 + (92 + 16 + 2);
int clickSlotPos = (y - y0 - headerHeight + static_cast<int>(yo) - 4);
int slot = clickSlotPos / itemHeight;
if (x >= x0 && x <= x1 && slot >= 0 && clickSlotPos >= 0 && slot < getNumberOfItems())
{
return slot;
}
return -1;
}
void ScrolledSelectionList::init(vector<Button *> *buttons, int upButtonId, int downButtonId)
{
this->upId = upButtonId;
this->downId = downButtonId;
}
void ScrolledSelectionList::capYPosition()
{
int max = getMaxPosition() - (y1 - y0 - 4);
if (max < 0) max /= 2;
if (yo < 0) yo = 0;
if (yo > max) yo = static_cast<float>(max);
}
void ScrolledSelectionList::buttonClicked(Button *button)
{
if (!button->active) return;
if (button->id == upId)
{
yo -= (itemHeight * 2) / 3;
yDrag = DRAG_OUTSIDE;
capYPosition();
} else if (button->id == downId)
{
yo += (itemHeight * 2) / 3;
yDrag = DRAG_OUTSIDE;
capYPosition();
}
}
void ScrolledSelectionList::render(int xm, int ym, float a)
{
// 4J Unused
#if 0
renderBackground();
int itemCount = getNumberOfItems();
int xx0 = width / 2 + 124;
int xx1 = xx0 + 6;
if (Mouse::isButtonDown(0))
{
if (yDrag == NO_DRAG)
{
bool doDrag = true;
if (ym >= y0 && ym <= y1)
{
int x0 = width / 2 - (92 + 16 + 2);
int x1 = width / 2 + (92 + 16 + 2);
int clickSlotPos = (ym - y0 - headerHeight + (int) yo - 4);
int slot = clickSlotPos / itemHeight;
if (xm >= x0 && xm <= x1 && slot >= 0 && clickSlotPos >= 0 && slot < itemCount)
{
bool doubleClick = slot == lastSelection && (System::currentTimeMillis() - lastSelectionTime) < 250;
selectItem(slot, doubleClick);
lastSelection = slot;
lastSelectionTime = System::currentTimeMillis();
}
else if (xm >= x0 && xm <= x1 && clickSlotPos < 0)
{
clickedHeader(xm - x0, ym - y0 + (int) yo - 4);
doDrag = false;
}
if (xm >= xx0 && xm <= xx1)
{
yDragScale = -1;
int max = getMaxPosition() - (y1 - y0 - 4);
if (max < 1) max = 1;
int barHeight = (int) ((y1 - y0) * (y1 - y0) / (float) getMaxPosition());
if (barHeight < 32) barHeight = 32;
if (barHeight > (y1 - y0 - 8)) barHeight = (y1 - y0 - 8);
// int yp = yo * (y1 - y0 - barHeight) / max + y0;
// if (yp < y0) yp = y0;
yDragScale /= (y1 - y0 - barHeight) / (float) max;
}
else
{
yDragScale = 1;
}
if (doDrag)
{
yDrag = (float)ym;
}
else
{
yDrag = DRAG_OUTSIDE;
}
}
else
{
yDrag = DRAG_OUTSIDE;
}
}
else if (yDrag >= 0)
{
yo -= (ym - yDrag) * yDragScale;
yDrag = (float)ym;
}
}
else
{
yDrag = NO_DRAG;
}
capYPosition();
glDisable(GL_LIGHTING);
glDisable(GL_FOG);
Tesselator *t = Tesselator::getInstance();
glBindTexture(GL_TEXTURE_2D, minecraft->textures->loadTexture(L"/gui/background.png"));
glColor4f(1.0f, 1, 1, 1);
float s = 32;
t->begin();
t->color(0x202020);
t->vertexUV((float)(x0), (float)( y1), (float)( 0), (float)( x0 / s), (float)( (y1 + (int) yo) / s));
t->vertexUV((float)(x1), (float)( y1), (float)( 0), (float)( x1 / s), (float)( (y1 + (int) yo) / s));
t->vertexUV((float)(x1), (float)( y0), (float)( 0), (float)( x1 / s), (float)( (y0 + (int) yo) / s));
t->vertexUV((float)(x0), (float)( y0), (float)( 0), (float)( x0 / s), (float)( (y0 + (int) yo) / s));
t->end();
int rowX = width / 2 - 92 - 16;
int rowBaseY = y0 + 4 - (int) yo;
if (_renderHeader)
{
renderHeader(rowX, rowBaseY, t);
}
for (int i = 0; i < itemCount; i++)
{
int y = rowBaseY + (i) * itemHeight + headerHeight;
int h = itemHeight - 4;
if (y > y1 || (y + h) < y0)
{
continue;
}
if (renderSelection && isSelectedItem(i))
{
int x0 = width / 2 - (92 + 16 + 2);
int x1 = width / 2 + (92 + 16 + 2);
glColor4f(1, 1, 1, 1);
glDisable(GL_TEXTURE_2D);
t->begin();
t->color(0x808080);
t->vertexUV((float)(x0), (float)( y + h + 2), (float)( 0), (float)( 0), (float)( 1));
t->vertexUV((float)(x1), (float)( y + h + 2), (float)( 0), (float)( 1), (float)( 1));
t->vertexUV((float)(x1), (float)( y - 2), (float)( 0), (float)( 1), (float)( 0));
t->vertexUV((float)(x0), (float)( y - 2), (float)( 0), (float)( 0), (float)( 0));
t->color(0x000000);
t->vertexUV((float)(x0 + 1), (float)( y + h + 1), (float)( 0), (float)( 0), (float)( 1));
t->vertexUV((float)(x1 - 1), (float)( y + h + 1), (float)( 0), (float)( 1), (float)( 1));
t->vertexUV((float)(x1 - 1), (float)( y - 1), (float)( 0), (float)( 1), (float)( 0));
t->vertexUV((float)(x0 + 1), (float)( y - 1), (float)( 0), (float)( 0), (float)( 0));
t->end();
glEnable(GL_TEXTURE_2D);
}
renderItem(i, rowX, y, h, t);
}
glDisable(GL_DEPTH_TEST);
int d = 4;
renderHoleBackground(0, y0, 255, 255);
renderHoleBackground(y1, height, 255, 255);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDisable(GL_ALPHA_TEST);
glShadeModel(GL_SMOOTH);
glDisable(GL_TEXTURE_2D);
t->begin();
t->color(0x000000, 0);
t->vertexUV((float)(x0), (float)( y0 + d), (float)( 0), (float)( 0), (float)( 1));
t->vertexUV((float)(x1), (float)( y0 + d), (float)( 0), (float)( 1), (float)( 1));
t->color(0x000000, 255);
t->vertexUV((float)(x1), (float)( y0), (float)( 0), (float)( 1), (float)( 0));
t->vertexUV((float)(x0), (float)( y0), (float)( 0), (float)( 0), (float)( 0));
t->end();
t->begin();
t->color(0x000000, 255);
t->vertexUV((float)(x0), (float)( y1), (float)( 0), (float)( 0), (float)( 1));
t->vertexUV((float)(x1), (float)( y1), (float)( 0), (float)( 1), (float)( 1));
t->color(0x000000, 0);
t->vertexUV((float)(x1), (float)( y1 - d), (float)( 0), (float)( 1), (float)( 0));
t->vertexUV((float)(x0), (float)( y1 - d), (float)( 0), (float)( 0), (float)( 0));
t->end();
{
int max = getMaxPosition() - (y1 - y0 - 4);
if (max > 0)
{
int barHeight = (int) (y1 - y0) * (y1 - y0) / (getMaxPosition());
if (barHeight < 32) barHeight = 32;
if (barHeight > (y1 - y0 - 8)) barHeight = (y1 - y0 - 8);
int yp = (int) yo * (y1 - y0 - barHeight) / max + y0;
if (yp < y0) yp = y0;
t->begin();
t->color(0x000000, 255);
t->vertexUV((float)(xx0), (float)( y1), (float)( 0), (float)( 0), (float)( 1));
t->vertexUV((float)(xx1), (float)( y1), (float)( 0), (float)( 1), (float)( 1));
t->vertexUV((float)(xx1), (float)( y0), (float)( 0), (float)( 1), (float)( 0));
t->vertexUV((float)(xx0), (float)( y0), (float)( 0), (float)( 0), (float)( 0));
t->end();
t->begin();
t->color(0x808080, 255);
t->vertexUV((float)(xx0), (float)( yp + barHeight), (float)( 0), (float)( 0), (float)( 1));
t->vertexUV((float)(xx1), (float)( yp + barHeight), (float)( 0), (float)( 1), (float)( 1));
t->vertexUV((float)(xx1), (float)( yp), (float)( 0), (float)( 1), (float)( 0));
t->vertexUV((float)(xx0), (float)( yp), (float)( 0), (float)( 0), (float)( 0));
t->end();
t->begin();
t->color(0xc0c0c0, 255);
t->vertexUV((float)(xx0), (float)( yp + barHeight - 1), (float)( 0), (float)( 0), (float)( 1));
t->vertexUV((float)(xx1 - 1), (float)( yp + barHeight - 1), (float)( 0), (float)( 1), (float)( 1));
t->vertexUV((float)(xx1 - 1), (float)( yp), (float)( 0), (float)( 1), (float)( 0));
t->vertexUV((float)(xx0), (float)( yp), (float)( 0), (float)( 0), (float)( 0));
t->end();
}
}
renderDecorations(xm, ym);
glEnable(GL_TEXTURE_2D);
glShadeModel(GL_FLAT);
glEnable(GL_ALPHA_TEST);
glDisable(GL_BLEND);
#endif
}
void ScrolledSelectionList::renderHoleBackground(int y0, int y1, int a0, int a1)
{
// 4J Unused
#if 0
Tesselator *t = Tesselator::getInstance();
glBindTexture(GL_TEXTURE_2D, minecraft->textures->loadTexture(L"/gui/background.png"));
glColor4f(1.0f, 1, 1, 1);
float s = 32;
t->begin();
t->color(0x404040, a1);
t->vertexUV((float)(0), (float)( y1), (float)( 0), (float)( 0), (float)( y1 / s));
t->vertexUV((float)(width), (float)( y1), (float)( 0), (float)( width / s), (float)( y1 / s));
t->color(0x404040, a0);
t->vertexUV((float)(width), (float)( y0), (float)( 0), (float)( width / s), (float)( y0 / s));
t->vertexUV((float)(0), (float)( y0), (float)( 0), (float)( 0), (float)( y0 / s));
t->end();
#endif
}
|