From 95a0b87d392c994bcde74ddbcf34f9f520efd13f Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Sat, 21 Mar 2020 17:37:49 +0100 Subject: We got percent --- src/ft_draw_life_bar.c | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) (limited to 'src/ft_draw_life_bar.c') diff --git a/src/ft_draw_life_bar.c b/src/ft_draw_life_bar.c index 4fd8a84..28a7110 100644 --- a/src/ft_draw_life_bar.c +++ b/src/ft_draw_life_bar.c @@ -14,10 +14,24 @@ #include #include -/* static void */ -/* ft_draw_tnum(int8_t id, int16_t y, int16_t x, t_cub *cl) */ -/* { */ -/* } */ +static void + ft_draw_tnum(int8_t id, int16_t y, int16_t x, t_cub *cl) +{ + const int16_t scl = cl->mlist.scale; + + cl->img.ptr[x * 4 + (cl->img.sizeline * (y + + cl->wlist.y_size - (cl->mlist.map_h * scl) - 10))] = + (uint8_t)cl->tnum[id].ptr[cl->tnum[id].tex_x * 4 + 4 * + cl->tnum[id].img_w * cl->tnum[id].tex_y]; + cl->img.ptr[x * 4 + (cl->img.sizeline * (y + + cl->wlist.y_size - (cl->mlist.map_h * scl) - 10)) + 1] = + (uint8_t)cl->tnum[id].ptr[cl->tnum[id].tex_x * 4 + 4 * + cl->tnum[id].img_w * cl->tnum[id].tex_y + 1]; + cl->img.ptr[x * 4 + (cl->img.sizeline * (y + + cl->wlist.y_size - (cl->mlist.map_h * scl) - 10)) + 2] = + (uint8_t)cl->tnum[id].ptr[cl->tnum[id].tex_x * 4 + 4 * + cl->tnum[id].img_w * cl->tnum[id].tex_y + 2]; +} /* static void */ /* ft_put_image_from_number(char *num, t_cub *cl) */ @@ -35,9 +49,8 @@ static void x_ratio = (int)(((cl->tnum[10].img_w) << 16) / w) + 1; y_ratio = (int)(((cl->tnum[10].img_h) << 16) / h) + 1; - /* y = cl->wlist.y_size - (cl->mlist.map_h * scl) - 10; */ y = 0; - while (y < (int32_t)(cl->wlist.y_size - 10)) + while (y < h) { cl->tnum[10].tex_y = ((y * y_ratio) >> 16); x = ((cl->mlist.map_w * scl) + 20) + (32 * scl) - ((32 * scl) / 4); @@ -47,15 +60,7 @@ static void if (cl->tnum[10].ptr[cl->tnum[10].tex_x * 4 + 4 * cl->tnum[10].img_h * cl->tnum[10].tex_y]) { - cl->img.ptr[x * 4 + (cl->img.sizeline * y)] = - (uint8_t)cl->tnum[10].ptr[cl->tnum[10].tex_x * 4 + 4 * - cl->tnum[10].img_w * cl->tnum[10].tex_y]; - cl->img.ptr[x * 4 + (cl->img.sizeline * y) + 1] = - (uint8_t)cl->tnum[10].ptr[cl->tnum[10].tex_x * 4 + 4 * - cl->tnum[10].img_w * cl->tnum[10].tex_y + 1]; - cl->img.ptr[x * 4 + (cl->img.sizeline * y) + 2] = - (uint8_t)cl->tnum[10].ptr[cl->tnum[10].tex_x * 4 + 4 * - cl->tnum[10].img_w * cl->tnum[10].tex_y + 2]; + ft_draw_tnum(10, y, x, cl); } x++; } @@ -80,7 +85,6 @@ static void } y -= cl->wlist.y_size - (cl->mlist.map_h * scl) - 10; x -= ((cl->mlist.map_w * scl) + 20) + (32 * scl) - ((32 * scl) / 4); - ft_printf("h %hu | w %hu\n", y, x); ft_put_percent_image(y, x, cl); } @@ -94,6 +98,6 @@ void calc = ((float)cl->plist.life / (float)FT_STRT_LIFE) * 100.0; if (!(num = ft_itoa((int64_t)calc))) ft_error(FT_RET_ALLOC_ERR, FT_ERR_ALLOCATE, cl); - /* ft_put_image_from_number(num, cl); */ + ft_put_image_from_number(num, cl); ft_memdel((void*)&num); } -- cgit v1.2.3