summaryrefslogtreecommitdiff
path: root/vec2ddes.bmx
diff options
context:
space:
mode:
authorIan C <ianc@noddybox.co.uk>2005-10-19 15:08:28 +0000
committerIan C <ianc@noddybox.co.uk>2005-10-19 15:08:28 +0000
commitaf2e25560a9b1027c14bf3636992e12d3ce210ed (patch)
tree87517c6d7978d3b32e5336195e92c55926957683 /vec2ddes.bmx
parent8c12683f42e97251f9b8005e71e0446192ef12ac (diff)
Improved editor
Diffstat (limited to 'vec2ddes.bmx')
-rw-r--r--vec2ddes.bmx209
1 files changed, 146 insertions, 63 deletions
diff --git a/vec2ddes.bmx b/vec2ddes.bmx
index 2782d93..a63cd75 100644
--- a/vec2ddes.bmx
+++ b/vec2ddes.bmx
@@ -176,7 +176,7 @@ Type TDesLine Extends TDesObj
EndIf
SetColor(r,g,b)
- DrawLine(p1.x*scale,p1.y*scale,p2.x*scale,p2.y*scale)
+ DrawLine(p1.lx()*scale,p1.ly()*scale,p2.lx()*scale,p2.ly()*scale)
End Method
Method DrawSelect()
@@ -236,6 +236,8 @@ End Type
Type TDesPoint Extends TDesObj
Field x:Int
Field y:Int
+ Field dx:Double
+ Field dy:Double
Function Create:TDesObj(x:Int, y:Int)
Local o:TDesPoint=New TDesPoint
@@ -265,11 +267,11 @@ Type TDesPoint Extends TDesObj
Method Draw(normals:Int)
SetColor(255,255,255)
- DrawRect(x*scale-1,y*scale-1,3,3)
+ DrawRect(lx()*scale-1,ly()*scale-1,3,3)
End Method
Method DrawSelect()
- DrawSelBox(x,y)
+ DrawSelBox(lx(),ly())
End Method
Method MouseOver:Int(x:Int, y:Int)
@@ -284,6 +286,18 @@ Type TDesPoint Extends TDesObj
EndIf
End Method
+ Method DragDelta(x:Double, y:Double)
+ dx=x
+ dy=y
+ End Method
+
+ Method CompleteDragDelta()
+ x=lx()
+ y=ly()
+ dx=0
+ dy=0
+ End Method
+
Method Edit()
End Method
@@ -295,6 +309,14 @@ Type TDesPoint Extends TDesObj
x=CalcSnap(x)
y=CalcSnap(y)
End Method
+
+ Method lx:Int()
+ Return x+dx
+ End Method
+
+ Method ly:Int()
+ Return y+dy
+ End Method
End Type
' **** Globals
@@ -433,11 +455,18 @@ Function DoDesigner()
Const DOT_TO_DOT_SNAP_MODE:Int=3
Const LINE_TO_LINE_MODE:Int=4
+ Const DRAG_NONE:Int=0
+ Const DRAG_SINGLE:Int=1
+ Const DRAG_MULTI:Int=2
+
Local sel:TDesObj=Null
- Local drag:Int=False
- Local sel1:TDesObj=Null
+ Local drag:Int=DRAG_NONE
+ Local sellist:TList=CreateList()
Local mode:Int=NORMAL_MODE
+ Local dragx:Double
+ Local dragy:Double
+
While Not Designer.done
Cls
@@ -479,7 +508,7 @@ Function DoDesigner()
Local x:Int=(MouseX()-GraphicsWidth()/2)
Local y:Int=(MouseY()-GraphicsHeight()/2)
- If Not drag
+ If drag=DRAG_NONE
sel=Null
EndIf
@@ -493,116 +522,170 @@ Function DoDesigner()
If sel<>Null
sel.SetInfo(Designer.info)
- sel.DrawSelect()
Select mode
Case LINE_MODE
If IsPoint(sel)
- If sel1=Null
- sel1=sel
+ If sellist.Count()=0
+ sellist.AddLast(sel)
Else
- If sel1<>sel
+ If sel<>sellist.ValueAtIndex(0)
mode=NORMAL_MODE
- Designer.obj.AddLast(TDesLine.Create(TDesPoint(sel1),TDesPoint(sel)))
+ Designer.obj.AddLast(TDesLine.Create(TDesPoint(sellist.ValueAtIndex(0)),TDesPoint(sel)))
+ sellist.Clear()
EndIf
EndIf
EndIf
Case LINE_TO_LINE_MODE
If IsPoint(sel)
- If sel1=Null
- sel1=sel
+ If sellist.Count()=0
+ sellist.AddLast(sel)
Else
- If sel1<>sel
- Designer.obj.AddLast(TDesLine.Create(TDesPoint(sel1),TDesPoint(sel)))
- sel1=sel
+ If sel<>sellist.ValueAtIndex(0)
+ Designer.obj.AddLast(TDesLine.Create(TDesPoint(sellist.ValueAtIndex(0)),TDesPoint(sel)))
+ sellist.Clear()
EndIf
EndIf
EndIf
+ Case NORMAL_MODE
+ If KeyDown(KEY_LSHIFT) Or KeyDown(KEY_RSHIFT)
+ If IsPoint(sel) And Not sellist.Contains(sel)
+ sellist.AddLast(sel)
+ EndIf
+ Else
+ sellist.Clear()
+ sellist.AddLast(sel)
+ EndIf
End Select
+ Else
+ If Not KeyDown(KEY_LSHIFT) And Not KeyDown(KEY_RSHIFT)
+ sellist.Clear()
+ EndIf
EndIf
- If drag
+
+ For Local o:TDesObj=EachIn sellist
+ o.DrawSelect()
+ Next
+
+ If drag=DRAG_SINGLE
sel.Drag(x/scale,y/scale,True)
+ ElseIf drag=DRAG_MULTI
+ For Local o:TDesPoint=EachIn sellist
+ o.DragDelta((x-dragx)/scale,(y-dragy)/scale)
+ Next
EndIf
SetOrigin(0,0)
'
' **** END CENTRED
- If Not drag And mode=NORMAL_MODE
+ If drag=DRAG_NONE And mode=NORMAL_MODE
Designer.gui.EventLoop()
EndIf
If mode=NORMAL_MODE And KeyHit(KEY_MOUSERIGHT)
- If sel<>Null
- If IsPoint(sel)
- Select GUIMenu("Point Menu",["Snap to grid","Delete"],MouseX(),MouseY(),pointer)
- Case 0
- sel.Snap()
- Case 1
- Designer.obj.Remove(sel)
+ If sellist.Count()>0
+ Select GUIMenu("Point Menu",["Snap to grid","Delete"],MouseX(),MouseY(),pointer)
+ Case 0
+ For Local o:TDesPoint=EachIn sellist
+ o.Snap()
+ Next
+ sellist.Clear()
+ Case 1
+ For Local o:TDesPoint=EachIn sellist
+ Designer.obj.Remove(o)
For Local d:TDesLine=EachIn Designer.obj
- If d<>Null And (d.p1=sel Or d.p2=sel)
+ If d<>Null And (d.p1=o Or d.p2=o)
Designer.obj.Remove(d)
EndIf
Next
- End Select
+ Next
+ sellist.Clear()
+ EndSelect
+ Else
+ If sel<>Null
+ If IsPoint(sel)
+ Select GUIMenu("Point Menu",["Snap to grid","Delete"],MouseX(),MouseY(),pointer)
+ Case 0
+ sel.Snap()
+ Case 1
+ Designer.obj.Remove(sel)
+
+ For Local d:TDesLine=EachIn Designer.obj
+ If d<>Null And (d.p1=sel Or d.p2=sel)
+ Designer.obj.Remove(d)
+ EndIf
+ Next
+ End Select
+ Else
+ Local l:TDesLine=TDesLine(sel)
+ Select GUIMenu("Line Menu",["Edit","Snap to grid","Flip","Delete"],MouseX(),MouseY(),pointer)
+ Case 0
+ l.Edit()
+ Case 1
+ l.Snap()
+ Case 2
+ l.FlipNormal()
+ Case 3
+ Designer.obj.Remove(l)
+ End Select
+ EndIf
Else
- Local l:TDesLine=TDesLine(sel)
- Select GUIMenu("Line Menu",["Edit","Snap to grid","Flip","Delete"],MouseX(),MouseY(),pointer)
+ Select GUIMenu("Create Menu",["Create Point","Create Line","Create Points","Create Points (Snapped)","Create Lines"],MouseX(),MouseY(),pointer)
Case 0
- l.Edit()
+ Designer.obj.AddLast(TDesPoint.Create(x/scale,y/scale))
Case 1
- l.Snap()
+ sellist.Clear()
+ sel=Null
+ mode=LINE_MODE
Case 2
- l.FlipNormal()
+ sellist.Clear()
+ sel=Null
+ mode=DOT_TO_DOT_MODE
Case 3
- Designer.obj.Remove(l)
+ sellist.Clear()
+ sel=Null
+ mode=DOT_TO_DOT_SNAP_MODE
+ Case 4
+ sellist.Clear()
+ sel=Null
+ mode=LINE_TO_LINE_MODE
End Select
- EndIf
- Else
- Select GUIMenu("Create Menu",["Create Point","Create Line","Create Points","Create Points (Snapped)","Create Lines"],MouseX(),MouseY(),pointer)
- Case 0
- Designer.obj.AddLast(TDesPoint.Create(x/scale,y/scale))
- Case 1
- sel1=Null
- sel=Null
- mode=LINE_MODE
- Case 2
- sel1=Null
- sel=Null
- mode=DOT_TO_DOT_MODE
- Case 3
- sel1=Null
- sel=Null
- mode=DOT_TO_DOT_SNAP_MODE
- Case 4
- sel1=Null
- sel=Null
- mode=LINE_TO_LINE_MODE
- End Select
+ EndIf
+ sel=Null
EndIf
- sel=Null
EndIf
SetColor(255,255,255)
Select mode
Case NORMAL_MODE
- If Not drag
- If KeyDown(KEY_MOUSELEFT) And sel<>Null
- mode=NORMAL_MODE
- drag=True
+ If drag=DRAG_NONE
+ If KeyDown(KEY_MOUSELEFT)
+ If sel<>Null And Not KeyDown(KEY_LSHIFT) And Not KeyDown(KEY_RSHIFT)
+ drag=DRAG_SINGLE
+ ElseIf (KeyDown(KEY_LSHIFT) Or KeyDown(KEY_RSHIFT)) And sellist.Count()>0
+ drag=DRAG_MULTI
+ dragx=x
+ dragy=y
+ EndIf
EndIf
Else
If Not KeyDown(KEY_MOUSELEFT)
- drag=False
+ If drag=DRAG_MULTI
+ For Local o:TDesPoint=EachIn sellist
+ o.CompleteDragDelta()
+ Next
+ EndIf
+
+ drag=DRAG_NONE
EndIf
EndIf
Case LINE_MODE
- If Not sel1
+ If sellist.Count()=0
Tip("Move to first point")
Else
Tip("Move to second point")
@@ -624,7 +707,7 @@ Function DoDesigner()
EndIf
Case LINE_TO_LINE_MODE
- If Not sel1
+ If sellist.Count()=0
Tip("Move to first point")
Else
Tip("Move to next point")