5 entity makeXonoticPicker()
8 me = NEW(XonoticPicker);
9 me.configureXonoticPicker(me);
13 void XonoticPicker_configureXonoticPicker(entity me)
15 me.realCellSize = eX / me.columns + eY / me.rows;
18 float XonoticPicker_mouseMove(entity me, vector coords)
20 vector prevFocusedCell = me.focusedCell;
21 me.focusedCell_x = floor(coords.x * me.columns);
22 me.focusedCell_y = floor(coords.y * me.rows);
24 if(me.focusedCell.x < 0 || me.focusedCell.y < 0 ||
25 me.focusedCell.x >= me.columns || me.focusedCell.y >= me.rows)
27 me.focusedCell = '-1 -1 0';
31 if(me.focusedCell != prevFocusedCell)
32 me.focusedCellAlpha = SKINALPHA_LISTBOX_FOCUSED;
37 float XonoticPicker_mouseDrag(entity me, vector coords)
39 return me.mouseMove(me, coords);
42 METHOD(XonoticPicker, mousePress, bool(XonoticPicker this, vector pos))
44 this.mouseMove(this, pos);
46 if(this.focusedCell.x >= 0)
49 this.pressedCell = this.focusedCell;
55 float XonoticPicker_mouseRelease(entity me, vector coords)
60 me.mouseMove(me, coords);
62 if(me.focusedCell == me.pressedCell)
63 me.cellSelect(me, me.focusedCell);
69 float XonoticPicker_keyDown(entity me, float key, float ascii, float shift)
75 // lower left cell then left arrow to select the last valid cell
76 me.focusedCell = eY * (me.rows - 1);
79 me.moveFocus(me, me.focusedCell, '-1 0 0');
83 // upper right cell then right arrow to select the first valid cell
84 me.focusedCell = eX * (me.columns - 1);
87 me.moveFocus(me, me.focusedCell, '1 0 0');
91 me.moveFocus(me, me.focusedCell, '0 -1 0');
95 me.moveFocus(me, me.focusedCell, '0 1 0');
101 me.cellSelect(me, me.focusedCell);
107 void XonoticPicker_moveFocus(entity me, vector initialCell, vector step)
109 me.focusedCell_x = mod(me.focusedCell.x + step.x + me.columns, me.columns);
110 me.focusedCell_y = mod(me.focusedCell.y + step.y + me.rows, me.rows);
112 if(me.focusedCell != initialCell) // Recursion break
113 if(!me.cellIsValid(me, me.focusedCell))
114 me.moveFocus(me, initialCell, step);
116 me.focusedCellAlpha = SKINALPHA_LISTBOX_FOCUSED;
119 void XonoticPicker_cellSelect(entity me, vector cell)
121 me.selectedCell = cell;
124 bool XonoticPicker_cellIsValid(entity me, vector cell)
129 void XonoticPicker_cellDraw(entity me, vector cell, vector cellPos)
133 void XonoticPicker_draw(entity me)
137 me.focusable = !me.disabled;
141 draw_alpha *= me.disabledAlpha;
143 vector cell, cellPos;
147 for(cell_y = 0; cell.y < me.rows; ++cell.y)
149 cellPos_y = mod(cell.y, me.rows) / me.rows;
150 for(cell_x = 0; cell.x < me.columns; ++cell.x)
152 if(!me.cellIsValid(me, cell))
155 cellPos_x = mod(cell.x, me.columns) / me.columns;
157 if(cell == me.selectedCell)
158 draw_Fill(cellPos, me.realCellSize, SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED);
159 else if(cell == me.focusedCell && me.focused)
161 if(!me.pressed || me.focusedCell == me.pressedCell)
163 me.focusedCellAlpha = getFadedAlpha(me.focusedCellAlpha, SKINALPHA_LISTBOX_FOCUSED, SKINFADEALPHA_LISTBOX_FOCUSED);
164 draw_Fill(cellPos, me.realCellSize, SKINCOLOR_LISTBOX_FOCUSED, me.focusedCellAlpha);
168 me.cellDraw(me, cell, cellPos);
174 SUPER(XonoticPicker).draw(me);