5 return me.scrollPos != me.scrollPosTarget;
12 if (me.itemHeight == 1)
14 me.needScrollToItem = i;
18 i =
bound(0, i, me.nItems - 1);
22 if (i < me.getFirstFullyVisibleItemAtScrollPos(me, me.scrollPos))
25 me.scrollPosTarget = me.getItemStart(me, i);
27 else if (i > me.getLastFullyVisibleItemAtScrollPos(me, me.scrollPos))
30 if (i == me.nItems - 1) me.scrollPosTarget = me.getTotalHeight(me) - 1;
31 else me.scrollPosTarget = me.getItemStart(me, i + 1) - 1;
37 i =
bound(0, i, me.nItems - 1);
38 me.scrollToItem(me, i);
43 SUPER(
ListBox).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
44 me.controlWidth = me.scrollbarWidth / absSize.x;
48 me.scrollbarWidth = theScrollbarWidth;
49 me.itemHeight = theItemHeight;
54 return me.nItems * me.itemHeight;
58 return floor(pos / me.itemHeight);
62 return me.itemHeight * i;
71 return me.getItemAtPos(me, pos + 0.999) - 1;
75 return me.getItemAtPos(me, pos + 0.001) + 1;
81 me.scrollPosTarget =
max(me.scrollPosTarget - 0.5, 0);
85 me.scrollPosTarget =
min(me.scrollPosTarget + 0.5,
max(0, me.getTotalHeight(me) - 1));
89 if (me.selectionDoesntMatter)
91 me.scrollPosTarget =
max(me.scrollPosTarget - 0.5, 0);
95 float i = me.selectedItem;
96 float a = me.getItemHeight(me, i);
101 a += me.getItemHeight(me, i);
104 me.setSelected(me, i + 1);
108 if (me.selectionDoesntMatter)
110 me.scrollPosTarget =
min(me.scrollPosTarget + 0.5, me.nItems * me.itemHeight - 1);
114 float i = me.selectedItem;
115 float a = me.getItemHeight(me, i);
119 if (i >= me.nItems)
break;
120 a += me.getItemHeight(me, i);
123 me.setSelected(me, i - 1);
127 if (me.selectionDoesntMatter)
129 me.scrollPosTarget =
max(me.scrollPosTarget - me.itemHeight, 0);
133 me.setSelected(me, me.selectedItem - 1);
137 if (me.selectionDoesntMatter)
139 me.scrollPosTarget =
min(me.scrollPosTarget + me.itemHeight, me.nItems * me.itemHeight - 1);
143 me.setSelected(me, me.selectedItem + 1);
147 me.setSelected(me, 0);
151 me.setSelected(me, me.nItems - 1);
161 me.mouseMoveOffset = -1;
162 if (pos_x < 0)
return 0;
163 if (pos_y < 0)
return 0;
164 if (pos_x >= 1)
return 0;
165 if (pos_y >= 1)
return 0;
166 if (pos_x < 1 - me.controlWidth)
168 me.mouseMoveOffset = pos.y;
172 me.setFocusedItem(me, -1);
173 me.mouseMoveOffset = -1;
180 me.updateControlTopBottom(me);
181 me.dragScrollPos = pos;
185 if (pos.x < 1 - me.controlWidth - me.tolerance.x * me.controlWidth) hit = 0;
186 if (pos.y < 0 - me.tolerance.y) hit = 0;
187 if (pos.x >= 1 + me.tolerance.x * me.controlWidth) hit = 0;
188 if (pos.y >= 1 + me.tolerance.y) hit = 0;
193 d = (pos.y - me.pressOffset) / (1 - (me.controlBottom - me.controlTop)) * (me.getTotalHeight(me) - 1);
194 me.scrollPosTarget = me.previousValue + d;
198 me.scrollPosTarget = me.previousValue;
200 me.scrollPosTarget =
min(me.scrollPosTarget, me.getTotalHeight(me) - 1);
201 me.scrollPosTarget =
max(me.scrollPosTarget, 0);
203 else if (me.pressed == 2)
205 me.setSelected(me, me.getItemAtPos(me, me.scrollPos + pos.y));
206 me.setFocusedItem(me, me.selectedItem);
207 me.mouseMoveOffset = -1;
213 if (pos.x < 0)
return false;
214 if (pos.y < 0)
return false;
215 if (pos.x >= 1)
return false;
216 if (pos.y >= 1)
return false;
217 this.dragScrollPos = pos;
218 this.updateControlTopBottom(
this);
219 if (pos.x >= 1 -
this.controlWidth)
222 if (pos.y <
this.controlTop)
225 this.scrollPosTarget =
max(this.scrollPosTarget - 1, 0);
227 else if (pos.y >
this.controlBottom)
230 this.scrollPosTarget =
min(this.scrollPosTarget + 1, this.getTotalHeight(
this) - 1);
235 this.pressOffset = pos.y;
236 this.previousValue = this.scrollPos;
244 this.setSelected(
this, this.getItemAtPos(
this, this.scrollPos + pos.y));
245 this.setFocusedItem(
this, this.selectedItem);
251 float focusedItem_save = me.focusedItem;
252 me.focusedItem = (item < me.nItems) ? item : -1;
253 if (focusedItem_save != me.focusedItem)
255 me.focusedItemChangeNotify(me);
256 if (me.focusedItem >= 0) me.focusedItemAlpha = SKINALPHA_LISTBOX_FOCUSED;
266 else if (me.pressed == 2)
271 me.setSelected(me, me.getItemAtPos(me, me.scrollPos + pos.y));
272 me.setFocusedItem(me, me.selectedItem);
276 vector where =
globalToBox(pos,
eY * (me.getItemStart(me, me.selectedItem) - me.scrollPos),
eX * (1 - me.controlWidth) +
eY * me.getItemHeight(me, me.selectedItem));
278 if ((me.selectedItem == me.lastClickedItem) && (
time < me.lastClickedTime + 0.3)) me.doubleClickListBoxItem(me, me.selectedItem, where);
279 else me.clickListBoxItem(me, me.selectedItem, where);
281 me.lastClickedItem = me.selectedItem;
282 me.lastClickedTime =
time;
294 me.setFocusedItem(me, -1);
295 me.mouseMoveOffset = -1;
301 if (me.getTotalHeight(me) <= 1)
305 me.controlBottom = 1;
311 me.scrollPos =
min(me.scrollPos, me.getTotalHeight(me) - 1);
313 me.scrollPos =
max(me.scrollPos, 0);
315 me.controlTop =
max(0, me.scrollPos / me.getTotalHeight(me));
316 me.controlBottom =
min((me.scrollPos + 1) / me.getTotalHeight(me), 1);
319 minfactor = 2 * me.controlWidth / me.size.y * me.size.x;
320 f = me.controlBottom - me.controlTop;
327 f = (minfactor - 1) / (f - 1);
328 me.controlTop = me.controlTop * f + 0 * (1 - f);
329 me.controlBottom = me.controlBottom * f + 1 * (1 - f);
333 AUTOCVAR(menu_scroll_averaging_time,
float, 0.16,
"smooth scroll averaging time");
335 AUTOCVAR(menu_scroll_averaging_time_pressed,
float, 0.06,
"smooth scroll averaging time when dragging the scrollbar");
338 vector fillSize =
'0 0 0';
341 if (me.mouseMoveOffset != -1) me.setFocusedItem(me, me.getItemAtPos(me, me.scrollPos + me.mouseMoveOffset));
343 if (me.needScrollToItem >= 0)
345 me.scrollToItem(me, me.needScrollToItem);
346 me.needScrollToItem = -1;
348 if (me.scrollPos != me.scrollPosTarget)
350 float averaging_time = (me.pressed == 1)
351 ? autocvar_menu_scroll_averaging_time_pressed
352 : autocvar_menu_scroll_averaging_time;
354 float f = averaging_time ?
exp(-
frametime / averaging_time) : 0;
355 me.scrollPos = me.scrollPos * f + me.scrollPosTarget * (1 - f);
356 if (
fabs(me.scrollPos - me.scrollPosTarget) < 0.001) me.scrollPos = me.scrollPosTarget;
359 if (me.pressed == 2) me.mouseDrag(me, me.dragScrollPos);
360 me.updateControlTopBottom(me);
361 fillSize.x = (1 - me.controlWidth);
362 if (me.alphaBG)
draw_Fill(
'0 0 0',
'0 1 0' + fillSize, me.colorBG, me.alphaBG);
366 if (me.getTotalHeight(me) > 1)
369 o =
eX * (1 - me.controlWidth) +
eY * me.controlTop;
370 s =
eX * me.controlWidth +
eY * (me.controlBottom - me.controlTop);
380 int i = me.getItemAtPos(me, me.scrollPos);
381 float y = me.getItemStart(me, i) - me.scrollPos;
382 for ( ; i < me.nItems && y < 1; ++i)
385 vector relSize =
eX * (1 - me.controlWidth) +
eY * me.getItemHeight(me, i);
388 me.drawListBoxItem(me, i, absSize, (me.selectedItem == i), (me.focusedItem == i));
413 draw_Text(
'0 0 0', sprintf(_(
"Item %d"), i),
eX * (8 / absSize.x) +
eY * (8 / absSize.y), (isSelected ?
'0 1 0' :
'1 1 1'), 1, 0);
void ListBox_clickListBoxItem(entity me, float i, vector where)
float ListBox_keyDown(entity me, float key, float ascii, float shift)
void ListBox_scrollToItem(entity me, int i)
void ListBox_updateControlTopBottom(entity me)
void ListBox_drawListBoxItem(entity me, int i, vector absSize, bool isSelected, bool isFocused)
float ListBox_getLastFullyVisibleItemAtScrollPos(entity me, float pos)
float ListBox_mouseDrag(entity me, vector pos)
bool ListBox_isScrolling(entity me)
#define METHOD(cname, name, prototype)
void ListBox_focusedItemChangeNotify(entity me)
void ListBox_configureListBox(entity me, float theScrollbarWidth, float theItemHeight)
float ListBox_getItemAtPos(entity me, float pos)
void ListBox_setFocusedItem(entity me, int item)
void ListBox_draw(entity me)
float ListBox_getTotalHeight(entity me)
float ListBox_getItemHeight(entity me, float i)
float ListBox_mouseMove(entity me, vector pos)
void ListBox_setSelected(entity me, float i)
float ListBox_mouseRelease(entity me, vector pos)
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
void ListBox_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
void ListBox_focusLeave(entity me)
void ListBox_doubleClickListBoxItem(entity me, float i, vector where)
vector(float skel, float bonenum) _skel_get_boneabs_hidden
float ListBox_getItemStart(entity me, float i)
float ListBox_getFirstFullyVisibleItemAtScrollPos(entity me, float pos)
AUTOCVAR(menu_scroll_averaging_time, float, 0.16, "smooth scroll averaging time")