Skip to content

Commit

Permalink
feat: [CHORE] Basic dynamic windowing setup
Browse files Browse the repository at this point in the history
  • Loading branch information
nots1dd committed Jul 8, 2024
1 parent ba81bfd commit 0048782
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 9 deletions.
1 change: 1 addition & 0 deletions headers/ncurses_helpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <SFML/Audio.hpp>

void ncursesSetup();
void updateWindowDimensions(int& menu_height, int& menu_width, int& title_height, int& title_width);
void ncursesWinControl(WINDOW* artist_menu_win, WINDOW* song_menu_win, WINDOW* status_win, WINDOW* title_win, const std::string& choice);
void ncursesWinLoop(MENU* artistMenu, MENU* songMenu, WINDOW* artist_menu_win, WINDOW* song_menu_win, WINDOW* status_win, WINDOW* title_win, const char* title_content, bool showingArtMen);
void displayWindow(WINDOW* menu_win, const std::string window);
Expand Down
8 changes: 4 additions & 4 deletions headers/src/keyHandlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ void handleKeyEvent_slash(MENU* artistMenu, MENU* songMenu, bool showingArtists)
getmaxyx(stdscr, y, x); // get the screen dimensions
int input_width = 40; // adjust this to your liking
int input_height = 3;
int input_x = x / 3; // center the input field
int input_y = y / 2; // center the input field
int input_y = (LINES - input_height) / 2;
int input_x = (COLS - input_width) / 2;

// create a window for the input field
WINDOW *input_win = newwin(input_height, input_width, input_y, input_x);
Expand Down Expand Up @@ -136,8 +136,8 @@ void displayLyricsWindow(WINDOW *artist_menu_win, std::string& currentLyrics, st
getmaxyx(stdscr, y, x); // get the screen dimensions
int warning_width = 75; // adjust this to your liking
int warning_height = 15;
int warning_x = x / 2; // center the input field
int warning_y = y / 2; // center the input field
int warning_y = (LINES - warning_height) / 2;
int warning_x = (COLS - warning_width) / 2 + 10;

WINDOW *warning_win = newwin(warning_height, warning_width, warning_y, warning_x);
displayWindow(warning_win, "warning");
Expand Down
11 changes: 11 additions & 0 deletions headers/src/ncurses_helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@ void ncursesSetup() {
init_pair(7, COLOR_YELLOW, COLOR_BLACK);
}

void updateWindowDimensions(int& menu_height, int& menu_width, int& title_height, int& title_width) {
int max_y, max_x;
getmaxyx(stdscr, max_y, max_x);

title_height = 2;
title_width = max_x;

menu_height = max_y - 2; // Leave space for the status window
menu_width = (max_x / 2); // Split the screen in half for two menus
}

void ncursesWinControl(WINDOW* artist_menu_win, WINDOW* song_menu_win, WINDOW* status_win, WINDOW* title_win, const std::string& choice) {
// Refresh all windows
if (choice == "refresh") {
Expand Down
25 changes: 20 additions & 5 deletions litemus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ const string BLD = "\033[1m";


const char* title_content = " LITEMUS - Light Music player ";
int menu_height = 44;
int menu_width = 90;
int title_height = 2;
int title_width = 208;

char* strdup(const char* s) {
size_t len = strlen(s);
Expand Down Expand Up @@ -73,6 +69,8 @@ int main(int argc, char* argv[]) {
std::string songsDirectory = read_file_to_string(songDirCache);
lmus_cache_main(songsDirectory, homeDir, cacheLitemusDir, cacheInfoDir, cacheInfoFile, cacheArtistDirectory, songDirCache, cacheDebugFile);
ncursesSetup();
int menu_height, menu_width, title_height, title_width;
updateWindowDimensions(menu_height, menu_width, title_height, title_width);

// Cache directory and song information
std::vector<std::string> allInodes = loadPreviousInodes(cacheInfoFile);
Expand Down Expand Up @@ -109,7 +107,7 @@ int main(int argc, char* argv[]) {
wrefresh(title_win);

WINDOW* artist_menu_win = newwin(menu_height, menu_width, 1, 0);
WINDOW* song_menu_win = newwin(menu_height, menu_width + 29, 1, menu_width);
WINDOW* song_menu_win = newwin(menu_height, menu_width, 1, menu_width);
WINDOW* status_win = newwin(10, 300, LINES - 2, 0);

// Set menus to their respective windows
Expand Down Expand Up @@ -404,6 +402,23 @@ int main(int argc, char* argv[]) {
updateStatusBar(status_win, currentSong, currentArtist, currentGenre, music, firstEnterPressed, showingLyrics);
}

if (is_term_resized(LINES, COLS)) {
clear();
refresh();
updateWindowDimensions(menu_height, menu_width, title_height, title_width);

wresize(title_win, title_height, title_width);
mvwin(title_win, 0, 0);
wresize(artist_menu_win, menu_height, menu_width);
wresize(song_menu_win, menu_height, menu_width);
mvwin(song_menu_win, 1, menu_width);
wresize(status_win, 10, title_width);
mvwin(status_win, menu_height + 2, 0);

ncursesWinControl(artist_menu_win, song_menu_win, status_win, title_win, "box");
ncursesWinControl(artist_menu_win, song_menu_win, status_win, title_win, "refresh");
}

// Update status bar and refresh windows
updateStatusBar(status_win, currentSong, currentArtist, currentGenre, music, firstEnterPressed, showingLyrics);
ncursesWinLoop(artistMenu, songMenu, artist_menu_win, song_menu_win, status_win, title_win, title_content, showingartMen);
Expand Down

0 comments on commit 0048782

Please sign in to comment.