From 9ed933760c286692273796e4e5d255f95204087d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Tue, 14 Aug 2018 13:55:01 +0200 Subject: [PATCH] Moved some drawing code into separate functions --- benchmark/space/draw.py | 153 ++++++++++++++++++++++------------------ 1 file changed, 83 insertions(+), 70 deletions(-) diff --git a/benchmark/space/draw.py b/benchmark/space/draw.py index 42130b8..96e0d54 100644 --- a/benchmark/space/draw.py +++ b/benchmark/space/draw.py @@ -100,78 +100,11 @@ def benchmark_draw_post_pixel(arg1, arg2): draw_image(splash_filepath, 0, image_y, window_width, image_h) if result_dict: - x = 0.5 * window_width - y = 0.70 * window_height - - score = 0 - for name_stats in G.result_dict["scenes"]: - stat = name_stats['stats'] - if stat["result"] == "OK": - score += stat["total_render_time"] - else: - score = -1 - - if score >= 0: - blf.size(font_id, int(32 * ui_scale), 72) - draw_text_center("Your Time: {}".format( - util.humanReadableTimeDifference(score)), x, y, shadow=True) - else: - blf.size(font_id, int(18 * ui_scale), 72) - draw_text_center("Unfortunately, crash happened :(", x, y, shadow=True) - blf.size(font_id, int(24 * ui_scale), 72) - draw_text_center("You can still share data of succeeded scenes!", - x, y - 26 * ui_scale, shadow=True) - - x = 50.0 * ui_scale - y = image_y - (image_y - 52 * ui_scale - 18 * 3 * ui_scale) * 0.5 - blf.size(font_id, int(12 * ui_scale), 72) - draw_text_multiline(BLURB_TEXT, x, y) + _draw_benchmark_has_run(image_y, ui_scale, window_width, window_height) elif result_stats or result_platform or progress_status: - blf.size(font_id, int(12 * ui_scale), 72) - - x = 50.0 * ui_scale - y = image_y - 20 * ui_scale - - # Stats - if result_platform: - draw_text_multiline(result_platform, 0.5 * window_width + x, y) - if result_stats: - draw_text_multiline(result_stats, x, y) - - # Progress - progress_x = 0.0 - progress_y = image_y + 1 - progress_w = window_width * G.current_progress - progress_h = 15.0 * ui_scale - progress_color = [0.8, 1.0, 1.0, 0.2] - - draw_rect(progress_x, progress_y, progress_w, progress_h, progress_color) - - # Current status - if G.progress_status: - blf.size(font_id, int(18 * ui_scale), 72) - draw_text_multiline(G.progress_status, - progress_x + 8.0 * ui_scale, - progress_y + progress_h + int(22 * ui_scale), - shadow=True) + _draw_benchmark_is_running(image_y, result_platform, result_stats, ui_scale, window_width) else: - # Title - x = 0.5 * window_width - y = 0.70 * window_height - - blf.size(font_id, int(32 * ui_scale), 72) - draw_text_center("Blender Benchmark 1.0 Beta", x, y, shadow=True) - - y -= 32 * ui_scale - - blf.size(font_id, int(12 * ui_scale), 72) - draw_text_center("Free and Open Data for everyone.", - x, y, shadow=True) - - x = 50.0 * ui_scale - y = image_y - (image_y - 52 * ui_scale - 18 * 3 * ui_scale) * 0.5 - blf.size(font_id, int(12 * ui_scale), 72) - draw_text_multiline(WELCOME_TEXT, x, y) + _draw_introduction(image_y, ui_scale, window_width, window_height) # Bottom bar bottom_x = 0 @@ -196,3 +129,83 @@ def benchmark_draw_post_pixel(arg1, arg2): draw_image(logo_filepath, logo_padding, logo_padding, logo_width, logo_height) + + +def _draw_introduction(image_y, ui_scale, window_width, window_height): + """Draw title and welcome text.""" + + x = 0.5 * window_width + y = 0.70 * window_height + blf.size(font_id, int(32 * ui_scale), 72) + draw_text_center("Blender Benchmark 1.0 Beta", x, y, shadow=True) + + y -= 32 * ui_scale + blf.size(font_id, int(12 * ui_scale), 72) + draw_text_center("Free and Open Data for everyone.", + x, y, shadow=True) + + x = 50.0 * ui_scale + y = image_y - (image_y - 52 * ui_scale - 18 * 3 * ui_scale) * 0.5 + blf.size(font_id, int(12 * ui_scale), 72) + draw_text_multiline(WELCOME_TEXT, x, y) + + +def _draw_benchmark_is_running(image_y, result_platform, result_stats, ui_scale, window_width): + """Draw while the benchmark is running.""" + + blf.size(font_id, int(12 * ui_scale), 72) + x = 50.0 * ui_scale + y = image_y - 20 * ui_scale + + # Stats + if result_platform: + draw_text_multiline(result_platform, 0.5 * window_width + x, y) + if result_stats: + draw_text_multiline(result_stats, x, y) + + # Progress + progress_x = 0.0 + progress_y = image_y + 1 + progress_w = window_width * G.current_progress + progress_h = 15.0 * ui_scale + progress_color = [0.8, 1.0, 1.0, 0.2] + draw_rect(progress_x, progress_y, progress_w, progress_h, progress_color) + + # Current status + if G.progress_status: + blf.size(font_id, int(18 * ui_scale), 72) + draw_text_multiline(G.progress_status, + progress_x + 8.0 * ui_scale, + progress_y + progress_h + int(22 * ui_scale), + shadow=True) + + +def _draw_benchmark_has_run(image_y, ui_scale, window_width, window_height): + """Draw submit button and other after-running stuff.""" + + x = 0.5 * window_width + y = 0.70 * window_height + + score = 0 + for name_stats in G.result_dict["scenes"]: + stat = name_stats['stats'] + if stat["result"] == "OK": + score += stat["total_render_time"] + else: + score = -1 + + if score >= 0: + blf.size(font_id, int(32 * ui_scale), 72) + draw_text_center("Your Time: {}".format( + util.humanReadableTimeDifference(score)), x, y, shadow=True) + else: + blf.size(font_id, int(18 * ui_scale), 72) + draw_text_center("Unfortunately, crash happened :(", x, y, shadow=True) + blf.size(font_id, int(24 * ui_scale), 72) + draw_text_center("You can still share data of succeeded scenes!", + x, y - 26 * ui_scale, shadow=True) + + x = 50.0 * ui_scale + y = image_y - (image_y - 52 * ui_scale - 18 * 3 * ui_scale) * 0.5 + blf.size(font_id, int(12 * ui_scale), 72) + draw_text_multiline(BLURB_TEXT, x, y)