2 * Copyright 2003 J Brown
3 * Copyright 2006 Eric Kohl
4 * Copyright 2007 Marc Piulachs (marc.piulachs@codexchange.net)
5 * Copyright 2015 Daniel Reimer
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
27 #define RANDOM( min, max ) ((rand() % (int)(((max)+1) - (min))) + (min))
29 #define MAX_LOADSTRING 100
30 #define MAX_STARS 1000
32 #define APPNAME _T("Starfield")
34 #define APP_TIMER_INTERVAL 20
36 #define MAX_STARS 1000
38 // Details of each individual star
41 int m_nXPos
, m_nYPos
, m_nZPos
;
48 int m_nCenterX
, m_nCenterY
;
50 void DrawStarField (HDC pDC
)
54 for (i
= 0; i
< m_nTotStars
; i
++)
56 // Clear last position of this star
63 nX
= (int)((((long)stars
[i
].m_nXPos
<< 7) / (long)stars
[i
].m_nZPos
) + m_nCenterX
);
64 nY
= (int)((((long)stars
[i
].m_nYPos
<< 7) / (long)stars
[i
].m_nZPos
) + m_nCenterY
);
73 // Remember current position for clearing later
74 stars
[i
].m_nOldX
= nX
;
75 stars
[i
].m_nOldY
= nY
;
79 BOOL
SetUpStars (int nNumStars
)
82 if (nNumStars
> MAX_STARS
)
85 _T("Too many stars! Aborting!"),
87 MB_OK
| MB_ICONWARNING
);
94 m_nTotStars
= nNumStars
;
96 stars
= (STAR
*)malloc(nNumStars
* sizeof(STAR
));
101 _T("Unable to allocate memory! Aborting!"),
103 MB_OK
| MB_ICONWARNING
);
107 for (i
= 0; i
< m_nTotStars
; i
++)
111 stars
[i
].m_nXPos
= RANDOM (-320, 320);
112 stars
[i
].m_nYPos
= RANDOM (-200, 200);
113 stars
[i
].m_nZPos
= i
+1;
114 stars
[i
].m_nOldX
= -1;
115 stars
[i
].m_nOldY
= -1;
116 } while ((stars
[i
].m_nXPos
== 0) || (stars
[i
].m_nYPos
== 0));
121 void MoveStarField (int nXofs
, int nYofs
, int nZofs
)
124 for (i
= 0; i
< m_nTotStars
; i
++)
126 stars
[i
].m_nXPos
+= nXofs
;
127 stars
[i
].m_nYPos
+= nYofs
;
128 stars
[i
].m_nZPos
+= nZofs
;
130 if (stars
[i
].m_nZPos
> m_nTotStars
)
131 stars
[i
].m_nZPos
-= m_nTotStars
;
132 if (stars
[i
].m_nZPos
< 1)
133 stars
[i
].m_nZPos
+= m_nTotStars
;
137 void SetDimensions (int nWidth
, int nHeight
)
139 m_nCenterX
= nWidth
/ 2;
140 m_nCenterY
= nHeight
/ 2;
143 LRESULT WINAPI
ScreenSaverProc(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
161 HDC pDC
= BeginPaint (hwnd
, &PtStr
);
163 EndPaint (hwnd
, &PtStr
);
170 if (wParam
== APP_TIMER
)
172 MoveStarField (0, 0, -3);
175 ReleaseDC(hwnd
, pDC
);
181 // Change the center point of the starfield
189 KillTimer (hwnd
, APP_TIMER
);
197 return DefScreenSaverProc(hwnd
, msg
, wParam
, lParam
);
202 BOOL WINAPI
ScreenSaverConfigureDialog(HWND hWnd
, UINT message
, WPARAM wparam
, LPARAM lparam
)
207 BOOL WINAPI
RegisterDialogClasses(HANDLE hmodule
)
225 MB_OK
| MB_ICONWARNING
);