changeset 30:d9e9ce8219f8

Drag and drop
author koryspansel
date Mon, 19 Sep 2011 14:55:26 -0700
parents 4bb3bcee0601
children 0b729faa4e73
files LightClone/LightClone.vcproj LightClone/Source/CodePanel.cpp LightClone/Source/CodePanel.h LightClone/Source/CodeSlot.cpp LightClone/Source/CodeSlot.h LightClone/Source/GuiImage.h
diffstat 6 files changed, 194 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/LightClone/LightClone.vcproj	Mon Sep 19 12:51:07 2011 -0700
+++ b/LightClone/LightClone.vcproj	Mon Sep 19 14:55:26 2011 -0700
@@ -193,6 +193,10 @@
 				>
 			</File>
 			<File
+				RelativePath=".\Source\CodeSlot.cpp"
+				>
+			</File>
+			<File
 				RelativePath=".\Source\Environment.cpp"
 				>
 			</File>
@@ -339,6 +343,10 @@
 				>
 			</File>
 			<File
+				RelativePath=".\Source\CodeSlot.h"
+				>
+			</File>
+			<File
 				RelativePath=".\Source\Environment.h"
 				>
 			</File>
--- a/LightClone/Source/CodePanel.cpp	Mon Sep 19 12:51:07 2011 -0700
+++ b/LightClone/Source/CodePanel.cpp	Mon Sep 19 14:55:26 2011 -0700
@@ -3,13 +3,13 @@
  */
 
 #include "CodePanel.h"
-#include "GuiImage.h"
 
 /*
  * CodePanel
  */
-CodePanel::CodePanel()
+CodePanel::CodePanel(uint32 nMaximum) : GuiImage(), nSlotCount(nMaximum)
 {
+	pSlot = new CodeSlot*[nMaximum];
 }
 
 /*
@@ -17,29 +17,20 @@
  */
 ErrorCode CodePanel::Initialize(ResourceManager* pResourceManager)
 {
-	ErrorCode eCode = GuiElement::Initialize(pResourceManager);
+	ErrorCode eCode = GuiImage::Initialize(pResourceManager);
 	if(eCode == Error_Success)
 	{
-		for(uint32 i = 0; i < 4; ++i)
+		SetTexture("Data\\Textures\\Panel.tga");
+
+		for(uint32 i = 0; i < nSlotCount; ++i)
 		{
-			GuiImage*
-			pImage = new GuiImage();
-			pImage->Initialize(pResourceManager);
-			pImage->SetTexture("Data\\Textures\\Slot.tga");
-			pImage->SetDimensions(48.0f, 48.0f);
-			pImage->SetPosition(48.0f * i, 0.0f);
+			pSlot[i] = new CodeSlot();
+			pSlot[i]->Initialize(pResourceManager);
+			pSlot[i]->SetPosition(48.0f * i, 0.0f);
 
-			Add(pImage);
+			Add(pSlot[i]);
 		}
 	}
 
 	return eCode;
 }
-
-/*
- * Update
- */
-void CodePanel::Update(float fElapsed)
-{
-}
-
--- a/LightClone/Source/CodePanel.h	Mon Sep 19 12:51:07 2011 -0700
+++ b/LightClone/Source/CodePanel.h	Mon Sep 19 14:55:26 2011 -0700
@@ -6,34 +6,34 @@
 #define __CODEPANEL_H__
 
 #include "Core.h"
-#include "GuiImage.h"
+#include "CodeSlot.h"
 
 /*
  * CodePanel
  */
-class CodePanel : public GuiElement
+class CodePanel : public GuiImage
 {
 	/*
 	 * pSlot
 	 */
-	GuiImage** pSlot;
+	CodeSlot** pSlot;
+
+	/*
+	 * nSlotCount
+	 */
+	uint32 nSlotCount;
 
 public:
 
 	/*
 	 * CodePanel
 	 */
-	CodePanel();
+	CodePanel(uint32 nMaximum);
 
 	/*
 	 * Initialize
 	 */
 	virtual ErrorCode Initialize(ResourceManager* pResourceManager);
-
-	/*
-	 * Update
-	 */
-	virtual void Update(float fElapsed);
 };
 
 #endif //__CODEPANEL_H__
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LightClone/Source/CodeSlot.cpp	Mon Sep 19 14:55:26 2011 -0700
@@ -0,0 +1,99 @@
+/*
+ * CodeSlot
+ */
+
+#include "CodeSlot.h"
+#include "GuiInterface.h"
+#include "InputManager.h"
+
+/*
+ * ActionTextureName
+ */
+const char* ActionTextureName[] = 
+{
+	"Data\\Textures\\Forward.tga",
+	"Data\\Textures\\RotateCW.tga",
+	"Data\\Textures\\RotateCCW.tga",
+	"Data\\Textures\\Jump.tga",
+	"Data\\Textures\\Light.tga",
+	"Data\\Textures\\FunctionA.tga",
+	"Data\\Textures\\FunctionB.tga",
+};
+
+/*
+ * CodeSlot
+ */
+CodeSlot::CodeSlot() : GuiImage()
+{
+	nAction		= Action_Default;
+	bMouseDown	= false;
+}
+
+/*
+ * Initialize
+ */
+ErrorCode CodeSlot::Initialize(ResourceManager* pManager)
+{
+	ErrorCode eCode = GuiImage::Initialize(pManager);
+	if(eCode == Error_Success)
+	{
+		SetTexture("Data\\Textures\\Slot.tga", true);
+	}
+
+	return eCode;
+}
+
+/*
+ * Terminate
+ */
+void CodeSlot::Terminate()
+{
+}
+
+/*
+ * OnMouseDown
+ */
+void CodeSlot::OnMouseDown(uint32 nButton, float fX, float fY)
+{
+	if(nButton == MouseButton_Left)
+	{
+		bMouseDown = true;
+	}
+}
+
+/*
+ * OnMouseUp
+ */
+void CodeSlot::OnMouseUp(uint32 nButton, float fX, float fY)
+{
+	bMouseDown = false;
+}
+
+/*
+ * OnMouseMove
+ */
+void CodeSlot::OnMouseMove(float fX, float fY)
+{
+	if(bMouseDown)
+	{
+		if(nAction != Action_Default)
+		{
+			pInterface->BeginDrag(this, MouseButton_Left);
+		}
+	}
+}
+
+/*
+ * OnDrop
+ */
+void CodeSlot::OnDrop(GuiElement* pSource, float fX, float fY)
+{
+	if(true) // pSource is a CodeSlot
+	{
+		uint32 nAction = ((CodeSlot*)pSource)->nAction;
+
+		if(nAction != Action_Default)
+		{
+		}
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LightClone/Source/CodeSlot.h	Mon Sep 19 14:55:26 2011 -0700
@@ -0,0 +1,66 @@
+/*
+ * CodeSlot
+ */
+
+#ifndef __CODESLOT_H__
+#define __CODESLOT_H__
+
+#include "Core.h"
+#include "GuiImage.h"
+
+/*
+ * CodeSlot
+ */
+class CodeSlot : public GuiImage
+{
+	/*
+	 * bMouseDown
+	 */
+	bool bMouseDown;
+
+	/*
+	 * nAction
+	 */
+	uint32 nAction;
+
+public:
+
+	/*
+	 * CodeSlot
+	 */
+	CodeSlot();
+
+	/*
+	 * Initialize
+	 */
+	virtual ErrorCode Initialize(ResourceManager* pResourceManager);
+
+	/*
+	 * Terminate
+	 */
+	virtual void Terminate();
+
+protected:
+
+	/*
+	 * OnMouseDown
+	 */
+	virtual void OnMouseDown(uint32 nButton, float fX, float fY);
+
+	/*
+	 * OnMouseUp
+	 */
+	virtual void OnMouseUp(uint32 nButton, float fX, float fY);
+
+	/*
+	 * OnMouseMove
+	 */
+	virtual void OnMouseMove(float fX, float fY);
+
+	/*
+	 * OnDrop
+	 */
+	virtual void OnDrop(GuiElement* pSource, float fX, float fY);
+};
+
+#endif //__CODESLOT_H__
--- a/LightClone/Source/GuiImage.h	Mon Sep 19 12:51:07 2011 -0700
+++ b/LightClone/Source/GuiImage.h	Mon Sep 19 14:55:26 2011 -0700
@@ -13,6 +13,8 @@
  */
 class GuiImage : public GuiElement
 {
+protected:
+
 	/*
 	 * pResourceManager
 	 */