Window cleanup and focused window pointer handling.
This commit is contained in:
		
							parent
							
								
									dc292a3554
								
							
						
					
					
						commit
						cb4a564c48
					
				| @ -179,6 +179,23 @@ bool FiestaOnlineEditor::OnUserUpdate(float fElapsedTime){ | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	bool focusErased=false; | ||||
| 	std::erase_if(windows,[&](Window*w){ | ||||
| 		if(w->IsClosed()){ | ||||
| 			if(w->IsFocusedWindow()){ | ||||
| 				focusErased=true; | ||||
| 			} | ||||
| 			w->Cleanup(); | ||||
| 			return true; | ||||
| 		} else { | ||||
| 			return false; | ||||
| 		} | ||||
| 	}); | ||||
| 
 | ||||
| 	if(focusErased&&windows.size()>0){ | ||||
| 		Window::SetFocusedWindow(windows[0]); | ||||
| 	} | ||||
| 
 | ||||
| 	SetDrawTarget(nullptr); | ||||
| 	//FOREGROUND DRAWING
 | ||||
| 	manager.Draw(sprMenu,{64,64}); | ||||
|  | ||||
| @ -76,7 +76,7 @@ | ||||
|       <SDLCheck>true</SDLCheck> | ||||
|       <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> | ||||
|       <ConformanceMode>true</ConformanceMode> | ||||
|       <LanguageStandard>stdcpp17</LanguageStandard> | ||||
|       <LanguageStandard>stdcpp20</LanguageStandard> | ||||
|     </ClCompile> | ||||
|     <Link> | ||||
|       <SubSystem>Console</SubSystem> | ||||
| @ -91,7 +91,7 @@ | ||||
|       <SDLCheck>true</SDLCheck> | ||||
|       <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> | ||||
|       <ConformanceMode>true</ConformanceMode> | ||||
|       <LanguageStandard>stdcpp17</LanguageStandard> | ||||
|       <LanguageStandard>stdcpp20</LanguageStandard> | ||||
|     </ClCompile> | ||||
|     <Link> | ||||
|       <SubSystem>Console</SubSystem> | ||||
| @ -106,7 +106,7 @@ | ||||
|       <SDLCheck>true</SDLCheck> | ||||
|       <PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> | ||||
|       <ConformanceMode>true</ConformanceMode> | ||||
|       <LanguageStandard>stdcpp17</LanguageStandard> | ||||
|       <LanguageStandard>stdcpp20</LanguageStandard> | ||||
|     </ClCompile> | ||||
|     <Link> | ||||
|       <SubSystem>Console</SubSystem> | ||||
| @ -121,7 +121,7 @@ | ||||
|       <SDLCheck>true</SDLCheck> | ||||
|       <PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> | ||||
|       <ConformanceMode>true</ConformanceMode> | ||||
|       <LanguageStandard>stdcpp17</LanguageStandard> | ||||
|       <LanguageStandard>stdcpp20</LanguageStandard> | ||||
|     </ClCompile> | ||||
|     <Link> | ||||
|       <SubSystem>Console</SubSystem> | ||||
|  | ||||
| @ -17,6 +17,17 @@ void Window::InternalUpdate(FiestaOnlineEditor*pge,float fElapsedTime){ | ||||
| 	if(dragging){ | ||||
| 		pos=pge->GetMousePos()-dragPoint; | ||||
| 	} | ||||
| 	if(pge->GetMouseX()>=pos.x+size.x-64&&pge->GetMouseY()<pos.y+headerHeight&&pge->GetMouseY()>=pos.y){ | ||||
| 		if(!canClose){ | ||||
| 			canClose=true; | ||||
| 			InternalRefresh(pge); | ||||
| 		} | ||||
| 	} else { | ||||
| 		if(canClose){ | ||||
| 			canClose=false; | ||||
| 			InternalRefresh(pge); | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| void Window::InternalRefresh(FiestaOnlineEditor*pge){ | ||||
| @ -25,10 +36,18 @@ void Window::InternalRefresh(FiestaOnlineEditor*pge){ | ||||
| 
 | ||||
| 	//Window background drawing
 | ||||
| 	if(focusedWindow==this){ | ||||
| 		if(canClose){ | ||||
| 			pge->FillRect({0,headerHeight},size,VERY_DARK_RED); | ||||
| 		} else { | ||||
| 			pge->FillRect({0,headerHeight},size,VERY_DARK_BLUE); | ||||
| 		} | ||||
| 	} else { | ||||
| 		if(canClose){ | ||||
| 			pge->FillRect({0,headerHeight},size,DARK_GREY); | ||||
| 		} else { | ||||
| 			pge->FillRect({0,headerHeight},size,VERY_DARK_GREY); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	//All other drawing functions should go here.
 | ||||
| 
 | ||||
| @ -36,10 +55,18 @@ void Window::InternalRefresh(FiestaOnlineEditor*pge){ | ||||
| 	Refresh(pge); | ||||
| 	pos.y-=headerHeight; | ||||
| 	if(focusedWindow==this){ | ||||
| 		if(canClose){ | ||||
| 			pge->FillRect({0,0},{size.x,headerHeight},VERY_DARK_RED); | ||||
| 		} else { | ||||
| 			pge->FillRect({0,0},{size.x,headerHeight},VERY_DARK_BLUE); | ||||
| 		} | ||||
| 	} else { | ||||
| 		if(canClose){ | ||||
| 			pge->FillRect({0,0},{size.x,headerHeight},DARK_GREY); | ||||
| 		} else { | ||||
| 			pge->FillRect({0,0},{size.x,headerHeight},VERY_DARK_GREY); | ||||
| 		} | ||||
| 	} | ||||
| 	pge->DrawString({2,2},windowTitle,CYAN); | ||||
| 	pge->DrawLine({1,10},{size.x-2,10},DARK_CYAN,0xFFFFFF00); | ||||
| 	decWindow->Update(); | ||||
| @ -79,5 +106,16 @@ void Window::InternalMouseFocus(FiestaOnlineEditor*pge){ | ||||
| 	if(pge->GetMouse(0).bReleased){ | ||||
| 		dragging=false; | ||||
| 	} | ||||
| 	if(pge->GetMouse(1).bPressed){ | ||||
| 		closed=true; | ||||
| 	} | ||||
| } | ||||
| void Window::MouseFocus(FiestaOnlineEditor*pge){} | ||||
| 
 | ||||
| bool Window::IsClosed(){ | ||||
| 	return closed; | ||||
| } | ||||
| 
 | ||||
| void Window::SetFocusedWindow(Window*w){ | ||||
| 	focusedWindow=w;	 | ||||
| } | ||||
| @ -10,6 +10,8 @@ private: | ||||
| 	const int headerHeight=12; | ||||
| 	bool dragging=false; | ||||
| 	vf2d dragPoint; | ||||
| 	bool canClose=false; | ||||
| 	bool closed=false; | ||||
| protected: | ||||
| 	vi2d size; | ||||
| 	Sprite*sprWindow; | ||||
| @ -23,8 +25,10 @@ public: | ||||
| 	void InternalRefresh(FiestaOnlineEditor*pge); | ||||
| 	void Draw(FiestaOnlineEditor*pge); | ||||
| 	bool IsFocusedWindow(); | ||||
| 	static void SetFocusedWindow(Window*w); | ||||
| 	void Cleanup(); | ||||
| 	bool IsInBounds(vf2d point); | ||||
| 	void InternalMouseFocus(FiestaOnlineEditor*pge); | ||||
| 	virtual void MouseFocus(FiestaOnlineEditor*pge); | ||||
| 	bool IsClosed(); | ||||
| }; | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user