2 CLASS(XonoticCharmap) EXTENDS(Image)
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, draw, void(entity))
11 ATTRIB(XonoticCharmap, controlledTextbox, entity, NULL)
12 ATTRIB(XonoticCharmap, image, string, SKINGFX_CHARMAP)
13 ATTRIB(XonoticCharmap, image2, string, SKINGFX_CHARMAP_SELECTED)
14 ATTRIB(XonoticCharmap, focusable, float, 1)
15 ATTRIB(XonoticCharmap, previouslySelectedCharacterCell, float, -1)
16 ATTRIB(XonoticCharmap, selectedCharacterCell, float, 0)
17 ATTRIB(XonoticCharmap, mouseSelectedCharacterCell, float, -1)
18 ENDCLASS(XonoticCharmap)
19 entity makeXonoticCharmap(entity theTextbox);
23 entity makeXonoticCharmap(entity theTextbox)
26 me = spawnXonoticCharmap();
27 me.configureXonoticCharmap(me, theTextbox);
31 string CharMap_CellToChar(float c)
33 if (cvar("utf8_enable")) {
35 return chr(0xE000 + 127);
37 return chr(0xE000 + c);
39 return chr(0xE000 + c + 96);
50 void XonoticCharmap_configureXonoticCharmap(entity me, entity theTextbox)
52 me.controlledTextbox = theTextbox;
53 me.configureImage(me, me.image);
56 float XonoticCharmap_mouseMove(entity me, vector coords)
59 x = floor(coords_x * 16);
60 y = floor(coords_y * 10);
61 if(x < 0 || y < 0 || x >= 16 || y >= 10)
63 me.mouseSelectedCharacterCell = -1;
67 if(c != me.mouseSelectedCharacterCell)
68 me.mouseSelectedCharacterCell = me.selectedCharacterCell = c;
71 float XonoticCharmap_mouseDrag(entity me, vector coords)
73 return me.mouseMove(me, coords);
75 float XonoticCharmap_mousePress(entity me, vector coords)
77 me.mouseMove(me, coords);
78 if(me.mouseSelectedCharacterCell >= 0)
81 me.previouslySelectedCharacterCell = me.selectedCharacterCell;
85 float XonoticCharmap_mouseRelease(entity me, vector coords)
89 me.mouseMove(me, coords);
90 if(me.selectedCharacterCell == me.previouslySelectedCharacterCell)
91 me.controlledTextbox.enterText(me.controlledTextbox, CharMap_CellToChar(me.selectedCharacterCell));
95 float XonoticCharmap_keyDown(entity me, float key, float ascii, float shift)
101 me.selectedCharacterCell = mod(me.selectedCharacterCell + 159, 160);
104 case K_KP_RIGHTARROW:
105 me.selectedCharacterCell = mod(me.selectedCharacterCell + 1, 160);
109 me.selectedCharacterCell = mod(me.selectedCharacterCell + 144, 160);
113 me.selectedCharacterCell = mod(me.selectedCharacterCell + 16, 160);
117 me.selectedCharacterCell = 0;
121 me.selectedCharacterCell = 159;
128 me.controlledTextbox.enterText(me.controlledTextbox, CharMap_CellToChar(me.selectedCharacterCell));
131 return me.controlledTextbox.keyDown(me.controlledTextbox, key, ascii, shift);
134 void XonoticCharmap_focusLeave(entity me)
136 me.controlledTextbox.saveCvars(me.controlledTextbox);
138 void XonoticCharmap_draw(entity me)
142 if(!me.pressed || (me.selectedCharacterCell == me.previouslySelectedCharacterCell))
145 c = eX * (mod(me.selectedCharacterCell, 16) / 16.0);
146 c += eY * (floor(me.selectedCharacterCell / 16.0) / 10.0);
147 draw_Picture(c, me.image2, '0.0625 0.1 0', '1 1 1', 1);
150 SUPER(XonoticCharmap).draw(me);