2 CLASS(XonoticCharmap) EXTENDS(Item)
3 METHOD(XonoticCharmap, configureXonoticCharmap, void(entity, entity))
4 METHOD(XonoticCharmap, mousePress, float(entity, vector))
5 METHOD(XonoticCharmap, mouseRelease, float(entity, vector))
6 METHOD(XonoticCharmap, mouseMove, float(entity, vector))
7 METHOD(XonoticCharmap, mouseDrag, float(entity, vector))
8 METHOD(XonoticCharmap, keyDown, float(entity, float, float, float))
9 METHOD(XonoticCharmap, focusLeave, void(entity))
10 METHOD(XonoticCharmap, resizeNotify, void(entity, vector, vector, vector, vector))
11 METHOD(XonoticCharmap, draw, void(entity))
12 ATTRIB(XonoticCharmap, focusable, float, 1)
14 METHOD(XonoticCharmap, moveFocus, void(entity, vector, vector))
15 METHOD(XonoticCharmap, enterChar, void(entity))
16 ATTRIB(XonoticCharmap, inputBox, entity, NULL)
17 ATTRIB(XonoticCharmap, realFontSize, vector, '0 0 0')
18 ATTRIB(XonoticCharmap, realCellSize, vector, '0 0 0')
19 ATTRIB(XonoticCharmap, focusedCell, vector, '-1 -1 0')
20 ATTRIB(XonoticCharmap, previouslyFocusedCell, vector, '-1 -1 0')
21 ENDCLASS(XonoticCharmap)
22 entity makeXonoticCharmap(entity controlledInputBox);
27 #define CHARMAP_COLS 14
28 #define CHARMAP_ROWS 10
36 "\xEE\x83\xA1\xEE\x83\xA2\xEE\x83\xA3\xEE\x83\xA4\xEE\x83\xA5\xEE\x83\xA6\xEE\x83\xA7"
37 "\xEE\x83\xA8\xEE\x83\xA9\xEE\x83\xAA\xEE\x83\xAB\xEE\x83\xAC\xEE\x83\xAD\xEE\x83\xAE"
38 "\xEE\x83\xAF\xEE\x83\xB0\xEE\x83\xB1\xEE\x83\xB2\xEE\x83\xB3\xEE\x83\xB4\xEE\x83\xB5"
39 "\xEE\x83\xB6\xEE\x83\xB7\xEE\x83\xB8\xEE\x83\xB9\xEE\x83\xBA\xEE\x80\x90\xEE\x80\x91"
40 "\xEE\x82\xB0\xEE\x82\xB1\xEE\x82\xB2\xEE\x82\xB3\xEE\x82\xB4\xEE\x82\xB5\xEE\x82\xB6"
41 "\xEE\x82\xB7\xEE\x82\xB8\xEE\x82\xB9\xEE\x82\xA1\xEE\x82\xBF\xEE\x82\xA6\xEE\x82\xA5"
42 "\xEE\x83\x81\xEE\x83\x82\xEE\x83\x83\xEE\x83\x84\xEE\x83\x85\xEE\x83\x86\xEE\x83\x87"
43 "\xEE\x83\x88\xEE\x83\x89\xEE\x83\x8A\xEE\x83\x8B\xEE\x83\x8C\xEE\x83\x8D\xEE\x83\x8E"
44 "\xEE\x83\x8F\xEE\x83\x90\xEE\x83\x91\xEE\x83\x92\xEE\x83\x93\xEE\x83\x94\xEE\x83\x95"
45 "\xEE\x83\x96\xEE\x83\x97\xEE\x83\x98\xEE\x83\x99\xEE\x83\x9A\xEE\x81\x9B\xEE\x81\x9D";
47 string charmap_cellToChar(vector cell)
49 string character = substring(CHARMAP, cell_y * CHARMAP_COLS + cell_x, 1);
57 entity makeXonoticCharmap(entity controlledInputBox)
60 me = spawnXonoticCharmap();
61 me.configureXonoticCharmap(me, controlledInputBox);
65 void XonoticCharmap_configureXonoticCharmap(entity me, entity controlledInputBox)
67 me.inputBox = controlledInputBox;
68 me.realCellSize = eX / CHARMAP_COLS + eY / CHARMAP_ROWS;
71 void XonoticCharmap_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
73 SUPER(XonoticCharmap).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
75 float maxFontWidth = SKINFONTSIZE_NORMAL / absSize_x;
76 float maxFontHeight = SKINFONTSIZE_NORMAL / absSize_y;
78 if((me.realCellSize_x * absSize_x) > (me.realCellSize_y * absSize_y))
80 me.realFontSize_x = me.realCellSize_y * absSize_y / absSize_x;
81 me.realFontSize_y = me.realCellSize_y;
85 me.realFontSize_x = me.realCellSize_x;
86 me.realFontSize_y = me.realCellSize_x * absSize_x / absSize_y;
89 if(me.realFontSize_x > maxFontWidth || me.realFontSize_y > maxFontHeight)
90 me.realFontSize = eX * maxFontWidth + eY * maxFontHeight;
93 float XonoticCharmap_mouseMove(entity me, vector coords)
95 me.focusedCell_x = floor(coords_x * CHARMAP_COLS);
96 me.focusedCell_y = floor(coords_y * CHARMAP_ROWS);
98 if(me.focusedCell_x < 0 || me.focusedCell_y < 0 ||
99 me.focusedCell_x >= CHARMAP_COLS || me.focusedCell_y >= CHARMAP_ROWS)
101 me.focusedCell = '-1 -1 0';
108 float XonoticCharmap_mouseDrag(entity me, vector coords)
110 return me.mouseMove(me, coords);
113 float XonoticCharmap_mousePress(entity me, vector coords)
115 me.mouseMove(me, coords);
117 if(me.focusedCell_x >= 0)
120 me.previouslyFocusedCell = me.focusedCell;
126 float XonoticCharmap_mouseRelease(entity me, vector coords)
131 me.mouseMove(me, coords);
133 if(me.focusedCell == me.previouslyFocusedCell)
140 float XonoticCharmap_keyDown(entity me, float key, float ascii, float shift)
146 me.moveFocus(me, me.focusedCell, '-1 0 0');
149 case K_KP_RIGHTARROW:
150 me.moveFocus(me, me.focusedCell, '1 0 0');
154 me.moveFocus(me, me.focusedCell, '0 -1 0');
158 me.moveFocus(me, me.focusedCell, '0 1 0');
162 me.focusedCell = '0 0 0';
166 me.focusedCell_x = CHARMAP_COLS - 1;
167 me.focusedCell_y = CHARMAP_ROWS - 1;
176 return me.inputBox.keyDown(me.inputBox, key, ascii, shift);
180 void XonoticCharmap_moveFocus(entity me, vector initialCell, vector step)
182 me.focusedCell_x = mod(me.focusedCell_x + step_x + CHARMAP_COLS, CHARMAP_COLS);
183 me.focusedCell_y = mod(me.focusedCell_y + step_y + CHARMAP_ROWS, CHARMAP_ROWS);
185 if(me.focusedCell != initialCell) // Recursion break
186 if(charmap_cellToChar(me.focusedCell) == "")
187 me.moveFocus(me, initialCell, step);
190 void XonoticCharmap_enterChar(entity me)
192 string character = charmap_cellToChar(me.focusedCell);
194 me.inputBox.enterText(me.inputBox, character);
197 void XonoticCharmap_focusLeave(entity me)
199 me.inputBox.saveCvars(me.inputBox);
202 void XonoticCharmap_draw(entity me)
205 vector cell, cellPos, charPos;
210 float CHAR_OFFSET_X = me.realCellSize_x / 2;
211 float CHAR_OFFSET_Y = (me.realCellSize_y - me.realFontSize_y) / 2;
213 for(cell_y = 0; cell_y < CHARMAP_ROWS; ++cell_y)
215 charPos_y = cell_y / CHARMAP_ROWS + CHAR_OFFSET_Y;
216 for(cell_x = 0; cell_x < CHARMAP_COLS; ++cell_x)
218 character = charmap_cellToChar(cell);
224 if(cell == me.focusedCell && me.focused)
226 if(!me.pressed || me.focusedCell == me.previouslyFocusedCell)
228 cellPos_x = mod(me.focusedCell_x, CHARMAP_COLS) / CHARMAP_COLS;
229 cellPos_y = mod(me.focusedCell_y, CHARMAP_ROWS) / CHARMAP_ROWS;
230 draw_Fill(cellPos, me.realCellSize, SKINCOLOR_CHARMAP_FOCUS, SKINALPHA_CHARMAP_FOCUS);
235 charPos_x = cell_x / CHARMAP_COLS + CHAR_OFFSET_X;
236 draw_CenterText(charPos, character, me.realFontSize, SKINCOLOR_CHARMAP_CHAR, SKINALPHA_CHARMAP_CHAR, 0);