CamArtProvider Class Reference

A derived event handler which providers art for bitmap buttons and other controls within Camelot Notes: In the OIL See Also:. More...

#include <cartprov.h>

List of all members.

Public Member Functions

 CamArtProvider ()
 Constructor.
 ~CamArtProvider ()
 Destructor.
void GetBitmapEvent (wxCamArtProviderEvent &event)
 Called when we need to load some art.
void InvalidateArtEvent (wxCamArtProviderEvent &event)
 Called when we need to load some art.
void Draw (wxDC &dc, const wxRect &rect, ResourceID Resource, CamArtFlags Flags=CAF_DEFAULT, const wxString &text=wxEmptyString)
 Draws the art into the appropriate DC.
wxSize GetSize (ResourceID r, CamArtFlags Flags=CAF_DEFAULT, const wxString &text=wxEmptyString)
 

void EnsureBitmapLoaded (ResourceID Resource, BOOL SkipArtLoad=FALSE)
 Passes an event to DialogManager::Event.
void EnsureChildBitmapsLoaded (wxWindow *pWindow=NULL, BOOL SkipArtLoad=FALSE)
 Invalidates every window which has art in it.
void ReloadAllArt ()
 Reloads all the art.
wxBitmap * FindBitmap (ResourceID Resource, CamArtFlags Flags=CAF_DEFAULT, BOOL SkipArtLoad=FALSE)
 Finds the cached bitmap with the relevant resource ID & flags.
wxImage * FindImage (ResourceID Resource, CamArtFlags Flags=CAF_DEFAULT, BOOL SkipArtLoad=FALSE)
 Finds the cached bitmap with the relevant resource ID & flags.
wxImage * GetMissingImage () const
wxBitmap * GetMissingBitmap () const

Static Public Member Functions

static BOOL Init ()
 Initialize the class.
static void DeInit ()
 Initialize resources.
static CamArtProviderGet ()
static CamArtFlags GetBitmapFlags (const wxString &str)
static wxString MakeBitmapFlagString (const CamArtFlags flags)

Protected Member Functions

ResIDWithFlagsToBitmapPtr::iterator Find (ResourceID Resource, CamArtFlags Flags, BOOL SkipArtLoad)
 Finds the cached bitmap with the relevant resource ID & flags.
ResourceIDWithFlags CombineFlags (ResourceID Resource, CamArtFlags Flags)
CamArtFlags GetFlags (ResourceIDWithFlags ResWithFlags)
ResourceID GetResourceID (ResourceIDWithFlags ResWithFlags)
wxImage * MakeBitmap (ResourceIDWithFlags ResWithFlags)
 Makes a bitmap from the appropraite resource.
void InvalidateAllArt ()
 Invalidates every window which has art in it.
void InvalidateAllArtInChildren (wxWindow *pWindow)
 Invalidates every window which has art in it.
void DeleteHashContents ()
 Delete every hash table entry.
void ArtLoad (BOOL newbitmaps=FALSE, BOOL defer=TRUE)
 Schedule a GetBitmap event, unless one is already scheduled.
wxSize GetBorderSize (CamArtFlags Flags=CAF_DEFAULT)
 

wxString GetTextInfoOrDraw (ResourceID r, CamArtFlags f, wxDC &dc, BOOL Draw=FALSE, wxCoord *w=NULL, wxCoord *h=NULL, wxCoord x=0, wxCoord y=0, wxCoord MaxWidth=-1, const wxString &text=wxEmptyString)
 Sets up the DC and returns the text.

Static Protected Member Functions

static wxColor DarkenColour (const wxColor &c, INT32 amount)
 Returns a darkened colour.
static wxColor LightenColour (const wxColor &c, INT32 amount)
 Returns a lightened colour.

Protected Attributes

ResIDWithFlagsToBitmapPtr * m_pHash
BOOL m_GetBitmapEventPending
BOOL m_InvalidateArtEventPending
wxImage * m_pMissingImage
wxBitmap * m_pMissingBitmap

Static Private Attributes

static CamArtProviderm_ArtProvider = NULL


Detailed Description

A derived event handler which providers art for bitmap buttons and other controls within Camelot Notes: In the OIL See Also:.

Author:
Alex_Bligh <alex@alex.org.uk>
Date:
19/12/2005
This class is specificly written so it will provided cached vector-drawn art.

Definition at line 203 of file cartprov.h.


Constructor & Destructor Documentation

CamArtProvider::CamArtProvider  ) 
 

Constructor.

Author:
Alex_Bligh <alex@alex.org.uk>
Date:
30/12/2005
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
-

Errors: -

See also:
-

Definition at line 142 of file cartprov.cpp.

00143 {
00144     m_pHash = NULL;
00145     m_GetBitmapEventPending = FALSE;
00146     m_InvalidateArtEventPending = FALSE;
00147     m_pMissingImage = NULL;
00148 
00149     m_pMissingImage = new wxImage; // if this returns NULL, all missing bitmaps will be blank. Oh well
00150     if (m_pMissingImage) CamResource::LoadwxImage(*m_pMissingImage, _T("missing.png") );
00151     if (m_pMissingImage) m_pMissingBitmap=new wxBitmap(*m_pMissingImage, -1);
00152 
00153     m_pHash = new ResIDWithFlagsToBitmapPtr; // if this returns NULL, Init will whinge, so don't check
00154 }

CamArtProvider::~CamArtProvider  ) 
 

Destructor.

Author:
Alex_Bligh <alex@alex.org.uk>
Date:
30/12/2005
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
-

Errors: -

See also:
-

Definition at line 172 of file cartprov.cpp.

00173 {
00174     if (m_pHash)
00175     {
00176         DeleteHashContents();
00177         if (m_pHash) delete m_pHash;
00178         m_pHash = NULL;
00179     }
00180     if (m_pMissingImage)
00181     {
00182         delete(m_pMissingImage);
00183         m_pMissingImage=NULL;
00184     }
00185     if (m_pMissingBitmap)
00186     {
00187         delete(m_pMissingBitmap);
00188         m_pMissingBitmap=NULL;
00189     }
00190 }


Member Function Documentation

void CamArtProvider::ArtLoad BOOL  newbitmaps = FALSE,
BOOL  defer = TRUE
[protected]
 

Schedule a GetBitmap event, unless one is already scheduled.

Author:
Alex_Bligh <alex@alex.org.uk>
Date:
30/12/2005
Parameters:
newbitmaps - set TRUE if we should forget cache of all bitmaps that were [INPUTS] missing last time. Also causes existing pending event flag to be ignored in case an event got lost (should never happen). defer - set TRUE if the art load is to be deferred
- [OUTPUTS]
Returns:
-

Errors: -

See also:
-

Definition at line 347 of file cartprov.cpp.

00348 {
00349     // If we already have an event pending, don't generate a new one
00350     if (m_GetBitmapEventPending && !newbitmaps) return;
00351 
00352     if (newbitmaps && m_pMissingImage && m_pHash && !m_pHash->empty())
00353     {
00354         ResIDWithFlagsToBitmapPtr::iterator current;
00355 
00356         for( current = m_pHash->begin(); current != m_pHash->end(); ++current )
00357         {
00358             // we don't need to worry about memory management as deleting the
00359             // bitmaps are CamResource::'s responsibility
00360             if (current->second.m_pImage == m_pMissingImage)
00361                 m_pMissingImage = NULL; // mark as required to be loaded on the event
00362         }
00363     }
00364 
00365     // Send ourselves a deferred event
00366     m_GetBitmapEventPending = TRUE;
00367     wxCamArtProviderEvent event (wxEVT_CAMARTPROVIDER_GETBITMAP, 0, defer);
00368     if (defer)
00369         AddPendingEvent(event);
00370     else
00371         ProcessEvent(event);    
00372 }

ResourceIDWithFlags CamArtProvider::CombineFlags ResourceID  Resource,
CamArtFlags  Flags
[inline, protected]
 

Definition at line 238 of file cartprov.h.

00238 { return Resource | (((UINT64)Flags)<<32) ; }

wxColor CamArtProvider::DarkenColour const wxColor &  c,
INT32  amount
[static, protected]
 

Returns a darkened colour.

Author:
Alex_Bligh <alex@alex.org.uk>
Date:
30/12/2005
Parameters:
c - a wxColour [INPUTS] amount - amount to darken it by
a darkened colour [OUTPUTS]
Returns:
-

Errors: -

See also:
-

Definition at line 209 of file cartprov.cpp.

00210 {
00211     INT32 r = c.Red(), g = c.Green(), b = c.Blue();
00212     return wxColour((r*amount)/100, (g*amount)/100, (b*amount)/100);
00213 }

void CamArtProvider::DeInit void   )  [static]
 

Initialize resources.

Author:
Alex_Bligh <alex@alex.org.uk>
Date:
30/12/2005
Parameters:
None [INPUTS]
None [OUTPUTS]
Returns:
TRUE if succeeded, FALSE if fails

Errors: via wxMessageBox

See also:
-

Definition at line 279 of file cartprov.cpp.

00280 {
00281     if (m_ArtProvider)
00282     {
00283         delete m_ArtProvider;
00284         m_ArtProvider = FALSE;
00285     }
00286 }

void CamArtProvider::DeleteHashContents  )  [protected]
 

Delete every hash table entry.

Author:
Alex_Bligh <alex@alex.org.uk>
Date:
30/12/2005
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
-

Errors: -

See also:
-
Note we don't need to delete the bitmaps themselves - CamResource:: does that. Thus right now this routine does nothing much with the hash contents.

Definition at line 307 of file cartprov.cpp.

00308 {
00309     if (m_pHash)
00310     {
00311         ResIDWithFlagsToBitmapPtr::iterator current;
00312 
00313         while (!m_pHash->empty())
00314         {
00315             current = m_pHash->begin();
00316             // wxImage * s=current->second.m_pImage;
00317             m_pHash->erase(current);
00318             // delete s;  -- we don't need to do this, CamResource:: does this
00319         }
00320         // for good measure
00321         m_pHash->clear();
00322         
00323         delete (m_pHash);
00324         m_pHash = NULL;
00325     }
00326 }

void CamArtProvider::Draw wxDC &  dc,
const wxRect &  rect,
ResourceID  Resource,
CamArtFlags  Flags = CAF_DEFAULT,
const wxString &  text = wxEmptyString
 

Draws the art into the appropriate DC.

Author:
Alex_Bligh <alex@alex.org.uk>
Date:
30/12/2005
Parameters:
dc - the wxDC to draw into [INPUTS] Resource - the ResourceID to load CamArtFlags - the flags to use for drawing InternalBorder - the internal border (in pixels) - see note
- [OUTPUTS]
Returns:
pointer to a string containing the event number

Errors: -

See also:
-
Note that the internal border is the TOTAL internal border (i.e. left plus right). Border pixels will be allocated preferentially on left and top, to right and bottom. Rect should already have been inflated (wxCamArtControl does this by increasing its client area).

Definition at line 756 of file cartprov.cpp.

00757 {
00758     dc.SetBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE));
00759     dc.SetPen(*wxTRANSPARENT_PEN);
00760 //  dc.DrawRectangle(rect.x, rect.y, rect.width, rect.height);
00761     
00762 //  dc.SetBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE));
00763     dc.SetBrush(*wxTRANSPARENT_BRUSH); // Needed in case we need to paint 3D furniture, but not the button top (ALWAYS3D)
00764 
00765     wxRect brect = rect;
00766 
00767     UINT32 bitmapoffsetX=0;
00768     UINT32 bitmapoffsetY=0;
00769 
00770     if ((Flags & CAF_PUSHBUTTON) && !rect.IsEmpty())
00771     {
00772         // 3Dness
00773         brect.width-=1;
00774         brect.height-=1;
00775         
00776         if (Flags & CAF_SELECTED)
00777         {
00778             // It's pushed in
00779             brect.x++;
00780             brect.y++;
00781         }
00782 
00783         UINT32 InternalBorderX = (Flags & CAF_NOINTERNALBORDER)?0:2;
00784         UINT32 InternalBorderY = (Flags & CAF_NOINTERNALBORDER)?0:1;
00785 
00786         bitmapoffsetX=1+((InternalBorderX+1)>>1); // this is a completely independent offset to the brect stuff, which gives the bitmap a border
00787         bitmapoffsetY=1+((InternalBorderY+1)>>1); // this is a completely independent offset to the brect stuff, which gives the bitmap a border
00788 
00789 //      BOOL FaceSelected = ( (Flags & CAF_SELECTED) || (Flags & CAF_BUTTONHOVER) );
00790 //      BOOL Border3D = ( (Flags & CAF_SELECTED) || (Flags & CAF_ALWAYS3D));
00791 
00792         BOOL FaceSelected = ( (Flags & CAF_SELECTED) || ((Flags & CAF_ALWAYS3D) && (Flags & CAF_BUTTONHOVER)) ); // highlight face on hover if always3D
00793         BOOL Border3D = ( (Flags & CAF_SELECTED) || (Flags & CAF_ALWAYS3D) || (Flags & CAF_BUTTONHOVER));
00794 
00795         // Change the brush if the face is selected
00796         if (FaceSelected)
00797         {
00798             if (Flags & CAF_TOOLBACKGROUND)
00799                 dc.SetBrush(wxColour(255,255,192)); // A light yellow - we should load this from somewhere else
00800             else
00801             {   
00802                 if (Flags & CAF_BUTTONHOVER)
00803                     dc.SetBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_3DHIGHLIGHT));
00804                 else    
00805                     dc.SetBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE));
00806             }
00807         }
00808 
00809         if (Border3D)
00810         {
00811             // draw the light highlights
00812             dc.SetPen(wxSystemSettings::GetColour((Flags & CAF_SELECTED)?wxSYS_COLOUR_3DHIGHLIGHT:wxSYS_COLOUR_3DDKSHADOW));
00813             // draw the background behind the button undisplaced
00814             dc.DrawRectangle(rect.x, rect.y, rect.width, rect.height);
00815             // now draw the left & top bits
00816             dc.SetPen(wxSystemSettings::GetColour((Flags & CAF_SELECTED)?wxSYS_COLOUR_3DDKSHADOW:wxSYS_COLOUR_3DHIGHLIGHT));
00817             dc.DrawLine(rect.x, rect.y, rect.x+rect.width-1, rect.y);
00818             dc.DrawLine(rect.x, rect.y, rect.x, rect.y+rect.height-1);
00819         }
00820         else if (FaceSelected) // if not FaceSelected, we've already drawn it
00821         {
00822             // draw the background behind the button displaced
00823             dc.DrawRectangle(brect.x, brect.y, brect.width, brect.height);
00824         }
00825     }
00826 
00827     // Now apply justification to the object
00828     wxRect BestSize(GetSize(Resource, Flags, text));
00829     if (BestSize.width != rect.width)
00830     {
00831         if (Flags & CAF_RIGHT)
00832         {
00833             bitmapoffsetX += (rect.width-BestSize.width);
00834         }
00835         else if (Flags & CAF_LEFT)
00836         {
00837             // do nothing
00838         }
00839         else
00840         {
00841             bitmapoffsetX += (rect.width-BestSize.width)/2;
00842         }   
00843     }   
00844     if (BestSize.height != rect.height)
00845     {
00846         if (Flags & CAF_BOTTOM)
00847         {
00848             bitmapoffsetY += (rect.height-BestSize.height);
00849         }
00850         else if (Flags & CAF_TOP)
00851         {
00852             // do nothing
00853         }
00854         else
00855         {
00856             bitmapoffsetY += (rect.height-BestSize.height)/2;
00857         }   
00858     }   
00859 
00860     if (Flags & CAF_TEXT)
00861     {
00862         // The max width is the width of the entire control, less the internal border width
00863         wxCoord MaxWidth = rect.GetWidth() - GetBorderSize(Flags).GetWidth();
00864         if (MaxWidth<0)
00865             MaxWidth=0;
00866         wxString ctext = GetTextInfoOrDraw(Resource, Flags, dc, TRUE, NULL, NULL, brect.x+bitmapoffsetX, brect.y+bitmapoffsetY, MaxWidth, text);
00867     }
00868     else
00869     {
00870         // Get the bitmap with the correct flags. We here pretend the button is selected if we are
00871         // hovering. We can't do this in the control (grrr...) because else by the time the flags get
00872         // here we cannot distinguish selection from hover, which means we slab wrongly
00873         wxBitmap *pBitmap = FindBitmap(Resource, (CamArtFlags)(Flags|((Flags & CAF_BUTTONHOVER)?CAF_SELECTED:0) ));
00874         
00875         // plot the bitmap
00876         if (pBitmap)
00877             dc.DrawBitmap(*pBitmap, brect.x+bitmapoffsetX, brect.y+bitmapoffsetY, TRUE);
00878     }
00879 }

void CamArtProvider::EnsureBitmapLoaded ResourceID  Resource,
BOOL  SkipArtLoad = FALSE
 

Passes an event to DialogManager::Event.

Author:
Alex_Bligh <alex@alex.org.uk>
Date:
30/12/2005
Parameters:
Resource - the ResourceID of the art to ensure is loaded [INPUTS]
- [OUTPUTS]
Returns:
-

Errors: -

See also:
-

Definition at line 535 of file cartprov.cpp.

00536 {
00537     UINT32 f;
00538     for (f = 0; f<CAF_CACHE_MAX; f++)
00539     {
00540         FindBitmap(Resource, (CamArtFlags)f, SkipArtLoad);  // Find all the variants of the bitmap, thus ensuring a load
00541     }
00542 }

void CamArtProvider::EnsureChildBitmapsLoaded wxWindow *  pWindow = NULL,
BOOL  SkipArtLoad = FALSE
 

Invalidates every window which has art in it.

Author:
Alex_Bligh <alex@alex.org.uk>
Date:
30/12/2005
Parameters:
event - the wxEvent [INPUTS]
- [OUTPUTS]
Returns:
-

Errors: -

See also:
-
Note this function should do a broadcast to all, which will allow others to invalidate themselves. Note that we bunch up all the art loading until the end by ensuring that internally we call with SkipArtLoad set.

Definition at line 565 of file cartprov.cpp.

00566 {
00567     if (!pWindow)
00568         pWindow = CCamFrame::GetMainFrame();
00569 
00570     if (!pWindow) return;
00571 
00572     // Process this one
00573     if ( (pWindow->IsKindOf(CLASSINFO(wxCamArtControl))) &&
00574          !(((wxCamArtControl*)pWindow)->GetStyle() & wxCACS_TEXT) ) // don't bother finding bitmaps for text ones, as there isn't one!
00575         EnsureBitmapLoaded((ResourceID)(pWindow->GetId()), TRUE); // always skip the art load
00576 
00577     // Now process children if any
00578     wxWindowList::Node * pNode = pWindow->GetChildren().GetFirst();
00579     while (pNode)
00580     {
00581         EnsureChildBitmapsLoaded(pNode->GetData(), TRUE); // Always skip the art load
00582         pNode = pNode->GetNext();
00583     }
00584 
00585     if (!SkipArtLoad)
00586         ArtLoad(FALSE, FALSE);
00587 
00588     return;
00589 }

ResIDWithFlagsToBitmapPtr::iterator CamArtProvider::Find ResourceID  Resource,
CamArtFlags  Flags,
BOOL  SkipArtLoad
[protected]
 

Finds the cached bitmap with the relevant resource ID & flags.

Author:
Alex_Bligh <alex@alex.org.uk>
Date:
30/12/2005
Parameters:
Resource - the resource ID to find [INPUTS] Flags - the flags to find
- [OUTPUTS]
Returns:
a pointer to the bitmap that has been foudn

Errors: -

See also:
-
may return NULL if there is no default "missing bitmap" that could be loaded

Definition at line 634 of file cartprov.cpp.

00635 {
00636     ResourceIDWithFlags f = CombineFlags(Resource, (CamArtFlags)(Flags & (CAF_CACHE_MAX-1)));
00637     if (!m_pHash) return m_pHash->end();
00638 
00639     // get the bitmap from the hash
00640     ResIDWithFlagsToBitmapPtr::iterator i=m_pHash->find(f);
00641     if (i==m_pHash->end())
00642     {
00643         // Oh dear, we haven't found an entry. We thus create one and schedule a load
00644         ImageAndBitmap IandB;
00645         (*m_pHash)[f]=IandB;
00646         if (!SkipArtLoad)
00647             ArtLoad(FALSE, FALSE);
00648         // See if it's appeared
00649         i=m_pHash->find(f);
00650     }
00651 
00652     return i;
00653 }

wxBitmap * CamArtProvider::FindBitmap ResourceID  Resource,
CamArtFlags  Flags = CAF_DEFAULT,
BOOL  SkipArtLoad = FALSE
 

Finds the cached bitmap with the relevant resource ID & flags.

Author:
Alex_Bligh <alex@alex.org.uk>
Date:
30/12/2005
Parameters:
Resource - the resource ID to find [INPUTS] Flags - the flags to find
- [OUTPUTS]
Returns:
a pointer to the bitmap that has been foudn

Errors: -

See also:
-
may return NULL if there is no default "missing bitmap" that could be loaded

We look for an image, and if there is an attached bitmap, use that, else make one

Definition at line 709 of file cartprov.cpp.

00710 {
00711     ResIDWithFlagsToBitmapPtr::iterator i=Find(Resource, Flags, SkipArtLoad);
00712     if (i==m_pHash->end())
00713     {
00714         return m_pMissingBitmap;
00715     }
00716     wxBitmap *pBitmap = i->second.m_pBitmap;
00717     if (pBitmap) return pBitmap;
00718 
00719     // No bitmap. Do we have an image?
00720     wxImage *pImage = i->second.m_pImage;
00721 
00722     if (!pImage || (pImage==m_pMissingImage))
00723         return m_pMissingBitmap;
00724 
00725     // OK make a bitmap
00726     pBitmap = new wxBitmap(*pImage, -1); // for now, always use screen depth, not least as GDK doesn't support anything except this & 1bpp
00727     if (!pBitmap) return m_pMissingBitmap;
00728 
00729     i->second.m_pBitmap=pBitmap;
00730     return pBitmap;
00731 }

wxImage * CamArtProvider::FindImage ResourceID  Resource,
CamArtFlags  Flags = CAF_DEFAULT,
BOOL  SkipArtLoad = FALSE
 

Finds the cached bitmap with the relevant resource ID & flags.

Author:
Alex_Bligh <alex@alex.org.uk>
Date:
30/12/2005
Parameters:
Resource - the resource ID to find [INPUTS] Flags - the flags to find
- [OUTPUTS]
Returns:
a pointer to the bitmap that has been foudn

Errors: -

See also:
-
may return NULL if there is no default "missing bitmap" that could be loaded

Definition at line 675 of file cartprov.cpp.

00676 {
00677     ResIDWithFlagsToBitmapPtr::iterator i=Find(Resource, Flags, SkipArtLoad);
00678     if (i==m_pHash->end())
00679     {
00680         return m_pMissingImage;
00681     }
00682     wxImage *pImage = i->second.m_pImage;
00683 
00684     return pImage?pImage:m_pMissingImage;
00685 }

static CamArtProvider* CamArtProvider::Get  )  [inline, static]
 

Definition at line 215 of file cartprov.h.

00215 {return m_ArtProvider;}

void CamArtProvider::GetBitmapEvent wxCamArtProviderEvent event  ) 
 

Called when we need to load some art.

Author:
Alex_Bligh <alex@alex.org.uk>
Date:
30/12/2005
Parameters:
event - the wxEvent [INPUTS]
- [OUTPUTS]
Returns:
-

Errors: -

See also:
-

Definition at line 392 of file cartprov.cpp.

00393 {
00394     if (m_pHash && !m_pHash->empty())
00395     {
00396         BOOL FoundBitmapToLoad = FALSE;
00397         ResIDWithFlagsToBitmapPtr::iterator current;
00398         for( current = m_pHash->begin(); current != m_pHash->end(); ++current )
00399         {
00400             if (!current->second.m_pImage) // we have no blank bitmap
00401             {
00402                 FoundBitmapToLoad = TRUE;
00403 
00404 //              ResourceID r = GetResourceID(current->first);
00405 //              CamArtFlags f = GetFlags(current->first);
00406 //              TRACE(_T("Hash for bitmap 0x%x:%d %s"),f,r,CamResource::GetObjectName(r));
00407 
00408                 wxImage * pBitmap = MakeBitmap(current->first);
00409                 current->second.m_pImage = pBitmap?pBitmap:m_pMissingImage;
00410             }
00411         }
00412 
00413         if (FoundBitmapToLoad)
00414         {
00415             if (!m_InvalidateArtEventPending)
00416             {
00417                 m_InvalidateArtEventPending = TRUE;
00418                 BOOL defer=!event.m_deferred; //Defer the invalidate if this is immediate
00419                 wxCamArtProviderEvent event (wxEVT_CAMARTPROVIDER_INVALIDATEART, 0, defer);
00420                 if (defer)
00421                     AddPendingEvent(event);
00422                 else
00423                     ProcessEvent(event);    
00424             }
00425         }
00426     }
00427     m_GetBitmapEventPending=FALSE;
00428 }

CamArtFlags CamArtProvider::GetBitmapFlags const wxString &  str  )  [static]
 

Author:
Alex_Bligh <alex@alex.org.uk>
Date:
24/01/2005
Parameters:
str - sting to look at [INPUTS]
None [OUTPUTS]
Returns:
Flags associated with a bitmap string

Errors: -

See also:
-

Definition at line 1205 of file cartprov.cpp.

01206 {
01207     wxString ext=CamResource::GetBitmapFlagString(str);
01208     return (CamArtFlags)(
01209             ((ext.Find('s')>=0)?CAF_SMALL:0) |
01210             ((ext.Find('f')>=0)?CAF_FOCUS:0) |
01211             ((ext.Find('x')>=0)?CAF_SELECTED:0) |
01212             ((ext.Find('g')>=0)?CAF_GREYED:0) |
01213             0);
01214 }

wxSize CamArtProvider::GetBorderSize CamArtFlags  Flags = CAF_DEFAULT  )  [protected]
 

Author:
Alex_Bligh <alex@alex.org.uk>
Date:
25/01/2005
Parameters:
Flags - the flags [INPUTS]
- [OUTPUTS]
Returns:
The size of the border around the control

Errors: -

See also:
-
Note that the internal border is the TOTAL internal border (i.e. left plus right). Border pixels will be allocated preferentially on left and top, to right and bottom. Rect should already have been inflated (wxCamArtControl does this by increasing its client area).

Definition at line 946 of file cartprov.cpp.

00947 {
00948     UINT32 InternalBorderX = (Flags & CAF_NOINTERNALBORDER)?0:2;
00949     UINT32 InternalBorderY = (Flags & CAF_NOINTERNALBORDER)?0:1;
00950     // 3 extra pixels for push buttons, 2 border (one on each side) and one for push displacement
00951     UINT32 extraX=InternalBorderX+3*((Flags & CAF_ALWAYS3D) || (Flags & CAF_PUSHBUTTON)); // 3 or 0
00952     UINT32 extraY=InternalBorderY+3*((Flags & CAF_ALWAYS3D) || (Flags & CAF_PUSHBUTTON)); // 3 or 0
00953     return wxSize(extraX, extraY);
00954 }

CamArtFlags CamArtProvider::GetFlags ResourceIDWithFlags  ResWithFlags  )  [inline, protected]
 

Definition at line 239 of file cartprov.h.

00239 { return (CamArtFlags)(ResWithFlags>>32); }

wxBitmap* CamArtProvider::GetMissingBitmap  )  const [inline]
 

Definition at line 233 of file cartprov.h.

00233 {return m_pMissingBitmap;}

wxImage* CamArtProvider::GetMissingImage  )  const [inline]
 

Definition at line 232 of file cartprov.h.

00232 {return m_pMissingImage;}

ResourceID CamArtProvider::GetResourceID ResourceIDWithFlags  ResWithFlags  )  [inline, protected]
 

Definition at line 240 of file cartprov.h.

00240 { return (ResourceID)(ResWithFlags & 0xFFFFFFFF); } // mask unnecessary but for clarity

wxSize CamArtProvider::GetSize ResourceID  r,
CamArtFlags  Flags = CAF_DEFAULT,
const wxString &  text = wxEmptyString
 

Author:
Alex_Bligh <alex@alex.org.uk>
Date:
25/01/2005
Parameters:
r - the resource [INPUTS] Flags - the flags
- [OUTPUTS]
Returns:
The size of the control

Errors: -

See also:
-
Note that the internal border is the TOTAL internal border (i.e. left plus right). Border pixels will be allocated preferentially on left and top, to right and bottom. Rect should already have been inflated (wxCamArtControl does this by increasing its client area).

Definition at line 902 of file cartprov.cpp.

00903 {
00904     wxCoord w=24;
00905     wxCoord h=24;
00906 
00907     if (Flags & CAF_TEXT)
00908     {
00909         wxScreenDC dc;
00910         wxString ctext = GetTextInfoOrDraw(r, Flags, dc, FALSE, &w, &h, 0, 0, -1, text);
00911     }
00912     else
00913     {
00914         wxBitmap * pBitmap=FindBitmap(r, Flags);
00915         if (pBitmap)
00916         {
00917             w=pBitmap->GetWidth();
00918             h=pBitmap->GetHeight();
00919         }
00920     }
00921 
00922     wxSize Border=GetBorderSize(Flags);
00923     return wxSize(w+Border.GetWidth(), h+Border.GetHeight());
00924 }

wxString CamArtProvider::GetTextInfoOrDraw ResourceID  r,
CamArtFlags  f,
wxDC &  dc,
BOOL  Draw = FALSE,
wxCoord *  w = NULL,
wxCoord *  h = NULL,
wxCoord  x = 0,
wxCoord  y = 0,
wxCoord  MaxWidth = -1,
const wxString &  text = wxEmptyString
[protected]
 

Sets up the DC and returns the text.

Author:
Alex_Bligh <alex@alex.org.uk>
Date:
24/04/2006
Parameters:
r - the resource [INPUTS] Flags - the flags Draw = TRUE to draw the text x, y - location to draw the text (if Draw is set) MaxWidth - the maximum width or the text (use -1 when calculating for no max width)
w,h,pointers to fill in (can be NULL) for the text extent. Either both or neither must be NULL [OUTPUTS]
Returns:
The text

Errors: -

See also:
-

Definition at line 977 of file cartprov.cpp.

00979 {
00980     // find the name by looking up the ID as a string
00981     const TCHAR * tcname=text;
00982 
00983     if (w) *w=0;
00984     if (h) *h=0;
00985 
00986     if (text.IsEmpty())
00987     {
00988         tcname = CamResource::GetTextFail(r);
00989         if (!tcname || ( (tcname[0]==_T('-')) && !tcname[1]) )
00990         {
00991             // default to object name
00992             tcname = CamResource::GetObjectNameFail(r);
00993         }
00994         
00995         if (!tcname)
00996         {
00997             // If this goes off, then somehow we've been passed a resource ID without a reverse
00998             // bitmap lookup. This can normally only happen if the resource ID is corrupted, or
00999             // the resources are corrupted
01000             ERROR3_PF(("Cannot get text for resource %d",r));
01001             return wxEmptyString;
01002         }
01003     }
01004 
01005     dc.SetTextForeground(wxSystemSettings::GetColour((f & CAF_GREYED)?wxSYS_COLOUR_GRAYTEXT:wxSYS_COLOUR_BTNTEXT));
01006     wxFont font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
01007     font.SetPointSize((f & CAF_HALFHEIGHT)?7:8);
01008     dc.SetFont(font);
01009 
01010     wxString RenderText(tcname);
01011 
01012     if (!(f & CAF_STATUSBARTEXT))
01013     {
01014         if (h && w)
01015             dc.GetTextExtent(RenderText, w, h);
01016     
01017         if (Draw)
01018             dc.DrawText(RenderText, x, y);
01019     }
01020     else
01021     {
01022         // It's status bar text. We have to go through the tokens individually
01023 
01024         // First tokenize the string
01025         INT32 i=0;
01026         wxArrayString Tokens;
01027         wxArrayString Separators;
01028         wxString SubString=wxEmptyString;
01029         INT32 BoldBreak=-1;
01030         for (i=0; i<(INT32)(RenderText.Length()); i++)
01031         {
01032             wxChar c = RenderText[i];
01033             if ( (c==_T(';')) ||
01034                  ((c==_T(':')) && (i<((INT32)RenderText.Length())-1) && (RenderText[i+1]==_T(':')) )
01035                 )
01036             {
01037                 // We found a separator
01038                 Tokens.Add(SubString);
01039                 Separators.Add(wxString(c));
01040 
01041                 // Was it a colon separator?
01042                 if (c==_T(':'))
01043                 {
01044                     // Remember it's now bold up to here
01045                     BoldBreak=Tokens.GetCount();
01046                     // Skip over the second colon
01047                     i++;
01048                 }
01049 
01050                 SubString=wxEmptyString;
01051             }
01052             else
01053                 SubString+=c; // It's not a separator, add it to the substring
01054         }
01055 
01056         // add the final token
01057         if (!SubString.IsEmpty())
01058         {
01059             Tokens.Add(SubString);
01060             Separators.Add(wxEmptyString);
01061         }
01062 
01063         BOOL Stop = FALSE;
01064         wxCoord CumWidth = 0; // The cumulative width used so far
01065         wxCoord MaxHeight = 0; // The max height used so far
01066         wxFont BoldFont = font;
01067         BoldFont.SetWeight(wxFONTWEIGHT_BOLD);
01068 
01069         for (i=0; i<(INT32)(Tokens.GetCount()) && !Stop; i++)
01070         {
01071             wxString TextBlob = Tokens[i] + Separators[i];
01072 
01073             // Set the font up
01074             if (i<BoldBreak)
01075                 dc.SetFont(BoldFont);
01076             else
01077                 dc.SetFont(font);
01078 
01079             // Find out how large this blob is
01080             wxCoord ww=0;
01081             wxCoord hh=0;
01082             dc.GetTextExtent(TextBlob, &ww, &hh);
01083 
01084             // Does it fit (or do we force it to fit because it is the first text)
01085             if ((MaxWidth<0) || (i==0) || (CumWidth+ww<=MaxWidth))
01086             {
01087                 // Draw it if necessary
01088                 if (Draw)
01089                     dc.DrawText(TextBlob, x+CumWidth, y);
01090 
01091                 // Account for its width
01092                 CumWidth+=ww;
01093                 if (hh>MaxHeight)
01094                     MaxHeight=hh;
01095             }
01096             else
01097                 Stop=TRUE;
01098         }
01099         if (h)
01100             *h = MaxHeight;
01101         if (w)
01102             *w = CumWidth;
01103     }
01104 
01105     return RenderText;
01106 }

BOOL CamArtProvider::Init void   )  [static]
 

Initialize the class.

Author:
Alex_Bligh <alex@alex.org.uk>
Date:
30/12/2005
Parameters:
None [INPUTS]
None [OUTPUTS]
Returns:
TRUE if succeeded, FALSE if fails

Errors: via wxMessageBox

See also:
-

Definition at line 254 of file cartprov.cpp.

00255 {
00256     ERROR3IF(m_ArtProvider, "Double Init of ArtProvider");
00257     m_ArtProvider=new(CamArtProvider);
00258     ERROR2IF(!m_ArtProvider, FALSE, "Cannot get an ArtProvider");
00259 
00260     return TRUE;
00261 }

void CamArtProvider::InvalidateAllArt  )  [protected]
 

Invalidates every window which has art in it.

Author:
Alex_Bligh <alex@alex.org.uk>
Date:
30/12/2005
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
-

Errors: -

See also:
-
Note this function should do a broadcast to all, which will allow others to invalidate themselves.

Definition at line 473 of file cartprov.cpp.

00474 {
00475     wxWindow * pWindow = CCamFrame::GetMainFrame();
00476     if (pWindow) InvalidateAllArtInChildren(pWindow);
00477 
00478     // Broadcast an art changing message here!
00479 
00480 }

void CamArtProvider::InvalidateAllArtInChildren wxWindow *  pWindow  )  [protected]
 

Invalidates every window which has art in it.

Author:
Alex_Bligh <alex@alex.org.uk>
Date:
30/12/2005
Parameters:
event - the wxEvent [INPUTS]
- [OUTPUTS]
Returns:
-

Errors: -

See also:
-
Note this function should do a broadcast to all, which will allow others to invalidate themselves.

Definition at line 502 of file cartprov.cpp.

00503 {
00504     // Process this one
00505     if (pWindow->IsKindOf(CLASSINFO(wxCamArtControl)))
00506         ((wxCamArtControl *)pWindow)->NewBitmap();
00507 
00508     // Now process children if any
00509     wxWindowList::Node * pNode = pWindow->GetChildren().GetFirst();
00510     while (pNode)
00511     {
00512         InvalidateAllArtInChildren(pNode->GetData());
00513         pNode = pNode->GetNext();
00514     }
00515     return;
00516 }

void CamArtProvider::InvalidateArtEvent wxCamArtProviderEvent event  ) 
 

Called when we need to load some art.

Author:
Alex_Bligh <alex@alex.org.uk>
Date:
30/12/2005
Parameters:
event - the wxEvent [INPUTS]
- [OUTPUTS]
Returns:
-

Errors: -

See also:
-

Definition at line 447 of file cartprov.cpp.

00448 {
00449     m_InvalidateArtEventPending = FALSE;
00450     InvalidateAllArt();
00451 }

wxColor CamArtProvider::LightenColour const wxColor &  c,
INT32  amount
[static, protected]
 

Returns a lightened colour.

Author:
Alex_Bligh <alex@alex.org.uk>
Date:
30/12/2005
Parameters:
c - a wxColour [INPUTS] amount - amount to lighten it by
a lightened colour [OUTPUTS]
Returns:
-

Errors: -

See also:
-

Definition at line 232 of file cartprov.cpp.

00233 {
00234     INT32 r = 255-c.Red(), g = 255-c.Green(), b = 255-c.Blue();
00235     return wxColour(255-(r*amount)/100, 255-(g*amount)/100, 255-(b*amount)/100);
00236 }

wxImage * CamArtProvider::MakeBitmap ResourceIDWithFlags  ResWithFlags  )  [protected]
 

Makes a bitmap from the appropraite resource.

Author:
Alex_Bligh <alex@alex.org.uk>
Date:
30/12/2005
Parameters:
ResWithFlags - the hash key to make a bitmap for (ResourceID combined with flags) [INPUTS] Grey - true if we should grey (in software) the image we find. Don't set this when calling, set CAF_GREYED which will use a greyed preprepared version if available
- [OUTPUTS]
Returns:
a pointer to the bitmap, or NULL if one could not be made

Errors: -

See also:
-
This routine is abstracted to allow an easy switch to vector art. Simlarly, it is only called from the main event loop, so we are safe to muck arround with the current document etc. so we can do a true render.

Definition at line 1131 of file cartprov.cpp.

01132 {
01133     ResourceID r = GetResourceID(ResWithFlags);
01134     CamArtFlags f = GetFlags(ResWithFlags);
01135     wxImage * pBitmap = NULL;
01136 
01137     // find the name by looking up the ID as a string
01138     const TCHAR * tcname = NULL; /*CamResource::GetTextFail(r);*/
01139     if (!tcname || ( (tcname[0]==_T('-')) && !tcname[1]) )
01140     {
01141         // default to object name
01142         tcname = CamResource::GetObjectNameFail(r);
01143     }
01144 
01145     if (!tcname)
01146     {
01147         // If this goes off, then somehow we've been passed a resource ID without a reverse
01148         // bitmap lookup. This can normally only happen if the resource ID is corrupted, or
01149         // the resources are corrupted
01150         ERROR3_PF(("Cannot get bitmap name for resource %d",r));
01151         delete pBitmap;
01152         return FALSE;
01153     }
01154 
01155     wxString basename(tcname);
01156     wxString resname;
01157 
01158     // Iterate over all extensions
01159     INT32 ext;
01160     for (ext=0; ext<(INT32)(CamResource::BitmapExtensions.GetCount()); ext++)
01161     {
01162         resname=CamResource::MakeBitmapString(basename, MakeBitmapFlagString(f), CamResource::BitmapExtensions[ext]);
01163     
01164         pBitmap=CamResource::GetCachedBitmap(resname.c_str());
01165         if (pBitmap) return pBitmap;
01166     
01167         // OK, it didn't work. Try deleting the flags in order and seeing whether
01168         // that works. Note each of these will itself try deleting flags. Thus recursively
01169         // we work our way down to the base bitmap.
01170     
01171 #ifdef _DEBUG
01172         static INT32 recursion=0;
01173         recursion++;
01174         ERROR3IF(recursion>16,"Too much recursion in CamArtProvider::MakeBitmap");
01175 #endif
01176         if (!pBitmap && (f & CAF_SELECTED)) pBitmap=MakeBitmap(CombineFlags(r, (CamArtFlags)(f & ~CAF_SELECTED)));
01177         if (!pBitmap && (f & CAF_FOCUS)) pBitmap=MakeBitmap(CombineFlags(r, (CamArtFlags)(f & ~CAF_FOCUS)));
01178         if (!pBitmap && (f & CAF_SMALL)) pBitmap=MakeBitmap(CombineFlags(r, (CamArtFlags)(f & ~CAF_SMALL)));
01179         if (!pBitmap && (f & CAF_GREYED)) pBitmap=MakeBitmap(CombineFlags(r, (CamArtFlags)(f & ~CAF_GREYED)));
01180 #if _DEBUG
01181         recursion--;
01182 #endif
01183         if (pBitmap) return pBitmap;
01184     }   
01185 
01186     return NULL;
01187 }

wxString CamArtProvider::MakeBitmapFlagString const CamArtFlags  flags  )  [static]
 

Author:
Alex_Bligh <alex@alex.org.uk>
Date:
24/01/2005
Parameters:
flags - the flags to look at [INPUTS]
None [OUTPUTS]
Returns:
Flags string associated with a bitmap

Errors: -

See also:
-

Definition at line 1232 of file cartprov.cpp.

01233 {
01234     wxString mod;
01235 
01236     if (flags & CAF_SMALL) mod+=_T("s");
01237     if (flags & CAF_FOCUS) mod+=_T("f");
01238     if (flags & CAF_SELECTED) mod+=_T("x");
01239     if (flags & CAF_GREYED) mod+=_T("g");
01240     return mod;
01241 }

void CamArtProvider::ReloadAllArt  ) 
 

Reloads all the art.

Author:
Alex_Bligh <alex@alex.org.uk>
Date:
30/12/2005
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
-

Errors: -

See also:
-

Definition at line 607 of file cartprov.cpp.

00608 {
00609     m_GetBitmapEventPending=FALSE; // to be sure
00610     DeleteHashContents();
00611     EnsureChildBitmapsLoaded();
00612 }


Member Data Documentation

CamArtProvider * CamArtProvider::m_ArtProvider = NULL [static, private]
 

Definition at line 210 of file cartprov.h.

BOOL CamArtProvider::m_GetBitmapEventPending [protected]
 

Definition at line 256 of file cartprov.h.

BOOL CamArtProvider::m_InvalidateArtEventPending [protected]
 

Definition at line 257 of file cartprov.h.

ResIDWithFlagsToBitmapPtr* CamArtProvider::m_pHash [protected]
 

Definition at line 255 of file cartprov.h.

wxBitmap* CamArtProvider::m_pMissingBitmap [protected]
 

Definition at line 259 of file cartprov.h.

wxImage* CamArtProvider::m_pMissingImage [protected]
 

Definition at line 258 of file cartprov.h.


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