[MAZESCR]

Made mazescr use screensaver.lib for multi screen support
Add symbol to make things look more... mature in C:\ReactOS
Fixes of my two problems (app does not really terminate and maze is not generated completely) and tidy up (-200 lines of code!) of my mess and the mess we had in there before by David Quintana. Thx man :-D

svn path=/trunk/; revision=67781
This commit is contained in:
Daniel Reimer 2015-05-16 19:16:40 +00:00
parent a175511a5a
commit d6510c4911
7 changed files with 598 additions and 1002 deletions

View file

@ -1,10 +1,8 @@
add_executable(mazescr add_executable(mazescr maze.c maze.rc)
scrnsave.c
maze.c
scrnsave.rc)
set_module_type(mazescr win32gui) set_module_type(mazescr win32gui UNICODE)
set_target_properties(mazescr PROPERTIES SUFFIX ".scr") set_target_properties(mazescr PROPERTIES SUFFIX ".scr")
target_link_libraries(mazescr scrnsave)
add_importlibs(mazescr user32 gdi32 msvcrt kernel32) add_importlibs(mazescr user32 gdi32 msvcrt kernel32)
add_cd_file(TARGET mazescr DESTINATION reactos/system32 FOR all) add_cd_file(TARGET mazescr DESTINATION reactos/system32 FOR all)

View file

@ -53,35 +53,30 @@
#include <string.h> #include <string.h>
#include <time.h> #include <time.h>
#include <windows.h> /* required for all Windows applications */ #include <windows.h> /* required for all Windows applications */
#include <scrnsave.h>
#include "resource.h"
#if !defined (APIENTRY) /* Windows NT defines APIENTRY, but 3.x doesn't */ #define APPNAME _T("Maze")
#define APIENTRY far pascal
#endif
#if !defined(WIN32) /* Windows 3.x uses a FARPROC for dialogs */ static BOOL InitInstance(HWND hParent);
#define DLGPROC FARPROC LRESULT CALLBACK ScreenSaverProc(HWND hWnd, UINT message, WPARAM uParam, LPARAM lParam);
#endif static int choose_door();
static long backup();
static void draw_wall();
static void draw_solid_square(int, int, int, HDC, HBRUSH);
static void enter_square(int, HDC, HBRUSH);
static BOOL InitInstance(HINSTANCE hInstance, HWND hParent); extern HINSTANCE hMainInstance; /* current instance */
LRESULT CALLBACK MazeWndProc(HWND hWnd, UINT message, WPARAM uParam,
LPARAM lParam);
HINSTANCE hInst; /* current instance */
HWND hWnd; /* Main window handle.*/
HBRUSH hBrushDead; HBRUSH hBrushDead;
HBRUSH hBrushLiving; HBRUSH hBrushLiving;
HPEN hPenWall; HPEN hPenWall;
HDC hDC; HDC hDC;
static BOOL waiting; static BOOL waiting;
WCHAR szAppName[] = L"Maze"; /* The name of this application */
WCHAR szTitle[] = L"Maze"; /* The title bar text */
static int solve_delay, pre_solve_delay, post_solve_delay; static int solve_delay, pre_solve_delay, post_solve_delay;
#define MAX_MAZE_SIZE_X ((unsigned long) 250) #define MAX_MAZE_SIZE_X ((unsigned long) 1000) // Dynamic detection?
#define MAX_MAZE_SIZE_Y ((unsigned long) 250) #define MAX_MAZE_SIZE_Y ((unsigned long) 1000) // Dynamic detection?
#define MOVE_LIST_SIZE (MAX_MAZE_SIZE_X * MAX_MAZE_SIZE_Y) #define MOVE_LIST_SIZE (MAX_MAZE_SIZE_X * MAX_MAZE_SIZE_Y)
@ -112,10 +107,9 @@ static int solve_delay, pre_solve_delay, post_solve_delay;
static unsigned short maze[MAX_MAZE_SIZE_X][MAX_MAZE_SIZE_Y]; static unsigned short maze[MAX_MAZE_SIZE_X][MAX_MAZE_SIZE_Y];
static struct { static struct {
unsigned char x; unsigned int x;
unsigned char y; unsigned int y;
unsigned char dir; unsigned int dir;
unsigned char dummy;
} move_list[MOVE_LIST_SIZE], save_path[MOVE_LIST_SIZE], path[MOVE_LIST_SIZE]; } move_list[MOVE_LIST_SIZE], save_path[MOVE_LIST_SIZE], path[MOVE_LIST_SIZE];
static int maze_size_x, maze_size_y; static int maze_size_x, maze_size_y;
@ -123,47 +117,48 @@ static long sqnum, path_length;
static int cur_sq_x, cur_sq_y; static int cur_sq_x, cur_sq_y;
static int start_x, start_y, start_dir, end_x, end_y, end_dir; static int start_x, start_y, start_dir, end_x, end_y, end_dir;
static int grid_width, grid_height; static int grid_width, grid_height;
static int bw;
static int state = 1, pathi = 0; static int state = 1, pathi = 0;
static void static void set_maze_sizes(width, height)
set_maze_sizes (width, height) int width, height;
int width, height;
{ {
maze_size_x = width / grid_width; maze_size_x = (width -1)/ grid_width;
maze_size_y = height / grid_height; maze_size_y = (height-1) / grid_height;
if (maze_size_x > MAX_MAZE_SIZE_X)
maze_size_x = MAX_MAZE_SIZE_X;
if (maze_size_y > MAX_MAZE_SIZE_Y)
maze_size_y = MAX_MAZE_SIZE_Y;
} }
static void initialize_maze() /* draw the surrounding wall and start/end squares */
static void
initialize_maze() /* draw the surrounding wall and start/end squares */
{ {
register int i, j, wall; register int i, j, wall;
/* initialize all squares */ /* initialize all squares */
for ( i=0; i<maze_size_x; i++) { for (i = 0; i < maze_size_x; i++) {
for ( j=0; j<maze_size_y; j++) { for (j = 0; j < maze_size_y; j++) {
maze[i][j] = 0; maze[i][j] = 0;
} }
} }
/* top wall */ /* top wall */
for ( i=0; i<maze_size_x; i++ ) { for (i = 0; i < maze_size_x; i++) {
maze[i][0] |= WALL_TOP; maze[i][0] |= WALL_TOP;
} }
/* right wall */ /* right wall */
for ( j=0; j<maze_size_y; j++ ) { for (j = 0; j < maze_size_y; j++) {
maze[maze_size_x-1][j] |= WALL_RIGHT; maze[maze_size_x - 1][j] |= WALL_RIGHT;
} }
/* bottom wall */ /* bottom wall */
for ( i=0; i<maze_size_x; i++ ) { for (i = 0; i < maze_size_x; i++) {
maze[i][maze_size_y-1] |= WALL_BOTTOM; maze[i][maze_size_y - 1] |= WALL_BOTTOM;
} }
/* left wall */ /* left wall */
for ( j=0; j<maze_size_y; j++ ) { for (j = 0; j < maze_size_y; j++) {
maze[0][j] |= WALL_LEFT; maze[0][j] |= WALL_LEFT;
} }
@ -188,8 +183,8 @@ initialize_maze() /* draw the surrounding wall and start/end squares */
break; break;
} }
maze[i][j] |= START_SQUARE; maze[i][j] |= START_SQUARE;
maze[i][j] |= ( DOOR_IN_TOP >> wall ); maze[i][j] |= (DOOR_IN_TOP >> wall);
maze[i][j] &= ~( WALL_TOP >> wall ); maze[i][j] &= ~(WALL_TOP >> wall);
cur_sq_x = i; cur_sq_x = i;
cur_sq_y = j; cur_sq_y = j;
start_x = i; start_x = i;
@ -198,7 +193,7 @@ initialize_maze() /* draw the surrounding wall and start/end squares */
sqnum = 0; sqnum = 0;
/* set end square */ /* set end square */
wall = (wall + 2)%4; wall = (wall + 2) % 4;
switch (wall) { switch (wall) {
case 0: case 0:
i = get_random(maze_size_x); i = get_random(maze_size_x);
@ -218,39 +213,29 @@ initialize_maze() /* draw the surrounding wall and start/end squares */
break; break;
} }
maze[i][j] |= END_SQUARE; maze[i][j] |= END_SQUARE;
maze[i][j] |= ( DOOR_OUT_TOP >> wall ); maze[i][j] |= (DOOR_OUT_TOP >> wall);
maze[i][j] &= ~( WALL_TOP >> wall ); maze[i][j] &= ~(WALL_TOP >> wall);
end_x = i; end_x = i;
end_y = j; end_y = j;
end_dir = wall; end_dir = wall;
} }
static int choose_door (); static void create_maze(HWND hWnd) /* create a maze layout given the initialized maze */
static long backup ();
static void draw_wall ();
static void draw_solid_square(int, int, int, HDC, HBRUSH);
static void enter_square(int, HDC, HBRUSH);
static void
create_maze() /* create a maze layout given the intiialized maze */
{ {
register int i, newdoor = 0; register int i, newdoor = 0;
HDC hDC;
hDC = GetDC(hWnd);
do { do {
move_list[sqnum].x = cur_sq_x; move_list[sqnum].x = cur_sq_x;
move_list[sqnum].y = cur_sq_y; move_list[sqnum].y = cur_sq_y;
move_list[sqnum].dir = newdoor; move_list[sqnum].dir = newdoor;
while ( ( newdoor = choose_door(hDC) ) == -1 ) { /* pick a door */ while ((newdoor = choose_door(hDC)) == -1) { /* pick a door */
if ( backup() == -1 ) { /* no more doors ... backup */ if (backup() == -1) { /* no more doors ... backup */
ReleaseDC(hWnd, hDC);
return; /* done ... return */ return; /* done ... return */
} }
} }
/* mark the out door */ /* mark the out door */
maze[cur_sq_x][cur_sq_y] |= ( DOOR_OUT_TOP >> newdoor ); maze[cur_sq_x][cur_sq_y] |= (DOOR_OUT_TOP >> newdoor);
switch (newdoor) { switch (newdoor) {
case 0: cur_sq_y--; case 0: cur_sq_y--;
@ -265,25 +250,21 @@ create_maze() /* create a maze layout given the intiialized maze */
sqnum++; sqnum++;
/* mark the in door */ /* mark the in door */
maze[cur_sq_x][cur_sq_y] |= ( DOOR_IN_TOP >> ((newdoor+2)%4) ); maze[cur_sq_x][cur_sq_y] |= (DOOR_IN_TOP >> ((newdoor + 2) % 4));
/* if end square set path length and save path */ /* if end square set path length and save path */
if ( maze[cur_sq_x][cur_sq_y] & END_SQUARE ) { if (maze[cur_sq_x][cur_sq_y] & END_SQUARE) {
path_length = sqnum; path_length = sqnum;
for ( i=0; i<path_length; i++) { for (i = 0; i < path_length; i++) {
save_path[i].x = move_list[i].x; save_path[i].x = move_list[i].x;
save_path[i].y = move_list[i].y; save_path[i].y = move_list[i].y;
save_path[i].dir = move_list[i].dir; save_path[i].dir = move_list[i].dir;
} }
} }
} while (1); } while (1);
} }
static int choose_door(HDC hDC) /* pick a new path */
static int
choose_door(HDC hDC) /* pick a new path */
{ {
int candidates[3]; int candidates[3];
register int num_candidates; register int num_candidates;
@ -291,13 +272,13 @@ choose_door(HDC hDC) /* pick a new path */
num_candidates = 0; num_candidates = 0;
/* top wall */ /* top wall */
if ( maze[cur_sq_x][cur_sq_y] & DOOR_IN_TOP ) if (maze[cur_sq_x][cur_sq_y] & DOOR_IN_TOP)
goto rightwall; goto rightwall;
if ( maze[cur_sq_x][cur_sq_y] & DOOR_OUT_TOP ) if (maze[cur_sq_x][cur_sq_y] & DOOR_OUT_TOP)
goto rightwall; goto rightwall;
if ( maze[cur_sq_x][cur_sq_y] & WALL_TOP ) if (maze[cur_sq_x][cur_sq_y] & WALL_TOP)
goto rightwall; goto rightwall;
if ( maze[cur_sq_x][cur_sq_y - 1] & DOOR_IN_ANY ) { if (maze[cur_sq_x][cur_sq_y - 1] & DOOR_IN_ANY) {
maze[cur_sq_x][cur_sq_y] |= WALL_TOP; maze[cur_sq_x][cur_sq_y] |= WALL_TOP;
maze[cur_sq_x][cur_sq_y - 1] |= WALL_BOTTOM; maze[cur_sq_x][cur_sq_y - 1] |= WALL_BOTTOM;
draw_wall(cur_sq_x, cur_sq_y, 0, hDC); draw_wall(cur_sq_x, cur_sq_y, 0, hDC);
@ -305,15 +286,15 @@ choose_door(HDC hDC) /* pick a new path */
} }
candidates[num_candidates++] = 0; candidates[num_candidates++] = 0;
rightwall: rightwall:
/* right wall */ /* right wall */
if ( maze[cur_sq_x][cur_sq_y] & DOOR_IN_RIGHT ) if (maze[cur_sq_x][cur_sq_y] & DOOR_IN_RIGHT)
goto bottomwall; goto bottomwall;
if ( maze[cur_sq_x][cur_sq_y] & DOOR_OUT_RIGHT ) if (maze[cur_sq_x][cur_sq_y] & DOOR_OUT_RIGHT)
goto bottomwall; goto bottomwall;
if ( maze[cur_sq_x][cur_sq_y] & WALL_RIGHT ) if (maze[cur_sq_x][cur_sq_y] & WALL_RIGHT)
goto bottomwall; goto bottomwall;
if ( maze[cur_sq_x + 1][cur_sq_y] & DOOR_IN_ANY ) { if (maze[cur_sq_x + 1][cur_sq_y] & DOOR_IN_ANY) {
maze[cur_sq_x][cur_sq_y] |= WALL_RIGHT; maze[cur_sq_x][cur_sq_y] |= WALL_RIGHT;
maze[cur_sq_x + 1][cur_sq_y] |= WALL_LEFT; maze[cur_sq_x + 1][cur_sq_y] |= WALL_LEFT;
draw_wall(cur_sq_x, cur_sq_y, 1, hDC); draw_wall(cur_sq_x, cur_sq_y, 1, hDC);
@ -321,15 +302,15 @@ choose_door(HDC hDC) /* pick a new path */
} }
candidates[num_candidates++] = 1; candidates[num_candidates++] = 1;
bottomwall: bottomwall:
/* bottom wall */ /* bottom wall */
if ( maze[cur_sq_x][cur_sq_y] & DOOR_IN_BOTTOM ) if (maze[cur_sq_x][cur_sq_y] & DOOR_IN_BOTTOM)
goto leftwall; goto leftwall;
if ( maze[cur_sq_x][cur_sq_y] & DOOR_OUT_BOTTOM ) if (maze[cur_sq_x][cur_sq_y] & DOOR_OUT_BOTTOM)
goto leftwall; goto leftwall;
if ( maze[cur_sq_x][cur_sq_y] & WALL_BOTTOM ) if (maze[cur_sq_x][cur_sq_y] & WALL_BOTTOM)
goto leftwall; goto leftwall;
if ( maze[cur_sq_x][cur_sq_y + 1] & DOOR_IN_ANY ) { if (maze[cur_sq_x][cur_sq_y + 1] & DOOR_IN_ANY) {
maze[cur_sq_x][cur_sq_y] |= WALL_BOTTOM; maze[cur_sq_x][cur_sq_y] |= WALL_BOTTOM;
maze[cur_sq_x][cur_sq_y + 1] |= WALL_TOP; maze[cur_sq_x][cur_sq_y + 1] |= WALL_TOP;
draw_wall(cur_sq_x, cur_sq_y, 2, hDC); draw_wall(cur_sq_x, cur_sq_y, 2, hDC);
@ -337,15 +318,15 @@ choose_door(HDC hDC) /* pick a new path */
} }
candidates[num_candidates++] = 2; candidates[num_candidates++] = 2;
leftwall: leftwall:
/* left wall */ /* left wall */
if ( maze[cur_sq_x][cur_sq_y] & DOOR_IN_LEFT ) if (maze[cur_sq_x][cur_sq_y] & DOOR_IN_LEFT)
goto donewall; goto donewall;
if ( maze[cur_sq_x][cur_sq_y] & DOOR_OUT_LEFT ) if (maze[cur_sq_x][cur_sq_y] & DOOR_OUT_LEFT)
goto donewall; goto donewall;
if ( maze[cur_sq_x][cur_sq_y] & WALL_LEFT ) if (maze[cur_sq_x][cur_sq_y] & WALL_LEFT)
goto donewall; goto donewall;
if ( maze[cur_sq_x - 1][cur_sq_y] & DOOR_IN_ANY ) { if (maze[cur_sq_x - 1][cur_sq_y] & DOOR_IN_ANY) {
maze[cur_sq_x][cur_sq_y] |= WALL_LEFT; maze[cur_sq_x][cur_sq_y] |= WALL_LEFT;
maze[cur_sq_x - 1][cur_sq_y] |= WALL_RIGHT; maze[cur_sq_x - 1][cur_sq_y] |= WALL_RIGHT;
draw_wall(cur_sq_x, cur_sq_y, 3, hDC); draw_wall(cur_sq_x, cur_sq_y, 3, hDC);
@ -353,34 +334,29 @@ choose_door(HDC hDC) /* pick a new path */
} }
candidates[num_candidates++] = 3; candidates[num_candidates++] = 3;
donewall: donewall:
if (num_candidates == 0) if (num_candidates == 0)
return ( -1 ); return -1;
if (num_candidates == 1) if (num_candidates == 1)
return ( candidates[0] ); return candidates[0];
return ( candidates[ get_random(num_candidates) ] ); return candidates[get_random(num_candidates)];
} }
static long backup() /* back up a move */
static long
backup() /* back up a move */
{ {
sqnum--; sqnum--;
if (0 <= sqnum) { if (0 <= sqnum) {
cur_sq_x = move_list[sqnum].x; cur_sq_x = move_list[sqnum].x;
cur_sq_y = move_list[sqnum].y; cur_sq_y = move_list[sqnum].y;
} }
return ( sqnum ); return sqnum;
} }
int bw; static void draw_solid_square(i, j, dir, hDC, hBrush) /* draw a solid square in a square */
register int i, j, dir;
static void HDC hDC;
draw_solid_square(i, j, dir, hDC, hBrush) /* draw a solid square in a square */ HBRUSH hBrush;
register int i, j, dir;
HDC hDC;
HBRUSH hBrush;
{ {
RECT rc; RECT rc;
@ -413,118 +389,67 @@ draw_solid_square(i, j, dir, hDC, hBrush) /* draw a solid square in a s
(void) FillRect(hDC, &rc, hBrush); (void) FillRect(hDC, &rc, hBrush);
} }
static void static void draw_maze_border(HWND hWnd) /* draw the maze outline */
draw_maze_border(HWND hWnd, HDC hDC) /* draw the maze outline */
{ {
register int i, j; register int i, j;
HBRUSH hBrush; HBRUSH hBrush;
SelectObject(hDC, hPenWall); SelectObject(hDC, hPenWall);
for ( i=0; i<maze_size_x; i++) { for (i = 0; i < maze_size_x; i++) {
if ( maze[i][0] & WALL_TOP ) { if (maze[i][0] & WALL_TOP) {
MoveToEx(hDC, border_x + grid_width * i, border_y, NULL); MoveToEx(hDC, border_x + grid_width * i, border_y, NULL);
(void) LineTo(hDC, border_x + grid_width * (i + 1) - 1, border_y); (void) LineTo(hDC, border_x + grid_width * (i + 1) - 1, border_y);
} }
if ((maze[i][maze_size_y - 1] & WALL_BOTTOM)) { if ((maze[i][maze_size_y - 1] & WALL_BOTTOM)) {
MoveToEx(hDC, border_x + grid_width * i, MoveToEx(hDC, border_x + grid_width * i, border_y + grid_height * (maze_size_y) -1, NULL);
border_y + grid_height * (maze_size_y) - 1, NULL); (void) LineTo(hDC, border_x + grid_width * (i + 1) - 1, border_y + grid_height * (maze_size_y) -1);
(void) LineTo(hDC, border_x + grid_width * (i+1) - 1,
border_y + grid_height * (maze_size_y) - 1);
} }
} }
for ( j=0; j<maze_size_y; j++) { for (j = 0; j < maze_size_y; j++) {
if ( maze[maze_size_x - 1][j] & WALL_RIGHT ) { if (maze[maze_size_x - 1][j] & WALL_RIGHT) {
MoveToEx(hDC, border_x + grid_width * maze_size_x - 1, MoveToEx(hDC, border_x + grid_width * maze_size_x - 1, border_y + grid_height * j, NULL);
border_y + grid_height * j, NULL); (void) LineTo(hDC, border_x + grid_width * maze_size_x - 1, border_y + grid_height * (j + 1) - 1);
(void) LineTo(hDC, border_x + grid_width * maze_size_x - 1,
border_y + grid_height * (j+1) - 1);
} }
if ( maze[0][j] & WALL_LEFT ) { if (maze[0][j] & WALL_LEFT) {
MoveToEx(hDC, border_x, border_y + grid_height * j, NULL); MoveToEx(hDC, border_x, border_y + grid_height * j, NULL);
(void) LineTo(hDC, border_x, border_y + grid_height * (j+1) - 1); (void) LineTo(hDC, border_x, border_y + grid_height * (j + 1) - 1);
} }
} }
hBrush = GetStockObject(WHITE_BRUSH); // FIXME: do not hardcode hBrush = GetStockObject(WHITE_BRUSH); // FIXME: do not hardcode
draw_solid_square (start_x, start_y, start_dir, hDC, hBrush); draw_solid_square(start_x, start_y, start_dir, hDC, hBrush);
draw_solid_square (end_x, end_y, end_dir, hDC, hBrush); draw_solid_square(end_x, end_y, end_dir, hDC, hBrush);
} }
static void draw_wall(i, j, dir, hDC) /* draw a single wall */
static void register int i, j, dir;
draw_wall(i, j, dir, hDC) /* draw a single wall */ HDC hDC;
int i, j, dir;
HDC hDC;
{ {
SelectObject(hDC, hPenWall); SelectObject(hDC, hPenWall);
switch (dir) { switch (dir) {
case 0: case 0:
MoveToEx(hDC, border_x + grid_width * i, border_y + grid_height * j, NULL); MoveToEx(hDC, border_x + grid_width * i, border_y + grid_height * j, NULL);
(void) LineTo(hDC, border_x + grid_width * (i+1), (void) LineTo(hDC, border_x + grid_width * (i + 1), border_y + grid_height * j);
border_y + grid_height * j);
break; break;
case 1: case 1:
MoveToEx(hDC, border_x + grid_width * (i+1), border_y + grid_height * j, MoveToEx(hDC, border_x + grid_width * (i + 1), border_y + grid_height * j, NULL);
NULL); (void) LineTo(hDC, border_x + grid_width * (i + 1), border_y + grid_height * (j + 1));
(void) LineTo(hDC, border_x + grid_width * (i+1),
border_y + grid_height * (j+1));
break; break;
case 2: case 2:
MoveToEx(hDC, border_x + grid_width * i, border_y + grid_height * (j+1), MoveToEx(hDC, border_x + grid_width * i, border_y + grid_height * (j + 1), NULL);
NULL); (void) LineTo(hDC, border_x + grid_width * (i + 1), border_y + grid_height * (j + 1));
(void) LineTo(hDC, border_x + grid_width * (i+1),
border_y + grid_height * (j+1));
break; break;
case 3: case 3:
MoveToEx(hDC, border_x + grid_width * i, border_y + grid_height * j, MoveToEx(hDC, border_x + grid_width * i, border_y + grid_height * j, NULL);
NULL); (void) LineTo(hDC, border_x + grid_width * i, border_y + grid_height * (j + 1));
(void) LineTo(hDC, border_x + grid_width * i,
border_y + grid_height * (j+1));
break; break;
} }
} }
static void static void begin_solve_maze(HWND hWnd) /* solve it with graphical feedback */
begin_solve_maze() /* solve it with graphical feedback */
{ {
static long grayPattern[] = {
0x55555555,
0xaaaaaaaa,
0x55555555,
0xaaaaaaaa,
0x55555555,
0xaaaaaaaa,
0x55555555,
0xaaaaaaaa
};
static RGBQUAD argbq[] = {
{ 0, 0, 255, 0 },
{ 255, 255, 255, 0 }
};
BITMAPINFO *pbmi;
hDC = GetDC(hWnd);
pbmi = malloc(sizeof(BITMAPINFOHEADER) + sizeof(argbq) + sizeof(grayPattern));
pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
pbmi->bmiHeader.biWidth = 8;
pbmi->bmiHeader.biHeight = 8;
pbmi->bmiHeader.biPlanes = 1;
pbmi->bmiHeader.biBitCount = 1;
pbmi->bmiHeader.biCompression = BI_RGB;
(void) memcpy(pbmi->bmiColors, argbq, sizeof(argbq));
(void) memcpy(pbmi->bmiColors + 2, grayPattern, sizeof(grayPattern));
#if 0
/* FIXME Pattern brushes not yet implemented in ReactOS */
hBrushDead = CreateDIBPatternBrushPt(pbmi, DIB_RGB_COLORS);
#else
hBrushDead = CreateSolidBrush(RGB(255, 0, 0));
#endif
// hBrushDead = CreateHatchBrush(HS_DIAGCROSS, RGB(255, 0, 0));
free(pbmi);
hBrushLiving = CreateSolidBrush(RGB(0, 255, 0));
/* plug up the surrounding wall */ /* plug up the surrounding wall */
maze[start_x][start_y] |= (WALL_TOP >> start_dir); maze[start_x][start_y] |= (WALL_TOP >> start_dir);
maze[end_x][end_y] |= (WALL_TOP >> end_dir); maze[end_x][end_y] |= (WALL_TOP >> end_dir);
@ -536,257 +461,65 @@ begin_solve_maze() /* solve it with graphical feedba
path[pathi].dir = -1; path[pathi].dir = -1;
} }
static int static int solve_maze(HWND hWnd) /* solve it with graphical feedback */
solve_maze() /* solve it with graphical feedback */
{ {
int ret; int ret;
int action_done; int action_done;
do { do {
action_done = 1; action_done = 1;
if ( ++path[pathi].dir >= 4 ) { if (++path[pathi].dir >= 4) {
pathi--; pathi--;
draw_solid_square( (int)(path[pathi].x), (int)(path[pathi].y), draw_solid_square((int) (path[pathi].x), (int) (path[pathi].y), (int) (path[pathi].dir), hDC, hBrushDead);
(int)(path[pathi].dir), hDC, hBrushDead);
ret = 0; ret = 0;
} }
else if ( ! (maze[path[pathi].x][path[pathi].y] & else if (!(maze[path[pathi].x][path[pathi].y] & (WALL_TOP >> path[pathi].dir)) &&
(WALL_TOP >> path[pathi].dir)) && ((pathi == 0) || ((path[pathi].dir != (int) (path[pathi - 1].dir + 2) % 4)))) {
( (pathi == 0) || ( (path[pathi].dir !=
(int)(path[pathi-1].dir+2)%4) ) ) ) {
enter_square(pathi, hDC, hBrushLiving); enter_square(pathi, hDC, hBrushLiving);
pathi++; pathi++;
if ( maze[path[pathi].x][path[pathi].y] & START_SQUARE ) { if (maze[path[pathi].x][path[pathi].y] & START_SQUARE) {
DeleteObject(hBrushLiving);
DeleteObject(hBrushDead);
ReleaseDC(hWnd, hDC);
ret = 1; ret = 1;
} else { }
else {
ret = 0; ret = 0;
} }
} else { }
else {
action_done = 0; action_done = 0;
} }
} while (! action_done); } while (!action_done);
return ret; return ret;
} }
static void enter_square(int n, HDC hDC, HBRUSH hBrush) /* move into a neighboring square */
static void
enter_square(int n, HDC hDC, HBRUSH hBrush) /* move into a neighboring square */
{ {
draw_solid_square( (int)path[n].x, (int)path[n].y, draw_solid_square((int) path[n].x, (int) path[n].y, (int) path[n].dir, hDC, hBrush);
(int)path[n].dir, hDC, hBrush);
path[n+1].dir = -1; path[n + 1].dir = -1;
switch (path[n].dir) { switch (path[n].dir) {
case 0: path[n+1].x = path[n].x; case 0: path[n + 1].x = path[n].x;
path[n+1].y = path[n].y - 1; path[n + 1].y = path[n].y - 1;
break; break;
case 1: path[n+1].x = path[n].x + 1; case 1: path[n + 1].x = path[n].x + 1;
path[n+1].y = path[n].y; path[n + 1].y = path[n].y;
break; break;
case 2: path[n+1].x = path[n].x; case 2: path[n + 1].x = path[n].x;
path[n+1].y = path[n].y + 1; path[n + 1].y = path[n].y + 1;
break; break;
case 3: path[n+1].x = path[n].x - 1; case 3: path[n + 1].x = path[n].x - 1;
path[n+1].y = path[n].y; path[n + 1].y = path[n].y;
break; break;
} }
} }
static void static void start_timer(HWND hWnd, int iTimeout)
start_timer(HWND hWnd, int iTimeout)
{ {
waiting = TRUE;
SetTimer(hWnd, 1, iTimeout, NULL); SetTimer(hWnd, 1, iTimeout, NULL);
} }
/**************************************************************************** static BOOL OnCreate(HWND hWnd, LPCREATESTRUCT lpCreateStruct)
FUNCTION: WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
PURPOSE: calls initialization function, processes message loop
COMMENTS:
Windows recognizes this function by name as the initial entry point
for the program. This function calls the application initialization
routine, if no other instance of the program is running, and always
calls the instance initialization routine. It then executes a message
retrieval and dispatch loop that is the top-level control structure
for the remainder of execution. The loop is terminated when a WM_QUIT
message is received, at which time this function exits the application
instance by returning the value passed by PostQuitMessage().
If this function must abort before entering the message loop, it
returns the conventional value NULL.
****************************************************************************/
int APIENTRY MazeMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
HWND hParent)
{ {
MSG msg;
HDC hDC;
/* Perform initializations that apply to a specific instance */
if (!InitInstance(hInstance, hParent)) {
return (FALSE);
}
waiting = FALSE;
state = 1;
/* Acquire and dispatch messages until a WM_QUIT message is received. */
while (0 != state) {
if (waiting) {
(void) WaitMessage();
}
while (0 != state && PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
if (WM_QUIT == msg.message) {
state = 0;
} else {
DispatchMessage(&msg); /* Dispatches message to window */
}
}
switch (state) {
case 1:
initialize_maze();
state = 2;
break;
case 2:
hDC = GetDC(hWnd);
SendMessage(hWnd, WM_ERASEBKGND, (WPARAM) hDC, (LPARAM) 0);
draw_maze_border(hWnd, hDC);
ReleaseDC(hWnd, hDC);
state = 3;
break;
case 3:
create_maze();
state = 4;
break;
case 4:
start_timer(hWnd, pre_solve_delay);
state = 5;
break;
case 5:
if (! waiting) {
state = 6;
}
break;
case 6:
begin_solve_maze();
if (0 != solve_delay) {
start_timer(hWnd, solve_delay);
state = 7;
} else {
state = 8;
}
break;
case 7:
if (! waiting) {
state = 8;
}
break;
case 8:
if (! solve_maze()) {
if (0 != solve_delay) {
start_timer(hWnd, solve_delay);
state = 7;
}
} else {
state = 9;
}
break;
case 9:
start_timer(hWnd, post_solve_delay);
state = 10;
break;
case 10:
if (! waiting) {
state = 11;
}
break;
case 11:
state = 1;
break;
}
}
return (msg.wParam); /* Returns the value from PostQuitMessage */
}
/****************************************************************************
FUNCTION: InitInstance(HINSTANCE, int)
PURPOSE: Saves instance handle and creates main window
COMMENTS:
This function is called at initialization time for every instance of
this application. This function performs initialization tasks that
cannot be shared by multiple instances.
In this case, we save the instance handle in a static variable and
create and display the main program window.
****************************************************************************/
static BOOL InitInstance(
HINSTANCE hInstance,
HWND hParent)
{
RECT rect;
/* Save the instance handle in static variable, which will be used in
many subsequence calls from this application to Windows. */
hInst = hInstance; /* Store instance handle in our global variable */
GetClientRect(hParent, &rect);
#if 0
/* Create a main window for this application instance. */
hWnd = CreateWindow(
szAppName, /* See RegisterClass() call. */
szTitle, /* Text for window title bar. */
WS_CHILD,/* Window style. */
0, 0, rect.right/2, rect.bottom/2, /* Use default positioning */
hParent, /* We use a Parent. */
NULL, /* Use the window class menu. */
hInstance, /* This instance owns this window. */
NULL /* We don't use any data in our WM_CREATE */
);
#endif
hWnd = hParent;
// If window could not be created, return "failure"
if (!hWnd) {
return (FALSE);
}
// Make the window visible; update its client area; and return "success"
ShowWindow(hWnd, SW_SHOW); // Show the window
SetCursor(NULL);
UpdateWindow(hWnd); // Sends WM_PAINT message
hPenWall = CreatePen(PS_SOLID, 3, RGB(150,150,150));
return (TRUE); // We succeeded...
}
static BOOL
OnCreate(HWND hWnd, LPCREATESTRUCT lpCreateStruct)
{
RECT rc;
int size; int size;
srand((unsigned) time(NULL)); srand((unsigned) time(NULL));
@ -794,12 +527,9 @@ OnCreate(HWND hWnd, LPCREATESTRUCT lpCreateStruct)
#if 0 #if 0
/* FIXME GetPrivateProfileInt not yet implemented in ReactOS */ /* FIXME GetPrivateProfileInt not yet implemented in ReactOS */
size = GetPrivateProfileInt("maze", "gridsize", 0, "maze.ini"); size = GetPrivateProfileInt("maze", "gridsize", 0, "maze.ini");
pre_solve_delay = GetPrivateProfileInt("maze", "predelay", 5000, pre_solve_delay = GetPrivateProfileInt("maze", "predelay", 5000, "maze.ini");
"maze.ini"); post_solve_delay = GetPrivateProfileInt("maze", "postdelay", 5000, "maze.ini");
post_solve_delay = GetPrivateProfileInt("maze", "postdelay", 5000, solve_delay = GetPrivateProfileInt("maze", "solvedelay", 10, "maze.ini");
"maze.ini");
solve_delay = GetPrivateProfileInt("maze", "solvedelay", 10,
"maze.ini");
#else #else
size = 10; size = 10;
pre_solve_delay = 5000; pre_solve_delay = 5000;
@ -811,58 +541,131 @@ OnCreate(HWND hWnd, LPCREATESTRUCT lpCreateStruct)
size = 7 + (rand() % 30); size = 7 + (rand() % 30);
} }
grid_width = grid_height = size; grid_width = grid_height = size;
bw = (size > 6 ? 3 : (size-1)/2); bw = (size > 6 ? 3 : (size - 1) / 2);
GetClientRect(hWnd, &rc); #if 0
set_maze_sizes(rc.right - rc.left, rc.bottom - rc.top); /* FIXME Pattern brushes not yet implemented in ReactOS */
{
static long grayPattern [] = {
0x55555555,
0xaaaaaaaa,
0x55555555,
0xaaaaaaaa,
0x55555555,
0xaaaaaaaa,
0x55555555,
0xaaaaaaaa
};
static RGBQUAD argbq [] = {
{ 0, 0, 255, 0 },
{ 255, 255, 255, 0 }
};
BITMAPINFO *pbmi;
pbmi = malloc(sizeof(BITMAPINFOHEADER) + sizeof(argbq) + sizeof(grayPattern));
pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
pbmi->bmiHeader.biWidth = 8;
pbmi->bmiHeader.biHeight = 8;
pbmi->bmiHeader.biPlanes = 1;
pbmi->bmiHeader.biBitCount = 1;
pbmi->bmiHeader.biCompression = BI_RGB;
(void) memcpy(pbmi->bmiColors, argbq, sizeof(argbq));
(void) memcpy(pbmi->bmiColors + 2, grayPattern, sizeof(grayPattern));
hBrushDead = CreateDIBPatternBrushPt(pbmi, DIB_RGB_COLORS);
// hBrushDead = CreateHatchBrush(HS_DIAGCROSS, RGB(255, 0, 0));
free(pbmi);
}
#else
hBrushDead = CreateSolidBrush(RGB(255, 0, 0));
#endif
hBrushLiving = CreateSolidBrush(RGB(0, 255, 0));
hPenWall = CreatePen(PS_SOLID, 3, RGB(150, 150, 150));
hDC = GetDC(hWnd);
start_timer(hWnd, 1);
return TRUE; return TRUE;
} }
void OnTimer(HWND hwnd, UINT id) LRESULT CALLBACK ScreenSaverProc(
{
waiting = FALSE;
}
/****************************************************************************
FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
PURPOSE: Processes messages
MESSAGES:
WM_DESTROY - destroy window
COMMENTS:
****************************************************************************/
LRESULT CALLBACK MazeWndProc(
HWND hWnd, // window handle HWND hWnd, // window handle
UINT message, // type of message UINT message, // type of message
WPARAM wParam, // additional information WPARAM wParam, // additional information
LPARAM lParam) // additional information LPARAM lParam) // additional information
{ {
PAINTSTRUCT ps; switch (message)
{
switch (message) {
case WM_CREATE: case WM_CREATE:
OnCreate(hWnd, (LPCREATESTRUCT) lParam); OnCreate(hWnd, (LPCREATESTRUCT) lParam);
break; break;
case WM_PAINT: case WM_SIZE:
BeginPaint(hWnd, &ps); set_maze_sizes(LOWORD(lParam), HIWORD(lParam));
state = 1;
EndPaint(hWnd, &ps);
case WM_TIMER:
OnTimer(hWnd, wParam);
break; break;
case WM_TIMER:
switch (state)
{
case 2:
begin_solve_maze(hWnd);
state = 3;
start_timer(hWnd, solve_delay);
break;
case 3:
if (!solve_maze(hWnd))
{
start_timer(hWnd, solve_delay);
}
else
{
state = 1;
start_timer(hWnd, post_solve_delay);
}
break;
default:
initialize_maze();
SendMessage(hWnd, WM_ERASEBKGND, (WPARAM) hDC, (LPARAM) 0);
draw_maze_border(hWnd);
create_maze(hWnd);
state = 2;
start_timer(hWnd, pre_solve_delay);
break;
}
break;
case WM_DESTROY: // message: window being destroyed case WM_DESTROY: // message: window being destroyed
PostQuitMessage(0); DeleteObject(hBrushLiving);
DeleteObject(hBrushDead);
ReleaseDC(hWnd, hDC);
break; break;
default: // Passes it on if unproccessed default: // Passes it on if unproccessed
return (DefWindowProc(hWnd, message, wParam, lParam)); return DefScreenSaverProc(hWnd, message, wParam, lParam);
} }
return (0); return 0;
}
BOOL WINAPI ScreenSaverConfigureDialog(HWND hWnd, UINT message, WPARAM wparam, LPARAM lparam)
{
return TRUE;
}
BOOL WINAPI RegisterDialogClasses(HANDLE hmodule)
{
TCHAR szTitle[256];
TCHAR szText[256];
LoadString(hmodule, IDS_TITLE, szTitle, 256);
LoadString(hmodule, IDS_TEXT, szText, 256);
MessageBox(0, szText, szTitle, MB_OK | MB_ICONWARNING);
return TRUE;
} }

View file

@ -0,0 +1,53 @@
#include <windows.h>
#include <scrnsave.h>
#include "resource.h"
LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
IDI_ICON ICON DISCARDABLE "res/icon_mazescr.ico"
#define REACTOS_VERSION_DLL
#define REACTOS_STR_FILE_DESCRIPTION "Maze ScreenSaver\0"
#define REACTOS_STR_INTERNAL_NAME "maze\0"
#define REACTOS_STR_ORIGINAL_FILENAME "maze.scr\0"
#include <reactos/version.rc>
#include <reactos/manifest_exe.rc>
/* UTF-8 */
#pragma code_page(65001)
#ifdef LANGUAGE_BG_BG
#include "lang/bg-BG.rc"
#endif
#ifdef LANGUAGE_DE_DE
#include "lang/de-DE.rc"
#endif
#ifdef LANGUAGE_EN_US
#include "lang/en-US.rc"
#endif
#ifdef LANGUAGE_ES_ES
#include "lang/es-ES.rc"
#endif
#ifdef LANGUAGE_FR_FR
#include "lang/fr-FR.rc"
#endif
#ifdef LANGUAGE_LT_LT
#include "lang/lt-LT.rc"
#endif
#ifdef LANGUAGE_NO_NO
#include "lang/no-NO.rc"
#endif
#ifdef LANGUAGE_PL_PL
#include "lang/pl-PL.rc"
#endif
#ifdef LANGUAGE_RO_RO
#include "lang/ro-RO.rc"
#endif
#ifdef LANGUAGE_SK_SK
#include "lang/sk-SK.rc"
#endif
#ifdef LANGUAGE_UK_UA
#include "lang/uk-UA.rc"
#endif

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

View file

@ -1,4 +1,6 @@
#pragma once
#define IDS_DESCRIPTION 1 #define IDS_DESCRIPTION 1
#define IDS_TITLE 2 #define IDS_TITLE 2
#define IDS_TEXT 3 #define IDS_TEXT 3
#define IDI_ICON 101

View file

@ -1,234 +0,0 @@
/*
* Copyright 2003 J Brown
* Copyright 2006 Eric Kohl
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#include <windows.h>
#include <tchar.h>
#include "resource.h"
#define APPNAME _T("Scrnsave")
LRESULT CALLBACK MazeWndProc(
HWND hWnd, // window handle
UINT message, // type of message
WPARAM wParam, // additional information
LPARAM lParam); // additional information
int APIENTRY MazeMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
HWND hParent);
HINSTANCE hInstance;
BOOL fullscreen = FALSE;
LRESULT WINAPI WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
static POINT ptLast;
static POINT ptCursor;
static BOOL fFirstTime = TRUE;
switch (msg)
{
case WM_DESTROY:
if (fullscreen)
ShowCursor(TRUE);
PostQuitMessage(0);
break;
// break out of screen-saver if any keyboard activity
case WM_NOTIFY:
case WM_SYSKEYDOWN:
PostMessage(hwnd, WM_CLOSE, 0, 0);
break;
// break out of screen-saver if any mouse activity
case WM_LBUTTONDOWN:
case WM_LBUTTONUP:
case WM_RBUTTONDOWN:
case WM_RBUTTONUP:
case WM_MBUTTONDOWN:
case WM_MBUTTONUP:
case WM_MOUSEMOVE:
// If we've got a parent then we must be a preview
if(GetParent(hwnd) != 0)
return 0;
if(fFirstTime)
{
GetCursorPos(&ptLast);
fFirstTime = FALSE;
}
GetCursorPos(&ptCursor);
// if the mouse has moved more than 3 pixels then exit
if(abs(ptCursor.x - ptLast.x) >= 3 || abs(ptCursor.y - ptLast.y) >= 3)
PostMessage(hwnd, WM_CLOSE, 0, 0);
ptLast = ptCursor;
return 0;
}
return MazeWndProc(hwnd, msg, wParam, lParam);
}
HWND InitSaver(HWND hwndParent)
{
WNDCLASS wc;
HWND hwnd;
ZeroMemory(&wc, sizeof(wc));
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WndProc;
wc.lpszClassName = APPNAME;
wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
RegisterClass(&wc);
if (hwndParent != 0)
{
RECT rect;
GetClientRect(hwndParent, &rect);
hwnd = CreateWindow(APPNAME, APPNAME,
WS_VISIBLE | WS_CHILD,
0, 0,
rect.right,
rect.bottom,
hwndParent, 0,
hInstance, NULL);
fullscreen = FALSE;
}
else
{
hwnd = CreateWindowEx(WS_EX_TOPMOST,
APPNAME,
APPNAME,
WS_VISIBLE | WS_POPUP,
0,
0,
GetSystemMetrics(SM_CXSCREEN),
GetSystemMetrics(SM_CYSCREEN),
HWND_DESKTOP,
0,
hInstance,
NULL);
SetWindowPos(hwnd,
0,
0,
0,
0,
0,
SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOSIZE | SWP_SHOWWINDOW);
ShowCursor(FALSE);
fullscreen = TRUE;
}
return hwnd;
}
void ParseCommandLine(PSTR szCmdLine, int *chOption, HWND *hwndParent)
{
int ch = *szCmdLine++;
if(ch == '-' || ch == '/')
ch = *szCmdLine++;
if(ch >= 'A' && ch <= 'Z')
ch += 'a' - 'A';
*chOption = ch;
ch = *szCmdLine++;
if(ch == ':')
ch = *szCmdLine++;
while(ch == ' ' || ch == '\t')
ch = *szCmdLine++;
if(isdigit(ch))
{
unsigned int i = atoi(szCmdLine - 1);
*hwndParent = (HWND)i;
}
else
*hwndParent = 0;
}
void Configure(void)
{
TCHAR szTitle[256];
TCHAR szText[256];
LoadString(hInstance,
IDS_TITLE,
szTitle,
256);
LoadString(hInstance,
IDS_TEXT,
szText,
256);
MessageBox(0,
szText,
szTitle,
MB_OK | MB_ICONWARNING);
}
int WINAPI WinMain (HINSTANCE hInst,
HINSTANCE hPrev,
LPSTR lpCmdLine,
int iCmdShow)
{
HWND hwndParent;
HWND hwndChild;
UINT nPreviousState;
int chOption;
hInstance = hInst;
ParseCommandLine(lpCmdLine, &chOption, &hwndParent);
SystemParametersInfo(SPI_SETSCREENSAVERRUNNING, TRUE, &nPreviousState, 0);
switch (chOption)
{
case 's':
hwndChild = InitSaver(0);
break;
case 'p':
hwndChild = InitSaver(hwndParent);
break;
case 'c':
default:
Configure();
return 0;
}
MazeMain(hInst, hPrev, lpCmdLine, hwndChild);
SystemParametersInfo(SPI_SETSCREENSAVERRUNNING, FALSE, &nPreviousState, 0);
return 0;
}

View file

@ -1,26 +0,0 @@
#include <windows.h>
#include "resource.h"
LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
#define REACTOS_VERSION_DLL
#define REACTOS_STR_FILE_DESCRIPTION "Maze ScreenSaver\0"
#define REACTOS_STR_INTERNAL_NAME "maze\0"
#define REACTOS_STR_ORIGINAL_FILENAME "maze.scr\0"
#include <reactos/version.rc>
/* UTF-8 */
#pragma code_page(65001)
#include "lang/bg-BG.rc"
#include "lang/de-DE.rc"
#include "lang/en-US.rc"
#include "lang/es-ES.rc"
#include "lang/fr-FR.rc"
#include "lang/lt-LT.rc"
#include "lang/no-NO.rc"
#include "lang/pl-PL.rc"
#include "lang/ro-RO.rc"
#include "lang/sk-SK.rc"
#include "lang/uk-UA.rc"