GBrush Class Reference

A GBrush is a way of getting to Gavin-created brushes, when available. It can supply GDI with better dithered brushes than it does normally. Before use, you should call Init which tells you whether a GBrush is available. If it is not, no further use can be made of it. If it is, call Start on it (cv StartRender). It can then be used, until such time as End is called on it. An in-line member function called Available can be used to determine its functionality at any time. There can only be one active GBrush in use at a time. More...

#include <gbrush.h>

Inheritance diagram for GBrush:

ListItem CCObject SimpleCCObject List of all members.

Public Member Functions

 GBrush ()
 GBrush constructor. Call Init before trying to use.
 ~GBrush ()
 GBrush destructor. Does necessary cleanup.
BOOL Init (wxDC *Ref)
 Determines whether a GBrush can be used in the given device. Call Start before trying to use, assuming a TRUE result.
void Start ()
 Call before trying to use the GBrush. There can only be one active GBrush in use at a time. Will fail silently if not available.
void Stop ()
 Says 'we have stopped using this for the moment'. Call Start to start again. It is not necessary to call this before destruction. Safe to call even if not Available.
BOOL Available ()
void GetLogBrush (ColourContext *, DocColour &, wxBrush *)
 The whole point of the GBrush class is to get one of these.
void GetLogBrush (const COLORREF rgb, wxBrush *pBrush)
 The whole point of the GBrush class is to get one of these. This method returns a brush given the RGB screen word to use fo it. Probably you really want to use the other overloaded GetLogBrush method, as this does all the colour conversion for you.
void SetSolidColours (BOOL UseSolid)
 Allows the dithering of colours to be turned off so they look the same using GDraw as they do with the GDI.

Static Public Member Functions

static BOOL InitGBrush (BOOL)
 Allows the user to determine whether GDraw brushes are used (1) or normal GDI brushes (0). Defaults to 1 because it produces a much nicer colour bar.GBuilds the pretend bitmap which ise used to fool GDraw into suppyling us with brushes. Called from GRenderRegion::Init and relies on that being called first.
static void DeinitGBrush (void)
 De-initialises the GBrush pretend bitmap. Called on DeInit of GRenderRegion to shut down without a memory leak taking place.
static void NewBrushState ()
 Called when the WantBetterBrushes state changes. Goes around and invalidates any current GBrushes, else they will be wrong. It also frees the global memory block in each GBrush so it will be re-allocated.
static void ResetOnFatalError ()

Private Member Functions

 CC_DECLARE_MEMDUMP (GBrush)
void GetLogBrushInternal (const COLORREF rgb, wxBrush *pBrush)
 The whole point of the GBrush class is to get one of these. This is an inline macro used by the 2 overloaded GetLogBrush functions so the code need only be changed in one place.

Private Attributes

BOOL Valid
BOOL CanUse
wxDC * ReferenceDC
RGBQUAD RGBList [256]
BOOL UseSolidColours

Static Private Attributes

static List BrushList
static GBrushCurrent

Detailed Description

A GBrush is a way of getting to Gavin-created brushes, when available. It can supply GDI with better dithered brushes than it does normally. Before use, you should call Init which tells you whether a GBrush is available. If it is not, no further use can be made of it. If it is, call Start on it (cv StartRender). It can then be used, until such time as End is called on it. An in-line member function called Available can be used to determine its functionality at any time. There can only be one active GBrush in use at a time.

Author:
Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
Date:
5/4/94

Definition at line 126 of file gbrush.h.


Constructor & Destructor Documentation

GBrush::GBrush  ) 
 

GBrush constructor. Call Init before trying to use.

Author:
Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
Date:
5/4/94
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
-
See also:
GBrush::Init
Returns:
Errors: -

Definition at line 238 of file gbrush.cpp.

00239 {
00240     CanUse = FALSE;
00241     Valid = FALSE;
00242 
00243     BrushList.AddHead( this );
00244 
00245     UseSolidColours = FALSE;
00246 }

GBrush::~GBrush  ) 
 

GBrush destructor. Does necessary cleanup.

Author:
Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
Date:
5/4/94
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
-

Errors: -

Definition at line 264 of file gbrush.cpp.

00265 {
00266     if (Current == this)
00267         Current = NULL;
00268 
00269 #ifdef _DEBUG
00270     ListItem *Old = BrushList.RemoveItem( this );
00271     ERROR3IF( Old == NULL, "GBrush being deleted not in list" );
00272 #else
00273     BrushList.RemoveItem( this ); // to suppress compiler warning in both debug & retail builds
00274 #endif
00275 }


Member Function Documentation

BOOL GBrush::Available  )  [inline]
 

Definition at line 135 of file gbrush.h.

00135 { return Valid; }

GBrush::CC_DECLARE_MEMDUMP GBrush   )  [private]
 

void GBrush::DeinitGBrush void   )  [static]
 

De-initialises the GBrush pretend bitmap. Called on DeInit of GRenderRegion to shut down without a memory leak taking place.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
11/9/95
See also:
GBrush::InitGBrush
Returns:
Errors: ERROR3 with graceful exit if there are GBrushes still active at the time
Scope: Static

Definition at line 209 of file gbrush.cpp.

00210 {
00211 #ifdef _DEBUG
00212     // This was an ERROR3, but our stupid error handler doesn't handle errors very well,
00213     // (in fact, at this stage in program de-initialisation, it doesn' handle them at all)
00214     // so it's just a trace warning now.
00215     if (!BrushList.IsEmpty())
00216     {
00217         TRACEALL( wxT("Warning: Deinitialising GBrush when GBrush(es) still active\n\n" ) );
00218     }
00219 #endif
00220 }

void GBrush::GetLogBrush const COLORREF  rgb,
wxBrush *  pBrush
 

The whole point of the GBrush class is to get one of these. This method returns a brush given the RGB screen word to use fo it. Probably you really want to use the other overloaded GetLogBrush method, as this does all the colour conversion for you.

Author:
Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>/Jason
Date:
5/4/94 (28/6/94)
Parameters:
rgb - a GDI/GDraw style RGB word defining the colour [INPUTS]
lpBrush is updated to create a suitably brush which can then be passed [OUTPUTS] to CreateBrushIndirect.
Returns:
-

Errors: Will ENSURE if not Available.

See also:
GBrush::Available

Definition at line 543 of file gbrush.cpp.

00544 {
00545     GetLogBrushInternal(rgb,pBrush);
00546 }

void GBrush::GetLogBrush ColourContext OutputContext,
DocColour Col,
wxBrush *  pBrush
 

The whole point of the GBrush class is to get one of these.

Author:
Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
Date:
5/4/94
Parameters:
OutputContext - The output colour context in which the DocColour [INPUTS] is to be used. Col - colour that the brush is required in
lpBrush is updated to create a suitably brush which can then be passed [OUTPUTS] to CreateBrushIndirect.
Returns:
-

Errors: Will ENSURE if not Available.

See also:
GBrush::Available

Definition at line 515 of file gbrush.cpp.

00516 {
00517     const COLORREF rgb = ConvertColourToScreenWord(OutputContext, &Col);
00518 
00519     GetLogBrushInternal(rgb,pBrush);
00520 }

void GBrush::GetLogBrushInternal const COLORREF  rgb,
wxBrush *  pBrush
[inline, private]
 

The whole point of the GBrush class is to get one of these. This is an inline macro used by the 2 overloaded GetLogBrush functions so the code need only be changed in one place.

Author:
Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com> (Jason)
Date:
5/4/94 (28/6/94)
Parameters:
rgb - a GDI/GDraw style RGB word defining the colour [INPUTS]
lpBrush is updated to create a suitably brush which can then be passed [OUTPUTS] to CreateBrushIndirect.
Returns:
-

Errors: Will ENSURE if not Available. Notes: This is fundametally the same as the other overloaded GetLogBrush, but for efficiency I've repeated the code in both functions.

SetSolidColours should be called to enable/disable dithering of this brush

See also:
GBrush::Available; GBrush::SetSolidColours

Definition at line 417 of file gbrush.cpp.

00418 {
00419     ERROR3IF( !Valid, "GBrush called when not available");
00420     ERROR3IF( Current != this, "GBrush not current");
00421 
00422     pBrush->SetStyle(wxSOLID);
00423 
00424     // we let the Widgets handle primary colours cos they should be able to manage it (!)
00425     if ( ((rgb & 0x0000FF)==0x000000 || (rgb & 0x0000FF)==0x0000FF) &&
00426          ((rgb & 0x00FF00)==0x000000 || (rgb & 0x00FF00)==0x00FF00) &&
00427          ((rgb & 0xFF0000)==0x000000 || (rgb & 0xFF0000)==0xFF0000) )
00428     {
00429         pBrush->SetColour(GetRValue(rgb),GetGValue(rgb),GetBValue(rgb));
00430         return;
00431     }
00432 
00433     // We assume the GBrush is defined in the GContext belonging to GRenderRegions
00434     // ARRRGGHHH Who wrote MakeCurrent() without making it Virtual. What a naughty
00435     // boy I am (Andy, that is! - Jason ;-)
00436     GDrawContext *GContext = GRenderRegion::GetStaticDrawContext();
00437     const BYTE *pGBrush = NULL;
00438 
00439     // This was checked in init/start, but we might as well be safe
00440     if (GContext != NULL)
00441     {
00442         // If the current mode is for solid colours (no dithering) then we ask for solid colour.
00443         // This is used for things like pasteboards which shouldn't dither for aesthetic (eor!) reasons
00444         if (UseSolidColours)
00445             GContext->SetSolidColour(rgb);
00446         else
00447             GContext->SetColour(rgb);
00448 
00449         pGBrush = GContext->ReturnBrushRGB();
00450     }
00451     else
00452         ERROR3("GBrush got a NULL GContext!\n");
00453 
00454     if (pGBrush == NULL)
00455         pBrush->SetColour(GetRValue(rgb),GetGValue(rgb),GetBValue(rgb));
00456     else if ( UseSolidColours )
00457         pBrush->SetColour(pGBrush[0],pGBrush[1],pGBrush[2]);
00458     else
00459     {
00460 #ifdef __WXGTK__
00461         // The following line shouldn't be necessary, but wxGTK appears to
00462         // fail if it doesn't have a valid colour when setting the brush
00463         // into a device context.
00464         pBrush->SetColour(0,0,0);
00465 #endif
00466         wxImage image(4,4,(BYTE*)pGBrush,true);
00467         wxBitmap bitmap(image);
00468         pBrush->SetStipple(bitmap);     // Also sets style to wxSTIPPLE
00469     }
00470 }

BOOL GBrush::Init wxDC *  RefDC  ) 
 

Determines whether a GBrush can be used in the given device. Call Start before trying to use, assuming a TRUE result.

Author:
Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
Date:
5/4/94
Parameters:
RefDC - an HDC of the output device (must be screen currently). [INPUTS] This must remain a valid DC for the entire length of time that this brush is used.
- [OUTPUTS]
Returns:
TRUE if GBrush is available for use, FALSE if not.

Errors: -

Definition at line 295 of file gbrush.cpp.

00296 {
00297     ENSURE( Current==NULL, "Only one current GBrush at a time" );
00298 
00299     Valid = FALSE;                                          // in case of failure
00300 
00301     ReferenceDC = RefDC;                                    // remember for Start time
00302 
00303     CanUse = TRUE;
00304     return CanUse;
00305 }

BOOL GBrush::InitGBrush BOOL  FirstTime  )  [static]
 

Allows the user to determine whether GDraw brushes are used (1) or normal GDI brushes (0). Defaults to 1 because it produces a much nicer colour bar.GBuilds the pretend bitmap which ise used to fool GDraw into suppyling us with brushes. Called from GRenderRegion::Init and relies on that being called first.

Author:
Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
Date:
5/4/94
Parameters:
FirstTime is TRUE if called from starup, FALSE if called subsequently (e.g. [INPUTS] after screen mode change).
- [OUTPUTS]
Returns:
TRUE if worked, FALSE if failed (e.g. no memory). Returns TRUE if not required too (e.g. incompatible screen depth) i.e. FALSE is an error which could be serious.
See also:
GBrush::Init
Returns:
Errors: - Scope: Static

Definition at line 160 of file gbrush.cpp.

00161 {
00162     if (FirstTime && Camelot.DeclareSection( wxT("Screen"), 10))
00163     {
00164         Camelot.DeclarePref(NULL, wxT("BetterBrushes"), &WantBetterBrushes, FALSE, TRUE );
00165     }
00166     // Register the (debug) Op to enable/disable GBrush
00167     if (!Operation::RegisterOpDescriptor(
00168                         0,
00169                         _R(IDS_GBRUSH),
00170                         CC_RUNTIME_CLASS(OpGBrush),
00171                         OPTOKEN_GBRUSH,
00172                         OpGBrush::GetState,
00173                         0,  /* help ID */
00174                         0, //_R(IDBBL_ANTIALIASOP),
00175                         0   /* bitmap ID */
00176                         ))
00177     {
00178         TRACE( wxT("RegisterOpDescriptor( OpGBrush ) failed") );
00179         return FALSE;
00180     }
00181 
00182     // Ensure that none of the GBrushes are active
00183     NewBrushState();
00184     Current = NULL;
00185 
00186     return TRUE;
00187 }

void GBrush::NewBrushState  )  [static]
 

Called when the WantBetterBrushes state changes. Goes around and invalidates any current GBrushes, else they will be wrong. It also frees the global memory block in each GBrush so it will be re-allocated.

Author:
Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
Date:
28/7/94
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
-

Definition at line 566 of file gbrush.cpp.

00567 {
00568     // find all current GBrushes
00569     ListItem *Item = BrushList.GetHead();
00570     while (Item)
00571     {
00572         // check type
00573         #ifdef _DEBUG
00574         ENSURE( Item->GetRuntimeClass() == CC_RUNTIME_CLASS(GBrush), "Not GBrush in list");
00575         #endif
00576 
00577         // safe to cast now
00578         GBrush *const Brush = (GBrush*const)Item;
00579         Brush->Stop();                                  // reset Valid & Current
00580 
00581         // get next one in list
00582         Item = BrushList.GetNext( Item );
00583     }
00584 }

static void GBrush::ResetOnFatalError  )  [inline, static]
 

Definition at line 146 of file gbrush.h.

00146 {if (Current) Current->Stop();}

void GBrush::SetSolidColours BOOL  SetSolid  ) 
 

Allows the dithering of colours to be turned off so they look the same using GDraw as they do with the GDI.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
15/5/95
Parameters:
TRUE to turn off dithering of colours, FALSE to turn on dithering [INPUTS]
Notes: By default, GBrushes use dithering.

Definition at line 489 of file gbrush.cpp.

00490 {
00491     UseSolidColours = SetSolid;
00492 }

void GBrush::Start  ) 
 

Call before trying to use the GBrush. There can only be one active GBrush in use at a time. Will fail silently if not available.

Author:
Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
Date:
5/4/94
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
-

Errors: GBrush::Available

Definition at line 324 of file gbrush.cpp.

00325 {
00326     ENSURE( Current==NULL, "Only one current GBrush at a time" );
00327 
00328     if (CanUse && WantBetterBrushes)
00329     {
00330         GDrawContext *GContext = GRenderRegion::GetStaticDrawContext();
00331 
00332         // We checked this in Init() so it should be OK, but we might as well be safe
00333         if (GContext != NULL)
00334         {
00335             Valid = TRUE;
00336             Current = this;
00337 
00338             // Get the 16bpp screen hinting value so Gavin can do solid colours properly
00339             DWORD GavinHint = DIBUtil::GetGavinBlitFormat(GRenderRegion::ScreenDepth,
00340                                     32, GRenderRegion::ScreenHinting);
00341 
00342             // And set Gavin up to render into our brush bitmap
00343             GContext->SetupBitmap( 
00344                 4,4, 
00345                 GRenderRegion::ScreenDepth==24?32:GRenderRegion::ScreenDepth, 
00346                 NULL, 
00347                 GavinHint
00348             );
00349 
00350             // We want dithering not error diffusion please GDraw
00351             /*pcLOGPALETTE lpPal =*/ GContext->SelectPalette(0);
00352 
00353             // In 8bpp, make sure GDraw is aware of the current system palette
00354             if (GRenderRegion::ScreenDepth == 8)
00355                 GRenderRegion::GColInit( ReferenceDC );
00356 
00357             // Attempt to ensure halftone patterns always use the same origin
00358             GContext->SetHalftoneOrigin(0, 0);
00359         }
00360         else
00361             ERROR3("GDraw Context not available in GBrush::Start()");
00362     }
00363 }

void GBrush::Stop  ) 
 

Says 'we have stopped using this for the moment'. Call Start to start again. It is not necessary to call this before destruction. Safe to call even if not Available.

Author:
Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
Date:
5/4/94
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
-

Errors: -

Definition at line 383 of file gbrush.cpp.

00384 {
00385     if (Current == this)
00386         Current = NULL;
00387 
00388     Valid = FALSE;
00389 }


Member Data Documentation

List GBrush::BrushList [static, private]
 

Definition at line 158 of file gbrush.h.

BOOL GBrush::CanUse [private]
 

Definition at line 152 of file gbrush.h.

GBrush * GBrush::Current [static, private]
 

Definition at line 159 of file gbrush.h.

wxDC* GBrush::ReferenceDC [private]
 

Definition at line 154 of file gbrush.h.

RGBQUAD GBrush::RGBList[256] [private]
 

Definition at line 156 of file gbrush.h.

BOOL GBrush::UseSolidColours [private]
 

Definition at line 161 of file gbrush.h.

BOOL GBrush::Valid [private]
 

Definition at line 151 of file gbrush.h.


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