bmpalctrl.cpp

Go to the documentation of this file.
00001 // $Id: bmpalctrl.cpp 1269 2006-06-08 09:27:36Z 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 // Palette control for use in the export/create bitmap copy dialog
00099 
00100 // Implementation notes:  The palette contol displays the palette in the
00101 // bitmap export dialog.  This palette has various sort options so the user
00102 // can view the palette in diffrent ways.  To avoid having to change the actual
00103 // bitmap when the user changes the sort type, this controls comunicates with
00104 // the actual palette throught an interface class, BitmapExportPaletteInterface,
00105 // which sits between the palette from the bitmap and the palette that this
00106 // control uses (throught the member variable m_Palette).  Because of this,
00107 // when the palette is comunicating with other parts of camelot, it must take
00108 // into account this sorting and provide indexs into the palette in terms that
00109 // the caller expects (ie sorted or non sorted).
00110 
00111 #include "camtypes.h"
00112 
00113 #include "bmpalctrl.h"
00114 
00115 #include "dlgmgr.h"
00116 #include "filedlgs.h"       // required CreateOSRenderRegion
00117 #include "dlgcol.h"         // required for DialogColours
00118 //#include "bmpreres.h"     // for _R(IDC_T2_PALETTE_CONTROL)
00119 #include "bmpalint.h"       // bitmap palette interface class
00120 #include "bmpprefs.h"       // for colour type bit fields
00121 #include "bmapprev.h"       // for BmapPrevDlg (used in web safe code)
00122 #include "grndrgn.h"        // for GRenderRegion::GetDefaultDPI()
00123 #include "palmenu.h"        // for palette's context senesitve menu
00124 
00125 CC_IMPLEMENT_MEMDUMP(BitmapExportPaletteControl, CC_CLASS_MEMDUMP)
00126 
00127 #define new CAM_DEBUG_NEW
00128 
00129 BitmapExportPaletteControl::BitmapExportPaletteControl()
00130  : m_MouseOverCell(INVALID_COLOUR_VALUE /* Set to none */)
00131  , m_SelectedCell(INVALID_COLOUR_VALUE /* Set to none */)
00132  , m_WindowID(0)
00133  , m_nPixelSize(72000 / GRenderRegion::GetDefaultDPI())
00134  , m_nCellWidthPixels(11)
00135  , m_nCellHeightPixels(11)
00136  , m_nCellWidth(m_nPixelSize * m_nCellHeightPixels)
00137  , m_nCellHeight(m_nPixelSize * m_nCellHeightPixels)
00138  , m_nCellsPerLine(30)
00139  , m_NumberOfColoursAtLastRedraw(0)
00140 {
00141 }
00142 
00143 BitmapExportPaletteControl::~BitmapExportPaletteControl()
00144 {
00145 }
00146 
00147 /********************************************************************************************
00148 >   void BitmapExportPaletteControl::SetCurrentSortType(BitmapExportPaletteInterface::PaletteSortType newSortType)
00149     Author:     Jonathan_Payne (Xara Group Ltd) <camelotdev@xara.com>
00150     Created:    19/12/2000
00151     Purpose:    Sets the palette control to use a new sort method (hue, luminance etc) - 
00152                 changes will be visible the next time the palette is drawn
00153 ********************************************************************************************/
00154 void BitmapExportPaletteControl::SetCurrentSortType(BitmapExportPaletteInterface::PaletteSortType newSortType)
00155 {
00156     m_Palette.SetPaletteSortType(newSortType);
00157 }
00158 
00159 /********************************************************************************************
00160 >   BitmapExportPaletteInterface::PaletteSortType BitmapExportPaletteControl::GetCurrentSortType()
00161     Author:     Jonathan_Payne (Xara Group Ltd) <camelotdev@xara.com>
00162     Created:    19/12/2000
00163     Purpose:    Returns the current sorting order of the palette control
00164 ********************************************************************************************/
00165 BitmapExportPaletteInterface::PaletteSortType BitmapExportPaletteControl::GetCurrentSortType()
00166 {
00167     return m_Palette.GetPaletteSortType();
00168 }
00169 
00170 /********************************************************************************************
00171 >   INT32 BitmapExportPaletteControl::GetCellFromPos(INT32 x, INT32 y)
00172     Author:     Jonathan_Payne (Xara Group Ltd) <camelotdev@xara.com>
00173     Created:    18/12/2000
00174     Inputs:     x and y coords in DocCoords (not win coords)
00175     Purpose:    Find the cell from a coord
00176 ********************************************************************************************/
00177 INT32 BitmapExportPaletteControl::GetCellFromPos(INT32 x, INT32 y)
00178 {
00179     INT32 cellX = x / m_nCellWidthPixels;       // zero based
00180 
00181     INT32 cellY = y / m_nCellHeightPixels;  // zero based
00182 
00183     INT32 cell = (m_nCellsPerLine * cellY) + cellX;
00184 
00185     if (cell >= m_Palette.GetNumberOfColours() || cellX >= m_nCellsPerLine)
00186         return INVALID_COLOUR_VALUE;
00187     else
00188         return cell;
00189 }
00190 
00191 void BitmapExportPaletteControl::MsgMouseMove(ReDrawInfoType *pInfo)
00192 {
00193     INT32 cell = GetCellFromPos(pInfo->pMousePos->x / m_nPixelSize, (pInfo->dy - pInfo->pMousePos->y) / m_nPixelSize);
00194 
00195     SetHighlightedCellFromSortedIndex(pInfo, cell);
00196 }
00197 
00198 /********************************************************************************************
00199 >   bool BitmapExportPaletteControl::MsgMouseLeftButtonDown(ReDrawInfoType *pInfo)
00200     Author:     Jonathan_Payne (Xara Group Ltd) <camelotdev@xara.com>
00201     Created:    05/12/2000
00202     Inputs:     pInfo struct passed to parent dlg as part of the mouse message
00203     Returns:    true if the message resulted in a change to the selection else false
00204     Purpose:    Processes a mouse message for the palette control
00205 ********************************************************************************************/
00206 bool BitmapExportPaletteControl::MsgMouseLeftButtonDown(ReDrawInfoType *pInfo)
00207 {
00208     ERROR3IF(!m_WindowID, "Window ID not set");
00209 
00210     INT32 cell = GetCellFromPos(pInfo->pMousePos->x / m_nPixelSize, (pInfo->dy - pInfo->pMousePos->y) / m_nPixelSize);
00211 
00212     return SetSelectedCellFromSortedIndex(pInfo, cell);
00213 }
00214 
00215 /********************************************************************************************
00216 >   bool BitmapExportPaletteControl::MsgMouseRightButtonUp()
00217     Author:     Jonathan_Payne (Xara Group Ltd) <camelotdev@xara.com>
00218     Created:    5/12/2000
00219     Purpose:    Show palette's context sensitive menu
00220 ********************************************************************************************/
00221 void BitmapExportPaletteControl::MsgMouseRightButtonUp(ReDrawInfoType *pInfo, BmapPrevDlg *pBmapPrevDlg)
00222 {
00223     MsgMouseLeftButtonDown(pInfo);
00224 
00225     if (m_SelectedCell == INVALID_COLOUR_VALUE)
00226         return;
00227 
00228     //  User has right-clicked on the palette control. So, we have
00229     //  to construct and display the right-click palette menu.
00230     OpPalettePopupCommand::Init(this, pBmapPrevDlg);
00231 
00232     PaletteContextMenu* Menu = new PaletteContextMenu;
00233 
00234     //  If everything is OK, then show the menu.
00235     if( Menu != NULL )
00236         Menu->Show();
00237     else
00238         ERROR3( "Can't create PaletteContextMenu" );
00239 }
00240 
00241 /********************************************************************************************
00242 >   void BitmapExportPaletteControl::RedrawSelectedCell(ReDrawInfoType *pInfo)
00243     Author:     Jonathan_Payne (Xara Group Ltd) <camelotdev@xara.com>
00244     Created:    19/12/2000
00245     Inputs:     pInfo struct
00246     Purpose:    Redraws the selected cell, to be used after SetSelectedCell[Toggle]*()
00247                 functions
00248 ********************************************************************************************/
00249 void BitmapExportPaletteControl::RedrawSelectedCell(ReDrawInfoType *pInfo)
00250 {
00251     InvalidateCell(pInfo, m_SelectedCell);
00252 }
00253 
00254 void BitmapExportPaletteControl::InvalidateCell(ReDrawInfoType *pInfo, INT32 paletteIndex)
00255 {
00256     DocRect cellRect;
00257     ERROR3IF(!m_WindowID, "Window ID not set");
00258 
00259     GetRectForCell(paletteIndex, &cellRect, pInfo->dy);
00260 
00261     // Add the bodge factor
00262     cellRect.lo.y   -= m_nPixelSize;
00263     cellRect.hi.y   += m_nPixelSize;
00264     cellRect.hi.x   += m_nPixelSize * 2;
00265 
00266     DialogManager::InvalidateGadget(m_WindowID, _R(IDC_T2_PALETTE_CONTROL), pInfo, &cellRect);
00267 }
00268 
00269 /********************************************************************************************
00270 >   bool BitmapExportPaletteControl::SetSelectedCell(ReDrawInfoType *pInfo, INT32 paletteIndex)
00271     Author:     Jonathan_Payne (Xara Group Ltd) <camelotdev@xara.com>
00272     Created:    19/12/2000
00273     Inputs:     pInfo           - ReDrawInfoType struct
00274                 paletteIndex    - an index into the real palette
00275     Purpose:    Sets the selected cell in the palette
00276 ********************************************************************************************/
00277 bool BitmapExportPaletteControl::SetSelectedCell(ReDrawInfoType *pInfo, INT32 paletteIndex)
00278 {
00279     return SetSelectedCellFromSortedIndex(pInfo, m_Palette.RealValueToSortedValue(paletteIndex));
00280 }
00281 
00282 /********************************************************************************************
00283 >   bool BitmapExportPaletteControl::SetSelectedCellFromSortedIndex(ReDrawInfoType *pInfo, INT32 paletteIndex)
00284     Author:     Jonathan_Payne (Xara Group Ltd) <camelotdev@xara.com>
00285     Created:    19/12/2000
00286     Author:     Jonathan_Payne (Xara Group Ltd) <camelotdev@xara.com>
00287     Created:    19/12/2000
00288     Inputs:     pInfo           - ReDrawInfoType struct
00289                 paletteIndex    - an index into the sorted palette
00290     Purpose:    Sets the selected cell in the palette
00291 ********************************************************************************************/
00292 bool BitmapExportPaletteControl::SetSelectedCellFromSortedIndex(ReDrawInfoType *pInfo, INT32 paletteIndex)
00293 {
00294     if (paletteIndex == m_SelectedCell)
00295         return false;
00296 
00297     // Invalidate the old cell
00298     if (m_SelectedCell != INVALID_COLOUR_VALUE)
00299         InvalidateCell(pInfo, m_SelectedCell);
00300 
00301     m_SelectedCell = paletteIndex;
00302 
00303     // See if the mouse is in a valid cell
00304     if (m_SelectedCell == INVALID_COLOUR_VALUE)
00305         return true;
00306 
00307     // Invalidate the new cell so it will be redrawn
00308     InvalidateCell(pInfo, m_SelectedCell);
00309 
00310     return true;
00311 }
00312 
00313 bool BitmapExportPaletteControl::SetHighlightedCell(ReDrawInfoType *pInfo, INT32 paletteIndex)
00314 {
00315     return SetHighlightedCellFromSortedIndex(pInfo, m_Palette.RealValueToSortedValue(paletteIndex));
00316 }
00317 
00318 bool BitmapExportPaletteControl::SetHighlightedCellFromSortedIndex(ReDrawInfoType *pInfo, INT32 paletteIndex)
00319 {
00320     if (paletteIndex == m_MouseOverCell)
00321         return false;
00322 
00323     // Invalidate the old cell
00324     if (m_MouseOverCell != INVALID_COLOUR_VALUE)
00325         InvalidateCell(pInfo, m_MouseOverCell);
00326 
00327     m_MouseOverCell = paletteIndex;
00328 
00329     // See if the mouse is in a valid cell
00330     if (m_MouseOverCell == INVALID_COLOUR_VALUE)
00331         return true;
00332 
00333     // Invalidate the new cell so it will be redrawn
00334     InvalidateCell(pInfo, m_MouseOverCell);
00335 
00336     return true;
00337 }
00338 
00339 /********************************************************************************************
00340 >   void BitmapExportPaletteControl::RenderSoon()
00341     Author:     Jonathan_Payne (Xara Group Ltd) <camelotdev@xara.com>
00342     Created:    19/12/2000
00343     Purpose:    This function redraws the palette control by invaldating it so it is drawn
00344                 latter.  This is useful for functions that can't get a DC in the pInfo
00345                 struct.
00346 ********************************************************************************************/
00347 void BitmapExportPaletteControl::RenderSoon()
00348 {
00349     // Check the selection and mouse over colour are valid as the palette has probably changed
00350     if (m_SelectedCell > m_Palette.GetNumberOfColours())
00351         m_SelectedCell = INVALID_COLOUR_VALUE;
00352     if (m_MouseOverCell > m_Palette.GetNumberOfColours())
00353         m_MouseOverCell = INVALID_COLOUR_VALUE;
00354 
00355     DialogManager::InvalidateGadget(m_WindowID, _R(IDC_T2_PALETTE_CONTROL));
00356 }
00357 
00358 /********************************************************************************************
00359 >   void BitmapExportPaletteControl::Render(ReDrawInfoType *pInfo)
00360     Author:     Jonathan_Payne (Xara Group Ltd) <camelotdev@xara.com>
00361     Created:    19/12/2000
00362     Returns:    Draw the palette.  This assumes that the pInfo struct contains a DC to draw
00363                 with.
00364 ********************************************************************************************/
00365 void BitmapExportPaletteControl::Render(ReDrawInfoType *pInfo)
00366 {
00367     DocRect PaletteSize(0, 0, pInfo->dx, pInfo->dy);
00368 
00369     //  Create a RenderRegion so that we can draw the control
00370     RenderRegion *pRender = CreateOSRenderRegion(&PaletteSize, pInfo);
00371     if (pRender == 0)
00372         return; // Could not create a RenderRegion
00373 
00374     // Decide if we are going to render the palette
00375     if (!m_Palette.GetNumberOfColours())
00376     {
00377         // We are not rendering a palette so just draw a grey box
00378         RenderGrey(&PaletteSize, pRender);
00379     }
00380     else
00381     {
00382         // Check the selection and mouse over colour are valid
00383         if (m_SelectedCell > m_Palette.GetNumberOfColours())
00384             m_SelectedCell = INVALID_COLOUR_VALUE;
00385         if (m_MouseOverCell > m_Palette.GetNumberOfColours())
00386             m_MouseOverCell = INVALID_COLOUR_VALUE;
00387 
00388         // We are rendering a full palette
00389         RenderPalette(&PaletteSize, pRender, pInfo->dy, pInfo->pClipRect);
00390     }
00391 
00392     DestroyOSRenderRegion(pRender);
00393 }
00394 
00395 /********************************************************************************************
00396 >   void BitmapExportPaletteControl::RenderGrey(DocRect *pPaletteSize, RenderRegion *pRender)
00397     Author:     Jonathan_Payne (Xara Group Ltd) <camelotdev@xara.com>
00398     Created:    19/12/2000
00399     Purpose:    Render the palette's background in dialog background colour.
00400 ********************************************************************************************/
00401 void BitmapExportPaletteControl::RenderGrey(DocRect *pPaletteSize, RenderRegion *pRender)
00402 {
00403     DialogColourInfo DialogColours;
00404     pRender->SetFillColour(DialogColours.DialogBack());
00405     pRender->SetLineColour(COLOUR_TRANS);
00406     pRender->DrawRect(pPaletteSize);
00407 }
00408 
00409 void BitmapExportPaletteControl::GetRectForCell(INT32 cell, DocRect *pRect, INT32 controlHeight)
00410 {
00411     pRect->lo.x = (cell % m_nCellsPerLine) * m_nCellWidth;
00412     pRect->lo.y = controlHeight - (cell / m_nCellsPerLine) * m_nCellHeight - m_nCellHeight;
00413     pRect->hi.x = (cell % m_nCellsPerLine + 1) * m_nCellWidth - m_nPixelSize;
00414     pRect->hi.y = controlHeight - (cell / m_nCellsPerLine) * m_nCellHeight - m_nPixelSize;
00415 }
00416 
00417 void BitmapExportPaletteControl::RenderPalette(DocRect *pPaletteSize, RenderRegion *pRender, INT32 controlHeight,
00418                                                DocRect* pClipRect)
00419 {
00420     INT32 nColours = m_Palette.GetNumberOfColours();
00421 
00422     // See if the background needs rendering
00423     if (nColours < m_NumberOfColoursAtLastRedraw)
00424         RenderGrey(pPaletteSize, pRender);
00425 
00426     m_NumberOfColoursAtLastRedraw = nColours;
00427 
00428     pRender->SetLineColour(COLOUR_BLACK);
00429 
00430     DocRect cell;
00431 
00432     // Draw each cell in turn
00433     for (INT32 i = 0; i < nColours; ++i)
00434     {
00435         GetRectForCell(i, &cell, controlHeight);
00436         if (cell.IsIntersectedWith(*pClipRect))
00437         {
00438             BYTE r, g, b;
00439             r = m_Palette.GetRed(i);
00440             g = m_Palette.GetGreen(i);
00441             b = m_Palette.GetBlue(i);
00442             DrawCell(&cell, DocColour(r, g, b), m_Palette.GetFlags(i), pRender,
00443                 IsColourWebSafe(r, g, b), i == m_SelectedCell);
00444         }
00445     }
00446 
00447     // Draw the mouse over high light
00448     if (m_MouseOverCell != INVALID_COLOUR_VALUE)
00449     {
00450         GetRectForCell(m_MouseOverCell, &cell, controlHeight);
00451         pRender->SetFillColour(COLOUR_TRANS);
00452         pRender->SetLineColour(COLOUR_WHITE);
00453         pRender->DrawRect(&cell);
00454     }
00455 
00456 }
00457 
00458 void BitmapExportPaletteControl::SetSelectedColourToggleLocked()
00459 {
00460     m_Palette.SetFlags(m_SelectedCell, m_Palette.GetFlags(m_SelectedCell) ^ LOCKED_COLOUR);
00461     if (!GetSelectedColourLocked())
00462         BmapPrevDlg::m_pExportOptions->InvalidatePalette();
00463 }
00464 
00465 /********************************************************************************************
00466 >   void BitmapExportPaletteControl::MakeColourWebSafe(BYTE *pColour)
00467     Author:     Jonathan_Payne (Xara Group Ltd) <camelotdev@xara.com>
00468     Created:    12/12/2000
00469     Inputs:     A pointer to a colour value (in BYTE format)
00470     Purpose:    Makes a colour web safe by moving it to the closest multiple of 51
00471 ********************************************************************************************/
00472 void BitmapExportPaletteControl::MakeColourWebSafe(BYTE *pColour)
00473 {
00474     if (*pColour % 51 != 0)
00475     {
00476         if (*pColour % 51 > 20)
00477             // round up to nearest multiple of 51
00478             *pColour += (51 - *pColour % 51);
00479         else
00480             // round down to nearest multiple of 51
00481             *pColour -= *pColour % 51;
00482     }
00483 }
00484 
00485 /********************************************************************************************
00486 >   void BitmapExportPaletteControl::SetSelectedColourWebSafe()
00487     Author:     Jonathan_Payne (Xara Group Ltd) <camelotdev@xara.com>
00488     Created:    12/12/2000
00489     Purpose:    Makes the currently selected colour web safe
00490 ********************************************************************************************/
00491 void BitmapExportPaletteControl::SetSelectedColourWebSafe()
00492 {
00493     INT32 realIndex = m_Palette.SortedValueToRealValue(m_SelectedCell);
00494 
00495     ExtendedPalette *palette = BmapPrevDlg::m_pExportOptions->GetExtendedPalette();
00496     ERROR3IF(!palette, "There is no palette - This should never happen");
00497 
00498     if (!GetSelectedColourLocked())
00499         SetSelectedColourToggleLocked();
00500 
00501     palette->Data[realIndex].PreEditedRed   = palette->Data[realIndex].Red;
00502     palette->Data[realIndex].PreEditedGreen = palette->Data[realIndex].Green;
00503     palette->Data[realIndex].PreEditedBlue  = palette->Data[realIndex].Blue;
00504 
00505     MakeColourWebSafe(&palette->Data[realIndex].Red);
00506     MakeColourWebSafe(&palette->Data[realIndex].Green);
00507     MakeColourWebSafe(&palette->Data[realIndex].Blue);
00508 }
00509 
00510 bool BitmapExportPaletteControl::SetSelectedColourToggleTransparent()
00511 {
00512     m_Palette.SetFlags(m_SelectedCell, m_Palette.GetFlags(m_SelectedCell) ^ TRANSPARENT_COLOUR);
00513     // if we have turned off transp for the background return TRUE to let the caller know
00514     if (m_SelectedCell == 0 && ((m_Palette.GetFlags(m_SelectedCell) & TRANSPARENT_COLOUR) == 0))
00515         return true;
00516     else
00517         return false;
00518 }
00519 void BitmapExportPaletteControl::SetSelectedColourToggleDeleted()
00520 {
00521     m_Palette.SetFlags(m_SelectedCell, m_Palette.GetFlags(m_SelectedCell) ^ DELETED_COLOUR);
00522     if (GetSelectedColourDeleted())
00523         BmapPrevDlg::m_pExportOptions->MakePaletteEntryUnreadable(m_Palette.SortedValueToRealValue(m_SelectedCell));
00524     else
00525         BmapPrevDlg::m_pExportOptions->InvalidatePalette();
00526 }
00527 
00528 INT32 BitmapExportPaletteControl::GetSelectedColour()
00529 {
00530     return m_Palette.SortedValueToRealValue(m_SelectedCell);
00531 }
00532 
00533 INT32 BitmapExportPaletteControl::GetMouseOverColour()
00534 {
00535     return m_Palette.SortedValueToRealValue(m_MouseOverCell);
00536 }
00537 
00538 bool BitmapExportPaletteControl::GetSelectedColourLocked()
00539 {
00540     return ((m_Palette.GetFlags(m_SelectedCell) & LOCKED_COLOUR) != 0);
00541 }
00542 
00543 bool BitmapExportPaletteControl::IsColourWebSafe(BYTE r, BYTE g, BYTE b)
00544 {
00545     return (r % 51 == 0 && g % 51 == 0 && b % 51 == 0);
00546 }
00547 
00548 bool BitmapExportPaletteControl::GetSelectedColourWebSafe()
00549 {
00550     return IsColourWebSafe( m_Palette.GetRed(m_SelectedCell),
00551                             m_Palette.GetGreen(m_SelectedCell),
00552                             m_Palette.GetBlue(m_SelectedCell));
00553 }
00554 
00555 bool BitmapExportPaletteControl::GetSelectedColourTransparent()
00556 {
00557     return ((m_Palette.GetFlags(m_SelectedCell) & TRANSPARENT_COLOUR) != 0);
00558 }
00559 
00560 bool BitmapExportPaletteControl::GetSelectedColourDeleted()
00561 {
00562     return ((m_Palette.GetFlags(m_SelectedCell) & DELETED_COLOUR) != 0);
00563 }
00564 
00565 /********************************************************************************************
00566 >   void BitmapExportPaletteControl::DrawCell(DocRect *pCellRect, DocColour colour, INT32 flags,
00567                     RenderRegion *pRender, bool webSafe, bool selected, bool highlight)
00568     Author:     Jonathan_Payne (Xara Group Ltd) <camelotdev@xara.com>
00569     Created:    12/12/2000
00570     Purpose:    Draw a palette cell with the given options
00571     Inputs:     pCellRect   - The rect to draw the palette cell in
00572                 colour      - The colour of the palette entry to draw
00573                 flags       - The flags of that palette entry (locked, transparency, etc)
00574                 pRender     - The render region to render with (tested with an OS rr)
00575                 webSafe     - Is the colour web safe (ie do we draw the web safe mark)
00576                 selected    - Do we draw the cell as the selected cell?
00577 ********************************************************************************************/
00578 void BitmapExportPaletteControl::DrawCell(DocRect *pCellRect, DocColour colour, INT32 flags, RenderRegion *pRender,
00579                                                 bool webSafe, bool selected)
00580 {
00581     pRender->SetLineColour(COLOUR_BLACK);
00582     pRender->SetFillColour(colour);
00583     pRender->DrawRect(pCellRect);
00584 
00585     if (selected)
00586     {
00587         pRender->SetFillColour(COLOUR_TRANS);
00588 
00589         DocRect cell = *pCellRect; // make temp copy
00590 
00591         // Draw the outer line in white
00592         pRender->SetLineColour(COLOUR_WHITE);
00593         cell.Inflate(-1 * m_nPixelSize);
00594         pRender->DrawRect(&cell);
00595 
00596         // Draw the inner line in black
00597         pRender->SetLineColour(COLOUR_BLACK);
00598         cell.Inflate(-1 * m_nPixelSize);
00599         pRender->DrawRect(&cell);
00600     }
00601 
00602     if (flags & DELETED_COLOUR)
00603     {
00604         //  Draw a mark to show that this palette entry has been deleted
00605 
00606         // Draw a black line from top left to bottom right
00607         pRender->SetLineColour(COLOUR_BLACK);
00608         pRender->DrawLine(  DocCoord(pCellRect->lo.x, pCellRect->hi.y + m_nPixelSize),
00609                             DocCoord(pCellRect->hi.x + m_nPixelSize, pCellRect->lo.y));
00610 
00611         // Draw a white line from top right to bottom left
00612         pRender->SetLineColour(COLOUR_WHITE);
00613         pRender->DrawLine(  DocCoord(pCellRect->hi.x + m_nPixelSize, pCellRect->hi.y + m_nPixelSize),
00614                             DocCoord(pCellRect->lo.x + m_nPixelSize, pCellRect->lo.y + m_nPixelSize));
00615 
00616         return; // Stop before rending any other marks
00617     }
00618 
00619     if (flags & LOCKED_COLOUR)
00620     {
00621         //  Draw a mark to show that this palette entry has been
00622         //  edited by the user.
00623 
00624         pRender->SetLineColour(COLOUR_BLACK);
00625         pRender->SetFillColour(COLOUR_WHITE);
00626         
00627         // Draw a rectangle in the bottom left corner of the cell
00628         DocRect markRect;
00629         markRect.hi.x   = pCellRect->lo.x + m_nPixelSize * 2;
00630         markRect.lo.x   = pCellRect->lo.x;
00631         markRect.hi.y   = pCellRect->lo.y + m_nPixelSize * 2;
00632         markRect.lo.y   = pCellRect->lo.y;
00633         pRender->DrawRect(&markRect);
00634     }
00635 
00636     if (flags & TRANSPARENT_COLOUR)
00637     {
00638         //  Draw a mark to show that this palette entry is transparent
00639 
00640         pRender->SetLineColour(COLOUR_BLACK);
00641         pRender->SetFillColour(COLOUR_WHITE);
00642         
00643         // Draw a rectangle in the top left corner of the cell
00644         DocRect markRect;
00645         markRect.hi.x   = pCellRect->lo.x + m_nPixelSize * 2;
00646         markRect.lo.x   = pCellRect->lo.x;
00647         markRect.hi.y   = pCellRect->hi.y;
00648         markRect.lo.y   = pCellRect->hi.y - m_nPixelSize * 2;
00649         pRender->DrawRect(&markRect);
00650     }
00651     
00652     if (webSafe)
00653     {
00654         //  Draw a mark to show that this palette entry is web-safe
00655 
00656         pRender->SetLineColour(COLOUR_BLACK);
00657         pRender->SetFillColour(COLOUR_WHITE);
00658 
00659         DocRect markRect = *pCellRect;
00660         markRect.Inflate(-4 * m_nPixelSize);
00661         pRender->DrawRect(&markRect);
00662     }
00663 }

Generated on Sat Nov 10 03:44:26 2007 for Camelot by  doxygen 1.4.4