sdlterm/demo.cc
author Radek Brich <radek.brich@devl.cz>
Sat, 05 Jan 2013 18:56:45 +0100
changeset 51 dce7325109c1
parent 50 c5b8b9d2da95
child 52 50a1857557da
permissions -rw-r--r--
Clean up: expand unwanted tabs.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     1
#include "sdlterm.h"
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     2
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     3
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     4
class Application
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     5
{
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     6
public:
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
     7
    Terminal term;
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
     8
    bool done;
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     9
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    10
    Application() : term(), done(false) {};
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    11
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    12
    void init();
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    13
    void wait_and_process_event();
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    14
};
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    15
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    16
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    17
void Application::init()
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    18
{
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    19
    term.resize(800, 600);
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    20
    term.select_font("font/DejaVuSansMono.ttf", "font/DejaVuSansMono-Bold.ttf", 12);
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    21
    term.erase();
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    22
    term.set_attr( term.prepare_attr(14, 1, 1) );
50
c5b8b9d2da95 DriverSDL: Implement colors.
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
    23
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    24
    char hello[] = "Hello World!";
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    25
    for (char *c = hello; *c; c++)
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    26
    {
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    27
        term.putch(5 + (c - hello), 5, *c);
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    28
    }
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    29
    term.commit();
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    30
}
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    31
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    32
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    33
void Application::wait_and_process_event()
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    34
{
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    35
    Event event;
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    36
    term.get_next_event(event);
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    37
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    38
    switch (event.type)
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    39
    {
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    40
        case Event::QUIT:
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    41
            done = true;
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    42
            break;
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    43
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    44
        default:
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    45
            break;
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    46
    }
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    47
}
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    48
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    49
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    50
int main(int argc, char *argv[])
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    51
{
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    52
    Application app;
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    53
    app.init();
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    54
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    55
    while (!app.done)
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    56
    {
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    57
        app.wait_and_process_event();
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    58
    }
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    59
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    60
    return 0;
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    61
}
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    62