1 #ifndef NEO_GDI_OBJECT_H
2 #define NEO_GDI_OBJECT_H
10 template<
typename HANDLE_T>
14 GdiObject(HANDLE_T pHandle = 0) : handle(pHandle) {}
20 void SetHandle(HANDLE_T pHandle)
26 operator HANDLE_T() {
return handle; }
42 void Create(COLORREF color) { SetHandle(CreateSolidBrush(color)); }
57 void Create(
int hatch, COLORREF color) { SetHandle(CreateHatchBrush(hatch, color)); }
72 void Create(HBITMAP bitmap) { SetHandle(CreatePatternBrush(bitmap)); }
86 Pen(COLORREF color,
int width = 1,
int penStyle = PS_SOLID) {
Create(color, width, penStyle); }
89 void Create(COLORREF color,
int width = 1,
int penStyle = PS_SOLID) { SetHandle(CreatePen(penStyle, width, color)); }
101 Bitmap(
int width,
int height, UINT planes, UINT bpp,
const void* data) {
CreateBitmap(width, height, planes, bpp, data); }
108 void CreateBitmap(
int width,
int height, UINT planes, UINT bpp,
const void* data) { SetHandle(::
CreateBitmap(width, height, planes, bpp, data)); }
112 void LoadBitmap(
const tstring& filename) { DeleteObject(handle); SetHandle((HBITMAP)LoadImage(0, filename.c_str(), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE)); }
137 DibSection(
int width,
int height,
int bpp,
bool bottomup =
true);
139 DibSection(HBITMAP bitmap,
int bpp,
bool bottomup);
146 static int BPP(HBITMAP bitmap);
152 static void FillBitmapInfo(BITMAPINFO& bmi,
int w,
int h,
int bpp,
bool bottomup =
true);
155 bool Create(
int width,
int height,
int bpp,
bool bottomup =
true);
157 bool CopyCreate(HBITMAP bitmap,
int bpp,
bool bottomup);
162 bool Attach(HBITMAP bitmap);
191 static bool GetObject(HANDLE handle, T& obj) { return ::GetObject(handle,
sizeof(obj), &obj) ==
sizeof(obj); }
206 , weight(FW_DONTCARE)
210 , charset(ANSI_CHARSET)
211 , outPrecision(OUT_DEFAULT_PRECIS)
212 , clipPrecision(CLIP_DEFAULT_PRECIS)
213 , quality(PROOF_QUALITY)
214 , pitchAndFamily(VARIABLE_PITCH | FF_DONTCARE)
247 return ::CreateFont(height,
274 DWORD pitchAndFamily;
287 void Create(
int height,
const FontParams& params =
FontParams()) { SetHandle(params.CreateFont(height)); }
300 NONCLIENTMETRICS ncm;
301 ncm.cbSize =
sizeof(ncm);
305 #if(WINVER >= 0x0600)
307 os.dwOSVersionInfoSize =
sizeof(os);
310 if(os.dwMajorVersion < 6)
313 ncm.cbSize -=
sizeof(ncm.iPaddedBorderWidth);
315 SystemParametersInfo(SPI_GETNONCLIENTMETRICS, ncm.cbSize, &ncm, 0);
318 SetHandle(CreateFontIndirect(&ncm.lfMessageFont));
333 Create(width, height, bpp, bottomup);
358 if(GetObject(bitmap, bm))
359 return bm.bmBitsPixel;
366 return GetObject(bitmap, ds);
372 if(GetObject(bitmap, ds))
373 return ds.dsBmih.biHeight > 0;
379 ZeroMemory(&bmi,
sizeof(bmi));
380 bmi.bmiHeader.biSize =
sizeof(bmi.bmiHeader);
381 bmi.bmiHeader.biWidth = w;
382 bmi.bmiHeader.biHeight = h;
384 bmi.bmiHeader.biHeight = -h;
385 bmi.bmiHeader.biBitCount = bpp;
386 bmi.bmiHeader.biPlanes = 1;
387 bmi.bmiHeader.biCompression = BI_RGB;
388 bmi.bmiHeader.biXPelsPerMeter = 0x0ec4;
389 bmi.bmiHeader.biYPelsPerMeter = 0x0ec4;
394 DeleteObject(handle);
397 handle = CreateDIBSection(
ClientDC(0), &
dibInfo, DIB_RGB_COLORS, 0, 0, 0);
410 if(GetObject(bitmap, bm))
411 if(
Create(bm.bmWidth, bm.bmHeight, bpp, bottomup))
422 if(GetObject(bitmap, ds)){
423 DeleteObject(handle);
436 HBITMAP result = handle;
444 DeleteObject(handle);
453 if(GetObject(bitmap, bm))
464 if(GetObject(bitmap, bm))
HBITMAP Detach()
Definition: GdiObject.h:434
FontParams & SetOrientation(int pOrientation)
Definition: GdiObject.h:222
void Create(COLORREF color)
Definition: GdiObject.h:42
void Create(int hatch, COLORREF color)
Definition: GdiObject.h:57
void LoadBitmap(const tstring &filename)
Definition: GdiObject.h:112
PatternBrush(HBITMAP bitmap)
Definition: GdiObject.h:69
bool CopyToBitmap(HBITMAP bitmap)
Definition: GdiObject.h:461
static void FillBitmapInfo(BITMAPINFO &bmi, int w, int h, int bpp, bool bottomup=true)
Definition: GdiObject.h:377
Font parameters with everything set to default.
Definition: GdiObject.h:199
Bitmap()
Definition: GdiObject.h:99
Brush handle
Definition: GdiObject.h:63
FontParams & SetItalic(BOOL set)
Definition: GdiObject.h:226
FontParams & SetUnderline(BOOL set)
Definition: GdiObject.h:228
static bool IsDibSection(HBITMAP bitmap)
Definition: GdiObject.h:363
FontParams & SetOutPrecision(BYTE pOutPrecision)
Definition: GdiObject.h:234
bool IsBottomUp()
Definition: GdiObject.h:183
int GetWidth()
Definition: GdiObject.h:173
void * GetBits()
Definition: GdiObject.h:179
Basic GDI class that automatically deletes the handle.
Definition: GdiObject.h:11
int GetHeight()
Definition: GdiObject.h:175
bool CopyCreate(HBITMAP bitmap)
Definition: GdiObject.h:159
PatternBrush()
Definition: GdiObject.h:67
void * GetPixelAddress(int x, int y)
Definition: GdiObject.h:181
Brush handle
Definition: GdiObject.h:48
BITMAP dibData
Definition: GdiObject.h:187
bool Create(int width, int height, int bpp, bool bottomup=true)
Definition: GdiObject.h:392
void Create(COLORREF color, int width=1, int penStyle=PS_SOLID)
Definition: GdiObject.h:89
Pen(COLORREF color, int width=1, int penStyle=PS_SOLID)
Definition: GdiObject.h:86
Wraps the creation of a BITMAP struct from a HBITMAP.
Definition: GdiObject.h:118
void CreateBitmap(int width, int height, UINT planes, UINT bpp, const void *data)
Definition: GdiObject.h:108
void CreateDefaultFont()
Definition: GdiObject.h:297
BITMAPINFO dibInfo
Definition: GdiObject.h:188
Bitmap(int width, int height, UINT planes, UINT bpp, const void *data)
Definition: GdiObject.h:101
Font handle
Definition: GdiObject.h:281
Bitmap(const tstring &filename)
Definition: GdiObject.h:105
FontParams & SetClipPrecision(BYTE pClipPrecision)
Definition: GdiObject.h:236
Pen handle
Definition: GdiObject.h:80
int GetBPP()
Definition: GdiObject.h:177
void Create(HBITMAP bitmap)
Definition: GdiObject.h:72
HatchBrush()
Definition: GdiObject.h:52
Device independent bitmap.
Definition: GdiObject.h:131
Bitmap(HDC compatibleDC, int width, int height)
Definition: GdiObject.h:103
DibSection()
Definition: GdiObject.h:324
FontParams & SetEscapment(int pEscapement)
Definition: GdiObject.h:220
HatchBrush(int hatch, COLORREF color)
Definition: GdiObject.h:54
FontParams & SetPitchAndFamily(BYTE pPitchAndFamily)
Definition: GdiObject.h:240
bool Attach(HBITMAP bitmap)
Definition: GdiObject.h:419
HFONT CreateFont(int height) const
Definition: GdiObject.h:245
SolidBrush()
Definition: GdiObject.h:37
FontParams & SetWeight(int pWeight)
Definition: GdiObject.h:224
Brush handle
Definition: GdiObject.h:33
A client device context allows drawing to the client area of a window.
Definition: DC.h:218
bool CopyCreate(HBITMAP bitmap, int bpp, bool bottomup)
Definition: GdiObject.h:407
bool CopyFromBitmap(HBITMAP bitmap)
Definition: GdiObject.h:450
FontParams & SetFaceName(const tstring &pFacename)
Definition: GdiObject.h:242
FontParams & SetCharSet(BYTE pCharset)
Definition: GdiObject.h:232
FontParams & SetWidth(int pWidth)
Definition: GdiObject.h:218
DibSection & operator=(const DibSection &other)
Definition: GdiObject.h:348
void CreateCompatibleBitmap(HDC compatibleDC, int width, int height)
Definition: GdiObject.h:110
Pen()
Definition: GdiObject.h:84
FontParams & SetQuality(BYTE pQuality)
Definition: GdiObject.h:238
void Clear()
Definition: GdiObject.h:442
FontParams & SetStrikeout(BOOL set)
Definition: GdiObject.h:230
static int BPP(HBITMAP bitmap)
Definition: GdiObject.h:355
Bitmap handle
Definition: GdiObject.h:95
int FlippedY(int y)
Definition: GdiObject.h:185
SolidBrush(COLORREF color)
Definition: GdiObject.h:39