Debian Codegraph @

RSPiX/Src/ORANGE/MFC_Cntl/RSPXBlue.cpp

raw
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright 2016 RWS Inc, All Rights Reserved
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of version 2 of the GNU General Public License as published by
7 // the Free Software Foundation
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License along
15 // with this program; if not, write to the Free Software Foundation, Inc.,
16 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 //
18 // RSPiXBlue.cpp : implementation file
19 //
20
21 #include "stdafx.h"
22 #include "MFC_CNTL/RSPXBlue.h"
23
24 #ifdef _DEBUG
25 #define new DEBUG_NEW
26 #undef THIS_FILE
27 static char THIS_FILE[] = __FILE__;
28 #endif
29
30 /////////////////////////////////////////////////////////////////////////////
31 // Jon's includes.
32 /////////////////////////////////////////////////////////////////////////////
33 #include "common/system.h"
34 #include "common/wmain.h"
35 #include "common/bdisplay.h"
36 #include "common/bpalette.h"
37 #include "common/wpalette.h"
38 #include "common/bluewin.h"
39
40 /////////////////////////////////////////////////////////////////////////////
41 // CRSPiXBlue
42
43 CRSPiXBlue::CRSPiXBlue()
44 {
45 m_pim = NULL;
46 }
47
48 CRSPiXBlue::~CRSPiXBlue()
49 {
50 }
51
52
53 BEGIN_MESSAGE_MAP(CRSPiXBlue, CStatic)
54 //{{AFX_MSG_MAP(CRSPiXBlue)
55 ON_WM_DESTROY()
56 ON_WM_SETFOCUS()
57 //}}AFX_MSG_MAP
58 END_MESSAGE_MAP()
59
60 /////////////////////////////////////////////////////////////////////////////
61 // CRSPiXBlue message handlers
62
63 ///////////////////////////////////////////////////////////////////////////////
64 //
65 // Set the buffer Blue uses to draw and redraw the display.
66 //
67 ///////////////////////////////////////////////////////////////////////////////
68 void CRSPiXBlue::SetDisplayImage(CImage* pim, int16_t sFlip /*= FALSE*/)
69 {
70 ASSERT(pim != NULL);
71
72 // Calculate DIB type width.
73 int32_t lWinWidth = pim->lPitch / ((int32_t)pim->sDepth / 8L);
74
75 Blu_SetDisplayBuf(pim->pData,
76 lWinWidth, pim->lHeight,
77 pim->sDepth,
78 sFlip);
79
80 Blu_SetRedrawBuf( pim->pData,
81 lWinWidth, pim->lHeight,
82 0, 0, 0, 0,
83 pim->lWidth, pim->lHeight, pim->sDepth,
84 sFlip);
85
86 ::MoveWindow(gsi.hWnd, 0, 0, pim->lWidth, pim->lHeight, TRUE);
87
88 RECT rcWindow;
89 GetWindowRect(&rcWindow);
90 ScreenToClient(&rcWindow);
91 RECT rcClient;
92 GetClientRect(&rcClient);
93
94 MoveWindow(0, 0, pim->lWidth - (rcClient.left - rcWindow.left),
95 pim->lHeight - (rcClient.top - rcWindow.top));
96
97 m_pim = pim;
98 }
99
100 ///////////////////////////////////////////////////////////////////////////////
101 //
102 // Set the palette Blue uses to draw and redraw the display.
103 //
104 ///////////////////////////////////////////////////////////////////////////////
105 void CRSPiXBlue::SetDisplayPalette(CPal* ppal)
106 {
107 ASSERT(ppal != NULL);
108
109 SetFocus();
110
111 switch (ppal->ulType)
112 {
113 case NO_PALETTE:
114 break;
115 case PDIB:
116 case PSYS:
117 Blu_SetPalette((RGBQUAD*)ppal->pData,
118 ppal->sStartIndex,
119 ppal->sNumEntries);
120 break;
121 case P555:
122 Blu_SetPalette((PRGBT5)ppal->pData,
123 ppal->sStartIndex,
124 ppal->sNumEntries);
125 break;
126 case P888:
127 case PFLX:
128 Blu_SetPalette((PRGBT8)ppal->pData,
129 ppal->sStartIndex,
130 ppal->sNumEntries);
131 break;
132 case P565:
133 TRACE("SetDisplayPalette(): Unsupported palette type.\n");
134 break;
135 }
136 }
137
138 ///////////////////////////////////////////////////////////////////////////////
139 //
140 // On initial subclass, create the RSPiX window to the size of the parent.
141 //
142 ///////////////////////////////////////////////////////////////////////////////
143 void CRSPiXBlue::PreSubclassWindow()
144 {
145 int16_t sError = 0; // Assume success.
146
147 // Initialize Blue . . .
148 if (Blu_Init(AfxGetApp()->m_hInstance, m_hWnd) == 0)
149 {
150 RECT rcClient;
151 GetClientRect(&rcClient);
152
153 // Create a display that fills this window completely . . .
154 if (Blu_CreateDisplay( rcClient.right, rcClient.bottom,
155 (int16_t)Blu_GetDisplayInfo(DI_MONITOR_COLORDEPTH))
156 == 0)
157 {
158 // Success.
159 m_wndRSPiX.Attach(gsi.hWnd);
160
161 m_wndPal.Attach(Blu_GetPaletteWindow());
162
163 if (m_wndPal.m_hWnd != NULL)
164 {
165 m_wndPal.SetParent(this);
166 }
167 }
168 else
169 {
170 TRACE("OnCreate(): Blu_CreateDisplay() failed.\n");
171 sError = -2;
172 }
173
174 // If we fail after initing Blue . . .
175 if (sError != 0)
176 {
177 Blu_Kill();
178 }
179 }
180 else
181 {
182 TRACE("OnCreate(): Blu_Init() failed.\n");
183 sError = -1;
184 }
185
186 CStatic::PreSubclassWindow();
187 }
188
189 ///////////////////////////////////////////////////////////////////////////////
190 //
191 // When the parent is destroyed, kill Blue.
192 //
193 ///////////////////////////////////////////////////////////////////////////////
194 void CRSPiXBlue::OnDestroy()
195 {
196 m_wndPal.Detach();
197
198 m_wndRSPiX.Detach();
199
200 Blu_Kill();
201
202 CStatic::OnDestroy();
203 }
204
205 ///////////////////////////////////////////////////////////////////////////////
206 //
207 // Redraw the RSPiX Blue window.
208 //
209 ///////////////////////////////////////////////////////////////////////////////
210 void CRSPiXBlue::Redraw(void)
211 {
212 ASSERT(m_pim != NULL);
213
214 Blu_UpdateDisplay(0, 0, 0, 0, m_pim->lWidth, m_pim->lHeight);
215 }
216
217
218 ///////////////////////////////////////////////////////////////////////////////
219 //
220 // Pass focus to RSPiX.
221 //
222 ///////////////////////////////////////////////////////////////////////////////
223 void CRSPiXBlue::OnSetFocus(CWnd* pOldWnd)
224 {
225 CStatic::OnSetFocus(pOldWnd);
226
227 if (gsi.hWnd != NULL)
228 {
229 ::SetFocus(gsi.hWnd);
230 }
231 }
232
233 ///////////////////////////////////////////////////////////////////////////////
234 //
235 // Pass through to RSPiX.
236 //
237 ///////////////////////////////////////////////////////////////////////////////
238 #if 0
239 void CRSPiXBlue::OnPaletteChanged(CWnd* pFocusWnd)
240 {
241 CStatic::OnPaletteChanged(pFocusWnd);
242
243 if (gsi.hWnd != NULL)
244 {
245 ::SendMessage( gsi.hWnd, WM_PALETTECHANGED,
246 (WPARAM)pFocusWnd->GetSafeHwnd(), 0L);
247 }
248 }
249
250 ///////////////////////////////////////////////////////////////////////////////
251 //
252 // Pass through to RSPiX.
253 //
254 ///////////////////////////////////////////////////////////////////////////////
255 BOOL CRSPiXBlue::OnQueryNewPalette()
256 {
257 BOOL bRes = TRUE;
258
259 if (gsi.hWnd != NULL)
260 {
261 bRes = ::SendMessage( gsi.hWnd, WM_QUERYNEWPALETTE,
262 0L, 0L);
263 }
264
265 // Bah! Who cares what the static control returns.
266 CStatic::OnQueryNewPalette();
267
268 return bRes;
269 }
270 #endif
271
272 ///////////////////////////////////////////////////////////////////////////////
273 //
274 // Returns a CWnd* to the palette window. Returns NULL if no window.
275 //
276 ///////////////////////////////////////////////////////////////////////////////
277 CWnd* CRSPiXBlue::GetPaletteWindow(void)
278 {
279 return (m_wndPal.m_hWnd == NULL) ? NULL : &m_wndPal;
280 }
281
282 ///////////////////////////////////////////////////////////////////////////////
283 //
284 // Returns a CWnd* to the RSPiX window.
285 //
286 ///////////////////////////////////////////////////////////////////////////////
287 CWnd* CRSPiXBlue::GetBlueWindow()
288 {
289 return &m_wndRSPiX;
290 }
291
292 ///////////////////////////////////////////////////////////////////////////////
293 //
294 // Passes messages vital to RSPiX on to the actual RSPiX window.
295 //
296 ///////////////////////////////////////////////////////////////////////////////
297 LRESULT CRSPiXBlue::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
298 {
299 switch (message)
300 {
301 /////////////////////////////////////////////////////////////////////////
302 // These messages should be passed to the Blue window.
303 /////////////////////////////////////////////////////////////////////////
304
305 //////////////////////////// Window Oriented ////////////////////////////
306 case WM_ACTIVATEAPP:
307 //////////////////////////// Mouse Oriented /////////////////////////////
308 // case WM_LBUTTONDOWN: // Mouse messages should go straight there anyways.
309 // case WM_MBUTTONDOWN:
310 // case WM_RBUTTONDOWN:
311 // case WM_MOUSEMOVE:
312 // case WM_LBUTTONUP:
313 // case WM_MBUTTONUP:
314 // case WM_RBUTTONUP:
315 //////////////////////////// Key Oriented ///////////////////////////////
316 case WM_KEYDOWN:
317 case WM_KEYUP:
318 case WM_CHAR:
319 //////////////////////////// Palette Oriented ///////////////////////////
320 case WM_QUERYNEWPALETTE:
321 case WM_PALETTECHANGED:
322 if (gsi.hWnd != NULL)
323 {
324 ::SendMessage(gsi.hWnd, message, wParam, lParam);
325 }
326 break;
327 }
328
329 return CStatic::WindowProc(message, wParam, lParam);
330 }