public void startGuiControlDrag(string className) { GuiCanvas Canvas = "Canvas"; // Create a new control of the given class. GuiControl payload = Util.eval("return new " + className + "();"); if (!payload.isObject()) { return; } // this offset puts the cursor in the middle of the dragged object. int xOffset = Util.getWord(payload.extent.AsString(), 0).AsInt() / 2; int yOffset = Util.getWord(payload.extent.AsString(), 1).AsInt() / 2; // position where the drag will start, to prevent visible jumping. Point2I cursorpos = Canvas.getCursorPos(); int xPos = Util.getWord(cursorpos.AsString(), 0).AsInt() - xOffset; int yPos = Util.getWord(cursorpos.AsString(), 1).AsInt() - yOffset; // Create drag&drop control. ObjectCreator oc = new ObjectCreator("GuiDragAndDropControl"); oc["canSaveDynamicFields"] = "0"; oc["Profile"] = "ToolsGuiSolidDefaultProfile"; oc["HorizSizing"] = "right"; oc["VertSizing"] = "bottom"; oc["Position"] = xPos + ' ' + yPos; oc["extent"] = payload.extent; oc["MinExtent"] = "32 32"; oc["canSave"] = "1"; oc["Visible"] = "1"; oc["hovertime"] = "1000"; oc["deleteOnMouseUp"] = true; oc["class"] = "GuiDragAndDropControlType_GuiControl"; GuiDragAndDropControl dragCtrl = oc.Create(); dragCtrl.add(payload); ((SimSet)Canvas.getContent()).add(dragCtrl); // Start drag. dragCtrl.startDragging(xOffset, yOffset); }
public override void onMouseDragged() { GuiCanvas canvas = "canvas"; ObjectCreator oc = new ObjectCreator("GuiControl"); oc["profile"] = "GuiCreatorIconButtonProfile"; oc["position"] = "0 0"; oc["extent"] = this.extent.x + " 5"; oc["dragSourceControl"] = this; GuiControl payload = oc.Create(); int xOffset = payload.extent.x / 2; int yOffset = payload.extent.y / 2; Point2I cursorPos = canvas.getCursorPos(); int xPos = cursorPos.x - xOffset; int yPos = cursorPos.y - yOffset; // Create the drag control. oc = new ObjectCreator("GuiDragAndDropControl"); oc["canSaveDynamicFields"] = "0"; oc["Profile"] = "EPainterDragDropProfile"; oc["HorizSizing"] = "right"; oc["VertSizing"] = "bottom"; oc["Position"] = xPos + " " + yPos; oc["extent"] = payload.extent; oc["MinExtent"] = "4 4"; oc["canSave"] = "1"; oc["Visible"] = "1"; oc["hovertime"] = "1000"; oc["deleteOnMouseUp"] = true; GuiDragAndDropControl ctrl = oc.Create(); ctrl.add(payload); ((GuiControl)canvas.getContent()).add(ctrl); ctrl.startDragging(xOffset, yOffset); }