comparison 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
comparison
equal deleted inserted replaced
25:eae13b04b06f 26:3a63df04f3c0
69 69
70 pCursor->SetPosition(fMouseX, fMouseY); 70 pCursor->SetPosition(fMouseX, fMouseY);
71 pCursor->Update(fElapsed); 71 pCursor->Update(fElapsed);
72 } 72 }
73 73
74 GuiElement* pElement = Pick(fMouseX, fMouseY); 74 if(pDragElement)
75 75 {
76 if(fMouseDeltaX != 0.0f || fMouseDeltaY != 0.0f) 76 if(pInputManager->IsButtonReleased(nDragButton))
77 { 77 {
78 //Mouse moved 78 EndDrag(Pick(fMouseX, fMouseY), fMouseX, fMouseY);
79 if(pCaptureElement) 79 }
80 { 80 else
81 81 {
82 } 82 for(uint32 nButton = MouseButton_Left; nButton < MouseButton_Count; ++nButton)
83 } 83 {
84 84 if(pInputManager->IsButtonPressed(nButton) || pInputManager->IsButtonReleased(nButton))
85 for(uint32 nButton = MouseButton_Left; nButton < MouseButton_Count; ++nButton) 85 {
86 { 86 EndDrag(NULL, fMouseX, fMouseY);
87 // button down 87 }
88 if(pInputManager->IsButtonDown(nButton) && !pInputManager->WasButtonDown(nButton)) 88 }
89 }
90 }
91 else
92 {
93 GuiElement* pElement = Pick(fMouseX, fMouseY);
94
95 if(pFocusElement != pElement)
96 {
97 if(!pCaptureElement)
98 {
99 if(pFocusElement)
100 {
101 pFocusElement->OnMouseLeave();
102 }
103
104 if(pElement)
105 {
106 pElement->OnMouseEnter();
107 }
108 }
109
110 pFocusElement = pElement;
111 }
112
113 for(uint32 nButton = MouseButton_Left; nButton < MouseButton_Count; ++nButton)
114 {
115 // button down
116 if(pInputManager->IsButtonPressed(nButton))
117 {
118 if(pCaptureElement)
119 {
120 pElement->OnMouseDown(nButton, fMouseX, fMouseY);
121 }
122 else
123
124 if(pElement)
125 {
126 pElement->OnMouseDown(nButton, fMouseX, fMouseY);
127 }
128 }
129 else
130
131 // button up
132 if(pInputManager->IsButtonReleased(nButton))
133 {
134 if(pCaptureElement)
135 {
136 pCaptureElement->OnMouseUp(nButton, fMouseX, fMouseY);
137 }
138 else
139
140 if(pElement)
141 {
142 pElement->OnMouseUp(nButton, fMouseX, fMouseY);
143 }
144 }
145 }
146
147 // mouse moved
148 if(fDeltaX != 0.0f || fDeltaY != 0.0f)
149 //if(pInputManager->MouseMoved())
89 { 150 {
90 if(pCaptureElement) 151 if(pCaptureElement)
91 { 152 {
92 //TODO: Does capture make sense for mouse down events? 153 pCaptureElement->OnMouseMove(fMouseX, fMouseY);
93 pElement->OnMouseDown(nButton, fMouseX, fMouseY);
94 } 154 }
95 else 155 else
96 { 156
97 if(pElement) 157 if(pElement)
98 { 158 {
99 pElement->OnMouseDown(nButton, fMouseX, fMouseY); 159 pElement->OnMouseMove(fMouseX, fMouseY);
100 }
101 }
102 }
103 else
104
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 } 160 }
133 } 161 }
134 } 162 }
135 } 163 }
136 164
140 void GuiInterface::Render(RenderContext& kContext, Camera& kCamera) 168 void GuiInterface::Render(RenderContext& kContext, Camera& kCamera)
141 { 169 {
142 //TODO: Begin batch 170 //TODO: Begin batch
143 //kContext.BeginBatch(); 171 //kContext.BeginBatch();
144 172
145 if(bVisible) 173 if(nFlags & GuiElementFlag_Visible)
146 { 174 {
147 //TODO: Inside Render functions call kContext.AddToBatch(pTexture, kPosition, kDimensions, kColor) 175 //TODO: Inside Render functions call kContext.AddToBatch(pTexture, kPosition, kDimensions, kColor)
148 GuiElement::Render(kContext, kCamera); 176 GuiElement::Render(kContext, kCamera);
149 177
150 if(pCursor) 178 if(pCursor)
183 { 211 {
184 pCaptureElement = NULL; 212 pCaptureElement = NULL;
185 } 213 }
186 214
187 /* 215 /*
216 * IsCursorAcquiredBy
217 */
218 bool GuiInterface::IsCursorAcquiredBy(GuiElement* pElement) const
219 {
220 return pDragElement == pElement;
221 }
222
223 /*
188 * BeginDrag 224 * BeginDrag
189 */ 225 */
190 void GuiInterface::BeginDrag(GuiElement* pSource) 226 void GuiInterface::BeginDrag(GuiElement* pSource, uint32 nButton)
191 { 227 {
228 //ASSERT(pDragElement == NULL);
229
230 pDragElement = pSource;
231 nDragButton = nButton;
192 } 232 }
193 233
194 /* 234 /*
195 * EndDrag 235 * EndDrag
196 */ 236 */
197 void GuiInterface::EndDrag() 237 void GuiInterface::EndDrag(GuiElement* pTarget, float fX, float fY)
198 { 238 {
199 } 239 if(pTarget)
240 {
241 pTarget->OnDrop(pDragElement, fX, fY);
242 }
243
244 pDragElement = NULL;
245 }