diff --git a/cs-code/client_menu.qc b/cs-code/client_menu.qc index 7b3875021..077f1516a 100644 --- a/cs-code/client_menu.qc +++ b/cs-code/client_menu.qc @@ -442,7 +442,10 @@ void () main_menu = Menu_FadeScreen (1); Menu_Pic (16, 4, "gfx/qplaque.lmp"); Menu_CenterPic (160, 4, "gfx/ttl_main.lmp"); - Menu_Pic (71,32, "gfx/mainmenu.lmp"); + if (do_single_player) + Menu_Pic (71,32, "gfx/mainmenu.lmp"); + else + Menu_SubPic (71,52, "gfx/mainmenu.lmp", 0, 20, 240, 92); Menu_Cursor (spinner); if (do_single_player) single_player_menu (); diff --git a/cs-code/draw.h b/cs-code/draw.h index 44ba51968..681ef8431 100644 --- a/cs-code/draw.h +++ b/cs-code/draw.h @@ -10,6 +10,7 @@ typedef _qpic_t [] qpic_t; @extern qpic_t (string name, integer alpha) Draw_CachePic; @extern void (integer x, integer y, qpic_t pic) Draw_Pic; +@extern void (integer x, integer y, qpic_t pic, integer srcx, integer srcy, integer width, integer height) Draw_SubPic; @extern void (integer x, integer y, qpic_t pic) Draw_CenterPic; @extern void (integer x, integer y, integer chr) Draw_Character; diff --git a/cs-code/draw.r b/cs-code/draw.r index 12953fa4a..7c14762ba 100644 --- a/cs-code/draw.r +++ b/cs-code/draw.r @@ -3,6 +3,7 @@ qpic_t (string name, integer alpha) Draw_CachePic = #0; void (integer x, integer y, qpic_t pic) Draw_Pic = #0; +void (integer x, integer y, qpic_t pic, integer srcx, integer srcy, integer width, integer height) Draw_SubPic = #0; void (integer x, integer y, qpic_t pic) Draw_CenterPic = #0; void (integer x, integer y, integer chr) Draw_Character = #0; diff --git a/cs-code/menu.h b/cs-code/menu.h index 90c5aeef9..3f550d6b5 100644 --- a/cs-code/menu.h +++ b/cs-code/menu.h @@ -7,7 +7,9 @@ @extern void (integer () func) Menu_EnterHook; @extern void (integer () func) Menu_LeaveHook; @extern void (integer x, integer y, string name) Menu_Pic; +@extern void (integer x, integer y, string name, integer srcx, integer srcy, integer width, integer height) Menu_SubPic; @extern void (integer x, integer y, string name) Menu_CenterPic; +@extern void (integer x, integer y, string name, integer srcx, integer srcy, integer width, integer height) Menu_CenterSubPic; @extern void (integer x, integer y, string text, integer (string text, integer key) func, integer allkeys) Menu_Item; @extern void (void (integer x, integer y) func) Menu_Cursor; @extern void (integer (integer key, integer unicode, integer down) func) Menu_KeyEvent; diff --git a/cs-code/menu.r b/cs-code/menu.r index 24177400f..718850510 100644 --- a/cs-code/menu.r +++ b/cs-code/menu.r @@ -6,7 +6,9 @@ void (integer () func) Menu_Draw = #0; void (integer () func) Menu_EnterHook = #0; void (integer () func) Menu_LeaveHook = #0; void (integer x, integer y, string name) Menu_Pic = #0; +void (integer x, integer y, string name, integer srcx, integer srcy, integer width, integer height) Menu_SubPic = #0; void (integer x, integer y, string name) Menu_CenterPic = #0; +void (integer x, integer y, string name, integer srcx, integer srcy, integer width, integer height) Menu_CenterSubPic = #0; void (integer x, integer y, string text, integer (string text, integer key) func, integer allkeys) Menu_Item = #0; void (void (integer x, integer y) func) Menu_Cursor = #0; void (integer (integer key, integer unicode, integer down) func) Menu_KeyEvent = #0; diff --git a/libs/console/menu.c b/libs/console/menu.c index 2ece35e63..70d519b77 100644 --- a/libs/console/menu.c +++ b/libs/console/menu.c @@ -48,6 +48,7 @@ static const char rcsid[] = typedef struct menu_pic_s { struct menu_pic_s *next; int x, y; + int srcx, srcy, width, height; const char *name; } menu_pic_t; @@ -137,6 +138,24 @@ menu_add_item (menu_item_t *m, menu_item_t *i) m->items[m->num_items++] = i; } +static void +menu_pic (int x, int y, const char *name, + int srcx, int srcy, int width, int height) +{ + menu_pic_t *pic = malloc (sizeof (menu_pic_t)); + + pic->x = x; + pic->y = y; + pic->name = strdup (name); + pic->srcx = srcx; + pic->srcy = srcy; + pic->width = width; + pic->height = height; + + pic->next = menu->pics; + menu->pics = pic; +} + static void bi_Menu_Begin (progs_t *pr) { @@ -184,13 +203,22 @@ bi_Menu_Pic (progs_t *pr) int x = P_INT (pr, 0); int y = P_INT (pr, 1); const char *name = P_STRING (pr, 2); - menu_pic_t *pic = malloc (sizeof (menu_pic_t)); - pic->x = x; - pic->y = y; - pic->name = strdup (name); - pic->next = menu->pics; - menu->pics = pic; + menu_pic (x, y, name, 0, 0, -1, -1); +} + +static void +bi_Menu_SubPic (progs_t *pr) +{ + int x = P_INT (pr, 0); + int y = P_INT (pr, 1); + const char *name = P_STRING (pr, 2); + int srcx = P_INT (pr, 3); + int srcy = P_INT (pr, 4); + int width = P_INT (pr, 5); + int height = P_INT (pr, 6); + + menu_pic (x, y, name, srcx, srcy, width, height); } static void @@ -199,19 +227,30 @@ bi_Menu_CenterPic (progs_t *pr) int x = P_INT (pr, 0); int y = P_INT (pr, 1); const char *name = P_STRING (pr, 2); - menu_pic_t *pic = malloc (sizeof (menu_pic_t)); qpic_t *qpic = Draw_CachePic (name, 1); - if (!qpic) { - free (pic); + if (!qpic) return; - } - pic->x = x - qpic->width / 2; - pic->y = y; - pic->name = strdup (name); - pic->next = menu->pics; - menu->pics = pic; + menu_pic (x - qpic->width / 2, y, name, 0, 0, -1, -1); +} + +static void +bi_Menu_CenterSubPic (progs_t *pr) +{ + int x = P_INT (pr, 0); + int y = P_INT (pr, 1); + const char *name = P_STRING (pr, 2); + qpic_t *qpic = Draw_CachePic (name, 1); + int srcx = P_INT (pr, 3); + int srcy = P_INT (pr, 4); + int width = P_INT (pr, 5); + int height = P_INT (pr, 6); + + if (!qpic) + return; + + menu_pic (x - qpic->width / 2, y, name, srcx, srcy, width, height); } static void @@ -367,7 +406,9 @@ Menu_Init (void) PR_AddBuiltin (&menu_pr_state, "Menu_EnterHook", bi_Menu_EnterHook, -1); PR_AddBuiltin (&menu_pr_state, "Menu_LeaveHook", bi_Menu_LeaveHook, -1); PR_AddBuiltin (&menu_pr_state, "Menu_Pic", bi_Menu_Pic, -1); + PR_AddBuiltin (&menu_pr_state, "Menu_SubPic", bi_Menu_SubPic, -1); PR_AddBuiltin (&menu_pr_state, "Menu_CenterPic", bi_Menu_CenterPic, -1); + PR_AddBuiltin (&menu_pr_state, "Menu_CenterSubPic", bi_Menu_CenterSubPic, -1); PR_AddBuiltin (&menu_pr_state, "Menu_Item", bi_Menu_Item, -1); PR_AddBuiltin (&menu_pr_state, "Menu_Cursor", bi_Menu_Cursor, -1); PR_AddBuiltin (&menu_pr_state, "Menu_KeyEvent", bi_Menu_KeyEvent, -1); @@ -464,7 +505,11 @@ Menu_Draw (void) qpic_t *pic = Draw_CachePic (m_pic->name, 1); if (!pic) continue; - Draw_Pic (m_pic->x, m_pic->y, pic); + if (m_pic->width > 0 && m_pic->height > 0) + Draw_SubPic (m_pic->x, m_pic->y, pic, m_pic->srcx, m_pic->srcy, + m_pic->width, m_pic->height); + else + Draw_Pic (m_pic->x, m_pic->y, pic); } for (i = 0; i < menu->num_items; i++) { if (menu->items[i]->text) {