X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=dosdemo;a=blobdiff_plain;f=src%2Fdemo.c;h=6abcf672b751f58424ad5c6b47415f005bc70214;hp=f25610a9c5db35dacdbb886e4556352c0db804f0;hb=9ed338a5e703fc819cede5cb797e82e08046ac17;hpb=1442212ba0ff24b868dd29facc2278a26c8a9a18 diff --git a/src/demo.c b/src/demo.c index f25610a..6abcf67 100644 --- a/src/demo.c +++ b/src/demo.c @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include "demo.h" @@ -99,21 +100,96 @@ void demo_draw(void) ++nframes; } -void demo_keyboard(int key, int state) +static void change_screen(int idx) { - if(state) { + printf("change screen %d\n", idx); + scr_change(scr_screen(idx), 4000); +} + +#define CBUF_SIZE 64 +#define CBUF_MASK (CBUF_SIZE - 1) +void demo_keyboard(int key, int press) +{ + static char cbuf[CBUF_SIZE]; + static int rd, wr; + char inp[CBUF_SIZE + 1], *dptr; + int i, nscr; + + if(press) { switch(key) { case 27: demo_quit(); break; + case '\n': + case '\r': + dptr = inp; + while(rd != wr) { + *dptr++ = cbuf[rd]; + rd = (rd + 1) & CBUF_MASK; + } + *dptr = 0; + if(inp[0]) { + printf("trying to match: %s\n", inp); + nscr = scr_num_screens(); + for(i=0; iname, inp)) { + change_screen(i); + break; + } + } + } + break; + default: - if(key >= '1' && key <= '1' + scr_num_screens()) { - int idx = key - '1'; - printf("change screen %d\n", idx); - scr_change(scr_screen(idx), 4000); + if(key >= '1' && key <= '9' && key <= '1' + scr_num_screens()) { + change_screen(key - '1'); + } else if(key == '0' && scr_num_screens() >= 10) { + change_screen(9); + } + + if(key < 256 && isprint(key)) { + cbuf[wr] = key; + wr = (wr + 1) & CBUF_MASK; + if(wr == rd) { /* overflow */ + rd = (rd + 1) & CBUF_MASK; + } } break; } } } + + +void mouse_orbit_update(float *theta, float *phi, float *dist) +{ + static int prev_mx, prev_my; + static unsigned int prev_bmask; + + if(mouse_bmask) { + if((mouse_bmask ^ prev_bmask) == 0) { + int dx = mouse_x - prev_mx; + int dy = mouse_y - prev_my; + + if(dx || dy) { + if(mouse_bmask & 1) { + float p = *phi; + *theta += dx * 1.0; + p += dy * 1.0; + + if(p < -90) p = -90; + if(p > 90) p = 90; + *phi = p; + } + if(mouse_bmask & 4) { + *dist += dy * 0.5; + + if(*dist < 0) *dist = 0; + } + } + } + } + prev_mx = mouse_x; + prev_my = mouse_y; + prev_bmask = mouse_bmask; +}