Files
road_pov_template/components/special_area.py
2023-09-22 22:34:19 +08:00

42 lines
1.3 KiB
Python

from utils.font_size import FontSize
from components.text import *
from components.rect import *
from settings import *
class SpecialAreaBaseComponent:
def __init__(self, name, main_color, stroke_color) -> None:
self.name = name
self.main_color = main_color
self.stroke_color = stroke_color
self.p_height = 50 * SCALE
self.inset = 5 * SCALE
self.text_height = self.p_height - 2 * self.inset
self.stroke_width = 2 * SCALE
self.r = 8 * SCALE
def width(self):
text_width = FontSize.get_font_width(self.name, FONT_PATH_A, self.text_height)
return text_width + 2 * self.inset
def height(self):
return self.p_height
def draw(self, container, x, y):
rect = SingleStrokeRectComponent(self.width(), self.height(), self.main_color, self.stroke_color, self.stroke_width, self.r)
rect.draw(container, x, y)
text = TextAComponent(self.name, self.stroke_color, self.text_height)
text.draw(container, x + self.inset, y + self.inset)
class StreetComponent(SpecialAreaBaseComponent):
def __init__(self, name) -> None:
super().__init__(name, COLOR_BLUE, COLOR_WHITE)
class TouristComponent(SpecialAreaBaseComponent):
def __init__(self, name) -> None:
super().__init__(name, COLOR_BROWN, COLOR_WHITE)