Mercurial > LightClone
comparison LightClone/Source/GuiInterface.cpp @ 25:eae13b04b06f
Working on Gui drag and drop
author | koryspansel <koryspansel@bendbroadband.com> |
---|---|
date | Fri, 16 Sep 2011 13:11:35 -0700 |
parents | a785b0aaf004 |
children | 3a63df04f3c0 |
comparison
equal
deleted
inserted
replaced
24:4ee162fc3537 | 25:eae13b04b06f |
---|---|
5 #include "GuiInterface.h" | 5 #include "GuiInterface.h" |
6 | 6 |
7 /* | 7 /* |
8 * GuiInterface | 8 * GuiInterface |
9 */ | 9 */ |
10 GuiInterface::GuiInterface() : pInputManager(NULL), pDragSource(NULL) | 10 GuiInterface::GuiInterface() : pInputManager(NULL), pDragElement(NULL), pCaptureElement(NULL), pFocusElement(NULL) |
11 { | 11 { |
12 pCursor = new GuiCursor(); | 12 pInterface = this; |
13 pCursor = new GuiCursor(); | |
13 } | 14 } |
14 | 15 |
15 /* | 16 /* |
16 * Initialize | 17 * Initialize |
17 */ | 18 */ |
49 /* | 50 /* |
50 * Update | 51 * Update |
51 */ | 52 */ |
52 void GuiInterface::Update(float fElapsed) | 53 void GuiInterface::Update(float fElapsed) |
53 { | 54 { |
54 const float fX = pInputManager->GetMouseX(); | 55 const float fMouseX = pInputManager->GetMouseX(); |
55 const float fY = pInputManager->GetMouseY(); | 56 const float fMouseY = pInputManager->GetMouseY(); |
57 const float fDeltaX = pInputManager->GetMouseDeltaX(); | |
58 const float fDeltaY = pInputManager->GetMouseDeltaY(); | |
56 | 59 |
57 GuiElement::Update(fElapsed); | 60 GuiElement::Update(fElapsed); |
58 | 61 |
59 if(pCursor) | 62 if(pCursor) |
60 { | 63 { |
62 char kBuffer[128]; | 65 char kBuffer[128]; |
63 sprintf_s(kBuffer, "<%0.2f, %0.2f>\n", fX, fY); | 66 sprintf_s(kBuffer, "<%0.2f, %0.2f>\n", fX, fY); |
64 OutputDebugStringA(kBuffer); | 67 OutputDebugStringA(kBuffer); |
65 */ | 68 */ |
66 | 69 |
67 pCursor->SetPosition(fX, fY); | 70 pCursor->SetPosition(fMouseX, fMouseY); |
68 pCursor->Update(fElapsed); | 71 pCursor->Update(fElapsed); |
69 } | 72 } |
70 | 73 |
71 if(pInputManager->IsButtonDown(MouseButton_Left) && !pInputManager->WasButtonDown(MouseButton_Left)) | 74 GuiElement* pElement = Pick(fMouseX, fMouseY); |
75 | |
76 if(fMouseDeltaX != 0.0f || fMouseDeltaY != 0.0f) | |
72 { | 77 { |
73 GuiElement* pElement = Pick(fX, fY); | 78 //Mouse moved |
74 if(pElement) | 79 if(pCaptureElement) |
75 { | 80 { |
76 pElement->OnMouseDown(MouseButton_Left, fX, fY); | |
77 | 81 |
78 //TODO: pElement could also be the source of a drag operation | |
79 } | 82 } |
80 } | 83 } |
81 else | |
82 | 84 |
83 if(!pInputManager->IsButtonDown(MouseButton_Left) && pInputManager->WasButtonDown(MouseButton_Left)) | 85 for(uint32 nButton = MouseButton_Left; nButton < MouseButton_Count; ++nButton) |
84 { | 86 { |
85 GuiElement* pElement = Pick(fX, fY); | 87 // button down |
86 if(pElement) | 88 if(pInputManager->IsButtonDown(nButton) && !pInputManager->WasButtonDown(nButton)) |
87 { | 89 { |
88 GuiElement* pContainer = pElement; | 90 if(pCaptureElement) |
89 | |
90 if(pDragSource) | |
91 { | 91 { |
92 while(pContainer && !pElement->AllowDrop()) | 92 //TODO: Does capture make sense for mouse down events? |
93 { | 93 pElement->OnMouseDown(nButton, fMouseX, fMouseY); |
94 pContainer = pContainer->GetContainer(); | |
95 } | |
96 | |
97 if(pContainer) | |
98 { | |
99 pContainer->OnDrop(pDragSource, fX, fY); | |
100 } | |
101 } | 94 } |
102 else | 95 else |
103 { | 96 { |
104 pElement->OnMouseUp(MouseButton_Left, fX, fY); | 97 if(pElement) |
98 { | |
99 pElement->OnMouseDown(nButton, fMouseX, fMouseY); | |
100 } | |
105 } | 101 } |
102 } | |
103 else | |
106 | 104 |
107 pDragSource = NULL; | 105 // button up |
106 if(!pInputManager->IsButtonDown(nButton) && pInputManager->WasButtonDown(nButton)) | |
107 { | |
108 if(pDragElement) | |
109 { | |
110 GuiElement* pElement = Pick(fMouseX, fMouseY); | |
111 if(pElement) | |
112 { | |
113 pElement->OnDrop(pDragElement, fMouseX, fMouseY); | |
114 } | |
115 | |
116 pDragElement = NULL; | |
117 } | |
118 else | |
119 { | |
120 if(pCaptureElement) | |
121 { | |
122 pCaptureElement->OnMouseUp(nButton, fMouseX, fMouseY); | |
123 } | |
124 else | |
125 { | |
126 GuiElement* pElement = Pick(fMouseX, fMouseY); | |
127 if(pElement) | |
128 { | |
129 pElement->OnMouseUp(nButton, fMouseX, fMouseY); | |
130 } | |
131 } | |
132 } | |
108 } | 133 } |
109 } | 134 } |
110 } | 135 } |
111 | 136 |
112 /* | 137 /* |
123 GuiElement::Render(kContext, kCamera); | 148 GuiElement::Render(kContext, kCamera); |
124 | 149 |
125 if(pCursor) | 150 if(pCursor) |
126 { | 151 { |
127 pCursor->Render(kContext, kCamera); | 152 pCursor->Render(kContext, kCamera); |
153 | |
154 if(pDragElement) | |
155 { | |
156 //TODO: Move to cursor position | |
157 //pDragElement->Render(kContext, kCamera); | |
158 } | |
128 } | 159 } |
129 } | 160 } |
130 | 161 |
131 //TODO: End batch | 162 //TODO: End batch |
132 //kContext.EndBatch() | 163 //kContext.EndBatch() |
133 } | 164 } |
165 | |
166 /* | |
167 * AcquireCursor | |
168 */ | |
169 ErrorCode GuiInterface::AcquireCursor(GuiElement* pSource) | |
170 { | |
171 if(!pCaptureElement) | |
172 { | |
173 return pCaptureElement = pSource, Error_Success; | |
174 } | |
175 | |
176 return Error_Fail; | |
177 } | |
178 | |
179 /* | |
180 * ReleaseCursor | |
181 */ | |
182 void GuiInterface::ReleaseCursor() | |
183 { | |
184 pCaptureElement = NULL; | |
185 } | |
186 | |
187 /* | |
188 * BeginDrag | |
189 */ | |
190 void GuiInterface::BeginDrag(GuiElement* pSource) | |
191 { | |
192 } | |
193 | |
194 /* | |
195 * EndDrag | |
196 */ | |
197 void GuiInterface::EndDrag() | |
198 { | |
199 } |