]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - ui.c
rewrote memory system entirely (hunk, cache, and zone are gone, memory pools replaced...
[xonotic/darkplaces.git] / ui.c
diff --git a/ui.c b/ui.c
index 1e10d337d6de4dee8bc02cf0cb664f35e1086b1c..9097aaf5b2c772eb55c1d9b9670a198ace63e384 100644 (file)
--- a/ui.c
+++ b/ui.c
@@ -27,46 +27,73 @@ 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, 0xFF, 0xFF, 0xFF, 
-       0x02, 0x06, 0x04, 0x01, 0x04, 0x05, 0x06, 0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 
-       0x02, 0x05, 0x01, 0xFF, 0x01, 0x04, 0x05, 0x06, 0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 
-       0x02, 0x01, 0xFF, 0xFF, 0xFF, 0x01, 0x04, 0x05, 0x06, 0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 
-       0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01, 0x04, 0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 
-       0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 
-       0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 
-       0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 
-       0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 
-       0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 
-       0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 
-       0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 
+       "333333332......."
+       "26777761........"
+       "2655541........."
+       "265541.........."
+       "2654561........."
+       "26414561........"
+       "251.14561......."
+       "21...14561......"
+       "1.....141......."
+       ".......1........"
+       "................"
+       "................"
+       "................"
+       "................"
+       "................"
+       "................"
 };
 
-void ui_start(void)
+static rtexturepool_t *uitexturepool;
+
+static void ui_start(void)
 {
+       int i;
+       byte buffer[256][4];
+       uitexturepool = R_AllocTexturePool();
 //     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;
+       for (i = 0;i < 256;i++)
+       {
+               if (pointerimage[i] == '.')
+               {
+                       buffer[i][0] = 0;
+                       buffer[i][1] = 0;
+                       buffer[i][2] = 0;
+                       buffer[i][3] = 0;
+               }
+               else
+               {
+                       buffer[i][0] = (pointerimage[i] - '0') * 16;
+                       buffer[i][1] = (pointerimage[i] - '0') * 16;
+                       buffer[i][2] = (pointerimage[i] - '0') * 16;
+                       buffer[i][3] = 255;
+               }
+       }
+       ui_mousepointertexture = R_LoadTexture(uitexturepool, "mousepointer", 16, 16, &buffer[0][0], TEXTYPE_RGBA, TEXF_ALPHA | TEXF_PRECACHE);
+       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;
+       R_FreeTexturePool(&uitexturepool);
 }
 
-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 +102,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 +113,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 +131,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 +142,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, qpic_t *pic, 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 +167,37 @@ void ui_item
                }
                ui->item_count++;
        }
+       memset(it, 0, sizeof(ui_item_t));
        strncpy(it->name, itemname, 32);
        it->flags = 0;
+       if (pic || string)
+       {
+               it->flags |= ITEM_DRAWABLE;
+               it->draw_pic = pic;
+               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)
@@ -298,8 +332,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,17 +431,28 @@ 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_pic)
+                                                               Draw_Pic(it->draw_x, it->draw_y, it->draw_pic);
+                                                       if (it->draw_string)
+                                                               Draw_String(it->draw_x, it->draw_y, it->draw_string, 9999);
+                                               }
 
                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)
+                       if (it->draw_pic)
+                               Draw_AdditivePic(it->draw_x, it->draw_y, it->draw_pic);
+                       if (it->draw_string)
+                               Draw_AdditiveString(it->draw_x, it->draw_y, it->draw_string, 9999);
+                       if (ui_showname.integer)
                                Draw_String(ui_mouse_x, ui_mouse_y + 16, it->name, 9999);
        }
 
                it = ui_keyrealitem;
-               Draw_AdditivePic(it->draw_x, it->draw_y, it->draw_pic);
+               if (it->draw_pic)
+                       Draw_AdditivePic(it->draw_x, it->draw_y, it->draw_pic);
+               if (it->draw_string)
+                       Draw_AdditiveString(it->draw_x, it->draw_y, it->draw_string, 9999);
 
 //             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);