Metadata-Version: 2.4
Name: SimplGraphics
Version: 1.0.0
Summary: A simple 2D graphics library.
License: MIT License
        
        Copyright (c) 2026 DanF
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Requires-Python: >=3.9
Requires-Dist: glfw
Requires-Dist: numpy
Requires-Dist: pillow
Requires-Dist: pyopengl
Description-Content-Type: text/markdown

# SimplGraphics

A Simple 2D Graphics Library accelerated by OpenGL.

## Installation

`pip install SimplGraphics`

## Basic Usage


First, the window must be created, this is done by using the `init` function with the signature `(title: str, width: int, height: int, vsync: bool=5, msaa: int=0)`.

To handle the running loop, the `update` function should be used. It takes no parameters and will return a bool depending on whether it should be running or not. It is recommended to have the main logic loop in the following format ```while SimplGraphics.update() and not externalShouldClose:```.

Finally, once the application has ended and should be closed, the `exit` function should be used. It takes no arguments.


## Drawing Shapes


The drawing mechanism in SimplGraphics is buffer based and whenever a draw function is called, it will add necessary values to a buffer and all items in the buffer will be rendered when the `renderScreen` function is called.

The screen will be automatically cleared every time `renderScreen` is called with a clearColour value. This value can be changed with the `setClearColour` function which just takes in the colour value to set the clear colour to.

All functions taking in a colour value with use the proprietary `Colour` object. This can be created using the `rgbToColour` and `hexToColour` functions.

There are several shape drawing function in SimplGraphics. Below is a table of all of them.

| Function Name   | Function Signature                                                                                                | Description                                                           |
|-----------------|-------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------|
| drawRectangleTL | def drawRectangleTL(pos: tuple[int, int], size: tuple[int, int], col: Colour, borderRadius: int=0):               | Draw a rectangle with pos being the coordinate of the top-left corner |
| drawRectangle   | def drawRectangle(pos: tuple[int, int], size: tuple[int, int], col: Colour, borderRadius: int=0, rot: float=0.0): | Draw a rectangle with pos being the coordinate of the centre          |
| drawCircle      | def drawCircle(pos: tuple[int, int], radius: float, col: Colour):                                                 | Draw a circle with pos being the coordinate of the centre             |


## Drawing Images and Text


In order to draw images, first you need to load it using the `loadImage` which will take the filepath of the image, load and and create an OpenGL texture with it. The function will return the id of the image, you will need it to draw the image.

To draw the image once it is loaded, there are convenient `drawImage` and `drawImageTL` function which define a rectangle shape the same as `drawRectangle` and `drawRectangleTL` with a near-identical signature but instead of giving a colour, you will give the image id from the loaded image.

In order to draw text, it first needs to be laoded, to do that there is a `loadFont` function which will take in either a standard font name such as "arial" and "calibri" or the filepath to a .ttf or .ttc file. The function will also need the size of the font to be loaded in pixels. This will then add the font and the size to a unique key in a font atlas.

To draw the text, there are the `drawText` and `drawTextTL` functions where you specify the position, colour and optionally rotation like when drawing a rectangle but instead of giving a cornerRadius or a size, you will give the string used to load the font, the size used to load the font and the string of the text to be drawn. the signatures are as following: `def drawText(pos: tuple[int, int], font: str, size: int, text: str, col: Colour, rot:float=0.0):` and `def drawTextTL(pos: tuple[int, int], font: str, size: int, text: str, col: Colour):`


## Input

Most of the input is build directly on top of the input from glfw, the window library used by SimplGraphics, but there are a few slight differences. The key and mouse button constants are the same but they will instead be given to the bool returning function `keyPressed`, `keyDown`, `keyReleased`, `mouseButtonPressed`, `mouseButtonDown` and `mouseButtonReleased` with pressed being the change from the key/button transitioning from not pressed to pressed and released the opposite.

The function `getMousePos` will return a tuple of the mouse position and the function `getMouseInWindow` will return a bool depending on whether the cursor is currently over the window or not.

The function `getScrollChangeX` and `getScrollChangeY` will return the change in mouse scroll since the last time `update` was called.

`getTime` will return of float of the time since `init` was called in seconds.

Finally, the clipboard functions `getClipboard` and `setClipboard` will get the string value of the current clipboard and set the string value of the clipboard.

## Window Control

There are a few function to have some control over the window. They are stated below.

`setWindowIcon` requried the user to specify the path of an icon but will then set the icon of the window to the image.

`setCursorLock` will set wether the cursor is locked in the screen or not. It is useful for creating first-person games.

`setCursorShow` will set wether the cursor is visible or not. Useful if you have a custom non-conventional cursor as you can hide the default one and draw a custom cursor where the cursor would be.