Skip to content

Commit fb996c5

Browse files
Initial commit
1 parent a030c8e commit fb996c5

File tree

1 file changed

+84
-2
lines changed

1 file changed

+84
-2
lines changed

README.md

Lines changed: 84 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,84 @@
1-
# Sauer-GUICANVAS
2-
A set of commands for manipulating pixels in Cube 2 Sauerbraten menus.
1+
## Cube 2 Sauerbraten Canvas Interface
2+
GUICANVAS is a set of commands for [Sauerbraten](http://sauerbraten.org/) that allows you to draw pixels in GUI menus using CubeScript.
3+
4+
![](https://github.com/SalatielSauer/misc/blob/master/guicanvas_notepad_1.gif)
5+
6+
### Installation
7+
1. Download [guicanvas.zip](https://github.com/CubeScript/Sauer-GUICANVAS/releases/latest) (without extracting it).
8+
2. Move the zip to the Sauerbraten home folder (or the main installation folder).
9+
3. Find your autoexec.cfg file or create a new one (also in one of the root folders), open it in a text editor and add the following commands:
10+
`addzip guicanvas.zip; exec guicanvas.cfg`<br>
11+
The zip will be extracted internally and the configuration file (guicanvas.cfg) will be applied whenever you start the game.
12+
13+
Alternatively to step 3 you can type the command `/notepad autoexec.cfg` during the game to open the built-in text editor.
14+
15+
<hr>
16+
17+
### Playable Demos
18+
![](https://github.com/SalatielSauer/misc/blob/master/guicanvas_snake_1.gif)
19+
20+
Currently the installation zip comes with the demos below that you can run and test:
21+
- [guicanvas_snake.cfg](https://github.com/CubeScript/Sauer-GUICANVAS/blob/main/guicanvas/guicanvas_snake.cfg) by [@SalatielSauer](https://github.com/SalatielSauer)
22+
- [guicanvas_raycast.cfg](https://github.com/CubeScript/Sauer-GUICANVAS/blob/main/guicanvas/guicanvas_raycast.cfg) by [@SalatielSauer](https://github.com/SalatielSauer)
23+
24+
feel free to contribute more :)
25+
26+
Note: Some GUICANVAS demos are expected to replace key binds such as directional arrows.
27+
28+
<hr>
29+
30+
### How it works
31+
Behind the scenes GUICANVAS uses .obj mapmodels as *screens*, each pixel is a mesh whose name corresponds to its position (index) in the 2D plane. The model command to define skins by meshes (in this case `objskin`) is extremely fast, allowing us to easily update their colors or textures.
32+
33+
For the front end, GUICANVAS uses the `guimodelpreview` command, which allows us to register and display any mapmodel with a given size and even an animation state.
34+
35+
Another important command is `guistrut`, with it we can overlay GUI elements and make the magic work.
36+
37+
If you are not into menus or want to create your own physical arcade, you can spawn the screen using the `/newent mapmodel $nummapmodels; mmodel guicanvas` command in edit mode.
38+
39+
<hr>
40+
41+
### GUICANVAS Custom Commands
42+
`guicanvas.cfg` has some commands and variables that you can use.
43+
44+
### `guicanvas.setPixel x y r g b`
45+
This is the main command to add a pixel before drawing it, `x` refers to the horizontal line and `y` to the vertical, `r` `g` `b` are the colors ranging between 0-1.
46+
47+
If `r` is set to -1 the pixel will be displayed with complete opacity;
48+
49+
If `r` is a string it will be treated as a texture path.
50+
51+
### `guicanvas.fillRect x y width height r g b`
52+
This is a helper function that uses `guicanvas.setPixels` to fill a square with a given size `width` `height` at a given `x` `y` position.
53+
54+
### `guicanvas.refresh`
55+
This is the command to actually draw the screen from the list of added pixels (`$guicanvas.pixels`), it will also clear the list unless `guicanvas.keepPixels` is set to 1.
56+
57+
### `guicanvas.onupdate = [action]`
58+
Works as an event hook, the contents of `$guicanvas.onupdate` are executed every millisecond set by `$guicanvas.refreshRate`.
59+
60+
### `guicanvas.play [action] [interface] x y`
61+
This is the main command for creating and displaying the GUI menu, with extra functions to facilitate the positioning of other GUI elements.
62+
63+
`action` has the same effect as `$guicanvas.onupdate`, its content is executed every millisecond defined by `$guicanvas.refreshRate`;
64+
65+
`interface` is where you can include other GUI elements that you want to see on the screen (guitext, guititle, guibutton...), they are positioned by default at 0 0 unless determined by `x` and `y`.
66+
67+
Careful and extensive use of `guistrut` may be necessary if you wish to hide the original background (the guiskin), which may appear depending on the lenght of your text elements, take a look at the demo files to get an idea of ​​how to correct these.
68+
69+
Alternatively you can always create your own menu using the guimodelpreview command to display the screen.
70+
71+
### `guicanvas.perspective pitch fov`
72+
This command is just a mix of the `modelpreviewpitch` and `modelpreviewfov` commands, allows you to control the display of the preview itself in 3D context.
73+
74+
Note: `fov` can make the preview invisible at certain sizes and values (logically the same applies to `pitch` :P).
75+
76+
### `guicanvas.size w h`
77+
This is the command that determines which screen model will be loaded and displayed, if a certain screen size is not available, the user will be prompted to generate it.
78+
79+
Alternatively you can generate screens with extra customizations using `guicanvas.genScreen`.
80+
81+
### `guicanvas name`
82+
The `/guicanvas` command displays all .cfg files contained in the "guicanvas" folder and allows you to play or edit them.
83+
84+
![](https://github.com/SalatielSauer/misc/blob/master/guicanvas_raycast_1.gif)

0 commit comments

Comments
 (0)