Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Advanced radials #500

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 74 additions & 3 deletions library/lcd/lcd_comm.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,29 @@ def DisplayLineGraph(self, x: int, y: int, width: int, height: int,

self.DisplayPILImage(graph_image, x, y)

def DrawRadialDecoration(self, draw: ImageDraw, angle: float, radius: float, width: float, color: Tuple[int, int, int] = (0, 0, 0)):
i_cos = math.cos(angle*math.pi/180)
i_sin = math.sin(angle*math.pi/180)
x_f = (i_cos * (radius - width/2)) + radius
if math.modf(x_f) == 0.5:
if i_cos > 0:
x_f = math.floor(x_f)
else:
x_f = math.ceil(x_f)
else:
x_f = math.floor(x_f + 0.5)

y_f = (i_sin * (radius - width/2)) + radius
if math.modf(y_f) == 0.5:
if i_sin > 0:
y_f = math.floor(y_f)
else:
y_f = math.ceil(y_f)
else:
y_f = math.floor(y_f + 0.5)
draw.ellipse([x_f - width/2, y_f - width/2, x_f + width/2, y_f - 1 + width/2 - 1], outline=color, fill=color, width=1)


def DisplayRadialProgressBar(self, xc: int, yc: int, radius: int, bar_width: int,
min_value: int = 0,
max_value: int = 100,
Expand All @@ -436,7 +459,12 @@ def DisplayRadialProgressBar(self, xc: int, yc: int, radius: int, bar_width: int
font_color: Tuple[int, int, int] = (0, 0, 0),
bar_color: Tuple[int, int, int] = (0, 0, 0),
background_color: Tuple[int, int, int] = (255, 255, 255),
background_image: str = None):
background_image: str = None,
custom_bbox: Tuple[int, int, int, int] = (0, 0, 0, 0),
text_offset: Tuple[int, int] = (0,0),
bar_background_color: Tuple[int, int, int] = (0, 0, 0),
draw_bar_background: bool = False,
bar_decoration: str = ""):
# Generate a radial progress bar and display it
# Provide the background image path to display progress bar with transparent background

Expand All @@ -449,6 +477,9 @@ def DisplayRadialProgressBar(self, xc: int, yc: int, radius: int, bar_width: int
if isinstance(font_color, str):
font_color = tuple(map(int, font_color.split(', ')))

if isinstance(bar_background_color, str):
bar_background_color = tuple(map(int, bar_background_color.split(', ')))

if angle_start % 361 == angle_end % 361:
if clockwise:
angle_start += 0.1
Expand Down Expand Up @@ -500,6 +531,23 @@ def DisplayRadialProgressBar(self, xc: int, yc: int, radius: int, bar_width: int
ecart = 360 - angle_start + angle_end
else:
ecart = angle_end - angle_start

# draw bar background
if draw_bar_background:
if angle_end < angle_start:
angleE = angle_start + ecart
angleS = angle_start
else:
angleS = angle_start
angleE = angle_start + ecart
draw.arc([0, 0, diameter - 1, diameter - 1], angleS, angleE, fill=bar_background_color, width=bar_width)

# draw bar decoration
if bar_decoration == "Ellipse":
self.DrawRadialDecoration(draw = draw, angle = angle_end, radius = radius, width = bar_width, color = bar_background_color)
self.DrawRadialDecoration(draw = draw, angle = angle_start, radius = radius, width = bar_width, color = bar_color)
self.DrawRadialDecoration(draw = draw, angle = angle_start + pct * ecart, radius = radius, width = bar_width, color = bar_color)

#
# solid bar case
if angle_sep == 0:
Expand Down Expand Up @@ -533,6 +581,25 @@ def DisplayRadialProgressBar(self, xc: int, yc: int, radius: int, bar_width: int
ecart = angle_start - angle_end
else:
ecart = 360 - angle_end + angle_start

# draw bar background
if draw_bar_background:
if angle_end < angle_start:
angleE = angle_start
angleS = angle_start - ecart
else:
angleS = angle_start - ecart
angleE = angle_start
draw.arc([0, 0, diameter - 1, diameter - 1], angleS, angleE, fill=bar_background_color, width=bar_width)


# draw bar decoration
if bar_decoration == "Ellipse":
self.DrawRadialDecoration(draw = draw, angle = angle_end, radius = radius, width = bar_width, color = bar_background_color)
self.DrawRadialDecoration(draw = draw, angle = angle_start, radius = radius, width = bar_width, color = bar_color)
self.DrawRadialDecoration(draw = draw, angle = angle_start - pct * ecart, radius = radius, width = bar_width, color = bar_color)

#
# solid bar case
if angle_sep == 0:
if angle_end < angle_start:
Expand Down Expand Up @@ -568,10 +635,14 @@ def DisplayRadialProgressBar(self, xc: int, yc: int, radius: int, bar_width: int
font = ImageFont.truetype("./res/fonts/" + font, font_size)
left, top, right, bottom = font.getbbox(text)
w, h = right - left, bottom - top
draw.text((radius - w / 2, radius - top - h / 2), text,
draw.text((radius - w / 2 + text_offset[0], radius - top - h / 2 + text_offset[1]), text,
font=font, fill=font_color)

self.DisplayPILImage(bar_image, xc - radius, yc - radius)
if custom_bbox[0] != 0 or custom_bbox[1] != 0 or custom_bbox[2] != 0 or custom_bbox[3] != 0:
bar_image = bar_image.crop(box=custom_bbox)

self.DisplayPILImage(bar_image, xc - radius + custom_bbox[0], yc - radius + custom_bbox[1])
# self.DisplayPILImage(bar_image, xc - radius, yc - radius)

# Load image from the filesystem, or get from the cache if it has already been loaded previously
def open_image(self, bitmap_path: str) -> Image:
Expand Down
11 changes: 8 additions & 3 deletions library/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,12 @@ def display_themed_radial_bar(theme_data, value, min_size=0, unit='', custom_tex
font_size=theme_data.get("FONT_SIZE", 10),
font_color=theme_data.get("FONT_COLOR", (0, 0, 0)),
background_color=theme_data.get("BACKGROUND_COLOR", (0, 0, 0)),
background_image=get_theme_file_path(theme_data.get("BACKGROUND_IMAGE", None))
background_image=get_theme_file_path(theme_data.get("BACKGROUND_IMAGE", None)),
custom_bbox=theme_data.get("CUSTOM_BBOX", (0, 0, 0, 0)),
text_offset=theme_data.get("TEXT_OFFSET", (0, 0)),
bar_background_color = theme_data.get("BAR_BACKGROUND_COLOR", (0, 0, 0)),
draw_bar_background = theme_data.get("DRAW_BAR_BACKGROUND", False),
bar_decoration = theme_data.get("BAR_DECORATION", "")
)


Expand Down Expand Up @@ -313,8 +318,8 @@ def temperature(cls):
cpu_temp_line_graph_data['SHOW'] = False

display_themed_temperature_value(cpu_temp_text_data, temperature)
display_themed_progress_bar(cpu_temp_radial_data, temperature)
display_themed_temperature_radial_bar(cpu_temp_graph_data, temperature)
display_themed_progress_bar(cpu_temp_graph_data, temperature)
display_themed_temperature_radial_bar(cpu_temp_radial_data, temperature)
display_themed_line_graph(cpu_temp_line_graph_data, cls.last_values_cpu_temperature)

@classmethod
Expand Down
4 changes: 4 additions & 0 deletions res/themes/Advanced Radials Test/Credits.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
### Credits for graphical resources used from freepik

Acknowledgements for resources :

Binary file added res/themes/Advanced Radials Test/background.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/themes/Advanced Radials Test/preview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading