sdlterm/tests/test_sdlterm.cc
changeset 72 6e0656600754
parent 57 911927edbdde
equal deleted inserted replaced
71:cfd3445107b4 72:6e0656600754
       
     1 #include "sdlterm.h"
       
     2 
       
     3 
       
     4 class Application
       
     5 {
       
     6 public:
       
     7     Terminal term;
       
     8     bool done;
       
     9 
       
    10     Application() : term(), done(false) {};
       
    11 
       
    12     void init();
       
    13     void wait_and_process_event();
       
    14 };
       
    15 
       
    16 
       
    17 void Application::init()
       
    18 {
       
    19     term.resize(800, 600);
       
    20     term.select_font("font/DejaVuSansMono.ttf", "font/DejaVuSansMono-Bold.ttf", 12);
       
    21     term.erase();
       
    22 
       
    23     char hello[] = "Hello World!";
       
    24     for (int bg = 0; bg < 16; bg++)
       
    25     {
       
    26         for (int fg = 0; fg < 16; fg++)
       
    27         {
       
    28             for (char *c = hello; *c; c++)
       
    29             {
       
    30                 term.set_attr( term.prepare_attr(fg, bg, 1) );
       
    31                 term.putch(5 + 6 * bg + (c - hello), 5 + fg, *c);
       
    32             }
       
    33         }
       
    34     }
       
    35     term.commit();
       
    36 }
       
    37 
       
    38 
       
    39 void Application::wait_and_process_event()
       
    40 {
       
    41     Event event;
       
    42     term.wait_event(event, 0);
       
    43 
       
    44     switch (event.type)
       
    45     {
       
    46         case Event::QUIT:
       
    47             done = true;
       
    48             break;
       
    49 
       
    50         case Event::MOUSEDOWN:
       
    51             printf("mouse button down\n");
       
    52             break;
       
    53 
       
    54         case Event::MOUSEUP:
       
    55             printf("mouse button up\n");
       
    56             break;
       
    57 
       
    58         default:
       
    59             break;
       
    60     }
       
    61 }
       
    62 
       
    63 
       
    64 int main(int argc, char *argv[])
       
    65 {
       
    66     Application app;
       
    67     app.init();
       
    68 
       
    69     while (!app.done)
       
    70     {
       
    71         app.wait_and_process_event();
       
    72     }
       
    73 
       
    74     return 0;
       
    75 }
       
    76