1 /* $Id: Splash.cpp,v 5.1 2001/05/27 20:40:46 dik Exp $
2  *
3  * XPilot, a multiplayer gravity war game.  Copyright (C) 1991-2001 by
4  *
5  *      Bj�rn Stabell        <bjoern@xpilot.org>
6  *      Ken Ronny Schouten   <ken@xpilot.org>
7  *      Bert Gijsbers        <bert@xpilot.org>
8  *      Dick Balaska         <dick@xpilot.org>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23  */
24 
25 /***************************************************************************\
26 *  Splash.cpp - The Splash Panel for XPilot.exe								*
27 *																			*
28 *  This file is the standard splash component from MSDEV enhanced to allow	*
29 *  displaying progress messages in the lower left corner.					*
30 *																			*
31 *  $Id: Splash.cpp,v 5.1 2001/05/27 20:40:46 dik Exp $							*
32 \***************************************************************************/
33 // CG: This file was added by the Splash Screen component.
34 
35 #include "stdafx.h"  // e. g. stdafx.h
36 #include "resource.h"  // e.g. resource.h
37 
38 #include "Splash.h"  // e.g. splash.h
39 #include "../../common/version.h"
40 
41 #ifdef _DEBUG
42 #define new DEBUG_NEW
43 #undef THIS_FILE
44 static char BASED_CODE THIS_FILE[] = __FILE__;
45 #endif
46 
47 /////////////////////////////////////////////////////////////////////////////
48 //   Splash Screen class
49 
50 BOOL CSplashWnd::c_bShowSplashWnd;
51 CSplashWnd* CSplashWnd::c_pSplashWnd;
CSplashWnd()52 CSplashWnd::CSplashWnd()
53 {
54 }
55 
~CSplashWnd()56 CSplashWnd::~CSplashWnd()
57 {
58 	// Clear the static window pointer.
59 	ASSERT(c_pSplashWnd == this);
60 	c_pSplashWnd = NULL;
61 }
62 
BEGIN_MESSAGE_MAP(CSplashWnd,CWnd)63 BEGIN_MESSAGE_MAP(CSplashWnd, CWnd)
64 	//{{AFX_MSG_MAP(CSplashWnd)
65 	ON_WM_CREATE()
66 	ON_WM_PAINT()
67 	ON_WM_TIMER()
68 	//}}AFX_MSG_MAP
69 END_MESSAGE_MAP()
70 
71 void CSplashWnd::EnableSplashScreen(BOOL bEnable /*= TRUE*/)
72 {
73 	c_bShowSplashWnd = bEnable;
74 }
75 
ShowSplashScreen(CWnd * pParentWnd)76 void CSplashWnd::ShowSplashScreen(CWnd* pParentWnd /*= NULL*/)
77 {
78 	if (!c_bShowSplashWnd || c_pSplashWnd != NULL)
79 		return;
80 
81 	// Allocate a new splash screen, and create the window.
82 	c_pSplashWnd = new CSplashWnd;
83 	if (!c_pSplashWnd->Create(pParentWnd))
84 		delete c_pSplashWnd;
85 	else
86 		c_pSplashWnd->UpdateWindow();
87 }
88 
PreTranslateAppMessage(MSG * pMsg)89 BOOL CSplashWnd::PreTranslateAppMessage(MSG* pMsg)
90 {
91 	if (c_pSplashWnd == NULL)
92 		return FALSE;
93 
94 	// If we get a keyboard or mouse message, hide the splash screen.
95 	if (pMsg->message == WM_KEYDOWN ||
96 	    pMsg->message == WM_SYSKEYDOWN ||
97 	    pMsg->message == WM_LBUTTONDOWN ||
98 	    pMsg->message == WM_RBUTTONDOWN ||
99 	    pMsg->message == WM_MBUTTONDOWN ||
100 	    pMsg->message == WM_NCLBUTTONDOWN ||
101 	    pMsg->message == WM_NCRBUTTONDOWN ||
102 	    pMsg->message == WM_NCMBUTTONDOWN)
103 	{
104 		c_pSplashWnd->HideSplashScreen();
105 		return TRUE;	// message handled here
106 	}
107 
108 	return FALSE;	// message not handled
109 }
110 
Create(CWnd * pParentWnd)111 BOOL CSplashWnd::Create(CWnd* pParentWnd /*= NULL*/)
112 {
113 	if (!m_bitmap.LoadBitmap(IDB_SPLASH))
114 		return FALSE;
115 
116 	BITMAP bm;
117 	m_bitmap.GetBitmap(&bm);
118 
119 	return CreateEx(0,
120 		AfxRegisterWndClass(0, AfxGetApp()->LoadStandardCursor(IDC_ARROW)),
121 		NULL, WS_POPUP | WS_VISIBLE, 0, 0, bm.bmWidth, bm.bmHeight, pParentWnd->GetSafeHwnd(), NULL);
122 }
123 
HideSplashScreen()124 void CSplashWnd::HideSplashScreen()
125 {
126 	// Destroy the window, and update the mainframe.
127 	DestroyWindow();
128 	AfxGetMainWnd()->UpdateWindow();
129 }
130 
PostNcDestroy()131 void CSplashWnd::PostNcDestroy()
132 {
133 	// Free the C++ class.
134 	delete this;
135 }
136 
OnCreate(LPCREATESTRUCT lpCreateStruct)137 int CSplashWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
138 {
139 	if (CWnd::OnCreate(lpCreateStruct) == -1)
140 		return -1;
141 
142 	// Center the window.
143 	CenterWindow();
144 
145 	// Set a timer to destroy the splash screen.
146 	SetTimer(1, 750, NULL);
147 
148 	return 0;
149 }
150 
OnPaint()151 void CSplashWnd::OnPaint()
152 {
153 	CPaintDC dc(this);
154 
155 	CDC dcImage;
156 	if (!dcImage.CreateCompatibleDC(&dc))
157 		return;
158 
159 	BITMAP bm;
160 	m_bitmap.GetBitmap(&bm);
161 
162 	// Paint the image.
163 	CBitmap* pOldBitmap = dcImage.SelectObject(&m_bitmap);
164 	dc.BitBlt(0, 0, bm.bmWidth, bm.bmHeight, &dcImage, 0, 0, SRCCOPY);
165 	dcImage.SelectObject(pOldBitmap);
166 
167 	CFont	font;
168 	CFont*	ofont;
169 	COLORREF	ocolor;
170 	int			omode;
171 	font.CreateFont(-20, 0,
172 		0, 0,								// No rotation
173 		FW_SEMIBOLD,
174 		TRUE, FALSE, FALSE,				// No Italic, Underline or Strikeout
175 		DEFAULT_CHARSET,
176 		OUT_DEFAULT_PRECIS,
177 		CLIP_DEFAULT_PRECIS,
178 		DEFAULT_QUALITY,
179 		FF_ROMAN | FF_DONTCARE,
180 		"");
181 	ofont = dc.SelectObject(&font);
182 	ocolor = dc.SetTextColor(RGB(255,0,255));
183 	omode = dc.SetBkMode(TRANSPARENT);
184 	CString cs;
185 	cs.Format("Version %s", TITLE);
186 	CSize sz = dc.GetOutputTextExtent(cs);
187 	dc.TextOut(347-(sz.cx/2), 79, cs);
188 	dc.SetTextColor(RGB(255,255,0));
189 	dc.TextOut(346-(sz.cx/2), 78, cs);
190 
191 	dc.SetTextColor(ocolor);
192 	dc.SelectObject(ofont);
193 	dc.SetBkMode(omode);
194 
195 }
196 
OnTimer(UINT nIDEvent)197 void CSplashWnd::OnTimer(UINT nIDEvent)
198 {
199 	// Destroy the splash screen window.
200 	HideSplashScreen();
201 }
202 
ShowMessage(const CString & cs)203 void CSplashWnd::ShowMessage(const CString& cs)
204 {
205 
206 	if (c_bShowSplashWnd && !c_pSplashWnd)
207 		ShowSplashScreen();
208 
209 	CDC*	dc = c_pSplashWnd->GetDC();
210 	CRect	rect;
211 	c_pSplashWnd->GetClientRect(&rect);
212 	CFont	font;
213 	CFont*	ofont;
214 	COLORREF	ocolor;
215 	int			omode;
216 	//COLORREF	oback;
217 
218 	font.CreateFont(-20, 0,
219 		0, 0,								// No rotation
220 		FW_NORMAL,
221 		FALSE, FALSE, FALSE,				// No Italic, Underline or Strikeout
222 		DEFAULT_CHARSET,
223 		OUT_DEFAULT_PRECIS,
224 		CLIP_DEFAULT_PRECIS,
225 		DEFAULT_QUALITY,
226 		FF_ROMAN | FF_DONTCARE,
227 		"");
228 	ofont = dc->SelectObject(&font);
229 	ocolor = dc->SetTextColor(RGB(255,255,255));
230 	//oback = dc->SetBkColor(RGB(0,0,0));
231 
232 	omode = dc->SetBkMode(TRANSPARENT);
233 	rect.top = rect.bottom-30;
234 	rect.left += 10;
235 	rect.right -= 10;
236 	rect.bottom -= 8;
237 #ifdef	_DEBUG
238 	dc->FillSolidRect(rect, RGB(255,0,0));
239 #else
240 	dc->FillSolidRect(rect, RGB(0,0,0));
241 #endif
242 	dc->TextOut(10, rect.bottom-24, cs);
243 
244 	dc->SetBkMode(omode);
245 	//dc->SetBkColor(oback);
246 	dc->SetTextColor(ocolor);
247 	dc->SelectObject(ofont);
248 	c_pSplashWnd->ReleaseDC(dc);
249 
250 #ifdef	_DEBUG
251 //	Sleep(1000);
252 #endif
253 }
254