#include <bitmapgriddropdown.h>
Inheritance diagram for CBGDDCachedItem:
Public Member Functions | |
CBGDDCachedItem (String_256 strLabel=String_256()) | |
virtual | ~CBGDDCachedItem () |
virtual void | DrawItem (wxDC &dc, const wxRect &rect, INT32 iFlags) const |
Protected Member Functions | |
virtual wxBitmap * | RenderItemToBitmap (wxSize szBitmap) const |
virtual void | RenderItemToGRenderRegion (GRenderRegion *pRenderRegion, DocRect drcItem) const |
Private Types | |
typedef std::vector< pair< wxSize, wxBitmap * > * > | TDCacheCollection |
Private Member Functions | |
wxBitmap * | GetWxBitmap (wxSize szBitmap) const |
Static Private Member Functions | |
static BOOL | DoesCacheItemSizeMatch (const pair< wxSize, wxBitmap * > *poItem, wxSize szBitmap) |
Private Attributes | |
TDCacheCollection | m_colCache |
Definition at line 198 of file bitmapgriddropdown.h.
|
Definition at line 216 of file bitmapgriddropdown.h. |
|
Definition at line 253 of file bitmapgriddropdown.cpp. 00254 : CBGDDItemInfo(strLabel) 00255 { 00256 }
|
|
Definition at line 258 of file bitmapgriddropdown.cpp. 00259 { 00260 TDCacheCollection::const_iterator citCur; 00261 for (citCur = m_colCache.begin(); citCur != m_colCache.end(); ++citCur) 00262 { 00263 delete (*citCur)->second; 00264 delete *citCur; 00265 } 00266 00267 m_colCache.clear(); 00268 }
|
|
Function : CBGDDCachedItem::DoesCacheItemSizeMatch Author : Mikhail Tatarnikov Purpose : Checks whether a cache item corresponds to the specific size Returns : BOOL - Exceptions: Parameters: [in] const pair<wxSize, xBitmap*>* poItem - [in] wxSize szBitmap - Notes : Definition at line 280 of file bitmapgriddropdown.cpp.
|
|
Implements CBGDDItemInfo. Definition at line 313 of file bitmapgriddropdown.cpp. 00314 { 00315 wxBitmap* pBitmap = GetWxBitmap(rcDraw.GetSize()); 00316 00317 // We don't need to scale or do anything since we already have a bitmap of the right size. 00318 dc.DrawBitmap(*pBitmap, rcDraw.x, rcDraw.y, FALSE); 00319 }
|
|
Function : CBGDDCachedItem::GetWxBitmap Author : Mikhail Tatarnikov Purpose : Retrieves a representation from the cache Returns : wxBitmap* - the representation with the required size. Exceptions: Parameters: [in] wxSize szBitmap - cached image size to look for. Notes : Creates a new representation if it doesn't exist. Definition at line 295 of file bitmapgriddropdown.cpp. 00296 { 00297 // Try to locate the cache. 00298 TDCacheCollection::const_iterator citFound = find_if(m_colCache.begin(), m_colCache.end(), 00299 bind2nd(ptr_fun(DoesCacheItemSizeMatch), szBitmap)); 00300 00301 if (citFound != m_colCache.end()) 00302 return (*citFound)->second; 00303 00304 // No bitmap found in the cache. Ask the derivide class to render its content. 00305 wxBitmap* pBitmap = RenderItemToBitmap(szBitmap); 00306 00307 // Now we have a resulting bitmap. We need to cache and return it. 00308 m_colCache.push_back(new pair<wxSize, wxBitmap*>(szBitmap, pBitmap)); 00309 00310 return pBitmap; 00311 }
|
|
Function : CBGDDCachedItem::RenderItemToBitmap Author : Mikhail Tatarnikov Purpose : Renders an item to bitmap. Returns : wxBitmap* - bitmap with the rendered item. Exceptions: Parameters: [in] wxSize szBitmap - size of the required bitmap. Notes : The function prepares a GRenderRegion and asks the derived class to draw itself into it. Reimplemented in CBGDDKernelBitmapItem. Definition at line 332 of file bitmapgriddropdown.cpp. 00333 { 00334 wxMemoryDC dcMem; 00335 wxBitmap* pBitmap = new wxBitmap(szBitmap.x, szBitmap.y); 00336 dcMem.SelectObject(*pBitmap); 00337 00338 00339 INT32 iDPI = 96; 00340 00341 // Since we don't have a view, we need a fake one. 00342 DialogView *pDialogView = new DialogView; 00343 pDialogView->Init(); 00344 FIXED16 Scale(1); 00345 00346 Matrix oMatrix(1, 0, 0, 1, 0, 0); 00347 00348 // Convert the item area to millipoints 00349 DocRect drcDocClip; 00350 drcDocClip.lo.x = 0; 00351 drcDocClip.lo.y = 0; 00352 00353 drcDocClip.hi.x = (szBitmap.x * 1000); 00354 drcDocClip.hi.y = (szBitmap.y * 1000); 00355 00356 00357 // Create a bitmap render region. 00358 GRenderBitmap* pRenderRegion = new GRenderBitmap(drcDocClip, oMatrix, Scale, 24, iDPI, FALSE, 0, NULL, TRUE); 00359 pRenderRegion->AttachDevice(pDialogView, &dcMem, NULL, false); 00360 00361 // Prepare for the rendering. 00362 pRenderRegion->InitDevice(); 00363 pRenderRegion->SaveContext(); 00364 pRenderRegion->StartRender(); 00365 00366 00367 // Ask the derived class to render itself into GRenderRegion. 00368 RenderItemToGRenderRegion(pRenderRegion, drcDocClip); 00369 00370 // Finalize the rendering. 00371 pRenderRegion->StopRender(); 00372 pRenderRegion->RestoreContext(); 00373 00374 // Extract bitmap from the render region. 00375 KernelBitmap* pKernelBitmap = new KernelBitmap(pRenderRegion->ExtractBitmap(), FALSE); 00376 00377 BitmapDragInformation oDragBitmap(pKernelBitmap, szBitmap.x, szBitmap.y, 0, 0); 00378 oDragBitmap.OnDrawSolidDrag(wxPoint(0, 0), &dcMem); 00379 00380 // Free resourced and return the resulting bitmap. 00381 delete pKernelBitmap; 00382 delete pRenderRegion; 00383 delete pDialogView; 00384 00385 dcMem.SelectObject(wxNullBitmap); 00386 00387 return pBitmap; 00388 }
|
|
Function : CBGDDCachedItem::RenderItemToGRenderRegion Author : Mikhail Tatarnikov Purpose : Renders the item into GRenderRegion. Returns : void Exceptions: Parameters: [in] GRenderRegion* pRenderRegion - Render region to draw to; [in] DocRect drcItem - item size. Notes : The derived classes should override this function if they don't override RenderItemToBitmap. Reimplemented in CBGDDStrokeItem, and CBGDDBrushItem. Definition at line 402 of file bitmapgriddropdown.cpp. 00403 { 00404 ASSERT(FALSE); // The derived classes should override this method 00405 // Or the parent RenderItemToBitmap method. 00406 }
|
|
Definition at line 217 of file bitmapgriddropdown.h. |