grndclik.cpp

Go to the documentation of this file.
00001 // $Id: grndclik.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 
00099 // classes to render into a bitmap for click detection/colour detection
00100 
00101 /*
00102 */
00103 
00104 #include "camtypes.h"
00105 #include "grndclik.h"
00106 #include "ccdc.h"
00107 //#include "dibutil.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00108 
00109 CC_IMPLEMENT_DYNAMIC( GRenderClick, GRenderDIB )
00110 CC_IMPLEMENT_DYNAMIC( GRenderClickColour, GRenderClick )
00111 CC_IMPLEMENT_DYNAMIC( GRenderClickColourNoPaper, GRenderClickColour )
00112 
00113 #define new CAM_DEBUG_NEW
00114 
00115 /********************************************************************************************
00116 
00117 >   GRenderClick::GRenderClick( DocRect ClipRegion, Matrix ConvertMatrix, FIXED16 ViewScale, UINT32 Depth, double dpi)
00118 
00119     Author:     Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
00120     Created:    15/11/94
00121     Inputs:     A clip region, conversion matrix, scale and bitmap depth.
00122     Outputs:    None
00123     Returns:    None
00124     Purpose:    Constructor. Most important job is to set the VeryMono flag.
00125                 Do not call directly, use OSRenderBitmap::Create
00126                 INT32 dpi changed to double dpi (12/12/95) to improve the range of values allowed
00127                 at the < 1000dpi settings that we will be using.
00128 
00129 ********************************************************************************************/
00130 
00131 GRenderClick::GRenderClick( DocRect ClipRegion, Matrix ConvertMatrix, FIXED16 ViewScale, UINT32 Depth, double dpi)
00132     : GRenderDIB(ClipRegion, ConvertMatrix, ViewScale, Depth, dpi)
00133 {
00134     pMiddle = NULL;                             // just in case used before set up
00135     RenderFlags.VeryMono = TRUE;                // simple black&white rendering
00136     ClearOnStart = FALSE;
00137 }
00138 
00139 
00140 
00141 /********************************************************************************************
00142 
00143 >   GRenderClickColour::GRenderClickColour( DocRect ClipRegion, Matrix ConvertMatrix, FIXED16 ViewScale, UINT32 Depth, double dpi)
00144 
00145     Author:     Chris_Snook (Xara Group Ltd) <camelotdev@xara.com>
00146     Created:    27/10/99
00147     Inputs:     A clip region, conversion matrix, scale and bitmap depth.
00148     Outputs:    None
00149     Returns:    None
00150     Purpose:    Constructor. Most important jobs are to set the VeryMono flag to FALSE, and
00151                 to set m_DoCompression = TRUE to ensure correct handling of transparencies.
00152                 
00153                 Do not call directly, use OSRenderBitmap::Create
00154 
00155 ********************************************************************************************/
00156 
00157 GRenderClickColour::GRenderClickColour( DocRect ClipRegion, Matrix ConvertMatrix, FIXED16 ViewScale, UINT32 Depth, double dpi)
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 }
00164 
00165 
00166 
00167 /********************************************************************************************
00168 
00169 >   GRenderClickColourNoPaper::GRenderClickColourNoPaper( DocRect ClipRegion, Matrix ConvertMatrix, FIXED16 ViewScale, UINT32 Depth, double dpi)
00170 
00171     Author:     Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
00172     Created:    17/03/2004
00173     Inputs:     A clip region, conversion matrix, scale and bitmap depth.
00174     Outputs:    None
00175     Returns:    None
00176     Purpose:    Constructor. Most important jobs are to set the VeryMono flag to FALSE, and
00177                 to set m_DoCompression = TRUE to ensure correct handling of transparencies.
00178                 
00179                 Do not call directly, use OSRenderBitmap::Create
00180 
00181 ********************************************************************************************/
00182 
00183 GRenderClickColourNoPaper::GRenderClickColourNoPaper( DocRect ClipRegion, Matrix ConvertMatrix, FIXED16 ViewScale, UINT32 Depth, double dpi)
00184     : GRenderClickColour(ClipRegion, ConvertMatrix, ViewScale, Depth, dpi)
00185 {
00186     RenderFlags.VeryMono = FALSE;               // simple black&white rendering NOT !!!!!
00187     RenderFlags.HitDetect = TRUE;
00188     m_DoCompression = TRUE;
00189     ClearOnStart = FALSE;
00190 }
00191 
00192 
00193 
00194 /********************************************************************************************
00195 
00196 >   GRenderClick::~GRenderClick()
00197 
00198     Author:     Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
00199     Created:    15/11/94
00200     Purpose:    Destructor. Simple cleanup, which involves deleting the RenderDC.
00201 
00202 ********************************************************************************************/
00203 
00204 GRenderClick::~GRenderClick()
00205 {
00206     // Free up the bitmap here, as the call to FreeLPBits in the
00207     // GRenderDIB will not call the correct version (the virtual-ness will be
00208     // broken as it is called from a destructor
00209     if (pBitmapInfo!=NULL)
00210     {
00211 //      FreeLPBits( lpBitmapInfo, lpBits );
00212         FreeOffscreenState();
00213         pBitmapInfo = NULL;
00214         pBits = NULL;
00215     }
00216 }
00217 
00218 
00219 
00220 /********************************************************************************************
00221 
00222 >   GRenderClickColour::~GRenderClickColour ()
00223 
00224     Author:     Chris_Snook (Xara Group Ltd) <camelotdev@xara.com>
00225     Created:    27/10/99
00226     Purpose:    Destructor. Simple cleanup, which involves calling our base classes.
00227 
00228 ********************************************************************************************/
00229 
00230 GRenderClickColour::~GRenderClickColour ()
00231 //  : ~GRenderClick()
00232 {
00233 
00234 }
00235 
00236 
00237 
00238 /********************************************************************************************
00239 
00240 >   GRenderClickColourNoPaper::~GRenderClickColourNoPaper()
00241 
00242     Author:     Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
00243     Created:    17/03/2004
00244     Purpose:    Destructor. Simple cleanup, which involves calling our base classes.
00245 
00246 ********************************************************************************************/
00247 
00248 GRenderClickColourNoPaper::~GRenderClickColourNoPaper()
00249 //  : ~GRenderClick()
00250 {
00251 
00252 }
00253 
00254 
00255 
00256 
00257 /********************************************************************************************
00258 
00259 >   BOOL GRenderClick::ImmediateRender()
00260 
00261     Author:     Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
00262     Created:    18/03/2004
00263     Inputs:     -
00264     Outputs:    -
00265     Returns:    TRUE if current clip rect is within view (ie whether to render or not).
00266     Purpose:    Used to Draw something immediately.
00267     Errors:     -
00268     SeeAlso:    -
00269 
00270 ********************************************************************************************/
00271 
00272 BOOL GRenderClick::ImmediateRender()
00273 {
00274     RenderFlags.bImmediateRender = TRUE;
00275     if (!StartRender())
00276         return FALSE;
00277 
00278     // Set no funny attributes - let the hit test rendering do all that
00279 
00280     return TRUE;
00281 }
00282 
00283 
00284 
00285 /********************************************************************************************
00286 
00287 >   virtual void GRenderClick::SetClean(BOOL bResetChangedBounds, BOOL FillWhite)
00288 
00289     Author:     Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
00290     Created:    15/11/94
00291     Inputs:     FillWhite TRUE for fill with white, FALSE to leave contents alone.
00292     Purpose:    Clears out the RR, both logically and (optionally) physically). 
00293 
00294 ********************************************************************************************/
00295 
00296 void GRenderClick::SetClean(BOOL bResetChangedBounds, BOOL FillWhite)
00297 {
00298     // Do the normal cleaning process
00299     GRenderDIB::SetClean(bResetChangedBounds, FillWhite);
00300 
00301     // and if asked, mark the rr as needing clearing
00302     ClearOnStart = FillWhite;
00303 
00304     // Damn well clear it NOW!
00305     if (ClearOnStart)
00306     {
00307         // Set it to white
00308         if (pBits!=NULL)
00309             memset(pBits, 0xFF, pBitmapInfo->bmiHeader.biSizeImage);
00310         
00311         // Dont do it next time please
00312         ClearOnStart = FALSE;
00313     }
00314 }
00315 
00316 
00317 
00318 /********************************************************************************************
00319 
00320 >   BitmapContents GRenderClick::GetContents( BOOL JustMiddle )
00321 
00322     Author:     Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
00323     Created:    15/11/94
00324     Inputs:     If justmiddle is TRUE, only checks on the centre pixel will be done (which
00325                 is faster).
00326     Outputs:    None
00327     Returns:    BITMAPCONTENTS_CENTRE if centre pixel is set, _ANY if any pixel is set,
00328                 _NONE if none and _ERROR if failed for some reason.
00329     Purpose:    To investigate whether anything has been rendered into a bitmap-based
00330                 render region. Don't call directly, use OSRenderBitmap::GetContents
00331     SeeAlso:    OSRenderBitmap::GetContents
00332 
00333 ********************************************************************************************/
00334 
00335 BitmapContents GRenderClick::GetContents( BOOL JustMiddle )
00336 {
00337     RECT UsedRect;
00338 
00339     if (
00340         HaveRenderedSomething &&
00341         (GetDrawContext()->GetChangedBBox( &UsedRect ))
00342        )
00343     {
00344         if (
00345             (UsedRect.right > UsedRect.left) ||
00346             (UsedRect.top < UsedRect.bottom)
00347            )
00348         {
00349             // something has been drawn - is it the middle?
00350             if ( (*pMiddle & MiddleMask) == 0)
00351                 return BITMAPCONTENTS_CENTRE;
00352 
00353             // if only interested in centre pixel then we're out of here
00354             if (JustMiddle)
00355                 return BITMAPCONTENTS_NONE;
00356 
00357             // not in the middle - if any byte is not 0xFF then something must have been
00358             // rendered
00359             LPDWORD Search = (LPDWORD)pBits;
00360             size_t Count = pBitmapInfo->bmiHeader.biSizeImage >> 2;
00361             while (Count--)
00362             {
00363                 if (*Search != 0xFFFFFFFF)
00364                     return BITMAPCONTENTS_ANY;
00365                 Search++;
00366             }
00367             // else nothing rendered
00368         }
00369     }
00370 
00371     return BITMAPCONTENTS_NONE;
00372 }
00373 
00374 /********************************************************************************************
00375 
00376 >   BitmapContents GRenderClickColour::GetContents( BOOL JustMiddle )
00377 
00378     Author:     Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>     (Phil 16/03/2004)
00379     Created:    15/11/94
00380     Inputs:     If justmiddle is TRUE, only checks on the centre pixel will be done (which
00381                 is faster).
00382     Outputs:    None
00383     Returns:    BITMAPCONTENTS_CENTRE if centre pixel is set, _ANY if any pixel is set,
00384                 _NONE if none and _ERROR if failed for some reason.
00385     Purpose:    To investigate whether anything has been rendered into a bitmap-based
00386                 render region. Don't call directly, use OSRenderBitmap::GetContents
00387     SeeAlso:    OSRenderBitmap::GetContents
00388 
00389 ********************************************************************************************/
00390 
00391 BitmapContents GRenderClickColour::GetContents( BOOL JustMiddle )
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 }
00430 
00431 /********************************************************************************************
00432 
00433 >   Pixel32bpp GRenderClickColour::GetCentrePixel32bpp()
00434 
00435     Author:     Chris_Snook (Xara Group Ltd) <camelotdev@xara.com>
00436     Created:    27/10/99
00437     Inputs:     Pix --- reference to variable that colour information will be returned in.
00438                         This is created internally by the custom colour picker control.
00439     Outputs:    Pix (via reference)
00440     Purpose:    This sexy little function is what makes my custom colour picker control
00441                 read the TRUE 32-bit document colour.
00442     SeeAlso:    NodeRenderableInk::FindSimpleAtPointForColourPicker
00443                 ccolpick.cpp
00444 
00445 ********************************************************************************************/
00446 
00447 Pixel32bpp GRenderClickColour::GetCentrePixel32BPP()
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 }
00461 
00462 
00463 /********************************************************************************************
00464 
00465 >   Pixel32bpp GRenderClickColour::GetAveragePixel32BPP()
00466 
00467     Author:     Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
00468     Created:    14/10/2004
00469     Inputs:     -
00470     Outputs:    Pix - 32bpp value of average colour in GRenderClickColour bitmap
00471     Returns:    -
00472     Purpose:    To find the colour under the pointer, taking the differences of pixels
00473                 around the centre pixel into account
00474     SeeAlso:    OSRenderBitmap::GetContents
00475 
00476 ********************************************************************************************/
00477 
00478 Pixel32bpp GRenderClickColour::GetAveragePixel32BPP()
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 }
00510 
00511 
00512 /********************************************************************************************
00513 
00514 >   void GRenderClick::DebugMe( INT32 Stretch )
00515 
00516     Author:     Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
00517     Created:    17/11/94
00518     Inputs:     How much you want the image stretched by
00519     Purpose:    Dupms the current bitmap onto the current view window, so we can see what
00520                 is going on. Do not call directly, use OSRenderBitmap::DebugMe
00521     SeeAlso:    OSRenderBitmap::DebugMe
00522 
00523 ********************************************************************************************/
00524 
00525 void GRenderClick::DebugMe( INT32 Stretch )
00526 {
00527 #if defined(_DEBUG) && 0        // GAT
00528     DWORD *rgb = (DWORD*)lpBitmapInfo->bmiColors;
00529 
00530     rgb[0] = RGB(0,0,0);
00531     rgb[1] = RGB(255,255,255);
00532 
00533     const INT32 w = WRect.width;
00534     const INT32 h = WRect.height;
00535 
00536     ::StretchDIBits( RenderDC->m_hDC, 0,0, w*Stretch, h*Stretch,
00537                         0,0,w,h,
00538                         lpBits, lpBitmapInfo,
00539                         DIB_RGB_COLORS,
00540                         SRCCOPY
00541                     );
00542 #endif
00543 }
00544 
00545 
00546 
00547 /********************************************************************************************
00548 
00549 >   void GRenderClickColour::DebugMe( INT32 Stretch )
00550 
00551     Author:     Chris_Snook (Xara Group Ltd) <camelotdev@xara.com>
00552     Created:    27/10/99
00553     Inputs:     How much you want the image stretched by
00554     Purpose:    Dumps the current bitmap onto the current view window, so we can see what
00555                 is going on. Do not call directly, use OSRenderBitmap::DebugMe
00556     SeeAlso:    OSRenderBitmap::DebugMe
00557 
00558 ********************************************************************************************/
00559 
00560 void GRenderClickColour::DebugMe( INT32 Stretch )
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 }
00582 
00583 
00584 
00585 // we don't actually want to display this bitmap thanks
00586 
00587 /********************************************************************************************
00588 
00589 >   BOOL GRenderClick::DisplayBits(LPBITMAPINFO lpDisplayBitmapInfo, LPBYTE lpDisplayBits)
00590 
00591     Author:     Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
00592     Created:    17/11/94
00593     Returns:    TRUE always (cannot fail).
00594     Purpose:    Supposed to dump bitmap on screen, but that makes no sense for this bitmap
00595                 so it just does nothing and always returns TRUE.
00596 
00597 ********************************************************************************************/
00598 
00599 BOOL GRenderClick::DisplayBits(LPBITMAPINFO lpDisplayBitmapInfo, LPBYTE lpDisplayBits)
00600 {
00601     return TRUE;
00602 }
00603 
00604 
00605 
00606 /********************************************************************************************
00607 
00608 >   BOOL GRenderClick::AttachDevice(View* pView, CDC* DCToAttach, Spread* SpreadToAttach)
00609 
00610     Author:     Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
00611     Created:    15/11/94
00612     Inputs:     pView is used for debug purposes only. DCToAttach is used as a 
00613                 reference when making the bitmap. 
00614     Returns:    FALSE if failed (no mem for bitmap or CCDC), TRUE if OK
00615     Purpose:    Most work done in base class, except for the creation of a CCDC member.
00616 
00617 ********************************************************************************************/
00618 
00619 BOOL GRenderClick::AttachDevice(View* pView, wxDC* DCToAttach, Spread* SpreadToAttach, bool fOwned /*= false*/ )
00620 {
00621 
00622     // call base class first
00623     if (!GRenderDIB::AttachDevice(pView, DCToAttach, SpreadToAttach, fOwned))
00624         return FALSE;
00625             
00626     // now replace the usual RenderDC with our new one. This makes the type of the CCDC
00627     // correct, so Quality rendering works correctly, for example.
00628 /*
00629     TRY
00630     {
00631         // IMPORTANT: we 'borrow' the HDC from DCToAttach. We must take care when
00632         // deleting this not to delete the HDCs (see the constructor).
00633         RenderDC = new CCDC( DCToAttach, RENDERTYPE_MONOBITMAP );
00634     }
00635     CATCH (CMemoryException, e)
00636     {
00637         // Ooer - not enough memory
00638         TRACEALL( _T("No memory for CCDC in GRenderClick::AttachDevice") );
00639         return FALSE;
00640     }
00641     END_CATCH
00642 */
00643     RenderDC = new wxBufferedDC() ;
00644     m_fOwned = true;
00645 
00646     return TRUE;
00647 }
00648 
00649 
00650 
00651 /********************************************************************************************
00652 
00653 >   BOOL GRenderClickColour::AttachDevice(View* pView, CDC* DCToAttach, Spread* SpreadToAttach)
00654 
00655     Author:     Chris_Snook (Xara Group Ltd) <camelotdev@xara.com>
00656     Created:    27/10/99
00657     Inputs:     pView is used for debug purposes only. DCToAttach is used as a 
00658                 reference when making the bitmap. 
00659     Returns:    FALSE if failed (no mem for bitmap or CCDC), TRUE if OK
00660     Purpose:    Most work done in base class, except for the creation of a CCDC member.
00661 
00662 ********************************************************************************************/
00663 
00664 BOOL GRenderClickColour::AttachDevice(View* pView, wxDC* DCToAttach, Spread* SpreadToAttach, bool fOwned /*= false*/)
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 }
00692 
00693 
00694 /********************************************************************************************
00695 
00696 >   BOOL GRenderClickColourNoPaper::AttachDevice(View* pView, CDC* DCToAttach, Spread* SpreadToAttach)
00697 
00698     Author:     Chris_Snook (Xara Group Ltd) <camelotdev@xara.com>
00699     Created:    27/10/99
00700     Inputs:     pView is used for debug purposes only. DCToAttach is used as a 
00701                 reference when making the bitmap. 
00702     Returns:    FALSE if failed (no mem for bitmap or CCDC), TRUE if OK
00703     Purpose:    Most work done in base class, except for the creation of a CCDC member.
00704 
00705 ********************************************************************************************/
00706 
00707 BOOL GRenderClickColourNoPaper::AttachDevice(View* pView, wxDC* DCToAttach, Spread* SpreadToAttach, bool fOwned /*= false*/)
00708 {
00709 
00710     // call base class first
00711     if (!GRenderDIB::AttachDevice(pView, DCToAttach, SpreadToAttach, fOwned))
00712         return FALSE;
00713 /*          
00714     // now replace the usual RenderDC with our new one. This makes the type of the CCDC
00715     // correct, so Quality rendering works correctly, for example.
00716     TRY
00717     {
00718         // IMPORTANT: we 'borrow' the HDC from DCToAttach. We must take care when
00719         // deleting this not to delete the HDCs (see the constructor).
00720         RenderDC = new CCDC( DCToAttach, RENDERTYPE_HITDETECT );
00721     }
00722     CATCH (CMemoryException, e)
00723     {
00724         // Ooer - not enough memory
00725         TRACEALL( _T("No memory for CCDC in GRenderClickColour::AttachDevice") );
00726         return FALSE;
00727     }
00728     END_CATCH
00729 */
00730     RenderDC = new wxBufferedDC() ;
00731     m_fOwned = true;
00732 
00733     return TRUE;
00734 }
00735 
00736 
00737 /********************************************************************************************
00738 
00739 >   BOOL GRenderClick::StartRender()
00740 
00741     Author:     Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
00742     Created:    15/11/94
00743     Returns:    TRUE if worked, FALSE if failed.
00744     Purpose:    Most work done in base class, except for the calculation of the address &
00745                 mask of the centre pixel.
00746 
00747 ********************************************************************************************/
00748 
00749 BOOL GRenderClick::StartRender()
00750 {
00751     if (!GRenderDIB::StartRender())
00752         return FALSE;
00753 
00754     // work out the address & mask of the centre pixel
00755     const INT32 w = WRect.width;
00756     const INT32 h = WRect.height;
00757 
00758     // address is pretty easy
00759     pMiddle = pBits + (h/2)*DIBUtil::ScanlineSize( w, 1 );
00760     pMiddle += ((w/2)/8);
00761 
00762     // bit within byte is also reasonably straight-forward (and should be independent of
00763     // byte-sex)
00764     MiddleMask = (BYTE) ( (INT32)0x80 >> ((w/2)&7) );
00765 
00766     // If we have been asked to clear out the contents of the bmp, then do it
00767     if (ClearOnStart)
00768     {
00769         // Set it to white
00770         if (pBits!=NULL)
00771             memset(pBits, 0xFF, pBitmapInfo->bmiHeader.biSizeImage);
00772         
00773         // Dont do it next time please
00774         ClearOnStart = FALSE;
00775     }
00776 
00777     return TRUE;
00778 }
00779 
00780 /********************************************************************************************
00781 
00782 >   BOOL GRenderClickColour::StartRender()
00783 
00784     Author:     Chris_Snook (Xara Group Ltd) <camelotdev@xara.com>
00785     Created:    15/11/94
00786     Returns:    TRUE if worked, FALSE if failed.
00787     Purpose:    Most work done in base class, except for the calculation of the address &
00788                 mask of the centre pixel.
00789 
00790 ********************************************************************************************/
00791 
00792 BOOL GRenderClickColour::StartRender()
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 }
00825 
00826 
00827 
00828 /********************************************************************************************
00829 
00830 >   virtual BOOL GRenderClick::SetFirstBand()
00831 
00832     Author:     Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
00833     Created:    5/5/95
00834     Returns:    TRUE 
00835     Purpose:    Sets up for banded rendering. This class does not do banded rendering as yet.
00836                 This just sets things up to indicate that everything will be done in one band.
00837 
00838 ********************************************************************************************/
00839 
00840 BOOL GRenderClick::SetFirstBand()
00841 {
00842     // No Banding needed
00843     IsRegionBanded = FALSE;
00844     IsWaitingForRAM = FALSE;
00845     IsLastBand = TRUE;
00846     return TRUE;
00847 }
00848 
00849 
00850 
00851 /********************************************************************************************
00852 
00853 >   virtual BOOL GRenderClick::GetNextBand()
00854 
00855     Author:     Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
00856     Created:    5/5/95
00857     Returns:    FALSE
00858     Purpose:    Since this class does not do banded rendering, there are never any more bands
00859 
00860 ********************************************************************************************/
00861 
00862 BOOL GRenderClick::GetNextBand()
00863 {
00864     // No banding
00865     return FALSE;
00866 }
00867 
00868 
00869 
00870 /********************************************************************************************
00871 
00872 >   LPBITMAPINFO GRenderClick::GetLPBits( INT32 Width, INT32 Height, INT32 Depth, LPBYTE*)
00873 
00874     Author:     Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
00875     Created:    5/5/95
00876     Inputs:     Width, Height - the width and height of the required bitmap
00877                 Depth - the bpp of the bitmap
00878     Returns:    Pointer to a bitmap header block
00879     Purpose:    Allocates a bitmap from the CCMalloc heap
00880 
00881 ********************************************************************************************/
00882 
00883 LPBITMAPINFO GRenderClick::GetLPBits( INT32 Width, INT32 Height, INT32 Depth, LPBYTE* lplpBits)
00884 {
00885     // Get a DIB out of the CCMalloc heap
00886     LPBITMAPINFO bmInfo = NULL;
00887     bmInfo = AllocDIB( Width, Height, Depth, lplpBits, NULL, FALSE);
00888 
00889     // return it.
00890     return bmInfo;
00891 }
00892 
00893 
00894 
00895 
00896 /********************************************************************************************
00897 
00898 >   void GRenderClick::FreeLPBits( LPBITMAPINFO, LPBYTE )
00899 
00900     Author:     Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
00901     Created:    5/5/95
00902     Purpose:    Frees the memory allocated in GetLPBits.
00903 
00904 ********************************************************************************************/
00905 
00906 void GRenderClick::FreeLPBits( LPBITMAPINFO lpBMI, LPBYTE lpB )
00907 {
00908     // Free up the memory. Not from Limited Heap
00909     FreeDIB(lpBMI, lpB, NULL, FALSE);
00910 }

Generated on Sat Nov 10 03:48:32 2007 for Camelot by  doxygen 1.4.4