|
1 | 1 | #!/usr/bin/env python3 |
2 | | -""" |
3 | | -This code demonstrates various usages of python-tcod. |
4 | | -""" |
| 2 | +"""This code demonstrates various usages of python-tcod.""" |
5 | 3 | # To the extent possible under law, the libtcod maintainers have waived all |
6 | 4 | # copyright and related or neighboring rights to these samples. |
7 | 5 | # https://creativecommons.org/publicdomain/zero/1.0/ |
@@ -1412,7 +1410,7 @@ def init_context(renderer: int) -> None: |
1412 | 1410 | context = tcod.context.new( |
1413 | 1411 | columns=root_console.width, |
1414 | 1412 | rows=root_console.height, |
1415 | | - title=f"python-tcod samples" f" (python-tcod {tcod.__version__}, libtcod {libtcod_version})", |
| 1413 | + title=f"python-tcod samples (python-tcod {tcod.__version__}, libtcod {libtcod_version})", |
1416 | 1414 | renderer=renderer, |
1417 | 1415 | vsync=False, # VSync turned off since this is for benchmarking. |
1418 | 1416 | tileset=tileset, |
@@ -1488,7 +1486,19 @@ def handle_time() -> None: |
1488 | 1486 |
|
1489 | 1487 | def handle_events() -> None: |
1490 | 1488 | for event in tcod.event.get(): |
1491 | | - context.convert_event(event) |
| 1489 | + if context.sdl_renderer: |
| 1490 | + # Manual handing of tile coordinates since context.present is skipped. |
| 1491 | + if isinstance(event, (tcod.event.MouseState, tcod.event.MouseMotion)): |
| 1492 | + event.tile = tcod.event.Point(event.pixel.x // tileset.tile_width, event.pixel.y // tileset.tile_height) |
| 1493 | + if isinstance(event, tcod.event.MouseMotion): |
| 1494 | + prev_tile = ( |
| 1495 | + (event.pixel[0] - event.pixel_motion[0]) // tileset.tile_width, |
| 1496 | + (event.pixel[1] - event.pixel_motion[1]) // tileset.tile_height, |
| 1497 | + ) |
| 1498 | + event.tile_motion = tcod.event.Point(event.tile[0] - prev_tile[0], event.tile[1] - prev_tile[1]) |
| 1499 | + else: |
| 1500 | + context.convert_event(event) |
| 1501 | + |
1492 | 1502 | SAMPLES[cur_sample].dispatch(event) |
1493 | 1503 | if isinstance(event, tcod.event.Quit): |
1494 | 1504 | raise SystemExit() |
|
0 commit comments