diff LightClone/Source/GuiInterface.cpp @ 26:3a63df04f3c0

Several Gui enhancements; Drag and drop should work; Added resource caching
author koryspansel
date Fri, 16 Sep 2011 15:28:15 -0700
parents eae13b04b06f
children 0b729faa4e73
line wrap: on
line diff
--- a/LightClone/Source/GuiInterface.cpp	Fri Sep 16 13:11:35 2011 -0700
+++ b/LightClone/Source/GuiInterface.cpp	Fri Sep 16 15:28:15 2011 -0700
@@ -71,66 +71,94 @@
 		pCursor->Update(fElapsed);
 	}
 
-	GuiElement* pElement = Pick(fMouseX, fMouseY);
-
-	if(fMouseDeltaX != 0.0f || fMouseDeltaY != 0.0f)
+	if(pDragElement)
 	{
-		//Mouse moved
-		if(pCaptureElement)
+		if(pInputManager->IsButtonReleased(nDragButton))
+		{
+			EndDrag(Pick(fMouseX, fMouseY), fMouseX, fMouseY);
+		}
+		else
 		{
-
+			for(uint32 nButton = MouseButton_Left; nButton < MouseButton_Count; ++nButton)
+			{
+				if(pInputManager->IsButtonPressed(nButton) || pInputManager->IsButtonReleased(nButton))
+				{
+					EndDrag(NULL, fMouseX, fMouseY);
+				}
+			}
 		}
 	}
-
-	for(uint32 nButton = MouseButton_Left; nButton < MouseButton_Count; ++nButton)
+	else
 	{
-		// button down
-		if(pInputManager->IsButtonDown(nButton) && !pInputManager->WasButtonDown(nButton))
+		GuiElement* pElement = Pick(fMouseX, fMouseY);
+
+		if(pFocusElement != pElement)
 		{
-			if(pCaptureElement)
+			if(!pCaptureElement)
 			{
-				//TODO: Does capture make sense for mouse down events?
-				pElement->OnMouseDown(nButton, fMouseX, fMouseY);
+				if(pFocusElement)
+				{
+					pFocusElement->OnMouseLeave();
+				}
+
+				if(pElement)
+				{
+					pElement->OnMouseEnter();
+				}
 			}
-			else
+
+			pFocusElement = pElement;
+		}
+
+		for(uint32 nButton = MouseButton_Left; nButton < MouseButton_Count; ++nButton)
+		{
+			// button down
+			if(pInputManager->IsButtonPressed(nButton))
 			{
+				if(pCaptureElement)
+				{
+					pElement->OnMouseDown(nButton, fMouseX, fMouseY);
+				}
+				else
+
 				if(pElement)
 				{
 					pElement->OnMouseDown(nButton, fMouseX, fMouseY);
 				}
 			}
-		}
-		else
+			else
 
-		// button up
-		if(!pInputManager->IsButtonDown(nButton) && pInputManager->WasButtonDown(nButton))
-		{
-			if(pDragElement)
-			{
-				GuiElement* pElement = Pick(fMouseX, fMouseY);
-				if(pElement)
-				{
-					pElement->OnDrop(pDragElement, fMouseX, fMouseY);
-				}
-
-				pDragElement = NULL;
-			}
-			else
+			// button up
+			if(pInputManager->IsButtonReleased(nButton))
 			{
 				if(pCaptureElement)
 				{
 					pCaptureElement->OnMouseUp(nButton, fMouseX, fMouseY);
 				}
 				else
+
+				if(pElement)
 				{
-					GuiElement* pElement = Pick(fMouseX, fMouseY);
-					if(pElement)
-					{
-						pElement->OnMouseUp(nButton, fMouseX, fMouseY);
-					}
+					pElement->OnMouseUp(nButton, fMouseX, fMouseY);
 				}
 			}
 		}
+
+		// mouse moved
+		if(fDeltaX != 0.0f || fDeltaY != 0.0f)
+		//if(pInputManager->MouseMoved())
+		{
+			if(pCaptureElement)
+			{
+				pCaptureElement->OnMouseMove(fMouseX, fMouseY);
+			}
+			else
+
+			if(pElement)
+			{
+				pElement->OnMouseMove(fMouseX, fMouseY);
+			}
+		}
 	}
 }
 
@@ -142,7 +170,7 @@
 	//TODO: Begin batch
 	//kContext.BeginBatch();
 
-	if(bVisible)
+	if(nFlags & GuiElementFlag_Visible)
 	{
 		//TODO: Inside Render functions call kContext.AddToBatch(pTexture, kPosition, kDimensions, kColor)
 		GuiElement::Render(kContext, kCamera);
@@ -185,15 +213,33 @@
 }
 
 /*
+ * IsCursorAcquiredBy
+ */
+bool GuiInterface::IsCursorAcquiredBy(GuiElement* pElement) const
+{
+	return pDragElement == pElement;
+}
+
+/*
  * BeginDrag
  */
-void GuiInterface::BeginDrag(GuiElement* pSource)
+void GuiInterface::BeginDrag(GuiElement* pSource, uint32 nButton)
 {
+	//ASSERT(pDragElement == NULL);
+
+	pDragElement	= pSource;
+	nDragButton		= nButton;
 }
 
 /*
  * EndDrag
  */
-void GuiInterface::EndDrag()
+void GuiInterface::EndDrag(GuiElement* pTarget, float fX, float fY)
 {
+	if(pTarget)
+	{
+		pTarget->OnDrop(pDragElement, fX, fY);
+	}
+
+	pDragElement = NULL;
 }