From c3a2233138b8d5d9d28395311515f4013d9124da Mon Sep 17 00:00:00 2001 From: Vitaly Driedfruit Date: Sun, 21 Apr 2013 17:27:59 +0400 Subject: [PATCH] Clean up unit face drawing routine a little. --- src/draw.c | 43 ++++++++++++++++--------------------------- 1 file changed, 16 insertions(+), 27 deletions(-) diff --git a/src/draw.c b/src/draw.c index a321e47..629aa76 100644 --- a/src/draw.c +++ b/src/draw.c @@ -191,18 +191,19 @@ void draw_btile(SDL_Renderer *screen, Uint32 sy, Uint32 sx, Uint32 x, Uint32 y, } -void draw_proto(SDL_Renderer *screen, unit_p *p, Uint8 frame, Uint32 x, Uint32 y) { +void draw_proto(SDL_Renderer *screen, unit_p *p, Uint8 axis, Uint8 frame, Uint32 x, Uint32 y) { //unit_p *p = &bunits[u->tile]; SDL_Rect dst = { x, y, p->plane.w, p->plane.h }; //start with plane... SDL_Rect src = { p->plane.x, p->plane.y, p->plane.w, p->plane.h }; - src.x += frame * p->axis_offset[0].w + p->axis_offset[0].x; - src.y += frame * p->axis_offset[0].h + p->axis_offset[0].y; + src.x += frame * p->axis_offset[axis].w + p->axis_offset[axis].x; + src.y += frame * p->axis_offset[axis].h + p->axis_offset[axis].y; SDL_RenderCopy(screen, tiles, &src, &dst); } + void draw_blackbox(SDL_Renderer *screen, Uint32 x, Uint32 y, Uint32 w, Uint32 h) { // Uint32 brown = SDL_MapRGB(screen->format, 0x6c, 0x44, 0x1c); @@ -484,18 +485,15 @@ void draw_minimap(SDL_Renderer *screen) { } void draw_unitname(SDL_Renderer *screen, unit_t *u, Uint32 y, Uint8 offset) { + unit_p *p = &bunits[u->tile]; Uint32 x = ui.log_width - PANE_WIDTH; - Uint8 tile = u->tile; - Uint8 frame = 4; - //draw_blackbox(screen, x, y+2, w, h); - if (tile > 14) { tile -= 14; frame += 5; } - - int icon = unit_icon(u); - if (!u->tile) draw_tile(screen, 0, 0, x, y); else - draw_tile(screen, tile, frame, x + 2, y); + /* :( draw face in bad way */ + if (!u->tile) draw_tile(screen, 0, 0, x, y); + else + draw_proto(screen, p, 0, p->anim[ANIM_FACE][u->faceframe], x, y - (p->h-1)*TILE_H); incolor1(&bunits[u->tile].color); incolor(0x00ffffff, 0); @@ -609,17 +607,14 @@ void draw_unitbox(SDL_Renderer *screen) { unit_t *u = &units[ui.unit]; unit_p *p = &bunits[u->tile]; - Uint8 tile = u->tile; - Uint8 frame = 4; + int icon = unit_icon(u); - if (tile > 14) { tile -= 14; frame += 5; } + /* :( draw face in bad way */ + if (!u->tile) draw_tile(screen, 0, 0, x, y); + else + draw_proto(screen, p, 0, p->anim[ANIM_FACE][u->faceframe], x, y - (p->h-1)*TILE_H); - int icon = unit_icon(u); -if (!u->tile) draw_tile(screen, 0, 0, x, y); else -{ - draw_proto(screen, p, p->anim[ANIM_FACE][u->faceframe], x, y - (p->h-1)*TILE_H); - //draw_tile(screen, tile, frame, x, y); -} + /* Print name */ inprint(screen, u->name, x + 17, y + 3); incolor1(&bunits[u->tile].color); inprint(screen, bunits[u->tile].title, x + 17, y+8+3); @@ -627,6 +622,7 @@ if (!u->tile) draw_tile(screen, 0, 0, x, y); else /* Draw pin */ draw_tile(screen, TILE_UICO_Y, TILE_UICO_X + 4 + u->pin, unitpin.x, unitpin.y); + /* Print state (and draw icon) */ draw_tile(screen, TILE_UICO_Y, TILE_UICO_X + icon, x + 26, y + 114); incolor(state_colors[icon], 0); inprint(screen, state_names[icon], x + 16 + 17, y+110+3); @@ -895,13 +891,6 @@ void draw_units(SDL_Renderer *screen) { exit(-1); } - Uint8 tile = u->tile; - Uint8 frame = u->frame; - Uint8 size = 1; - - SDL_Rect *base = &proto->plane; - - Uint32 by = y; y -= TILE_H * (proto->h - 1); if (u->visiting) continue; -- 2.11.4.GIT