11#if defined(BI_MULTI_THREAD_RTL)
15#if defined(__BORLANDC__)
40#if defined(BI_MULTI_THREAD_RTL)
54 HANDLE Lookup(COLORREF color);
55 bool CheckHandle(HANDLE handle);
57 bool AddRef(HANDLE handle, COLORREF color);
58 void DecRef(HANDLE handle);
60#if defined(BI_MULTI_THREAD_RTL)
70TBrushCache& GetBrushCache();
79TBrushCache& GetBrushCache()
84 static TBrushCache __BrushCache;
89#if defined(BI_MULTI_THREAD_RTL)
90#define LOCKCACHE(l,s) TMRSWSection::TLock __lock(l,s)
98TBrushCache::TBrushCache()
102 memset(Entries,0,
sizeof(Entries));
109TBrushCache::~TBrushCache()
111 for (
int i = 0; i < Size; i++){
112 if (Entries[i].Handle) {
113 TGdiObject::RefDec(Entries[i].Handle,
false);
116 Entries[i].Handle =
nullptr;
117 Entries[i].Color = 0;
118 Entries[i].RefCnt = 0;
127TBrushCache::Float(
int i)
130 HANDLE handle = Entries[i].Handle;
131 COLORREF color = Entries[i].Color;
132 int refCnt = Entries[i].RefCnt;
134 TRACEX(OwlGDI, 2,
_T(
"TBrushCache::Float(") << i <<
_T(
") (") <<
135 static_cast<void*
>(handle) <<
_T(
", ") << hex << color <<
_T(
")"));
138 memmove(Entries+1, Entries,
sizeof(TEntry)*i);
139 Entries[0].Handle = handle;
140 Entries[0].Color = color;
141 Entries[0].RefCnt = refCnt;
150TBrushCache::AddRef(HANDLE handle, COLORREF color)
153 TRACEX(OwlGDI, 2,
_T(
"TBrushCache::Add(") <<
static_cast<void*
>(handle) <<
154 _T(
", ") << hex << color <<
_T(
")"));
158 if (Entries[Size-1].Handle){
162 if(!Entries[i].RefCnt){
163 TGdiObject::RefDec(Entries[i].Handle,
true);
165 Entries[i].Handle = handle;
166 Entries[i].Color = color;
167 Entries[i].RefCnt = 1;
177 memmove(Entries+1, Entries,
sizeof(TEntry)*(Size-1));
178 Entries[0].Handle = handle;
179 Entries[0].Color = color;
180 Entries[0].RefCnt = 1;
183 TGdiObject::RefAdd(handle, TGdiObject::Brush);
192TBrushCache::DecRef(HANDLE handle)
194 for (
int i = 0; i < Size && Entries[i].Handle; i++){
195 if (handle == Entries[i].Handle) {
196 TRACEX(OwlGDI, 2,
_T(
"TBrushCache::DecRef(") << hex << handle <<
197 _T(
"): found ") <<
_T(
" @") << i);
199 CHECK(Entries[i].RefCnt >= 0);
209TBrushCache::CheckHandle(HANDLE handle)
211 for (
int i = 0; i < Size && Entries[i].Handle; i++){
212 if (handle == Entries[i].Handle) {
213 TRACEX(OwlGDI, 2,
_T(
"TBrushCache::CheckHandle(") <<
214 static_cast<void*
>(Entries[i].Handle) <<
_T(
" @") << i);
219 TRACEX(OwlGDI, 2,
_T(
"TBrushCache::CheckHandle(") <<
static_cast<void*
>(handle) <<
_T(
"): not found"));
227TBrushCache::Lookup(COLORREF color)
229 for (
int i = 0; i < Size && Entries[i].Handle; i++){
230 if (color == Entries[i].Color) {
231 TRACEX(OwlGDI, 2,
_T(
"TBrushCache::Lookup(") << hex << color <<
232 _T(
"): found ") <<
static_cast<void*
>(Entries[i].Handle) <<
_T(
" @") << i);
235 return Entries[0].Handle;
238 TRACEX(OwlGDI, 2,
_T(
"TBrushCache::Lookup(") << hex << color <<
_T(
"): not found"));
260 GetBrushCache().CheckHandle(
Handle);
262 _T(
" with handle ") <<
static_cast<void*
>(handle));
277 if(useCache && (
Handle = GetBrushCache().Lookup(cr)) !=
nullptr)
287 Handle = ::CreateSolidBrush(cr);
289 WARNX(OwlGDI, !
Handle, 0,
_T(
"Cannot create solid TBrush ") << hex << color);
296 if(!GetBrushCache().AddRef(
Handle, color))
314 _T(
" with color ") <<
static_cast<COLORREF
>(color));
323 Handle = ::CreateHatchBrush(style, color);
324 WARNX(OwlGDI, !
Handle, 0,
_T(
"Cannot create hatch TBrush ") << hex << color <<
329 _T(
" with color ") <<
static_cast<COLORREF
>(color) <<
330 _T(
", style 0x") << style);
340 WARNX(OwlGDI, !
Handle, 0,
_T(
"Cannot create pattern TBrush from bitmap ") <<
341 static_cast<void*
>(
pattern.GetHandle()));
345 _T(
" from bitmap ") <<
static_cast<const void*
>(
pattern.GetHandle()));
354 Handle = ::CreateBrushIndirect(&logBrush);
355 WARNX(OwlGDI, !
Handle, 0,
_T(
"Cannot create TBrush from logBrush @") <<
static_cast<const void*
>(&logBrush));
359 <<
_T(
" from logBrush @") <<
static_cast<const void*
>(&logBrush));
362#if defined(OWL5_COMPAT)
371 Handle = ::CreateBrushIndirect((LPLOGBRUSH)logBrush);
372 WARNX(OwlGDI, !
Handle, 0,
_T(
"Cannot create TBrush from logBrush @") <<
static_cast<const void*
>(logBrush));
376 _T(
" from logBrush @") <<
static_cast<const void*
>(logBrush));
388#if !defined(NO_GDI_SHARE_HANDLES)
394 Handle = ::CreateBrushIndirect(&logBrush);
395 WARNX(OwlGDI, !
Handle, 0,
_T(
"Cannot create TBrush from TBrush @") <<
396 hex <<
uint32(LPVOID(&src)));
401 _T(
" from TBrush @") << (
void*)&src);
411 GetBrushCache().DecRef(
Handle);
421 WARNX(OwlGDI, !
Handle, 0,
_T(
"Cannot create pattern TBrush from DIB ") <<
422 static_cast<void*
>(
pattern.GetHandle()));
426 _T(
" from DIB ") <<
static_cast<void*
>(
pattern.GetHandle()));
468 Handle = Create(hatch, fgColor, bgColor);
476THatch8x8Brush::Create(
const uint8 hatch[],
const TColor& fgColor,
const TColor& bgColor)
478 TDib dib(8, 8, 2, DIB_RGB_COLORS);
480 memset(bits, 0, 8*
sizeof(
uint32));
481 for (
int i = 0; i < 8; i++)
482 bits[(7-i) *
sizeof(
uint32)] = hatch[i];
483 dib.SetColor(0, bgColor);
484 dib.SetColor(1, fgColor);
488 LOGBRUSH lb = { BS_PATTERN, DIB_RGB_COLORS, (int)HANDLE(bm) };
489 HBRUSH handle = ::CreateBrushIndirect(&lb);
491 HBRUSH handle = ::CreateDIBPatternBrush(dib.GetHandle(), DIB_RGB_COLORS);
503 0x99, 0x33, 0x66, 0xCC, 0x99, 0x33, 0x66, 0xCC
507 0x88, 0x11, 0x22, 0x44, 0x88, 0x11, 0x22, 0x44
511 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55
515 0xCC, 0x66, 0x33, 0x99, 0xCC, 0x66, 0x33, 0x99
519 0x44, 0x22, 0x11, 0x88, 0x44, 0x22, 0x11, 0x88
#define WARNX(group, condition, level, message)
#define PRECONDITION(condition)
#define TRACEX(group, level, message)
TBitmap is the GDI bitmap class derived from TGdiObject.
LOGBRUSH GetObject() const
Retrieves information about this brush object and places it in the given LOGBRUSH structure.
HBRUSH GetHandle() const
Returns the handle of the brush with type HBRUSH.
TBrush(HBRUSH handle, TAutoDelete autoDelete=NoAutoDelete)
TBrush encapsulates an HBRUSH.
Class wrapper for management of color values.
int Index() const
Return the index of the palette entry.
bool IsSysColor() const
Return true if the color is a system color.
Pseudo-GDI object Device Independent Bitmap (DIB) class.
static void RefDec(HANDLE handle, bool wantDelete)
Decrements this object's reference count by 1 and deletes the object when the reference count reaches...
void CheckValid(uint resId=IDS_GDIFAILURE)
static void _CheckValid(HANDLE handle, uint resId=IDS_GDIFAILURE)
int GetObject(int count, void *object) const
Retrieve the object's attributes into a buffer.
bool ShouldDelete
Should object delete GDI handle in dtor?
static void RefAdd(HANDLE handle, TType type)
RefAdd adds a reference entry for the object with the given handle and type.
TGdiObject()
This default constructor sets Handle to 0 and ShouldDelete to true.
HANDLE Handle
GDI handle of this object.
static const uint8 Hatch11F1[8]
The static array Hatch11F1[8] holds the logical hatched brush pattern of one pixel on and one pixel o...
static const uint8 Hatch13F1[8]
The static array Hatch13F1[8] holds a hatched brush pattern of one pixel on and three pixels off in f...
void Reconstruct(const uint8 hatch[], const TColor &fgColor, const TColor &bgColor)
Reconstructs the hatched brush with a new pattern or new set of colors.
static const uint8 Hatch22F1[8]
The static array Hatch22F1[8] holds a monochrome hatched brush pattern of two pixels on and two off i...
static const uint8 Hatch13B1[8]
The static array Hatch13B1[8] holds a hatched brush pattern of one pixel on and three pixels off in b...
THatch8x8Brush(const uint8 hatch[], const TColor &fgColor=TColor::White, const TColor &bgColor=TColor::Black)
Constructs a THatchBrush object with the specified hatched pattern and colors.
static const uint8 Hatch22B1[8]
The static array Hatch22B1[8] holds a hatched brush pattern of two pixels on and two off in backward ...
TXGdi(uint resId=IDS_GDIFAILURE, HANDLE handle=0)
Constructs a TXGdi object with a default IDS_GDIFAILURE message.
Definition of abstract GDI object class and derived classes.
TAutoDelete
Flag for Handle ctors to control Handle deletion in dtor.
Object Windows Library (OWLNext Core).
DIAG_DECLARE_GROUP(OwlThread)