added -W, -w, -h command line options, retabbed a couple files

git-svn-id: svn://anubis/dwscr/trunk@91 5bef9df8-b654-44bb-925b-0ff18baa8f8c
This commit is contained in:
josh 2008-11-13 02:49:11 +00:00
parent 49d091deeb
commit 4ed97f09f6
4 changed files with 98 additions and 93 deletions

View File

@ -4,9 +4,6 @@
# set this to compile in "debug" mode # set this to compile in "debug" mode
#DEBUG := 1 #DEBUG := 1
# set this to be in "window mode" - i.e. do not hide mouse
# cursor and grab input
#WINDOW_MODE := 1
OBJS = dwscr.o wfobj/WFObj.o LoadFile/LoadFile.o ss/ss.a OBJS = dwscr.o wfobj/WFObj.o LoadFile/LoadFile.o ss/ss.a
TARGET = dwscr TARGET = dwscr
@ -15,9 +12,6 @@ export CPPFLAGS
ifdef DEBUG ifdef DEBUG
CPPFLAGS += -DDEBUG CPPFLAGS += -DDEBUG
endif endif
ifdef WINDOW_MODE
CPPFLAGS += -DWINDOW_MODE
endif
ifdef WITHOUT_ODE ifdef WITHOUT_ODE
CPPFLAGS += -DWITHOUT_ODE CPPFLAGS += -DWITHOUT_ODE
endif endif

View File

@ -15,38 +15,38 @@ static int numMonitors = 0;
void getDisplaySize(int * width, int * height) void getDisplaySize(int * width, int * height)
{ {
std::string nullStr = ""; std::string nullStr = "";
int w = 0; int w = 0;
int h = 0; int h = 0;
/* loop through the display devices to get their dimensions */ /* loop through the display devices to get their dimensions */
for (int i = 0; i < 10; i++) for (int i = 0; i < 10; i++)
{ {
DISPLAY_DEVICE dev; DISPLAY_DEVICE dev;
dev.cb = sizeof(DISPLAY_DEVICE); dev.cb = sizeof(DISPLAY_DEVICE);
if (!EnumDisplayDevices(NULL, i, &dev, 0)) if (!EnumDisplayDevices(NULL, i, &dev, 0))
break; break;
/* we only want real display devices to matter */ /* we only want real display devices to matter */
if (dev.DeviceID != nullStr) if (dev.DeviceID != nullStr)
{ {
HDC hdc = CreateDC(TEXT("DISPLAY"), dev.DeviceString, NULL, NULL); HDC hdc = CreateDC(TEXT("DISPLAY"), dev.DeviceString, NULL, NULL);
if (hdc != NULL) if (hdc != NULL)
{ {
numMonitors++; numMonitors++;
w += GetDeviceCaps(hdc, HORZRES); w += GetDeviceCaps(hdc, HORZRES);
int thisHeight = GetDeviceCaps(hdc, VERTRES); int thisHeight = GetDeviceCaps(hdc, VERTRES);
if (thisHeight > h) if (thisHeight > h)
h = thisHeight; h = thisHeight;
} }
} }
} }
/* only update width and height if we have valid data */ /* only update width and height if we have valid data */
if (w != 0 && h != 0) if (w != 0 && h != 0)
{ {
*width = w; *width = w;
*height = h; *height = h;
} }
} }
int getNumMonitors() int getNumMonitors()

101
dwscr.cc
View File

@ -23,75 +23,88 @@ using namespace std;
/* main function, called upon program invocation */ /* main function, called upon program invocation */
int main(int argc, char * argv[]) int main(int argc, char * argv[])
{ {
const string startString = "/s";
#ifdef WIN32 #ifdef WIN32
bool start = false; bool start = false;
#else #else
bool start = true; bool start = true;
#endif #endif
SDL_Surface * sdlSurface; SDL_Surface * sdlSurface;
int width = DEFAULT_WIDTH; int width = DEFAULT_WIDTH;
int height = DEFAULT_HEIGHT; int height = DEFAULT_HEIGHT;
bool windowed = false;
#ifdef DEBUG #ifdef DEBUG
start = true; start = true;
#endif #endif
/* make the SDL window appear in the top-left corner of the screen */ /* make the SDL window appear in the top-left corner of the screen */
putenv("SDL_VIDEO_WINDOW_POS=0,0"); putenv("SDL_VIDEO_WINDOW_POS=0,0");
/* do not disable power management (this will allow monitors /* do not disable power management (this will allow monitors
* to power off at the normally configured timeout) */ * to power off at the normally configured timeout) */
putenv("SDL_VIDEO_ALLOW_SCREENSAVER=1"); putenv("SDL_VIDEO_ALLOW_SCREENSAVER=1");
getDisplaySize(&width, &height);
/* extremely simple command-line argument handling */ /* extremely simple command-line argument handling */
for (int i = 1; i < argc; i++) for (int i = 1; i < argc; i++)
{ {
if (startString == argv[i]) if (!strcmp("/s", argv[i]))
start = true; start = true;
} else if (!strcmp("-W", argv[i]))
windowed = true;
else if (!strncmp("-w", argv[i], 2))
{
width = atoi( (strlen(argv[i]) > 2)
? argv[i] + 2
: argv[++i] );
}
else if (!strncmp("-h", argv[i], 2))
{
height = atoi( (strlen(argv[i]) > 2)
? argv[i] + 2
: argv[++i] );
}
}
if (!start) if (!start)
return 0; return 0;
getDisplaySize(&width, &height);
/* initialize SDL library */ /* initialize SDL library */
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER)) if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER))
{ {
cerr << "Error initializing video!" << endl; cerr << "Error initializing video!" << endl;
return -1; return -1;
} }
SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 1); SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 1);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
/* Enable multisampling */ /* Enable multisampling */
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1); SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 4); SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 4);
if ((sdlSurface = SDL_SetVideoMode(width, height, 0, int sdlMode = SDL_HWSURFACE | SDL_OPENGL;
SDL_HWSURFACE if (!windowed)
#ifndef WINDOW_MODE sdlMode |= SDL_NOFRAME;
| SDL_NOFRAME if ((sdlSurface = SDL_SetVideoMode(width, height, 0, sdlMode)) == NULL)
#endif {
| SDL_OPENGL)) == NULL) cerr << "Error setting video mode!" << endl;
{ return -2;
cerr << "Error setting video mode!" << endl; }
return -2;
}
SDL_WM_SetCaption("dwscr", "dwscr"); SDL_WM_SetCaption("dwscr", "dwscr");
#ifndef WINDOW_MODE if (!windowed)
SDL_WM_GrabInput(SDL_GRAB_ON); {
SDL_ShowCursor(SDL_DISABLE); SDL_WM_GrabInput(SDL_GRAB_ON);
#endif SDL_ShowCursor(SDL_DISABLE);
}
/* after our window is created and SDL and OpenGL are initialized, /* after our window is created and SDL and OpenGL are initialized,
* start the main screensaver functionality */ * start the main screensaver functionality */
SSMain ss(width, height, getNumMonitors(), sdlSurface); SSMain ss(width, height, getNumMonitors(), sdlSurface);
ss.run(); ss.run();
SDL_Quit(); SDL_Quit();
return 0; return 0;
} }

View File

@ -71,7 +71,7 @@ void SSMain::run()
{ {
Uint32 elapsed_msec; Uint32 elapsed_msec;
Uint32 lastChanged_msec = 0; Uint32 lastChanged_msec = 0;
SDL_Event event; SDL_Event event;
/* initially set the screensaver mode */ /* initially set the screensaver mode */
m_mode = startMode(); m_mode = startMode();
@ -83,8 +83,8 @@ void SSMain::run()
update(); update();
/* main event loop */ /* main event loop */
while (SDL_WaitEvent(&event)) while (SDL_WaitEvent(&event))
{ {
elapsed_msec = SDL_GetTicks(); /* get the time the event occurred at */ elapsed_msec = SDL_GetTicks(); /* get the time the event occurred at */
if (elapsed_msec - lastChanged_msec > SSMODE_TIMEOUT_MSEC) if (elapsed_msec - lastChanged_msec > SSMODE_TIMEOUT_MSEC)
{ {
@ -93,14 +93,12 @@ void SSMain::run()
lastChanged_msec = elapsed_msec; lastChanged_msec = elapsed_msec;
} }
switch (event.type) switch (event.type)
{ {
#ifndef WINDOW_MODE case SDL_KEYDOWN: /* terminate screensaver upon */
case SDL_KEYDOWN: /* terminate screensaver upon */ case SDL_QUIT: /* key press or quit event */
#endif goto RET;
case SDL_QUIT: /* key press or quit event */ case SDL_MOUSEBUTTONDOWN:
goto RET;
case SDL_MOUSEBUTTONDOWN:
if (event.button.button == 1) if (event.button.button == 1)
{ {
delete m_mode; delete m_mode;
@ -114,8 +112,8 @@ void SSMain::run()
update(); update();
} }
break; break;
} }
} }
RET: RET:
; ;
} }