4 CLASS(XonoticPicker, Item)
5 METHOD(XonoticPicker, configureXonoticPicker, void(entity))
6 METHOD(XonoticPicker, mousePress, float(entity, vector))
7 METHOD(XonoticPicker, mouseRelease, float(entity, vector))
8 METHOD(XonoticPicker, mouseMove, float(entity, vector))
9 METHOD(XonoticPicker, mouseDrag, float(entity, vector))
10 METHOD(XonoticPicker, keyDown, float(entity, float, float, float))
11 METHOD(XonoticPicker, draw, void(entity))
12 ATTRIB(XonoticPicker, focusable, float, 1)
13 ATTRIB(XonoticPicker, disabled, float, 0)
14 ATTRIB(XonoticPicker, alpha, float, 1)
15 ATTRIB(XonoticPicker, disabledAlpha, float, SKINALPHA_DISABLED)
17 ATTRIB(XonoticPicker, rows, float, 3)
18 ATTRIB(XonoticPicker, columns, float, 2)
20 METHOD(XonoticPicker, moveFocus, void(entity, vector, vector))
21 METHOD(XonoticPicker, cellSelect, void(entity, vector))
22 METHOD(XonoticPicker, cellDraw, void(entity, vector, vector))
23 METHOD(XonoticPicker, cellIsValid, bool(entity, vector))
24 ATTRIB(XonoticPicker, realCellSize, vector, '0 0 0')
25 ATTRIB(XonoticPicker, selectedCell, vector, '-1 -1 0')
26 ATTRIB(XonoticPicker, focusedCell, vector, '-1 -1 0')
27 ATTRIB(XonoticPicker, focusedCellAlpha, float, 0)
28 ATTRIB(XonoticPicker, focusedCellTime, float, 0)
29 ATTRIB(XonoticPicker, pressedCell, vector, '-1 -1 0')
30 ENDCLASS(XonoticPicker)
31 entity makeXonoticPicker();
36 entity makeXonoticPicker()
39 me = NEW(XonoticPicker);
40 me.configureXonoticPicker(me);
44 void XonoticPicker_configureXonoticPicker(entity me)
46 me.realCellSize = eX / me.columns + eY / me.rows;
49 float XonoticPicker_mouseMove(entity me, vector coords)
51 vector prevFocusedCell = me.focusedCell;
52 me.focusedCell_x = floor(coords.x * me.columns);
53 me.focusedCell_y = floor(coords.y * me.rows);
55 if(me.focusedCell.x < 0 || me.focusedCell.y < 0 ||
56 me.focusedCell.x >= me.columns || me.focusedCell.y >= me.rows)
58 me.focusedCell = '-1 -1 0';
62 if(me.focusedCell != prevFocusedCell)
63 me.focusedCellAlpha = SKINALPHA_LISTBOX_FOCUSED;
68 float XonoticPicker_mouseDrag(entity me, vector coords)
70 return me.mouseMove(me, coords);
73 float XonoticPicker_mousePress(entity me, vector coords)
75 me.mouseMove(me, coords);
77 if(me.focusedCell.x >= 0)
80 me.pressedCell = me.focusedCell;
86 float XonoticPicker_mouseRelease(entity me, vector coords)
91 me.mouseMove(me, coords);
93 if(me.focusedCell == me.pressedCell)
94 me.cellSelect(me, me.focusedCell);
100 float XonoticPicker_keyDown(entity me, float key, float ascii, float shift)
106 me.moveFocus(me, me.focusedCell, '-1 0 0');
109 case K_KP_RIGHTARROW:
110 me.moveFocus(me, me.focusedCell, '1 0 0');
114 me.moveFocus(me, me.focusedCell, '0 -1 0');
118 me.moveFocus(me, me.focusedCell, '0 1 0');
122 me.focusedCell = '0 0 0';
126 me.focusedCell_x = me.columns - 1;
127 me.focusedCell_y = me.rows - 1;
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);
149 void XonoticPicker_cellSelect(entity me, vector cell)
151 me.selectedCell = cell;
154 bool XonoticPicker_cellIsValid(entity me, vector cell)
159 void XonoticPicker_cellDraw(entity me, vector cell, vector cellPos)
163 void XonoticPicker_draw(entity me)
167 me.focusable = !me.disabled;
171 draw_alpha *= me.disabledAlpha;
173 vector cell, cellPos;
177 for(cell_y = 0; cell.y < me.rows; ++cell.y)
179 cellPos_y = mod(cell.y, me.rows) / me.rows;
180 for(cell_x = 0; cell.x < me.columns; ++cell.x)
182 if(!me.cellIsValid(me, cell))
185 cellPos_x = mod(cell.x, me.columns) / me.columns;
187 if(cell == me.selectedCell)
188 draw_Fill(cellPos, me.realCellSize, SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED);
189 else if(cell == me.focusedCell && me.focused)
191 if(!me.pressed || me.focusedCell == me.pressedCell)
193 me.focusedCellAlpha = getFadedAlpha(me.focusedCellAlpha, SKINALPHA_LISTBOX_FOCUSED, SKINFADEALPHA_LISTBOX_FOCUSED);
194 draw_Fill(cellPos, me.realCellSize, SKINCOLOR_LISTBOX_FOCUSED, me.focusedCellAlpha);
198 me.cellDraw(me, cell, cellPos);
204 SUPER(XonoticPicker).draw(me);