Debian Codegraph @

editor/GrWnd.cpp

raw symbols SCIP
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 --- HISTORICAL COMMENTS FOLLOW ---
19
20 * $Logfile: /DescentIII/Main/editor/GrWnd.cpp $
21 * $Revision: 1.1.1.1 $
22 * $Date: 2003-08-26 03:57:38 $
23 * $Author: kevinb $
24 *
25 * Base class of all GrWnds. Does screen and viewport allocation
26 *
27 * $Log: not supported by cvs2svn $
28 *
29 * 2 8/19/97 10:46a Samir
30 * Fixed unusual problem when for some reason during GrWnd creation, the
31 * height or width is 0, causing an error.
32 *
33 * 10 1/30/97 6:43p Samir
34 * stupid forgetting an argument
35 *
36 * 9 1/30/97 6:23p Samir
37 * Reflect changes in grScreen, where there is no viewing rect, so we blt
38 * to the entire window
39 *
40 * 8 1/21/97 12:47p Samir
41 * Added OnSize and GRWND_STYLE constant to adjust window look.
42 *
43 * $NoKeywords: $
44 */
45
46 #include "stdafx.h"
47 #include "editor.h"
48 #include "GrWnd.h"
49
50 #include <assert.h>
51
52 #include "mono.h"
53
54 #ifdef _DEBUG
55 #define new DEBUG_NEW
56 #undef THIS_FILE
57 static char THIS_FILE[] = __FILE__;
58 #endif
59
60 /////////////////////////////////////////////////////////////////////////////
61 // CGrWnd
62
63 CGrWnd::CGrWnd(const char *name) {
64 m_grScreen = NULL;
65 m_grViewport = NULL;
66 if (name)
67 strncpy(m_Name, name, 15);
68 m_Name[31] = 0;
69
70 m_Active = FALSE;
71 }
72
73 CGrWnd::~CGrWnd() {}
74
75 BEGIN_MESSAGE_MAP(CGrWnd, CWnd)
76 //{{AFX_MSG_MAP(CGrWnd)
77 ON_WM_DESTROY()
78 ON_WM_CREATE()
79 ON_WM_MOVE()
80 ON_WM_SIZE()
81 ON_WM_NCACTIVATE()
82 ON_WM_NCPAINT()
83 ON_WM_CHILDACTIVATE()
84 //}}AFX_MSG_MAP
85 END_MESSAGE_MAP()
86
87 /////////////////////////////////////////////////////////////////////////////
88 // CGrWnd message handlers
89
90 BOOL CGrWnd::PreCreateWindow(CREATESTRUCT &cs) { return CWnd::PreCreateWindow(cs); }
91
92 void CGrWnd::OnDestroy() {
93 CWnd::OnDestroy();
94
95 // TODO: Add your message handler code here
96 // destroy screen element
97 if (m_grViewport) {
98 delete m_grViewport;
99 m_grViewport = NULL;
100 }
101 if (m_grScreen) {
102 delete m_grScreen;
103 m_grScreen = NULL;
104 }
105
106 m_grCreated = FALSE;
107 }
108
109 int CGrWnd::OnCreate(LPCREATESTRUCT lpCreateStruct) {
110 if (CWnd::OnCreate(lpCreateStruct) == -1)
111 return -1;
112
113 // TODO: Add your specialized creation code here
114 // Create a screen the size of the new client area
115 RECT rect;
116 int client_width, client_height;
117
118 GetClientRect(&rect);
119 client_width = (rect.right - rect.left);
120 client_height = (rect.bottom - rect.top);
121 if (client_width && client_height) {
122 ASSERT(m_grScreen == NULL);
123 m_grScreen = new grScreen(client_width, client_height, BPP_16, m_Name);
124 m_grScreen->attach_to_window((unsigned)m_hWnd);
125 m_grViewport = new grViewport(m_grScreen);
126 }
127
128 return 0;
129 }
130
131 void CGrWnd::OnMove(int x, int y) {
132 CWnd::OnMove(x, y);
133
134 // TODO: Add your message handler code here
135 }
136
137 void CGrWnd::OnSize(UINT nType, int cx, int cy) {
138 CWnd::OnSize(nType, cx, cy);
139
140 // TODO: Add your message handler code here
141 if (m_grViewport) {
142 delete m_grViewport;
143 delete m_grScreen;
144 m_grViewport = NULL;
145 m_grScreen = NULL;
146 }
147 if (cx && cy && !m_grViewport) {
148 RECT rect;
149 int client_width, client_height;
150
151 GetClientRect(&rect);
152 client_width = (rect.right - rect.left);
153 client_height = (rect.bottom - rect.top);
154
155 m_grScreen = new grScreen(client_width, client_height, BPP_16, m_Name);
156 m_grScreen->attach_to_window((unsigned)m_hWnd);
157 m_grViewport = new grViewport(m_grScreen);
158 }
159 }
160
161 // ---------------------------------------------------------------------------
162 // private functions
163 // ---------------------------------------------------------------------------
164
165 void CGrWnd::DrawCaption(BOOL active) {
166 CDC *dc;
167 DWORD dwstyle;
168 RECT winrect, caprect;
169 int c_left = 0, c_top = 0; // caption bar's coordinates in window
170
171 // get needed info
172 GetWindowRect(&winrect);
173 dwstyle = GetStyle();
174 if ((dwstyle & WS_CAPTION) != WS_CAPTION)
175 return;
176 dc = GetWindowDC();
177
178 // calculate c_left, c_top
179 if (dwstyle & WS_THICKFRAME) {
180 c_left += GetSystemMetrics(SM_CXSIZEFRAME);
181 c_top += GetSystemMetrics(SM_CYSIZEFRAME);
182 }
183 if (dwstyle & WS_SYSMENU) {
184 c_left += GetSystemMetrics(SM_CXSIZE);
185 }
186 caprect.left = c_left;
187 caprect.top = c_top;
188
189 // calucation c_right, c_bottom.
190 caprect.right = winrect.right - winrect.left - (2 * c_left);
191 if (dwstyle & WS_THICKFRAME) {
192 caprect.right -= GetSystemMetrics(SM_CXSIZEFRAME);
193 }
194 caprect.bottom = GetSystemMetrics(SM_CYSIZE);
195
196 if (active) {
197 dc->SetBkColor(GetSysColor(COLOR_ACTIVECAPTION));
198 dc->SetTextColor(GetSysColor(COLOR_CAPTIONTEXT));
199 } else {
200 dc->SetBkColor(GetSysColor(COLOR_INACTIVECAPTION));
201 dc->SetTextColor(GetSysColor(COLOR_INACTIVECAPTIONTEXT));
202 }
203
204 dc->DrawText(m_Name, -1, &caprect, DT_LEFT);
205
206 ReleaseDC(dc);
207 }
208
209 BOOL CGrWnd::OnNcActivate(BOOL bActive) {
210 CWnd::OnNcActivate(bActive);
211
212 /* m_Active = bActive;
213
214 OnNcPaint();
215 */
216 return TRUE;
217 }
218
219 void CGrWnd::OnNcPaint() {
220 CWnd::OnNcPaint(); // We may have to do this.
221 // DrawCaption(m_Active);
222 }
223
224 void CGrWnd::OnChildActivate() { CWnd::OnChildActivate(); }