docs: add example for drect(), dline() and the like

This commit is contained in:
Lephenixnoir 2024-02-26 22:38:10 +01:00
parent 430fe06adc
commit c14f770483
Signed by: Lephenixnoir
GPG Key ID: 1BBA026E13FC0495
5 changed files with 80 additions and 30 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

View File

@ -82,19 +82,19 @@ elif ev.key == KEY_DOWN and pos < N-1:
The function `getkey_opt()` generalizes `getkey()` and provides more options to customize its behavior. The `opts` parameter accepts a combination (sum) of options from the table below, and the parameter `timeout_ms`, when not `None`, specifies how long `getkey_opt()` should wait before returning a `KEYEV_NONE` event if nothing happens. The delay is specified in milliseconds but the actual resolution is about 7-8 ms.
| Option | `getkey()` | Description |
|----------------------|------------|--------------------------------------------------|
| GETKEY_MOD_SHIFT | Yes | SHIFT is a modifier key |
| GETKEY_MOD_ALPHA | Yes | ALPHA is a modifier key |
| GETKEY_BACKLIGHT | Yes | SHIFT+OPTN toggles display backlight |
| GETKEY_MENU | Yes | MENU brings up the calculator's main menu |
| GETKEY_REP_ARROWS | Yes | Repeats arrow keys when held |
| GETKEY_REP_ALL | No | Repeats all keys when held |
| GETKEY_REP_PROFILE | Yes* | Enable custom repeat delays |
| GETKEY_FEATURES | Yes* | Enable custom global shortcuts |
| GETKEY_MENU_DUPDATE | Yes | Update display after return to menu (fx-CG) |
| GETKEY_MENU_EVENT | No | Send a `KEYEV_OSMENU` event after return to menu |
| GETKEY_POWEROFF | Yes | SHIFT+AC/ON turns the calculator off |
| Option | `getkey()` | Description |
|------------------------|------------|--------------------------------------------------|
| `GETKEY_MOD_SHIFT` | Yes | SHIFT is a modifier key |
| `GETKEY_MOD_ALPHA` | Yes | ALPHA is a modifier key |
| `GETKEY_BACKLIGHT` | Yes | SHIFT+OPTN toggles display backlight |
| `GETKEY_MENU` | Yes | MENU brings up the calculator's main menu |
| `GETKEY_REP_ARROWS` | Yes | Repeats arrow keys when held |
| `GETKEY_REP_ALL` | No | Repeats all keys when held |
| `GETKEY_REP_PROFILE` | Yes* | Enable custom repeat delays |
| `GETKEY_FEATURES` | Yes* | Enable custom global shortcuts |
| `GETKEY_MENU_DUPDATE` | Yes | Update display after return to menu (fx-CG) |
| `GETKEY_MENU_EVENT` | No | Send a `KEYEV_OSMENU` event after return to menu |
| `GETKEY_POWEROFF` | Yes | SHIFT+AC/ON turns the calculator off |
`getkey()` is equivalent to `getkey_opt(opts, None)` where `opts` is the sum of all options that have "Yes" in the `getkey()` column above.
@ -301,7 +301,9 @@ dellipse(x1: int, y1: int, x2: int, y2: int, fill_color: int,
`dellipse()` draws an ellipse defined by its bounding box. Both (x1, y1) and (x2, y2) are included in the bounding box. To render an ellipse from its center coordinates (x,y) and semi-major/minor axes a/b, use `dellipse(x-a, y-b, x+a, y+b, fill_color, border_color)`.
TODO: Example for `drect()`, `drect_border()`, `dline()`.
_Exemple ([`ex_draw2.py`](../../ports/sh/examples/ex_draw2.py))._
![](images/modgint-draw2-cg.png) ![](images/modgint-draw2-fx.png)
_Example ([`ex_circle.py`](../../ports/sh/examples/ex_circle.py))._

View File

@ -84,19 +84,19 @@ elif ev.key == KEY_DOWN and pos < N-1:
La fonction `getkey_opt()` est une généralisation de `getkey()` qui donne accès à plus d'options pour personnaliser le comportement de la fonction. Le paramètre `opts` accepte une combinaison d'options dans le tableau ci-dessous, et le paramètre `timeout_ms`, quand il n'est pas `None`, spécifie au bout de combien de temps la fonction doit s'arrêter et renvoyer un événement de type `KEYEV_NONE` s'il n'y a aucune activité sur le clavier. Le délai est exprimé en millisecondes mais la précision réelle est de l'ordre de 7-8 ms.
| Option | `getkey()` | Description |
|----------------------|------------|------------------------------------------------------------|
| GETKEY_MOD_SHIFT | Oui | La touche SHIFT est un modifieur |
| GETKEY_MOD_ALPHA | Oui | La touche ALPHA est un modifieur |
| GETKEY_BACKLIGHT | Oui | SHIFT+OPTN allume/éteint le rétroéclairage |
| GETKEY_MENU | Oui | MENU retourne au menu principal de la calculatrice |
| GETKEY_REP_ARROWS | Oui | Répète les touches directionnelles si maintenues |
| GETKEY_REP_ALL | Non | Répète toutes les touches si maintenues |
| GETKEY_REP_PROFILE | Oui* | Personnalisation des durées de répétition |
| GETKEY_FEATURES | Oui* | Personnalisation des raccourcis claviers globaux |
| GETKEY_MENU_DUPDATE | Oui | Rafraîchit l'écran après un retour au menu (Prizm/G90) |
| GETKEY_MENU_EVENT | Non | Envoie un événement `KEYEV_OSMENU` après un retour au menu |
| GETKEY_POWEROFF | Oui | SHIFT+AC/ON éteint la calculatrice |
| Option | `getkey()` | Description |
|------------------------|------------|------------------------------------------------------------|
| `GETKEY_MOD_SHIFT` | Oui | La touche SHIFT est un modifieur |
| `GETKEY_MOD_ALPHA` | Oui | La touche ALPHA est un modifieur |
| `GETKEY_BACKLIGHT` | Oui | SHIFT+OPTN allume/éteint le rétroéclairage |
| `GETKEY_MENU` | Oui | MENU retourne au menu principal de la calculatrice |
| `GETKEY_REP_ARROWS` | Oui | Répète les touches directionnelles si maintenues |
| `GETKEY_REP_ALL` | Non | Répète toutes les touches si maintenues |
| `GETKEY_REP_PROFILE` | Oui* | Personnalisation des durées de répétition |
| `GETKEY_FEATURES` | Oui* | Personnalisation des raccourcis claviers globaux |
| `GETKEY_MENU_DUPDATE` | Oui | Rafraîchit l'écran après un retour au menu (Prizm/G90) |
| `GETKEY_MENU_EVENT` | Non | Envoie un événement `KEYEV_OSMENU` après un retour au menu |
| `GETKEY_POWEROFF` | Oui | SHIFT+AC/ON éteint la calculatrice |
`getkey()` est équivalent à `getkey_opt(opts, None)``opts` est la somme de toutes les options marquées "Oui" dans la colonne `getkey()` ci-dessus.
@ -263,7 +263,7 @@ La fonction `dpixel()` modifie la couleur d'un pixel. Les coordonnées, comme po
La fonction `dgetpixel()` renvoie la couleur d'un pixel. Attention, `dgetpixel()` lit dans la VRAM, pas sur l'écran.
_Exemple ([`ex_draw1.py`](../../sh/ports/examples/ex_draw1.py))._
_Exemple ([`ex_draw1.py`](../../ports/sh/examples/ex_draw1.py))._
```py
from gint import *
@ -302,9 +302,11 @@ dellipse(x1: int, y1: int, x2: int, y2: int, fill_color: int,
`dellipse()` dessine une ellipse définie par son rectangle englobant. Les points (x1, y1) et (x2, y2) sont tous les deux inclus dans le rectangle. Pour dessiner une ellipse à partir de son centre (x, y) et de ses demi-grand/petit axes a/b, utilisez `dellipse(x-a, y-b, x+a, y+b, fill_color, border_color)`.
TODO: Exemple pour `drect()`, `drect_border()`, `dline()`.
_Exemple ([`ex_draw2.py`](../../ports/sh/examples/ex_draw2.py))._
_Exemple ([`ex_circle.py`](../../sh/ports/examples/ex_circle.py))._
![](images/modgint-draw2-cg.png) ![](images/modgint-draw2-fx.png)
_Exemple ([`ex_circle.py`](../../ports/sh/examples/ex_circle.py))._
![](images/modgint-circle-cg.png) ![](images/modgint-circle-fx.png)

View File

@ -0,0 +1,46 @@
from gint import *
import math
if DWIDTH==128:
C_RGB = lambda r, g, b: 0
_ = lambda x, y: x
else:
_ = lambda x, y: y
dclear(C_WHITE)
c1 = _(C_BLACK, C_RGB(24, 24, 24))
c2 = _(C_BLACK, C_BLACK)
c3 = _(C_NONE, C_RGB(24, 24, 24))
x1 = _(5,20)
x2 = _(40,90)
x3 = _(120,360)
y1 = _(2,20)
y2 = _(19,60)
y3 = _(30,135)
y4 = _(45,170)
y5 = _(50,190)
xp = _(90,200)
yp = _(25,100)
rp = _(20,50)
drect(x1, y1, x2, y2, c1)
drect_border(x1, y3, x2, y4, c3, 2, c2)
dvline(x3, c1)
dvline(x3+2, c1)
dvline(x3+4, c1)
dhline(y5, c2)
dhline(y5+2, c2)
dhline(y5+4, c2)
p = [2*math.pi*i/7 for i in range(7)]
p = [(int(xp+rp*math.cos(a)), int(yp+rp*math.sin(a))) for a in p]
for i in range(7):
dline(*p[i], *p[(i+2)%7], C_BLACK)
dupdate()
getkey()