Skip to content

Instantly share code, notes, and snippets.

@FoamyGuy
Created July 8, 2023 15:28
Show Gist options
  • Save FoamyGuy/427a5494c5e74f09ce609a3aabca56e3 to your computer and use it in GitHub Desktop.
Save FoamyGuy/427a5494c5e74f09ce609a3aabca56e3 to your computer and use it in GitHub Desktop.
OutlinedLabel Early Experimends
import time
import board
import bitmaptools
import terminalio
from adafruit_display_text import bitmap_label, outlined_label
import displayio
from adafruit_bitmap_font import bitmap_font
main_group = displayio.Group()
scaled_group = displayio.Group()
background = displayio.OnDiskBitmap("PCB_Background.bmp")
bg_tg = displayio.TileGrid(bitmap=background, pixel_shader=background.pixel_shader)
main_group.append(bg_tg)
display = board.DISPLAY
font_file = "fonts/Arial-Bold-24.bdf"
font = bitmap_font.load_font(font_file)
text = "Hello Show & Tell!"
# text_area = bitmap_label.Label(font, text=text, color=0xffffff,
# padding_left=10, padding_top=10, padding_bottom=10, padding_right=10,
# scale=1)
# text_area.anchor_point = (0, 0)
# text_area.anchored_position = (10, 50)
# main_group.append(text_area)
#
# # print(hex(text_area._palette[0]))
# # print(hex(text_area._palette[1]))
#
# source_bmp = text_area.bitmap
# other_bmp = displayio.Bitmap(source_bmp.width, source_bmp.height, 5)
#
# other_palette = displayio.Palette(5)
# other_palette[0] = text_area._palette[0]
# other_palette[1] = text_area._palette[1]
# other_palette[2] = 0x000000
#
# other_palette.make_transparent(0)
# #other_bmp.blit(0, 0, source_bmp)
# bitmaptools.blit(other_bmp, source_bmp, 0, 0)
#
# other_tg = displayio.TileGrid(bitmap=other_bmp, pixel_shader=other_palette)
# scaled_group.append(other_tg)
#
# main_group.append(scaled_group)
#text_area.background_color = 0x00000
# rect_text_area = outlined_label.OutlinedLabel(font, text=text, color=0xffffff, background_color=0x000000,
# padding_left=2, padding_top=1, padding_bottom=1, padding_right=2,
# scale=1, outline_color=0xff0000, outline_size=2)
rect_text_area = outlined_label.OutlinedLabel(font, text=text, color=0xffffff,
#padding_left=2, padding_top=0, padding_bottom=4, padding_right=1,
scale=1, outline_color=0x00ff00, outline_size=2)
rect_text_area.anchor_point = (0,0)
rect_text_area.anchored_position = (10, 100)
main_group.append(rect_text_area)
def add_outline(bitmap, target_color_index, outline_color_index, size=1):
before = time.monotonic()
stamp_source = displayio.Bitmap((size * 2) + 1, (size * 2) + 1, outline_color_index + 1)
stamp_source.fill(outline_color_index)
for y in range(bitmap.height):
for x in range(bitmap.width):
if bitmap[x, y] == target_color_index:
# bitmap.blit(x-size,y-size, stamp_source, skip_self_index=target_color_index)
bitmaptools.blit(bitmap, stamp_source, x - size, y - size, skip_dest_index=target_color_index)
#bitmaptools.blit(bitmap, stamp_source, x - size, y - size)
# for y_loc in range(-size, size+1):
# for x_loc in range(-size, size+1):
# if bitmap[x+x_loc, y+y_loc] != target_color_index:
# bitmap[x + x_loc, y + y_loc] = outline_color_index
after = time.monotonic()
print(f"took: {after - before}")
#add_outline(other_bmp, 1, 2, 2)
display.show(main_group)
time.sleep(3)
rect_text_area.color = 0x000000
rect_text_area.background_color = 0xFFFF00
rect_text_area.text = "Hello Deep Dive!"
rect_text_area.outline_color = 0xff0000
rect_text_area.outline_size = 5
while True:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment