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
29 string charmapRow0[CHARMAP_COLS];
30 string charmapRow1[CHARMAP_COLS];
31 string charmapRow2[CHARMAP_COLS];
32 string charmapRow3[CHARMAP_COLS];
33 string charmapRow4[CHARMAP_COLS];
34 string charmapRow5[CHARMAP_COLS];
35 string charmapRow6[CHARMAP_COLS];
36 string charmapRow7[CHARMAP_COLS];
37 string charmapRow8[CHARMAP_COLS];
38 string charmapRow9[CHARMAP_COLS];
40 void charmap_initializeRows()
42 if (charmapRow0[0] != "")
45 charmapRow0[0] = strzone(chr(0x2190));
46 charmapRow0[1] = strzone(chr(0x2191));
47 charmapRow0[2] = strzone(chr(0x2192));
48 charmapRow0[3] = strzone(chr(0x2193));
49 charmapRow0[4] = strzone(chr(0x25c0));
50 charmapRow0[5] = strzone(chr(0x25b2));
51 charmapRow0[6] = strzone(chr(0x25b6));
52 charmapRow0[7] = strzone(chr(0x25bc));
53 charmapRow0[8] = strzone(chr(0x25e3));
54 charmapRow0[9] = strzone(chr(0x25e4));
55 charmapRow0[10] = strzone(chr(0x25e5));
56 charmapRow0[11] = strzone(chr(0x25e2));
57 charmapRow0[12] = strzone(chr(0x2770));
58 charmapRow0[13] = strzone(chr(0x2771));
60 charmapRow1[0] = strzone(chr(0x25A0));
61 charmapRow1[1] = strzone(chr(0x25AC));
62 charmapRow1[2] = strzone(chr(0x25AE));
63 charmapRow1[3] = strzone(chr(0x25B0));
64 charmapRow1[4] = strzone(chr(0x25C6));
65 charmapRow1[5] = strzone(chr(0x25CF));
66 charmapRow1[6] = strzone(chr(0x2605));
67 charmapRow1[7] = strzone(chr(0x2764));
68 charmapRow1[8] = strzone(chr(0x1F52B));
69 charmapRow1[9] = strzone(chr(0x2316));
70 charmapRow1[10] = strzone(chr(0x2747));
71 charmapRow1[11] = strzone(chr(0x2748));
72 charmapRow1[12] = strzone(chr(0x2772));
73 charmapRow1[13] = strzone(chr(0x2773));
75 charmapRow2[0] = strzone(chr(0x1F47D));
76 charmapRow2[1] = strzone(chr(0x2620));
77 charmapRow2[2] = strzone(chr(0x2622));
78 charmapRow2[3] = strzone(chr(0x2623));
79 charmapRow2[4] = strzone(chr(0x2699));
80 charmapRow2[5] = strzone(chr(0x269B));
81 charmapRow2[6] = strzone(chr(0x26A0));
82 charmapRow2[7] = strzone(chr(0x26A1));
83 charmapRow2[8] = strzone(chr(0x274C));
84 charmapRow2[9] = strzone(chr(0x1F680));
85 charmapRow2[10] = strzone(chr(0x1F30C));
86 charmapRow2[11] = strzone(chr(0x1F30D));
87 charmapRow2[12] = strzone(chr(0x1F30E));
88 charmapRow2[13] = strzone(chr(0x1F30F));
90 charmapRow3[0] = strzone(chr(0x1F601));
91 charmapRow3[1] = strzone(chr(0x1F603));
92 charmapRow3[2] = strzone(chr(0x1F604));
93 charmapRow3[3] = strzone(chr(0x1F606));
94 charmapRow3[4] = strzone(chr(0x1F607));
95 charmapRow3[5] = strzone(chr(0x1F608));
96 charmapRow3[6] = strzone(chr(0x1F609));
97 charmapRow3[7] = strzone(chr(0x1F60A));
98 charmapRow3[8] = strzone(chr(0x1F60E));
99 charmapRow3[9] = strzone(chr(0x1F610));
100 charmapRow3[10] = strzone(chr(0x1F612));
101 charmapRow3[11] = strzone(chr(0x1F618));
102 charmapRow3[12] = string_null;
103 charmapRow3[13] = string_null;
105 charmapRow4[0] = strzone(chr(0x1F615));
106 charmapRow4[1] = strzone(chr(0x1F61B));
107 charmapRow4[2] = strzone(chr(0x1F61D));
108 charmapRow4[3] = strzone(chr(0x1F61E));
109 charmapRow4[4] = strzone(chr(0x1F61F));
110 charmapRow4[5] = strzone(chr(0x1F620));
111 charmapRow4[6] = strzone(chr(0x1F623));
112 charmapRow4[7] = strzone(chr(0x1F62D));
113 charmapRow4[8] = strzone(chr(0x1F62E));
114 charmapRow4[9] = strzone(chr(0x1F632));
115 charmapRow4[10] = strzone(chr(0x1F635));
116 charmapRow4[11] = strzone(chr(0x1F634));
117 charmapRow4[12] = string_null;
118 charmapRow4[13] = string_null;
120 // Legacy characters:
123 for(i = 0; i < 14; ++i)
124 charmapRow5[i] = strzone(chr(0xE0E1 + i));
126 for(i = 0; i < 12; ++i)
127 charmapRow6[i] = strzone(chr(0xE0EF + i));
128 charmapRow6[12] = strzone(chr(0xE010));
129 charmapRow6[13] = strzone(chr(0xE011));
131 for(i = 0; i < 10; ++i)
132 charmapRow7[i] = strzone(chr(0xE0B0 + i));
133 charmapRow7[10] = strzone(chr(0xE0A1));
134 charmapRow7[11] = strzone(chr(0xE0BF));
135 charmapRow7[12] = strzone(chr(0xE0A6));
136 charmapRow7[13] = strzone(chr(0xE0A5));
138 for(i = 0; i < 14; ++i)
139 charmapRow8[i] = strzone(chr(0xE0C1 + i));
141 for(i = 0; i < 12; ++i)
142 charmapRow9[i] = strzone(chr(0xE0CF + i));
143 charmapRow9[12] = strzone(chr(0xE05B));
144 charmapRow9[13] = strzone(chr(0xE05D));
147 string charmap_cellToChar(vector cell)
149 if(!cvar("utf8_enable"))
152 if(cell_x >= CHARMAP_COLS)
157 case 0: return charmapRow0[cell_x];
158 case 1: return charmapRow1[cell_x];
159 case 2: return charmapRow2[cell_x];
160 case 3: return charmapRow3[cell_x];
161 case 4: return charmapRow4[cell_x];
162 case 5: return charmapRow5[cell_x];
163 case 6: return charmapRow6[cell_x];
164 case 7: return charmapRow7[cell_x];
165 case 8: return charmapRow8[cell_x];
166 case 9: return charmapRow9[cell_x];
171 entity makeXonoticCharmap(entity controlledInputBox)
173 charmap_initializeRows();
176 me = spawnXonoticCharmap();
177 me.configureXonoticCharmap(me, controlledInputBox);
181 void XonoticCharmap_configureXonoticCharmap(entity me, entity controlledInputBox)
183 me.inputBox = controlledInputBox;
184 me.realCellSize = eX / CHARMAP_COLS + eY / CHARMAP_ROWS;
187 void XonoticCharmap_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
189 SUPER(XonoticCharmap).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
191 if((me.realCellSize_x * absSize_x) > (me.realCellSize_y * absSize_y))
193 me.realFontSize_x = me.realCellSize_y * absSize_y / absSize_x;
194 me.realFontSize_y = me.realCellSize_y;
198 me.realFontSize_x = me.realCellSize_x;
199 me.realFontSize_y = me.realCellSize_x * absSize_x / absSize_y;
203 float XonoticCharmap_mouseMove(entity me, vector coords)
205 me.focusedCell_x = floor(coords_x * CHARMAP_COLS);
206 me.focusedCell_y = floor(coords_y * CHARMAP_ROWS);
208 if(me.focusedCell_x < 0 || me.focusedCell_y < 0 ||
209 me.focusedCell_x >= CHARMAP_COLS || me.focusedCell_y >= CHARMAP_ROWS)
211 me.focusedCell = '-1 -1 0';
218 float XonoticCharmap_mouseDrag(entity me, vector coords)
220 return me.mouseMove(me, coords);
223 float XonoticCharmap_mousePress(entity me, vector coords)
225 me.mouseMove(me, coords);
227 if(me.focusedCell_x >= 0)
230 me.previouslyFocusedCell = me.focusedCell;
236 float XonoticCharmap_mouseRelease(entity me, vector coords)
241 me.mouseMove(me, coords);
243 if(me.focusedCell == me.previouslyFocusedCell)
250 float XonoticCharmap_keyDown(entity me, float key, float ascii, float shift)
256 me.moveFocus(me, me.focusedCell, '-1 0 0');
259 case K_KP_RIGHTARROW:
260 me.moveFocus(me, me.focusedCell, '1 0 0');
264 me.moveFocus(me, me.focusedCell, '0 -1 0');
268 me.moveFocus(me, me.focusedCell, '0 1 0');
272 me.focusedCell = '0 0 0';
276 me.focusedCell_x = CHARMAP_COLS - 1;
277 me.focusedCell_y = CHARMAP_ROWS - 1;
286 return me.inputBox.keyDown(me.inputBox, key, ascii, shift);
290 void XonoticCharmap_moveFocus(entity me, vector initialCell, vector step)
292 me.focusedCell_x = mod(me.focusedCell_x + step_x + CHARMAP_COLS, CHARMAP_COLS);
293 me.focusedCell_y = mod(me.focusedCell_y + step_y + CHARMAP_ROWS, CHARMAP_ROWS);
295 if(me.focusedCell != initialCell) // Recursion break
296 if(charmap_cellToChar(me.focusedCell) == "")
297 me.moveFocus(me, initialCell, step);
300 void XonoticCharmap_enterChar(entity me)
302 string character = charmap_cellToChar(me.focusedCell);
304 me.inputBox.enterText(me.inputBox, character);
307 void XonoticCharmap_focusLeave(entity me)
309 me.inputBox.saveCvars(me.inputBox);
312 void XonoticCharmap_draw(entity me)
315 vector cell, cellPos, charPos;
320 for(cell_y = 0; cell_y < CHARMAP_ROWS; ++cell_y)
322 charPos_y = cell_y / CHARMAP_ROWS + (me.realCellSize_y - me.realFontSize_y) / 2;
323 for(cell_x = 0; cell_x < CHARMAP_COLS; ++cell_x)
325 character = charmap_cellToChar(cell);
331 if(cell == me.focusedCell && me.focused)
333 if(!me.pressed || me.focusedCell == me.previouslyFocusedCell)
335 cellPos_x = mod(me.focusedCell_x, CHARMAP_COLS) / CHARMAP_COLS;
336 cellPos_y = mod(me.focusedCell_y, CHARMAP_ROWS) / CHARMAP_ROWS;
337 draw_Fill(cellPos, me.realCellSize, SKINCOLOR_CHARMAP_FOCUS, SKINALPHA_CHARMAP_FOCUS);
342 charPos_x = cell_x / CHARMAP_COLS + me.realCellSize_x / 2;
343 draw_CenterText(charPos, character, me.realFontSize, SKINCOLOR_CHARMAP_CHAR, SKINALPHA_CHARMAP_CHAR, 0);