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

47 lines
1.4 KiB
Python

from utils.font_size import FontSize
from components.text import *
from components.rect import *
from settings import *
class CommonRoadBaseComponent:
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 = 10 * SCALE
self.stroke_width = 2 * SCALE
self.r = 8 * SCALE
def width(self):
text_width = FontSize.get_font_width(self.name, FONT_PATH_B, self.p_height)
return text_width + self.inset * 2
def height(self):
return self.p_height
def draw(self, container, x, y):
rect = SingleStrokeRectComponent(self.width(), self.p_height, self.main_color, self.stroke_color, self.stroke_width, self.r)
rect.draw(container, x, y)
text = TextBComponent(self.name, self.stroke_color, self.p_height)
text.draw(container, x + self.inset, y)
class CommonRoadNationalComponent(CommonRoadBaseComponent):
def __init__(self, name) -> None:
super().__init__(name, COLOR_RED, COLOR_WHITE)
class CommonRoadProvincialComponent(CommonRoadBaseComponent):
def __init__(self, name) -> None:
super().__init__(name, COLOR_YELLOW, COLOR_BLACK)
class CommonRoadTownshipComponent(CommonRoadBaseComponent):
def __init__(self, name) -> None:
super().__init__(name, COLOR_WHITE, COLOR_BLACK)