SavvyUI C++ UI Library
Loading...
Searching...
No Matches
Graphics.h
Go to the documentation of this file.
1#pragma once
2
3#include "Common.h"
4#include "Theme.h"
5#include "Models.h"
6
7#define STANDARD_FONT_NAME L"Arial"
8#define STANDARD_FONT_SIZE 12
9
10enum class IconSourceType {
12 File = 1,
13 Stock = 2,
15};
16
17enum class IconType {
18 ADD = 1,
19 ADDONS = 2,
20 ATTACH = 3,
21 BANNER = 4,
28 CAMERA = 11,
29 CANCEL = 12,
34 CLEAR = 17,
35 COLORS = 18,
39 COPY = 22,
43 REMOVE = 26,
45 DETACH = 28,
47 DISK = 30,
49 EDIT = 32,
52 EXIT = 35,
54 EXPORT = 37,
55 EYE = 38,
56 FILTER = 39,
62 HELP = 45,
63 HOME = 46,
64 IMAGE = 47,
65 IMPORT = 48,
67 INVOICE = 50,
69 LAYAWAY = 52,
70 LINK = 53,
71 LOCK = 54,
72 LOGIN = 55,
73 LOGOUT = 56,
77 NOTE = 60,
78 OK = 61,
85 PO = 69,
86 PRINTER = 70,
87 PRODUCT = 71,
90 QUOTE = 74,
92 REFRESH = 76,
93 REFUNDS = 77,
94 RENTAL = 78,
95 REPAIR = 79,
96 REPORT = 80,
97 RETURNS = 81,
98 SEARCH = 82,
99 SERVICE = 83,
103 SMS = 87,
105 TAG = 89,
106 TAX = 90,
107 TODO = 91,
108 TRASH = 92,
109 UPLOAD = 93,
110 USER = 94,
122};
123
125{
126 IconSourceType _iconFormat;
127
128public:
129
131 {
132 _iconFormat = IconSourceType::Invalid;
133 }
134
135 IconSource(const wstring& iconFile)
136 {
137 _iconFile = iconFile;
138 _iconFormat = iconFile.length() > 0 ? IconSourceType::File : _iconFormat;
139 }
140
141 IconSource(const IconType& iconType)
142 {
143 _iconType = iconType;
144 _iconFormat = IconSourceType::Stock;
145 }
146
147 IconSource(unsigned int resourceId, const ImageType& imageContentType)
148 {
149 _resourceId = resourceId;
150 _resourceContentType = imageContentType;
151 _iconFormat = IconSourceType::Resource;
152 }
153
154 BOOL isValid() const
155 {
156 return _iconFormat != IconSourceType::Invalid;
157 }
158
160 {
161 return _iconFormat;
162 }
163
164 wstring _iconFile;
166 unsigned int _resourceId;
168};
169
171{
172 WinHandle _hWnd;
173 DCHandle _hDC;
174 HPEN _hPen, _hOldPen;
175 HFONT _hFont, _hOldFont;
176 HRGN _clipRgn;
177
178public:
179
181 virtual ~Graphics();
182
184
185 COLORREF setTextColor(COLORREF newColor);
186 COLORREF getTextColor();
187 COLORREF setBackgroundColor(COLORREF newColor);
189 int setBackgroundMode(int bkMode/*TRANSPARENT|OPAQUE|...*/);
190
196 int getTextHeight(int defaultHeight);
197
203 int getTextWidth(const wstring& text);
204
205 void setPen(int width, COLORREF color);
207
208 void setFont(const wstring& fontName, int fontSize, BOOL isBold = FALSE, BOOL isItalic = FALSE, BOOL isUnderlined = FALSE);
210
219 void drawLine(long x1, long y1, long x2, long y2, COLORREF color = Theme::LineColor);
220
226 void drawBorder(Bounds rect, COLORREF color = Theme::LineColor);
227
233
239
253 void drawButton(Bounds rect, const wstring& text, const ButtonType& btnType = ButtonType::DEFAULT,
254 BOOL isPressed = FALSE, BOOL isDisabled = FALSE,
255 const IconSource& iconSource = IconSource(), const Direction& iconPosition = Direction::LEFT,
256 BOOL isRounded = FALSE, BOOL hasShadow = TRUE, BOOL hasBorder = TRUE,
257 BOOL isGradient = FALSE,
258 COLORREF bkColor = Theme::ButtonBackgroundStartColor, /* Will only be used is btnType is set to ButtonType::CUSTOM */
259 COLORREF fgColor = Theme::ButtonForegroundColor /* Will only be used is btnType is set to ButtonType::CUSTOM */);
260
267 void fillGradient(Bounds rect, COLORREF bkStartColor, COLORREF bkEndColor);
268
274 void fillRect(Bounds rect, COLORREF color);
275
285 void drawText(Bounds rect, const wstring& text, int alignment/*-1|0|1*/,
286 BOOL bold = FALSE, BOOL italic = FALSE, BOOL underlined = FALSE);
287
293 void paintHeader(Bounds rect, const wstring& text);
294
300 void paintCheckBox(Bounds rect, BOOL checked);
301
307 void paintRadioButton(Bounds rect, BOOL checked);
308
314 void paintSortIndicator(Bounds rect, const SortType& sortDirection, COLORREF color);
315
316 void polygon(const POINT* pts, int ptCount, COLORREF fillColor = Theme::BackgroundColor);
317 void ellipse(Bounds rect, COLORREF fillColor = Theme::BackgroundColor);
318 void rectangle(Bounds rect, COLORREF fillColor = Theme::BackgroundColor);
319 void roundRect(Bounds rect, int xRadius, int yRadius, COLORREF bkColor = Theme::BackgroundColor, COLORREF color = Theme::LineColor);
320
321 void setClipRegion(int x1, int y1, int x2, int y2);
323
324 void drawDownArrow(Bounds rect, COLORREF color = Theme::ForegroundColor);
325 void drawUpArrow(Bounds rect, COLORREF color = Theme::ForegroundColor);
326 void drawLeftArrow(Bounds rect, COLORREF color = Theme::ForegroundColor);
327 void drawRightArrow(Bounds rect, COLORREF color = Theme::ForegroundColor);
328
329 void drawCheckMark(Bounds rect, COLORREF color = Theme::ForegroundColor);
330};
Direction
Definition Common.h:122
@ LEFT
Definition Common.h:123
ImageType
Definition Common.h:141
HWND WinHandle
Definition Common.h:16
HDC DCHandle
Definition Common.h:17
ButtonType
Definition Common.h:159
@ DEFAULT
Definition Common.h:160
IconType
Definition Graphics.h:17
@ BANNER
Definition Graphics.h:21
@ RETURNS
Definition Graphics.h:97
@ EXPORT
Definition Graphics.h:54
@ SEARCH
Definition Graphics.h:98
@ NOTE
Definition Graphics.h:77
@ FUELTYPE
Definition Graphics.h:60
@ SHOPPINGBASKET
Definition Graphics.h:101
@ FOLDEROPENED
Definition Graphics.h:119
@ CANCEL
Definition Graphics.h:29
@ JOBTITLES
Definition Graphics.h:68
@ IMAGE
Definition Graphics.h:64
@ INVENTORY
Definition Graphics.h:66
@ PRODUCT
Definition Graphics.h:87
@ MODIFIERS
Definition Graphics.h:75
@ DISK
Definition Graphics.h:47
@ BARCODE
Definition Graphics.h:22
@ CREDITCARD
Definition Graphics.h:40
@ USER
Definition Graphics.h:110
@ PASSWORD
Definition Graphics.h:79
@ DETACH
Definition Graphics.h:45
@ PAYMENTGATEWAY
Definition Graphics.h:80
@ PROMOTION
Definition Graphics.h:89
@ RENTAL
Definition Graphics.h:94
@ FUELPUMP
Definition Graphics.h:58
@ ALIGNBOTTOM
Definition Graphics.h:116
@ LOGIN
Definition Graphics.h:72
@ CONTRACTTERMS
Definition Graphics.h:38
@ CASHREGISTER
Definition Graphics.h:30
@ SMS
Definition Graphics.h:103
@ HELP
Definition Graphics.h:62
@ COLORS
Definition Graphics.h:35
@ PRINTER
Definition Graphics.h:86
@ LINK
Definition Graphics.h:70
@ MARKETING
Definition Graphics.h:74
@ COMMISSION
Definition Graphics.h:36
@ DOWNLOAD
Definition Graphics.h:48
@ LOGOUT
Definition Graphics.h:73
@ DIAMONDKARAT
Definition Graphics.h:46
@ HOME
Definition Graphics.h:63
@ ALIGNLEFT
Definition Graphics.h:111
@ EXPENSES
Definition Graphics.h:53
@ REMOVE
Definition Graphics.h:43
@ BUSINESSTYPE
Definition Graphics.h:25
@ CALCULATOR
Definition Graphics.h:27
@ ALIGNRIGHT
Definition Graphics.h:113
@ ENVELOPE
Definition Graphics.h:51
@ CLEAR
Definition Graphics.h:34
@ TRASH
Definition Graphics.h:108
@ PAYMENTS
Definition Graphics.h:82
@ CHECKMARK
Definition Graphics.h:33
@ UPLOAD
Definition Graphics.h:109
@ RECEIVEDINVENTORY
Definition Graphics.h:91
@ BUSINESSPROFILE
Definition Graphics.h:24
@ EDIT
Definition Graphics.h:49
@ PRODUCTCOST
Definition Graphics.h:88
@ PAYROLLENTRIES
Definition Graphics.h:83
@ CUSTOMER
Definition Graphics.h:41
@ EMPLOYEE
Definition Graphics.h:50
@ ADD
Definition Graphics.h:18
@ EXIT
Definition Graphics.h:52
@ ADDONS
Definition Graphics.h:19
@ REFRESH
Definition Graphics.h:92
@ REFUNDS
Definition Graphics.h:93
@ GIFTCARD
Definition Graphics.h:61
@ PAYROLLHOURS
Definition Graphics.h:84
@ DATABASE
Definition Graphics.h:42
@ FOLDERCLOSED
Definition Graphics.h:120
@ PO
Definition Graphics.h:85
@ INVOICE
Definition Graphics.h:67
@ QUOTE
Definition Graphics.h:90
@ TODO
Definition Graphics.h:107
@ ATTACH
Definition Graphics.h:20
@ FUELTANK
Definition Graphics.h:59
@ CALENDAR
Definition Graphics.h:26
@ DOCUMENT
Definition Graphics.h:121
@ ALIGNMIDDLE
Definition Graphics.h:115
@ SHOWALL
Definition Graphics.h:102
@ LAYAWAY
Definition Graphics.h:69
@ MONEYBILL
Definition Graphics.h:76
@ REPAIR
Definition Graphics.h:95
@ REPORT
Definition Graphics.h:96
@ CHECKLIST
Definition Graphics.h:32
@ TAX
Definition Graphics.h:106
@ PAYMENTMETHODS
Definition Graphics.h:81
@ DEPARTMENT
Definition Graphics.h:44
@ SUPPLIER
Definition Graphics.h:104
@ MAXIMIZEWINDOW
Definition Graphics.h:118
@ IMPORT
Definition Graphics.h:65
@ CAMERA
Definition Graphics.h:28
@ FUELDELIVERY
Definition Graphics.h:57
@ OK
Definition Graphics.h:78
@ BINOCULAR
Definition Graphics.h:23
@ CATEGORY
Definition Graphics.h:31
@ TAG
Definition Graphics.h:105
@ FILTER
Definition Graphics.h:56
@ COPY
Definition Graphics.h:39
@ EYE
Definition Graphics.h:55
@ ALIGNTOP
Definition Graphics.h:114
@ SETTINGS
Definition Graphics.h:100
@ ALIGNCENTER
Definition Graphics.h:112
@ LOCK
Definition Graphics.h:71
@ CONNECTION
Definition Graphics.h:37
@ SERVICE
Definition Graphics.h:99
@ RESTOREWINDOW
Definition Graphics.h:117
IconSourceType
Definition Graphics.h:10
@ File
Definition Graphics.h:12
@ Stock
Definition Graphics.h:13
@ Invalid
Definition Graphics.h:11
@ Resource
Definition Graphics.h:14
SortType
Definition Models.h:6
Definition Common.h:21
void drawLine(long x1, long y1, long x2, long y2, COLORREF color=Theme::LineColor)
Draws a line on the device context.
virtual ~Graphics()
void drawDownArrow(Bounds rect, COLORREF color=Theme::ForegroundColor)
Graphics(WinHandle hWnd, DCHandle hDC)
int setBackgroundMode(int bkMode)
void paintHeader(Bounds rect, const wstring &text)
Paints a header area with text.
void restorePen()
COLORREF getBackgroundColor()
void paintSortIndicator(Bounds rect, const SortType &sortDirection, COLORREF color)
Paints a sort direction indicator.
void paintCheckBox(Bounds rect, BOOL checked)
Paints a checkbox.
void drawCheckMark(Bounds rect, COLORREF color=Theme::ForegroundColor)
int getTextHeight(int defaultHeight)
Calculates the height of text for a given window.
void paintRadioButton(Bounds rect, BOOL checked)
Paints a radio button.
void setFont(const wstring &fontName, int fontSize, BOOL isBold=FALSE, BOOL isItalic=FALSE, BOOL isUnderlined=FALSE)
int getTextWidth(const wstring &text)
Calculates the width of the specified text for a given window.
void fillRect(Bounds rect, COLORREF color)
Fills a rectangle with the specified color.
void drawBorder(Bounds rect, COLORREF color=Theme::LineColor)
Draws a border around the specified rectangle.
DCHandle getHDC()
void drawUpArrow(Bounds rect, COLORREF color=Theme::ForegroundColor)
void drawRaisedBorder(Bounds rect)
Draws a raised (3D) border around the rectangle.
void ellipse(Bounds rect, COLORREF fillColor=Theme::BackgroundColor)
void drawLeftArrow(Bounds rect, COLORREF color=Theme::ForegroundColor)
COLORREF setBackgroundColor(COLORREF newColor)
void fillGradient(Bounds rect, COLORREF bkStartColor, COLORREF bkEndColor)
Fills a rectangle with a vertical gradient.
void drawRightArrow(Bounds rect, COLORREF color=Theme::ForegroundColor)
void polygon(const POINT *pts, int ptCount, COLORREF fillColor=Theme::BackgroundColor)
void drawText(Bounds rect, const wstring &text, int alignment, BOOL bold=FALSE, BOOL italic=FALSE, BOOL underlined=FALSE)
Draws text within the specified rectangle with formatting.
COLORREF setTextColor(COLORREF newColor)
COLORREF getTextColor()
void setPen(int width, COLORREF color)
void roundRect(Bounds rect, int xRadius, int yRadius, COLORREF bkColor=Theme::BackgroundColor, COLORREF color=Theme::LineColor)
void drawSunkenBorder(Bounds rect)
Draws a sunken (3D) border around the rectangle.
void clearClipRegion()
void setClipRegion(int x1, int y1, int x2, int y2)
void restoreFont()
void rectangle(Bounds rect, COLORREF fillColor=Theme::BackgroundColor)
void drawButton(Bounds rect, const wstring &text, const ButtonType &btnType=ButtonType::DEFAULT, BOOL isPressed=FALSE, BOOL isDisabled=FALSE, const IconSource &iconSource=IconSource(), const Direction &iconPosition=Direction::LEFT, BOOL isRounded=FALSE, BOOL hasShadow=TRUE, BOOL hasBorder=TRUE, BOOL isGradient=FALSE, COLORREF bkColor=Theme::ButtonBackgroundStartColor, COLORREF fgColor=Theme::ButtonForegroundColor)
Draws a button with the specified text and style.
Definition Graphics.h:125
IconType _iconType
Definition Graphics.h:165
IconSourceType getType() const
Definition Graphics.h:159
unsigned int _resourceId
Definition Graphics.h:166
IconSource(unsigned int resourceId, const ImageType &imageContentType)
Definition Graphics.h:147
IconSource()
Definition Graphics.h:130
wstring _iconFile
Definition Graphics.h:164
BOOL isValid() const
Definition Graphics.h:154
ImageType _resourceContentType
Definition Graphics.h:167
IconSource(const IconType &iconType)
Definition Graphics.h:141
IconSource(const wstring &iconFile)
Definition Graphics.h:135
static COLORREF BackgroundColor
Definition Theme.h:111
static COLORREF ForegroundColor
Definition Theme.h:112
static COLORREF ButtonForegroundColor
Definition Theme.h:128
static COLORREF LineColor
Definition Theme.h:203
static COLORREF ButtonBackgroundStartColor
Definition Theme.h:126