| 1 | /* |
| 2 | * Descent 3 |
| 3 | * Copyright (C) 2024 Parallax Software |
| 4 | * |
| 5 | * This program is free software: you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation, either version 3 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | */ |
| 18 | |
| 19 | // D3Splash.cpp : implementation file |
| 20 | // |
| 21 | |
| 22 | #include "stdafx.h" |
| 23 | #include "editor.h" |
| 24 | #include "D3Splash.h" |
| 25 | |
| 26 | #include <stdarg.h> |
| 27 | |
| 28 | #ifdef _DEBUG |
| 29 | #define new DEBUG_NEW |
| 30 | #undef THIS_FILE |
| 31 | static char THIS_FILE[] = __FILE__; |
| 32 | #endif |
| 33 | |
| 34 | const int SPLASHTEXT_LEFT = 10; |
| 35 | const int SPLASHTEXT_TOP = 180; |
| 36 | const int SPLASHTEXT_RIGHT = 310; |
| 37 | const int SPLASHTEXT_BOTTOM = 230; |
| 38 | |
| 39 | CD3Splash *D3_splash_screen; |
| 40 | |
| 41 | ///////////////////////////////////////////////////////////////////////////// |
| 42 | // CD3Splash dialog |
| 43 | |
| 44 | CD3Splash::CD3Splash(CWnd *pParent /*=NULL*/) : CDialog(CD3Splash::IDD, pParent) { |
| 45 | //{{AFX_DATA_INIT(CD3Splash) |
| 46 | // NOTE: the ClassWizard will add member initialization here |
| 47 | //}}AFX_DATA_INIT |
| 48 | |
| 49 | m_ParentWnd = pParent; |
| 50 | } |
| 51 | |
| 52 | void CD3Splash::DoDataExchange(CDataExchange *pDX) { |
| 53 | CDialog::DoDataExchange(pDX); |
| 54 | //{{AFX_DATA_MAP(CD3Splash) |
| 55 | // NOTE: the ClassWizard will add DDX and DDV calls here |
| 56 | //}}AFX_DATA_MAP |
| 57 | } |
| 58 | |
| 59 | BOOL CD3Splash::Create() { |
| 60 | m_TextLines[0][0] = 0; |
| 61 | m_TextLines[1][0] = 0; |
| 62 | m_TextLines[2][0] = 0; |
| 63 | m_CurLine = 0; |
| 64 | |
| 65 | D3_splash_screen = this; |
| 66 | |
| 67 | m_SplashBmp.LoadBitmap(IDB_D3SPLASH); |
| 68 | |
| 69 | return CDialog::Create(CD3Splash::IDD, m_ParentWnd); |
| 70 | } |
| 71 | |
| 72 | void CD3Splash::PutText(char *buf) { |
| 73 | RECT rect; |
| 74 | |
| 75 | if (m_CurLine == 3) { |
| 76 | for (int i = 0; i < 2; i++) |
| 77 | lstrcpy(&m_TextLines[i][0], &m_TextLines[i + 1][0]); |
| 78 | } else |
| 79 | m_CurLine++; |
| 80 | |
| 81 | lstrcpy(&m_TextLines[m_CurLine - 1][0], buf); |
| 82 | |
| 83 | // mprintf(1, "%d:%s",m_CurLine-1, m_TextLines[m_CurLine-1]); |
| 84 | |
| 85 | SetRect(&rect, SPLASHTEXT_LEFT, SPLASHTEXT_TOP, SPLASHTEXT_RIGHT, SPLASHTEXT_BOTTOM); |
| 86 | InvalidateRect(&rect, FALSE); |
| 87 | UpdateWindow(); |
| 88 | } |
| 89 | |
| 90 | BEGIN_MESSAGE_MAP(CD3Splash, CDialog) |
| 91 | //{{AFX_MSG_MAP(CD3Splash) |
| 92 | ON_WM_PAINT() |
| 93 | ON_WM_DESTROY() |
| 94 | //}}AFX_MSG_MAP |
| 95 | END_MESSAGE_MAP() |
| 96 | |
| 97 | ///////////////////////////////////////////////////////////////////////////// |
| 98 | // CD3Splash message handlers |
| 99 | |
| 100 | void CD3Splash::OnCancel() { |
| 101 | // Absolutely nothing |
| 102 | } |
| 103 | |
| 104 | void CD3Splash::OnOK() { |
| 105 | // Absolutely nothing |
| 106 | } |
| 107 | |
| 108 | void CD3Splash::PostNcDestroy() { |
| 109 | // needed for modeless dialogs |
| 110 | delete this; |
| 111 | } |
| 112 | |
| 113 | void CD3Splash::OnPaint() { |
| 114 | CPaintDC dc(this); // device context for painting |
| 115 | CDC sdc; // source dc |
| 116 | CBitmap *bmp; |
| 117 | CFont *fnt; |
| 118 | CSize textdim; |
| 119 | BITMAP bm; |
| 120 | RECT uprect; |
| 121 | int x, y; |
| 122 | |
| 123 | GetClientRect(&uprect); |
| 124 | |
| 125 | m_SplashBmp.GetObject(sizeof(bm), &bm); |
| 126 | |
| 127 | sdc.CreateCompatibleDC(NULL); |
| 128 | bmp = sdc.SelectObject(&m_SplashBmp); |
| 129 | dc.StretchBlt(uprect.left + 1, uprect.top + 1, uprect.right - uprect.left - 2, uprect.bottom - uprect.top - 2, &sdc, |
| 130 | 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY); |
| 131 | sdc.SelectObject(bmp); |
| 132 | |
| 133 | fnt = dc.SelectObject(GetFont()); |
| 134 | dc.SetBkMode(TRANSPARENT); |
| 135 | dc.SetTextColor(RGB(255, 255, 255)); |
| 136 | |
| 137 | textdim = dc.GetTextExtent(&m_TextLines[0][0], lstrlen(m_TextLines[0])); |
| 138 | |
| 139 | y = uprect.bottom - (4 * (textdim.cy + 2)); |
| 140 | |
| 141 | for (int r = 0; r < 3; r++) { |
| 142 | if (lstrlen(m_TextLines[r])) { |
| 143 | textdim = dc.GetTextExtent(&m_TextLines[r][0], lstrlen(m_TextLines[r])); |
| 144 | x = ((uprect.right - uprect.left) - textdim.cx) / 2; |
| 145 | dc.TextOut(x, y, &m_TextLines[r][0], lstrlen(m_TextLines[r])); |
| 146 | y += textdim.cy + 2; |
| 147 | } |
| 148 | } |
| 149 | dc.SelectObject(fnt); |
| 150 | } |
| 151 | |
| 152 | void CD3Splash::OnDestroy() { |
| 153 | CDialog::OnDestroy(); |
| 154 | |
| 155 | D3_splash_screen = NULL; |
| 156 | } |