X-Git-Url: https://git.stderr.nl/gitweb?p=rodin%2Fchimara.git;a=blobdiff_plain;f=tests%2Fstyletest.c;h=8ed77372268c74d3662adc8a5222636a2942a70c;hp=3cfd15ea63051fa542a1142599149cc8f15b19f4;hb=268cb7d6d08efc2fcbe52aa7b1e0d27ec19b6dc0;hpb=6d54ac994ad1b08f88d23be5e2b5b8e2e45908cb diff --git a/tests/styletest.c b/tests/styletest.c index 3cfd15e..8ed7737 100644 --- a/tests/styletest.c +++ b/tests/styletest.c @@ -7,15 +7,24 @@ void print_help(); void do_style_test(); void do_link_test(); +void do_mouse_test(); winid_t mainwin; +winid_t statuswin; void glk_main(void) { + char stringbuffer[128]; event_t ev; + + /* Define some custom styles */ + glk_stylehint_set(wintype_AllTypes, style_User1, stylehint_TextColor, 0x00FF0000); + mainwin = glk_window_open(0, 0, 0, wintype_TextBuffer, 0); if(!mainwin) return; + + statuswin = glk_window_open(mainwin, winmethod_Above | winmethod_Fixed, 3, wintype_TextGrid, 1); glk_set_window(mainwin); @@ -23,7 +32,6 @@ void glk_main(void) assert(buffer); glk_put_string("Welcome to the style test\n"); - glk_request_line_event(mainwin, buffer, 255, 0); while(strncmp(buffer, "quit", 4)) { @@ -39,6 +47,9 @@ void glk_main(void) else if( !strncmp(buffer, "link", 4) ) { do_link_test(); } + else if( !strncmp(buffer, "mouse", 4) ) { + do_mouse_test(); + } else { glk_put_string("Huh?\n"); } @@ -47,10 +58,15 @@ void glk_main(void) else if(ev.type == evtype_Hyperlink) { glk_cancel_line_event(mainwin, NULL); - if(ev.val1 == 1) - glk_put_string("Link 1 was clicked\n"); - if(ev.val1 == 2) - glk_put_string("Link 2 was clicked\n"); + snprintf(stringbuffer, 128, "Link %d was clicked\n", ev.val1); + glk_put_string(stringbuffer); + glk_request_line_event(mainwin, buffer, 255, 0); + } + else if(ev.type == evtype_MouseInput) + { + glk_cancel_line_event(mainwin, NULL); + snprintf(stringbuffer, 128, "Mouse click: x=%d, y=%d\n", ev.val1, ev.val2); + glk_put_string(stringbuffer); glk_request_line_event(mainwin, buffer, 255, 0); } } @@ -100,15 +116,38 @@ do_style_test() { void do_link_test() { + glk_set_window(mainwin); glk_set_hyperlink(1); glk_put_string("This is link 1\n"); glk_set_hyperlink(2); glk_put_string("This is link 2\n"); glk_set_hyperlink(0); + + glk_set_window(statuswin); + glk_set_hyperlink(3); + glk_window_move_cursor(statuswin, 0, 0); + glk_put_string("This is link 3\n"); + glk_set_hyperlink(4); + glk_window_move_cursor(statuswin, 0, 1); + glk_put_string("This is link 4\n"); + glk_set_hyperlink(0); + glk_request_hyperlink_event(mainwin); + glk_request_hyperlink_event(statuswin); + + glk_set_window(mainwin); +} + +void +do_mouse_test() { + glk_set_window(statuswin); + glk_window_move_cursor(statuswin, 0, 0); + glk_put_string("Click me......\n"); + glk_request_mouse_event(statuswin); + glk_set_window(mainwin); } void print_help() { - glk_put_string("The following commands are supported:\n - help (this help text)\n - style (perform style test)\n - link (perform hyperlink test)\n - quit (quit the program)\n"); + glk_put_string("The following commands are supported:\n - help (this help text)\n - style (perform style test)\n - link (perform hyperlink test)\n - mouse (perform mouse test)\n - quit (quit the program)\n"); }