Pierosforo

This commit is contained in:
admin committed 2025-06-13 00:48:23 +02:00
1 parent 405963cf5d
commit 3607f14f86
2 files changed
+100 -13

No files matched your search

+100 -13
View File
@@ -13,18 +13,21 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ncurses.h>
// Prototipi
int runMainMenu();
void warning(char *string);
WINDOW *create_newwin(int height, int width, int starty, int startx);
void destroy_win(WINDOW *local_win);
void print_menu(WINDOW *menu_win, int highlight);
void print_menu(WINDOW *menu_win, int y, int x, int highlight);
void word_wrap_print(WINDOW *win, int start_y, int start_x, int max_width, const char *str);
int getCount();
void changeFile();
int checkIfFileExists();
// Costanti
// Globali
char productPricesFileLocation[64]="./productPricesSetting.txt";
char countFileLocation[64]="./count.txt";
FILE *productPrices;
@@ -47,6 +50,7 @@ int n_mainMenu = sizeof(mainMenu) / sizeof(char *);
// Funzioni
int main(){
initscr();
//initialize options
noecho();
curs_set(0);
raw();
@@ -55,6 +59,13 @@ int main(){
int running = 0;
while(running != 6){
running = runMainMenu();
switch(running) {
case 5:
warning("Questa è una stringa molto lunga . . . Ma anche un test, che ti devo dire, ci proviamo a fare cose che non sono mai state fatte, oltretutto che divertimento ci sarebbe senza esperienze nuove?");
break;
case 6:
break;
}
}
endwin();
@@ -77,37 +88,41 @@ int runMainMenu(){
int c;
keypad(mainWin, TRUE);
mvwprintw(mainWin, 1, 2, "Usa le freccette ed invio per scegliere un'opzione!");
mvwprintw(mainWin, 2, 2, "Usa le FRECCETTE ed INVIO per scegliere un'opzione!");
mvwprintw(mainWin, 3, 2, "In alternativa ci sono J e K con SPAZIO!");
refresh();
print_menu(mainWin, highlight);
print_menu(mainWin, 6, width / 2 - 10, highlight);
while(1)
{ c = wgetch(mainWin);
switch(c)
{ case KEY_UP:
case 'k':
if(highlight == 1)
highlight = n_mainMenu;
else
--highlight;
break;
case KEY_DOWN:
case 'j':
if(highlight == n_mainMenu)
highlight = 1;
else
++highlight;
break;
case 10:
case 32:
choice = highlight;
break;
default:
mvwprintw(mainWin, height - 2, 2, "Hai premuto il tasto '%c'", c, c);
mvprintw(LINES - 2, 1, "Il tasto '%c' non e' un tasto valido . . .", c);
refresh();
break;
}
print_menu(mainWin, highlight);
print_menu(mainWin, 6, width / 2 - 10, highlight);
if(choice != 0) /* User did a choice come out of the infinite loop */
break;
}
mvprintw( LINES - 1 , 0, "Hai premuto il tasto %s\n . . .", mainMenu[choice - 1]);
mvprintw( LINES - 2 , 1, "Avvio opzione '%s' . . . ", mainMenu[choice - 1]);
clrtoeol();
refresh();
destroy_win(mainWin);
@@ -115,6 +130,23 @@ int runMainMenu(){
return choice;
}
void warning(char *string){
WINDOW *warningWin;
int startx, starty, width, height;
height = LINES / 2 - 2;
width = COLS / 2;
starty = LINES / 2;
startx = 0;
warningWin = create_newwin(height, width, starty, startx);
mvwprintw(warningWin, 2, 2, "ATTENZIONE! E' avvenuto un errore . . . ");
word_wrap_print(warningWin, 4, 3, width - 5, string);
wrefresh(warningWin);
getch();
destroy_win(warningWin);
}
WINDOW *create_newwin(int height, int width, int starty, int startx)
{ WINDOW *local_win;
@@ -128,17 +160,14 @@ WINDOW *create_newwin(int height, int width, int starty, int startx)
void destroy_win(WINDOW *local_win)
{
wborder(local_win, ' ', ' ', ' ',' ',' ',' ',' ',' ');
wborder(local_win, ':', ':', '.', '.', '+', '+', '+', '+');
wrefresh(local_win);
delwin(local_win);
}
void print_menu(WINDOW *menu_win, int highlight)
void print_menu(WINDOW *menu_win, int y, int x, int highlight)
{
int x, y, i;
x = 3;
y = 3;
int i;
box(menu_win, 0, 0);
for(i = 0; i < n_mainMenu; ++i)
{ if(highlight == i + 1) /* High light the present choice */
@@ -153,10 +182,67 @@ void print_menu(WINDOW *menu_win, int highlight)
wrefresh(menu_win);
}
void word_wrap_print(WINDOW *win, int start_y, int start_x, int max_width, const char *str) {
int y = start_y;
int x = start_x;
int line_length = 0;
int word_length = 0;
const char *word_start = str;
while (*str) {
// Trova la prossima parola
if (*str != ' ' && *str != '\n' && *str != '\t') {
str++;
continue;
}
// Calcola lunghezza parola corrente
word_length = str - word_start;
// Gestione wrap
if (line_length + word_length > max_width) {
y++;
x = start_x;
line_length = 0;
}
// Stampa parola
for (int i = 0; i < word_length; i++) {
mvwaddch(win, y, x++, word_start[i]);
}
line_length += word_length;
// Gestione spazi
if (*str == ' ' || *str == '\t') {
if (line_length < max_width) {
mvwaddch(win, y, x++, ' ');
line_length++;
} else {
y++;
x = start_x;
line_length = 0;
}
} else if (*str == '\n') {
y++;
x = start_x;
line_length = 0;
}
word_start = ++str;
}
// Stampa ultima parola
word_length = strlen(word_start);
if (line_length + word_length > max_width) {
y++;
x = start_x;
}
mvwprintw(win, y, x, "%s", word_start);
}
int checkIfFileExists(){
return 0;
}
void changeFile(){
@@ -165,5 +251,6 @@ void changeFile(){
int getCount(){
return 0;
}