WIP
This commit is contained in:
parent
b1e39d3ab6
commit
0f867e9f72
|
@ -74,6 +74,8 @@ elif ev.key == KEY_DOWN and pos < N-1:
|
|||
pos += 1 # Move one place down
|
||||
```
|
||||
|
||||
TODO: Mention `getkey_opt()`
|
||||
|
||||
### Reading keyboard events in real time
|
||||
|
||||
```py
|
||||
|
@ -119,7 +121,6 @@ def clearevents():
|
|||
|
||||
```py
|
||||
keydown(key: int) -> bool
|
||||
keyup(key: int) -> bool
|
||||
keydown_all(*keys: [int]) -> bool
|
||||
keydown_any(*keys: [int]) -> bool
|
||||
```
|
||||
|
@ -139,7 +140,7 @@ if keydown(KEY_RIGHT):
|
|||
player_x += 1
|
||||
```
|
||||
|
||||
`keyup()` returns the opposite of `keydown()`. `keydown_all()` takes a series of keys as parameters and returns `True` if they are all pressed. `keydown_any()` is similar and returns `True` if at least one of the listed keys is pressed.
|
||||
`keydown_all()` takes a series of keys as parameters and returns `True` if they are all pressed. `keydown_any()` is similar and returns `True` if at least one of the listed keys is pressed.
|
||||
|
||||
### Quickly querying key state changes
|
||||
|
||||
|
@ -171,13 +172,77 @@ if keydown(KEY_RIGHT):
|
|||
# Simulate game...
|
||||
```
|
||||
|
||||
## Basic rendering functions
|
||||
### Miscellaneous keyboard functions
|
||||
|
||||
```py
|
||||
keycode_function(key: int) -> int
|
||||
keycode_digit(key: int) -> int
|
||||
```
|
||||
|
||||
`keycode_function(k)` returns the F-key number if `k` (i.e. 1 for `KEY_F1`, 2 for `KEY_F2`, etc.) and -1 for other keys.
|
||||
|
||||
`keycode_digit(k)` returns the digit associated with `k` (i.e. 0 for `KEY_0`, 1 for `KEY_1`, etc.) and -1 for other keys.
|
||||
|
||||
## Drawing and rendering
|
||||
|
||||
Reference headers: [`<gint/display.h>`](https://gitea.planet-casio.com/Lephenixnoir/gint/src/branch/master/include/gint/display.h), and for some details [`<gint/display-fx.h>`](https://gitea.planet-casio.com/Lephenixnoir/gint/src/branch/master/include/gint/display-fx.h) and [`<gint/display-cg.h>`](https://gitea.planet-casio.com/Lephenixnoir/gint/src/branch/master/include/gint/display-cg.h).
|
||||
|
||||
### Color manipulation
|
||||
|
||||
```py
|
||||
C_WHITE: int # White
|
||||
C_BLACK: int # Black
|
||||
C_LIGHT: int # Light gray (on B&W: gray engine)
|
||||
C_DARK: int # Dark gray (on B&W: gray engine)
|
||||
C_NONE: int # Transparent
|
||||
C_INVERT: int # Function: inverse
|
||||
|
||||
# Black-and-white (B&W) models only:
|
||||
C_LIGHTEN: int # Function: lighten (gray engine)
|
||||
C_DARKEN: int # Function: darken (gray engine)
|
||||
|
||||
# fx-CG models only:
|
||||
C_RED: int # Pure red
|
||||
C_GREEN: int # Pure green
|
||||
C_BLUE: int # Pure blue
|
||||
C_RGB(r: int, g: int, b: int) -> int
|
||||
```
|
||||
|
||||
Colors are all integers (manipulating `(r,g,b)` tuples is excruciatingly slow and requires memory allocations all over the place). A few default colors are provided.
|
||||
|
||||
On the fx-CG series, the `C_RGB()` function can be used to create colors from three components ranging from 0 to 31.
|
||||
|
||||
TODO: Explain the gray engine.
|
||||
|
||||
### Basic rendering functions
|
||||
|
||||
|
||||
```py
|
||||
DWIDTH: int
|
||||
DHEIGHT: int
|
||||
dupdate() -> None
|
||||
dclear(color: int) -> None
|
||||
dpixel(x: int, y: int, color: int) -> None
|
||||
dgetpixel(x: int, y: int) -> int
|
||||
```
|
||||
|
||||
The integers `DWIDTH` and `DHEIGHT` indicate the screen's dimensions. The screen is 128x64 on black-and-white models (like the G-III) and 396x224 on the fx-CG series (the full screen is available).
|
||||
|
||||
All rendering functions draw to an internal image called the "VRAM"; rendering calls are thus not immediate visible on the screen. For the result to be visible one must call the `dupdate()` function, which transfers the contents of the VRAM to the real display. Usually, this is done after rendering everything we need on one frame instead of after each drawing function call.
|
||||
|
||||
In PythonExtra, `dupdate()` also indicates a "switch to graphics mode". Due to certain optimizations any call to `print()` is considered a "switch to text mode", and while in text mode the shell might redraw at any time. In order to draw after using text mode, one must call `dupdate()` to force a switch to graphics mode before starting rendering. Otherwise the shell and program might render at the same time and produce incoherent results.
|
||||
|
||||
`dclear()` fills the screen with a uniform color.
|
||||
|
||||
`dpixel()` changes a pixel's color. Coordinates are universally (x,y) where `x` is in the range 0 to DWIDTH-1 inclusive (0 being left) and `y` is in the range 0 to DHEIGHT-1 inclusive (0 being top).
|
||||
|
||||
`dgetpixel()` returns the color of a pixel. Note that `dgetpixel()` reads from VRAM, not from the display.
|
||||
|
||||
### Geometric shape rendering functions
|
||||
|
||||
TODO
|
||||
|
||||
## Image rendering functions
|
||||
### Image rendering functions
|
||||
|
||||
TODO
|
||||
|
||||
|
|
|
@ -76,6 +76,8 @@ elif ev.key == KEY_DOWN and pos < N-1:
|
|||
pos += 1 # Descendre d'une position
|
||||
```
|
||||
|
||||
TODO: Parler de `getkey_opt()`
|
||||
|
||||
### Lecture des événements en temps réel
|
||||
|
||||
```py
|
||||
|
@ -121,7 +123,6 @@ def clearevents():
|
|||
|
||||
```py
|
||||
keydown(key: int) -> bool
|
||||
keyup(key: int) -> bool
|
||||
keydown_all(*keys: [int]) -> bool
|
||||
keydown_any(*keys: [int]) -> bool
|
||||
```
|
||||
|
@ -141,7 +142,7 @@ if keydown(KEY_RIGHT):
|
|||
player_x += 1
|
||||
```
|
||||
|
||||
La fonction `keyup()` renvoie l'opposé de `keydown()`. La fonction `keydown_all()` prent une série de touches en paramètre et renvoie `True` si elles sout toutes pressées. `keydown_any()` est similaire et renvoie `True` si au moins une des touches listées est pressée.
|
||||
La fonction `keydown_all()` prent une série de touches en paramètre et renvoie `True` si elles sout toutes pressées. `keydown_any()` est similaire et renvoie `True` si au moins une des touches listées est pressée.
|
||||
|
||||
### Lecture rapide des changements de position des touches
|
||||
|
||||
|
@ -173,13 +174,100 @@ if keydown(KEY_RIGHT):
|
|||
# Simuler le jeu...
|
||||
```
|
||||
|
||||
## Fonctions de dessin basiques
|
||||
### Fonctions diverses concernant le clavier
|
||||
|
||||
```py
|
||||
keycode_function(key: int) -> int
|
||||
keycode_digit(key: int) -> int
|
||||
```
|
||||
|
||||
`keycode_function(k)` renvoie le numéro de F-touche de `k` (i.e. 1 pour `KEY_F1`, 2 pour `KEY_F2`, etc.) et -1 pour les autres touches.
|
||||
|
||||
`keycode_digit(k)` renvoie le chiffre associé à `k` (i.e. 0 pour `KEY_0`, 1 pour `KEY_1`, etc.) et -1 pour les autres touches.
|
||||
|
||||
## Dessin à l'écran
|
||||
|
||||
Les en-têtes de référence sont [`<gint/display.h>`](https://gitea.planet-casio.com/Lephenixnoir/gint/src/branch/master/include/gint/display.h), et pour certains détails techniques [`<gint/display-fx.h>`](https://gitea.planet-casio.com/Lephenixnoir/gint/src/branch/master/include/gint/display-fx.h) et [`<gint/display-cg.h>`](https://gitea.planet-casio.com/Lephenixnoir/gint/src/branch/master/include/gint/display-cg.h).
|
||||
|
||||
### Manipulation de couleurs
|
||||
|
||||
```py
|
||||
C_WHITE: int # Blanc
|
||||
C_BLACK: int # Noir
|
||||
C_LIGHT: int # Gris clair (sur mono: moteur de gris)
|
||||
C_DARK: int # Gris foncé (sur mono: moteur de gris)
|
||||
C_NONE: int # Transparent
|
||||
C_INVERT: int # Inverseur de couleur
|
||||
|
||||
# Graph mono uniquement :
|
||||
C_LIGHTEN: int # Éclaircisseur de couleur (moteur de gris)
|
||||
C_DARKEN: int # Assombrisseur de couleur (moteur de gris)
|
||||
|
||||
# Graph 90+E uniquement :
|
||||
C_RED: int # Rouge pur
|
||||
C_GREEN: int # Vert pur
|
||||
C_BLUE: int # Bleu pur
|
||||
C_RGB(r: int, g: int, b: int) -> int
|
||||
```
|
||||
|
||||
Les couleurs sont toutes des nombres entiers (manipuler des tuples `(r,g,b)` est atrocement lent par comparaison et requiert des allocations mémoire dans tous les sens). Une poignée de couleurs est fournie par défaut.
|
||||
|
||||
Sur Graph 90+E, la fonction `C_RGB()` peut être utilisée pour créer des couleurs à partir de trois composantes de valeur 0 à 31.
|
||||
|
||||
TODO: Expliquer le moteur de gris.
|
||||
|
||||
### Fonctions de dessin basiques
|
||||
|
||||
```py
|
||||
DWIDTH: int
|
||||
DHEIGHT: int
|
||||
dupdate() -> None
|
||||
dclear(color: int) -> None
|
||||
dpixel(x: int, y: int, color: int) -> None
|
||||
dgetpixel(x: int, y: int) -> int
|
||||
```
|
||||
|
||||
Les entiers `DWIDTH` et `DHEIGHT` indiquent la taille de l'écran. C'est 128x64 sur les Graph mono (type Graph 35+E II), 396x224 sur la Prizm et Graph 90+E (le plein écran est disponible).
|
||||
|
||||
Toutes les fonctions de dessin opèrent sur une image interne appellée "VRAM" ; l'effet du dessin n'est donc pas visible immédiatement à l'écran. Pour que le dessin se voie il faut appeler la fonction `dupdate()` qui transfère les contenus de la VRAM à l'écran réel. Généralement, on fait ça après avoir affiché tout ce dont on a besoin et surtout pas après chaque appel de fonction de dessin.
|
||||
|
||||
Dans PythonExtra, la fonction `dupdate()` indique aussi implicitement qu'on « passe en mode graphique ». À cause de certaines optimisations tout appel à `print()` est considéré comme un « passage en mode texte » et pendant qu'on est en mode texte le shell peut redessiner à tout moment. Si on veut dessiner après avoir utilisé le mode texte, il faut appeler `dupdate()` pour forcer un passage en mode graphique avant de commencer à dessiner. Sinon le dessin du shell pourrait interférer avec le dessin du programme.
|
||||
|
||||
La fonction `dclear()` remplit l'écran d'une couleur unie.
|
||||
|
||||
La fonction `dpixel()` modifie la couleur d'un pixel. Les coordonnées sont universellement (x,y) où `x` varie entre 0 et DWIDTH-1 inclus (0 étant à gauche), et `y` varie entre 0 et DHEIGHT-1 inclus (0 étant en haut).
|
||||
|
||||
La fonction `dgetpixel()` renvoie la couleur d'un pixel. Attention, `dgetpixel()` lit dans la VRAM, pas sur l'écran.
|
||||
|
||||
_Exemple ([`ex_draw1.py`](../../sh/examples/ex_draw1.py))._
|
||||
|
||||
```py
|
||||
from gint import *
|
||||
dclear(C_WHITE)
|
||||
for y in range(10):
|
||||
for x in range(10):
|
||||
if (x^y) & 1:
|
||||
dpixel(x, y, C_BLACK)
|
||||
dupdate()
|
||||
```
|
||||
|
||||
### Fonctions de dessin de formes géométriques
|
||||
|
||||
```py
|
||||
drect(x1: int, y1: int, x2: int, y2: int, color: int) -> None
|
||||
drect_border(x1: int, y1: int, x2: int, y2: int, fill_color: int,
|
||||
border_width: int, border_color: int) -> None
|
||||
dline(x1: int, y1: int, x2: int, y2: int, color: int) -> None
|
||||
dhline(y: int, color: int) -> None
|
||||
dvline(x: int, color: int) -> None
|
||||
dcircle(x: int, y: int, radius: int, fill_color: int,
|
||||
border_color: int) -> None
|
||||
dellipse(x1: int, y1: int, x2: int, y2: int, fill_color: int,
|
||||
border_color: int) -> None
|
||||
```
|
||||
TODO
|
||||
|
||||
## Fonctions de dessin d'images
|
||||
### Fonctions de dessin d'images
|
||||
|
||||
TODO
|
||||
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
from gint import *
|
||||
dclear(C_WHITE)
|
||||
for y in range(10):
|
||||
for x in range(10):
|
||||
if (x^y) & 1:
|
||||
dpixel(x, y, C_BLACK)
|
||||
dupdate()
|
||||
getkey()
|
|
@ -66,7 +66,7 @@ static ssize_t stdouterr_write(void *data, void const *buf, size_t size)
|
|||
return size;
|
||||
}
|
||||
|
||||
fs_descriptor_type_t stdouterr_type = {
|
||||
static fs_descriptor_type_t const stdouterr_type = {
|
||||
.read = NULL,
|
||||
.write = stdouterr_write,
|
||||
.lseek = NULL,
|
||||
|
@ -219,6 +219,12 @@ static void pe_print_prompt(int which)
|
|||
else
|
||||
prompt = mp_repl_get_ps1();
|
||||
|
||||
char str[32];
|
||||
kmalloc_gint_stats_t *s;
|
||||
s = kmalloc_get_gint_stats(kmalloc_get_arena("_uram"));
|
||||
sprintf(str, "%lu", s->free_memory);
|
||||
console_write(PE.console, str, -1);
|
||||
|
||||
console_write(PE.console, prompt, -1);
|
||||
console_lock_prefix(PE.console);
|
||||
}
|
||||
|
|
|
@ -616,7 +616,12 @@ STATIC const mp_rom_map_elem_t modgint_module_globals_table[] = {
|
|||
INT(C_LIGHT),
|
||||
INT(C_DARK),
|
||||
INT(C_BLACK),
|
||||
INT(C_INVERT),
|
||||
INT(C_NONE),
|
||||
#ifdef FX9860G
|
||||
INT(C_LIGHTEN),
|
||||
INT(C_DARKEN),
|
||||
#endif
|
||||
#ifdef FXCG50
|
||||
INT(C_RED),
|
||||
INT(C_GREEN),
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
|
||||
/* gint.font(name, flags, line_heignt, data_height, block_count, glyph_count,
|
||||
char_spacing, blocks, glyphs, ...)
|
||||
Fixed-width fonts:
|
||||
... width, storage_size
|
||||
Proportional fonts:
|
||||
... glyph_index, glyph_width */
|
Loading…
Reference in New Issue