]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Use a string instead of arrays for the charmap
authorSeverin Meyer <sev.ch@web.de>
Thu, 25 Dec 2014 03:23:40 +0000 (04:23 +0100)
committerSeverin Meyer <sev.ch@web.de>
Thu, 25 Dec 2014 03:23:40 +0000 (04:23 +0100)
qcsrc/menu/xonotic/charmap.c

index d65519c356303d614b72bade55027c771275acfd..b8b307cd23163e521fbfee8fdcc487723a237a93 100644 (file)
@@ -26,152 +26,31 @@ entity makeXonoticCharmap(entity controlledInputBox);
 
 #define CHARMAP_COLS 14
 #define CHARMAP_ROWS 10
-string charmapRow0[CHARMAP_COLS];
-string charmapRow1[CHARMAP_COLS];
-string charmapRow2[CHARMAP_COLS];
-string charmapRow3[CHARMAP_COLS];
-string charmapRow4[CHARMAP_COLS];
-string charmapRow5[CHARMAP_COLS];
-string charmapRow6[CHARMAP_COLS];
-string charmapRow7[CHARMAP_COLS];
-string charmapRow8[CHARMAP_COLS];
-string charmapRow9[CHARMAP_COLS];
-
-void charmap_initializeRows()
-{
-       if (charmapRow0[0] != "")
-               return;
-
-       charmapRow0[0]  = strzone(chr(0x2190));
-       charmapRow0[1]  = strzone(chr(0x2191));
-       charmapRow0[2]  = strzone(chr(0x2192));
-       charmapRow0[3]  = strzone(chr(0x2193));
-       charmapRow0[4]  = strzone(chr(0x25c0));
-       charmapRow0[5]  = strzone(chr(0x25b2));
-       charmapRow0[6]  = strzone(chr(0x25b6));
-       charmapRow0[7]  = strzone(chr(0x25bc));
-       charmapRow0[8]  = strzone(chr(0x25e3));
-       charmapRow0[9]  = strzone(chr(0x25e4));
-       charmapRow0[10] = strzone(chr(0x25e5));
-       charmapRow0[11] = strzone(chr(0x25e2));
-       charmapRow0[12] = strzone(chr(0x2770));
-       charmapRow0[13] = strzone(chr(0x2771));
-
-       charmapRow1[0]  = strzone(chr(0x25A0));
-       charmapRow1[1]  = strzone(chr(0x25AC));
-       charmapRow1[2]  = strzone(chr(0x25AE));
-       charmapRow1[3]  = strzone(chr(0x25B0));
-       charmapRow1[4]  = strzone(chr(0x25C6));
-       charmapRow1[5]  = strzone(chr(0x25CF));
-       charmapRow1[6]  = strzone(chr(0x2605));
-       charmapRow1[7]  = strzone(chr(0x2764));
-       charmapRow1[8]  = strzone(chr(0x1F52B));
-       charmapRow1[9]  = strzone(chr(0x2316));
-       charmapRow1[10] = strzone(chr(0x2747));
-       charmapRow1[11] = strzone(chr(0x2748));
-       charmapRow1[12] = strzone(chr(0x2772));
-       charmapRow1[13] = strzone(chr(0x2773));
-
-       charmapRow2[0]  = strzone(chr(0x1F47D));
-       charmapRow2[1]  = strzone(chr(0x2620));
-       charmapRow2[2]  = strzone(chr(0x2622));
-       charmapRow2[3]  = strzone(chr(0x2623));
-       charmapRow2[4]  = strzone(chr(0x2699));
-       charmapRow2[5]  = strzone(chr(0x269B));
-       charmapRow2[6]  = strzone(chr(0x26A0));
-       charmapRow2[7]  = strzone(chr(0x26A1));
-       charmapRow2[8]  = strzone(chr(0x274C));
-       charmapRow2[9]  = strzone(chr(0x1F680));
-       charmapRow2[10] = strzone(chr(0x1F30C));
-       charmapRow2[11] = strzone(chr(0x1F30D));
-       charmapRow2[12] = strzone(chr(0x1F30E));
-       charmapRow2[13] = strzone(chr(0x1F30F));
-
-       charmapRow3[0]  = strzone(chr(0x1F601));
-       charmapRow3[1]  = strzone(chr(0x1F603));
-       charmapRow3[2]  = strzone(chr(0x1F604));
-       charmapRow3[3]  = strzone(chr(0x1F606));
-       charmapRow3[4]  = strzone(chr(0x1F607));
-       charmapRow3[5]  = strzone(chr(0x1F608));
-       charmapRow3[6]  = strzone(chr(0x1F609));
-       charmapRow3[7]  = strzone(chr(0x1F60A));
-       charmapRow3[8]  = strzone(chr(0x1F60E));
-       charmapRow3[9]  = strzone(chr(0x1F610));
-       charmapRow3[10] = strzone(chr(0x1F612));
-       charmapRow3[11] = strzone(chr(0x1F618));
-       charmapRow3[12] = string_null;
-       charmapRow3[13] = string_null;
-
-       charmapRow4[0]  = strzone(chr(0x1F615));
-       charmapRow4[1]  = strzone(chr(0x1F61B));
-       charmapRow4[2]  = strzone(chr(0x1F61D));
-       charmapRow4[3]  = strzone(chr(0x1F61E));
-       charmapRow4[4]  = strzone(chr(0x1F61F));
-       charmapRow4[5]  = strzone(chr(0x1F620));
-       charmapRow4[6]  = strzone(chr(0x1F623));
-       charmapRow4[7]  = strzone(chr(0x1F62D));
-       charmapRow4[8]  = strzone(chr(0x1F62E));
-       charmapRow4[9]  = strzone(chr(0x1F632));
-       charmapRow4[10] = strzone(chr(0x1F635));
-       charmapRow4[11] = strzone(chr(0x1F634));
-       charmapRow4[12] = string_null;
-       charmapRow4[13] = string_null;
-
-       // Legacy characters:
-
-       float i;
-       for(i = 0; i < 14; ++i)
-               charmapRow5[i] = strzone(chr(0xE0E1 + i));
-
-       for(i = 0; i < 12; ++i)
-               charmapRow6[i] = strzone(chr(0xE0EF + i));
-       charmapRow6[12] = strzone(chr(0xE010));
-       charmapRow6[13] = strzone(chr(0xE011));
-
-       for(i = 0; i < 10; ++i)
-               charmapRow7[i] = strzone(chr(0xE0B0 + i));
-       charmapRow7[10] = strzone(chr(0xE0A1));
-       charmapRow7[11] = strzone(chr(0xE0BF));
-       charmapRow7[12] = strzone(chr(0xE0A6));
-       charmapRow7[13] = strzone(chr(0xE0A5));
-
-       for(i = 0; i < 14; ++i)
-               charmapRow8[i] = strzone(chr(0xE0C1 + i));
-
-       for(i = 0; i < 12; ++i)
-               charmapRow9[i] = strzone(chr(0xE0CF + i));
-       charmapRow9[12] = strzone(chr(0xE05B));
-       charmapRow9[13] = strzone(chr(0xE05D));
-}
+
+string CHARMAP =
+       "๐ŸŒ๐ŸŒŽ๐ŸŒ๐Ÿš€๐ŸŒŒ๐Ÿ‘ฝ๐Ÿ”ซโŒ–โ‡โˆโ†โ†‘โ†’โ†“"
+       "โ˜ โ˜ฃโ˜ขโš›โšกโš™๐Ÿ”ฅโŒโš โ›”โฐโฑโฒโณ"
+       "โ˜…โ—†โ– โ–ฎโ–ฐโ–ฌโ—ฃโ—คโ—ฅโ—ขโ—€โ–ฒโ–ถโ–ผ"
+       "๐Ÿ˜ƒ๐Ÿ˜Š๐Ÿ˜๐Ÿ˜„๐Ÿ˜†๐Ÿ˜Ž๐Ÿ˜ˆ๐Ÿ˜‡๐Ÿ˜‰๐Ÿ˜›๐Ÿ˜๐Ÿ˜˜โค "
+       "๐Ÿ˜๐Ÿ˜’๐Ÿ˜•๐Ÿ˜ฎ๐Ÿ˜ฒ๐Ÿ˜ž๐Ÿ˜Ÿ๐Ÿ˜ ๐Ÿ˜ฃ๐Ÿ˜ญ๐Ÿ˜ต๐Ÿ˜ด  "
+       "๎ƒก๎ƒข๎ƒฃ๎ƒค๎ƒฅ๎ƒฆ๎ƒง๎ƒจ๎ƒฉ๎ƒช๎ƒซ๎ƒฌ๎ƒญ๎ƒฎ"
+       "๎ƒฏ๎ƒฐ๎ƒฑ๎ƒฒ๎ƒณ๎ƒด๎ƒต๎ƒถ๎ƒท๎ƒธ๎ƒน๎ƒบ๎€๎€‘"
+       "๎‚ฐ๎‚ฑ๎‚ฒ๎‚ณ๎‚ด๎‚ต๎‚ถ๎‚ท๎‚ธ๎‚น๎‚ก๎‚ฟ๎‚ฆ๎‚ฅ"
+       "๎ƒ๎ƒ‚๎ƒƒ๎ƒ„๎ƒ…๎ƒ†๎ƒ‡๎ƒˆ๎ƒ‰๎ƒŠ๎ƒ‹๎ƒŒ๎ƒ๎ƒŽ"
+       "๎ƒ๎ƒ๎ƒ‘๎ƒ’๎ƒ“๎ƒ”๎ƒ•๎ƒ–๎ƒ—๎ƒ˜๎ƒ™๎ƒš๎›๎";
 
 string charmap_cellToChar(vector cell)
 {
-       if(!cvar("utf8_enable"))
-               return "";
+       string character = substring(CHARMAP, cell_y * CHARMAP_COLS + cell_x, 1);
 
-       if(cell_x >= CHARMAP_COLS)
+       if (character != " ")
+               return character;
+       else
                return "";
-
-       switch(cell_y)
-       {
-               case 0: return charmapRow0[cell_x];
-               case 1: return charmapRow1[cell_x];
-               case 2: return charmapRow2[cell_x];
-               case 3: return charmapRow3[cell_x];
-               case 4: return charmapRow4[cell_x];
-               case 5: return charmapRow5[cell_x];
-               case 6: return charmapRow6[cell_x];
-               case 7: return charmapRow7[cell_x];
-               case 8: return charmapRow8[cell_x];
-               case 9: return charmapRow9[cell_x];
-       }
-       return "";
 }
 
 entity makeXonoticCharmap(entity controlledInputBox)
 {
-       charmap_initializeRows();
-
        entity me;
        me = spawnXonoticCharmap();
        me.configureXonoticCharmap(me, controlledInputBox);
@@ -188,6 +67,9 @@ void XonoticCharmap_resizeNotify(entity me, vector relOrigin, vector relSize, ve
 {
        SUPER(XonoticCharmap).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
 
+       float maxFontWidth = SKINFONTSIZE_NORMAL / absSize_x;
+       float maxFontHeight = SKINFONTSIZE_NORMAL / absSize_y;
+
        if((me.realCellSize_x * absSize_x) > (me.realCellSize_y * absSize_y))
        {
                me.realFontSize_x = me.realCellSize_y * absSize_y / absSize_x;
@@ -198,6 +80,9 @@ void XonoticCharmap_resizeNotify(entity me, vector relOrigin, vector relSize, ve
                me.realFontSize_x = me.realCellSize_x;
                me.realFontSize_y = me.realCellSize_x * absSize_x / absSize_y;
        }
+
+       if(me.realFontSize_x > maxFontWidth || me.realFontSize_y > maxFontHeight)
+               me.realFontSize = eX * maxFontWidth + eY * maxFontHeight;
 }
 
 float XonoticCharmap_mouseMove(entity me, vector coords)
@@ -317,9 +202,12 @@ void XonoticCharmap_draw(entity me)
        cellPos = '0 0 0';
        charPos = '0 0 0';
 
+       float CHAR_OFFSET_X = me.realCellSize_x / 2;
+       float CHAR_OFFSET_Y = (me.realCellSize_y - me.realFontSize_y) / 2;
+
        for(cell_y = 0; cell_y < CHARMAP_ROWS; ++cell_y)
        {
-               charPos_y = cell_y / CHARMAP_ROWS + (me.realCellSize_y - me.realFontSize_y) / 2;
+               charPos_y = cell_y / CHARMAP_ROWS + CHAR_OFFSET_Y;
                for(cell_x = 0; cell_x < CHARMAP_COLS; ++cell_x)
                {
                        character = charmap_cellToChar(cell);
@@ -339,7 +227,7 @@ void XonoticCharmap_draw(entity me)
                        }
 
                        // Draw character
-                       charPos_x = cell_x / CHARMAP_COLS + me.realCellSize_x / 2;
+                       charPos_x = cell_x / CHARMAP_COLS + CHAR_OFFSET_X;
                        draw_CenterText(charPos, character, me.realFontSize, SKINCOLOR_CHARMAP_CHAR, SKINALPHA_CHARMAP_CHAR, 0);
                }
        }