65 lines
1.6 KiB
C
65 lines
1.6 KiB
C
//
|
|
// Created by william on 1/12/24.
|
|
//
|
|
|
|
#include <assert.h>
|
|
#include <stdlib.h>
|
|
#include "window.h"
|
|
|
|
void window_init(Window *window, int x, int y, int width, int height, char *title) {
|
|
assert(x >= 0);
|
|
assert(y >= 0);
|
|
assert(width > 0);
|
|
assert(height > 0);
|
|
|
|
WINDOW *curse_win = newwin(height, width, y, x);
|
|
box(curse_win, 0, 0);
|
|
|
|
mvwprintw(curse_win, 0, 1, " %s ", title);
|
|
|
|
window->panel = new_panel(curse_win);
|
|
window->width = width;
|
|
window->height = height;
|
|
}
|
|
|
|
void window_inter_init(InteractWindow *window, int x, int y, int width, int height, char *title) {
|
|
window_init(&window->window, x, y, width, height, title);
|
|
}
|
|
|
|
void window_print_va(Window *window, int x, int y, const char *fmt, va_list args) {
|
|
assert(x >= 0);
|
|
assert(x < window->width - 1);
|
|
assert(y >= 0);
|
|
assert(y < window->height - 1);
|
|
|
|
wmove(window->panel->win, y + 1, x + 1);
|
|
vw_printw(window->panel->win, fmt, args);
|
|
}
|
|
|
|
void window_inter_cursor_init(InteractWindow *window, int max_x, int max_y) {
|
|
cursor_init(&window->cursor, window->window.panel->win, max_x, max_y);
|
|
}
|
|
|
|
void window_print(Window *window, int x, int y, const char *fmt, ...) {
|
|
va_list args;
|
|
va_start(args, fmt);
|
|
window_print_va(window, x, y, fmt, args);
|
|
va_end(args);
|
|
}
|
|
|
|
void window_inter_print(InteractWindow *window, int x, int y, const char *fmt, ...) {
|
|
va_list args;
|
|
va_start(args, fmt);
|
|
window_print_va(&window->window, x, y, fmt, args);
|
|
va_end(args);
|
|
}
|
|
|
|
void window_inter_deinit(InteractWindow *window) {
|
|
assert(window->view != NULL);
|
|
|
|
if (window->deinit != NULL) {
|
|
window->deinit(window);
|
|
}
|
|
|
|
free(window->view);
|
|
} |