]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - menu.c
added Vector4Set macro
[xonotic/darkplaces.git] / menu.c
diff --git a/menu.c b/menu.c
index 2ae3f6374df02a97a9bfb3175ec94c5e5ae04856..25e2ab55c0148332f2aac7d7a4227c31e9b73094 100644 (file)
--- a/menu.c
+++ b/menu.c
@@ -209,7 +209,7 @@ static void M_ItemPrint(float cx, float cy, const char *str, int unghosted)
 
 static void M_DrawPic(float cx, float cy, const char *picname)
 {
-       DrawQ_Pic(menu_x + cx, menu_y + cy, Draw_CachePic(picname, false), 0, 0, 1, 1, 1, 1, 0);
+       DrawQ_Pic(menu_x + cx, menu_y + cy, Draw_CachePic(picname, true), 0, 0, 1, 1, 1, 1, 0);
 }
 
 static unsigned char identityTable[256];
@@ -420,7 +420,7 @@ static void M_Main_Draw (void)
        if (gamemode == GAME_TRANSFUSION) {
                int y1, y2, y3;
                M_Background(640, 480);
-               p = Draw_CachePic ("gfx/menu/tb-transfusion", false);
+               p = Draw_CachePic ("gfx/menu/tb-transfusion", true);
                M_DrawPic (640/2 - p->width/2, 40, "gfx/menu/tb-transfusion");
                y2 = 120;
                // 8 rather than MAIN_ITEMS to skip a number and not miss the last option
@@ -452,7 +452,7 @@ static void M_Main_Draw (void)
        }
        M_Background(320, 200);
        M_DrawPic (16, 4, "gfx/qplaque");
-       p = Draw_CachePic ("gfx/ttl_main", false);
+       p = Draw_CachePic ("gfx/ttl_main", true);
        M_DrawPic ( (320-p->width)/2, 4, "gfx/ttl_main");
 // Nehahra
        if (gamemode == GAME_NEHAHRA)
@@ -753,7 +753,7 @@ static void M_SinglePlayer_Draw (void)
        M_Background(320, 200);
 
        M_DrawPic (16, 4, "gfx/qplaque");
-       p = Draw_CachePic ("gfx/ttl_sgl", false);
+       p = Draw_CachePic ("gfx/ttl_sgl", true);
 
        // Some mods don't have a single player mode
        if (gamemode == GAME_GOODVSBAD2 || gamemode == GAME_BATTLEMECH)
@@ -917,7 +917,7 @@ static void M_Load_Draw (void)
 
        M_Background(320, 200);
 
-       p = Draw_CachePic ("gfx/p_load", false);
+       p = Draw_CachePic ("gfx/p_load", true);
        M_DrawPic ( (320-p->width)/2, 4, "gfx/p_load" );
 
        for (i=0 ; i< MAX_SAVEGAMES; i++)
@@ -935,7 +935,7 @@ static void M_Save_Draw (void)
 
        M_Background(320, 200);
 
-       p = Draw_CachePic ("gfx/p_save", false);
+       p = Draw_CachePic ("gfx/p_save", true);
        M_DrawPic ( (320-p->width)/2, 4, "gfx/p_save");
 
        for (i=0 ; i<MAX_SAVEGAMES ; i++)
@@ -1041,7 +1041,7 @@ static void M_Transfusion_Episode_Draw (void)
        cachepic_t *p;
        M_Background(640, 480);
 
-       p = Draw_CachePic ("gfx/menu/tb-episodes", false);
+       p = Draw_CachePic ("gfx/menu/tb-episodes", true);
        M_DrawPic (640/2 - p->width/2, 40, "gfx/menu/tb-episodes");
        for (y = 0; y < EPISODE_ITEMS; y++){
                M_DrawPic (0, 160 + y * 40, va("gfx/menu/episode%i", y+1));
@@ -1098,7 +1098,7 @@ static void M_Transfusion_Skill_Draw (void)
        cachepic_t      *p;
        M_Background(640, 480);
 
-       p = Draw_CachePic ("gfx/menu/tb-difficulty", false);
+       p = Draw_CachePic ("gfx/menu/tb-difficulty", true);
        M_DrawPic(640/2 - p->width/2, 40, "gfx/menu/tb-difficulty");
 
        for (y = 0; y < SKILL_ITEMS; y++)
@@ -1202,7 +1202,7 @@ static void M_MultiPlayer_Draw (void)
        if (gamemode == GAME_TRANSFUSION)
        {
                M_Background(640, 480);
-               p = Draw_CachePic ("gfx/menu/tb-online", false);
+               p = Draw_CachePic ("gfx/menu/tb-online", true);
                M_DrawPic (640/2 - p->width/2, 140, "gfx/menu/tb-online");
                for (f = 1; f <= MULTIPLAYER_ITEMS; f++)
                        M_DrawPic (0, 180 + f*40, va("gfx/menu/online%i", f));
@@ -1212,7 +1212,7 @@ static void M_MultiPlayer_Draw (void)
        M_Background(320, 200);
 
        M_DrawPic (16, 4, "gfx/qplaque");
-       p = Draw_CachePic ("gfx/p_multi", false);
+       p = Draw_CachePic ("gfx/p_multi", true);
        M_DrawPic ( (320-p->width)/2, 4, "gfx/p_multi");
        M_DrawPic (72, 32, "gfx/mp_menu");
 
@@ -1330,7 +1330,7 @@ static void M_Setup_Draw (void)
        M_Background(320, 200);
 
        M_DrawPic (16, 4, "gfx/qplaque");
-       p = Draw_CachePic ("gfx/p_multi", false);
+       p = Draw_CachePic ("gfx/p_multi", true);
        M_DrawPic ( (320-p->width)/2, 4, "gfx/p_multi");
 
        M_Print(64, 40, "Your name");
@@ -1363,8 +1363,8 @@ static void M_Setup_Draw (void)
                        menuplyr_width = image_width;
                        menuplyr_height = image_height;
                        Mem_Free(f);
-                       menuplyr_pixels = (unsigned char *)Mem_Alloc(cls.mempool, menuplyr_width * menuplyr_height);
-                       menuplyr_translated = (unsigned int *)Mem_Alloc(cls.mempool, menuplyr_width * menuplyr_height * 4);
+                       menuplyr_pixels = (unsigned char *)Mem_Alloc(cls.permanentmempool, menuplyr_width * menuplyr_height);
+                       menuplyr_translated = (unsigned int *)Mem_Alloc(cls.permanentmempool, menuplyr_width * menuplyr_height * 4);
                        memcpy(menuplyr_pixels, data, menuplyr_width * menuplyr_height);
                        Mem_Free(data);
                }
@@ -1559,8 +1559,6 @@ static void M_Menu_Options_AdjustSliders (int dir)
                Cvar_SetValueQuick (&vid_conwidth, bound(320, vid_conwidth.value + dir * 64, 2048));
        else if (options_cursor == optnum++)
                Cvar_SetValueQuick (&vid_conheight, bound(240, vid_conheight.value + dir * 48, 1536));
-       else if (options_cursor == optnum++)
-               Cvar_SetValueQuick (&scr_conspeed, bound(0, scr_conspeed.value + dir * 100, 1000));
        else if (options_cursor == optnum++)
                Cvar_SetValueQuick (&scr_conalpha, bound(0, scr_conalpha.value + dir * 0.2, 1));
        else if (options_cursor == optnum++)
@@ -1578,7 +1576,7 @@ static void M_Menu_Options_AdjustSliders (int dir)
        else if (options_cursor == optnum++)
                Cvar_SetValueQuick (&scr_screenshot_jpeg_quality, bound(0, scr_screenshot_jpeg_quality.value + dir * 0.1, 1));
        else if (options_cursor == optnum++)
-               Cvar_SetValueQuick (&scr_screenshot_gamma, bound(0.1, scr_screenshot_gamma.value + dir * 0.1, 4));
+               Cvar_SetValueQuick (&scr_screenshot_gammaboost, bound(0.1, scr_screenshot_gammaboost.value + dir * 0.1, 4));
        else if (options_cursor == optnum++)
                Cvar_SetValueQuick (&r_sky, !r_sky.integer);
        else if (options_cursor == optnum++)
@@ -1681,12 +1679,12 @@ static void M_Options_Draw (void)
        M_Background(320, bound(200, 32 + OPTIONS_ITEMS * 8, vid_conheight.integer));
 
        M_DrawPic(16, 4, "gfx/qplaque");
-       p = Draw_CachePic("gfx/p_option", false);
+       p = Draw_CachePic("gfx/p_option", true);
        M_DrawPic((320-p->width)/2, 4, "gfx/p_option");
 
        optnum = 0;
        optcursor = options_cursor;
-       visible = (menu_height - 32) / 8;
+       visible = (int)((menu_height - 32) / 8);
        opty = 32 - bound(0, optcursor - (visible >> 1), max(0, OPTIONS_ITEMS - visible)) * 8;
 
        M_Options_PrintCommand( "Customize controls", true);
@@ -1698,7 +1696,6 @@ static void M_Options_Draw (void)
        M_Options_PrintCommand( "     Color Control", true);
        M_Options_PrintSlider(  "  2D Screen Width ", true, vid_conwidth.value, 320, 2048);
        M_Options_PrintSlider(  "  2D Screen Height", true, vid_conheight.value, 240, 1536);
-       M_Options_PrintSlider(  "     Console Speed", true, scr_conspeed.value, 0, 1000);
        M_Options_PrintSlider(  "     Console Alpha", true, scr_conalpha.value, 0, 1);
        M_Options_PrintSlider(  "Conback Brightness", true, scr_conbrightness.value, 0, 1);
        M_Options_PrintSlider(  "     Sbar Alpha BG", true, sbar_alpha_bg.value, 0, 1);
@@ -1707,7 +1704,7 @@ static void M_Options_Draw (void)
        M_Options_PrintSlider(  "     Field of View", true, scr_fov.integer, 1, 170);
        M_Options_PrintCheckbox("  JPEG screenshots", jpeg_dll != NULL, scr_screenshot_jpeg.integer);
        M_Options_PrintSlider(  "      JPEG quality", jpeg_dll != NULL, scr_screenshot_jpeg_quality.value, 0, 1);
-       M_Options_PrintSlider(  "  Screenshot Gamma", jpeg_dll != NULL, scr_screenshot_gamma.value, 0.1, 4);
+       M_Options_PrintSlider(  "  Screenshot Gamma", jpeg_dll != NULL, scr_screenshot_gammaboost.value, 0.1, 4);
        M_Options_PrintCheckbox("               Sky", true, r_sky.integer);
        M_Options_PrintCheckbox("         Dithering", true, gl_dither.integer);
        M_Options_PrintSlider(  "Anisotropic Filter", gl_support_anisotropy, gl_texture_anisotropy.integer, 1, gl_max_anisotropy);
@@ -1876,12 +1873,12 @@ static void M_Options_Effects_Draw (void)
        M_Background(320, bound(200, 32 + OPTIONS_EFFECTS_ITEMS * 8, vid_conheight.integer));
 
        M_DrawPic(16, 4, "gfx/qplaque");
-       p = Draw_CachePic("gfx/p_option", false);
+       p = Draw_CachePic("gfx/p_option", true);
        M_DrawPic((320-p->width)/2, 4, "gfx/p_option");
 
        optcursor = options_effects_cursor;
        optnum = 0;
-       visible = (menu_height - 32) / 8;
+       visible = (int)((menu_height - 32) / 8);
        opty = 32 - bound(0, optcursor - (visible >> 1), max(0, OPTIONS_EFFECTS_ITEMS - visible)) * 8;
 
        M_Options_PrintSlider(  "      Corona Intensity", true, r_coronas.value, 0, 4);
@@ -2016,12 +2013,12 @@ static void M_Options_Graphics_Draw (void)
        M_Background(320, bound(200, 32 + OPTIONS_GRAPHICS_ITEMS * 8, vid_conheight.integer));
 
        M_DrawPic(16, 4, "gfx/qplaque");
-       p = Draw_CachePic("gfx/p_option", false);
+       p = Draw_CachePic("gfx/p_option", true);
        M_DrawPic((320-p->width)/2, 4, "gfx/p_option");
 
        optcursor = options_graphics_cursor;
        optnum = 0;
-       visible = (menu_height - 32) / 8;
+       visible = (int)((menu_height - 32) / 8);
        opty = 32 - bound(0, optcursor - (visible >> 1), max(0, OPTIONS_GRAPHICS_ITEMS - visible)) * 8;
 
        M_Options_PrintSlider(  "             Gloss Mode", true, r_shadow_gloss.integer, 0, 2);
@@ -2198,17 +2195,17 @@ static void M_Options_ColorControl_Draw (void)
        float x, c, s, t, u, v;
        cachepic_t      *p, *dither;
 
-       dither = Draw_CachePic("gfx/colorcontrol/ditherpattern", false);
+       dither = Draw_CachePic("gfx/colorcontrol/ditherpattern", true);
 
        M_Background(320, 256);
 
        M_DrawPic(16, 4, "gfx/qplaque");
-       p = Draw_CachePic("gfx/p_option", false);
+       p = Draw_CachePic("gfx/p_option", true);
        M_DrawPic((320-p->width)/2, 4, "gfx/p_option");
 
        optcursor = options_colorcontrol_cursor;
        optnum = 0;
-       visible = (menu_height - 32) / 8;
+       visible = (int)((menu_height - 32) / 8);
        opty = 32 - bound(0, optcursor - (visible >> 1), max(0, OPTIONS_COLORCONTROL_ITEMS - visible)) * 8;
 
        M_Options_PrintCommand( "     Reset to defaults", true);
@@ -2591,7 +2588,7 @@ static void M_Keys_Draw (void)
 
        M_Background(320, 48 + 8 * numcommands);
 
-       p = Draw_CachePic ("gfx/ttl_cstm", false);
+       p = Draw_CachePic ("gfx/ttl_cstm", true);
        M_DrawPic ( (320-p->width)/2, 4, "gfx/ttl_cstm");
 
        if (bind_grab)
@@ -2877,7 +2874,7 @@ static void M_Video_Draw (void)
        M_Background(320, 200);
 
        M_DrawPic(16, 4, "gfx/qplaque");
-       p = Draw_CachePic("gfx/vidmodes", false);
+       p = Draw_CachePic("gfx/vidmodes", true);
        M_DrawPic((320-p->width)/2, 4, "gfx/vidmodes");
 
        // Current Resolution
@@ -3282,7 +3279,7 @@ static void M_LanConfig_Draw (void)
        M_Background(320, 200);
 
        M_DrawPic (16, 4, "gfx/qplaque");
-       p = Draw_CachePic ("gfx/p_multi", false);
+       p = Draw_CachePic ("gfx/p_multi", true);
        basex = (320-p->width)/2;
        M_DrawPic (basex, 4, "gfx/p_multi");
 
@@ -3892,7 +3889,7 @@ void M_GameOptions_Draw (void)
        M_Background(320, 200);
 
        M_DrawPic (16, 4, "gfx/qplaque");
-       p = Draw_CachePic ("gfx/p_multi", false);
+       p = Draw_CachePic ("gfx/p_multi", true);
        M_DrawPic ( (320-p->width)/2, 4, "gfx/p_multi");
 
        M_DrawTextBox (152, 32, 10, 1);
@@ -4335,11 +4332,11 @@ static void M_ServerList_Draw (void)
        if (*m_return_reason)
                M_Print(16, menu_height - 8, m_return_reason);
        y = 48;
-       visible = (menu_height - 16 - y) / 8 / 2;
+       visible = (int)((menu_height - 16 - y) / 8 / 2);
        start = bound(0, slist_cursor - (visible >> 1), serverlist_viewcount - visible);
        end = min(start + visible, serverlist_viewcount);
 
-       p = Draw_CachePic("gfx/p_multi", false);
+       p = Draw_CachePic("gfx/p_multi", true);
        M_DrawPic((640 - p->width) / 2, 4, "gfx/p_multi");
        if (end > start)
        {
@@ -4413,7 +4410,7 @@ static void M_ServerList_Key(int k, char ascii)
 //=============================================================================
 /* Menu Subsystem */
 
-static void M_Keydown(int key, char ascii);
+static void M_KeyEvent(int key, char ascii, qboolean downevent);
 static void M_Draw(void);
 void M_ToggleMenu_f(void);
 static void M_Shutdown(void);
@@ -4612,10 +4609,10 @@ void M_Draw (void)
                        g = (int)(realtime * 64)%96;
                        scale_y_rate = (float)(g+1) / 96;
                        top_offset = (g+12)/12;
-                       p = Draw_CachePic (va("gfx/menu/blooddrip%i", top_offset), false);
-                       drop1 = Draw_CachePic("gfx/menu/blooddrop1", false);
-                       drop2 = Draw_CachePic("gfx/menu/blooddrop2", false);
-                       drop3 = Draw_CachePic("gfx/menu/blooddrop3", false);
+                       p = Draw_CachePic (va("gfx/menu/blooddrip%i", top_offset), true);
+                       drop1 = Draw_CachePic("gfx/menu/blooddrop1", true);
+                       drop2 = Draw_CachePic("gfx/menu/blooddrop2", true);
+                       drop3 = Draw_CachePic("gfx/menu/blooddrop3", true);
                        for (scale_x = 0; scale_x <= vid_conwidth.integer; scale_x += p->width) {
                                for (scale_y = -scale_y_repeat; scale_y <= vid_conheight.integer; scale_y += scale_y_repeat) {
                                        DrawQ_Pic (scale_x + 21, scale_y_repeat * .5 + scale_y + scale_y_rate * scale_y_repeat, drop3, 0, 0, 1, 1, 1, 1, 0);
@@ -4630,7 +4627,7 @@ void M_Draw (void)
                                        DrawQ_Pic (scale_x + 557, scale_y_repeat * .9425 + scale_y + scale_y_rate * scale_y_repeat, drop1, 0, 0, 1, 1, 1, 1, 0);
                                        DrawQ_Pic (scale_x + 606, scale_y_repeat * .5 + scale_y + scale_y_rate * scale_y_repeat, drop2, 0, 0, 1, 1, 1, 1, 0);
                                }
-                               DrawQ_Pic (scale_x, -1, Draw_CachePic(va("gfx/menu/blooddrip%i", top_offset), false), 0, 0, 1, 1, 1, 1, 0);
+                               DrawQ_Pic (scale_x, -1, Draw_CachePic(va("gfx/menu/blooddrip%i", top_offset), true), 0, 0, 1, 1, 1, 1, 0);
                        }
                }
        }
@@ -4645,8 +4642,10 @@ void M_Draw (void)
 }
 
 
-void M_Keydown (int key, char ascii)
+void M_KeyEvent (int key, char ascii, qboolean downevent)
 {
+       if (!downevent)
+               return;
        switch (m_state)
        {
        case m_none:
@@ -4759,6 +4758,7 @@ mfunction_t *PRVM_ED_FindFunction(const char *);
 
 #define M_F_INIT               "m_init"
 #define M_F_KEYDOWN            "m_keydown"
+#define M_F_KEYUP              "m_keyup"
 #define M_F_DRAW               "m_draw"
 // normal menu names (rest)
 #define M_F_TOGGLE             "m_toggle"
@@ -4779,6 +4779,7 @@ static qboolean m_displayed;
 static int m_numrequiredfunc = sizeof(m_required_func) / sizeof(char*);
 
 static func_t m_draw, m_keydown;
+static mfunction_t *m_keyup;
 
 void MR_SetRouting (qboolean forceold);
 
@@ -4814,7 +4815,7 @@ void MP_Error(const char *format, ...)
        Host_AbortCurrentFrame();
 }
 
-void MP_Keydown (int key, char ascii)
+void MP_KeyEvent (int key, char ascii, qboolean downevent)
 {
        PRVM_Begin;
        PRVM_SetProg(PRVM_MENUPROG);
@@ -4825,7 +4826,10 @@ void MP_Keydown (int key, char ascii)
        // pass key
        prog->globals.generic[OFS_PARM0] = (float) key;
        prog->globals.generic[OFS_PARM1] = (float) ascii;
-       PRVM_ExecuteProgram(m_keydown, M_F_KEYDOWN"(float key, float ascii) required\n");
+       if (downevent)
+               PRVM_ExecuteProgram(m_keydown, M_F_KEYDOWN"(float key, float ascii) required\n");
+       else if (m_keyup)
+               PRVM_ExecuteProgram((func_t)(m_keyup - prog->functions), M_F_KEYUP"(float key, float ascii) required\n");
 
        PRVM_End;
 }
@@ -4918,6 +4922,7 @@ void MP_Init (void)
        // set m_draw and m_keydown
        m_draw = (func_t) (PRVM_ED_FindFunction(M_F_DRAW) - prog->functions);
        m_keydown = (func_t) (PRVM_ED_FindFunction(M_F_KEYDOWN) - prog->functions);
+       m_keyup = PRVM_ED_FindFunction(M_F_KEYUP);
 
 #ifdef NG_MENU
        m_displayed = false;
@@ -4942,7 +4947,7 @@ void MP_Restart(void)
 
 static cvar_t forceqmenu = { 0, "forceqmenu", "0", "enables the quake menu instead of the quakec menu.dat (if present)" };
 
-void (*MR_Keydown) (int key, char ascii);
+void (*MR_KeyEvent) (int key, char ascii, qboolean downevent);
 void (*MR_Draw) (void);
 void (*MR_ToggleMenu_f) (void);
 void (*MR_Shutdown) (void);
@@ -4955,7 +4960,7 @@ void MR_SetRouting(qboolean forceold)
        if(!FS_FileExists(M_PROG_FILENAME) || forceqmenu.integer || forceold)
        {
                // set menu router function pointers
-               MR_Keydown = M_Keydown;
+               MR_KeyEvent = M_KeyEvent;
                MR_Draw = M_Draw;
                MR_ToggleMenu_f = M_ToggleMenu_f;
                MR_Shutdown = M_Shutdown;
@@ -4972,7 +4977,7 @@ void MR_SetRouting(qboolean forceold)
        else
        {
                // set menu router function pointers
-               MR_Keydown = MP_Keydown;
+               MR_KeyEvent = MP_KeyEvent;
                MR_Draw = MP_Draw;
                MR_ToggleMenu_f = MP_ToggleMenu_f;
                MR_Shutdown = MP_Shutdown;