5 CLASS(XonoticPicker, Item)
6 METHOD(XonoticPicker, configureXonoticPicker, void(entity));
7 METHOD(XonoticPicker, mousePress, float(entity, vector));
8 METHOD(XonoticPicker, mouseRelease, float(entity, vector));
9 METHOD(XonoticPicker, mouseMove, float(entity, vector));
10 METHOD(XonoticPicker, mouseDrag, float(entity, vector));
11 METHOD(XonoticPicker, keyDown, float(entity, float, float, float));
12 METHOD(XonoticPicker, draw, void(entity));
13 ATTRIB(XonoticPicker, focusable, float, 1)
14 ATTRIB(XonoticPicker, disabled, float, 0)
15 ATTRIB(XonoticPicker, alpha, float, 1)
16 ATTRIB(XonoticPicker, disabledAlpha, float, SKINALPHA_DISABLED)
18 ATTRIB(XonoticPicker, rows, float, 3)
19 ATTRIB(XonoticPicker, columns, float, 2)
21 METHOD(XonoticPicker, moveFocus, void(entity, vector, vector));
22 METHOD(XonoticPicker, cellSelect, void(entity, vector));
23 METHOD(XonoticPicker, cellDraw, void(entity, vector, vector));
24 METHOD(XonoticPicker, cellIsValid, bool(entity, vector));
25 ATTRIB(XonoticPicker, realCellSize, vector, '0 0 0')
26 ATTRIB(XonoticPicker, selectedCell, vector, '-1 -1 0')
27 ATTRIB(XonoticPicker, focusedCell, vector, '-1 -1 0')
28 ATTRIB(XonoticPicker, focusedCellAlpha, float, 0)
29 ATTRIB(XonoticPicker, focusedCellTime, float, 0)
30 ATTRIB(XonoticPicker, pressedCell, vector, '-1 -1 0')
31 ENDCLASS(XonoticPicker)
32 entity makeXonoticPicker();
37 entity makeXonoticPicker()
40 me = NEW(XonoticPicker);
41 me.configureXonoticPicker(me);
45 void XonoticPicker_configureXonoticPicker(entity me)
47 me.realCellSize = eX / me.columns + eY / me.rows;
50 float XonoticPicker_mouseMove(entity me, vector coords)
52 vector prevFocusedCell = me.focusedCell;
53 me.focusedCell_x = floor(coords.x * me.columns);
54 me.focusedCell_y = floor(coords.y * me.rows);
56 if(me.focusedCell.x < 0 || me.focusedCell.y < 0 ||
57 me.focusedCell.x >= me.columns || me.focusedCell.y >= me.rows)
59 me.focusedCell = '-1 -1 0';
63 if(me.focusedCell != prevFocusedCell)
64 me.focusedCellAlpha = SKINALPHA_LISTBOX_FOCUSED;
69 float XonoticPicker_mouseDrag(entity me, vector coords)
71 return me.mouseMove(me, coords);
74 float XonoticPicker_mousePress(entity me, vector coords)
76 me.mouseMove(me, coords);
78 if(me.focusedCell.x >= 0)
81 me.pressedCell = me.focusedCell;
87 float XonoticPicker_mouseRelease(entity me, vector coords)
92 me.mouseMove(me, coords);
94 if(me.focusedCell == me.pressedCell)
95 me.cellSelect(me, me.focusedCell);
101 float XonoticPicker_keyDown(entity me, float key, float ascii, float shift)
107 // lower left cell then left arrow to select the last valid cell
108 me.focusedCell = eY * (me.rows - 1);
111 me.moveFocus(me, me.focusedCell, '-1 0 0');
115 // upper right cell then right arrow to select the first valid cell
116 me.focusedCell = eX * (me.columns - 1);
118 case K_KP_RIGHTARROW:
119 me.moveFocus(me, me.focusedCell, '1 0 0');
123 me.moveFocus(me, me.focusedCell, '0 -1 0');
127 me.moveFocus(me, me.focusedCell, '0 1 0');
133 me.cellSelect(me, me.focusedCell);
139 void XonoticPicker_moveFocus(entity me, vector initialCell, vector step)
141 me.focusedCell_x = mod(me.focusedCell.x + step.x + me.columns, me.columns);
142 me.focusedCell_y = mod(me.focusedCell.y + step.y + me.rows, me.rows);
144 if(me.focusedCell != initialCell) // Recursion break
145 if(!me.cellIsValid(me, me.focusedCell))
146 me.moveFocus(me, initialCell, step);
148 me.focusedCellAlpha = SKINALPHA_LISTBOX_FOCUSED;
151 void XonoticPicker_cellSelect(entity me, vector cell)
153 me.selectedCell = cell;
156 bool XonoticPicker_cellIsValid(entity me, vector cell)
161 void XonoticPicker_cellDraw(entity me, vector cell, vector cellPos)
165 void XonoticPicker_draw(entity me)
169 me.focusable = !me.disabled;
173 draw_alpha *= me.disabledAlpha;
175 vector cell, cellPos;
179 for(cell_y = 0; cell.y < me.rows; ++cell.y)
181 cellPos_y = mod(cell.y, me.rows) / me.rows;
182 for(cell_x = 0; cell.x < me.columns; ++cell.x)
184 if(!me.cellIsValid(me, cell))
187 cellPos_x = mod(cell.x, me.columns) / me.columns;
189 if(cell == me.selectedCell)
190 draw_Fill(cellPos, me.realCellSize, SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED);
191 else if(cell == me.focusedCell && me.focused)
193 if(!me.pressed || me.focusedCell == me.pressedCell)
195 me.focusedCellAlpha = getFadedAlpha(me.focusedCellAlpha, SKINALPHA_LISTBOX_FOCUSED, SKINFADEALPHA_LISTBOX_FOCUSED);
196 draw_Fill(cellPos, me.realCellSize, SKINCOLOR_LISTBOX_FOCUSED, me.focusedCellAlpha);
200 me.cellDraw(me, cell, cellPos);
206 SUPER(XonoticPicker).draw(me);