rendering stuff except not much
This commit is contained in:
parent
3db04e5a5b
commit
fc61921ab6
7 changed files with 92 additions and 30 deletions
BIN
core
Normal file
BIN
core
Normal file
Binary file not shown.
2
debug
2
debug
|
@ -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
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
#define BANNER_WIDTH 57
|
||||
#define BANNER_HEIGHT 6
|
||||
#define AFTER_BANNER BANNER_HEIGHT + 6
|
||||
#define AFTER_BANNER BANNER_HEIGHT + 3
|
||||
char BANNER[BANNER_HEIGHT][BANNER_WIDTH + 1] = {
|
||||
". : :::. :: .: ... ... :::",
|
||||
";;,. ;;; ;;`;; ,;; ;;, .;;;;;;;. ;; ;;;",
|
||||
|
@ -31,6 +31,7 @@ struct {
|
|||
|
||||
static int main_menu();
|
||||
static void how_to_play();
|
||||
static void login_prompt(char*, uint16_t*);
|
||||
static void create_account();
|
||||
static void client_loop();
|
||||
|
||||
|
@ -47,6 +48,7 @@ void client() {
|
|||
return;
|
||||
}
|
||||
|
||||
setlocale(LC_ALL, "");
|
||||
initscr();
|
||||
|
||||
start_color();
|
||||
|
@ -73,21 +75,14 @@ void client() {
|
|||
|
||||
endwin();
|
||||
|
||||
/*char in[10];
|
||||
sock_recv(sock, in, 10);
|
||||
printf("got %s\r\n", in);
|
||||
|
||||
sock_send(sock, "hello", 6);
|
||||
printf("sent message");
|
||||
|
||||
sock_stop(sock);
|
||||
sock_free(sock);*/
|
||||
sock_stop(ctx.sock);
|
||||
sock_free(ctx.sock);
|
||||
}
|
||||
|
||||
static void draw_banner() {
|
||||
int 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() {
|
||||
|
@ -96,10 +91,13 @@ static int main_menu() {
|
|||
|
||||
clear();
|
||||
noecho();
|
||||
//raw();
|
||||
cbreak();
|
||||
|
||||
#ifdef WORK
|
||||
init_pair(1, COLOR_WHITE, COLOR_BLACK);
|
||||
#else
|
||||
init_pair(1, COLOR_WHITE, COLOR_BLUE);
|
||||
#endif
|
||||
init_pair(2, COLOR_BLACK, COLOR_CYAN);
|
||||
|
||||
attron(COLOR_PAIR(1) | A_BOLD);
|
||||
|
@ -114,7 +112,7 @@ static int main_menu() {
|
|||
color = selected == i ? 2 : 1;
|
||||
|
||||
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]);
|
||||
attroff(COLOR_PAIR(color));
|
||||
}
|
||||
|
@ -152,21 +150,8 @@ void how_to_play() {
|
|||
}
|
||||
|
||||
void create_account() {
|
||||
clear();
|
||||
noecho();
|
||||
cbreak();
|
||||
|
||||
init_pair(1, COLOR_WHITE, COLOR_BLUE);
|
||||
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);
|
||||
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");
|
||||
|
||||
int a = 0;
|
||||
while(a != KEY_LF)
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#define CLIENT_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <locale.h>
|
||||
#include <ncurses.h>
|
||||
#include "sock.h"
|
||||
#include "screen.h"
|
||||
|
|
|
@ -7,6 +7,13 @@ void scr_char_fill(char 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() {
|
||||
scr_char_fill(' ');
|
||||
}
|
||||
|
@ -14,3 +21,55 @@ void scr_fill() {
|
|||
void scr_hide_cursor() {
|
||||
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));
|
||||
}
|
|
@ -3,9 +3,22 @@
|
|||
|
||||
#include <ncurses.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include "common.h"
|
||||
|
||||
void scr_fill();
|
||||
void scr_char_fill(char);
|
||||
void scr_wchar_fill(wchar_t);
|
||||
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
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#define WORK
|
||||
|
||||
#define FALSE 0
|
||||
#define TRUE 1
|
||||
#define BOOL char
|
||||
|
@ -12,6 +14,8 @@
|
|||
#define MAX(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 MAX_CONNS 100
|
||||
|
|
Loading…
Reference in a new issue