BitmapExportPaletteControl Class Reference

#include <bmpalctrl.h>

Inheritance diagram for BitmapExportPaletteControl:

CCObject SimpleCCObject List of all members.

Public Types

enum  { INVALID_COLOUR_VALUE = -1 }

Public Member Functions

 BitmapExportPaletteControl ()
 ~BitmapExportPaletteControl ()
void Init (CWindowID wid)
void SetCurrentSortType (BitmapExportPaletteInterface::PaletteSortType newSortType)
void SetSelectedColourToggleLocked ()
void SetSelectedColourWebSafe ()
bool SetSelectedColourToggleTransparent ()
void SetSelectedColourToggleDeleted ()
bool SetSelectedCell (ReDrawInfoType *pInfo, INT32 paletteIndex)
bool SetHighlightedCell (ReDrawInfoType *pInfo, INT32 paletteIndex)
BitmapExportPaletteInterface::PaletteSortType GetCurrentSortType ()
INT32 GetSelectedColour ()
INT32 GetMouseOverColour ()
bool GetSelectedColourLocked ()
bool GetSelectedColourWebSafe ()
bool GetSelectedColourTransparent ()
bool GetSelectedColourDeleted ()
void MsgMouseMove (ReDrawInfoType *pInfo)
bool MsgMouseLeftButtonDown (ReDrawInfoType *pInfo)
void MsgMouseRightButtonUp (ReDrawInfoType *pInfo, BmapPrevDlg *pBmapPrevDlg)
void Render (ReDrawInfoType *pInfo)
void RenderSoon ()
void RedrawSelectedCell (ReDrawInfoType *pInfo)

Private Member Functions

 CC_DECLARE_MEMDUMP (BitmapExportPaletteControl)
INT32 GetCellFromPos (INT32 x, INT32 y)
void RenderGrey (DocRect *pPaletteSize, RenderRegion *pRender)
void RenderPalette (DocRect *pPaletteSize, RenderRegion *pRender, INT32 controlHeight, DocRect *pClipRect)
void GetRectForCell (INT32 cell, DocRect *rect, INT32 controlHeight)
void InvalidateCell (ReDrawInfoType *pInfo, INT32 paletteIndex)
void DrawCell (DocRect *rect, DocColour colour, INT32 flags, RenderRegion *pRender, bool webSafe, bool selected)
bool IsColourWebSafe (BYTE r, BYTE g, BYTE b)
void MakeColourWebSafe (BYTE *pColour)
bool SetSelectedCellFromSortedIndex (ReDrawInfoType *pInfo, INT32 paletteIndex)
bool SetHighlightedCellFromSortedIndex (ReDrawInfoType *pInfo, INT32 paletteIndex)

Private Attributes

INT32 m_MouseOverCell
INT32 m_SelectedCell
BitmapExportPaletteInterface m_Palette
CWindowID m_WindowID
INT32 m_nPixelSize
INT32 m_nCellWidthPixels
INT32 m_nCellHeightPixels
INT32 m_nCellWidth
INT32 m_nCellHeight
INT32 m_nCellsPerLine
INT32 m_NumberOfColoursAtLastRedraw

Detailed Description

Definition at line 125 of file bmpalctrl.h.


Member Enumeration Documentation

anonymous enum
 

Enumerator:
INVALID_COLOUR_VALUE 

Definition at line 150 of file bmpalctrl.h.

00150          {
00151         INVALID_COLOUR_VALUE    = -1 // A value that can never be a colour index
00152     };


Constructor & Destructor Documentation

BitmapExportPaletteControl::BitmapExportPaletteControl  ) 
 

Definition at line 129 of file bmpalctrl.cpp.

BitmapExportPaletteControl::~BitmapExportPaletteControl  ) 
 

Definition at line 143 of file bmpalctrl.cpp.

00144 {
00145 }


Member Function Documentation

BitmapExportPaletteControl::CC_DECLARE_MEMDUMP BitmapExportPaletteControl   )  [private]
 

void BitmapExportPaletteControl::DrawCell DocRect rect,
DocColour  colour,
INT32  flags,
RenderRegion pRender,
bool  webSafe,
bool  selected
[private]
 

Definition at line 578 of file bmpalctrl.cpp.

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 }

INT32 BitmapExportPaletteControl::GetCellFromPos INT32  x,
INT32  y
[private]
 

Definition at line 177 of file bmpalctrl.cpp.

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 }

BitmapExportPaletteInterface::PaletteSortType BitmapExportPaletteControl::GetCurrentSortType  ) 
 

Definition at line 165 of file bmpalctrl.cpp.

00166 {
00167     return m_Palette.GetPaletteSortType();
00168 }

INT32 BitmapExportPaletteControl::GetMouseOverColour  ) 
 

Definition at line 533 of file bmpalctrl.cpp.

00534 {
00535     return m_Palette.SortedValueToRealValue(m_MouseOverCell);
00536 }

void BitmapExportPaletteControl::GetRectForCell INT32  cell,
DocRect rect,
INT32  controlHeight
[private]
 

Definition at line 409 of file bmpalctrl.cpp.

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 }

INT32 BitmapExportPaletteControl::GetSelectedColour  ) 
 

Definition at line 528 of file bmpalctrl.cpp.

00529 {
00530     return m_Palette.SortedValueToRealValue(m_SelectedCell);
00531 }

bool BitmapExportPaletteControl::GetSelectedColourDeleted  ) 
 

Definition at line 560 of file bmpalctrl.cpp.

00561 {
00562     return ((m_Palette.GetFlags(m_SelectedCell) & DELETED_COLOUR) != 0);
00563 }

bool BitmapExportPaletteControl::GetSelectedColourLocked  ) 
 

Definition at line 538 of file bmpalctrl.cpp.

00539 {
00540     return ((m_Palette.GetFlags(m_SelectedCell) & LOCKED_COLOUR) != 0);
00541 }

bool BitmapExportPaletteControl::GetSelectedColourTransparent  ) 
 

Definition at line 555 of file bmpalctrl.cpp.

00556 {
00557     return ((m_Palette.GetFlags(m_SelectedCell) & TRANSPARENT_COLOUR) != 0);
00558 }

bool BitmapExportPaletteControl::GetSelectedColourWebSafe  ) 
 

Definition at line 548 of file bmpalctrl.cpp.

void BitmapExportPaletteControl::Init CWindowID  wid  )  [inline]
 

Definition at line 157 of file bmpalctrl.h.

00157 { m_WindowID = wid; };

void BitmapExportPaletteControl::InvalidateCell ReDrawInfoType pInfo,
INT32  paletteIndex
[private]
 

Definition at line 254 of file bmpalctrl.cpp.

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 }

bool BitmapExportPaletteControl::IsColourWebSafe BYTE  r,
BYTE  g,
BYTE  b
[private]
 

Definition at line 543 of file bmpalctrl.cpp.

00544 {
00545     return (r % 51 == 0 && g % 51 == 0 && b % 51 == 0);
00546 }

void BitmapExportPaletteControl::MakeColourWebSafe BYTE *  pColour  )  [private]
 

Definition at line 472 of file bmpalctrl.cpp.

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 }

bool BitmapExportPaletteControl::MsgMouseLeftButtonDown ReDrawInfoType pInfo  ) 
 

Definition at line 206 of file bmpalctrl.cpp.

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 }

void BitmapExportPaletteControl::MsgMouseMove ReDrawInfoType pInfo  ) 
 

Definition at line 191 of file bmpalctrl.cpp.

00192 {
00193     INT32 cell = GetCellFromPos(pInfo->pMousePos->x / m_nPixelSize, (pInfo->dy - pInfo->pMousePos->y) / m_nPixelSize);
00194 
00195     SetHighlightedCellFromSortedIndex(pInfo, cell);
00196 }

void BitmapExportPaletteControl::MsgMouseRightButtonUp ReDrawInfoType pInfo,
BmapPrevDlg pBmapPrevDlg
 

Definition at line 221 of file bmpalctrl.cpp.

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 }

void BitmapExportPaletteControl::RedrawSelectedCell ReDrawInfoType pInfo  ) 
 

Definition at line 249 of file bmpalctrl.cpp.

00250 {
00251     InvalidateCell(pInfo, m_SelectedCell);
00252 }

void BitmapExportPaletteControl::Render ReDrawInfoType pInfo  ) 
 

Definition at line 365 of file bmpalctrl.cpp.

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 }

void BitmapExportPaletteControl::RenderGrey DocRect pPaletteSize,
RenderRegion pRender
[private]
 

Definition at line 401 of file bmpalctrl.cpp.

00402 {
00403     DialogColourInfo DialogColours;
00404     pRender->SetFillColour(DialogColours.DialogBack());
00405     pRender->SetLineColour(COLOUR_TRANS);
00406     pRender->DrawRect(pPaletteSize);
00407 }

void BitmapExportPaletteControl::RenderPalette DocRect pPaletteSize,
RenderRegion pRender,
INT32  controlHeight,
DocRect pClipRect
[private]
 

Definition at line 417 of file bmpalctrl.cpp.

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 }

void BitmapExportPaletteControl::RenderSoon  ) 
 

Definition at line 347 of file bmpalctrl.cpp.

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 }

void BitmapExportPaletteControl::SetCurrentSortType BitmapExportPaletteInterface::PaletteSortType  newSortType  ) 
 

Definition at line 154 of file bmpalctrl.cpp.

00155 {
00156     m_Palette.SetPaletteSortType(newSortType);
00157 }

bool BitmapExportPaletteControl::SetHighlightedCell ReDrawInfoType pInfo,
INT32  paletteIndex
 

Definition at line 313 of file bmpalctrl.cpp.

00314 {
00315     return SetHighlightedCellFromSortedIndex(pInfo, m_Palette.RealValueToSortedValue(paletteIndex));
00316 }

bool BitmapExportPaletteControl::SetHighlightedCellFromSortedIndex ReDrawInfoType pInfo,
INT32  paletteIndex
[private]
 

Definition at line 318 of file bmpalctrl.cpp.

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 }

bool BitmapExportPaletteControl::SetSelectedCell ReDrawInfoType pInfo,
INT32  paletteIndex
 

Definition at line 277 of file bmpalctrl.cpp.

00278 {
00279     return SetSelectedCellFromSortedIndex(pInfo, m_Palette.RealValueToSortedValue(paletteIndex));
00280 }

bool BitmapExportPaletteControl::SetSelectedCellFromSortedIndex ReDrawInfoType pInfo,
INT32  paletteIndex
[private]
 

Definition at line 292 of file bmpalctrl.cpp.

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 }

void BitmapExportPaletteControl::SetSelectedColourToggleDeleted  ) 
 

Definition at line 519 of file bmpalctrl.cpp.

void BitmapExportPaletteControl::SetSelectedColourToggleLocked  ) 
 

Definition at line 458 of file bmpalctrl.cpp.

bool BitmapExportPaletteControl::SetSelectedColourToggleTransparent  ) 
 

Definition at line 510 of file bmpalctrl.cpp.

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 }

void BitmapExportPaletteControl::SetSelectedColourWebSafe  ) 
 

Definition at line 491 of file bmpalctrl.cpp.

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 }


Member Data Documentation

INT32 BitmapExportPaletteControl::m_MouseOverCell [private]
 

Definition at line 131 of file bmpalctrl.h.

INT32 BitmapExportPaletteControl::m_nCellHeight [private]
 

Definition at line 143 of file bmpalctrl.h.

INT32 BitmapExportPaletteControl::m_nCellHeightPixels [private]
 

Definition at line 141 of file bmpalctrl.h.

INT32 BitmapExportPaletteControl::m_nCellsPerLine [private]
 

Definition at line 144 of file bmpalctrl.h.

INT32 BitmapExportPaletteControl::m_nCellWidth [private]
 

Definition at line 142 of file bmpalctrl.h.

INT32 BitmapExportPaletteControl::m_nCellWidthPixels [private]
 

Definition at line 140 of file bmpalctrl.h.

INT32 BitmapExportPaletteControl::m_nPixelSize [private]
 

Definition at line 139 of file bmpalctrl.h.

INT32 BitmapExportPaletteControl::m_NumberOfColoursAtLastRedraw [private]
 

Definition at line 146 of file bmpalctrl.h.

BitmapExportPaletteInterface BitmapExportPaletteControl::m_Palette [private]
 

Definition at line 134 of file bmpalctrl.h.

INT32 BitmapExportPaletteControl::m_SelectedCell [private]
 

Definition at line 132 of file bmpalctrl.h.

CWindowID BitmapExportPaletteControl::m_WindowID [private]
 

Definition at line 136 of file bmpalctrl.h.


The documentation for this class was generated from the following files:
Generated on Sat Nov 10 03:51:17 2007 for Camelot by  doxygen 1.4.4