Add Bar Fill Direction

This commit is contained in:
GreenComfyTea
2023-05-26 13:18:46 +03:00
parent e2354eedcc
commit 7ad40bbb89
10 changed files with 300 additions and 33 deletions

View File

@@ -167,7 +167,6 @@ function this.draw_label(label, position, opacity_scale, ...)
end
function this.draw_bar(bar, position, opacity_scale, percentage)
if bar == nil or not bar.visibility then
return;
end
@@ -182,6 +181,7 @@ function this.draw_bar(bar, position, opacity_scale, percentage)
local outline_visibility = bar.outline.visibility;
local style = bar.outline.style; -- Inside/Center/Outside
local fill_direction = bar.settings.fill_direction; -- Left to Right/Right to Left/Top to Bottom/Bottom to Top
local outline_thickness = bar.outline.thickness;
if not outline_visibility then
@@ -206,10 +206,21 @@ function this.draw_bar(bar, position, opacity_scale, percentage)
local position_x = 0;
local position_y = 0;
local foreground_width = 0;
local background_width = 0;
local width = 0;
local height = 0;
local foreground_width = 0;
local foreground_height = 0;
local background_width = 0;
local background_height = 0;
local foreground_shift_x = 0;
local foreground_shift_y = 0;
local background_shift_x = 0;
local background_shift_y = 0;
if style == "Inside" then
outline_position_x = position.x + bar.offset.x + half_outline_thickness;
outline_position_y = position.y + bar.offset.y + half_outline_thickness;
@@ -220,10 +231,7 @@ function this.draw_bar(bar, position, opacity_scale, percentage)
position_x = outline_position_x + half_outline_thickness + outline_offset;
position_y = outline_position_y + half_outline_thickness + outline_offset;
local width = outline_width - outline_thickness - outline_offset - outline_offset;
foreground_width = width * percentage;
background_width = width - foreground_width;
width = outline_width - outline_thickness - outline_offset - outline_offset;
height = outline_height - outline_thickness - outline_offset - outline_offset;
elseif style == "Center" then
@@ -236,22 +244,16 @@ function this.draw_bar(bar, position, opacity_scale, percentage)
position_x = outline_position_x + half_outline_thickness + outline_offset;
position_y = outline_position_y + half_outline_thickness + outline_offset;
local width = outline_width - outline_thickness - outline_offset - outline_offset;
foreground_width = width * percentage;
background_width = width - foreground_width;
width = outline_width - outline_thickness - outline_offset - outline_offset;
height = outline_height - outline_thickness - outline_offset - outline_offset;
else
else -- Outside
position_x = position.x + bar.offset.x;
position_y = position.y + bar.offset.y;
local width = bar.size.width;
width = bar.size.width;
height = bar.size.height;
foreground_width = width * percentage;
background_width = width - foreground_width;
outline_position_x = position_x - half_outline_thickness - outline_offset;
outline_position_y = position_y - half_outline_thickness - outline_offset;
@@ -259,6 +261,43 @@ function this.draw_bar(bar, position, opacity_scale, percentage)
outline_height = height + outline_thickness + outline_offset + outline_offset;
end
if fill_direction == "Right to Left" then
foreground_width = width * percentage;
foreground_height = height;
background_width = width - foreground_width;
background_height = height;
foreground_shift_x = background_width;
elseif fill_direction == "Top to Bottom" then
foreground_width = width;
foreground_height = height * percentage;
background_width = width;
background_height = height - foreground_height;
background_shift_y = foreground_height;
elseif fill_direction == "Bottom to Top" then
foreground_width = width;
foreground_height = height * percentage;
background_width = width;
background_height = height - foreground_height;
foreground_shift_y = background_height;
else -- Left to Right
foreground_width = width * percentage;
foreground_height = height;
background_width = width - foreground_width;
background_height = height;
background_shift_x = foreground_width;
end
local foreground_color = bar.colors.foreground;
local background_color = bar.colors.background;
local outline_color = bar.colors.outline;
@@ -271,35 +310,33 @@ function this.draw_bar(bar, position, opacity_scale, percentage)
local use_d2d = d2d ~= nil and config.current_config.global_settings.renderer.use_d2d_if_available;
-- outline
if outline_thickness ~= 0 then
-- background
if background_width ~= 0 then
if use_d2d then
d2d.outline_rect(outline_position_x, outline_position_y, outline_width, outline_height, outline_thickness,
outline_color);
d2d.fill_rect(position_x + background_shift_x, position_y + background_shift_y, background_width, background_height, background_color);
else
outline_color = this.argb_color_to_abgr_color(outline_color);
draw.outline_rect(outline_position_x, outline_position_y, outline_width, outline_height, outline_color);
background_color = this.argb_color_to_abgr_color(background_color);
draw.filled_rect(position_x + background_shift_x, position_y + background_shift_y, background_width, background_height, background_color)
end
end
-- foreground
if foreground_width ~= 0 then
if use_d2d then
d2d.fill_rect(position_x, position_y, foreground_width, height, foreground_color);
d2d.fill_rect(position_x + foreground_shift_x, position_y + foreground_shift_y, foreground_width, foreground_height, foreground_color);
else
foreground_color = this.argb_color_to_abgr_color(foreground_color);
draw.filled_rect(position_x, position_y, foreground_width, height, foreground_color)
draw.filled_rect(position_x + foreground_shift_x, position_y + foreground_shift_y, foreground_width, foreground_height, foreground_color)
end
end
-- background
if background_width ~= 0 then
-- outline
if outline_thickness ~= 0 then
if use_d2d then
d2d.fill_rect(position_x + foreground_width, position_y, background_width, height, background_color);
d2d.outline_rect(outline_position_x, outline_position_y, outline_width, outline_height, outline_thickness, outline_color);
else
background_color = this.argb_color_to_abgr_color(background_color);
draw.filled_rect(position_x + foreground_width, position_y, background_width, height, background_color)
outline_color = this.argb_color_to_abgr_color(outline_color);
draw.outline_rect(outline_position_x, outline_position_y, outline_width, outline_height, outline_color);
end
end
end