Moved some drawing code into separate functions

This commit is contained in:
2018-08-14 13:55:01 +02:00
parent 2999d063db
commit 9ed933760c

View File

@@ -100,6 +100,89 @@ def benchmark_draw_post_pixel(arg1, arg2):
draw_image(splash_filepath, 0, image_y, window_width, image_h) draw_image(splash_filepath, 0, image_y, window_width, image_h)
if result_dict: if result_dict:
_draw_benchmark_has_run(image_y, ui_scale, window_width, window_height)
elif result_stats or result_platform or progress_status:
_draw_benchmark_is_running(image_y, result_platform, result_stats, ui_scale, window_width)
else:
_draw_introduction(image_y, ui_scale, window_width, window_height)
# Bottom bar
bottom_x = 0
bottom_y = 0
bottom_w = window_width
bottom_h = 52 * ui_scale
bottom_color = [0.2, 0.2, 0.2, 1.0]
draw_rect(bottom_x, bottom_y, bottom_w, bottom_h, bottom_color)
# Logo
logo_width_unscaled = 326
logo_height_unscaled = 104
logo_dir = os.path.dirname(os.path.abspath(__file__))
logo_filepath = os.path.join(logo_dir, 'blender.png')
logo_scale_factor = 1.0
while logo_height_unscaled * logo_scale_factor > bottom_h:
logo_scale_factor *= 0.5
logo_width = logo_width_unscaled * logo_scale_factor
logo_height = logo_height_unscaled * logo_scale_factor
logo_padding = (bottom_h - logo_height) * 0.5
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 x = 0.5 * window_width
y = 0.70 * window_height y = 0.70 * window_height
@@ -126,73 +209,3 @@ def benchmark_draw_post_pixel(arg1, arg2):
y = image_y - (image_y - 52 * ui_scale - 18 * 3 * ui_scale) * 0.5 y = image_y - (image_y - 52 * ui_scale - 18 * 3 * ui_scale) * 0.5
blf.size(font_id, int(12 * ui_scale), 72) blf.size(font_id, int(12 * ui_scale), 72)
draw_text_multiline(BLURB_TEXT, x, y) draw_text_multiline(BLURB_TEXT, x, y)
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)
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)
# Bottom bar
bottom_x = 0
bottom_y = 0
bottom_w = window_width
bottom_h = 52 * ui_scale
bottom_color = [0.2, 0.2, 0.2, 1.0]
draw_rect(bottom_x, bottom_y, bottom_w, bottom_h, bottom_color)
# Logo
logo_width_unscaled = 326
logo_height_unscaled = 104
logo_dir = os.path.dirname(os.path.abspath(__file__))
logo_filepath = os.path.join(logo_dir, 'blender.png')
logo_scale_factor = 1.0
while logo_height_unscaled * logo_scale_factor > bottom_h:
logo_scale_factor *= 0.5
logo_width = logo_width_unscaled * logo_scale_factor
logo_height = logo_height_unscaled * logo_scale_factor
logo_padding = (bottom_h - logo_height) * 0.5
draw_image(logo_filepath,
logo_padding, logo_padding,
logo_width, logo_height)