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
12 File = 1,
13 Stock = 2,
15};
16
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,
79 OPEN = 62,
86 PO = 69,
87 PRINTER = 70,
88 PRODUCT = 71,
91 QUOTE = 74,
93 REFRESH = 76,
94 REFUNDS = 77,
95 RENTAL = 78,
96 REPAIR = 79,
97 REPORT = 80,
98 RETURNS = 81,
99 SEARCH = 82,
104 SMS = 87,
106 TAG = 89,
107 TAX = 90,
108 TODO = 91,
109 TRASH = 92,
110 UPLOAD = 93,
111 USER = 94
112};
113
115{
116 IconSourceType _iconFormat;
117
118public:
119
121 {
122 _iconFormat = IconSourceType::Invalid;
123 }
124
125 IconSource(const wstring& iconFile)
126 {
127 _iconFile = iconFile;
128 _iconFormat = iconFile.length() > 0 ? IconSourceType::File : _iconFormat;
129 }
130
131 IconSource(const IconType& iconType)
132 {
133 _iconType = iconType;
134 _iconFormat = IconSourceType::Stock;
135 }
136
137 IconSource(unsigned int resourceId, const ImageType& imageContentType)
138 {
139 _resourceId = resourceId;
140 _resourceContentType = imageContentType;
141 _iconFormat = IconSourceType::Resource;
142 }
143
144 BOOL isValid() const
145 {
146 return _iconFormat != IconSourceType::Invalid;
147 }
148
150 {
151 return _iconFormat;
152 }
153
154 wstring _iconFile;
156 unsigned int _resourceId;
158};
159
161{
162 WinHandle _hWnd;
163 DCHandle _hDC;
164 HPEN _hPen, _hOldPen;
165 HFONT _hFont, _hOldFont;
166 HRGN _clipRgn;
167
168public:
169
171 virtual ~Graphics();
172
174
175 COLORREF setTextColor(COLORREF newColor);
176 COLORREF getTextColor();
177 COLORREF setBackgroundColor(COLORREF newColor);
179 int setBackgroundMode(int bkMode/*TRANSPARENT|OPAQUE|...*/);
180
186 int getTextHeight(int defaultHeight);
187
193 int getTextWidth(const wstring& text);
194
195 void setPen(int width, COLORREF color);
197
198 void setFont(const wstring& fontName, int fontSize, BOOL isBold = FALSE, BOOL isItalic = FALSE, BOOL isUnderlined = FALSE);
200
209 void drawLine(long x1, long y1, long x2, long y2, COLORREF color = Theme::LineColor);
210
216 void drawBorder(Bounds rect, COLORREF color = Theme::LineColor);
217
223
229
243 void drawButton(Bounds rect, const wstring& text, const ButtonType& btnType = ButtonType::DEFAULT,
244 BOOL isPressed = FALSE, BOOL isDisabled = FALSE,
245 const IconSource& iconSource = IconSource(), const Direction& iconPosition = Direction::LEFT,
246 BOOL isRounded = FALSE, BOOL hasShadow = TRUE, BOOL hasBorder = TRUE,
247 BOOL isGradient = FALSE,
248 COLORREF bkColor = Theme::ButtonBackgroundStartColor, /* Will only be used is btnType is set to ButtonType::CUSTOM */
249 COLORREF fgColor = Theme::ButtonForegroundColor /* Will only be used is btnType is set to ButtonType::CUSTOM */);
250
257 void fillGradient(Bounds rect, COLORREF bkStartColor, COLORREF bkEndColor);
258
264 void fillRect(Bounds rect, COLORREF color);
265
275 void drawText(Bounds rect, const wstring& text, int alignment/*-1|0|1*/,
276 BOOL bold = FALSE, BOOL italic = FALSE, BOOL underlined = FALSE);
277
283 void paintHeader(Bounds rect, const wstring& text);
284
290 void paintCheckBox(Bounds rect, BOOL checked);
291
297 void paintRadioButton(Bounds rect, BOOL checked);
298
304 void paintSortIndicator(Bounds rect, const SortType& sortDirection, COLORREF color);
305
306 void polygon(const POINT* pts, int ptCount, COLORREF fillColor = Theme::BackgroundColor);
307 void ellipse(Bounds rect, COLORREF fillColor = Theme::BackgroundColor);
308 void rectangle(Bounds rect, COLORREF fillColor = Theme::BackgroundColor);
309 void roundRect(Bounds rect, int xRadius, int yRadius, COLORREF bkColor = Theme::BackgroundColor, COLORREF color = Theme::LineColor);
310
311 void setClipRegion(int x1, int y1, int x2, int y2);
313
314 void drawDownArrow(Bounds rect, COLORREF color = Theme::ForegroundColor);
315 void drawUpArrow(Bounds rect, COLORREF color = Theme::ForegroundColor);
316 void drawLeftArrow(Bounds rect, COLORREF color = Theme::ForegroundColor);
317 void drawRightArrow(Bounds rect, COLORREF color = Theme::ForegroundColor);
318
319 void drawCheckMark(Bounds rect, COLORREF color = Theme::ForegroundColor);
320};
Direction
Definition Common.h:114
@ LEFT
Definition Common.h:115
ImageType
Definition Common.h:133
HWND WinHandle
Definition Common.h:16
HDC DCHandle
Definition Common.h:17
ButtonType
Definition Common.h:151
@ DEFAULT
Definition Common.h:152
IconType
Definition Graphics.h:17
@ EMPLOYEE
Definition Graphics.h:50
@ GIFTCARD
Definition Graphics.h:61
@ RETURNS
Definition Graphics.h:98
@ MONEYBILL
Definition Graphics.h:76
@ PASSWORD
Definition Graphics.h:80
@ BUSINESSTYPE
Definition Graphics.h:25
@ OPEN
Definition Graphics.h:79
@ PAYMENTS
Definition Graphics.h:83
@ PAYMENTGATEWAY
Definition Graphics.h:81
@ ENVELOPE
Definition Graphics.h:51
@ BINOCULAR
Definition Graphics.h:23
@ EXPENSES
Definition Graphics.h:53
@ REFRESH
Definition Graphics.h:93
@ SUPPLIER
Definition Graphics.h:105
@ SHOWALL
Definition Graphics.h:103
@ PAYMENTMETHODS
Definition Graphics.h:82
@ CLEAR
Definition Graphics.h:34
@ CALENDAR
Definition Graphics.h:26
@ TODO
Definition Graphics.h:108
@ OK
Definition Graphics.h:78
@ EDIT
Definition Graphics.h:49
@ BARCODE
Definition Graphics.h:22
@ TAX
Definition Graphics.h:107
@ IMAGE
Definition Graphics.h:64
@ NOTE
Definition Graphics.h:77
@ EXPORT
Definition Graphics.h:54
@ LOCK
Definition Graphics.h:71
@ CATEGORY
Definition Graphics.h:31
@ COMMISSION
Definition Graphics.h:36
@ DEPARTMENT
Definition Graphics.h:44
@ CUSTOMER
Definition Graphics.h:41
@ DIAMONDKARAT
Definition Graphics.h:46
@ REPAIR
Definition Graphics.h:96
@ SERVICE
Definition Graphics.h:100
@ FUELPUMP
Definition Graphics.h:58
@ FUELDELIVERY
Definition Graphics.h:57
@ COLORS
Definition Graphics.h:35
@ MARKETING
Definition Graphics.h:74
@ RENTAL
Definition Graphics.h:95
@ FILTER
Definition Graphics.h:56
@ EXIT
Definition Graphics.h:52
@ PRODUCTCOST
Definition Graphics.h:89
@ LOGIN
Definition Graphics.h:72
@ SEARCH
Definition Graphics.h:99
@ BANNER
Definition Graphics.h:21
@ INVOICE
Definition Graphics.h:67
@ IMPORT
Definition Graphics.h:65
@ LOGOUT
Definition Graphics.h:73
@ CONNECTION
Definition Graphics.h:37
@ SHOPPINGBASKET
Definition Graphics.h:102
@ REMOVE
Definition Graphics.h:43
@ HOME
Definition Graphics.h:63
@ CONTRACTTERMS
Definition Graphics.h:38
@ REFUNDS
Definition Graphics.h:94
@ LAYAWAY
Definition Graphics.h:69
@ PAYROLLHOURS
Definition Graphics.h:85
@ BUSINESSPROFILE
Definition Graphics.h:24
@ HELP
Definition Graphics.h:62
@ INVENTORY
Definition Graphics.h:66
@ JOBTITLES
Definition Graphics.h:68
@ DISK
Definition Graphics.h:47
@ TAG
Definition Graphics.h:106
@ PO
Definition Graphics.h:86
@ PRINTER
Definition Graphics.h:87
@ COPY
Definition Graphics.h:39
@ PAYROLLENTRIES
Definition Graphics.h:84
@ CHECKMARK
Definition Graphics.h:33
@ REPORT
Definition Graphics.h:97
@ SETTINGS
Definition Graphics.h:101
@ ATTACH
Definition Graphics.h:20
@ EYE
Definition Graphics.h:55
@ TRASH
Definition Graphics.h:109
@ PRODUCT
Definition Graphics.h:88
@ DETACH
Definition Graphics.h:45
@ FUELTYPE
Definition Graphics.h:60
@ ADD
Definition Graphics.h:18
@ CASHREGISTER
Definition Graphics.h:30
@ CALCULATOR
Definition Graphics.h:27
@ QUOTE
Definition Graphics.h:91
@ CAMERA
Definition Graphics.h:28
@ DATABASE
Definition Graphics.h:42
@ MODIFIERS
Definition Graphics.h:75
@ USER
Definition Graphics.h:111
@ CANCEL
Definition Graphics.h:29
@ RECEIVEDINVENTORY
Definition Graphics.h:92
@ ADDONS
Definition Graphics.h:19
@ CREDITCARD
Definition Graphics.h:40
@ UPLOAD
Definition Graphics.h:110
@ PROMOTION
Definition Graphics.h:90
@ LINK
Definition Graphics.h:70
@ DOWNLOAD
Definition Graphics.h:48
@ FUELTANK
Definition Graphics.h:59
@ CHECKLIST
Definition Graphics.h:32
@ SMS
Definition Graphics.h:104
IconSourceType
Definition Graphics.h:10
@ File
Definition Graphics.h:12
@ Resource
Definition Graphics.h:14
@ Stock
Definition Graphics.h:13
@ Invalid
Definition Graphics.h:11
SortType
Definition Models.h:6
Definition Common.h:20
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:115
IconType _iconType
Definition Graphics.h:155
IconSourceType getType() const
Definition Graphics.h:149
unsigned int _resourceId
Definition Graphics.h:156
IconSource(unsigned int resourceId, const ImageType &imageContentType)
Definition Graphics.h:137
IconSource()
Definition Graphics.h:120
wstring _iconFile
Definition Graphics.h:154
BOOL isValid() const
Definition Graphics.h:144
ImageType _resourceContentType
Definition Graphics.h:157
IconSource(const IconType &iconType)
Definition Graphics.h:131
IconSource(const wstring &iconFile)
Definition Graphics.h:125
static COLORREF BackgroundColor
Definition Theme.h:103
static COLORREF ForegroundColor
Definition Theme.h:104
static COLORREF ButtonForegroundColor
Definition Theme.h:115
static COLORREF LineColor
Definition Theme.h:190
static COLORREF ButtonBackgroundStartColor
Definition Theme.h:113