Quelques utilitaires forth

 

 


Quelques mots développés en Gforth qui composent des cadres à l'écran pour enrichir un peu l'interface texte.

les arguments déposés préalablement sur la pile sont :
    - haut  = hauteur du cadre
    - long  = longueur du cadre
    - col   = coordonnée du point de départ du cadre X
    - ligne = coordonnée du point de départ du cadre Y

cadre1 : dessine un cadre simple trait
cadre2 : dessine un cadre double traits
cadre3 : dessine un cadre avec des caractères + - |
col_simple et col_double : dessine une colonnes
croise_simple et croise_double : dessine le caractère de croisement entre le cadre et la colonne


 

 

\\ ============================================
\\ Dessin de cadre avec recouvrement haut = nombre de lignes utilisables
\\ ============================================

\\ arguments :
\\ haut = nombre de lignes du cadre
\\ long = longueur utilisable dans le cadre
\\ col ligne = coordonnées x y du point de départ du cadre
\\ corient : orientation du croisement 1=gauche 2=droite 3=centre

variable ccol
variable clig
variable clong
variable chaut
variable corient

: cadre1 ( haut long col ligne --- )
    clig !     ccol ! clong ! chaut !
    ccol @ clig @ at-xy ." ┌" clong @ 0 do ." ─" loop ." ┐"
    chaut @ 0 do ccol @ clig @ 1+ i + at-xy ." │" clong @ spaces ." │" loop
    ccol @ clig @ chaut @ 1+ + at-xy ." └" clong @ 0 do ." ─" loop ." ┘"
;

: cadre2 ( haut long col ligne --- )
    clig !     ccol ! clong ! chaut !
    ccol @ clig @ at-xy ." ╔" clong @ 0 do ." ═" loop ." ╗"
    chaut @ 0 do ccol @ clig @ 1+ i + at-xy ." ║" clong @ spaces ." ║" loop
    ccol @ clig @ chaut @ 1+ + at-xy ." ╚" clong @ 0 do ." ═" loop ." ╝"
;

: cadre3 ( haut long col ligne --- )
    clig !     ccol ! clong ! chaut !
    ccol @ clig @ at-xy ." +" clong @ 0 do ." -" loop ." +"
    chaut @ 0 do ccol @ clig @ 1+ i + at-xy ." |" clong @ spaces ." |" loop
    ccol @ clig @ chaut @ 1+ + at-xy ." +" clong @ 0 do ." -" loop ." +"
;

: col_simple ( haut col ligne --- )
    clig ! ccol ! chaut !
    chaut @ 0 do ccol @ clig @ i + at-xy ." |" loop
;

: col_double ( haut col ligne --- )
    clig ! ccol ! chaut !
    chaut @ 0 do ccol @ clig @ i + at-xy ." ║" loop
;

: croise_simple ( orient col ligne --- )
    clig ! ccol ! corient !
    corient @ 1 = if ccol @ clig @ at-xy ." ├" then
    corient @ 2 = if ccol @ clig @ at-xy ." ┤" then
    corient @ 3 = if ccol @ clig @ at-xy ." ┬" then
;

: croise_double ( orient col ligne --- )
    clig ! ccol ! corient !
    corient @ 1 = if ccol @ clig @ at-xy ." ╠" then
    corient @ 2 = if ccol @ clig @ at-xy ." ╣" then
    corient @ 3 = if ccol @ clig @ at-xy ." ╦" then
;    



11/08/2012
0 Poster un commentaire

A découvrir aussi


Ces blogs de Informatique & Internet pourraient vous intéresser

Inscrivez-vous au blog

Soyez prévenu par email des prochaines mises à jour

Rejoignez les 9 autres membres