From 671445d4a75259c1764b3eee8e9e814fba9d02a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Madar=C3=A1sz?= Date: Sun, 16 Oct 2022 02:00:19 +0200 Subject: [PATCH] improve rendering --- code/foundation/src/gui/inventory.c | 9 +++++++-- code/games/sandbox/src/renderer.c | 7 ++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/code/foundation/src/gui/inventory.c b/code/foundation/src/gui/inventory.c index ee60153..379929f 100644 --- a/code/foundation/src/gui/inventory.c +++ b/code/foundation/src/gui/inventory.c @@ -83,7 +83,11 @@ void inventory_draw_panel(entity_view *e, bool is_player, float sx, float sy){ DrawRectangleLinesEco(x, y, 64, 64, color); if (item->quantity > 0) { - DrawTexturePro(GetSpriteTexture2D(assets_find(item->kind)), ASSET_SRC_RECT(), ASSET_DST_RECT(x,y), (Vector2){0.5f,0.5f}, 0.0f, WHITE); + Texture2D tex = GetSpriteTexture2D(assets_find(item->kind)); + float aspect = tex.width/(float)tex.height; + float size = WORLD_BLOCK_SIZE * aspect; + float ofs_x = (WORLD_BLOCK_SIZE-size)/2.0f; + DrawTexturePro(tex, ASSET_SRC_RECT_TEX(tex.width, tex.height), ASSET_DST_RECT_TEX(x+ofs_x, y, size, WORLD_BLOCK_SIZE), (Vector2){0.5f,0.5f}, 0.0f, WHITE); } if (item->quantity > 1) { @@ -119,7 +123,8 @@ void inventory_render_held_item(bool is_player){ Texture2D tex = GetSpriteTexture2D(assets_find(inv->held_item.kind)); float aspect = tex.width/(float)tex.height; float size = WORLD_BLOCK_SIZE * aspect; - DrawTexturePro(tex, ASSET_SRC_RECT_TEX(tex.width, tex.height), ASSET_DST_RECT_TEX(mpos.x, mpos.y, size, WORLD_BLOCK_SIZE), (Vector2){0.5f,0.5f}, 0.0f, ColorAlpha(WHITE, 0.8f)); + float ofs_x = (WORLD_BLOCK_SIZE-size)/2.0f; + DrawTexturePro(tex, ASSET_SRC_RECT_TEX(tex.width, tex.height), ASSET_DST_RECT_TEX(mpos.x+ofs_x, mpos.y, size, WORLD_BLOCK_SIZE), (Vector2){0.5f,0.5f}, 0.0f, ColorAlpha(WHITE, 0.8f)); DrawTextEco(zpl_bprintf("%d", inv->held_item.quantity), mpos.x, mpos.y, 16, RAYWHITE, 0.0f); if (!inv->is_inside && IsMouseButtonReleased(MOUSE_LEFT_BUTTON) && !inv2->is_inside) { diff --git a/code/games/sandbox/src/renderer.c b/code/games/sandbox/src/renderer.c index 2ccffc2..8c8095e 100644 --- a/code/games/sandbox/src/renderer.c +++ b/code/games/sandbox/src/renderer.c @@ -138,12 +138,13 @@ void renderer_draw_entry(uint64_t key, entity_view *data, game_world_render_entr DrawNametag("Bot", key, data, x, y); }break; case EKIND_ITEM: { - float x = data->x - 32.f; - float y = data->y - 32.f; Texture2D tex = GetSpriteTexture2D(assets_find(data->asset)); + float x = data->x - (tex.width/2); + float y = data->y - (tex.height/4); float aspect = tex.width/(float)tex.height; float size = WORLD_BLOCK_SIZE/2.0f * aspect; - DrawTexturePro(tex, ASSET_SRC_RECT_TEX(tex.width, tex.height), ASSET_DST_RECT_TEX(x,y,size,WORLD_BLOCK_SIZE/2.0f), (Vector2){0.5f,0.5f}, 0.0f, ALPHA(WHITE)); + float ofs_x = (WORLD_BLOCK_SIZE-size)/2.0f; + DrawTexturePro(tex, ASSET_SRC_RECT_TEX(tex.width, tex.height), ASSET_DST_RECT_TEX(x+ofs_x,y,size,WORLD_BLOCK_SIZE/2.0f), (Vector2){0.5f,0.5f}, 0.0f, ALPHA(WHITE)); if (data->quantity > 1) { DrawTextEco(zpl_bprintf("%d", data->quantity), x, y, 10, ALPHA(RAYWHITE), 0.0f);