修正代码细节
This commit is contained in:
		
							parent
							
								
									2d4e5ef60a
								
							
						
					
					
						commit
						cc300aeb7c
					
				|  | @ -317,9 +317,9 @@ void e2d::Window::setConsoleEnabled(bool enabled) | ||||||
| 				hwnd = ::GetConsoleWindow(); | 				hwnd = ::GetConsoleWindow(); | ||||||
| 				// 重定向输入输出
 | 				// 重定向输入输出
 | ||||||
| 				FILE * stdoutStream, * stdinStream, * stderrStream; | 				FILE * stdoutStream, * stdinStream, * stderrStream; | ||||||
| 				freopen_s(&stdoutStream, "conout$", "w+t", stdout); | 				WARN_IF(freopen_s(&stdoutStream, "conout$", "w+t", stdout) != 0, "freopen stdout failed!"); | ||||||
| 				freopen_s(&stdinStream, "conin$", "r+t", stdin); | 				WARN_IF(freopen_s(&stdinStream, "conin$", "r+t", stdin) != 0, "freopen stdin failed!"); | ||||||
| 				freopen_s(&stderrStream, "conout$", "w+t", stderr); | 				WARN_IF(freopen_s(&stderrStream, "conout$", "w+t", stderr) != 0, "freopen stderr failed!"); | ||||||
| 				// 禁用控制台关闭按钮
 | 				// 禁用控制台关闭按钮
 | ||||||
| 				HMENU hmenu = ::GetSystemMenu(hwnd, FALSE); | 				HMENU hmenu = ::GetSystemMenu(hwnd, FALSE); | ||||||
| 				::RemoveMenu(hmenu, SC_CLOSE, MF_BYCOMMAND); | 				::RemoveMenu(hmenu, SC_CLOSE, MF_BYCOMMAND); | ||||||
|  |  | ||||||
|  | @ -79,7 +79,7 @@ e2d::String e2d::String::format(const char * format, ...) | ||||||
| { | { | ||||||
| 	std::string tmp; | 	std::string tmp; | ||||||
| 
 | 
 | ||||||
| 	va_list marker = nullptr; | 	va_list marker; | ||||||
| 	va_start(marker, format); | 	va_start(marker, format); | ||||||
| 
 | 
 | ||||||
| 	size_t nu_of_chars = _vscprintf(format, marker); | 	size_t nu_of_chars = _vscprintf(format, marker); | ||||||
|  | @ -101,7 +101,7 @@ e2d::String e2d::String::format(const wchar_t * format, ...) | ||||||
| { | { | ||||||
| 	std::wstring tmp; | 	std::wstring tmp; | ||||||
| 
 | 
 | ||||||
| 	va_list marker = nullptr; | 	va_list marker; | ||||||
| 	va_start(marker, format); | 	va_start(marker, format); | ||||||
| 
 | 
 | ||||||
| 	size_t nu_of_chars = _vscwprintf(format, marker); | 	size_t nu_of_chars = _vscwprintf(format, marker); | ||||||
|  |  | ||||||
|  | @ -1,8 +1,29 @@ | ||||||
| #include "..\e2dnode.h" | #include "..\e2dnode.h" | ||||||
| 
 | 
 | ||||||
|  | #define SAFE_SET(pointer, func, ...) if (pointer) { pointer->##func(__VA_ARGS__); } | ||||||
|  | 
 | ||||||
|  | #define SET_BUTTON_NODE(Old, New)								\ | ||||||
|  | 	if (New != Old)												\ | ||||||
|  | 	{															\ | ||||||
|  | 		if (Old) this->removeChild(Old);						\ | ||||||
|  | 		if (New)												\ | ||||||
|  | 		{														\ | ||||||
|  | 			this->addChild(New);								\ | ||||||
|  | 			this->setSize(New->getWidth(), New->getHeight());	\ | ||||||
|  | 		}														\ | ||||||
|  | 		Old = New;												\ | ||||||
|  | 		_updateState();											\ | ||||||
|  | 		_updateVisible();										\ | ||||||
|  | 	}															\ | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| e2d::ToggleButton::ToggleButton() | e2d::ToggleButton::ToggleButton() | ||||||
| 	: Button() | 	: Button() | ||||||
| 	, _toggle(true) | 	, _toggle(true) | ||||||
|  | 	, _normalOn(nullptr) | ||||||
|  | 	, _mouseoverOn(nullptr) | ||||||
|  | 	, _selectedOn(nullptr) | ||||||
|  | 	, _disabledOn(nullptr) | ||||||
| 	, _normalOff(nullptr) | 	, _normalOff(nullptr) | ||||||
| 	, _mouseoverOff(nullptr) | 	, _mouseoverOff(nullptr) | ||||||
| 	, _selectedOff(nullptr) | 	, _selectedOff(nullptr) | ||||||
|  | @ -13,6 +34,10 @@ e2d::ToggleButton::ToggleButton() | ||||||
| e2d::ToggleButton::ToggleButton(Node * toggleOnNormal, Node * toggleOffNormal, const Function& func) | e2d::ToggleButton::ToggleButton(Node * toggleOnNormal, Node * toggleOffNormal, const Function& func) | ||||||
| 	: Button() | 	: Button() | ||||||
| 	, _toggle(true) | 	, _toggle(true) | ||||||
|  | 	, _normalOn(nullptr) | ||||||
|  | 	, _mouseoverOn(nullptr) | ||||||
|  | 	, _selectedOn(nullptr) | ||||||
|  | 	, _disabledOn(nullptr) | ||||||
| 	, _normalOff(nullptr) | 	, _normalOff(nullptr) | ||||||
| 	, _mouseoverOff(nullptr) | 	, _mouseoverOff(nullptr) | ||||||
| 	, _selectedOff(nullptr) | 	, _selectedOff(nullptr) | ||||||
|  | @ -26,6 +51,10 @@ e2d::ToggleButton::ToggleButton(Node * toggleOnNormal, Node * toggleOffNormal, c | ||||||
| e2d::ToggleButton::ToggleButton(Node * toggleOnNormal, Node * toggleOffNormal, Node * toggleOnSelected, Node * toggleOffSelected, const Function& func) | e2d::ToggleButton::ToggleButton(Node * toggleOnNormal, Node * toggleOffNormal, Node * toggleOnSelected, Node * toggleOffSelected, const Function& func) | ||||||
| 	: Button() | 	: Button() | ||||||
| 	, _toggle(true) | 	, _toggle(true) | ||||||
|  | 	, _normalOn(nullptr) | ||||||
|  | 	, _mouseoverOn(nullptr) | ||||||
|  | 	, _selectedOn(nullptr) | ||||||
|  | 	, _disabledOn(nullptr) | ||||||
| 	, _normalOff(nullptr) | 	, _normalOff(nullptr) | ||||||
| 	, _mouseoverOff(nullptr) | 	, _mouseoverOff(nullptr) | ||||||
| 	, _selectedOff(nullptr) | 	, _selectedOff(nullptr) | ||||||
|  | @ -41,6 +70,10 @@ e2d::ToggleButton::ToggleButton(Node * toggleOnNormal, Node * toggleOffNormal, N | ||||||
| e2d::ToggleButton::ToggleButton(Node * toggleOnNormal, Node * toggleOffNormal, Node * toggleOnMouseOver, Node * toggleOffMouseOver, Node * toggleOnSelected, Node * toggleOffSelected, const Function& func) | e2d::ToggleButton::ToggleButton(Node * toggleOnNormal, Node * toggleOffNormal, Node * toggleOnMouseOver, Node * toggleOffMouseOver, Node * toggleOnSelected, Node * toggleOffSelected, const Function& func) | ||||||
| 	: Button() | 	: Button() | ||||||
| 	, _toggle(true) | 	, _toggle(true) | ||||||
|  | 	, _normalOn(nullptr) | ||||||
|  | 	, _mouseoverOn(nullptr) | ||||||
|  | 	, _selectedOn(nullptr) | ||||||
|  | 	, _disabledOn(nullptr) | ||||||
| 	, _normalOff(nullptr) | 	, _normalOff(nullptr) | ||||||
| 	, _mouseoverOff(nullptr) | 	, _mouseoverOff(nullptr) | ||||||
| 	, _selectedOff(nullptr) | 	, _selectedOff(nullptr) | ||||||
|  | @ -91,186 +124,57 @@ void e2d::ToggleButton::setState(bool bState) | ||||||
| 
 | 
 | ||||||
| void e2d::ToggleButton::setNormal(Node * normal) | void e2d::ToggleButton::setNormal(Node * normal) | ||||||
| { | { | ||||||
| 	if (normal != _normal) | 	SET_BUTTON_NODE(_normalOn, normal); | ||||||
| 	{ |  | ||||||
| 		// 移除旧的
 |  | ||||||
| 		if (_normal) |  | ||||||
| 		{ |  | ||||||
| 			this->removeChild(_normal); |  | ||||||
| 		} |  | ||||||
| 		// 添加新的
 |  | ||||||
| 		if (normal) |  | ||||||
| 		{ |  | ||||||
| 			this->addChild(normal); |  | ||||||
| 			this->setSize(normal->getWidth(), normal->getHeight()); |  | ||||||
| 		} |  | ||||||
| 		_normal = normal; |  | ||||||
| 
 |  | ||||||
| 		_updateState(); |  | ||||||
| 		_updateVisible(); |  | ||||||
| 	} |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void e2d::ToggleButton::setMouseOver(Node * mouseover) | void e2d::ToggleButton::setMouseOver(Node * mouseover) | ||||||
| { | { | ||||||
| 	if (mouseover != _mouseover) | 	SET_BUTTON_NODE(_mouseoverOn, mouseover); | ||||||
| 	{ |  | ||||||
| 		// 移除旧的
 |  | ||||||
| 		if (_mouseover) |  | ||||||
| 		{ |  | ||||||
| 			this->removeChild(_mouseover); |  | ||||||
| 		} |  | ||||||
| 		// 添加新的
 |  | ||||||
| 		if (mouseover) |  | ||||||
| 		{ |  | ||||||
| 			this->addChild(mouseover); |  | ||||||
| 		} |  | ||||||
| 		_mouseover = mouseover; |  | ||||||
| 
 |  | ||||||
| 		_updateState(); |  | ||||||
| 		_updateVisible(); |  | ||||||
| 	} |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void e2d::ToggleButton::setSelected(Node * selected) | void e2d::ToggleButton::setSelected(Node * selected) | ||||||
| { | { | ||||||
| 	if (selected != _selected) | 	SET_BUTTON_NODE(_selectedOn, selected); | ||||||
| 	{ |  | ||||||
| 		// 移除旧的
 |  | ||||||
| 		if (_selected) |  | ||||||
| 		{ |  | ||||||
| 			this->removeChild(_selected); |  | ||||||
| 		} |  | ||||||
| 		// 添加新的
 |  | ||||||
| 		if (selected) |  | ||||||
| 		{ |  | ||||||
| 			this->addChild(selected); |  | ||||||
| 		} |  | ||||||
| 		_selected = selected; |  | ||||||
| 
 |  | ||||||
| 		_updateState(); |  | ||||||
| 		_updateVisible(); |  | ||||||
| 	} |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void e2d::ToggleButton::setDisabled(Node * disabled) | void e2d::ToggleButton::setDisabled(Node * disabled) | ||||||
| { | { | ||||||
| 	if (disabled != _disabled) | 	SET_BUTTON_NODE(_disabledOn, disabled); | ||||||
| 	{ |  | ||||||
| 		// 移除旧的
 |  | ||||||
| 		if (_disabled) |  | ||||||
| 		{ |  | ||||||
| 			this->removeChild(_disabled); |  | ||||||
| 		} |  | ||||||
| 		// 添加新的
 |  | ||||||
| 		if (disabled) |  | ||||||
| 		{ |  | ||||||
| 			this->addChild(disabled); |  | ||||||
| 		} |  | ||||||
| 		_disabled = disabled; |  | ||||||
| 
 |  | ||||||
| 		_updateState(); |  | ||||||
| 		_updateVisible(); |  | ||||||
| 	} |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void e2d::ToggleButton::setNormalOff(Node * normal) | void e2d::ToggleButton::setNormalOff(Node * normal) | ||||||
| { | { | ||||||
| 	if (normal != _normalOff) | 	SET_BUTTON_NODE(_normalOff, normal); | ||||||
| 	{ |  | ||||||
| 		// 移除旧的
 |  | ||||||
| 		if (_normalOff) |  | ||||||
| 		{ |  | ||||||
| 			this->removeChild(_normalOff); |  | ||||||
| 		} |  | ||||||
| 		// 添加新的
 |  | ||||||
| 		if (normal) |  | ||||||
| 		{ |  | ||||||
| 			this->addChild(normal); |  | ||||||
| 		} |  | ||||||
| 		_normalOff = normal; |  | ||||||
| 
 |  | ||||||
| 		_updateState(); |  | ||||||
| 		_updateVisible(); |  | ||||||
| 	} |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void e2d::ToggleButton::setMouseOverOff(Node * mouseover) | void e2d::ToggleButton::setMouseOverOff(Node * mouseover) | ||||||
| { | { | ||||||
| 	if (mouseover != _mouseoverOff) | 	SET_BUTTON_NODE(_mouseoverOff, mouseover); | ||||||
| 	{ |  | ||||||
| 		// 移除旧的
 |  | ||||||
| 		if (_mouseoverOff) |  | ||||||
| 		{ |  | ||||||
| 			this->removeChild(_mouseoverOff); |  | ||||||
| 		} |  | ||||||
| 		// 添加新的
 |  | ||||||
| 		if (mouseover) |  | ||||||
| 		{ |  | ||||||
| 			this->addChild(mouseover); |  | ||||||
| 		} |  | ||||||
| 		_mouseoverOff = mouseover; |  | ||||||
| 
 |  | ||||||
| 		_updateState(); |  | ||||||
| 		_updateVisible(); |  | ||||||
| 	} |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void e2d::ToggleButton::setSelectedOff(Node * selected) | void e2d::ToggleButton::setSelectedOff(Node * selected) | ||||||
| { | { | ||||||
| 	if (selected != _selectedOff) | 	SET_BUTTON_NODE(_selectedOff, selected); | ||||||
| 	{ |  | ||||||
| 		// 移除旧的
 |  | ||||||
| 		if (_selectedOff) |  | ||||||
| 		{ |  | ||||||
| 			this->removeChild(_selectedOff); |  | ||||||
| 		} |  | ||||||
| 		// 添加新的
 |  | ||||||
| 		if (selected) |  | ||||||
| 		{ |  | ||||||
| 			this->addChild(selected); |  | ||||||
| 		} |  | ||||||
| 		_selectedOff = selected; |  | ||||||
| 
 |  | ||||||
| 		_updateState(); |  | ||||||
| 		_updateVisible(); |  | ||||||
| 	} |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void e2d::ToggleButton::setDisabledOff(Node * disabled) | void e2d::ToggleButton::setDisabledOff(Node * disabled) | ||||||
| { | { | ||||||
| 	if (disabled != _disabledOff) | 	SET_BUTTON_NODE(_disabledOff, disabled); | ||||||
| 	{ |  | ||||||
| 		// 移除旧的
 |  | ||||||
| 		if (_disabledOff) |  | ||||||
| 		{ |  | ||||||
| 			this->removeChild(_disabledOff); |  | ||||||
| 		} |  | ||||||
| 		// 添加新的
 |  | ||||||
| 		if (disabled) |  | ||||||
| 		{ |  | ||||||
| 			this->addChild(disabled); |  | ||||||
| 		} |  | ||||||
| 		_disabledOff = disabled; |  | ||||||
| 
 |  | ||||||
| 		_updateState(); |  | ||||||
| 		_updateVisible(); |  | ||||||
| 	} |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void e2d::ToggleButton::_updateState() | void e2d::ToggleButton::_updateState() | ||||||
| { | { | ||||||
| 	if (_toggle) | 	if (_toggle) | ||||||
| 	{ | 	{ | ||||||
| 		_normal = _normal; | 		_normal = _normalOn; | ||||||
| 		_mouseover = _mouseover; | 		_mouseover = _mouseoverOn; | ||||||
| 		_selected = _selected; | 		_selected = _selectedOn; | ||||||
| 		_disabled = _disabled; | 		_disabled = _disabledOn; | ||||||
| 
 | 
 | ||||||
| 		if (_normalOff) _normalOff->setVisible(false); | 		SAFE_SET(_normalOff, setVisible, false); | ||||||
| 		if (_mouseoverOff) _mouseoverOff->setVisible(false); | 		SAFE_SET(_mouseoverOff, setVisible, false); | ||||||
| 		if (_selectedOff) _selectedOff->setVisible(false); | 		SAFE_SET(_selectedOff, setVisible, false); | ||||||
| 		if (_disabledOff) _disabledOff->setVisible(false); | 		SAFE_SET(_disabledOff, setVisible, false); | ||||||
| 	} | 	} | ||||||
| 	else | 	else | ||||||
| 	{ | 	{ | ||||||
|  | @ -279,10 +183,10 @@ void e2d::ToggleButton::_updateState() | ||||||
| 		_selected = _selectedOff; | 		_selected = _selectedOff; | ||||||
| 		_disabled = _disabledOff; | 		_disabled = _disabledOff; | ||||||
| 
 | 
 | ||||||
| 		if (_normal) _normal->setVisible(false); | 		SAFE_SET(_normalOn, setVisible, false); | ||||||
| 		if (_mouseover) _mouseover->setVisible(false); | 		SAFE_SET(_mouseoverOn, setVisible, false); | ||||||
| 		if (_selected) _selected->setVisible(false); | 		SAFE_SET(_selectedOn, setVisible, false); | ||||||
| 		if (_disabled) _disabled->setVisible(false); | 		SAFE_SET(_disabledOn, setVisible, false); | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -461,10 +461,10 @@ bool e2d::Music::_findMediaFileCch(wchar_t* strDestPath, int cchDest, const wcha | ||||||
| 	// Get the exe _name, and exe path
 | 	// Get the exe _name, and exe path
 | ||||||
| 	wchar_t strExePath[MAX_PATH] = { 0 }; | 	wchar_t strExePath[MAX_PATH] = { 0 }; | ||||||
| 	wchar_t strExeName[MAX_PATH] = { 0 }; | 	wchar_t strExeName[MAX_PATH] = { 0 }; | ||||||
| 	wchar_t* strLastSlash = nullptr; |  | ||||||
| 	GetModuleFileName(HINST_THISCOMPONENT, strExePath, MAX_PATH); | 	GetModuleFileName(HINST_THISCOMPONENT, strExePath, MAX_PATH); | ||||||
| 	strExePath[MAX_PATH - 1] = 0; | 	strExePath[MAX_PATH - 1] = 0; | ||||||
| 	strLastSlash = wcsrchr(strExePath, TEXT('\\')); | 
 | ||||||
|  | 	wchar_t* strLastSlash = wcsrchr(strExePath, TEXT('\\')); | ||||||
| 	if (strLastSlash) | 	if (strLastSlash) | ||||||
| 	{ | 	{ | ||||||
| 		wcscpy_s(strExeName, MAX_PATH, &strLastSlash[1]); | 		wcscpy_s(strExeName, MAX_PATH, &strLastSlash[1]); | ||||||
|  |  | ||||||
|  | @ -945,6 +945,10 @@ protected: | ||||||
| 	virtual void _runCallback() override; | 	virtual void _runCallback() override; | ||||||
| 
 | 
 | ||||||
| protected: | protected: | ||||||
|  | 	Node*	_normalOn; | ||||||
|  | 	Node*	_mouseoverOn; | ||||||
|  | 	Node*	_selectedOn; | ||||||
|  | 	Node*	_disabledOn; | ||||||
| 	Node*	_normalOff; | 	Node*	_normalOff; | ||||||
| 	Node*	_mouseoverOff; | 	Node*	_mouseoverOff; | ||||||
| 	Node*	_selectedOff; | 	Node*	_selectedOff; | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue