RSPXBlue.cpp 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  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. #include "stdafx.h"
  21. #include "MFC_CNTL/RSPXBlue.h"
  22. #ifdef _DEBUG
  23. #define new DEBUG_NEW
  24. #undef THIS_FILE
  25. static char THIS_FILE[] = __FILE__;
  26. #endif
  27. /////////////////////////////////////////////////////////////////////////////
  28. // Jon's includes.
  29. /////////////////////////////////////////////////////////////////////////////
  30. #include "common/system.h"
  31. #include "common/wmain.h"
  32. #include "common/bdisplay.h"
  33. #include "common/bpalette.h"
  34. #include "common/wpalette.h"
  35. #include "common/bluewin.h"
  36. /////////////////////////////////////////////////////////////////////////////
  37. // CRSPiXBlue
  38. CRSPiXBlue::CRSPiXBlue()
  39. {
  40. m_pim = NULL;
  41. }
  42. CRSPiXBlue::~CRSPiXBlue()
  43. {
  44. }
  45. BEGIN_MESSAGE_MAP(CRSPiXBlue, CStatic)
  46. //{{AFX_MSG_MAP(CRSPiXBlue)
  47. ON_WM_DESTROY()
  48. ON_WM_SETFOCUS()
  49. //}}AFX_MSG_MAP
  50. END_MESSAGE_MAP()
  51. /////////////////////////////////////////////////////////////////////////////
  52. // CRSPiXBlue message handlers
  53. ///////////////////////////////////////////////////////////////////////////////
  54. //
  55. // Set the buffer Blue uses to draw and redraw the display.
  56. //
  57. ///////////////////////////////////////////////////////////////////////////////
  58. void CRSPiXBlue::SetDisplayImage(CImage* pim, short sFlip /*= FALSE*/)
  59. {
  60. ASSERT(pim != NULL);
  61. // Calculate DIB type width.
  62. long lWinWidth = pim->lPitch / ((long)pim->sDepth / 8L);
  63. Blu_SetDisplayBuf(pim->pData,
  64. lWinWidth, pim->lHeight,
  65. pim->sDepth,
  66. sFlip);
  67. Blu_SetRedrawBuf( pim->pData,
  68. lWinWidth, pim->lHeight,
  69. 0, 0, 0, 0,
  70. pim->lWidth, pim->lHeight, pim->sDepth,
  71. sFlip);
  72. ::MoveWindow(gsi.hWnd, 0, 0, pim->lWidth, pim->lHeight, TRUE);
  73. RECT rcWindow;
  74. GetWindowRect(&rcWindow);
  75. ScreenToClient(&rcWindow);
  76. RECT rcClient;
  77. GetClientRect(&rcClient);
  78. MoveWindow(0, 0, pim->lWidth - (rcClient.left - rcWindow.left),
  79. pim->lHeight - (rcClient.top - rcWindow.top));
  80. m_pim = pim;
  81. }
  82. ///////////////////////////////////////////////////////////////////////////////
  83. //
  84. // Set the palette Blue uses to draw and redraw the display.
  85. //
  86. ///////////////////////////////////////////////////////////////////////////////
  87. void CRSPiXBlue::SetDisplayPalette(CPal* ppal)
  88. {
  89. ASSERT(ppal != NULL);
  90. SetFocus();
  91. switch (ppal->ulType)
  92. {
  93. case NO_PALETTE:
  94. break;
  95. case PDIB:
  96. case PSYS:
  97. Blu_SetPalette((RGBQUAD*)ppal->pData,
  98. ppal->sStartIndex,
  99. ppal->sNumEntries);
  100. break;
  101. case P555:
  102. Blu_SetPalette((PRGBT5)ppal->pData,
  103. ppal->sStartIndex,
  104. ppal->sNumEntries);
  105. break;
  106. case P888:
  107. case PFLX:
  108. Blu_SetPalette((PRGBT8)ppal->pData,
  109. ppal->sStartIndex,
  110. ppal->sNumEntries);
  111. break;
  112. case P565:
  113. TRACE("SetDisplayPalette(): Unsupported palette type.\n");
  114. break;
  115. }
  116. }
  117. ///////////////////////////////////////////////////////////////////////////////
  118. //
  119. // On initial subclass, create the RSPiX window to the size of the parent.
  120. //
  121. ///////////////////////////////////////////////////////////////////////////////
  122. void CRSPiXBlue::PreSubclassWindow()
  123. {
  124. short sError = 0; // Assume success.
  125. // Initialize Blue . . .
  126. if (Blu_Init(AfxGetApp()->m_hInstance, m_hWnd) == 0)
  127. {
  128. RECT rcClient;
  129. GetClientRect(&rcClient);
  130. // Create a display that fills this window completely . . .
  131. if (Blu_CreateDisplay( rcClient.right, rcClient.bottom,
  132. (short)Blu_GetDisplayInfo(DI_MONITOR_COLORDEPTH))
  133. == 0)
  134. {
  135. // Success.
  136. m_wndRSPiX.Attach(gsi.hWnd);
  137. m_wndPal.Attach(Blu_GetPaletteWindow());
  138. if (m_wndPal.m_hWnd != NULL)
  139. {
  140. m_wndPal.SetParent(this);
  141. }
  142. }
  143. else
  144. {
  145. TRACE("OnCreate(): Blu_CreateDisplay() failed.\n");
  146. sError = -2;
  147. }
  148. // If we fail after initing Blue . . .
  149. if (sError != 0)
  150. {
  151. Blu_Kill();
  152. }
  153. }
  154. else
  155. {
  156. TRACE("OnCreate(): Blu_Init() failed.\n");
  157. sError = -1;
  158. }
  159. CStatic::PreSubclassWindow();
  160. }
  161. ///////////////////////////////////////////////////////////////////////////////
  162. //
  163. // When the parent is destroyed, kill Blue.
  164. //
  165. ///////////////////////////////////////////////////////////////////////////////
  166. void CRSPiXBlue::OnDestroy()
  167. {
  168. m_wndPal.Detach();
  169. m_wndRSPiX.Detach();
  170. Blu_Kill();
  171. CStatic::OnDestroy();
  172. }
  173. ///////////////////////////////////////////////////////////////////////////////
  174. //
  175. // Redraw the RSPiX Blue window.
  176. //
  177. ///////////////////////////////////////////////////////////////////////////////
  178. void CRSPiXBlue::Redraw(void)
  179. {
  180. ASSERT(m_pim != NULL);
  181. Blu_UpdateDisplay(0, 0, 0, 0, m_pim->lWidth, m_pim->lHeight);
  182. }
  183. ///////////////////////////////////////////////////////////////////////////////
  184. //
  185. // Pass focus to RSPiX.
  186. //
  187. ///////////////////////////////////////////////////////////////////////////////
  188. void CRSPiXBlue::OnSetFocus(CWnd* pOldWnd)
  189. {
  190. CStatic::OnSetFocus(pOldWnd);
  191. if (gsi.hWnd != NULL)
  192. {
  193. ::SetFocus(gsi.hWnd);
  194. }
  195. }
  196. ///////////////////////////////////////////////////////////////////////////////
  197. //
  198. // Pass through to RSPiX.
  199. //
  200. ///////////////////////////////////////////////////////////////////////////////
  201. #if 0
  202. void CRSPiXBlue::OnPaletteChanged(CWnd* pFocusWnd)
  203. {
  204. CStatic::OnPaletteChanged(pFocusWnd);
  205. if (gsi.hWnd != NULL)
  206. {
  207. ::SendMessage( gsi.hWnd, WM_PALETTECHANGED,
  208. (WPARAM)pFocusWnd->GetSafeHwnd(), 0L);
  209. }
  210. }
  211. ///////////////////////////////////////////////////////////////////////////////
  212. //
  213. // Pass through to RSPiX.
  214. //
  215. ///////////////////////////////////////////////////////////////////////////////
  216. BOOL CRSPiXBlue::OnQueryNewPalette()
  217. {
  218. BOOL bRes = TRUE;
  219. if (gsi.hWnd != NULL)
  220. {
  221. bRes = ::SendMessage( gsi.hWnd, WM_QUERYNEWPALETTE,
  222. 0L, 0L);
  223. }
  224. // Bah! Who cares what the static control returns.
  225. CStatic::OnQueryNewPalette();
  226. return bRes;
  227. }
  228. #endif
  229. ///////////////////////////////////////////////////////////////////////////////
  230. //
  231. // Returns a CWnd* to the palette window. Returns NULL if no window.
  232. //
  233. ///////////////////////////////////////////////////////////////////////////////
  234. CWnd* CRSPiXBlue::GetPaletteWindow(void)
  235. {
  236. return (m_wndPal.m_hWnd == NULL) ? NULL : &m_wndPal;
  237. }
  238. ///////////////////////////////////////////////////////////////////////////////
  239. //
  240. // Returns a CWnd* to the RSPiX window.
  241. //
  242. ///////////////////////////////////////////////////////////////////////////////
  243. CWnd* CRSPiXBlue::GetBlueWindow()
  244. {
  245. return &m_wndRSPiX;
  246. }
  247. ///////////////////////////////////////////////////////////////////////////////
  248. //
  249. // Passes messages vital to RSPiX on to the actual RSPiX window.
  250. //
  251. ///////////////////////////////////////////////////////////////////////////////
  252. LRESULT CRSPiXBlue::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
  253. {
  254. switch (message)
  255. {
  256. /////////////////////////////////////////////////////////////////////////
  257. // These messages should be passed to the Blue window.
  258. /////////////////////////////////////////////////////////////////////////
  259. //////////////////////////// Window Oriented ////////////////////////////
  260. case WM_ACTIVATEAPP:
  261. //////////////////////////// Mouse Oriented /////////////////////////////
  262. // case WM_LBUTTONDOWN: // Mouse messages should go straight there anyways.
  263. // case WM_MBUTTONDOWN:
  264. // case WM_RBUTTONDOWN:
  265. // case WM_MOUSEMOVE:
  266. // case WM_LBUTTONUP:
  267. // case WM_MBUTTONUP:
  268. // case WM_RBUTTONUP:
  269. //////////////////////////// Key Oriented ///////////////////////////////
  270. case WM_KEYDOWN:
  271. case WM_KEYUP:
  272. case WM_CHAR:
  273. //////////////////////////// Palette Oriented ///////////////////////////
  274. case WM_QUERYNEWPALETTE:
  275. case WM_PALETTECHANGED:
  276. if (gsi.hWnd != NULL)
  277. {
  278. ::SendMessage(gsi.hWnd, message, wParam, lParam);
  279. }
  280. break;
  281. }
  282. return CStatic::WindowProc(message, wParam, lParam);
  283. }