ugBASIC 1.18
An isomorphic BASIC language compiler for retrocomputers
Loading...
Searching...
No Matches
vcenter.c
Go to the documentation of this file.
1/*****************************************************************************
2 * ugBASIC - an isomorphic BASIC language compiler for retrocomputers *
3 *****************************************************************************
4 * Copyright 2021-2026 Marco Spedaletti (asimov@mclink.it)
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *----------------------------------------------------------------------------
18 * Concesso in licenza secondo i termini della Licenza Apache, versione 2.0
19 * (la "Licenza"); è proibito usare questo file se non in conformità alla
20 * Licenza. Una copia della Licenza è disponibile all'indirizzo:
21 *
22 * http://www.apache.org/licenses/LICENSE-2.0
23 *
24 * Se non richiesto dalla legislazione vigente o concordato per iscritto,
25 * il software distribuito nei termini della Licenza è distribuito
26 * "COSÌ COM'È", SENZA GARANZIE O CONDIZIONI DI ALCUN TIPO, esplicite o
27 * implicite. Consultare la Licenza per il testo specifico che regola le
28 * autorizzazioni e le limitazioni previste dalla medesima.
29 ****************************************************************************/
30
31/****************************************************************************
32 * INCLUDE SECTION
33 ****************************************************************************/
34
35#include "../../ugbc.h"
36
37/****************************************************************************
38 * CODE SECTION
39 ****************************************************************************/
40
47/* <usermanual>
48@keyword VCENTRE
49
50@english
51
52@italian
53
54@syntax VCENTRE text [;]
55
56@example VCENTRE "HELLO!"
57@example VCENTRE "HELLO!";
58
59@target all
60
61@alias VCENTER
62
63@verified
64</usermanual> */
65/* <usermanual>
66@keyword VCENTER
67
68@english
69
70The ''VCENTER'' command aligns a text string in the center of the screen. In other
71words, it allows you to position a word or phrase so that it occupies the
72available space in a symmetrical manner, vertically. If the statement is followed
73by a semicolon, the cursor will remain on the same line. Otherwise, it will move to
74the next line.
75
76This command can be used to create aesthetically pleasing section or chapter titles,
77to center menu options in the center of the screen and to format data neatly
78in a report. Centered text is easier to read and makes programs look neater.
79
80By using VCENTER, you can ensure that text is aligned uniformly in different
81parts of the program, and on different targets. Moreover, reduce the need
82to manually calculate character positions.
83
84@italian
85
86Il comando ''VCENTER'' allinea una stringa di testo al centro dello schermo.
87In altre parole, consente di posizionare una parola o una frase in modo che
88occupi lo spazio disponibile in modo simmetrico, in verticale. Se l'istruzione
89è seguita da un punto e virgola, il cursore rimarrà sulla stessa riga. In caso
90contrario, si sposterà alla riga successiva.
91
92Questo comando può essere utilizzato per creare titoli di sezioni o capitoli
93esteticamente gradevoli, per centrare le opzioni di menu al centro dello schermo
94e per formattare i dati in modo ordinato in un report. Il testo centrato è più facile
95da leggere e rende i programmi più ordinati.
96
97Utilizzando VCENTER, è possibile assicurarsi che il testo sia allineato in modo
98uniforme in diverse parti del programma e su diversi target. Inoltre, si riduce
99la necessità di calcolare manualmente le posizioni dei caratteri.
100
101@syntax VCENTER text [;]
102
103@example VCENTER "HELLO!"
104@example VCENTER "HELLO!";
105
106@target all
107
108@alias VCENTRE
109</usermanual> */
110
111void vcenter( Environment * _environment, char * _string, int _newline ) {
112
114
115 Variable * string = variable_retrieve( _environment, _string );
116 Variable * currentHeight = variable_retrieve( _environment, "CONSOLEH");
117
118 Variable * height = variable_div2_const( _environment, currentHeight->name, 2, NULL );
119
120 locate( _environment, NULL, height->name );
121
122 text_text( _environment, string->name, 0 );
123
124 if ( _newline && ( _environment->centerWithoutNewLine == 0 ) ) {
125 text_newline( _environment );
126 }
127
128}
Variable * variable_retrieve(Environment *_environment, char *_name)
Variable * variable_div2_const(Environment *_environment, char *_destination, int _bits, char *_remainder)
Subdivide by two a variable for various times and return the result.
void locate(Environment *_environment, char *_x, char *_y)
Emit code for LOCATE ...,....
Definition locate.c:110
int centerWithoutNewLine
Definition ugbc.h:2968
char * name
Definition ugbc.h:979
void text_text(Environment *_environment, char *_text, int _raw)
Definition text.c:41
void text_newline(Environment *_environment)
Definition text.c:51
struct _Variable Variable
Structure of a single variable.
struct _Environment Environment
Structure of compilation environment.
#define MAKE_LABEL
Definition ugbc.h:3351
void vcenter(Environment *_environment, char *_string, int _newline)
Emit code for CENTRE ....
Definition vcenter.c:111