mirror of
				https://github.com/chibicitiberiu/rainmeter-studio.git
				synced 2024-02-24 04:33:31 +00:00 
			
		
		
		
	- Improved error handling for creating TrayMeasure.
- Code cleanup.
This commit is contained in:
		| @@ -109,6 +109,15 @@ CMeterWindow::CMeterWindow(const std::wstring& path, const std::wstring& config, | |||||||
| 	m_BackgroundSize.cx = 0; | 	m_BackgroundSize.cx = 0; | ||||||
| 	m_BackgroundSize.cy = 0; | 	m_BackgroundSize.cy = 0; | ||||||
|  |  | ||||||
|  | 	m_BackgroundMargins.left = 0; | ||||||
|  | 	m_BackgroundMargins.top = 0; | ||||||
|  | 	m_BackgroundMargins.right = 0; | ||||||
|  | 	m_BackgroundMargins.bottom = 0; | ||||||
|  | 	m_DragMargins.left = 0; | ||||||
|  | 	m_DragMargins.top = 0; | ||||||
|  | 	m_DragMargins.right = 0; | ||||||
|  | 	m_DragMargins.bottom = 0; | ||||||
|  |  | ||||||
| 	m_FadeStartTime = 0; | 	m_FadeStartTime = 0; | ||||||
| 	m_FadeStartValue = 0; | 	m_FadeStartValue = 0; | ||||||
| 	m_FadeEndValue = 0; | 	m_FadeEndValue = 0; | ||||||
| @@ -1736,13 +1745,9 @@ bool CMeterWindow::ReadSkin() | |||||||
| 	m_BackgroundName = m_Parser.ReadString(L"Rainmeter", L"Background", L""); | 	m_BackgroundName = m_Parser.ReadString(L"Rainmeter", L"Background", L""); | ||||||
| 	m_BackgroundName = MakePathAbsolute(m_BackgroundName); | 	m_BackgroundName = MakePathAbsolute(m_BackgroundName); | ||||||
|  |  | ||||||
| 	m_BackgroundMargins = m_Parser.ReadRect(L"Rainmeter", L"BackgroundMargins", Rect(0,0,0,0)); | 	static const RECT defMargins = {0}; | ||||||
| 	m_BackgroundMargins.Width -= m_BackgroundMargins.X; | 	m_BackgroundMargins = m_Parser.ReadRECT(L"Rainmeter", L"BackgroundMargins", defMargins); | ||||||
| 	m_BackgroundMargins.Height -= m_BackgroundMargins.Y; | 	m_DragMargins = m_Parser.ReadRECT(L"Rainmeter", L"DragMargins", defMargins); | ||||||
|  |  | ||||||
| 	m_DragMargins = m_Parser.ReadRect(L"Rainmeter", L"DragMargins", Rect(0,0,0,0)); |  | ||||||
| 	m_DragMargins.Width -= m_DragMargins.X; |  | ||||||
| 	m_DragMargins.Height -= m_DragMargins.Y; |  | ||||||
|  |  | ||||||
| 	m_BackgroundMode = (BGMODE)m_Parser.ReadInt(L"Rainmeter", L"BackgroundMode", BGMODE_IMAGE); | 	m_BackgroundMode = (BGMODE)m_Parser.ReadInt(L"Rainmeter", L"BackgroundMode", BGMODE_IMAGE); | ||||||
| 	m_SolidBevel = (BEVELTYPE)m_Parser.ReadInt(L"Rainmeter", L"BevelType", BEVELTYPE_NONE); | 	m_SolidBevel = (BEVELTYPE)m_Parser.ReadInt(L"Rainmeter", L"BevelType", BEVELTYPE_NONE); | ||||||
| @@ -2066,8 +2071,8 @@ void CMeterWindow::InitializeMeters() | |||||||
| */ | */ | ||||||
| bool CMeterWindow::ResizeWindow(bool reset) | bool CMeterWindow::ResizeWindow(bool reset) | ||||||
| { | { | ||||||
| 	int w = m_BackgroundMargins.GetLeft(); | 	int w = m_BackgroundMargins.left; | ||||||
| 	int h = m_BackgroundMargins.GetTop(); | 	int h = m_BackgroundMargins.top; | ||||||
|  |  | ||||||
| 	// Get the largest meter point | 	// Get the largest meter point | ||||||
| 	std::list<CMeter*>::const_iterator j = m_Meters.begin(); | 	std::list<CMeter*>::const_iterator j = m_Meters.begin(); | ||||||
| @@ -2079,8 +2084,8 @@ bool CMeterWindow::ResizeWindow(bool reset) | |||||||
| 		h = max(h, mb); | 		h = max(h, mb); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	w += m_BackgroundMargins.GetRight(); | 	w += m_BackgroundMargins.right; | ||||||
| 	h += m_BackgroundMargins.GetBottom(); | 	h += m_BackgroundMargins.bottom; | ||||||
|  |  | ||||||
| 	w = max(w, m_BackgroundSize.cx); | 	w = max(w, m_BackgroundSize.cx); | ||||||
| 	h = max(h, m_BackgroundSize.cy); | 	h = max(h, m_BackgroundSize.cy); | ||||||
| @@ -2139,7 +2144,7 @@ bool CMeterWindow::ResizeWindow(bool reset) | |||||||
|  |  | ||||||
| 				if (m_BackgroundMode == BGMODE_SCALED_IMAGE) | 				if (m_BackgroundMode == BGMODE_SCALED_IMAGE) | ||||||
| 				{ | 				{ | ||||||
| 					RECT m = {m_BackgroundMargins.GetLeft(), m_BackgroundMargins.GetTop(), m_BackgroundMargins.GetRight(), m_BackgroundMargins.GetBottom()}; | 					const RECT& m = m_BackgroundMargins; | ||||||
|  |  | ||||||
| 					if (m.top > 0)  | 					if (m.top > 0)  | ||||||
| 					{ | 					{ | ||||||
| @@ -3509,10 +3514,10 @@ LRESULT CMeterWindow::OnNcHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam) | |||||||
| 		pos.y = (SHORT)HIWORD(lParam); | 		pos.y = (SHORT)HIWORD(lParam); | ||||||
| 		MapWindowPoints(NULL, m_Window, &pos, 1); | 		MapWindowPoints(NULL, m_Window, &pos, 1); | ||||||
|  |  | ||||||
| 		int x1 = m_DragMargins.GetLeft(); | 		int x1 = m_DragMargins.left; | ||||||
| 		int x2 = m_WindowW - m_DragMargins.GetRight(); | 		int x2 = m_WindowW - m_DragMargins.right; | ||||||
| 		int y1 = m_DragMargins.GetTop(); | 		int y1 = m_DragMargins.top; | ||||||
| 		int y2 = m_WindowH - m_DragMargins.GetBottom(); | 		int y2 = m_WindowH - m_DragMargins.bottom; | ||||||
|  |  | ||||||
| 		if (x1 < 0) x1 += m_WindowW; | 		if (x1 < 0) x1 += m_WindowW; | ||||||
| 		if (y1 < 0) y1 += m_WindowH; | 		if (y1 < 0) y1 += m_WindowH; | ||||||
|   | |||||||
| @@ -297,8 +297,8 @@ private: | |||||||
| 	std::wstring m_Author;						// Skin's author | 	std::wstring m_Author;						// Skin's author | ||||||
| 	std::wstring m_ConfigGroup; | 	std::wstring m_ConfigGroup; | ||||||
| 	std::wstring m_BackgroundName;				// Name of the background image | 	std::wstring m_BackgroundName;				// Name of the background image | ||||||
| 	Gdiplus::Rect m_BackgroundMargins; | 	RECT m_BackgroundMargins; | ||||||
| 	Gdiplus::Rect m_DragMargins; | 	RECT m_DragMargins; | ||||||
| 	std::wstring m_WindowX;						// Window's X-position in config file | 	std::wstring m_WindowX;						// Window's X-position in config file | ||||||
| 	std::wstring m_WindowY;						// Window's Y-position in config file | 	std::wstring m_WindowY;						// Window's Y-position in config file | ||||||
| 	std::wstring m_AnchorX;						// Anchor's X-position in config file | 	std::wstring m_AnchorX;						// Anchor's X-position in config file | ||||||
|   | |||||||
| @@ -22,15 +22,6 @@ | |||||||
| #include "Meter.h" | #include "Meter.h" | ||||||
| #include "MeterWindow.h" | #include "MeterWindow.h" | ||||||
|  |  | ||||||
| enum CROPMODE |  | ||||||
| { |  | ||||||
| 	CROPMODE_TL = 1, |  | ||||||
| 	CROPMODE_TR, |  | ||||||
| 	CROPMODE_BR, |  | ||||||
| 	CROPMODE_BL, |  | ||||||
| 	CROPMODE_C |  | ||||||
| }; |  | ||||||
|  |  | ||||||
| class CTintedImage | class CTintedImage | ||||||
| { | { | ||||||
| public: | public: | ||||||
| @@ -53,6 +44,15 @@ public: | |||||||
| 	void LoadImage(const std::wstring& imageName, bool bLoadAlways); | 	void LoadImage(const std::wstring& imageName, bool bLoadAlways); | ||||||
|  |  | ||||||
| protected: | protected: | ||||||
|  | 	enum CROPMODE | ||||||
|  | 	{ | ||||||
|  | 		CROPMODE_TL = 1, | ||||||
|  | 		CROPMODE_TR, | ||||||
|  | 		CROPMODE_BR, | ||||||
|  | 		CROPMODE_BL, | ||||||
|  | 		CROPMODE_C | ||||||
|  | 	}; | ||||||
|  |  | ||||||
| 	void ApplyCrop(); | 	void ApplyCrop(); | ||||||
| 	void ApplyTint(); | 	void ApplyTint(); | ||||||
| 	void ApplyTransform(); | 	void ApplyTransform(); | ||||||
|   | |||||||
| @@ -291,6 +291,9 @@ HICON CTrayWindow::CreateTrayIcon(double value) | |||||||
|  |  | ||||||
| void CTrayWindow::ReadConfig(CConfigParser& parser) | void CTrayWindow::ReadConfig(CConfigParser& parser) | ||||||
| { | { | ||||||
|  | 	delete m_Measure; | ||||||
|  | 	m_Measure = NULL; | ||||||
|  |  | ||||||
| 	for (size_t i = 0; i < m_TrayIcons.size(); ++i)  | 	for (size_t i = 0; i < m_TrayIcons.size(); ++i)  | ||||||
| 	{ | 	{ | ||||||
| 		DestroyIcon(m_TrayIcons[i]); | 		DestroyIcon(m_TrayIcons[i]); | ||||||
| @@ -299,15 +302,29 @@ void CTrayWindow::ReadConfig(CConfigParser& parser) | |||||||
|  |  | ||||||
| 	std::wstring measureName = parser.ReadString(L"TrayMeasure", L"Measure", L""); | 	std::wstring measureName = parser.ReadString(L"TrayMeasure", L"Measure", L""); | ||||||
|  |  | ||||||
| 	CConfigParser* oldParser = Rainmeter->GetCurrentParser(); |  | ||||||
| 	Rainmeter->SetCurrentParser(&parser); |  | ||||||
| 	if (!measureName.empty()) | 	if (!measureName.empty()) | ||||||
| 	{ | 	{ | ||||||
| 		m_Measure = CMeasure::Create(measureName.c_str(), NULL); | 		CConfigParser* oldParser = Rainmeter->GetCurrentParser(); | ||||||
| 		m_Measure->SetName(L"TrayMeasure"); | 		Rainmeter->SetCurrentParser(&parser); | ||||||
| 		m_Measure->ReadConfig(parser, L"TrayMeasure"); |  | ||||||
|  | 		try | ||||||
|  | 		{ | ||||||
|  | 			m_Measure = CMeasure::Create(measureName.c_str(), NULL); | ||||||
|  | 			if (m_Measure) | ||||||
|  | 			{ | ||||||
|  | 				m_Measure->SetName(L"TrayMeasure"); | ||||||
|  | 				m_Measure->ReadConfig(parser, L"TrayMeasure"); | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
|  | 		catch (CError& error) | ||||||
|  | 		{ | ||||||
|  | 			delete m_Measure; | ||||||
|  | 			m_Measure = NULL; | ||||||
|  | 			MessageBox(m_Window, error.GetString().c_str(), APPNAME, MB_OK | MB_TOPMOST | MB_ICONEXCLAMATION); | ||||||
|  | 		} | ||||||
|  |  | ||||||
|  | 		Rainmeter->SetCurrentParser(oldParser); | ||||||
| 	} | 	} | ||||||
| 	Rainmeter->SetCurrentParser(oldParser); |  | ||||||
|  |  | ||||||
| 	m_MeterType = TRAY_METER_TYPE_NONE; | 	m_MeterType = TRAY_METER_TYPE_NONE; | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 spx
					spx