diff options
-rw-r--r-- | vec2ddes.bmx | 154 |
1 files changed, 113 insertions, 41 deletions
diff --git a/vec2ddes.bmx b/vec2ddes.bmx index d474693..2782d93 100644 --- a/vec2ddes.bmx +++ b/vec2ddes.bmx @@ -55,7 +55,7 @@ Type TDesObj Abstract Method Draw(normals:Int) Abstract Method DrawSelect() Abstract Method MouseOver:Int(x:Int, y:Int) Abstract - Method Drag(x:Int, y:Int) Abstract + Method Drag(x:Int, y:Int, show:Int) Abstract Method Edit() Abstract Method SetInfo(w:TLabel) Abstract Method Snap() Abstract @@ -86,6 +86,10 @@ Type TDesObj Abstract font.Draw(x+","+y,0,0) End Method + Method DrawCoords(x1:Int, y1:Int, x2:Int, y2:Int) + font.Draw(x1+","+y1+" -> "+x2+","+y2,0,0) + End Method + Method DoubleString:String(v:Double) Local s:String=v @@ -183,7 +187,7 @@ Type TDesLine Extends TDesObj Return InSelBox(x,y,CX(),CY()) End Method - Method Drag(x:Int, y:Int) + Method Drag(x:Int, y:Int, show:Int) x:-CX() y:-CY() @@ -192,7 +196,9 @@ Type TDesLine Extends TDesObj p1.y:+y p2.y:+y - DrawCoord(x,y) + If show + DrawCoords(p1.x,p1.y,p2.x,p2.y) + EndIf End Method Method Edit() @@ -270,10 +276,12 @@ Type TDesPoint Extends TDesObj Return InSelBox(x,y,self.x,self.y) End Method - Method Drag(x:Int, y:Int) + Method Drag(x:Int, y:Int, show:Int) self.x=x self.y=y - DrawCoord(x,y) + If show + DrawCoord(x,y) + EndIf End Method Method Edit() @@ -419,10 +427,16 @@ Function DoDesigner() Designer.done=False + Const NORMAL_MODE:Int=0 + Const LINE_MODE:Int=1 + Const DOT_TO_DOT_MODE:Int=2 + Const DOT_TO_DOT_SNAP_MODE:Int=3 + Const LINE_TO_LINE_MODE:Int=4 + Local sel:TDesObj=Null Local drag:Int=False Local sel1:TDesObj=Null - Local make_line:Int=False + Local mode:Int=NORMAL_MODE While Not Designer.done Cls @@ -481,33 +495,45 @@ Function DoDesigner() sel.SetInfo(Designer.info) sel.DrawSelect() - If make_line And IsPoint(sel) - If sel1=Null - sel1=sel - Else - If sel1<>sel - make_line=False - Designer.obj.AddLast(TDesLine.Create(TDesPoint(sel1),TDesPoint(sel))) + Select mode + Case LINE_MODE + If IsPoint(sel) + If sel1=Null + sel1=sel + Else + If sel1<>sel + mode=NORMAL_MODE + Designer.obj.AddLast(TDesLine.Create(TDesPoint(sel1),TDesPoint(sel))) + EndIf + EndIf EndIf - EndIf - EndIf + Case LINE_TO_LINE_MODE + If IsPoint(sel) + If sel1=Null + sel1=sel + Else + If sel1<>sel + Designer.obj.AddLast(TDesLine.Create(TDesPoint(sel1),TDesPoint(sel))) + sel1=sel + EndIf + EndIf + EndIf + End Select EndIf If drag - sel.Drag(x/scale,y/scale) + sel.Drag(x/scale,y/scale,True) EndIf SetOrigin(0,0) ' ' **** END CENTRED - If Not drag + If Not drag And mode=NORMAL_MODE Designer.gui.EventLoop() EndIf - If KeyHit(KEY_MOUSERIGHT) - make_line=False - + 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) @@ -536,39 +562,81 @@ Function DoDesigner() End Select EndIf Else - Select GUIMenu("Create Menu",["Create Point","Create Line"],MouseX(),MouseY(),pointer) + 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 - make_line=True + 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 - If Not drag - If KeyDown(KEY_MOUSELEFT) And sel<>Null - make_line=False - drag=True - EndIf - Else - If Not KeyDown(KEY_MOUSELEFT) - drag=False - EndIf - EndIf - SetColor(255,255,255) - If make_line - If Not sel1 - font.Draw("Move to first point",MouseX()+12,MouseY()+12) - Else - font.Draw("Move to second point",MouseX()+12,MouseY()+12) - EndIf - EndIf + Select mode + Case NORMAL_MODE + If Not drag + If KeyDown(KEY_MOUSELEFT) And sel<>Null + mode=NORMAL_MODE + drag=True + EndIf + Else + If Not KeyDown(KEY_MOUSELEFT) + drag=False + EndIf + EndIf + + Case LINE_MODE + If Not sel1 + Tip("Move to first point") + Else + Tip("Move to second point") + EndIf + Case DOT_TO_DOT_MODE + Tip("Press Button to place") + If KeyHit(KEY_MOUSELEFT) + Local p:TDesPoint=TDesPoint(TDesPoint.Create(x/scale,y/scale)) + Designer.obj.AddLast(p) + EndIf + + Case DOT_TO_DOT_SNAP_MODE + Tip("Press Button to place") + If KeyHit(KEY_MOUSELEFT) + Local p:TDesPoint=TDesPoint(TDesPoint.Create(x/scale,y/scale)) + p.Snap() + Designer.obj.AddLast(p) + EndIf + + Case LINE_TO_LINE_MODE + If Not sel1 + Tip("Move to first point") + Else + Tip("Move to next point") + EndIf + + End Select + + If KeyHit(KEY_ESCAPE) + mode=NORMAL_MODE + FlushKeys() + EndIf + DrawImage(pointer,MouseX(),MouseY()) Flip @@ -576,6 +644,10 @@ Function DoDesigner() Wend End Function +Function Tip(s:String) + font.Draw(s+" [ESC to cancel]",MouseX()+12,MouseY()+12) +End Function + Function IsLine:Int(o:Object) Local p:TDesLine=TDesLine(o) Return p<>Null @@ -624,7 +696,7 @@ Function LoadCallback(w:TWidget) Local fn:String=GUIFileSelect("Select object to load",filename,False,pointer) If fn<>Null - Local o:TVectorGfxObject=TVectorGfxObject.Load(Designer.fname_txt.text) + Local o:TVectorGfxObject=TVectorGfxObject.Load(fn) If o<>Null filename=fn |