DungeonCrawl
Loading...
Searching...
No Matches
menu.c File Reference

Implementation of helper functions for menus. More...

#include "menu.h"
#include "../common.h"
#include "../io/input/input_handler.h"
#include "../io/output/common/output_handler.h"
#include "../logging/logger.h"
#include "local/save_menu_local.h"
#include <string.h>

Go to the source code of this file.

Functions

void draw_menu (const char **menu_options, int menu_count, int selected_index)
 Draws a menu with the given options.
bool show_confirmation (const char *message)
 Shows a confirmation dialog with the given message.

Detailed Description

Implementation of helper functions for menus.

Definition in file menu.c.

Function Documentation

◆ draw_menu()

void draw_menu ( const char ** menu_options,
int menu_count,
int selected_index )

Draws a menu with the given options.

Parameters
menu_optionsArray of menu option strings
menu_countNumber of menu options
selected_indexCurrently selected menu index

Definition at line 15 of file menu.c.

15 {
16 // Clear the screen
18
19 // Draw title
20 print_text(MENU_START_Y, MENU_START_X, TITLE, RED_TEXT_COLORS);
21
22 // Draw menu options
23 int y = MENU_START_Y + 3;
24 for (int i = 0; i < menu_count; i++) {
25 if (i == selected_index) {
26 // Highlight selected option
27 print_text(y, MENU_START_X, menu_options[i], INVERTED_COLORS);
28 } else {
29 // Normal option
30 print_text_default(y, MENU_START_X, menu_options[i]);
31 }
32 y += MENU_ITEM_SPACING;
33 }
34
35 // Render the frame
37}
void print_text(int y, int x, const char *text, uint64_t ncchannel)
Print text at a specific position.
void print_text_default(int y, int x, const char *text)
Print text at a specific position with default colors.
bool render_frame(void)
Render the current frame.
void clear_screen(void)
Clear the screen.

◆ show_confirmation()

bool show_confirmation ( const char * message)

Shows a confirmation dialog with the given message.

Parameters
messageThe message to display
Returns
true if the user confirmed, false otherwise

Definition at line 39 of file menu.c.

39 {
40 // Clear the screen
42
43 // Print confirmation messages
44 print_text_default(MENU_START_Y, MENU_START_X, save_menu_strings[WARNING_LOST_PROGRESS]);
45 print_text_default(MENU_START_Y + 2, MENU_START_X, message);
46 print_text_default(MENU_START_Y + 4, MENU_START_X, "(Y/N)");
47
48 // Render the frame
50
51 // Wait for Y/N input
52 while (1) {
53 input_event_t input_event;
54 if (get_input_blocking(&input_event)) {
55 if (input_event.raw_input.id == 'y' || input_event.raw_input.id == 'Y') {
56 return true;
57 } else if (input_event.raw_input.id == 'n' || input_event.raw_input.id == 'N') {
58 return false;
59 }
60 }
61 }
62}
bool get_input_blocking(input_event_t *event)
Get the next input event (blocking)
Structure for advanced input events with context data.
Definition input_types.h:43