// Ryzom - MMORPG Framework // Copyright (C) 2010 Winch Gate Property Limited // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as // published by the Free Software Foundation, either version 3 of the // License, or (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Affero General Public License for more details. // // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . // icon_wnd.cpp: implementation of the CIconWnd class. // #include "stdafx.h" #include "georges_edit.h" #include "icon_wnd.h" #include "nel/misc/path.h" #include "nel/misc/file.h" #include "nel/misc/bitmap.h" using namespace NLMISC; using namespace std; string CIconWnd::IconPath; CIconWnd::CIconWnd() { pWndIcon = NULL; pWndIconColor = NULL; pWndIconBack = NULL; pWndIconBackColor = NULL; pWndIconOver = NULL; pWndIconOverColor = NULL; pWndIconOver2 = NULL; pWndIconOver2Color = NULL; } CIconWnd::~CIconWnd() { } BEGIN_MESSAGE_MAP(CIconWnd, CWnd) //{{AFX_MSG_MAP(CIconWnd) ON_WM_PAINT() //}}AFX_MSG_MAP END_MESSAGE_MAP() void CIconWnd::OnPaint() { CPaintDC dc(this); // update data if (updateStr()) updateIcon(); // Get client dc RECT client; GetClientRect(&client); dc.Rectangle(&client); for (uint y=0 ; yasString(); for (uint i=0 ; isize() ; i++) CPath::addSearchPath(var->asString(i), true, false, NULL); } else { nlinfo("!! IconPath missing in .cfg, Please complete the config file !!"); IconPath = "\\\\amiga\\3d\\Database\\Interfaces\\"; nlinfo("default to : IconPath = \"\\\\amiga\\3d\\Database\\Interfaces\\\""); CPath::addSearchPath(IconPath, true, false, NULL); } } NLMISC::CBitmap icon; NLMISC::CRGBA color; bitmap.reset(); bitmap.convertToType(NLMISC::CBitmap::RGBA); bitmap.resample(40, 40); // back icon if (loadIcon(strIconBack, icon)) { // back icon color if (getColorFromStr(strIconBackColor, color)) modulateIcon(icon, color); bitmap = icon; // base icon addIconLayer(bitmap, strIcon, strIconColor); } else { // base icon loadIcon(strIcon, icon); // base icon color if (getColorFromStr(strIconColor, color)) modulateIcon(icon, color); bitmap = icon; } // overlay icon addIconLayer(bitmap, strIconOver, strIconOverColor); // overlay 2 icon addIconLayer(bitmap, strIconOver2, strIconOver2Color); } bool CIconWnd::loadIcon(const std::string &filename, NLMISC::CBitmap &bmp) { // Try to get the file path string filepath = CPath::lookup(filename, false, false); if (filepath == "") { bmp.makeDummy(); bmp.convertToType(NLMISC::CBitmap::RGBA); bmp.resample(40, 40); return false; } // load icon CIFile f; f.open(filepath); bmp.load(f); bmp.convertToType(NLMISC::CBitmap::RGBA); bmp.resample(40, 40); f.close(); return true; } bool CIconWnd::getColorFromStr(const std::string &s, NLMISC::CRGBA &c) { // Convert string to color sint r, g, b; if (sscanf (s.c_str(), "%d,%d,%d", &r, &g, &b) == 3) { clamp (r, 0, 255); clamp (g, 0, 255); clamp (b, 0, 255); c = CRGBA(r, g, b); return true; } return false; } void CIconWnd::blendIcons(NLMISC::CBitmap &dst, const NLMISC::CBitmap &src) { // blend between two icons nlassert(dst.getWidth() == src.getWidth()); nlassert(dst.getHeight() == src.getHeight()); CObjectVector &data = dst.getPixels(); for (uint y=0 ; y &data = dst.getPixels(); for (uint y=0 ; yGetWindowText(buffer, 512); if (buffer != str) { str = buffer; return true; } } return false; }