Class PygameDisplay
A PygameContext's display (pygame.display): the one window the context draws into through
its surface, opened by SetMode(int, int, bool, EnvViewerFactory?, string?), shown by Flip(), closed by Quit().
Play plays an env in it. The window is a viewer from the viewer factory (DR-20), so it is
an Avalonia or WinForms window, or nothing at all under NullEnvViewer.
public sealed class PygameDisplay
- Inheritance
-
PygameDisplay
- Inherited Members
- Extension Methods
Remarks
One per context, as pygame has one per process: SetMode(int, int, bool, EnvViewerFactory?, string?) while a window is open replaces it. Other contexts' displays and the human-mode windows of envs are separate viewers and are not affected. The static Display is Default's.
The surface is opaque 32-bit (XRGB8888), black when the mode is set, as pygame's display surface. When the
window is an IInteractiveEnvViewer, its input reaches the context's PygameEventQueue as
pygame's events when the queue is pumped: KeyDown and KeyUp with
key, the close button as WindowClose then Quit, and a resize
of a resizable display as WindowResized with x and y, after the surface has
been replaced by a black one of the new size (read it again through GetSurface()). The events carry
only those attributes, and pygame's companion events of a resize (VIDEORESIZE, WINDOWSIZECHANGED)
are not posted. A posted WindowResized changes nothing, as in pygame.
Thread-safe; draw on the surface from the thread that pumps the queue, which is the one that sees it change.
Reference: src_c/display.c (pygame-ce 2.5.8).
Properties
Context
The context this display belongs to, whose Events its window feeds.
public PygameContext Context { get; }
Property Value
Methods
Flip()
pygame.display.flip(): shows the surface in the window, as it is now.
public void Flip()
Remarks
The viewer copies the frame before this returns; drawing on the surface afterwards does not change what is shown.
Exceptions
- SdlError
Thrown when no mode is set, with pygame's message:
Display mode not set.
GetInit()
pygame.display.get_init() read as "a mode is set": whether Flip() has a window to show.
public bool GetInit()
Returns
GetSurface()
pygame.display.get_surface(): the display surface, or null when no mode is set.
public Surface? GetSurface()
Returns
- Surface
The surface; after a resize, a new one of the new size.
Quit()
pygame.quit() for the display: closes the window, forgets the surface and drops every pending event of the
context's queue, as SDL's queue goes with its video subsystem. Safe to call when nothing is open.
public void Quit()
SetMode(int, int, bool, EnvViewerFactory?, string?)
pygame.display.set_mode((width, height), flags): opens a window of that client size and returns its black
surface. A window already open is closed first (pygame would reuse and resize it; the viewers cannot be
resized from code).
public Surface SetMode(int width, int height, bool resizable = false, EnvViewerFactory? viewerFactory = null, string? title = null)
Parameters
widthintThe client width in pixels, positive.
heightintThe client height in pixels, positive.
resizableboolWhether the user's resizes reach the surface (
pygame.RESIZABLE); otherwise they are ignored.viewerFactoryEnvViewerFactoryThe window's factory; null takes the context's ViewerFactory, then
Gymnasium.HumanViewerFactory.titlestringThe window's title, or null for the viewer's default (pygame's is
pygame window).
Returns
- Surface
The display surface, also GetSurface().
Remarks
An interactive window starts reporting input here (BeginInput()), so its
close button posts Quit instead of closing it until Quit(). The factory
returns once its window is up (DR-85), so this call returns with the window up, as set_mode does.
Exceptions
- ArgumentOutOfRangeException
Thrown for a size that is not positive: pygame refuses a negative one and opens a desktop-sized window for 0, which is not modelled.
- DependencyNotInstalled
Thrown when no factory is given or set, where pygame would be missing.