1 /* $Id: winAbout.cpp,v 5.2 2002/06/15 21:35:22 dik Exp $
2  * winAbout.cpp - XPilot.exe credits box
3  *
4  * This file contains the Windows about dialog and scrolling credits box.
5  *
6  * XPilot, a multiplayer gravity war game.  Copyright (C) 1991-2001 by
7  *
8  *      Bj�rn Stabell        <bjoern@xpilot.org>
9  *      Ken Ronny Schouten   <ken@xpilot.org>
10  *      Bert Gijsbers        <bert@xpilot.org>
11  *      Dick Balaska         <dick@xpilot.org>
12  *
13  * This program is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by
15  * the Free Software Foundation; either version 2 of the License, or
16  * (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software
25  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26  */
27 /*
28  * $Log: winAbout.cpp,v $
29  * Revision 5.2  2002/06/15 21:35:22  dik
30  * Don't include includes if the symbols were already defined
31  * (winAbout may be included from XPwho).
32  *
33  */
34 
35 #include "StdAfx.h"
36 #ifndef	DRAW_H
37 	#include "draw.h"
38 #endif
39 #ifndef	_WINX__H_
40 	#include "winX_.h"
41 	#include "resource.h"
42 #endif
43 #include "winAbout.h"
44 #include "../../common/version.h"
45 
46 /////////////////////////////////////////////////////////////////////////////
47 
48 #define	CR_WIDTH	crRect.Width()
49 //#define	CR_HEIGHT	2500
50 #define	LINEHEIGHT	19
51 
52 // read in from credits.inc.h
53 CString credits;
54 int		creditsHeight = 0;
55 int		lineCount = 0;
56 
CAboutDlg()57 CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
58 {
59 	//{{AFX_DATA_INIT(CAboutDlg)
60 	//}}AFX_DATA_INIT
61 
62 }
63 
DoDataExchange(CDataExchange * pDX)64 void CAboutDlg::DoDataExchange(CDataExchange* pDX)
65 {
66 	CDialog::DoDataExchange(pDX);
67 	//{{AFX_DATA_MAP(CAboutDlg)
68 	DDX_Control(pDX, IDC_CREDITS, m_credits);
69 	//}}AFX_DATA_MAP
70 }
71 
BEGIN_MESSAGE_MAP(CAboutDlg,CDialog)72 BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
73 	//{{AFX_MSG_MAP(CAboutDlg)
74 	//}}AFX_MSG_MAP
75 END_MESSAGE_MAP()
76 
77 /////////////////////////////////////////////////////////////////////////////
78 // CCredits
79 
80 CCredits::CCredits()
81 {
82 	scrollofs = 0;
83 	timer = FALSE;
84 	virgin = TRUE;
85 }
86 
~CCredits()87 CCredits::~CCredits()
88 {
89 #if 0
90 	CString e;
91 	e.Format("scrollofs = %d", scrollofs);
92 	AfxMessageBox(e);
93 #endif
94 }
95 
96 
BEGIN_MESSAGE_MAP(CCredits,CStatic)97 BEGIN_MESSAGE_MAP(CCredits, CStatic)
98 	//{{AFX_MSG_MAP(CCredits)
99 	ON_WM_PAINT()
100 	ON_WM_TIMER()
101 	//}}AFX_MSG_MAP
102 END_MESSAGE_MAP()
103 
104 ///////////////////////////////////////////////////////////////////////////////
105 // CCredits message handlers
106 void CCredits::OnTimer(UINT nIDEvent)
107 {
108 	// TODO: Add your message handler code here and/or call default
109 	if (scrollofs++ > creditsHeight)
110 		scrollofs = 0;
111 	TRACE("scrollofs = %d\n", scrollofs);
112 	CRect	rect;
113 	GetClientRect(&rect);
114 	InvalidateRect(&rect, FALSE);
115 	CStatic::OnTimer(nIDEvent);
116 }
117 
118 ///////////////////////////////////////////////////////////////////////////////
OnPaint()119 void CCredits::OnPaint()
120 {
121 	CPaintDC dc(this); // device context for painting
122 	CString	out;
123 //	int		i;
124 	int		line = 0;
125 
126 	// TODO: Add your message handler code here
127 	//CFont*	oldFont = dc.SelectObject(&font);
128 	GetClientRect(&crRect);
129 
130 	if (virgin)
131 	{
132 		// create the credits bitmap
133 		CDC	bdc;
134 		//CDC* wdc;
135 
136 		virgin = FALSE;
137 		//wdc = GetDC();
138 		bdc.CreateCompatibleDC(&dc);
139 		creditsHeight = lineCount*LINEHEIGHT+crRect.Height();
140 		bm.CreateCompatibleBitmap(&bdc, CR_WIDTH, creditsHeight);
141 
142 		CBitmap* oldbm = bdc.SelectObject(&bm);
143 		BuildBitmap(&bdc);
144 		bdc.SelectObject(oldbm);
145 		//ReleaseDC(wdc);
146 	}
147 	if (!timer)
148 		SetTimer(32, 30, NULL);
149 	timer = TRUE;
150 
151 	CDC		bdc;
152 	bdc.CreateCompatibleDC(&dc);
153 	CBitmap* obm = bdc.SelectObject(&bm);
154 	dc.BitBlt(0, 0, crRect.Width(), crRect.Height(), &bdc, 0, scrollofs, SRCCOPY);
155 	// dc.SelectObject(obm);
156 	// Do not call CStatic::OnPaint() for painting messages
157 	bdc.SelectObject(obm);
158 	//ReleaseDC(&bdc);
159 	//dc.SelectObject(oldFont);
160 }
161 
162 
163 ///////////////////////////////////////////////////////////////////////////////
Create(LPCTSTR lpszClassName,LPCTSTR lpszWindowName,DWORD dwStyle,const RECT & rect,CWnd * pParentWnd,UINT nID,CCreateContext * pContext)164 BOOL CCredits::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext)
165 {
166 	// TODO: Add your specialized code here and/or call the base class
167 	BOOL ret;
168 	ret = CWnd::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext);
169 	return(ret);
170 }
171 
172 ///////////////////////////////////////////////////////////////////////////////
DestroyWindow()173 BOOL CCredits::DestroyWindow()
174 {
175 	// TODO: Add your specialized code here and/or call the base class
176 	KillTimer(32);
177 	bm.DeleteObject();
178 
179 
180 	return CStatic::DestroyWindow();
181 }
182 
183 ///////////////////////////////////////////////////////////////////////////////
GetAnInt(int * i)184 int	GetAnInt(int* i)
185 {
186 	int		x;
187 	char	a;
188 
189 	(*i)++;		// skip control
190 	a = credits[*i];	// get char
191 	(*i)++;
192 	x = a & 0x0F;
193 	a = credits[*i];
194 	(*i)++;
195 	x = (x * 10) + (a & 0x0F);
196 	a = credits[*i];
197 	(*i)++;
198 	x = (x * 10) + (a & 0x0F);
199 	return(x);
200 }
201 
202 ///////////////////////////////////////////////////////////////////////////////
BuildBitmap(CDC * dc)203 void CCredits::BuildBitmap(CDC *dc)
204 {
205 	int		row = 0;
206 	int		col = 0;
207 	int		i = 0;
208 	CString	cs;
209 	int		rowinc = LINEHEIGHT;
210 	int		colinc = 10;
211 	COLORREF	myColor;
212 
213 	CRect	rect(0,0,CR_WIDTH, creditsHeight);
214 //	dc->FillSolidRect(&rect, objs[RED].color);
215 	COLORREF oldColor = dc->GetTextColor();
216 	dc->SetBkColor(RGB(0,0,0));
217 	myColor = RGB(255,255,255);
218 
219 	LOGFONT	lf;
220 	memset(&lf, 0, sizeof(LOGFONT));
221 	lf.lfHeight = -(CR_WIDTH / 42);
222 	lf.lfPitchAndFamily = FF_SWISS;
223 #if 0
224 	CString e;
225 	e.Format("Rect w=%d h=%d lfHeight=%d", crRect.Width(), crRect.Height(),
226 		lf.lfHeight);
227 	AfxMessageBox(e);
228 #endif
229 	haveFont = font.CreateFontIndirect(&lf);
230 	CFont*	oldfont = dc->SelectObject(&font);
231 //	myColor = objs[RED].color;
232 
233 	for (i=0; i<credits.GetLength();)
234 	{
235 		if (credits[i] == '#')
236 		{
237 			if (cs.GetLength())			// anything in the buffer?
238 			{							// yes, flush it
239 				TRACE("color=%08x cs=%s\n", myColor, (PCSTR)cs);
240 				dc->SetTextColor(myColor);
241 				dc->TextOut(col*10+2, row*LINEHEIGHT + crRect.Height(), cs);
242 				cs = "";
243 			}
244 			switch(credits[++i])
245 			{
246 			case 'r':
247 				row = row + GetAnInt(&i);
248 				col = 0;
249 //				myColor = objs[RED].color;
250 				myColor = RGB(255,0,0);
251 				break;
252 			case 'c':
253 				col = GetAnInt(&i);
254 //				myColor = objs[WHITE].color;
255 				break;
256 			default:
257 				AfxMessageBox("Unknown command in credits");
258 				break;
259 			}
260 		}
261 		else
262 		{
263 			cs += credits[i++];
264 		}
265 	}
266 	dc->SetTextColor(oldColor);
267 	dc->SelectObject(oldfont);
268 	font.DeleteObject();
269 }
270 
OnInitDialog()271 BOOL CAboutDlg::OnInitDialog()
272 {
273 	CDialog::OnInitDialog();
274 
275 	SendDlgItemMessage(IDC_VERSION, WM_SETTEXT, 0, (LPARAM)("XPilot " TITLE));
276 
277 #include "credits.inc.h"
278 
279 	return TRUE;  // return TRUE unless you set the focus to a control
280 	              // EXCEPTION: OCX Property Pages should return FALSE
281 }
282