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:
parent
49d091deeb
commit
4ed97f09f6
6
Makefile
6
Makefile
@ -4,9 +4,6 @@
|
||||
|
||||
# set this to compile in "debug" mode
|
||||
#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
|
||||
TARGET = dwscr
|
||||
@ -15,9 +12,6 @@ export CPPFLAGS
|
||||
ifdef DEBUG
|
||||
CPPFLAGS += -DDEBUG
|
||||
endif
|
||||
ifdef WINDOW_MODE
|
||||
CPPFLAGS += -DWINDOW_MODE
|
||||
endif
|
||||
ifdef WITHOUT_ODE
|
||||
CPPFLAGS += -DWITHOUT_ODE
|
||||
endif
|
||||
|
@ -15,38 +15,38 @@ static int numMonitors = 0;
|
||||
|
||||
void getDisplaySize(int * width, int * height)
|
||||
{
|
||||
std::string nullStr = "";
|
||||
int w = 0;
|
||||
int h = 0;
|
||||
std::string nullStr = "";
|
||||
int w = 0;
|
||||
int h = 0;
|
||||
|
||||
/* loop through the display devices to get their dimensions */
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
DISPLAY_DEVICE dev;
|
||||
dev.cb = sizeof(DISPLAY_DEVICE);
|
||||
if (!EnumDisplayDevices(NULL, i, &dev, 0))
|
||||
break;
|
||||
/* we only want real display devices to matter */
|
||||
if (dev.DeviceID != nullStr)
|
||||
{
|
||||
HDC hdc = CreateDC(TEXT("DISPLAY"), dev.DeviceString, NULL, NULL);
|
||||
if (hdc != NULL)
|
||||
{
|
||||
numMonitors++;
|
||||
w += GetDeviceCaps(hdc, HORZRES);
|
||||
int thisHeight = GetDeviceCaps(hdc, VERTRES);
|
||||
if (thisHeight > h)
|
||||
h = thisHeight;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* loop through the display devices to get their dimensions */
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
DISPLAY_DEVICE dev;
|
||||
dev.cb = sizeof(DISPLAY_DEVICE);
|
||||
if (!EnumDisplayDevices(NULL, i, &dev, 0))
|
||||
break;
|
||||
/* we only want real display devices to matter */
|
||||
if (dev.DeviceID != nullStr)
|
||||
{
|
||||
HDC hdc = CreateDC(TEXT("DISPLAY"), dev.DeviceString, NULL, NULL);
|
||||
if (hdc != NULL)
|
||||
{
|
||||
numMonitors++;
|
||||
w += GetDeviceCaps(hdc, HORZRES);
|
||||
int thisHeight = GetDeviceCaps(hdc, VERTRES);
|
||||
if (thisHeight > h)
|
||||
h = thisHeight;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* only update width and height if we have valid data */
|
||||
if (w != 0 && h != 0)
|
||||
{
|
||||
*width = w;
|
||||
*height = h;
|
||||
}
|
||||
/* only update width and height if we have valid data */
|
||||
if (w != 0 && h != 0)
|
||||
{
|
||||
*width = w;
|
||||
*height = h;
|
||||
}
|
||||
}
|
||||
|
||||
int getNumMonitors()
|
||||
|
101
dwscr.cc
101
dwscr.cc
@ -23,75 +23,88 @@ using namespace std;
|
||||
/* main function, called upon program invocation */
|
||||
int main(int argc, char * argv[])
|
||||
{
|
||||
const string startString = "/s";
|
||||
#ifdef WIN32
|
||||
bool start = false;
|
||||
bool start = false;
|
||||
#else
|
||||
bool start = true;
|
||||
#endif
|
||||
SDL_Surface * sdlSurface;
|
||||
int width = DEFAULT_WIDTH;
|
||||
int height = DEFAULT_HEIGHT;
|
||||
SDL_Surface * sdlSurface;
|
||||
int width = DEFAULT_WIDTH;
|
||||
int height = DEFAULT_HEIGHT;
|
||||
bool windowed = false;
|
||||
|
||||
#ifdef DEBUG
|
||||
start = true;
|
||||
start = true;
|
||||
#endif
|
||||
|
||||
/* make the SDL window appear in the top-left corner of the screen */
|
||||
putenv("SDL_VIDEO_WINDOW_POS=0,0");
|
||||
/* make the SDL window appear in the top-left corner of the screen */
|
||||
putenv("SDL_VIDEO_WINDOW_POS=0,0");
|
||||
|
||||
/* do not disable power management (this will allow monitors
|
||||
* to power off at the normally configured timeout) */
|
||||
putenv("SDL_VIDEO_ALLOW_SCREENSAVER=1");
|
||||
|
||||
getDisplaySize(&width, &height);
|
||||
|
||||
/* extremely simple command-line argument handling */
|
||||
for (int i = 1; i < argc; i++)
|
||||
{
|
||||
if (startString == argv[i])
|
||||
start = true;
|
||||
}
|
||||
for (int i = 1; i < argc; i++)
|
||||
{
|
||||
if (!strcmp("/s", argv[i]))
|
||||
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)
|
||||
return 0;
|
||||
|
||||
getDisplaySize(&width, &height);
|
||||
if (!start)
|
||||
return 0;
|
||||
|
||||
/* initialize SDL library */
|
||||
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER))
|
||||
{
|
||||
cerr << "Error initializing video!" << endl;
|
||||
return -1;
|
||||
}
|
||||
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER))
|
||||
{
|
||||
cerr << "Error initializing video!" << endl;
|
||||
return -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 */
|
||||
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
|
||||
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 4);
|
||||
/* Enable multisampling */
|
||||
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
|
||||
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 4);
|
||||
|
||||
if ((sdlSurface = SDL_SetVideoMode(width, height, 0,
|
||||
SDL_HWSURFACE
|
||||
#ifndef WINDOW_MODE
|
||||
| SDL_NOFRAME
|
||||
#endif
|
||||
| SDL_OPENGL)) == NULL)
|
||||
{
|
||||
cerr << "Error setting video mode!" << endl;
|
||||
return -2;
|
||||
}
|
||||
int sdlMode = SDL_HWSURFACE | SDL_OPENGL;
|
||||
if (!windowed)
|
||||
sdlMode |= SDL_NOFRAME;
|
||||
if ((sdlSurface = SDL_SetVideoMode(width, height, 0, sdlMode)) == NULL)
|
||||
{
|
||||
cerr << "Error setting video mode!" << endl;
|
||||
return -2;
|
||||
}
|
||||
|
||||
SDL_WM_SetCaption("dwscr", "dwscr");
|
||||
#ifndef WINDOW_MODE
|
||||
SDL_WM_GrabInput(SDL_GRAB_ON);
|
||||
SDL_ShowCursor(SDL_DISABLE);
|
||||
#endif
|
||||
if (!windowed)
|
||||
{
|
||||
SDL_WM_GrabInput(SDL_GRAB_ON);
|
||||
SDL_ShowCursor(SDL_DISABLE);
|
||||
}
|
||||
|
||||
/* after our window is created and SDL and OpenGL are initialized,
|
||||
* start the main screensaver functionality */
|
||||
SSMain ss(width, height, getNumMonitors(), sdlSurface);
|
||||
ss.run();
|
||||
SSMain ss(width, height, getNumMonitors(), sdlSurface);
|
||||
ss.run();
|
||||
|
||||
SDL_Quit();
|
||||
return 0;
|
||||
SDL_Quit();
|
||||
return 0;
|
||||
}
|
||||
|
24
ss/SSMain.cc
24
ss/SSMain.cc
@ -71,7 +71,7 @@ void SSMain::run()
|
||||
{
|
||||
Uint32 elapsed_msec;
|
||||
Uint32 lastChanged_msec = 0;
|
||||
SDL_Event event;
|
||||
SDL_Event event;
|
||||
|
||||
/* initially set the screensaver mode */
|
||||
m_mode = startMode();
|
||||
@ -83,8 +83,8 @@ void SSMain::run()
|
||||
update();
|
||||
|
||||
/* main event loop */
|
||||
while (SDL_WaitEvent(&event))
|
||||
{
|
||||
while (SDL_WaitEvent(&event))
|
||||
{
|
||||
elapsed_msec = SDL_GetTicks(); /* get the time the event occurred at */
|
||||
if (elapsed_msec - lastChanged_msec > SSMODE_TIMEOUT_MSEC)
|
||||
{
|
||||
@ -93,14 +93,12 @@ void SSMain::run()
|
||||
lastChanged_msec = elapsed_msec;
|
||||
}
|
||||
|
||||
switch (event.type)
|
||||
{
|
||||
#ifndef WINDOW_MODE
|
||||
case SDL_KEYDOWN: /* terminate screensaver upon */
|
||||
#endif
|
||||
case SDL_QUIT: /* key press or quit event */
|
||||
goto RET;
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
switch (event.type)
|
||||
{
|
||||
case SDL_KEYDOWN: /* terminate screensaver upon */
|
||||
case SDL_QUIT: /* key press or quit event */
|
||||
goto RET;
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
if (event.button.button == 1)
|
||||
{
|
||||
delete m_mode;
|
||||
@ -114,8 +112,8 @@ void SSMain::run()
|
||||
update();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
RET:
|
||||
;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user