demosys.context.base.BaseWindow¶
-
demosys.context.base.
BaseWindow
¶ The base window we extend when adding new window types to the system.
-
demosys.context.base.
BaseKeys
¶ Namespace for generic key constants working across all window types.
Methods¶
-
BaseWindow.
__init__
()¶ Base window intializer reading values from
settings
.When creating the initializer in your own window always call this methods using
super().__init__()
.The main responsebility of the initializer is to:
- initialize the window library
- identify the window framebuffer
- set up keyboard and mouse events
- create the
moderngl.Context
instance - register the window in
context.WINDOW
-
BaseWindow.
draw
(current_time, frame_time)¶ Draws a frame. Internally it calls the configured timeline’s draw method.
Parameters: - current_time (float) – The current time (preferrably always from the configured timer class)
- frame_time (float) – The duration of the previous frame in seconds
-
BaseWindow.
clear
()¶ Clear the window buffer
-
BaseWindow.
clear_values
(red=0.0, green=0.0, blue=0.0, alpha=0.0, depth=1.0)¶ Sets the clear values for the window buffer.
Parameters: - red (float) – red compoent
- green (float) – green compoent
- blue (float) – blue compoent
- alpha (float) – alpha compoent
- depth (float) – depth value
-
BaseWindow.
use
()¶ Set the window buffer as the current render target
Raises: NotImplementedError
-
BaseWindow.
swap_buffers
()¶ Swap the buffers. Most windows have at least support for double buffering cycling a back and front buffer.
Raises: NotImplementedError
-
BaseWindow.
resize
(width, height)¶ Resize the window. Should normallty be overriden when implementing a window as most window libraries need additional logic here.
Parameters: - width (int) – Width of the window
- height – (int): Height of the window
-
BaseWindow.
close
()¶ Set the window in close state. This doesn’t actually close the window, but should make
should_close()
returnTrue
so the main loop can exit gracefully.Raises: NotImplementedError
-
BaseWindow.
should_close
() → bool¶ Check if window should close. This should always be checked in the main draw loop.
Raises: NotImplementedError
-
BaseWindow.
terminate
()¶ The actual teardown of the window.
Raises: NotImplementedError
-
BaseWindow.
keyboard_event
(key, action, modifier)¶ Handles the standard keyboard events such as camera movements, taking a screenshot, closing the window etc.
Can be overriden add new keyboard events. Ensure this method is also called if you want to keep the standard features.
Parameters: - key – The key that was pressed or released
- action – The key action. Can be ACTION_PRESS or ACTION_RELEASE
- modifier – Modifiers such as holding shift or ctrl
-
BaseWindow.
cursor_event
(x, y, dx, dy)¶ The standard mouse movement event method. Can be overriden to add new functionality. By default this feeds the system camera with new values.
Parameters: - x – The current mouse x position
- y – The current mouse y position
- dx – Delta x postion (x position difference from the previous event)
- dy – Delta y postion (y position difference from the previous event)
-
BaseWindow.
print_context_info
()¶ Prints moderngl context info.
-
BaseWindow.
set_default_viewport
()¶ Calculates the viewport based on the configured aspect ratio in settings. Will add black borders if the window do not match the viewport.
Attributes¶
-
BaseWindow.
size
¶ (width, height) tuple containing the window size.
Note that for certain displays we rely on
buffer_size()
to get the actual window buffer size. This is fairly common for retina and 4k displays where the UI scale is > 1.0
-
BaseWindow.
buffer_size
¶ (width, heigh) buffer size of the window.
This is the actual buffer size of the window taking UI scale into account. A 1920 x 1080 window running in an environment with UI scale 2.0 would have a 3840 x 2160 window buffer.
-
BaseWindow.
keys
= None¶ The key class/namespace used by the window defining keyboard constants