From e0c422972b926b717d9d95dd90fd0b8c37cd3d10 Mon Sep 17 00:00:00 2001 From: Sebastian Krzyszkowiak Date: Thu, 16 Mar 2017 22:05:22 +0100 Subject: [PATCH] add TM_DrawDebug: debug view for timelines --- src/timeline.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ src/timeline.h | 2 ++ 2 files changed, 50 insertions(+) diff --git a/src/timeline.c b/src/timeline.c index 7408424..95302cd 100644 --- a/src/timeline.c +++ b/src/timeline.c @@ -349,6 +349,54 @@ SYMBOL_EXPORT void TM_CleanBackgroundQueue(struct Timeline* timeline) { timeline->background = NULL; } +SYMBOL_INTERNAL void DrawQueue(struct Game *game, struct TM_Action* queue, int clipX, int clipY) { + + int pos = clipX; + + struct TM_Action *pom = queue; + while (pom!=NULL) { + + int width = al_get_text_width(game->_priv.font_console, pom->name); + al_draw_filled_rectangle(pos-10, clipY, pos+width+10, clipY+ 60, pom->active ? al_map_rgba(255,255,255,192) : al_map_rgba(0, 0, 0, 0) ); + al_draw_rectangle(pos-10, clipY, pos+width+10, clipY+ 60, al_map_rgb(255,255,255), 2); + al_draw_text(game->_priv.font_console, pom->active ? al_map_rgb(0,0,0) : al_map_rgb(255,255,255), pos, clipY, ALLEGRO_ALIGN_LEFT, pom->name); + + if (pom->delay) { + al_draw_textf(game->_priv.font_console, al_map_rgb(255,255,255), pos, clipY - 50, ALLEGRO_ALIGN_LEFT, "%d", pom->delay); + } + + if (pom->function == *runinbackground) { + al_draw_textf(game->_priv.font_console, al_map_rgb(255,255,255), pos, clipY - 50, ALLEGRO_ALIGN_LEFT, "%s", (char*)pom->arguments->next->next->value); + } + + pos += width + 20; + pom = pom->next; + } +} + +SYMBOL_EXPORT void TM_DrawDebug(struct Game *game, struct Timeline* timeline, int pos) { + + if (!game->_priv.showconsole) { + return; + } + + al_set_target_backbuffer(game->display); + ALLEGRO_TRANSFORM trans; + al_identity_transform(&trans); + int clipX, clipY, clipWidth, clipHeight; + al_get_clipping_rectangle(&clipX, &clipY, &clipWidth, &clipHeight); + al_use_transform(&trans); + + al_draw_filled_rectangle(clipX, clipY+clipHeight-340*(pos+1), clipX + clipWidth, clipY+clipHeight-340*pos, al_map_rgba(0,0,0,92)); + + al_draw_textf(game->_priv.font_console, al_map_rgb(255,255,255), clipX + clipWidth / 2, clipY+clipHeight-340*(pos+1) + 10, ALLEGRO_ALIGN_CENTER, "Timeline: %s", timeline->name); + + DrawQueue(game, timeline->queue, clipX + 25, clipY + clipHeight - 220 - 340*pos); + DrawQueue(game, timeline->background, clipX + 25, clipY + clipHeight - 100 - 340*pos); + + al_use_transform(&game->projection); +} + SYMBOL_EXPORT void TM_SkipDelay(struct Timeline* timeline) { if (timeline->queue && timeline->queue->timer) { al_stop_timer(timeline->queue->timer); diff --git a/src/timeline.h b/src/timeline.h index e27ecbe..cbbd082 100644 --- a/src/timeline.h +++ b/src/timeline.h @@ -102,5 +102,7 @@ void TM_SkipDelay(struct Timeline*); bool TM_IsEmpty(struct Timeline* timeline); /*! \brief Checks if the background queue is empty */ bool TM_IsBackgroundEmpty(struct Timeline* timeline); +/*! \brief Draws debug info when console is visible */ +void TM_DrawDebug(struct Game *game, struct Timeline* timeline, int pos); #endif