1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2019 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Affero General Public License as
9 // published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Affero General Public License for more details.
17 // You should have received a copy of the GNU Affero General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
20 // icon_wnd.cpp: implementation of the CIconWnd class.
24 #include "georges_edit.h"
27 #include "nel/misc/path.h"
28 #include "nel/misc/file.h"
29 #include "nel/misc/bitmap.h"
31 using namespace NLMISC
;
34 string
CIconWnd::IconPath
;
42 pWndIconBackColor
= NULL
;
44 pWndIconOverColor
= NULL
;
46 pWndIconOver2Color
= NULL
;
54 BEGIN_MESSAGE_MAP(CIconWnd
, CWnd
)
55 //{{AFX_MSG_MAP(CIconWnd)
61 void CIconWnd::OnPaint()
71 GetClientRect(&client
);
72 dc
.Rectangle(&client
);
74 for (uint y
=0 ; y
<bitmap
.getHeight() ; y
++)
76 for (uint x
=0 ; x
<bitmap
.getWidth() ; x
++)
78 CRGBA c
= bitmap
.getPixelColor(x
, y
);
79 dc
.SetPixel(x
, y
, RGB(c
.R
, c
.G
, c
.B
));
84 void CIconWnd::create (DWORD wStyle
, RECT
&pos
, CWnd
*parent
, uint dialogIndex
)
87 // Register window class
88 LPCTSTR className
= AfxRegisterWndClass(CS_OWNDC
);
91 CWnd::Create(className
, _T("empty"), wStyle
, pos
, parent
, dialogIndex
);
94 bool CIconWnd::updateStr()
96 // check if icons need to be recomputed
97 bool needUpdate
= false;
99 if (updateWnd(pWndIcon
, strIcon
))
102 if (updateWnd(pWndIconColor
, strIconColor
))
105 if (updateWnd(pWndIconBack
, strIconBack
))
108 if (updateWnd(pWndIconBackColor
, strIconBackColor
))
111 if (updateWnd(pWndIconOver
, strIconOver
))
114 if (updateWnd(pWndIconOverColor
, strIconOverColor
))
117 if (updateWnd(pWndIconOver2
, strIconOver2
))
120 if (updateWnd(pWndIconOver2Color
, strIconOver2Color
))
126 void CIconWnd::updateIcon()
131 CConfigFile::CVar
*var
= theApp
.ConfigFile
.getVarPtr("IconPath");
134 IconPath
= var
->asString();
135 for (uint i
=0 ; i
<var
->size() ; i
++)
136 CPath::addSearchPath(var
->asString(i
), true, false, NULL
);
140 nlinfo("!! IconPath missing in .cfg, Please complete the config file !!");
141 IconPath
= "\\\\amiga\\3d\\Database\\Interfaces\\";
142 nlinfo("default to : IconPath = \"\\\\amiga\\3d\\Database\\Interfaces\\\"");
143 CPath::addSearchPath(IconPath
, true, false, NULL
);
147 NLMISC::CBitmap icon
;
151 bitmap
.convertToType(NLMISC::CBitmap::RGBA
);
152 bitmap
.resample(40, 40);
155 if (loadIcon(strIconBack
, icon
))
158 if (getColorFromStr(strIconBackColor
, color
))
159 modulateIcon(icon
, color
);
164 addIconLayer(bitmap
, strIcon
, strIconColor
);
169 loadIcon(strIcon
, icon
);
172 if (getColorFromStr(strIconColor
, color
))
173 modulateIcon(icon
, color
);
179 addIconLayer(bitmap
, strIconOver
, strIconOverColor
);
182 addIconLayer(bitmap
, strIconOver2
, strIconOver2Color
);
185 bool CIconWnd::loadIcon(const std::string
&filename
, NLMISC::CBitmap
&bmp
)
187 // Try to get the file path
188 string filepath
= CPath::lookup(filename
, false, false);
192 bmp
.convertToType(NLMISC::CBitmap::RGBA
);
193 bmp
.resample(40, 40);
202 bmp
.convertToType(NLMISC::CBitmap::RGBA
);
203 bmp
.resample(40, 40);
210 bool CIconWnd::getColorFromStr(const std::string
&s
, NLMISC::CRGBA
&c
)
212 // Convert string to color
215 if (sscanf (s
.c_str(), "%d,%d,%d", &r
, &g
, &b
) == 3)
227 void CIconWnd::blendIcons(NLMISC::CBitmap
&dst
, const NLMISC::CBitmap
&src
)
229 // blend between two icons
231 nlassert(dst
.getWidth() == src
.getWidth());
232 nlassert(dst
.getHeight() == src
.getHeight());
234 CObjectVector
<uint8
> &data
= dst
.getPixels();
236 for (uint y
=0 ; y
<dst
.getHeight() ; y
++)
238 for (uint x
=0 ; x
<dst
.getWidth() ; x
++)
241 c
.blendFromui(dst
.getPixelColor(x
, y
), src
.getPixelColor(x
, y
), src
.getPixelColor(x
, y
).A
);
243 data
[(x
+y
*dst
.getWidth())*4] = c
.R
;
244 data
[(x
+y
*dst
.getWidth())*4+1] = c
.G
;
245 data
[(x
+y
*dst
.getWidth())*4+2] = c
.B
;
246 data
[(x
+y
*dst
.getWidth())*4+3] = c
.A
;
252 void CIconWnd::modulateIcon(NLMISC::CBitmap
&dst
, const NLMISC::CRGBA
&col
)
254 // modulate an icon by a color
256 CObjectVector
<uint8
> &data
= dst
.getPixels();
258 for (uint y
=0 ; y
<dst
.getHeight() ; y
++)
260 for (uint x
=0 ; x
<dst
.getWidth() ; x
++)
263 c
.modulateFromColor(col
, dst
.getPixelColor(x
, y
));
265 data
[(x
+y
*dst
.getWidth())*4] = c
.R
;
266 data
[(x
+y
*dst
.getWidth())*4+1] = c
.G
;
267 data
[(x
+y
*dst
.getWidth())*4+2] = c
.B
;
268 data
[(x
+y
*dst
.getWidth())*4+3] = dst
.getPixelColor(x
, y
).A
;
273 void CIconWnd::addIconLayer(NLMISC::CBitmap
&dst
, const std::string iconStr
, const std::string iconCol
)
275 NLMISC::CBitmap icon
;
278 if (loadIcon(iconStr
, icon
))
280 if (getColorFromStr(iconCol
, color
))
281 modulateIcon(icon
, color
);
283 blendIcons(dst
, icon
);
287 bool CIconWnd::updateWnd(CWnd
*pWnd
, std::string
&str
)
293 pWnd
->GetWindowText(buffer
, 512);
294 std::string buf
= tStrToUtf8(buffer
);