GRenderClickColour Class Reference

Special version of a GRenderClick that renders into a colour bitmap. It is used for colour picker hit-detection/pixel colour detection only. More...

#include <grndclik.h>

Inheritance diagram for GRenderClickColour:

GRenderClick GRenderDIB GRenderRegion RenderRegion ListItem CCObject SimpleCCObject GRenderClickColourNoPaper List of all members.

Public Member Functions

 GRenderClickColour (DocRect ClipRegion, Matrix ConvertMatrix, FIXED16 ViewScale, UINT32 Depth, double dpi)
 Constructor. Most important jobs are to set the VeryMono flag to FALSE, and to set m_DoCompression = TRUE to ensure correct handling of transparencies.
 ~GRenderClickColour ()
 Destructor. Simple cleanup, which involves calling our base classes.
virtual void DebugMe (INT32 Stretch)
 Dumps the current bitmap onto the current view window, so we can see what is going on. Do not call directly, use OSRenderBitmap::DebugMe.
Pixel32bpp GetCentrePixel32BPP ()
 This sexy little function is what makes my custom colour picker control read the TRUE 32-bit document colour.
Pixel32bpp GetAveragePixel32BPP ()
 To find the colour under the pointer, taking the differences of pixels around the centre pixel into account.

Protected Member Functions

virtual BitmapContents GetContents (BOOL JustMiddle)
 To investigate whether anything has been rendered into a bitmap-based render region. Don't call directly, use OSRenderBitmap::GetContents.

Private Member Functions

BOOL AttachDevice (View *, wxDC *, Spread *SpreadToAttach=NULL, bool fOwned=false)
 Most work done in base class, except for the creation of a CCDC member.
BOOL StartRender ()
 Most work done in base class, except for the calculation of the address & mask of the centre pixel.

Friends

class OSRenderBitmap

Detailed Description

Special version of a GRenderClick that renders into a colour bitmap. It is used for colour picker hit-detection/pixel colour detection only.

Author:
Chris_Snook (Xara Group Ltd) <camelotdev@xara.com>
Date:
27/10/99

Definition at line 165 of file grndclik.h.


Constructor & Destructor Documentation

GRenderClickColour::GRenderClickColour DocRect  ClipRegion,
Matrix  ConvertMatrix,
FIXED16  ViewScale,
UINT32  Depth,
double  dpi
 

Constructor. Most important jobs are to set the VeryMono flag to FALSE, and to set m_DoCompression = TRUE to ensure correct handling of transparencies.

Author:
Chris_Snook (Xara Group Ltd) <camelotdev@xara.com>
Date:
27/10/99
Parameters:
A clip region, conversion matrix, scale and bitmap depth. [INPUTS]
None [OUTPUTS]
Returns:
None
Do not call directly, use OSRenderBitmap::Create

Definition at line 157 of file grndclik.cpp.

00158     : GRenderClick(ClipRegion, ConvertMatrix, ViewScale, Depth, dpi)
00159 {
00160     RenderFlags.VeryMono = FALSE;               // simple black&white rendering NOT !!!!!
00161     RenderFlags.HitDetect = FALSE;
00162     m_DoCompression = TRUE;
00163 }

GRenderClickColour::~GRenderClickColour  ) 
 

Destructor. Simple cleanup, which involves calling our base classes.

Author:
Chris_Snook (Xara Group Ltd) <camelotdev@xara.com>
Date:
27/10/99

Definition at line 230 of file grndclik.cpp.

00231     : ~GRenderClick()
00232 {
00233 
00234 }


Member Function Documentation

BOOL GRenderClickColour::AttachDevice View pView,
wxDC *  DCToAttach,
Spread SpreadToAttach = NULL,
bool  fOwned = false
[private, virtual]
 

Most work done in base class, except for the creation of a CCDC member.

Author:
Chris_Snook (Xara Group Ltd) <camelotdev@xara.com>
Date:
27/10/99
Parameters:
pView is used for debug purposes only. DCToAttach is used as a [INPUTS] reference when making the bitmap.
Returns:
FALSE if failed (no mem for bitmap or CCDC), TRUE if OK

Reimplemented from GRenderClick.

Reimplemented in GRenderClickColourNoPaper.

Definition at line 664 of file grndclik.cpp.

00665 {
00666 
00667     // call base class first
00668     if (!GRenderDIB::AttachDevice(pView, DCToAttach, SpreadToAttach, fOwned))
00669         return FALSE;
00670 /*
00671     // now replace the usual RenderDC with our new one. This makes the type of the CCDC
00672     // correct, so Quality rendering works correctly, for example.
00673     TRY
00674     {
00675         // IMPORTANT: we 'borrow' the HDC from DCToAttach. We must take care when
00676         // deleting this not to delete the HDCs (see the constructor).
00677         RenderDC = new CCDC( DCToAttach, RENDERTYPE_COLOURBITMAP );
00678     }
00679     CATCH (CMemoryException, e)
00680     {
00681         // Ooer - not enough memory
00682         TRACEALL( _T("No memory for CCDC in GRenderClickColour::AttachDevice") );
00683         return FALSE;
00684     }
00685     END_CATCH
00686 */
00687     RenderDC = new wxBufferedDC() ;
00688     m_fOwned = true;
00689 
00690     return TRUE;
00691 }

void GRenderClickColour::DebugMe INT32  Stretch  )  [virtual]
 

Dumps the current bitmap onto the current view window, so we can see what is going on. Do not call directly, use OSRenderBitmap::DebugMe.

Author:
Chris_Snook (Xara Group Ltd) <camelotdev@xara.com>
Date:
27/10/99
Parameters:
How much you want the image stretched by [INPUTS]
See also:
OSRenderBitmap::DebugMe

Reimplemented from GRenderClick.

Definition at line 560 of file grndclik.cpp.

00561 {
00562 #if defined(_DEBUG) && 0        // GAT
00563     const INT32 w = WRect.right - WRect.left;
00564     const INT32 h = WRect.bottom - WRect.top;
00565 
00566     INT32 Offset = (Stretch/100) * w * (Stretch%100);
00567     Stretch = Stretch%100;
00568 
00569 //  DIBUtil::InvertAlpha(lpBitmapInfo, lpBits);
00570     DWORD oldComp = lpBitmapInfo->bmiHeader.biCompression;
00571     lpBitmapInfo->bmiHeader.biCompression = BI_RGB;
00572     INT32 ret = ::StretchDIBits( RenderDC->m_hDC, 0,0, w*Stretch, h*Stretch,
00573                         0,0,w,h,
00574                         lpBits, lpBitmapInfo,
00575                         DIB_RGB_COLORS,
00576                         SRCCOPY
00577                     );
00578     lpBitmapInfo->bmiHeader.biCompression = oldComp;
00579 //  DIBUtil::InvertAlpha(lpBitmapInfo, lpBits);
00580 #endif
00581 }

Pixel32bpp GRenderClickColour::GetAveragePixel32BPP  ) 
 

To find the colour under the pointer, taking the differences of pixels around the centre pixel into account.

Author:
Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
Date:
14/10/2004
Parameters:
- [INPUTS]
Pix - 32bpp value of average colour in GRenderClickColour bitmap [OUTPUTS]
Returns:
-
See also:
OSRenderBitmap::GetContents

Definition at line 478 of file grndclik.cpp.

00479 {
00480     Pixel32bpp Pix;
00481     INT32 Blue  = pMiddle [0];      // Give centre pixel more weight by initialising average
00482     INT32 Green = pMiddle [1];
00483     INT32 Red   = pMiddle [2];
00484     INT32 Alpha = pMiddle [3];
00485 
00486     // not in the middle - if any byte is not 0xFF then something must have been
00487     // rendered
00488     LPBYTE pSearch = pBits;
00489     UINT32 Count = pBitmapInfo->bmiHeader.biSizeImage >> 2;
00490     UINT32 size = Count+1;
00491     while (Count--)
00492     {
00493         Blue    += pSearch[0];
00494         Green   += pSearch[1];
00495         Red     += pSearch[2];
00496         Alpha   += pSearch[3];
00497 
00498         pSearch += 4;
00499     }
00500 
00501 //TRACEUSER( "Phil", _T("AvgPix1 B=%d G=%d R=%d A=%d\n"), Blue, Green, Red, Alpha);
00502     Pix.Blue    = Blue/size;
00503     Pix.Green   = Green/size;
00504     Pix.Red     = Red/size;
00505     Pix.Alpha   = Alpha/size;
00506 //TRACEUSER( "Phil", _T("AvgPix2 B=%d G=%d R=%d A=%d\n"), Pix.Blue, Pix.Green, Pix.Red, Pix.Alpha);
00507 
00508     return Pix;
00509 }

Pixel32bpp GRenderClickColour::GetCentrePixel32BPP  ) 
 

This sexy little function is what makes my custom colour picker control read the TRUE 32-bit document colour.

Author:
Chris_Snook (Xara Group Ltd) <camelotdev@xara.com>
Date:
27/10/99
Parameters:
Pix --- reference to variable that colour information will be returned in. [INPUTS] This is created internally by the custom colour picker control.
Pix (via reference) [OUTPUTS]
See also:
NodeRenderableInk::FindSimpleAtPointForColourPicker ccolpick.cpp

Definition at line 447 of file grndclik.cpp.

00448 {
00449     Pixel32bpp Pix;
00450     Pix.Alpha = 0;              // Generally there is no alpha channel, so set it to a default
00451 
00452     // grab the centre pixels TRUE 32-bit value ....
00453     
00454     Pix.Blue = pMiddle [0];     // pointer to byte of centre pixel
00455     Pix.Green = pMiddle [1];
00456     Pix.Red = pMiddle [2];
00457     Pix.Alpha = pMiddle [3];
00458 
00459     return Pix;
00460 }

BitmapContents GRenderClickColour::GetContents BOOL  JustMiddle  )  [protected, virtual]
 

To investigate whether anything has been rendered into a bitmap-based render region. Don't call directly, use OSRenderBitmap::GetContents.

Author:
Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com> (Phil 16/03/2004)
Date:
15/11/94
Parameters:
If justmiddle is TRUE, only checks on the centre pixel will be done (which [INPUTS] is faster).
None [OUTPUTS]
Returns:
BITMAPCONTENTS_CENTRE if centre pixel is set, _ANY if any pixel is set, _NONE if none and _ERROR if failed for some reason.
See also:
OSRenderBitmap::GetContents

Reimplemented from GRenderClick.

Definition at line 391 of file grndclik.cpp.

00392 {
00393     RECT UsedRect;
00394 
00395     if (
00396         HaveRenderedSomething &&
00397         (GetDrawContext()->GetChangedBBox( &UsedRect ))
00398        )
00399     {
00400         if (
00401             (UsedRect.right > UsedRect.left) ||
00402             (UsedRect.top < UsedRect.bottom)
00403            )
00404         {
00405             // something has been drawn - is it the middle?
00406             BYTE middleT = pMiddle[3];              // Read transp channel
00407             if (middleT < GRenderRegion::ClickTranspLimit)
00408                 return BITMAPCONTENTS_CENTRE;
00409 
00410             // if only interested in centre pixel then we're out of here
00411             if (JustMiddle)
00412                 return BITMAPCONTENTS_NONE;
00413 
00414             // not in the middle - if any byte is not 0xFF then something must have been
00415             // rendered
00416             LPBYTE pSearch = pBits;
00417             size_t Count = pBitmapInfo->bmiHeader.biSizeImage >> 2;
00418             while (Count--)
00419             {
00420                 if (pSearch[3] < GRenderRegion::ClickTranspLimit)
00421                     return BITMAPCONTENTS_ANY;
00422                 pSearch += 4;
00423             }
00424             // else nothing rendered
00425         }
00426     }
00427 
00428     return BITMAPCONTENTS_NONE;
00429 }

BOOL GRenderClickColour::StartRender void   )  [private, virtual]
 

Most work done in base class, except for the calculation of the address & mask of the centre pixel.

Author:
Chris_Snook (Xara Group Ltd) <camelotdev@xara.com>
Date:
15/11/94
Returns:
TRUE if worked, FALSE if failed.

Reimplemented from GRenderClick.

Definition at line 792 of file grndclik.cpp.

00793 {
00794     if (!GRenderDIB::StartRender())
00795         return FALSE;
00796 
00797     // work out the address & mask of the centre pixel
00798     const INT32 w = WRect.width;
00799     const INT32 h = WRect.height;
00800 
00801     UINT32 scanlineSize = DIBUtil::ScanlineSize( w, 32 );
00802     
00803     // address is pretty easy
00804     GRenderClick::pMiddle = pBits + (h/2)*scanlineSize;
00805     GRenderClick::pMiddle += (w/2) * 32/8;                  // Bytes per pixel
00806 
00807     // The following is immaterial in 32BPP bitmaps...
00808     // bit within byte is also reasonably straight-forward (and should be independent of
00809     // byte-sex) 
00810     MiddleMask = (BYTE) ( (INT32)0x80 >> ((w/2)&7) );
00811 
00812     // If we have been asked to clear out the contents of the bmp, then do it
00813     if (ClearOnStart)
00814     {
00815         // Set it to white
00816         if (pBits!=NULL)
00817             memset(pBits, 0xFF, pBitmapInfo->bmiHeader.biSizeImage);
00818         
00819         // Dont do it next time please
00820         ClearOnStart = FALSE;
00821     }
00822 
00823     return TRUE;
00824 }


Friends And Related Function Documentation

friend class OSRenderBitmap [friend]
 

Reimplemented from GRenderClick.

Reimplemented in GRenderClickColourNoPaper.

Definition at line 167 of file grndclik.h.


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