From a9676bd9397ba4a939a11341c66f7fba6a8293a5 Mon Sep 17 00:00:00 2001 From: Cyril Hrubis Date: Tue, 21 May 2013 23:30:28 +0200 Subject: [PATCH] spiv: Cleanup the progress callback. Cleanup the code a little, draw better progress. Signed-off-by: Cyril Hrubis --- demos/spiv/spiv.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/demos/spiv/spiv.c b/demos/spiv/spiv.c index 87f2e261..5e0352e8 100644 --- a/demos/spiv/spiv.c +++ b/demos/spiv/spiv.c @@ -43,6 +43,7 @@ static GP_Pixel black_pixel; static GP_Pixel white_pixel; +static GP_Pixel gray_pixel; static GP_Backend *backend = NULL; @@ -123,17 +124,21 @@ static int image_loader_callback(GP_ProgressCallback *self) (const char*)self->priv, self->percentage); int align = GP_ALIGN_CENTER|GP_VALIGN_ABOVE; + + size = GP_TextWidth(NULL, buf); - GP_TextClear(c, NULL, c->w/2, c->h - 4, align, - black_pixel, GP_MAX(size, GP_TextWidth(NULL, buf))); + int start = c->w/2 - size/2 - 10; + int end = c->w/2 + size/2 + 10; + int middle = start + (end - start) * self->percentage / 100; + int top = c->h - GP_TextHeight(NULL) - 11; - GP_Text(c, NULL, c->w/2, c->h - 4, align, - white_pixel, black_pixel, buf); + GP_FillRectXYXY(c, start, c->h - 1, middle, top, gray_pixel); + GP_FillRectXYXY(c, middle, c->h - 1, end, top, black_pixel); - size = GP_TextWidth(NULL, buf); + GP_Text(c, NULL, c->w/2, c->h - 5, align, + white_pixel, black_pixel, buf); - GP_BackendUpdateRect(backend, c->w/2 - size/2 - 1, c->h - 4, - c->w/2 + size/2 + 1, c->h - 4 - GP_TextHeight(NULL)); + GP_BackendUpdateRect(backend, start, c->h - 1, end, top); return 0; } @@ -932,6 +937,7 @@ int main(int argc, char *argv[]) black_pixel = GP_ColorToContextPixel(GP_COL_BLACK, context); white_pixel = GP_ColorToContextPixel(GP_COL_WHITE, context); + gray_pixel = GP_RGBToContextPixel(0x33, 0x33, 0x33, context); GP_Fill(context, black_pixel); GP_BackendFlip(backend); -- 2.11.4.GIT