-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGuiLib.cpp
More file actions
92 lines (81 loc) · 2.89 KB
/
GuiLib.cpp
File metadata and controls
92 lines (81 loc) · 2.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include "StdAfx.h"
#include "GuiLib.h"
COLORREF CGuiLib::LightenColor(COLORREF col,double factor)
{
if(factor>0.0&&factor<=1.0){
BYTE red,green,blue,lightred,lightgreen,lightblue;
red = GetRValue(col);
green = GetGValue(col);
blue = GetBValue(col);
lightred = (BYTE)((factor*(255-red)) + red);
lightgreen = (BYTE)((factor*(255-green)) + green);
lightblue = (BYTE)((factor*(255-blue)) + blue);
col = RGB(lightred,lightgreen,lightblue);
}
return(col);
}
COLORREF CGuiLib::DarkenColor(COLORREF col,double factor)
{
if(factor>0.0&&factor<=1.0){
BYTE red,green,blue,lightred,lightgreen,lightblue;
red = GetRValue(col);
green = GetGValue(col);
blue = GetBValue(col);
lightred = (BYTE)(red-(factor*red));
lightgreen = (BYTE)(green-(factor*green));
lightblue = (BYTE)(blue-(factor*blue));
col = RGB(lightred,lightgreen,lightblue);
}
return(col);
}
COLORREF CGuiLib::GrayScale(COLORREF col)
{
BYTE dbGray;
dbGray = (BYTE)( GetRValue(col) * (0.3) + GetBValue(col) * (0.59) + GetGValue(col) * (0.11));
return (RGB(dbGray, dbGray, dbGray));
}
void CGuiLib::GradientFill (CDC *pDC, CRect rectBar, COLORREF cLeft, COLORREF cRight, BOOL bVertical)
{
TRIVERTEX vert[2]; // for specifying range to gradient fill
GRADIENT_RECT gRect;
COLORREF FromCol = cLeft;
COLORREF ToCol = cRight;
vert[0].Red = (COLOR16)((FromCol&0x0000FF)<<8);
vert[0].Green = (COLOR16)((FromCol&0x00FF00)<<0);
vert[0].Blue = (COLOR16)((FromCol&0xFF0000)>>8);
vert[0].Alpha = 0; // no fading/transparency
vert[1].Red = (COLOR16)((ToCol&0x0000FF)<<8);
vert[1].Green = (COLOR16)((ToCol&0x00FF00)<<0);
vert[1].Blue = (COLOR16)((ToCol&0xFF0000)>>8);
vert[1].Alpha = 0;
gRect.UpperLeft = 0;
gRect.LowerRight = 1;
vert[0].x = rectBar.left;
vert[0].y = rectBar.top;
vert[1].x = rectBar.right;
vert[1].y = rectBar.bottom;
if (bVertical) // vertically oriented?
pDC->GradientFill(vert,2,&gRect,1,GRADIENT_FILL_RECT_V);
else
pDC->GradientFill(vert,2,&gRect,1,GRADIENT_FILL_RECT_H);
}
void CGuiLib::DrawTransparent (CDC *pDC, HICON hIcon, CPoint pt, CSize sz)
{
CDC dcMem;
CBitmap CacheBitmap;
HBRUSH hBrush = NULL;
if (sz.cx == 0) {
ICONINFO IconInfo;
GetIconInfo(hIcon, &IconInfo);
sz.cx = IconInfo.xHotspot * 2;
sz.cy = IconInfo.xHotspot * 2;
}
dcMem.CreateCompatibleDC (pDC);
CacheBitmap.CreateCompatibleBitmap(pDC, sz.cx, sz.cy);
CBitmap* pBmpOld = dcMem.SelectObject (&CacheBitmap);
dcMem.DrawState(CPoint(0,0), sz, hIcon, DSS_NORMAL, hBrush);
pDC->TransparentBlt (pt.x, pt.y, sz.cx, sz.cy, &dcMem, 0, 0, sz.cx, sz.cy, RGB(0,0,0));
dcMem.SelectObject (pBmpOld);
CacheBitmap.DeleteObject();
dcMem.DeleteDC();
}