added CTRL+LMB drag
This commit is contained in:
parent
68b1496427
commit
509c7fec8a
@ -29,7 +29,8 @@ class Editor:
|
|||||||
self.running: bool = False
|
self.running: bool = False
|
||||||
self.image_handler: ImageHandler = ImageHandler(self.MAPS_DIR, self.MAP_SIZE)
|
self.image_handler: ImageHandler = ImageHandler(self.MAPS_DIR, self.MAP_SIZE)
|
||||||
self.clock: pygame.time.Clock = pygame.time.Clock()
|
self.clock: pygame.time.Clock = pygame.time.Clock()
|
||||||
self.drag_pos: Optional[tuple[int, int]] = None
|
self.left_drag_pos: Optional[tuple[int, int]] = None
|
||||||
|
self.mid_drag_pos: Optional[tuple[int, int]] = None
|
||||||
self.font: pygame.font.Font = pygame.font.SysFont("Ubuntu", 20)
|
self.font: pygame.font.Font = pygame.font.SysFont("Ubuntu", 20)
|
||||||
self.loading_font: pygame.font.Font = pygame.font.SysFont("Ubuntu", 30)
|
self.loading_font: pygame.font.Font = pygame.font.SysFont("Ubuntu", 30)
|
||||||
self.zooms_texts: list[pygame.Surface] = list(map(
|
self.zooms_texts: list[pygame.Surface] = list(map(
|
||||||
@ -54,6 +55,7 @@ class Editor:
|
|||||||
def process_events(self) -> None:
|
def process_events(self) -> None:
|
||||||
events = pygame.event.get()
|
events = pygame.event.get()
|
||||||
|
|
||||||
|
keys = pygame.key.get_pressed()
|
||||||
for event in events:
|
for event in events:
|
||||||
if event.type == pygame.QUIT:
|
if event.type == pygame.QUIT:
|
||||||
self.state = State.STOPPING
|
self.state = State.STOPPING
|
||||||
@ -69,12 +71,19 @@ class Editor:
|
|||||||
self.zoom_out()
|
self.zoom_out()
|
||||||
elif event.type == pygame.MOUSEBUTTONDOWN:
|
elif event.type == pygame.MOUSEBUTTONDOWN:
|
||||||
if event.button == 2:
|
if event.button == 2:
|
||||||
self.drag_pos = event.pos
|
self.mid_drag_pos = event.pos
|
||||||
|
elif event.button == 1 and keys[pygame.K_LCTRL]:
|
||||||
|
self.left_drag_pos = event.pos
|
||||||
|
elif event.button == 4:
|
||||||
|
self.zoom_in()
|
||||||
|
elif event.button == 5:
|
||||||
|
self.zoom_out()
|
||||||
elif event.type == pygame.MOUSEBUTTONUP:
|
elif event.type == pygame.MOUSEBUTTONUP:
|
||||||
if event.button == 2:
|
if event.button == 2:
|
||||||
self.drag_pos = None
|
self.mid_drag_pos = None
|
||||||
|
elif event.button == 1:
|
||||||
|
self.left_drag_pos = None
|
||||||
|
|
||||||
keys = pygame.key.get_pressed()
|
|
||||||
if keys[pygame.K_LEFT]:
|
if keys[pygame.K_LEFT]:
|
||||||
self.center[0] -= 4 / self.zoom
|
self.center[0] -= 4 / self.zoom
|
||||||
if keys[pygame.K_RIGHT]:
|
if keys[pygame.K_RIGHT]:
|
||||||
@ -86,12 +95,16 @@ class Editor:
|
|||||||
|
|
||||||
mbtns = pygame.mouse.get_pressed()
|
mbtns = pygame.mouse.get_pressed()
|
||||||
mpos = pygame.mouse.get_pos()
|
mpos = pygame.mouse.get_pos()
|
||||||
if mbtns[1]:
|
if mbtns[1] or (mbtns[0] and keys[pygame.K_LCTRL]):
|
||||||
dx = mpos[0] - self.drag_pos[0]
|
drag_pos = self.mid_drag_pos if mbtns[1] else self.left_drag_pos
|
||||||
dy = mpos[1] - self.drag_pos[1]
|
dx = mpos[0] - drag_pos[0]
|
||||||
|
dy = mpos[1] - drag_pos[1]
|
||||||
self.center[0] -= dx / self.zoom
|
self.center[0] -= dx / self.zoom
|
||||||
self.center[1] -= dy / self.zoom
|
self.center[1] -= dy / self.zoom
|
||||||
self.drag_pos = mpos
|
if mbtns[0] and keys[pygame.K_LCTRL]:
|
||||||
|
self.left_drag_pos = mpos
|
||||||
|
if mbtns[1]:
|
||||||
|
self.mid_drag_pos = mpos
|
||||||
|
|
||||||
def render(self) -> None:
|
def render(self) -> None:
|
||||||
self.win.fill((0, 0, 0))
|
self.win.fill((0, 0, 0))
|
||||||
|
Loading…
Reference in New Issue
Block a user