50 lines
1.4 KiB
C
50 lines
1.4 KiB
C
// Display a yes/no dialog with a message. Returns with 0 when yes was clicked.
|
|
// syntax: ./ask "message"
|
|
|
|
#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]);
|
|
exit(1);
|
|
}
|
|
|
|
// get text properties
|
|
TimText msg = tim_scan_str(argv[1]);
|
|
|
|
while (tim_run(0)) {
|
|
// calculate size of message box
|
|
i32 w = MAX(msg.width + 4, 28);
|
|
i32 h = MAX(msg.lines + 6, 7);
|
|
|
|
tim_scope(A, A, w, h) {
|
|
// draw frame around entire scope
|
|
tim_frame(0, 0, ~0, ~0, CFR);
|
|
|
|
// draw message
|
|
tim_label(argv[1], A, 1, msg.width, msg.lines, CTXT);
|
|
|
|
// draw 'yes' button, return 0 when clicked
|
|
if (tim_button("[y] Yes", 2, ~1, A, A, CYES) || 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')) {
|
|
exit(1);
|
|
}
|
|
|
|
// return with 1 when q or esc is pressed
|
|
if (tim_is_key_press('q') || tim_is_key_press(TimKey_Escape)) {
|
|
exit(2);
|
|
}
|
|
}
|
|
}
|
|
}
|