Create FUNDING.yml
[wdl/wdl-ol.git] / WDL / win32_curses / test.cpp
blob33a372fe6b14da368bacfddfc791ae94ef2521e3
1 #include "curses.h"
3 #ifdef _WIN32
4 win32CursesCtx g_curses_context; // we only need the one instance
5 #endif
7 #ifdef _WIN32
8 int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
9 g_curses_context.want_getch_runmsgpump = 1; // non-block
11 curses_registerChildClass(hInstance);
12 curses_CreateWindow(hInstance,&g_curses_context,"Sample Test App");
13 #else
14 int main() {
15 #endif
18 initscr();
19 cbreak();
20 noecho();
21 nonl();
22 intrflush(stdscr,FALSE);
23 keypad(stdscr,TRUE);
24 nodelay(stdscr,TRUE);
25 raw();
26 #if !defined(_WIN32) && !defined(MAC_NATIVE)
27 ESCDELAY=0; // dont wait--at least on the console this seems to work.
28 #endif
30 if (has_colors()) // we don't use color yet, but we could
32 start_color();
33 init_pair(1, COLOR_WHITE, COLOR_BLUE); // normal status lines
34 init_pair(2, COLOR_BLACK, COLOR_CYAN); // value
37 erase();
38 refresh();
40 float xpos=0,ypos=0, xdir=0.7, ydir=1.5;
41 for (;;)
43 int t=getch();
44 if (t==27) break;
45 else if (t== KEY_LEFT) xdir *=0.9;
46 else if (t== KEY_RIGHT) xdir *=1.1;
47 else if (t== KEY_UP) ydir *=1.1;
48 else if (t== KEY_DOWN) ydir *=0.9;
50 xpos+=xdir; ypos+=ydir;
51 if (xpos >= COLS-1||xpos<1) { if (xpos<1)xpos=1; else xpos=COLS-1; xdir=-xdir; }
52 if (ypos >= LINES-1||ypos<1) { if (ypos<1)ypos=1; else ypos=LINES-1; ydir=-ydir; }
54 erase();
55 mvaddstr(ypos,xpos,"X");
58 Sleep(10);
59 #ifdef _WIN32
60 if (!g_curses_context.m_hwnd) break;
61 #endif
65 erase();
66 refresh();
67 endwin();
69 #ifdef _WIN32
70 if (g_curses_context.m_hwnd) DestroyWindow(g_curses_context.m_hwnd);
71 curses_unregisterChildClass(hInstance);
72 #endif
74 return 0;