Mercurial > foo_out_sdl
comparison foosdk/sdk/libPPUI/GDIUtils.h @ 1:20d02a178406 default tip
*: check in everything else
yay
| author | Paper <paper@tflc.us> |
|---|---|
| date | Mon, 05 Jan 2026 02:15:46 -0500 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 0:e9bb126753e7 | 1:20d02a178406 |
|---|---|
| 1 #pragma once | |
| 2 #include "win32_op.h" | |
| 3 | |
| 4 HBITMAP CreateDIB24(CSize size); | |
| 5 HBITMAP CreateDIB16(CSize size); | |
| 6 HBITMAP CreateDIB8(CSize size, const COLORREF palette[256]); | |
| 7 void CreateScaledFont(CFont& out, CFontHandle in, double scale); | |
| 8 void CreateScaledFontEx(CFont& out, CFontHandle in, double scale, int weight); | |
| 9 void CreatePreferencesHeaderFont(CFont& out, CWindow source); | |
| 10 void CreatePreferencesHeaderFont2(CFont& out, CWindow source); | |
| 11 | |
| 12 template<typename TCtrl> | |
| 13 class CAltFontCtrl : public TCtrl { | |
| 14 public: | |
| 15 void Initialize(CWindow wnd, double scale, int weight) { | |
| 16 CreateScaledFontEx(m_font, wnd.GetFont(), scale, weight); | |
| 17 _initWnd(wnd); | |
| 18 } | |
| 19 void MakeHeader(CWindow wnd) { | |
| 20 CreatePreferencesHeaderFont(m_font, wnd); | |
| 21 _initWnd(wnd); | |
| 22 } | |
| 23 void MakeHeader2(CWindow wnd) { | |
| 24 CreatePreferencesHeaderFont2(m_font, wnd); | |
| 25 _initWnd(wnd); | |
| 26 } | |
| 27 private: | |
| 28 void _initWnd(CWindow wnd) { | |
| 29 this->SubclassWindow(wnd); this->SetFont(m_font); | |
| 30 } | |
| 31 CFont m_font; | |
| 32 }; | |
| 33 | |
| 34 class CFontScaled : public CFont { | |
| 35 public: | |
| 36 CFontScaled(HFONT _in, double scale) { | |
| 37 CreateScaledFont(*this, _in, scale); | |
| 38 } | |
| 39 }; | |
| 40 | |
| 41 class DCClipRgnScope { | |
| 42 public: | |
| 43 DCClipRgnScope(HDC dc) : m_dc(dc) { | |
| 44 m_dc.GetClipRgn(m_rgn); | |
| 45 } | |
| 46 ~DCClipRgnScope() { | |
| 47 m_dc.SelectClipRgn(m_rgn); | |
| 48 } | |
| 49 | |
| 50 HRGN OldVal() const noexcept {return m_rgn;} | |
| 51 | |
| 52 PFC_CLASS_NOT_COPYABLE_EX(DCClipRgnScope) | |
| 53 private: | |
| 54 CDCHandle m_dc; | |
| 55 CRgn m_rgn; | |
| 56 }; | |
| 57 | |
| 58 | |
| 59 HBRUSH MakeTempBrush(HDC dc, COLORREF color) noexcept; | |
| 60 | |
| 61 class CDCBrush : public CBrushHandle { | |
| 62 public: | |
| 63 CDCBrush(HDC dc, COLORREF color) noexcept { | |
| 64 m_dc = dc; | |
| 65 m_oldCol = m_dc.SetDCBrushColor(color); | |
| 66 m_hBrush = (HBRUSH) GetStockObject(DC_BRUSH); | |
| 67 } | |
| 68 ~CDCBrush() noexcept { | |
| 69 m_dc.SetDCBrushColor(m_oldCol); | |
| 70 } | |
| 71 PFC_CLASS_NOT_COPYABLE_EX(CDCBrush) | |
| 72 private: | |
| 73 CDCHandle m_dc; | |
| 74 COLORREF m_oldCol; | |
| 75 }; | |
| 76 | |
| 77 class CDCPen : public CPenHandle { | |
| 78 public: | |
| 79 CDCPen(HDC dc, COLORREF color) noexcept { | |
| 80 m_dc = dc; | |
| 81 m_oldCol = m_dc.SetDCPenColor(color); | |
| 82 m_hPen = (HPEN) GetStockObject(DC_PEN); | |
| 83 } | |
| 84 ~CDCPen() noexcept { | |
| 85 m_dc.SetDCPenColor(m_oldCol); | |
| 86 } | |
| 87 private: | |
| 88 CDCHandle m_dc; | |
| 89 COLORREF m_oldCol; | |
| 90 }; | |
| 91 | |
| 92 | |
| 93 class CBackBuffer : public CDC { | |
| 94 public: | |
| 95 CBackBuffer() { | |
| 96 CreateCompatibleDC(NULL); | |
| 97 ATLASSERT(m_hDC != NULL); | |
| 98 } | |
| 99 ~CBackBuffer() { | |
| 100 Dispose(); | |
| 101 } | |
| 102 void Attach(HBITMAP bmp, CSize size) { | |
| 103 Dispose(); | |
| 104 m_bitmap.Attach(bmp); m_curSize = size; | |
| 105 m_bitmapOld = SelectBitmap(m_bitmap); | |
| 106 } | |
| 107 void Attach(HBITMAP bmp) { | |
| 108 CSize size; | |
| 109 bool state = CBitmapHandle(bmp).GetSize(size); | |
| 110 ATLASSERT(state); (void)state; | |
| 111 Attach(bmp, size); | |
| 112 } | |
| 113 BOOL Allocate(CSize size, HDC dcCompatible = NULL) { | |
| 114 if (m_hDC == NULL) return FALSE; | |
| 115 if (m_curSize == size) return TRUE; | |
| 116 Dispose(); | |
| 117 HBITMAP temp; | |
| 118 if (dcCompatible == NULL) { | |
| 119 temp = CreateDIB24(size); | |
| 120 } else { | |
| 121 temp = CreateCompatibleBitmap(dcCompatible, size.cx, size.cy); | |
| 122 } | |
| 123 if (temp == NULL) return FALSE; | |
| 124 Attach(temp); | |
| 125 return TRUE; | |
| 126 } | |
| 127 | |
| 128 void Dispose() { | |
| 129 if (m_bitmap != NULL) { | |
| 130 SelectBitmap(m_bitmapOld); m_bitmapOld = NULL; | |
| 131 m_bitmap.DeleteObject(); | |
| 132 } | |
| 133 m_curSize = CSize(0,0); | |
| 134 } | |
| 135 BOOL GetBitmapPtr(t_uint8 * & ptr, t_ssize & lineWidth) { | |
| 136 if (m_bitmap == NULL) return FALSE; | |
| 137 BITMAP bmp = {}; | |
| 138 if (!m_bitmap.GetBitmap(bmp)) return FALSE; | |
| 139 lineWidth = bmp.bmWidthBytes; | |
| 140 ptr = reinterpret_cast<t_uint8*>(bmp.bmBits); | |
| 141 return TRUE; | |
| 142 } | |
| 143 CSize GetSize() const { return m_curSize; } | |
| 144 | |
| 145 PFC_CLASS_NOT_COPYABLE_EX(CBackBuffer) | |
| 146 private: | |
| 147 CSize m_curSize = CSize(0,0); | |
| 148 CBitmap m_bitmap; | |
| 149 HBITMAP m_bitmapOld = NULL; | |
| 150 }; | |
| 151 | |
| 152 class CBackBufferScope : public CDCHandle { | |
| 153 public: | |
| 154 CBackBufferScope(HDC hDC, HDC hDCBB, const CRect & rcPaint) : CDCHandle(hDCBB), m_rcPaint(rcPaint), m_dcOrig(hDC) | |
| 155 { | |
| 156 GetClipRgn(m_clipRgnOld); | |
| 157 CRgn temp; | |
| 158 if (m_dcOrig.GetClipRgn(temp) == 1) { | |
| 159 if (m_clipRgnOld != NULL) temp.CombineRgn(m_clipRgnOld,RGN_AND); | |
| 160 SelectClipRgn(temp); | |
| 161 } | |
| 162 IntersectClipRect(rcPaint); | |
| 163 } | |
| 164 | |
| 165 ~CBackBufferScope() | |
| 166 { | |
| 167 m_dcOrig.BitBlt(m_rcPaint.left,m_rcPaint.top,m_rcPaint.Width(),m_rcPaint.Height(),m_hDC,m_rcPaint.left,m_rcPaint.top,SRCCOPY); | |
| 168 SelectClipRgn(m_clipRgnOld); | |
| 169 } | |
| 170 private: | |
| 171 const CRect m_rcPaint; | |
| 172 CDCHandle m_dcOrig; | |
| 173 CRgn m_clipRgnOld; | |
| 174 }; | |
| 175 | |
| 176 class SetTextColorScope { | |
| 177 public: | |
| 178 SetTextColorScope(HDC dc, COLORREF col) noexcept : m_dc(dc) { | |
| 179 m_oldCol = SetTextColor(dc, col); | |
| 180 } | |
| 181 ~SetTextColorScope() noexcept { | |
| 182 SetTextColor(m_dc, m_oldCol); | |
| 183 } | |
| 184 PFC_CLASS_NOT_COPYABLE_EX(SetTextColorScope) | |
| 185 private: | |
| 186 HDC m_dc; | |
| 187 COLORREF m_oldCol; | |
| 188 }; | |
| 189 | |
| 190 CSize GetBitmapSize(HBITMAP bmp); | |
| 191 CSize GetIconSize(HICON icon); |
