added methods for interactive mode
This commit is contained in:
@@ -27,9 +27,6 @@ class MapDisplay:
|
||||
|
||||
self.font = pygame.font.SysFont("ubuntu", 20)
|
||||
|
||||
for city in self.cities:
|
||||
self.draw_city(*city)
|
||||
|
||||
def real_to_screen(self, lon: float, lat: float) -> tuple[float, float]:
|
||||
x = (lon - self.min_lon) / (self.max_lon - self.min_lon)
|
||||
y = (lat - self.min_lat) / (self.max_lat - self.min_lat)
|
||||
@@ -65,6 +62,10 @@ class MapDisplay:
|
||||
|
||||
pygame.draw.lines(self.surf, (255, 255, 255), True, points)
|
||||
|
||||
def draw_cities(self) -> None:
|
||||
for city in self.cities:
|
||||
self.draw_city(*city)
|
||||
|
||||
def draw_city(self, pos: Vec2, name: str, label_side: str) -> None:
|
||||
pos2 = Vec2(*self.real_to_screen(pos.x, pos.y))
|
||||
|
||||
@@ -94,3 +95,33 @@ class MapDisplay:
|
||||
|
||||
pygame.draw.line(self.surf, (255, 255, 255), (pos2.x, pos2.y), (line_end.x, line_end.y))
|
||||
self.surf.blit(label, (label_pos.x, label_pos.y))
|
||||
|
||||
def mainloop(self) -> None:
|
||||
running = True
|
||||
|
||||
self.init_interactive()
|
||||
|
||||
clock = pygame.time.Clock()
|
||||
while running:
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.QUIT:
|
||||
running = False
|
||||
|
||||
elif event.type == pygame.KEYDOWN:
|
||||
if event.key == pygame.K_ESCAPE:
|
||||
running = False
|
||||
|
||||
elif event.key == pygame.K_s and event.mod & pygame.KMOD_CTRL:
|
||||
path = "/tmp/image.jpg"
|
||||
pygame.image.save(self.surf, path)
|
||||
print(f"Saved as {path}")
|
||||
|
||||
self.render()
|
||||
pygame.display.flip()
|
||||
clock.tick(30)
|
||||
|
||||
def init_interactive(self) -> None:
|
||||
pass
|
||||
|
||||
def render(self) -> None:
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user