aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
All checks were successful
build_test / build (push) Successful in 1m38s

This commit is contained in:
PoliEcho 2025-04-14 12:08:14 +02:00
parent 07388c0761
commit 2e179eb780
3 changed files with 111 additions and 27 deletions

94
src/gameske_funkce.cpp Normal file
View File

@ -0,0 +1,94 @@
#include "gameske_funkce.h"
#include <menu.h>
#include <clocale>
#include <cstddef>
#include <cstdint>
#include <cstring>
size_t spawn_menu(uint16_t begin_y, uint16_t begin_x, const char** choices,
size_t n_choices) {
ITEM** sp_items;
int c;
MENU* sp_menu;
WINDOW* sp_menu_win;
int i;
sp_items = new ITEM*[n_choices];
/* Create items */
for (i = 0; i < n_choices; ++i) {
sp_items[i] = new_item(choices[i], choices[i]);
}
/* Crate menu */
sp_menu = new_menu(sp_items);
/* Create the window to be associated with the menu */
sp_menu_win = newwin(10, 40, begin_y, begin_x);
keypad(sp_menu_win, TRUE);
/* Set main window and sub window */
set_menu_win(sp_menu, sp_menu_win);
set_menu_sub(sp_menu, derwin(sp_menu_win, 6, 38, begin_y - 1, begin_x - 3));
/* Set menu mark to the string " * " */
set_menu_mark(sp_menu, " * ");
/* Print a border around the main window and print a title */
box(sp_menu_win, 0, 0);
print_in_middle(sp_menu_win, 1, 0, 40, "My Menu", COLOR_PAIR(1));
mvwaddch(sp_menu_win, 2, 0, ACS_LTEE);
mvwhline(sp_menu_win, 2, 1, ACS_HLINE, 38);
mvwaddch(sp_menu_win, 2, 39, ACS_RTEE);
mvprintw(LINES - 2, 0, "F1 to exit");
refresh();
/* Post the menu */
post_menu(sp_menu);
wrefresh(sp_menu_win);
while ((c = wgetch(sp_menu_win)) != 10) {
switch (c) {
case KEY_DOWN:
menu_driver(sp_menu, REQ_DOWN_ITEM);
break;
case KEY_UP:
menu_driver(sp_menu, REQ_UP_ITEM);
break;
}
wrefresh(sp_menu_win);
}
size_t selected = item_index(current_item(sp_menu));
/* Unpost and free all the memory taken up */
unpost_menu(sp_menu);
free_menu(sp_menu);
for (i = 0; i < n_choices; ++i)
free_item(sp_items[i]);
delete[] sp_items;
return selected;
}
void print_in_middle(WINDOW* win, int starty, int startx, int width,
char* string, chtype color) {
int length, x, y;
float temp;
if (win == NULL)
win = stdscr;
getyx(win, y, x);
if (startx != 0)
x = startx;
if (starty != 0)
y = starty;
if (width == 0)
width = 80;
length = strlen(string);
temp = (width - length) / 2;
x = startx + (int)temp;
wattron(win, color);
mvwprintw(win, y, x, "%s", string);
wattroff(win, color);
refresh();
}

9
src/gameske_funkce.h Normal file
View File

@ -0,0 +1,9 @@
#include <ncurses.h>
#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
size_t spawn_menu(uint16_t begin_y, uint16_t begin_x, const char** choices,
size_t n_choices);
void print_in_middle(WINDOW* win, int starty, int startx, int width,
char* string, chtype color);

View File

@ -1,15 +1,15 @@
#include <curses.h>
#include <menu.h>
#include <clocale>
#include <cstdlib>
#include <cstring>
#include "gameske_funkce.h"
#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
#define CTRLD 4
const char* choices[] = {"paradox", "kompromis", "Stereotyp", "Žena"};
const char* date[] = {"2023-10-01", "2023-10-02", "2023-10-03", "2023-10-04"};
void print_in_middle(WINDOW* win, int starty, int startx, int width,
char* string, chtype color);
const char* choices2[] = {"PRINT", "EDIT", "DELETE", "Žena"};
void menu() {
ITEM** my_items;
@ -68,6 +68,11 @@ void menu() {
case KEY_UP:
menu_driver(my_menu, REQ_UP_ITEM);
break;
case 10:
mvprintw(LINES - 1, 0, "%lu",
spawn_menu(15, 45, choices2, ARRAY_SIZE(choices2)));
refresh();
break;
}
wrefresh(my_menu_win);
}
@ -80,27 +85,3 @@ void menu() {
delete[] my_items;
endwin();
}
void print_in_middle(WINDOW* win, int starty, int startx, int width,
char* string, chtype color) {
int length, x, y;
float temp;
if (win == NULL)
win = stdscr;
getyx(win, y, x);
if (startx != 0)
x = startx;
if (starty != 0)
y = starty;
if (width == 0)
width = 80;
length = strlen(string);
temp = (width - length) / 2;
x = startx + (int)temp;
wattron(win, color);
mvwprintw(win, y, x, "%s", string);
wattroff(win, color);
refresh();
}