Use correct length for buffer
[TortoiseGit.git] / src / TortoiseProc / Colors.cpp
blob1dac4876550b98792e700b28caebf793ad901e08
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2007 - TortoiseSVN
4 // Copyright (C) 2009-2013, 2016 - TortoiseGit
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include "stdafx.h"
21 #include "Colors.h"
23 CColors::COLOR_DATA CColors::m_ColorArray[]=
25 { Cmd, CRegDWORD(L"Software\\TortoiseGit\\Colors\\Cmd", RGB(100, 100, 100)) },
26 { Conflict, CRegDWORD(L"Software\\TortoiseGit\\Colors\\Conflict", RGB(255, 0, 0)) },
27 { Modified, CRegDWORD(L"Software\\TortoiseGit\\Colors\\Modified", RGB(0, 50, 160)) },
28 { Merged, CRegDWORD(L"Software\\TortoiseGit\\Colors\\Merged", RGB(0, 100, 0)) },
29 { Deleted, CRegDWORD(L"Software\\TortoiseGit\\Colors\\Deleted", RGB(100, 0, 0)) },
30 { Added, CRegDWORD(L"Software\\TortoiseGit\\Colors\\Added", RGB(100, 0, 100)) },
31 { LastCommit, CRegDWORD(L"Software\\TortoiseGit\\Colors\\LastCommit", RGB(100, 100, 100)) },
32 { NoteNode, CRegDWORD(L"Software\\TortoiseGit\\Colors\\NoteNode", RGB(160, 160, 0)) },
33 { Renamed, CRegDWORD(L"Software\\TortoiseGit\\Colors\\Renamed", RGB(0, 0, 255)) },
34 { LastCommitNode, CRegDWORD(L"Software\\TortoiseGit\\Colors\\LastCommitNode", RGB(200, 200, 200)) },
35 { PropertyChanged, CRegDWORD(L"Software\\TortoiseGit\\Colors\\PropertyChanged", RGB(0, 50, 160)) },
36 { CurrentBranch, CRegDWORD(L"Software\\TortoiseGit\\Colors\\CurrentBranch", RGB(200, 0, 0)) },
37 { LocalBranch, CRegDWORD(L"Software\\TortoiseGit\\Colors\\LocalBranch", RGB(0, 195, 0)) },
38 { RemoteBranch, CRegDWORD(L"Software\\TortoiseGit\\Colors\\RemoteBranch", RGB(255, 221, 170)) },
39 { Tag, CRegDWORD(L"Software\\TortoiseGit\\Colors\\Tag", RGB(255, 255, 0)) },
40 { Stash, CRegDWORD(L"Software\\TortoiseGit\\Colors\\Stash", RGB(128, 128, 128)) },
41 { BranchLine1, CRegDWORD(L"Software\\TortoiseGit\\Colors\\BranchLine1", RGB(0, 0, 0)) },
42 { BranchLine2, CRegDWORD(L"Software\\TortoiseGit\\Colors\\BranchLine2", RGB(0xFF, 0, 0)) },
43 { BranchLine3, CRegDWORD(L"Software\\TortoiseGit\\Colors\\BranchLine3", RGB(0, 0xFF, 0)) },
44 { BranchLine4, CRegDWORD(L"Software\\TortoiseGit\\Colors\\BranchLine4", RGB(0, 0, 0xFF)) },
45 { BranchLine5, CRegDWORD(L"Software\\TortoiseGit\\Colors\\BranchLine5", RGB(128, 128, 128)) },
46 { BranchLine6, CRegDWORD(L"Software\\TortoiseGit\\Colors\\BranchLine6", RGB(128, 128, 0)) },
47 { BranchLine7, CRegDWORD(L"Software\\TortoiseGit\\Colors\\BranchLine7", RGB(0, 128, 128)) },
48 { BranchLine8, CRegDWORD(L"Software\\TortoiseGit\\Colors\\BranchLine8", RGB(128, 0, 128)) },
49 { BisectGood, CRegDWORD(L"Software\\TortoiseGit\\Colors\\BisectGood", RGB(0, 100, 200)) },
50 { BisectBad, CRegDWORD(L"Software\\TortoiseGit\\Colors\\BisectBad", RGB(255, 0, 0)) },
53 CColors::CColors(void)
57 CColors::~CColors(void)
61 COLORREF CColors::GetColor(Colors col, bool bDefault /*=true*/)
63 if (col == COLOR_END)
64 return RGB(0, 0, 0);
65 if (bDefault)
66 return m_ColorArray[col].RegKey.defaultValue();
67 else
68 return (COLORREF)(DWORD)m_ColorArray[col].RegKey;
71 void CColors::SetColor(Colors col, COLORREF cr)
73 if (col == COLOR_END)
75 ASSERT(FALSE);
76 return;
78 m_ColorArray[col].RegKey = cr;
82 COLORREF CColors::MixColors(COLORREF baseColor, COLORREF newColor, unsigned char mixFactor)
84 short colRed;
85 short colGreen;
86 short colBlue;
87 colRed = (short)((float)( baseColor&0x000000FF) -(float)( newColor&0x000000FF) )*mixFactor/0xFF;//red
88 colGreen = (short)((float)((baseColor&0x0000FF00)>>8) -(float)((newColor&0x0000FF00)>>8 ))*mixFactor/0xFF;//green
89 colBlue = (short)((float)((baseColor&0x00FF0000)>>16)-(float)((newColor&0x00FF0000)>>16))*mixFactor/0xFF;//blue
91 colRed = ( baseColor&0x000000FF) -colRed;
92 colGreen = ((baseColor&0x0000FF00)>>8) -colGreen;
93 colBlue = ((baseColor&0x00FF0000)>>16) -colBlue;
94 baseColor=(int)colRed|((int)colGreen<<8)|((int)colBlue<<16);
95 return baseColor;
98 COLORREF CColors::Lighten(COLORREF baseColor, unsigned char amount)
100 return MixColors(baseColor, RGB(255,255,255), amount);
103 COLORREF CColors::Darken(COLORREF baseColor, unsigned char amount)
105 return MixColors(baseColor, RGB(0,0,0), amount);