Skip to content

Commit 3266801

Browse files
committed
Add console parameter to tcod.context.new.
1 parent b3ff5fb commit 3266801

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

CHANGELOG.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ v2.0.0
88

99
Unreleased
1010
------------------
11+
Added
12+
- New `console` parameter in `tcod.context.new` which sets parameters from an existing Console.
1113

1214
13.1.0 - 2021-10-22
1315
-------------------

tcod/context.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,7 @@ def new(
365365
sdl_window_flags: Optional[int] = None,
366366
title: Optional[str] = None,
367367
argv: Optional[Iterable[str]] = None,
368+
console: Optional[tcod.Console] = None,
368369
) -> Context:
369370
"""Create a new context with the desired pixel size.
370371
@@ -376,6 +377,9 @@ def new(
376377
`columns` and `rows` is the desired size of the console. Can be left as
377378
`None` when you're setting a context by a window size instead of a console.
378379
380+
`console` automatically fills in the `columns` and `rows` parameters from an existing :any:`tcod.console.Console`
381+
instance.
382+
379383
Providing no size information at all is also acceptable.
380384
381385
`renderer` is the desired libtcod renderer to use.
@@ -409,13 +413,19 @@ def new(
409413
the console which should be used.
410414
411415
.. versionadded:: 11.16
416+
417+
.. versionchanged:: 13.2
418+
Added the `console` parameter.
412419
"""
413420
if renderer is None:
414421
renderer = RENDERER_OPENGL2
415422
if sdl_window_flags is None:
416423
sdl_window_flags = SDL_WINDOW_RESIZABLE
417424
if argv is None:
418425
argv = sys.argv
426+
if console is not None:
427+
columns = columns or console.width
428+
rows = rows or console.height
419429
argv_encoded = [ffi.new("char[]", arg.encode("utf-8")) for arg in argv] # Needs to be kept alive for argv_c.
420430
argv_c = ffi.new("char*[]", argv_encoded)
421431

0 commit comments

Comments
 (0)