refactoring; modal window init
This commit is contained in:
@@ -10,12 +10,15 @@ OBJS := $(SRCS:$(SRC_DIR)/%.c=$(OBJ_DIR)/%.o)
|
|||||||
UI_SRCS := $(wildcard $(SRC_DIR)/ui/*.c $(SRC_DIR)/ui/**/*.c)
|
UI_SRCS := $(wildcard $(SRC_DIR)/ui/*.c $(SRC_DIR)/ui/**/*.c)
|
||||||
OBJS += $(UI_SRCS:$(SRC_DIR)/ui/%.c=$(OBJ_DIR)/ui/%.o)
|
OBJS += $(UI_SRCS:$(SRC_DIR)/ui/%.c=$(OBJ_DIR)/ui/%.o)
|
||||||
|
|
||||||
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c $(SRC_DIR)/main.h
|
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c $(SRC_DIR)/%.h
|
||||||
$(CC) $(CFLAGS) -c $< -o $@
|
$(CC) $(CFLAGS) -c $< -o $@
|
||||||
|
|
||||||
$(OBJ_DIR)/ui/%.o: $(SRC_DIR)/ui/%.c $(SRC_DIR)/ui/%.h
|
$(OBJ_DIR)/ui/%.o: $(SRC_DIR)/ui/%.c $(SRC_DIR)/ui/%.h
|
||||||
$(CC) $(CFLAGS) -c $< -o $@
|
$(CC) $(CFLAGS) -c $< -o $@
|
||||||
|
|
||||||
|
$(OBJ_DIR)/ui/widget/%.o: $(SRC_DIR)/ui/widget/%.c $(SRC_DIR)/ui/widget/%.h
|
||||||
|
$(CC) $(CFLAGS) -c $< -o $@
|
||||||
|
|
||||||
bbs-client: $(OBJS)
|
bbs-client: $(OBJS)
|
||||||
$(CC) $(CFLAGS) $^ -o $(BIN_DIR)/$@
|
$(CC) $(CFLAGS) $^ -o $(BIN_DIR)/$@
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
|
#include "file_processor.h"
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
#include "client.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
#ifndef CLIENT_H
|
||||||
|
#define CLIENT_H
|
||||||
|
#include "main.h"
|
||||||
|
|
||||||
|
int process_client_command(char *line, int l_len, query_args_t *q_args);
|
||||||
|
void print_prompt(params_t *params);
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
#ifndef CONNECTION_H
|
||||||
|
#define CONNECTION_H
|
||||||
|
#include "main.h"
|
||||||
|
|
||||||
|
void connect_to_server(int sd, params_t *params);
|
||||||
|
void init_params(params_t *restrict);
|
||||||
|
void clear_params(params_t *params);
|
||||||
|
void get_missing_params(params_t *restrict);
|
||||||
|
void close_session(int sd);
|
||||||
|
int init_client();
|
||||||
|
void analyze_args(int argc, char *argv[], params_t *restrict);
|
||||||
|
|
||||||
|
#endif
|
||||||
+18
@@ -0,0 +1,18 @@
|
|||||||
|
client.o: src/client.c src/file_processor.h src/main.h src/types.h \
|
||||||
|
src/client.h
|
||||||
|
connection.o: src/connection.c src/main.h src/types.h
|
||||||
|
file_processor.o: src/file_processor.c src/client.h src/main.h \
|
||||||
|
src/types.h src/query.h
|
||||||
|
main.o: src/main.c src/main.h src/types.h src/modal.h src/ui/app.h \
|
||||||
|
src/ui/widget/dialogue.h src/ui/widget/../widget.h \
|
||||||
|
src/ui/widget/../../main.h src/ui/widget/button.h \
|
||||||
|
src/ui/widget/../../main.h src/ui/widget/dialogue.h
|
||||||
|
modal.o: src/modal.c src/ui/app.h src/ui/widget/dialogue.h \
|
||||||
|
src/ui/widget/../widget.h src/ui/widget/../../main.h \
|
||||||
|
src/ui/widget/../../types.h src/ui/widget/button.h \
|
||||||
|
src/ui/widget/../../main.h
|
||||||
|
query.o: src/query.c src/file_processor.h src/main.h src/types.h \
|
||||||
|
src/connection.h src/client.h src/server.h
|
||||||
|
server.o: src/server.c src/client.h src/main.h src/types.h \
|
||||||
|
src/connection.h src/query.h src/ui.h
|
||||||
|
ui.o: src/ui.c
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
|
#include "client.h"
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
#include "query.h"
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
@@ -58,17 +60,16 @@ void file_list(file_args_t *f_args, query_args_t *q_args) {
|
|||||||
void file_select(file_args_t *f_args, query_args_t *q_args) {
|
void file_select(file_args_t *f_args, query_args_t *q_args) {
|
||||||
char *buf = q_args->buf;
|
char *buf = q_args->buf;
|
||||||
fl_item_t *l_start = f_args->l_start;
|
fl_item_t *l_start = f_args->l_start;
|
||||||
fl_item_t *l_current = f_args->l_current;
|
// fl_item_t *l_current = f_args->l_current;
|
||||||
fl_item_t *l_selected; /* from the list */
|
fl_item_t *l_selected; /* from the list */
|
||||||
fl_item_t *f_selected =
|
fl_item_t *f_selected =
|
||||||
&(f_args->f_selected); /* new copy of file struct (list be cleared) */
|
&(f_args->f_selected); /* new copy of file struct (list be cleared) */
|
||||||
uint32_t filenum;
|
uint32_t filenum;
|
||||||
uint32_t pagenum;
|
|
||||||
uint32_t qlen;
|
uint32_t qlen;
|
||||||
char send_buf[256];
|
char send_buf[256];
|
||||||
struct stat st = {0};
|
struct stat st = {0};
|
||||||
|
|
||||||
if (!(sscanf(buf, "%d", &filenum))) {
|
if (!(sscanf(buf, "%u", &filenum))) {
|
||||||
write(q_args->sd, buf, strlen(buf));
|
write(q_args->sd, buf, strlen(buf));
|
||||||
q_args->state = STATE_FILE_LIST;
|
q_args->state = STATE_FILE_LIST;
|
||||||
fl_clear(&f_args->l_start, &f_args->l_current);
|
fl_clear(&f_args->l_start, &f_args->l_current);
|
||||||
@@ -240,7 +241,6 @@ void init_file_args(file_args_t *f_args) {
|
|||||||
/* work with file list */
|
/* work with file list */
|
||||||
static void fl_add(fl_item_t **cur, fl_item_t **start, char *line) {
|
static void fl_add(fl_item_t **cur, fl_item_t **start, char *line) {
|
||||||
char fname[128];
|
char fname[128];
|
||||||
size_t fsize;
|
|
||||||
char fowner[32];
|
char fowner[32];
|
||||||
int h_len;
|
int h_len;
|
||||||
fl_item_t *fitem = malloc(sizeof(fl_item_t));
|
fl_item_t *fitem = malloc(sizeof(fl_item_t));
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
#ifndef FILE_PROCESSOR_H
|
||||||
|
#define FILE_PROCESSOR_H
|
||||||
|
#include "main.h"
|
||||||
|
|
||||||
|
void file_list(file_args_t *f_args, query_args_t *q_args);
|
||||||
|
void file_download(file_args_t *f_args, query_args_t *q_args);
|
||||||
|
void file_select(file_args_t *fargs, query_args_t *q_args);
|
||||||
|
void init_file_args(file_args_t *fargs);
|
||||||
|
int file_upload_request(char *, query_args_t *q_args);
|
||||||
|
int file_upload_start(query_args_t *q_args);
|
||||||
|
int file_upload(query_args_t *q_args);
|
||||||
|
|
||||||
|
#endif
|
||||||
+11
@@ -9,6 +9,7 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "ui/app.h"
|
#include "ui/app.h"
|
||||||
|
#include "ui/widget/dialogue.h"
|
||||||
#include <ncurses.h>
|
#include <ncurses.h>
|
||||||
|
|
||||||
void event_loop(app_t *app);
|
void event_loop(app_t *app);
|
||||||
@@ -24,6 +25,11 @@ int main(int argc, char **argv) {
|
|||||||
wrefresh(app->menu_win);
|
wrefresh(app->menu_win);
|
||||||
wrefresh(app->action_win);
|
wrefresh(app->action_win);
|
||||||
|
|
||||||
|
// temporal
|
||||||
|
app->modal.active = login;
|
||||||
|
dialogue_t *dialogue = init_dialogue("Login");
|
||||||
|
draw_dialogue(dialogue, app->cur_x, app->cur_y);
|
||||||
|
|
||||||
event_loop(app);
|
event_loop(app);
|
||||||
|
|
||||||
destroy_app(app);
|
destroy_app(app);
|
||||||
@@ -38,6 +44,11 @@ void event_loop(app_t *app) {
|
|||||||
for (;;) {
|
for (;;) {
|
||||||
c = wgetch(app->win);
|
c = wgetch(app->win);
|
||||||
|
|
||||||
|
// if (app->modal.active != none_active) {
|
||||||
|
// modal_event_loop(c, app);
|
||||||
|
// continue;
|
||||||
|
// }
|
||||||
|
|
||||||
switch (c) {
|
switch (c) {
|
||||||
// 113 is q key. This exits the program
|
// 113 is q key. This exits the program
|
||||||
case 113:
|
case 113:
|
||||||
|
|||||||
+7
-27
@@ -1,3 +1,6 @@
|
|||||||
|
#ifndef MAIN_H
|
||||||
|
#define MAIN_H
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
@@ -6,6 +9,7 @@
|
|||||||
#define LISTEN_QLEN 32
|
#define LISTEN_QLEN 32
|
||||||
#define INBUFSIZE 1024
|
#define INBUFSIZE 1024
|
||||||
#define DOWNLOADS_DIR "./Downloads"
|
#define DOWNLOADS_DIR "./Downloads"
|
||||||
|
#define DIALOGUE_TITLE 64
|
||||||
|
|
||||||
typedef struct params {
|
typedef struct params {
|
||||||
unsigned short port;
|
unsigned short port;
|
||||||
@@ -29,8 +33,9 @@ enum state {
|
|||||||
STATE_UPLOAD_FILE,
|
STATE_UPLOAD_FILE,
|
||||||
STATE_UPLOAD_REQUESTED,
|
STATE_UPLOAD_REQUESTED,
|
||||||
STATE_ASK_USER_BEFORE_LOGIN,
|
STATE_ASK_USER_BEFORE_LOGIN,
|
||||||
ERR,
|
STATE_ERR,
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct p_file {
|
typedef struct p_file {
|
||||||
char *name;
|
char *name;
|
||||||
size_t size;
|
size_t size;
|
||||||
@@ -63,29 +68,4 @@ typedef struct query_args {
|
|||||||
params_t *params;
|
params_t *params;
|
||||||
} query_args_t;
|
} query_args_t;
|
||||||
|
|
||||||
void init_params(params_t *restrict);
|
#endif
|
||||||
void analyze_args(int argc, char *argv[], params_t *restrict);
|
|
||||||
void get_missing_params(params_t *restrict);
|
|
||||||
void connect_to_server(int sd, params_t *params);
|
|
||||||
int init_client();
|
|
||||||
void close_session(int sd);
|
|
||||||
void wait_register(query_args_t *q_args);
|
|
||||||
int process_query(query_args_t *query_args, file_args_t *file_args);
|
|
||||||
void query_loop(int sd, params_t *);
|
|
||||||
int query_extract_from_buf(char *buf, int *buf_used, char **output_line);
|
|
||||||
int process_client_command(char *line, int l_len, query_args_t *q_args);
|
|
||||||
int process_server_command(char *line, int l_len, query_args_t *q_args);
|
|
||||||
void ask_register(params_t *params, char *email);
|
|
||||||
|
|
||||||
void clear_params(params_t *params);
|
|
||||||
|
|
||||||
/* file processor */
|
|
||||||
void file_list(file_args_t *f_args, query_args_t *q_args);
|
|
||||||
void file_download(file_args_t *f_args, query_args_t *q_args);
|
|
||||||
void file_select(file_args_t *fargs, query_args_t *q_args);
|
|
||||||
void init_file_args(file_args_t *fargs);
|
|
||||||
int file_upload_request(char *, query_args_t *q_args);
|
|
||||||
int file_upload_start(query_args_t *q_args);
|
|
||||||
int file_upload(query_args_t *q_args);
|
|
||||||
|
|
||||||
void print_prompt(params_t *params);
|
|
||||||
+20
@@ -0,0 +1,20 @@
|
|||||||
|
#include "ui/app.h"
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
int32_t m_login(char evt_c, app_t *app);
|
||||||
|
|
||||||
|
int32_t modal_event_loop(char evt_c, app_t *app) {
|
||||||
|
switch (app->modal.active) {
|
||||||
|
|
||||||
|
case none_active:
|
||||||
|
return 0;
|
||||||
|
case login:
|
||||||
|
m_login(evt_c, app);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t m_login(char evt_c, app_t *app) {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
#ifndef MODAL_H
|
||||||
|
#define MODAL_H
|
||||||
|
|
||||||
|
#include "ui/app.h"
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
int32_t modal_event_loop(char evt_c, app_t *app);
|
||||||
|
|
||||||
|
#endif
|
||||||
+6
-2
@@ -1,4 +1,8 @@
|
|||||||
|
#include "file_processor.h"
|
||||||
|
#include "connection.h"
|
||||||
|
#include "client.h"
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
#include "server.h"
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
@@ -19,6 +23,7 @@ static void init_query_args(query_args_t *q_args, int sd, char *buf,
|
|||||||
enum state state, int buf_used, params_t *params);
|
enum state state, int buf_used, params_t *params);
|
||||||
static void wait_side(query_args_t *q_args);
|
static void wait_side(query_args_t *q_args);
|
||||||
void user_request_description(query_args_t *q_args);
|
void user_request_description(query_args_t *q_args);
|
||||||
|
int process_query(query_args_t *query_args, file_args_t *file_args);
|
||||||
|
|
||||||
void query_loop(int sd, params_t *params) {
|
void query_loop(int sd, params_t *params) {
|
||||||
fd_set readfds;
|
fd_set readfds;
|
||||||
@@ -26,7 +31,6 @@ void query_loop(int sd, params_t *params) {
|
|||||||
size_t qlen;
|
size_t qlen;
|
||||||
int sr;
|
int sr;
|
||||||
char buf[INBUFSIZE];
|
char buf[INBUFSIZE];
|
||||||
char *bufs = buf;
|
|
||||||
static file_args_t file_args;
|
static file_args_t file_args;
|
||||||
static query_args_t query_args;
|
static query_args_t query_args;
|
||||||
|
|
||||||
@@ -114,7 +118,7 @@ int process_query(query_args_t *query_args, file_args_t *file_args) {
|
|||||||
wait_side(query_args);
|
wait_side(query_args);
|
||||||
break;
|
break;
|
||||||
case UPLOAD_FILE:
|
case UPLOAD_FILE:
|
||||||
case ERR:
|
case STATE_ERR:
|
||||||
break;
|
break;
|
||||||
case STATE_FILE_LIST:
|
case STATE_FILE_LIST:
|
||||||
file_list(file_args, query_args);
|
file_list(file_args, query_args);
|
||||||
|
|||||||
+10
@@ -0,0 +1,10 @@
|
|||||||
|
#ifndef QUERY_H
|
||||||
|
#define QUERY_H
|
||||||
|
|
||||||
|
#include "main.h"
|
||||||
|
void query_loop(int sd, params_t *);
|
||||||
|
void wait_register(query_args_t *q_args);
|
||||||
|
int process_query(query_args_t *query_args, file_args_t *file_args);
|
||||||
|
int query_extract_from_buf(char *buf, int *buf_used, char **output_line);
|
||||||
|
|
||||||
|
#endif
|
||||||
+3
-1
@@ -1,4 +1,7 @@
|
|||||||
|
#include "client.h"
|
||||||
|
#include "connection.h"
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
#include "query.h"
|
||||||
#include "ui.h"
|
#include "ui.h"
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
@@ -19,7 +22,6 @@ int process_server_command(char *line, int l_len, query_args_t *q_args) {
|
|||||||
int ws_pos = l_len;
|
int ws_pos = l_len;
|
||||||
params_t *params = q_args->params;
|
params_t *params = q_args->params;
|
||||||
const char *login_options[] = {"Username", "Anonymous", "Register", NULL};
|
const char *login_options[] = {"Username", "Anonymous", "Register", NULL};
|
||||||
char r_buf[INBUFSIZE];
|
|
||||||
uint32_t answer;
|
uint32_t answer;
|
||||||
|
|
||||||
char *cptr = strchr(line, ' ');
|
char *cptr = strchr(line, ' ');
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
#ifndef SERVER_H
|
||||||
|
#define SERVER_H
|
||||||
|
|
||||||
|
#include "main.h"
|
||||||
|
int process_server_command(char *line, int l_len, query_args_t *q_args);
|
||||||
|
void ask_register(params_t *params, char *email);
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -3,7 +3,6 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
uint32_t print_ask_list(char title[], const char *options[]) {
|
uint32_t print_ask_list(char title[], const char *options[]) {
|
||||||
char *option;
|
|
||||||
char c;
|
char c;
|
||||||
uint32_t i, answer;
|
uint32_t i, answer;
|
||||||
|
|
||||||
|
|||||||
+5
-3
@@ -29,7 +29,7 @@ app_t *init_app() {
|
|||||||
_app->action_win = newwin(y_max - 4, action_w_x, 2, menu_w_x + 1);
|
_app->action_win = newwin(y_max - 4, action_w_x, 2, menu_w_x + 1);
|
||||||
|
|
||||||
// dialogue
|
// dialogue
|
||||||
_app->modal.win = NULL;
|
_app->modal.dialogue.win = NULL;
|
||||||
|
|
||||||
// print decorative bars
|
// print decorative bars
|
||||||
print_bars(_app);
|
print_bars(_app);
|
||||||
@@ -70,6 +70,7 @@ void init_nc() {
|
|||||||
start_color();
|
start_color();
|
||||||
init_pair(1, COLOR_RED, COLOR_BLACK);
|
init_pair(1, COLOR_RED, COLOR_BLACK);
|
||||||
init_pair(2, COLOR_GREEN, COLOR_BLACK);
|
init_pair(2, COLOR_GREEN, COLOR_BLACK);
|
||||||
|
init_pair(MODAL_COLOR_PAIR, COLOR_BLUE, COLOR_WHITE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,8 +95,9 @@ void print_bars(app_t *app) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// add content to the top bar
|
// add content to the top bar
|
||||||
mvwprintw(app->win, 1, 2, "example curses app | ");
|
mvwprintw(app->win, 1, 2, "example cprint_barsurses app | ");
|
||||||
mvwprintw(app->win, 1, 20, "size %d, %d", app->cur_x, app->cur_y);
|
mvwprintw(app->win, 1, sizeof "example cprint_barsurses app | " + 1,
|
||||||
|
"size %d, %d", app->cur_x, app->cur_y);
|
||||||
|
|
||||||
// add content to the bottom bar
|
// add content to the bottom bar
|
||||||
mvwprintw(app->win, app->cur_y - 2, 2, "F1 - Help | F9 - Quit");
|
mvwprintw(app->win, app->cur_y - 2, 2, "F1 - Help | F9 - Quit");
|
||||||
|
|||||||
+7
-2
@@ -2,9 +2,14 @@
|
|||||||
#define N_APP_H
|
#define N_APP_H
|
||||||
|
|
||||||
#include <ncurses.h>
|
#include <ncurses.h>
|
||||||
|
#include "widget/dialogue.h"
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
none = 0,
|
MODAL_COLOR_PAIR = 3,
|
||||||
|
} color;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
none_active = 0,
|
||||||
login = 1,
|
login = 1,
|
||||||
} dialogue_e;
|
} dialogue_e;
|
||||||
|
|
||||||
@@ -14,7 +19,7 @@ typedef struct {
|
|||||||
WINDOW *action_win;
|
WINDOW *action_win;
|
||||||
struct {
|
struct {
|
||||||
dialogue_e active;
|
dialogue_e active;
|
||||||
WINDOW *win;
|
dialogue_t dialogue;
|
||||||
} modal;
|
} modal;
|
||||||
|
|
||||||
// menu_bar_t *menu_bar;
|
// menu_bar_t *menu_bar;
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
#ifndef WIDGET_H
|
||||||
|
#define WIDGET_H
|
||||||
|
|
||||||
|
#include "../main.h"
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
char title[DIALOGUE_TITLE];
|
||||||
|
uint32_t x;
|
||||||
|
uint32_t y;
|
||||||
|
uint32_t m_x;
|
||||||
|
uint32_t m_y;
|
||||||
|
char color_pair;
|
||||||
|
} widget_t;
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
#ifndef BUTTON_H
|
||||||
|
#define BUTTON_H
|
||||||
|
|
||||||
|
#include "../../main.h"
|
||||||
|
#include "../widget.h"
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
widget_t widget;
|
||||||
|
char value;
|
||||||
|
uint32_t is_focused : 1;
|
||||||
|
uint32_t is_disabled : 1;
|
||||||
|
} button_t;
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
#include "dialogue.h"
|
||||||
|
#include "../app.h"
|
||||||
|
#include <ncurses.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
dialogue_t *init_dialogue(char title[]) {
|
||||||
|
dialogue_t *dialogue = malloc(sizeof(dialogue_t));
|
||||||
|
dialogue->win = 0;
|
||||||
|
dialogue->buttons = NULL;
|
||||||
|
strcpy(dialogue->w.title, title);
|
||||||
|
return dialogue;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t draw_dialogue(dialogue_t *d, uint32_t cur_x, uint32_t cur_y) {
|
||||||
|
d->w.x = 50;
|
||||||
|
d->w.y = 20;
|
||||||
|
d->w.m_x = (cur_x - d->w.x) / 2;
|
||||||
|
d->w.m_y = (cur_y - d->w.y) / 2;
|
||||||
|
|
||||||
|
d->win = newwin(d->w.y, d->w.x, d->w.m_y, d->w.m_x);
|
||||||
|
|
||||||
|
wcolor_set(d->win, MODAL_COLOR_PAIR, NULL);
|
||||||
|
wattrset(d->win, A_REVERSE);
|
||||||
|
|
||||||
|
for (int xp = 1; xp < d->w.x; xp++) {
|
||||||
|
for (int yp = 1; yp < d->w.y - 1; yp++) {
|
||||||
|
mvwprintw(d->win, yp, xp, " ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t title_mx_pos = (d->w.x - strlen(d->w.title)) / 2;
|
||||||
|
|
||||||
|
box(d->win, 0, 0);
|
||||||
|
mvwprintw(d->win, 0, title_mx_pos-1, " ");
|
||||||
|
mvwprintw(d->win, 0, title_mx_pos, d->w.title);
|
||||||
|
mvwprintw(d->win, 0, title_mx_pos + strlen(d->w.title), " ");
|
||||||
|
wattroff(d->win, A_REVERSE);
|
||||||
|
wrefresh(d->win);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
void destroy_active_dialogue(dialogue_t *d) {
|
||||||
|
delwin(d->win);
|
||||||
|
free(d->win);
|
||||||
|
d->win = NULL;
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
#ifndef DIALOGUE_H
|
||||||
|
#define DIALOGUE_H
|
||||||
|
|
||||||
|
#include <ncurses.h>
|
||||||
|
#include "../widget.h"
|
||||||
|
#include "button.h"
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
WINDOW *win;
|
||||||
|
widget_t w;
|
||||||
|
button_t *buttons; // ! should be NULL-terminated
|
||||||
|
} dialogue_t;
|
||||||
|
|
||||||
|
dialogue_t *init_dialogue(char title[]);
|
||||||
|
int32_t draw_dialogue(dialogue_t *d, uint32_t cur_x, uint32_t cur_y);
|
||||||
|
void destroy_active_dialogue(dialogue_t *d);
|
||||||
|
|
||||||
|
#endif
|
||||||
Reference in New Issue
Block a user