7 [
Attribute(defvalue:
"1", uiwidget: UIWidgets.CheckBox,
desc:
"Allows the widget to be dragged")]
10 [
Attribute(defvalue:
"0", uiwidget: UIWidgets.CheckBox,
desc:
"Allows to drag widget further off screen then default: half the size of the widget")]
11 bool m_bCanDragOffScreen;
13 [
Attribute(defvalue:
"0", uiwidget: UIWidgets.CheckBox,
desc:
"Allows the widget to be rotated")]
16 [
Attribute(defvalue:
"0", uiwidget: UIWidgets.CheckBox,
desc:
"Allows the widget to be activated")]
25 static bool s_bIsDragging =
false;
26 static bool s_bIsRotating =
false;
27 static bool s_bCanDragOffScreen =
false;
28 static float s_fDragTime;
30 static protected ref ScriptInvoker<Widget> s_OnDragWidget =
new ScriptInvoker();
31 static protected ref ScriptInvokerBase<ScriptInvokerWidgetBool> s_OnDragEnd =
new ScriptInvokerBase<ScriptInvokerWidgetBool>();
32 static protected ref ScriptInvoker<Widget> s_OnActivateTool =
new ScriptInvoker();
34 static protected Widget s_DraggedWidget;
35 static protected Widget s_RotatedWidget;
43 static ScriptInvoker GetOnDragWidgetInvoker()
45 return s_OnDragWidget;
50 static ScriptInvokerBase<ScriptInvokerWidgetBool> GetOnDragEndInvoker()
57 static ScriptInvoker GetOnActivateToolInvoker()
59 return s_OnActivateTool;
69 if (!CanBeManipulated(widgets))
72 foreach ( Widget widget : widgets )
75 if (!moveComp || !moveComp.m_bCanActivate)
78 s_OnActivateTool.Invoke(widget);
86 static bool StartDrag()
96 if (!CanBeManipulated(widgets))
99 foreach ( Widget widget : widgets )
104 if (!moveComp.m_bCanDrag)
107 s_DraggedWidget = widget;
108 s_bCanDragOffScreen = moveComp.m_bCanDragOffScreen;
115 s_bIsDragging =
true;
116 s_OnDragWidget.Invoke(s_DraggedWidget);
129 static bool StartRotate()
134 if (!CanBeManipulated(widgets))
137 foreach ( Widget widget : widgets )
142 if (!moveComp.m_bCanRotate)
145 s_RotatedWidget = widget;
152 s_bIsRotating =
true;
163 static bool CanBeManipulated(array<Widget> tracedWidgets)
165 foreach ( Widget widget : tracedWidgets )
167 if (ButtonWidget.Cast(widget))
176 static void EndDrag()
178 s_bIsDragging =
false;
181 s_DraggedWidget =
null;
182 s_OnDragWidget.Invoke(
null,
false);
189 static void EndRotate()
191 s_bIsRotating =
false;
192 s_RotatedWidget =
null;
201 int screenX =
GetGame().GetWorkspace().GetWidth();
202 int screenY =
GetGame().GetWorkspace().GetHeight();
204 float widgetX, widgetY, fx, fy, minX, minY, maxX, maxY;
207 fx = cursorInfo.x - cursorInfo.lastX;
208 fy = cursorInfo.y - cursorInfo.lastY;
211 if (fx == 0 && fy == 0)
215 vector pos = FrameSlot.GetPos(widget);
220 widget.GetScreenSize(widgetX, widgetY);
222 if (!s_bCanDragOffScreen)
225 WorkspaceWidget workspace =
GetGame().GetWorkspace();
226 minX = workspace.DPIUnscale(-widgetX/2);
227 minY = workspace.DPIUnscale(-widgetY/2);
228 maxX = workspace.DPIUnscale(screenX) - workspace.DPIUnscale(widgetX/2);
229 maxY = workspace.DPIUnscale(screenY) - workspace.DPIUnscale(widgetY/2);
232 fx = Math.Clamp(fx, minX, maxX);
233 fy = Math.Clamp(fy, minY, maxY);
237 FrameSlot.SetPos(widget, fx, fy);
246 ImageWidget image = ImageWidget.Cast(widget.GetChildren());
251 float fx, fy, minX, minY, maxX, maxY;
254 fx = cursorInfo.x - cursorInfo.lastX;
255 fy = cursorInfo.y - cursorInfo.lastY;
258 if (fx == 0 && fy == 0)
262 float widgetX, widgetY, widgetH, widgetV, centerX, centerY;
263 widget.GetScreenPos(widgetX, widgetY);
264 widget.GetScreenSize(widgetH, widgetV);
265 centerX = widgetX + widgetH/2;
266 centerY = widgetY + widgetV/2;
269 WorkspaceWidget workspace =
GetGame().GetWorkspace();
270 widgetH = workspace.DPIUnscale(widgetH);
271 centerX = workspace.DPIUnscale(centerX);
272 centerY = workspace.DPIUnscale(centerY);
274 float newAngle = Math.RAD2DEG * Math.Atan2(cursorInfo.x - centerX, cursorInfo.y - centerY);
275 float lastAngle = Math.RAD2DEG * Math.Atan2(cursorInfo.lastX - centerX, cursorInfo.lastY - centerY);
280 vector grip = Vector(cursorInfo.x - centerX, cursorInfo.y - centerY, 0);
281 float rotationScale = 1;
285 rotation *= rotationScale * rotationScale;
288 image.SetRotation(image.GetRotation() -
rotation);
294 super.OnMapOpen(config);
303 s_OnDragWidget.Clear();
305 s_OnActivateTool.Clear();
306 s_DraggedWidget =
null;
307 s_RotatedWidget =
null;
308 s_bIsDragging =
false;
309 s_bIsRotating =
false;
312 super.OnMapClose(config);
321 s_fDragTime += timeSlice;
323 else if (s_bIsRotating)