replaced confusing u64 joinded colors with struct TimStyle
This commit is contained in:
@@ -3,12 +3,6 @@
|
||||
|
||||
#include "tim.h"
|
||||
|
||||
// colors
|
||||
#define CTXT 0xf // text black, white
|
||||
#define CFR 0x8 // frame black, gray
|
||||
#define CYES 0xa000f // yes green, black, white
|
||||
#define CNO 0x9000f // no red, black white
|
||||
|
||||
i32 main(i32 argc, char** argv) {
|
||||
if (argc < 2 || strcmp(argv[1], "-h") == 0) {
|
||||
printf("syntax: %s message\n", argv[0]);
|
||||
@@ -18,6 +12,11 @@ i32 main(i32 argc, char** argv) {
|
||||
// get text properties
|
||||
TimText msg = tim_scan_str(argv[1]);
|
||||
|
||||
TimStyle style_frame = { .brd = TimColor16_DarkGray };
|
||||
TimStyle style_text = { .fg = TimColor16_White };
|
||||
TimStyle style_yes = { .brd = TimColor16_Green, .fg = style_text.fg };
|
||||
TimStyle style_no = { .brd = TimColor16_Red, .fg = style_yes.fg };
|
||||
|
||||
while (tim_run(0)) {
|
||||
// calculate size of message box
|
||||
i32 w = MAX(msg.width + 4, 28);
|
||||
@@ -25,18 +24,18 @@ i32 main(i32 argc, char** argv) {
|
||||
|
||||
tim_scope(A, A, w, h) {
|
||||
// draw frame around entire scope
|
||||
tim_frame(0, 0, ~0, ~0, CFR);
|
||||
tim_frame(0, 0, ~0, ~0, style_frame);
|
||||
|
||||
// draw message
|
||||
tim_label(argv[1], A, 1, msg.width, msg.lines, CTXT);
|
||||
tim_label(argv[1], A, 1, msg.width, msg.lines, style_text);
|
||||
|
||||
// draw 'yes' button, return 0 when clicked
|
||||
if (tim_button("[y] Yes", 2, ~1, A, A, CYES) || tim_is_key_press('y')) {
|
||||
if (tim_button("[y] Yes", 2, ~1, A, A, style_yes) || tim_is_key_press('y')) {
|
||||
exit(0);
|
||||
}
|
||||
|
||||
// draw 'no' button, return 1 when clicked
|
||||
if (tim_button("[n] No", ~2, ~1, A, A, CNO) || tim_is_key_press('n')) {
|
||||
if (tim_button("[n] No", ~2, ~1, A, A, style_no) || tim_is_key_press('n')) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@@ -46,4 +45,5 @@ i32 main(i32 argc, char** argv) {
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,15 +1,20 @@
|
||||
#include "tim.h"
|
||||
|
||||
i32 main(void) {
|
||||
while (tim_run(0)) { // init state and start event loop
|
||||
tim_scope(A, A, 24, 8) { // centered 24x8 scope
|
||||
u64 c = 0x0a060f; // three colors
|
||||
tim_frame(0, 0, ~0, ~0, c); // draw frame for scope
|
||||
while (tim_run(0)) { // init state and start event loop
|
||||
tim_scope(A, A, 24, 8) { // centered 24x8 scope
|
||||
TimStyle c = { // three colors
|
||||
.brd= TimColor16_Green,
|
||||
.bg = TimColor16_DarkCyan,
|
||||
.fg = TimColor16_White
|
||||
};
|
||||
tim_frame(0, 0, ~0, ~0, c); // draw frame for scope
|
||||
tim_label("Greetings!", A, 2, A, A, c); // label in top center
|
||||
if (tim_button("OK", A, ~1, 8, A, c)) // button in bottom center
|
||||
return 0; // exit on button click
|
||||
if (tim_is_key_press('q')) // ctrl-c is masked
|
||||
return 0; // exit on 'q' press
|
||||
return 0; // exit on button click
|
||||
if (tim_is_key_press('q')) // ctrl-c is masked
|
||||
return 0; // exit on 'q' press
|
||||
}
|
||||
} // atexit() cleanup
|
||||
} // atexit() cleanup
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
|
||||
#define FG 0x10
|
||||
#define BG 0xdd
|
||||
#define BTN (FG << 16 | BG << 8 | FG)
|
||||
|
||||
#define NEW 0
|
||||
#define RUN 1
|
||||
@@ -81,7 +80,7 @@ static void game(void) {
|
||||
}
|
||||
|
||||
// user input
|
||||
if (tim->event.type == KEY_EVENT) {
|
||||
if (tim->event.type == TimEvent_Key) {
|
||||
i32 key = tim->event.key;
|
||||
if ((key == TimKey_Right || key == 'd') && snek.look.x != -1) {
|
||||
snek.look = (point){{1, 0}};
|
||||
@@ -99,17 +98,18 @@ static void game(void) {
|
||||
}
|
||||
|
||||
static void menu(void) {
|
||||
TimStyle style_button = (TimStyle){ .brd= FG, .bg = BG, .fg = FG };
|
||||
tim_scope(A, A, 20, 13) {
|
||||
char* lbl = snek.state == OVER ? "GAME OVER" : "SNEK - THE GAME";
|
||||
char* btn = snek.state == PAUSE ? "Resume" : "Play";
|
||||
tim_label(lbl, A, 0, A, A, BTN);
|
||||
if (tim_button(btn, A, 2, 20, 5, BTN) || tim_is_key_press(TimKey_Enter)) {
|
||||
tim_label(lbl, A, 0, A, A, style_button);
|
||||
if (tim_button(btn, A, 2, 20, 5, style_button) || tim_is_key_press(TimKey_Enter)) {
|
||||
if (snek.state != PAUSE) {
|
||||
start();
|
||||
}
|
||||
snek.state = RUN;
|
||||
}
|
||||
if (tim_button("Exit", A, 8, 20, 5, BTN) || tim_is_key_press('q') || tim_is_key_press(TimKey_Escape)) {
|
||||
if (tim_button("Exit", A, 8, 20, 5, style_button) || tim_is_key_press('q') || tim_is_key_press(TimKey_Escape)) {
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
@@ -126,6 +126,6 @@ i32 main(void) {
|
||||
} else {
|
||||
menu();
|
||||
}
|
||||
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user