00001 // $Id: palman.cpp 1282 2006-06-09 09:46:49Z alex $ 00002 /* @@tag:xara-cn@@ DO NOT MODIFY THIS LINE 00003 ================================XARAHEADERSTART=========================== 00004 00005 Xara LX, a vector drawing and manipulation program. 00006 Copyright (C) 1993-2006 Xara Group Ltd. 00007 Copyright on certain contributions may be held in joint with their 00008 respective authors. See AUTHORS file for details. 00009 00010 LICENSE TO USE AND MODIFY SOFTWARE 00011 ---------------------------------- 00012 00013 This file is part of Xara LX. 00014 00015 Xara LX is free software; you can redistribute it and/or modify it 00016 under the terms of the GNU General Public License version 2 as published 00017 by the Free Software Foundation. 00018 00019 Xara LX and its component source files are distributed in the hope 00020 that it will be useful, but WITHOUT ANY WARRANTY; without even the 00021 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00022 See the GNU General Public License for more details. 00023 00024 You should have received a copy of the GNU General Public License along 00025 with Xara LX (see the file GPL in the root directory of the 00026 distribution); if not, write to the Free Software Foundation, Inc., 51 00027 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00028 00029 00030 ADDITIONAL RIGHTS 00031 ----------------- 00032 00033 Conditional upon your continuing compliance with the GNU General Public 00034 License described above, Xara Group Ltd grants to you certain additional 00035 rights. 00036 00037 The additional rights are to use, modify, and distribute the software 00038 together with the wxWidgets library, the wxXtra library, and the "CDraw" 00039 library and any other such library that any version of Xara LX relased 00040 by Xara Group Ltd requires in order to compile and execute, including 00041 the static linking of that library to XaraLX. In the case of the 00042 "CDraw" library, you may satisfy obligation under the GNU General Public 00043 License to provide source code by providing a binary copy of the library 00044 concerned and a copy of the license accompanying it. 00045 00046 Nothing in this section restricts any of the rights you have under 00047 the GNU General Public License. 00048 00049 00050 SCOPE OF LICENSE 00051 ---------------- 00052 00053 This license applies to this program (XaraLX) and its constituent source 00054 files only, and does not necessarily apply to other Xara products which may 00055 in part share the same code base, and are subject to their own licensing 00056 terms. 00057 00058 This license does not apply to files in the wxXtra directory, which 00059 are built into a separate library, and are subject to the wxWindows 00060 license contained within that directory in the file "WXXTRA-LICENSE". 00061 00062 This license does not apply to the binary libraries (if any) within 00063 the "libs" directory, which are subject to a separate license contained 00064 within that directory in the file "LIBS-LICENSE". 00065 00066 00067 ARRANGEMENTS FOR CONTRIBUTION OF MODIFICATIONS 00068 ---------------------------------------------- 00069 00070 Subject to the terms of the GNU Public License (see above), you are 00071 free to do whatever you like with your modifications. However, you may 00072 (at your option) wish contribute them to Xara's source tree. You can 00073 find details of how to do this at: 00074 http://www.xaraxtreme.org/developers/ 00075 00076 Prior to contributing your modifications, you will need to complete our 00077 contributor agreement. This can be found at: 00078 http://www.xaraxtreme.org/developers/contribute/ 00079 00080 Please note that Xara will not accept modifications which modify any of 00081 the text between the start and end of this header (marked 00082 XARAHEADERSTART and XARAHEADEREND). 00083 00084 00085 MARKS 00086 ----- 00087 00088 Xara, Xara LX, Xara X, Xara X/Xtreme, Xara Xtreme, the Xtreme and Xara 00089 designs are registered or unregistered trademarks, design-marks, and/or 00090 service marks of Xara Group Ltd. All rights in these marks are reserved. 00091 00092 00093 Xara Group Ltd, Gaddesden Place, Hemel Hempstead, HP2 6EX, UK. 00094 http://www.xara.com/ 00095 00096 =================================XARAHEADEREND============================ 00097 */ 00098 // palman.cpp - a centralised screen palette manager 00099 00100 /* 00101 */ 00102 00103 #include "camtypes.h" 00104 00105 //#include "document.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00106 //#include "docview.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00107 #include "grndrgn.h" 00108 //GAT #include "mainfrm.h" 00109 #include "palman.h" 00110 //GAT #include "dlgbar.h" 00111 //GAT #include "ccolbar.h" 00112 #include "rendwnd.h" 00113 //#include "fixmem.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00114 //#include "dibutil.h" // for identity palette - in camtypes.h [AUTOMATICALLY REMOVED] 00115 //GAT #include "bitbutn.h" // for WM_CAM_PALETTECHANGE 00116 #ifdef RALPH 00117 #include "ralphdoc.h" // For foreground / background forcing... 00118 #endif 00119 00120 BOOL PaletteManager::m_fPaletteLocked = FALSE; 00121 BOOL PaletteManager::sm_bUseMainPalette = FALSE; 00122 wxPalette PaletteManager::sm_MainPalette; 00123 00124 //#define DEBUG_PALMAN 1 00125 00126 /******************************************************************************************** 00127 00128 > static BOOL PaletteManager::Init(void) 00129 00130 Author: Gerry_Iles (Xara Group Ltd) <camelotdev@xara.com> 00131 Created: 28/6/96 00132 00133 Purpose: Initialises the palette manager 00134 00135 SeeAlso: PaletteManager::UpdatePalette 00136 00137 ********************************************************************************************/ 00138 00139 BOOL PaletteManager::Init(void) 00140 { 00141 #if DEBUG_PALMAN 00142 TRACE( _T("BOOL PaletteManager::Init(void)\n")); 00143 #endif 00144 UpdatePalette(); 00145 00146 return(TRUE); 00147 } 00148 00149 00150 /******************************************************************************************** 00151 00152 > static void PaletteManager::LockPalette(BOOL fLocked) 00153 00154 Author: Justin_Flude (Xara Group Ltd) <camelotdev@xara.com> 00155 Created: 16/10/95 00156 Inputs: fLocked if TRUE, lock the palette, if FALSE, unlock it. 00157 00158 Purpose: "Locks" or "unlocks" the palette, preventing or allowing palette changes 00159 due to window repaints. Ultra-bodge way of preventing splash-box palette 00160 flash during workspace restoration. 00161 00162 Notes: This bodge has been toned down (Jason). It now does not stop us realizing 00163 palettes (which is a big big big no-no) but instead forces us to background 00164 palette realization so that it does not affect the physical screen palette. 00165 00166 SeeAlso: PaletteManager::IsRedrawOnPaletteChangeRequired 00167 00168 ********************************************************************************************/ 00169 00170 void PaletteManager::LockPalette(BOOL fLocked) 00171 { 00172 #if DEBUG_PALMAN 00173 TRACE( _T("void PaletteManager::LockPalette(BOOL fLocked = %d)\n"), fLocked); 00174 #endif 00175 m_fPaletteLocked = fLocked; 00176 } 00177 00178 00179 00180 /******************************************************************************************** 00181 00182 > static BOOL CALLBACK PaletteManager::InvalidateChildProc(HWND hWnd, LPARAM lParam) 00183 00184 Author: Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> 00185 Created: 26/5/95 00186 00187 Inputs: hWnd - the window to invalidate 00188 lParam - unused 00189 00190 Returns: TRUE (success) 00191 00192 Purpose: A callback proc to invalidate child windows if they need to be redrawn 00193 as a result of a palette change 00194 00195 Scope: Static public 00196 00197 ********************************************************************************************/ 00198 00199 00200 BOOL CALLBACK PaletteManager::InvalidateChildProc(wxWindow* hWnd, LPARAM lParam) 00201 { 00202 /* GAT 00203 #if DEBUG_PALMAN 00204 TRACE( _T("BOOL CALLBACK PaletteManager::InvalidateChildProc(HWND hWnd = %d, LPARAM lParam = %d)\n"), 00205 (DWORD)hWnd, (DWORD)lParam); 00206 #endif 00207 BOOL bNotify = FALSE; 00208 if (PaletteManager::IsRedrawOnPaletteChangeRequired(hWnd, &bNotify)) 00209 { 00210 if (bNotify) 00211 SendMessage(hWnd, WM_CAM_PALETTECHANGE, 0, 0); 00212 00213 ::InvalidateRect(hWnd, NULL, TRUE); 00214 } 00215 */ 00216 return(TRUE); 00217 } 00218 00219 00220 00221 /******************************************************************************************** 00222 00223 > static void PaletteManager::RedrawAllPalettedWindows(HWND ParentWindow = NULL) 00224 00225 Author: Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> 00226 Created: 9/4/96 00227 00228 Inputs: hWnd - the parent window to invalidate, or NULL to use Camelot's MainFrame 00229 00230 Purpose: To redraw the given window (and all children) that are reliant upon 256- 00231 colour palettes. Usually called with NULL to just redraw the MainFrame. 00232 00233 ********************************************************************************************/ 00234 00235 void PaletteManager::RedrawAllPalettedWindows(wxWindow* hWnd) 00236 { 00237 /* GAT 00238 #if DEBUG_PALMAN 00239 TRACE( _T("void PaletteManager::RedrawAllPalettedWindows(HWND hWnd = %d)\n"), (DWORD)hWnd); 00240 #endif 00241 if (hWnd == NULL) 00242 { 00243 CMainFrame *MainFrame = GetMainFrame(); 00244 if (MainFrame != NULL) 00245 hWnd = MainFrame->m_hWnd; 00246 } 00247 00248 if (hWnd != NULL) 00249 { 00250 if (IsRedrawOnPaletteChangeRequired(hWnd)) 00251 ::InvalidateRect(hWnd, NULL, TRUE); // And redraw everything if necessary 00252 00253 EnumChildWindows(hWnd, InvalidateChildProc, 0); // And redraw all children which need it 00254 } 00255 */ 00256 } 00257 00258 00259 00260 /******************************************************************************************** 00261 00262 > BOOL PaletteManager::IsRedrawOnPaletteChangeRequired(HWND hWnd, BOOL* pNotifyFirst); 00263 00264 Author: Alex_Bligh (Xara Group Ltd) <camelotdev@xara.com> 00265 Created: 30/5/95 00266 00267 Inputs: hWnd - a window potentially to be redrawn 00268 Returns: TRUE if this window should redraw, FALSE if not 00269 00270 Purpose: To respond to InvalidateChildProc. Determines if the given window needs 00271 to be redrawn as a result of a palette change. 00272 00273 Scope: Static public 00274 00275 ********************************************************************************************/ 00276 00277 BOOL PaletteManager::IsRedrawOnPaletteChangeRequired(wxWindow* hWnd, BOOL* pNotifyFirst) 00278 { 00279 return FALSE; 00280 /* GAT 00281 #if DEBUG_PALMAN 00282 TRACE( _T("BOOL PaletteManager::IsRedrawOnPaletteChangeRequired(HWND hWnd = %d)\n"), (DWORD)hWnd); 00283 #endif 00284 00285 if (pNotifyFirst) 00286 *pNotifyFirst = FALSE; 00287 00288 #ifdef RALPH 00289 // Nasty Ralph bodge to get the palette working sensibly 00290 return(TRUE); 00291 00292 #else 00293 00294 // First see if it is an MFC Window 00295 // Well this does some of it 00296 CWnd* pCWnd = CWnd::FromHandlePermanent(hWnd); 00297 00298 // don't redraw it then 00299 // Note we keep its children separately 00300 #ifndef STANDALONE 00301 if (pCWnd) 00302 { 00303 if (pCWnd->IsKindOf(RUNTIME_CLASS(CColourBar)) || // Redraw the colour bar 00304 pCWnd->IsKindOf(RUNTIME_CLASS(CRenderWnd))) // and the view windows 00305 { 00306 return TRUE; 00307 } 00308 00309 return FALSE; 00310 } 00311 #else 00312 if (pCWnd) 00313 { 00314 if (pCWnd->IsKindOf(RUNTIME_CLASS(CRenderWnd))) // Redraw the view windows 00315 return TRUE; 00316 00317 return FALSE; 00318 } 00319 #endif 00320 00321 // OK, it's not an MFC window 00322 String_256 ClassNameStr; // The control type 00323 00324 // Find out the class type of the gadget 00325 GetClassName(hWnd, (TCHAR*)ClassNameStr, 255); 00326 if ((ClassNameStr == String_16(TEXT("cc_DialogDraw")))) 00327 return TRUE; 00328 00329 if ((ClassNameStr == String_16(TEXT("cc_BitmapButton")))) 00330 { 00331 if (pNotifyFirst) 00332 *pNotifyFirst = TRUE; 00333 return TRUE; 00334 } 00335 00336 if ((ClassNameStr == String_16(TEXT("cc_SmallButton")))) 00337 { 00338 if (pNotifyFirst) 00339 *pNotifyFirst = TRUE; 00340 return TRUE; 00341 } 00342 00343 if ((ClassNameStr == String_16(TEXT("cc_StaticBitmap")))) 00344 { 00345 if (pNotifyFirst) 00346 *pNotifyFirst = TRUE; 00347 return TRUE; 00348 } 00349 00350 return FALSE; 00351 00352 #endif 00353 */ 00354 } 00355 00356 00357 00358 /******************************************************************************************** 00359 00360 > BOOL PaletteManager::EnsurePalette(HWND hWnd, BOOL ForceRedraw) 00361 > BOOL PaletteManager::EnsurePalette(CWnd *CWindow, BOOL ForceRedraw) 00362 00363 Author: Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> 00364 Created: 26/5/95 00365 00366 Inputs: hWnd - the window for which EnsurePalette was called 00367 or CWindow the CWnd equivalent 00368 ForceRedraw - TRUE to force a redraw even when we haven't (seeminlgy) affected 00369 the palette 00370 00371 Returns: TRUE if it chnaged the palette in the course of realising the GDraw palette 00372 Now returns TRUE if it selects a palette 00373 00374 Purpose: To respond to WM_QUERYNEWPALETTE and WM_ONPALETTECHANGED 00375 Whenever you get one of these messages for youre window, call this method 00376 if you want to use the normal GDraw palette. The only splitter in this 00377 area to date is the splashbox window. 00378 00379 Scope: Static public 00380 00381 Notes: Use ForceRedraw = FALSE for WM_QUERYNEWPALETTE, TRUE for WM_ONPALETTECHANGED 00382 00383 ********************************************************************************************/ 00384 00385 BOOL PaletteManager::EnsurePalette(wxWindow* hWnd, BOOL ForceRedraw) 00386 { 00387 /* GAT 00388 #if DEBUG_PALMAN 00389 TRACE( _T("BOOL PaletteManager::EnsurePalette(HWND hWnd = %d, BOOL ForceRedraw = %d)\n"), 00390 (DWORD)hWnd, ForceRedraw); 00391 #endif 00392 00393 static PALETTEENTRY OldSysPal[256]; 00394 BOOL ForceBackground = m_fPaletteLocked; 00395 00396 static BOOL SelectingPalette = FALSE; 00397 00398 // This code may well look a bit odd but it is necessary to prevent reentrancy problems 00399 BOOL CheckPalette = !SelectingPalette; 00400 00401 #ifdef RALPH 00402 if(!RalphDocument::ForegroundPalette) 00403 ForceBackground = TRUE; 00404 #endif 00405 00406 // This "event" is directed at the application as a whole but the palette we set up is 00407 // always associated with the Selected DocView and so we'll set Current to Selected... 00408 if (Document::GetSelected != NULL) 00409 Document::GetSelected()->SetCurrent(); 00410 00411 if (DocView::GetSelected() != NULL) 00412 DocView::GetSelected()->SetCurrent(); 00413 00414 if (!UsePalette()) // We don't use a special palette, so do nothing 00415 return(FALSE); 00416 00417 // This check (to stop us changing the palette when minimised) has been removed (Jason - 26/7/95) 00418 // The reason for this is: 00419 // (a) This is contrary to microsoft coding guidelines, 00420 // (b) If you restore camelot from minimised state, it fails to realise its palette! 00421 // (c) The behaviour is now "correct" and exactly the same as all other apps 00422 // 00423 // if (MainFrame->IsIconic()) // We are currently in an iconised state, so do nothing 00424 // return(FALSE); 00425 00426 SelectingPalette = TRUE; 00427 00428 HDC hDC = ::GetDC(hWnd); 00429 00430 // We need to check that the palette actully has changed 00431 // because RealizePalette() will say that 256 colours have changed 00432 // if you close the help file on NT4/95 00433 00434 PALETTEENTRY NewSysPal[256]; 00435 00436 HPALETTE OldPal = ::SelectPalette(hDC, sm_MainPalette, ForceBackground); 00437 UINT32 NumColoursChanged = ::RealizePalette(hDC); 00438 ::SelectPalette(hDC, OldPal, TRUE); 00439 ::RealizePalette(hDC); 00440 00441 GetSystemPaletteEntries(hDC, 0, 256, NewSysPal); 00442 00443 ::ReleaseDC(hWnd, hDC); 00444 00445 SelectingPalette = FALSE; 00446 00447 if (CheckPalette) 00448 { 00449 for (DWORD Index = 0; Index < 256; Index++) 00450 NewSysPal[Index].peFlags = 0; 00451 00452 // If the palette has really changed 00453 if (memcmp(NewSysPal, OldSysPal, sizeof(PALETTEENTRY) * 256) != 0) 00454 { 00455 // TRACEUSER( "Gerry", _T("Palette has actually changed\n")); 00456 // Update the old palette 00457 memcpy(OldSysPal, NewSysPal, sizeof(PALETTEENTRY) * 256); 00458 00459 // TRACEUSER( "Gerry", _T("Cols changed %d\n"), NumColoursChanged); 00460 00461 // Only set the flag if the OS thinks the palette has changed 00462 if (NumColoursChanged != 0) 00463 ForceRedraw = TRUE; 00464 } 00465 // else 00466 // { 00467 // TRACEUSER( "Gerry", _T("Palette not actually changed\n")); 00468 // } 00469 } 00470 // else 00471 // { 00472 // TRACEUSER( "Gerry", _T("Not checking palette\n")); 00473 // } 00474 00475 if (ForceRedraw) 00476 { 00477 // TRACEUSER( "Gerry", _T("Forcing redraw\n")); 00478 GRenderRegion::GColInit(NULL, TRUE); // tell GDraw of new palette 00479 RedrawAllPalettedWindows(hWnd); // And redraw everything 00480 } 00481 00482 // This used to return the commented out line below but was changed 00483 // to help fix a problem with the help file 00484 00485 // return(NumColoursChanged != 0); 00486 */ return(TRUE); 00487 } 00488 00489 /* 00490 BOOL PaletteManager::EnsurePalette(CWnd *CWindow, BOOL ForceRedraw) 00491 { 00492 #if DEBUG_PALMAN 00493 TRACE( _T("BOOL PaletteManager::EnsurePalette(CWnd *CWindow = %d, BOOL ForceRedraw = %d)\n"), 00494 (DWORD)CWindow, ForceRedraw); 00495 #endif 00496 return(EnsurePalette(CWindow->GetSafeHwnd(), ForceRedraw)); 00497 } 00498 */ 00499 00500 00501 /******************************************************************************************** 00502 00503 > static CPalette *PaletteManager::StartPaintPalette(CDC *RenderDC, BOOL bForceBackground=FALSE) 00504 > static HPALETTE PaletteManager::StartPaintPalette(HDC hDC, HPALETTE *pHPal=NULL, BOOL bForceBackground=FALSE); 00505 > static HPALETTE PaletteManager::StartPaintPalette(HDC hDC, HPALETTE HPal, BOOL bForceBackground=FALSE); 00506 00507 Author: Alex_Bligh (Xara Group Ltd) <camelotdev@xara.com> 00508 Created: 26/5/95 00509 Inputs: RenderDC = the DC we're using 00510 00511 bForceBackground = value to pass to the force background param in SelectPalette 00512 If you don't understand foreground/background Windows palettes, use the default or ask Jason 00513 00514 HPal = palette to use (3 only) 00515 00516 Outputs: pHPal - if non-null, filled in with the palette which was selected into your DC (2 only) 00517 00518 Returns: Pointer to the old palette (or NULL if DC doesn't support palette) 00519 Purpose: To select and realise the mainframe GDraw palette before painting 00520 Scope: Static public 00521 00522 SeeAlso: PaletteManager::StopPaintPalette 00523 00524 ********************************************************************************************/ 00525 /* 00526 wxPalette* PaletteManager::StartPaintPalette(wxDC* RenderDC, BOOL bForceBackground) 00527 { 00528 #if 1 // GAT 00529 return NULL; 00530 #else 00531 #if DEBUG_PALMAN 00532 TRACE( _T("CPalette *PaletteManager::StartPaintPalette(CDC *RenderDC = %d, BOOL bForceBackground = %d)\n"), 00533 (DWORD)RenderDC, bForceBackground); 00534 #endif 00535 ERROR2IF (!RenderDC, NULL, "PaletteManager passed NULL RenderRC"); 00536 00537 #ifdef RALPH 00538 if(!RalphDocument::ForegroundPalette) 00539 bForceBackground = TRUE; 00540 #endif 00541 00542 if (!(RenderDC->GetDeviceCaps(RASTERCAPS) & RC_PALETTE)) 00543 return(NULL); 00544 00545 if (m_fPaletteLocked) 00546 bForceBackground = TRUE; 00547 00548 CPalette * OldPalette = RenderDC->SelectPalette(&sm_MainPalette, bForceBackground); 00549 RenderDC->RealizePalette(); 00550 00551 return OldPalette; 00552 #endif 00553 } 00554 */ 00555 00556 wxPalette* PaletteManager::StartPaintPalette(wxDC* hDC, wxPalette* pHPal, BOOL bForceBackground) 00557 { 00558 #if 1 // GAT 00559 return NULL; 00560 #else 00561 #if DEBUG_PALMAN 00562 TRACE( _T("HPALETTE PaletteManager::StartPaintPalette(HDC hDC = %d, HPALETTE *pHPal = %d, BOOL bForceBackground = %d)\n"), 00563 (DWORD)hDC, (DWORD)pHPal, bForceBackground); 00564 #endif 00565 ERROR2IF(!hDC, NULL, "PaletteManager passed NULL DC"); 00566 00567 #ifdef RALPH 00568 if(!RalphDocument::ForegroundPalette) 00569 bForceBackground = TRUE; 00570 #endif 00571 00572 if (!(::GetDeviceCaps(hDC, RASTERCAPS) & RC_PALETTE)) 00573 return(NULL); 00574 00575 HPALETTE NewPalette = sm_MainPalette; // Sneaky HPALETTE operator 00576 if (pHPal) 00577 *pHPal = NewPalette; 00578 00579 if (m_fPaletteLocked) 00580 bForceBackground = TRUE; 00581 00582 HPALETTE OldPalette = ::SelectPalette(hDC, NewPalette, bForceBackground); 00583 ::RealizePalette(hDC); 00584 00585 return OldPalette; 00586 #endif 00587 } 00588 00589 /* 00590 wxPalette* PaletteManager::StartPaintPalette(wxDC* hDC, const wxPalette& HPal, BOOL bForceBackground) 00591 { 00592 #if 1 // GAT 00593 return NULL; 00594 #else 00595 #if DEBUG_PALMAN 00596 TRACE( _T("HPALETTE PaletteManager::StartPaintPalette(HDC hDC = %d, HPALETTE HPal = %d, BOOL bForceBackground = %d)\n"), 00597 (DWORD)hDC, (DWORD)HPal, bForceBackground); 00598 #endif 00599 ERROR2IF(!hDC, NULL, "PaletteManager passed NULL DC"); 00600 00601 #ifdef RALPH 00602 if(!RalphDocument::ForegroundPalette) 00603 bForceBackground = TRUE; 00604 #endif 00605 00606 if (!(::GetDeviceCaps(hDC, RASTERCAPS) & RC_PALETTE)) 00607 return(NULL); 00608 00609 if (m_fPaletteLocked) 00610 bForceBackground = TRUE; 00611 00612 HPALETTE OldPalette = ::SelectPalette(hDC, HPal, bForceBackground); 00613 ::RealizePalette(hDC); 00614 00615 return OldPalette; 00616 #endif 00617 } 00618 */ 00619 00620 00621 /******************************************************************************************** 00622 00623 > static CPalette *PaletteManager::StopPaintPalette(CDC *RenderDC, CPalette *OldPalette, 00624 BOOL bForceBackground = TRUE) 00625 00626 > static HPALETTE PaletteManager::StopPaintPalette(HDC hDC, HPALETTE OldPalette, 00627 BOOL bForceBackground = TRUE) 00628 Author: Alex_Bligh (Xara Group Ltd) <camelotdev@xara.com> 00629 Created: 26/5/95 00630 00631 Inputs: RenderDC/hDC - the DC we're using 00632 00633 OldPalette - The palette returned to you when you called StartPaintPalette 00634 00635 bForceBackground = value to pass to the forcebackground param in SelectPalette 00636 It's not expected that this will ever be anything other than TRUE 00637 00638 Outputs: - 00639 Returns: Pointer to the old palette (or NULL if DC doesn't support palette) 00640 00641 Purpose: To restore the palette after painting, using the palette returned to you 00642 by StartPaintPalette 00643 00644 SeeAlso: PaletteManager::StartPaintPalette 00645 00646 Scope: Static public 00647 00648 ********************************************************************************************/ 00649 00650 wxPalette* PaletteManager::StopPaintPalette(wxDC* RenderDC, wxPalette* OldPalette, BOOL bForceBackground) 00651 { 00652 #if DEBUG_PALMAN 00653 TRACE( _T("CPalette *PaletteManager::StopPaintPalette(CDC *RenderDC = %d, CPalette *OldPalette = %d, BOOL bForceBackground = %d)\n"), 00654 (DWORD)RenderDC, (DWORD)OldPalette, bForceBackground); 00655 #endif 00656 ERROR2IF (!RenderDC, NULL, "PaletteManager passed NULL RenderRC"); 00657 // GAT 00658 // if (!(RenderDC->GetDeviceCaps(RASTERCAPS) & RC_PALETTE)) 00659 return(NULL); 00660 /* 00661 if (m_fPaletteLocked) 00662 bForceBackground = TRUE; 00663 00664 CPalette *PrevPalette = RenderDC->SelectPalette(OldPalette, bForceBackground); 00665 RenderDC->RealizePalette(); 00666 00667 return PrevPalette; 00668 */ 00669 } 00670 00671 00672 /******************************************************************************************** 00673 00674 > static void PaletteManager::UpdatePalette(void) 00675 00676 Author: Gerry_Iles (Xara Group Ltd) <camelotdev@xara.com> 00677 Created: 28/5/96 00678 Purpose: Sets up the static main frame palette 00679 This will be called whenever the palette needs updating 00680 SeeAlso: - 00681 00682 ********************************************************************************************/ 00683 00684 void PaletteManager::UpdatePalette(void) 00685 { 00686 /* GAT 00687 #if DEBUG_PALMAN 00688 TRACE( _T("void PaletteManager::UpdatePalette(void)\n")); 00689 #endif 00690 00691 HPALETTE hPal = (HPALETTE) sm_MainPalette.Detach(); // Detach the palette object 00692 00693 if (hPal != NULL) 00694 { 00695 ::DeleteObject(hPal); 00696 hPal = NULL; 00697 } 00698 00699 sm_bUseMainPalette = FALSE; 00700 00701 LPLOGPALETTE lpPal = (LPLOGPALETTE)GRenderRegion::GetRecommendedPalette(); 00702 00703 if (lpPal) 00704 { 00705 TRACEUSER( "Gerry", _T("Got a palette in PaletteManager::UpdatePalette()\n")); 00706 00707 // Gavin's palette has 10 unused entries at the front and 10 at the back, which 00708 // is dead handy indeed 00709 hPal = DIBUtil::MakeIdentityPalette( lpPal->palPalEntry, 256 ); 00710 if (hPal) 00711 { 00712 sm_bUseMainPalette = sm_MainPalette.Attach(hPal); 00713 } 00714 } 00715 */ 00716 } 00717 00718 /******************************************************************************************** 00719 00720 > static void PaletteManager::MakePaletteBrowserCompatible(LPLOGPALETTE pPalette,BOOL AvoidSystemColours) 00721 00722 Author: Mark_Neves (Xara Group Ltd) <camelotdev@xara.com> 00723 Created: 8/2/97 00724 Inputs: pPalette = ptr to 256 entry palette 00725 AvoidSystemColours = TRUE if you want the system colour palette entries to be lefte alone 00726 FALSE if you want the first 216 entries to be the browser palette. 00727 00728 Purpose: This inserts all the browser colours into the palette, and marks all other entries 00729 so that they are not used when creating bitmaps. 00730 00731 An entry is marked as "don't use" by setting the peFlags member to 255 00732 (e.g. pPalette->palPalEntry[x].peFlags = 255); 00733 00734 if AvoidSystemColours is TRUE, the system colour palette entries are marked as "don't use" 00735 00736 Introduced for Webster. 00737 Modified heavily for Webster v2 by Markn 20/6/97 00738 SeeAlso: - 00739 00740 ********************************************************************************************/ 00741 00742 void PaletteManager::MakePaletteBrowserCompatible(LPLOGPALETTE pPalette,BOOL AvoidSystemColours) 00743 { 00744 if (pPalette == NULL) 00745 { 00746 ERROR3("Null palette ptr"); 00747 return; 00748 } 00749 00750 if (pPalette->palNumEntries != 256) 00751 { 00752 ERROR3("Only suitable for 8bpp 256 entry palettes"); 00753 return; 00754 } 00755 00756 // Set all entries to be "Don't use" 00757 INT32 i; 00758 for (i = 0; i < pPalette->palNumEntries;i++) 00759 { 00760 pPalette->palPalEntry[i].peRed = 0; 00761 pPalette->palPalEntry[i].peGreen = 0; 00762 pPalette->palPalEntry[i].peBlue = 0; 00763 pPalette->palPalEntry[i].peFlags = 255; 00764 } 00765 00766 // If system colours entries are to be avoided, start from the first non-system colour entry (index value 11) 00767 if (AvoidSystemColours) 00768 i = 11; // 11 in case the bitmap is transparent, in which case index 10 will hold the transparent colour 00769 else 00770 i = 1; // 1 in case the bitmap is transparent, in which case index 0 will hold the transparent colour 00771 00772 // Fill it with the browser colours 00773 PaletteManager::FillWithBrowserColours(pPalette,i); 00774 00775 // Debug sanity check 00776 #ifdef _DEBUG 00777 TRACE( _T("Checking 216 colours\n")); 00778 if (!ContainsAllBrowserColours(pPalette)) 00779 ERROR3("Do what! Some browser colours are missing!"); 00780 #endif 00781 } 00782 00783 /******************************************************************************************** 00784 00785 > static void PaletteManager::FillWithBrowserColours(LPLOGPALETTE pPalette,INT32 StartIndex) 00786 00787 Author: Mark_Neves (Xara Group Ltd) <camelotdev@xara.com> 00788 Created: 20/6/97 00789 Inputs: pPalette = ptr palette 00790 StartIndex = the index to start filling the entries from 00791 Returns: - 00792 Purpose: Stuffs all the browser colours into the palette provided 00793 Also markes each peFlags entry to 0 (i.e. so Gavin will use it). 00794 SeeAlso: - 00795 00796 ********************************************************************************************/ 00797 00798 void PaletteManager::FillWithBrowserColours(LPLOGPALETTE pPalette,INT32 StartIndex) 00799 { 00800 ERROR3IF(pPalette == NULL,"NULL Entry param"); 00801 if (pPalette == NULL) 00802 return; 00803 00804 INT32 i = StartIndex; 00805 00806 // Generate the entire browser palette 00807 for (INT32 r=0;r <= 255;r += 51) 00808 { 00809 for (INT32 g=0;g <=255;g += 51) 00810 { 00811 for (INT32 b=0;b <=255;b += 51) 00812 { 00813 if (i < pPalette->palNumEntries) // Extra safety check 00814 { 00815 pPalette->palPalEntry[i].peRed = r; 00816 pPalette->palPalEntry[i].peGreen = g; 00817 pPalette->palPalEntry[i].peBlue = b; 00818 pPalette->palPalEntry[i].peFlags = 0; // Mark as "Use this colour if you want" 00819 } 00820 00821 i++; // Next entry please 00822 } 00823 } 00824 } 00825 } 00826 00827 /******************************************************************************************** 00828 00829 > static void PaletteManager::ContainsAllBrowserColours(LPLOGPALETTE pPalette) 00830 00831 Author: Mark_Neves (Xara Group Ltd) <camelotdev@xara.com> 00832 Created: 20/6/97 00833 Inputs: pPalette = ptr palette 00834 Returns: TRUE if palette contains all the 216 browser palette entries 00835 FALSE otherwise 00836 Purpose: A test to see if the palette contains all the 216 browser palette entries. 00837 SeeAlso: - 00838 00839 ********************************************************************************************/ 00840 00841 BOOL PaletteManager::ContainsAllBrowserColours(LPLOGPALETTE pPalette) 00842 { 00843 for (INT32 r=0;r <= 255;r += 51) 00844 { 00845 BYTE ra = r; 00846 for (INT32 g=0;g <=255;g += 51) 00847 { 00848 BYTE ga = g; 00849 for (INT32 b=0;b <=255;b += 51) 00850 { 00851 BYTE ba = b; 00852 BOOL found = FALSE; 00853 for (INT32 i=0;i<pPalette->palNumEntries;i++) 00854 { 00855 // if peFlags != 255, then it hasn't been marked as "Don't use", so check it 00856 if (pPalette->palPalEntry[i].peFlags != 255) 00857 { 00858 found = pPalette->palPalEntry[i].peRed == ra && 00859 pPalette->palPalEntry[i].peGreen == ga && 00860 pPalette->palPalEntry[i].peBlue == ba; 00861 if ( found ) 00862 break; 00863 } 00864 } 00865 if (!found) 00866 return FALSE; 00867 } 00868 } 00869 } 00870 return TRUE; 00871 } 00872 00873 00874 /******************************************************************************************** 00875 00876 > static LPLOGPALETTE PaletteManager::CreateBrowserPalette(LPLOGPALETTE pPalette,BOOL AvoidSystemColours) 00877 00878 Author: Mark_Neves (Xara Group Ltd) <camelotdev@xara.com> 00879 Created: 20/6/97 00880 Inputs: AvoidSystemColours = TRUE if you want the system colour palette entries to be left alone. 00881 FALSE if you want the first 216 entries to be the browser palette. 00882 00883 Returns: ptr to a palette, or NULL if it fails 00884 Purpose: Creates a palette of browser colours 00885 00886 To delete the palette, use CCFree(). 00887 SeeAlso: - 00888 00889 ********************************************************************************************/ 00890 00891 LPLOGPALETTE PaletteManager::CreateBrowserPalette(BOOL AvoidSystemColours) 00892 { 00893 LPLOGPALETTE pPalette = NULL; 00894 const size_t TotalPal = sizeof(LOGPALETTE) + ( sizeof(PALETTEENTRY) * 256 ); 00895 pPalette = (LPLOGPALETTE)CCMalloc( TotalPal ); 00896 if (pPalette!= NULL) 00897 { 00898 pPalette->palVersion = 0x300; 00899 pPalette->palNumEntries = 256; 00900 MakePaletteBrowserCompatible(pPalette,AvoidSystemColours); 00901 } 00902 00903 return pPalette; 00904 } 00905 00906 /******************************************************************************************** 00907 00908 > static void PaletteManager::FindNearestColour(const ColourRGBT& Colour, LPLOGPALETTE pPalette, ColourRGBT* const pResult) 00909 00910 Author: Mark_Neves (Xara Group Ltd) <camelotdev@xara.com> 00911 Created: 7/7/97 00912 Inputs: Colour = Original colour definition 00913 pPalette = look-up palette 00914 pResult = place to put closest colour definition 00915 00916 Returns: pResult contains a colour from the palette that's closest to the original 00917 Purpose: Finds the closest colour in the given palette. 00918 00919 The closest colour is the one that is closest in terms of distance within the RGB colour 00920 cube. 00921 SeeAlso: - 00922 00923 ********************************************************************************************/ 00924 00925 void PaletteManager::FindNearestColour(const ColourRGBT& Colour, LPLOGPALETTE pPalette, ColourRGBT* const pResult) 00926 { 00927 ERROR3IF(pResult == NULL,"NULL pResult pointer"); 00928 if (pResult == NULL) 00929 return; 00930 00931 // Convert original colour into an RGB palette entry 00932 PALETTEENTRY PalColour; 00933 PalColour.peRed = BYTE(Colour.Red.MakeDouble()*255); 00934 PalColour.peGreen = BYTE(Colour.Green.MakeDouble()*255); 00935 PalColour.peBlue = BYTE(Colour.Blue.MakeDouble()*255); 00936 00937 // Find the closest palette entry 00938 PALETTEENTRY ClosestPalColour = FindNearestColour(PalColour,pPalette); 00939 00940 // Convert back to a ColourRGBT 00941 pResult->Red = FIXED24(double(ClosestPalColour.peRed)/255.0); 00942 pResult->Green = FIXED24(double(ClosestPalColour.peGreen)/255.0); 00943 pResult->Blue = FIXED24(double(ClosestPalColour.peBlue)/255.0); 00944 } 00945 00946 /******************************************************************************************** 00947 00948 > static PALETTEENTRY PaletteManager::FindNearestColour(const PALETTEENTRY& PalColour, LPLOGPALETTE pPalette) 00949 00950 Author: Mark_Neves (Xara Group Ltd) <camelotdev@xara.com> 00951 Created: 7/7/97 00952 Inputs: PalColour = Original colour definition 00953 pPalette = look-up palette 00954 00955 Returns: A colour from the palette that's closest to the original 00956 Purpose: Finds the closest colour in the given palette. 00957 00958 The closest colour is the one that is closest in terms of distance within the RGB colour 00959 cube. 00960 SeeAlso: - 00961 00962 ********************************************************************************************/ 00963 00964 PALETTEENTRY PaletteManager::FindNearestColour(const PALETTEENTRY& PalColour, LPLOGPALETTE pPalette) 00965 { 00966 PALETTEENTRY Dummy = {0,0,0,0}; 00967 ERROR2IF(pPalette == NULL,Dummy,"NULL Palette ptr"); 00968 ERROR2IF(pPalette->palNumEntries < 1,Dummy,"No Palette entries"); 00969 00970 double SmallestDistance = 0.0; 00971 BOOL FirstDistanceCalc = TRUE; 00972 INT32 ClosestColourIndex = 0; 00973 00974 // look at all the colours in the palette 00975 for (INT32 i=0;i<pPalette->palNumEntries;i++) 00976 { 00977 // If the peFlags is 0, then it's not been marked as "ignore", so look at it 00978 if (pPalette->palPalEntry[i].peFlags == 0) 00979 { 00980 // Get the distance between the colour and this palette entry 00981 double d = FindColourDistanceSquared(&PalColour, &(pPalette->palPalEntry[i])); 00982 00983 if (FirstDistanceCalc) 00984 { 00985 // First time around, so 'd' must be closest yet 00986 FirstDistanceCalc = FALSE; 00987 SmallestDistance = d; 00988 ClosestColourIndex = i; 00989 } 00990 else if (d < SmallestDistance) 00991 { 00992 // Smallest distance so far? if so remember the distance & index 00993 SmallestDistance = d; 00994 ClosestColourIndex = i; 00995 } 00996 } 00997 } 00998 00999 // Return the closest palette entry 01000 return (pPalette->palPalEntry[ClosestColourIndex]); 01001 } 01002 01003 // This function is identical to FindNearestColour, except that it returns an index 01004 // rather than a colour. 01005 INT32 PaletteManager::FindIndexOfNearestColour(const PALETTEENTRY& PalColour, LPLOGPALETTE pPalette) 01006 { 01007 // PALETTEENTRY Dummy = {0,0,0,0}; 01008 01009 double SmallestDistance = 0.0; 01010 BOOL FirstDistanceCalc = TRUE; 01011 INT32 ClosestColourIndex = 0; 01012 01013 // look at all the colours in the palette 01014 for (INT32 i=0;i<pPalette->palNumEntries;i++) 01015 { 01016 // If the peFlags is 0, then it's not been marked as "ignore", so look at it 01017 if (pPalette->palPalEntry[i].peFlags == 0) 01018 { 01019 // Get the distance between the colour and this palette entry 01020 double d = FindColourDistanceSquared(&PalColour, &(pPalette->palPalEntry[i])); 01021 01022 if (FirstDistanceCalc) 01023 { 01024 // First time around, so 'd' must be closest yet 01025 FirstDistanceCalc = FALSE; 01026 SmallestDistance = d; 01027 ClosestColourIndex = i; 01028 } 01029 else if (d < SmallestDistance) 01030 { 01031 // Smallest distance so far? if so remember the distance & index 01032 SmallestDistance = d; 01033 ClosestColourIndex = i; 01034 } 01035 } 01036 } 01037 01038 // Return the closest palette entry 01039 return ClosestColourIndex; 01040 } 01041 01042 /******************************************************************************************** 01043 01044 > static double PaletteManager::FindColourDistanceSquared(const PALETTEENTRY* pPal1,const PALETTEENTRY* pPal2) 01045 01046 Author: Mark_Neves (Xara Group Ltd) <camelotdev@xara.com> 01047 Created: 7/7/97 01048 Inputs: pPal1 = Colour 1 01049 pPal2 = Colour 2 01050 01051 Returns: The distance between the two colours with the RGB cube, squared 01052 Purpose: Finds the distance between two colours 01053 SeeAlso: - 01054 01055 ********************************************************************************************/ 01056 01057 double PaletteManager::FindColourDistanceSquared(const PALETTEENTRY* pPal1,const PALETTEENTRY* pPal2) 01058 { 01059 ERROR2IF(pPal1 == NULL || pPal2 == NULL,0.0,"NULL pal entry pointer"); 01060 01061 double dr = double(pPal1->peRed - pPal2->peRed ); 01062 double dg = double(pPal1->peGreen - pPal2->peGreen); 01063 double db = double(pPal1->peBlue - pPal2->peBlue ); 01064 01065 return dr*dr+dg*dg+db*db ; 01066 } 01067 01068 /******************************************************************************************** 01069 01070 > static void PaletteManager::FindNearestBrowserColour(const ColourRGBT& Colour,ColourRGBT* const pResult) 01071 01072 Author: Mark_Neves (Xara Group Ltd) <camelotdev@xara.com> 01073 Created: 7/7/97 01074 Inputs: Colour = Original colour definition 01075 pResult = place to put closest colour definition 01076 01077 Returns: pResult contains a colour from the browser palette that's closest to the original 01078 Purpose: Finds the closest colour in the browser palette. 01079 01080 The closest colour is the one that is closest in terms of distance within the RGB colour 01081 cube. 01082 SeeAlso: - 01083 01084 ********************************************************************************************/ 01085 01086 void PaletteManager::FindNearestBrowserColour(const ColourRGBT& Colour,ColourRGBT* const pResult) 01087 { 01088 ERROR3IF(pResult == NULL,"NULL pResult pointer"); 01089 if (pResult == NULL) 01090 return; 01091 01092 LPLOGPALETTE pBrowserPalette = PaletteManager::CreateBrowserPalette(FALSE); 01093 if (pBrowserPalette != NULL) 01094 { 01095 FindNearestColour(Colour,pBrowserPalette,pResult); 01096 CCFree(pBrowserPalette); 01097 } 01098 } 01099 01100 /******************************************************************************************** 01101 01102 > static void PaletteManager::SnapToPalette(LPLOGPALETTE pPalette, const LPLOGPALETTE pPaletteToSnapTo) 01103 01104 Author: Mark_Neves (Xara Group Ltd) <camelotdev@xara.com> 01105 Created: 22/7/97 01106 Inputs: pPalette = ptr to palette that will be snapped 01107 pPaletteToSnapTo = ptr to palette to snap to 01108 01109 Returns: - 01110 Purpose: This snaps each colour in pPalette to the closest definition in pPaletteToSnapTo 01111 01112 The closest colour is the one that is closest in terms of distance within the RGB colour 01113 cube. 01114 01115 SeeAlso: - 01116 01117 ********************************************************************************************/ 01118 01119 void PaletteManager::SnapToPalette(LPLOGPALETTE pPalette, const LPLOGPALETTE pPaletteToSnapTo) 01120 { 01121 ERROR3IF(pPalette == NULL || pPaletteToSnapTo == NULL,"NULL pal pointer"); 01122 if (pPalette == NULL || pPaletteToSnapTo == NULL) 01123 return; 01124 01125 // look at all the colours in the palette 01126 for (INT32 i=0;i<pPalette->palNumEntries;i++) 01127 { 01128 // Get the next pal entry 01129 PALETTEENTRY PalEntry = pPalette->palPalEntry[i]; 01130 01131 // Find the closest pal entry in the palette to snap to 01132 PALETTEENTRY NearestPalEntry = FindNearestColour(PalEntry, pPaletteToSnapTo); 01133 01134 // Set the pal entry to the nearest colour 01135 pPalette->palPalEntry[i] = NearestPalEntry; 01136 } 01137 } 01138 01139 01140 /******************************************************************************************** 01141 01142 > static void PaletteManager::SnapToBrowserPalette(LPLOGPALETTE pPalette) 01143 01144 Author: Mark_Neves (Xara Group Ltd) <camelotdev@xara.com> 01145 Created: 22/7/97 01146 Inputs: pPalette = ptr to palette that will be snapped 01147 01148 Returns: - 01149 Purpose: This snaps each colour in pPalette to the closest definition in browser palette 01150 01151 The closest colour is the one that is closest in terms of distance within the RGB colour 01152 cube. 01153 01154 SeeAlso: - 01155 01156 ********************************************************************************************/ 01157 01158 void PaletteManager::SnapToBrowserPalette(LPLOGPALETTE pPalette) 01159 { 01160 ERROR3IF(pPalette == NULL,"NULL pPalette pointer"); 01161 if (pPalette == NULL) 01162 return; 01163 01164 LPLOGPALETTE pBrowserPalette = PaletteManager::CreateBrowserPalette(FALSE); 01165 if (pBrowserPalette != NULL) 01166 { 01167 SnapToPalette(pPalette,pBrowserPalette); 01168 CCFree(pBrowserPalette); 01169 } 01170 } 01171 01172 /******************************************************************************************** 01173 01174 > static void PaletteManager::PokePaletteEntry(LPLOGPALETTE Palette, INT32 * index, 01175 BYTE red, BYTE green, BYTE blue, BYTE Flags = 0) 01176 01177 Author: Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com> 01178 Created: 15/8/97 01179 Inputs: Palette palette to write to. 01180 index address of variable holding palette entry to write to 01181 red red value to enter into palette entry 01182 green green value to enter into palette entry 01183 blue blue value to enter into palette entry 01184 Outputs: index incremented by one 01185 Returns: - 01186 Purpose: Puts the required value of rgb into the specified palette entry. 01187 SeeAlso: OutputDIB::PokePaletteEntry; 01188 01189 ********************************************************************************************/ 01190 void PaletteManager::PokePaletteEntry(LPLOGPALETTE Palette, INT32 * index, 01191 BYTE red, BYTE green, BYTE blue, BYTE Flags) 01192 { 01193 ERROR3IF(Palette == NULL || index == NULL,"PaletteManager::PokePaletteEntry bad params"); 01194 if (Palette == NULL || index == NULL) 01195 return; 01196 01197 Palette->palPalEntry[*index].peRed = red; 01198 Palette->palPalEntry[*index].peGreen = green; 01199 Palette->palPalEntry[*index].peBlue = blue; 01200 Palette->palPalEntry[*index].peFlags = 0; 01201 // increment the counter and return it 01202 (*index) ++; 01203 } 01204 01205 /******************************************************************************************** 01206 01207 > static LPLOGPALETTE PaletteManager::Get4bppBrowserPalette(UINT32 ReservedColours) 01208 01209 Author: Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com> Humprhys 01210 Created: 15/8/97 01211 Inputs: ReservedColours number of reserved colours in this palette e.g. transparent colour 01212 Returns: LOGPALETTE containing the required palette or NULL 01213 Purpose: This produces a browser compatible 4bpp Palette. 01214 01215 ********************************************************************************************/ 01216 01217 LPLOGPALETTE PaletteManager::Get4bppBrowserPalette(UINT32 ReservedColours) 01218 { 01219 ERROR3IF(ReservedColours > 15,"Bad number of reserved colours"); 01220 01221 LPLOGPALETTE pPalette = DIBUtil::AllocateLogPalette(16); 01222 if (pPalette == NULL) 01223 return NULL; 01224 01225 INT32 i = 0; 01226 // Gavin uses a fixed 16 colour palette 01227 // Usually we use a half intensity value, instead we need to snap it to either 01228 // 40% (102) or 60% (153) to be browser compatible 01229 // Define a constant so its easy to change this snapped half intensity value 01230 const BYTE Shiv = 153; 01231 // We shall just use a browser snapped version of this 01232 PokePaletteEntry(pPalette, &i, 0x00, 0x00, 0x00); // black 01233 PokePaletteEntry(pPalette, &i, Shiv, 0x00, 0x00); // brown 01234 PokePaletteEntry(pPalette, &i, 0x00, Shiv, 0x00); // Half green 01235 PokePaletteEntry(pPalette, &i, Shiv, Shiv, 0x00); // Half browny (red/green) 01236 PokePaletteEntry(pPalette, &i, 0x00, 0x00, Shiv); // Dark blue 01237 PokePaletteEntry(pPalette, &i, Shiv, 0x00, Shiv); // Mauve 01238 PokePaletteEntry(pPalette, &i, 0x00, Shiv, Shiv); // greeny/blue 01239 PokePaletteEntry(pPalette, &i, Shiv, Shiv, Shiv); // mid grey 01240 01241 PokePaletteEntry(pPalette, &i, 0xcc, 0xcc, 0xcc); // light grey from 196 to 204 01242 PokePaletteEntry(pPalette, &i, 0xff, 0x00, 0x00); // red 01243 PokePaletteEntry(pPalette, &i, 0x00, 0xff, 0x00); // green 01244 PokePaletteEntry(pPalette, &i, 0xff, 0xff, 0x00); // yellow 01245 PokePaletteEntry(pPalette, &i, 0x00, 0x00, 0xff); // blue 01246 PokePaletteEntry(pPalette, &i, 0xff, 0x00, 0xff); // magenta 01247 PokePaletteEntry(pPalette, &i, 0x00, 0xff, 0xff); // cyan 01248 PokePaletteEntry(pPalette, &i, 0xff, 0xff, 0xff); // white 01249 01250 /* if (ReservedColours > 0) 01251 { 01252 // Used to pick index 10 to be transparent but now we pick the light grey 01253 i = 8; 01254 PokePaletteEntry(pPalette, &i, 0xFF, 0xFF, 0xFF, 0xFF); // don't use white 01255 01256 // Warn if we try to pick more than 1 reserved colour 01257 ERROR3IF(ReservedColours > 1,"Get4bppBrowserPalette We can only cope with 1 reserved colour"); 01258 } */ 01259 01260 return pPalette; 01261 } 01262 01263 /******************************************************************************************** 01264 01265 > static INT32 PaletteManager::FindFirstDontUseColourInPalette(LPLOGPALETTE pPalette) 01266 01267 Author: Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com> Humprhys 01268 Created: 15/8/97 01269 Inputs: pPalette palette to check 01270 Returns: index of the transparent colour or -1 01271 Purpose: This finds the first colour marked as don't use in the specified palette. 01272 This colour should correspond to the transparent colour. 01273 01274 ********************************************************************************************/ 01275 01276 INT32 PaletteManager::FindFirstDontUseColourInPalette(LPLOGPALETTE pPalette) 01277 { 01278 ERROR2IF(pPalette == NULL,-1,"FindFirstDontUseColourInPalette Bad palette"); 01279 01280 UINT32 colours = pPalette->palNumEntries; 01281 INT32 DontUseColour = -1; 01282 PALETTEENTRY * pPaletteEntry = pPalette->palPalEntry; 01283 for (UINT32 i = 0; (i < colours) && (DontUseColour == -1); i++) 01284 { 01285 if (pPaletteEntry[i].peFlags == 0xFF) 01286 DontUseColour = i; 01287 } 01288 01289 return DontUseColour; 01290 }