X-Git-Url: https://de.git.xonotic.org/?a=blobdiff_plain;f=ui.c;h=b2b91bc4874f862262807eff22c96e48fdf5c7ca;hb=04826446c325116c03990a9faf04d6439816a6e2;hp=1e10d337d6de4dee8bc02cf0cb664f35e1086b1c;hpb=659171da82bb0cc43ee0e2bde1c6115bc0e9d0f8;p=xonotic%2Fdarkplaces.git diff --git a/ui.c b/ui.c index 1e10d337..b2b91bc4 100644 --- a/ui.c +++ b/ui.c @@ -14,59 +14,36 @@ cvar_t ui_showname = {0, "ui_showname", "0"}; #define UI_MOUSEBUTTONS 3 -static int ui_alive, ui_active; -static float ui_mouse_x, ui_mouse_y; -static int ui_mousebutton[UI_MOUSEBUTTONS], ui_mouseclick; -static int ui_keyui, ui_keyitem; -static ui_item_t *ui_keyrealitem; +static int ui_alive, ui_active; +static float ui_mouse_x, ui_mouse_y; +static int ui_mousebutton[UI_MOUSEBUTTONS], ui_mouseclick; +static int ui_keyui, ui_keyitem; +static ui_item_t *ui_keyrealitem; static ui_t *ui_list[MAX_UI_COUNT]; -//static qpic_t *ui_mousepointer; -static rtexture_t *ui_mousepointertexture; - -static byte pointerimage[256] = -{ - 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x02, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0x02, 0x06, 0x07, 0x07, 0x07, 0x07, 0x06, 0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0x02, 0x06, 0x05, 0x05, 0x05, 0x04, 0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0x02, 0x06, 0x05, 0x05, 0x04, 0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0x02, 0x06, 0x05, 0x04, 0x05, 0x06, 0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xF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0xFF, 0xFF, 0xFF, 0xFF, 0xFF, -}; - -void ui_start(void) +static void ui_start(void) { -// ui_mousepointer = Draw_CachePic("ui/mousepointer.lmp"); - ui_mousepointertexture = R_LoadTexture("mousepointer", 16, 16, pointerimage, TEXF_ALPHA | TEXF_PRECACHE); - ui_mouse_x = vid.width * 0.5; - ui_mouse_y = vid.height * 0.5; + ui_mouse_x = vid.conwidth * 0.5; + ui_mouse_y = vid.conheight * 0.5; ui_alive = true; } -void ui_shutdown(void) +static void ui_shutdown(void) { -// ui_mousepointer = NULL; - ui_mousepointertexture = NULL; ui_alive = false; } -void ui_newmap(void) +static void ui_newmap(void) { } +static mempool_t *uimempool; + void ui_init(void) { + uimempool = Mem_AllocPool("UI"); + Cvar_RegisterVariable(&ui_showname); R_RegisterModule("UI", ui_start, ui_shutdown, ui_newmap); } @@ -75,8 +52,8 @@ void ui_mouseupdate(float x, float y) { if (ui_alive) { - ui_mouse_x = bound(0, x, vid.width); - ui_mouse_y = bound(0, y, vid.height); + ui_mouse_x = bound(0, x, vid.conwidth); + ui_mouse_y = bound(0, y, vid.conheight); } } @@ -86,15 +63,15 @@ void ui_mouseupdaterelative(float x, float y) { ui_mouse_x += x; ui_mouse_y += y; - ui_mouse_x = bound(0, ui_mouse_x, vid.width); - ui_mouse_y = bound(0, ui_mouse_y, vid.height); + ui_mouse_x = bound(0, ui_mouse_x, vid.conwidth); + ui_mouse_y = bound(0, ui_mouse_y, vid.conheight); } } ui_t *ui_create(void) { ui_t *ui; - ui = qmalloc(sizeof(*ui)); + ui = Mem_Alloc(uimempool, sizeof(*ui)); if (ui == NULL) Sys_Error("ui_create: unable to allocate memory for new ui\n"); memset(ui, 0, sizeof(*ui)); @@ -104,7 +81,7 @@ ui_t *ui_create(void) void ui_free(ui_t *ui) { if (ui) - qfree(ui); + Mem_Free(ui); } void ui_clear(ui_t *ui) @@ -115,7 +92,7 @@ void ui_clear(ui_t *ui) void ui_item ( ui_t *ui, char *basename, int number, - float x, float y, qpic_t *pic, + float x, float y, char *picname, char *string, float left, float top, float width, float height, void(*leftkey)(void *nativedata1, void *nativedata2, float data1, float data2), void(*rightkey)(void *nativedata1, void *nativedata2, float data1, float data2), @@ -140,30 +117,37 @@ void ui_item } ui->item_count++; } + memset(it, 0, sizeof(ui_item_t)); strncpy(it->name, itemname, 32); it->flags = 0; + if (picname || string) + { + it->flags |= ITEM_DRAWABLE; + it->draw_picname = picname; + it->draw_string = string; + it->draw_x = x; + it->draw_y = y; + } if (leftkey || rightkey || enterkey || mouseclick) + { it->flags |= ITEM_CLICKABLE; - if (pic) - it->flags |= ITEM_DRAWABLE; - it->draw_x = x; - it->draw_y = y; - it->click_x = x + left; - it->click_y = y + top; - it->click_x2 = it->click_x + width; - it->click_y2 = it->click_y + height; - it->leftkey = leftkey; - it->rightkey = rightkey; - it->enterkey = enterkey; - it->mouseclick = mouseclick; - if (it->mouseclick == NULL) - it->mouseclick = (void *)it->enterkey; - if (it->leftkey == NULL) - it->leftkey = it->enterkey; - if (it->rightkey == NULL) - it->rightkey = it->enterkey; - it->nativedata1 = nativedata1; - it->nativedata2 = nativedata2; + it->click_x = x + left; + it->click_y = y + top; + it->click_x2 = it->click_x + width; + it->click_y2 = it->click_y + height; + it->leftkey = leftkey; + it->rightkey = rightkey; + it->enterkey = enterkey; + it->mouseclick = mouseclick; + if (it->mouseclick == NULL) + it->mouseclick = (void *)it->enterkey; + if (it->leftkey == NULL) + it->leftkey = it->enterkey; + if (it->rightkey == NULL) + it->rightkey = it->enterkey; + it->nativedata1 = nativedata1; + it->nativedata2 = nativedata2; + } } void ui_item_remove(ui_t *ui, char *basename, int number) @@ -249,7 +233,7 @@ int ui_isactive(void) } #define UI_QUEUE_SIZE 256 -static byte ui_keyqueue[UI_QUEUE_SIZE]; +static qbyte ui_keyqueue[UI_QUEUE_SIZE]; static int ui_keyqueuepos = 0; void ui_leftkeyupdate(int pressed) @@ -298,8 +282,8 @@ void ui_update(void) ui_item_t *startitem, *it; if (ui_alive) { - ui_mouse_x = bound(0, ui_mouse_x, vid.width); - ui_mouse_y = bound(0, ui_mouse_y, vid.height); + ui_mouse_x = bound(0, ui_mouse_x, vid.conwidth); + ui_mouse_y = bound(0, ui_mouse_y, vid.conheight); if ((ui_active = ui_isactive())) { @@ -397,19 +381,30 @@ void ui_draw(void) if (ui->item_count) for (i = 0, it = ui->items;i < ui->item_count;i++, it++) if (it->flags & ITEM_DRAWABLE) - Draw_Pic(it->draw_x, it->draw_y, it->draw_pic); + { + if (it->draw_picname) + DrawQ_Pic(it->draw_x, it->draw_y, it->draw_picname, 0, 0, 1, 1, 1, 1, 0); + if (it->draw_string) + DrawQ_String(it->draw_x, it->draw_y, it->draw_string, 0, 8, 8, 1, 1, 1, 1, 0); + } if ((it = ui_hititem(ui_mouse_x, ui_mouse_y))) { - Draw_AdditivePic(it->draw_x, it->draw_y, it->draw_pic); - if (ui_showname.value) - Draw_String(ui_mouse_x, ui_mouse_y + 16, it->name, 9999); + if (it->draw_picname) + DrawQ_Pic(it->draw_x, it->draw_y, it->draw_picname, 0, 0, 1, 1, 1, 1, DRAWFLAG_ADDITIVE); + if (it->draw_string) + DrawQ_String(it->draw_x, it->draw_y, it->draw_string, 0, 8, 8, 1, 1, 1, 1, DRAWFLAG_ADDITIVE); + if (ui_showname.integer) + DrawQ_String(ui_mouse_x, ui_mouse_y + 16, it->name, 0, 8, 8, 1, 1, 1, 1, 0); } it = ui_keyrealitem; - Draw_AdditivePic(it->draw_x, it->draw_y, it->draw_pic); + if (it->draw_picname) + DrawQ_Pic(it->draw_x, it->draw_y, it->draw_picname, 0, 0, 1, 1, 1, 1, DRAWFLAG_ADDITIVE); + if (it->draw_string) + DrawQ_String(it->draw_x, it->draw_y, it->draw_string, 0, 8, 8, 1, 1, 1, 1, DRAWFLAG_ADDITIVE); -// Draw_Pic(ui_mouse_x, ui_mouse_y, ui_mousepointer); - Draw_GenericPic(ui_mousepointertexture, 1, 1, 1, 1, ui_mouse_x, ui_mouse_y, 16, 16); + DrawQ_Pic(ui_mouse_x, ui_mouse_y, "ui/mousepointer.tga", 0, 0, 1, 1, 1, 1, 0); } } +