From 5a08f8da562d72603093285a90ca8f8ddada0cb9 Mon Sep 17 00:00:00 2001 From: William McBrine Date: Mon, 25 Jun 2007 13:19:47 +0000 Subject: [PATCH] A special demo for SDL, showing how to combine SDL and PDCurses functions. --- sdl1/Makefile | 5 ++- sdl1/Makefile.mng | 5 +++ sdl1/sdltest.c | 82 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 sdl1/sdltest.c diff --git a/sdl1/Makefile b/sdl1/Makefile index 57d1a8c7..92ce83c5 100644 --- a/sdl1/Makefile +++ b/sdl1/Makefile @@ -29,7 +29,8 @@ LDFLAGS = $(LIBCURSES) $(SLIBS) RANLIB = ranlib LIBCURSES = libpdcurses.a -DEMOS = firework newdemo ptest rain testcurs tuidemo worm xmas +DEMOS = firework newdemo ptest rain testcurs tuidemo worm xmas \ +sdltest ######################################################################### .PHONY: all libs clean demos @@ -89,6 +90,8 @@ worm: $(demodir)/worm.c xmas: $(demodir)/xmas.c $(BUILD) $(DEMOFLAGS) -o $@ $< $(LDFLAGS) +sdltest: $(osdir)/sdltest.c + $(BUILD) $(DEMOFLAGS) -o $@ $< $(LDFLAGS) tui.o: $(demodir)/tui.c $(demodir)/tui.h $(BUILD) -c $(DEMOFLAGS) $(demodir)/tui.c diff --git a/sdl1/Makefile.mng b/sdl1/Makefile.mng index 66ade5c3..0f2d5842 100644 --- a/sdl1/Makefile.mng +++ b/sdl1/Makefile.mng @@ -36,6 +36,8 @@ else LDFLAGS += -lSDL endif +DEMOS += sdltest.exe + ######################################################################### .PHONY: all libs clean demos @@ -92,3 +94,6 @@ tui.o: $(demodir)/tui.c $(demodir)/tui.h tuidemo.o: $(demodir)/tuidemo.c $(demodir)/tui.h $(BUILD) -c $< + +sdltest.exe: $(osdir)/sdltest.c + $(BUILD) -o $@ $< -mwindows $(LIBCURSES) -lmingw32 -lSDLmain -lSDL diff --git a/sdl1/sdltest.c b/sdl1/sdltest.c new file mode 100644 index 00000000..604fbb57 --- /dev/null +++ b/sdl1/sdltest.c @@ -0,0 +1,82 @@ +/* Here's a simple example of combining SDL and PDCurses functionality. + The top portion of the window is devoted to SDL, with a four-line + (assuming the default 8x16 font) stdscr at the bottom. + + $Id: sdltest.c,v 1.1 2007/06/25 13:19:47 wmcbrine Exp $ +*/ + +#include +#include +#include +#include + +/* You could #include pdcsdl.h, or just add the relevant declarations + here: */ + +PDCEX SDL_Surface *pdc_screen; +PDCEX int pdc_yoffset; + +int main(int argc, char **argv) +{ + char inp[60]; + int i, j, seed; + + seed = time((time_t *)0); + srand(seed); + + /* Initialize SDL */ + + if (SDL_Init(SDL_INIT_VIDEO) < 0) + exit(1); + + atexit(SDL_Quit); + + pdc_screen = SDL_SetVideoMode(640, 480, 0, + SDL_SWSURFACE|SDL_ANYFORMAT); + + /* Initialize PDCurses */ + + pdc_yoffset = 416; /* 480 - 4 * 16 */ + + initscr(); + start_color(); + scrollok(stdscr, TRUE); + + PDC_set_title("PDCurses for SDL"); + + /* Do some SDL stuff */ + + for (i = 640, j = 416; j; i -= 2, j -= 2) + { + SDL_Rect dest; + + dest.x = (640 - i) / 2; + dest.y = (416 - j) / 2; + dest.w = i; + dest.h = j; + + SDL_FillRect(pdc_screen, &dest, + SDL_MapRGB(pdc_screen->format, rand() % 256, + rand() % 256, rand() % 256)); + } + + SDL_UpdateRect(pdc_screen, 0, 0, 640, 416); + + /* Do some curses stuff */ + + init_pair(1, COLOR_WHITE + 8, COLOR_BLUE); + bkgd(COLOR_PAIR(1)); + + addstr("This is a demo of "); + attron(A_UNDERLINE); + addstr("PDCurses for SDL"); + attroff(A_UNDERLINE); + addstr(".\nYour comments here: "); + getnstr(inp, 59); + addstr("Press any key to exit."); + + getch(); + endwin(); + + return 0; +}