rendering stuff except not much

This commit is contained in:
mallocnull 2017-11-06 17:02:04 -06:00
parent 3db04e5a5b
commit fc61921ab6
7 changed files with 92 additions and 30 deletions

BIN
core Normal file

Binary file not shown.

2
debug
View file

@ -1,2 +1,2 @@
gcc src/*.c src/server/*.c src/client/*.c -g -iquotesrc/ -lpthread -lncurses -o bin/mahou gcc src/*.c src/server/*.c src/client/*.c -g -iquotesrc/ -lpthread -lncursesw -o bin/mahou
chmod +x bin/mahou chmod +x bin/mahou

View file

@ -2,7 +2,7 @@
#define BANNER_WIDTH 57 #define BANNER_WIDTH 57
#define BANNER_HEIGHT 6 #define BANNER_HEIGHT 6
#define AFTER_BANNER BANNER_HEIGHT + 6 #define AFTER_BANNER BANNER_HEIGHT + 3
char BANNER[BANNER_HEIGHT][BANNER_WIDTH + 1] = { char BANNER[BANNER_HEIGHT][BANNER_WIDTH + 1] = {
". : :::. :: .: ... ... :::", ". : :::. :: .: ... ... :::",
";;,. ;;; ;;`;; ,;; ;;, .;;;;;;;. ;; ;;;", ";;,. ;;; ;;`;; ,;; ;;, .;;;;;;;. ;; ;;;",
@ -31,6 +31,7 @@ struct {
static int main_menu(); static int main_menu();
static void how_to_play(); static void how_to_play();
static void login_prompt(char*, uint16_t*);
static void create_account(); static void create_account();
static void client_loop(); static void client_loop();
@ -47,6 +48,7 @@ void client() {
return; return;
} }
setlocale(LC_ALL, "");
initscr(); initscr();
start_color(); start_color();
@ -72,22 +74,15 @@ void client() {
} }
endwin(); endwin();
/*char in[10]; sock_stop(ctx.sock);
sock_recv(sock, in, 10); sock_free(ctx.sock);
printf("got %s\r\n", in);
sock_send(sock, "hello", 6);
printf("sent message");
sock_stop(sock);
sock_free(sock);*/
} }
static void draw_banner() { static void draw_banner() {
int i; int i;
for(i = 0; i < BANNER_HEIGHT; ++i) for(i = 0; i < BANNER_HEIGHT; ++i)
mvprintw(3 + i, (COLS - BANNER_WIDTH) / 2, BANNER[i]); scr_center_write(BANNER[i], BANNER_WIDTH, 3 + i);
} }
static int main_menu() { static int main_menu() {
@ -96,10 +91,13 @@ static int main_menu() {
clear(); clear();
noecho(); noecho();
//raw();
cbreak(); cbreak();
#ifdef WORK
init_pair(1, COLOR_WHITE, COLOR_BLACK);
#else
init_pair(1, COLOR_WHITE, COLOR_BLUE); init_pair(1, COLOR_WHITE, COLOR_BLUE);
#endif
init_pair(2, COLOR_BLACK, COLOR_CYAN); init_pair(2, COLOR_BLACK, COLOR_CYAN);
attron(COLOR_PAIR(1) | A_BOLD); attron(COLOR_PAIR(1) | A_BOLD);
@ -114,7 +112,7 @@ static int main_menu() {
color = selected == i ? 2 : 1; color = selected == i ? 2 : 1;
attron(COLOR_PAIR(color)); attron(COLOR_PAIR(color));
mvprintw(AFTER_BANNER + i*2, (COLS - (MM_MAX_OPT_LEN + 2)) / 2, mvprintw(AFTER_BANNER + 3 + i*2, (COLS - (MM_MAX_OPT_LEN + 2)) / 2,
"* %s", MM_OPTIONS[i]); "* %s", MM_OPTIONS[i]);
attroff(COLOR_PAIR(color)); attroff(COLOR_PAIR(color));
} }
@ -152,21 +150,8 @@ void how_to_play() {
} }
void create_account() { void create_account() {
clear();
noecho();
cbreak();
init_pair(1, COLOR_WHITE, COLOR_BLUE); scr_alert(20, "this prompt box is a test of prompt box is a test of prompt box is a test of prompt box is a test of prompt box is a test of");
init_pair(2, COLOR_BLACK, COLOR_CYAN);
attron(COLOR_PAIR(1) | A_BOLD);
scr_fill();
draw_banner();
move(0, 0);
printw("%i %i %i ", KEY_BACKSPACE, KEY_BTAB, KEY_CTAB);
int a = 0; int a = 0;
while(a != KEY_LF) while(a != KEY_LF)

View file

@ -2,6 +2,7 @@
#define CLIENT_H #define CLIENT_H
#include <stdio.h> #include <stdio.h>
#include <locale.h>
#include <ncurses.h> #include <ncurses.h>
#include "sock.h" #include "sock.h"
#include "screen.h" #include "screen.h"

View file

@ -7,6 +7,13 @@ void scr_char_fill(char c) {
addch(c); addch(c);
} }
void scr_str_fill(char *s) {
int i, j;
for(i = 0; i < LINES; ++i)
for(j = 0; j < COLS; ++j)
addstr(s);
}
void scr_fill() { void scr_fill() {
scr_char_fill(' '); scr_char_fill(' ');
} }
@ -14,3 +21,55 @@ void scr_fill() {
void scr_hide_cursor() { void scr_hide_cursor() {
move(LINES - 1, COLS - 1); move(LINES - 1, COLS - 1);
} }
void scr_center_write(char *string, int length, int row) {
if(length == 0)
length = strlen(string);
mvprintw(row, (COLS - length) / 2, string);
}
void scr_box(int top, int left, int width, int height) {
int i, j;
mvaddstr(top, left, "\u2554");
for(i = 0; i < width - 2; ++i)
addstr("\u2550");
addstr("\u2557");
for(i = 0; i < height - 2; ++i) {
mvaddstr(top + i + 1, left, "\u2551");
for(j = 0; j < width - 2; ++j)
addch(' ');
addstr("\u2551");
}
mvaddstr(top, left, "\u255A");
for(i = 0; i < width - 2; ++i)
addstr("\u2550");
addstr("\u255D");
}
static int calculate_height(int width, int length) {
return (int)ciel((float)length / (float)width);
}
void scr_alert(int width, char *text) {
clear();
noecho();
cbreak();
int text_height = calculate_height(width, strlen(text));
init_pair(1, COLOR_WHITE, COLOR_BLUE);
init_pair(2, COLOR_BLACK, COLOR_CYAN);
init_pair(3, COLOR_WHITE, COLOR_BLACK);
attron(COLOR_PAIR(3));
scr_fill();
attroff(COLOR_PAIR(3));
attron(COLOR_PAIR(1));
scr_box(1, 1, 10, 10);
attroff(COLOR_PAIR(1));
}

View file

@ -3,9 +3,22 @@
#include <ncurses.h> #include <ncurses.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#include <math.h>
#include "common.h"
void scr_fill(); void scr_fill();
void scr_char_fill(char); void scr_char_fill(char);
void scr_wchar_fill(wchar_t);
void scr_hide_cursor(); void scr_hide_cursor();
void scr_center_write(char*, int, int);
void scr_box(int, int, int, int);
void scr_alert(int, char*);
BOOL scr_prompt_string(int, char*, char*, int);
BOOL scr_prompt_int(int, char*, int*);
BOOL scr_prompt_options(int, char*, char**, int, int*);
#endif #endif

View file

@ -5,6 +5,8 @@
#include <netinet/in.h> #include <netinet/in.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#define WORK
#define FALSE 0 #define FALSE 0
#define TRUE 1 #define TRUE 1
#define BOOL char #define BOOL char
@ -12,6 +14,8 @@
#define MAX(X,Y) ((X) > (Y) ? (X) : (Y)) #define MAX(X,Y) ((X) > (Y) ? (X) : (Y))
#define MIN(X,Y) ((X) < (Y) ? (X) : (Y)) #define MIN(X,Y) ((X) < (Y) ? (X) : (Y))
#define KEY_BS 8
#define KEY_TAB 9
#define KEY_LF 10 #define KEY_LF 10
#define MAX_CONNS 100 #define MAX_CONNS 100
@ -25,4 +29,4 @@ uint64_t ntohll(uint64_t);
void register_spawn_type(uint8_t); void register_spawn_type(uint8_t);
uint8_t get_spawn_type(); uint8_t get_spawn_type();
#endif #endif