Basic code to allow you to add draggable interface elements to your project. Any interface element with the isDragEl variable set to true like in the code below will be able to be dragged around the screen.
Interface
DraggableElement
isDragEl = true
The code to add to your project to let you do this is shown below.
Interface
onMouseDown(pClient, pX, pY, pButton)
if (this.isDragEl && pButton === 1)
pClient.isDragEl = {'el': this, 'xOff': pX, 'yOff': pY}
Client
onMouseMove(pD, pX, pY)
if (this.isDragEl)
this.isDragEl.el.setPos(pX - this.isDragEl.xOff, pY - this.isDragEl.yOff)
onMouseUp(pD, pX, pY, pButton)
if (this.isDragEl && pButton === 1)
this.isDragEl = null
This code is very basic and used at the highest level of inheritance so that it is universally usable. There will always be room for improvement on a per project basis, so improve on it when and where you can.
Interface DraggableElement isDragEl = true
The code to add to your project to let you do this is shown below.
Interface onMouseDown(pClient, pX, pY, pButton) if (this.isDragEl && pButton === 1) pClient.isDragEl = {'el': this, 'xOff': pX, 'yOff': pY} Client onMouseMove(pD, pX, pY) if (this.isDragEl) this.isDragEl.el.setPos(pX - this.isDragEl.xOff, pY - this.isDragEl.yOff) onMouseUp(pD, pX, pY, pButton) if (this.isDragEl && pButton === 1) this.isDragEl = null
This code is very basic and used at the highest level of inheritance so that it is universally usable. There will always be room for improvement on a per project basis, so improve on it when and where you can.