Skip to content
CShift0.45

System.Graphics

Drawing into images: Canvas draws rectangles, rounded rectangles, circles, lines, text and images into an Image (with clipping, transparency and smooth edges); Font is a bitmap font for its text.

Windows, the keyboard and the mouse: Window shows the frames of a program (images, or the frames of a System.Ui.Ui) and collects the Input of a frame. Windows has it with Win32 (stdlib/os/windows/window.cshift), Linux with X11 (stdlib/os/posix/window.cshift, libX11 is loaded when the first window opens, so programs without windows do not need it), the browser with a <canvas> (stdlib/os/wasi/window.cshift and web/cshift.js, –backend wasm), AmigaOS with Intuition and graphics.library (stdlib/amiga/window.cshift).

A game draws its screen into an Image with a Canvas and shows it scaled up:

using System.Drawing;
using System.Graphics;
using System.Image;
var window = try Window.Open("Game", 320 * 3, 180 * 3);
window.SetFrameRate(60);
var screen = Image.Create(320, 180);
var canvas = Canvas.Create(screen);
var x = 0.0;
while (window.Update())
{
var input = window.Input();
if (input.IsDown(Key.Right))
x += 60.0 * window.DeltaTime();
canvas.Clear(Color.Black());
canvas.FillRect(Rect.Create((int)x, 80, 16, 16), Color.Orange());
window.ShowScaled(screen);
}
Type Description
Canvas Draws into an Image: everything is clipped to Clip, colors with an alpha below 255 are blended with what is already there, and the edges of rounded rectangles, circles and lines are smooth.
SpriteSheet An image cut into frames of the same size, from left to right and top to bottom: the tiles of a map, the frames of an animation.
Font A bitmap font: every character is a cell of the same size.
Window A window that shows frames: images of a program (a game) or the frames of a System.Ui.Ui.
Clipboard The text of the system’s clipboard (Ui.TextBox uses it for Ctrl+C, Ctrl+X and Ctrl+V).
Input What the user did since the last frame: the state of the mouse and the keys that were pressed.
IWindowFrame What a window can show as a frame besides an image: a System.Ui.Ui shows its frame with window.Show(ui) this way.
Flip How an image is mirrored when it is drawn (Canvas.DrawImage with a flip); the values combine with |.
WindowError The errors of opening a window.
Scaling How Window.ShowScaled fits a picture into the window.
KeyModifiers The modifier keys held with a key press (Input.Pressed with modifiers, Input.ModifiersAt); they combine with |: KeyModifiers.Ctrl | KeyModifiers.Shift.
Key The keys that Input.Keys reports.
Cursor The shape of the mouse pointer that a frame asks for (see Ui.Cursor).