From b623f5953691b2a0614e6f1f4def86bdbb9a4113 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Frings-F=C3=BCrst?= Date: Sat, 8 Aug 2020 11:53:00 +0200 Subject: New upstream version 5.2.0Beta2.1 --- app/bin/cstraigh.c | 77 ++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 55 insertions(+), 22 deletions(-) (limited to 'app/bin/cstraigh.c') diff --git a/app/bin/cstraigh.c b/app/bin/cstraigh.c index 7be25ee..464f16e 100644 --- a/app/bin/cstraigh.c +++ b/app/bin/cstraigh.c @@ -29,6 +29,7 @@ #include "param.h" #include "track.h" #include "utility.h" +#include "layout.h" /* * STATE INFO @@ -40,6 +41,23 @@ static struct { BOOL_T down; } Dl; +static dynArr_t anchors_da; +#define anchors(N) DYNARR_N(trkSeg_t,anchors_da,N) + +static void CreateEndAnchor(coOrd p, wBool_t lock) { + DIST_T d = tempD.scale*0.15; + + DYNARR_APPEND(trkSeg_t,anchors_da,1); + int i = anchors_da.cnt-1; + anchors(i).type = lock?SEG_FILCRCL:SEG_CRVLIN; + anchors(i).color = wDrawColorBlue; + anchors(i).u.c.center = p; + anchors(i).u.c.radius = d/2; + anchors(i).u.c.a0 = 0.0; + anchors(i).u.c.a1 = 360.0; + anchors(i).width = 0; +} + static STATUS_T CmdStraight( wAction_t action, coOrd pos ) { @@ -47,40 +65,37 @@ static STATUS_T CmdStraight( wAction_t action, coOrd pos ) DIST_T dist; coOrd p; - switch (action) { + switch (action&0xFF) { case C_START: + DYNARR_RESET(trkSeg_t,anchors_da); Dl.pos0=pos; Dl.pos1=pos; Dl.trk = NULL; Dl.ep=-1; Dl.down = FALSE; - InfoMessage( _("Place 1st end point of straight track + Shift -> snap to unconnected endpoint") ); + InfoMessage( _("Place 1st endpoint of straight track, snap to unconnected endpoint") ); return C_CONTINUE; case C_DOWN: + DYNARR_RESET(trkSeg_t,anchors_da); p = pos; BOOL_T found = FALSE; Dl.trk = NULL; - if ((MyGetKeyState() & WKEY_SHIFT) != 0) { + if (((MyGetKeyState() & WKEY_ALT) == 0) == magneticSnap) { if ((t = OnTrack(&p, FALSE, TRUE)) != NULL) { EPINX_T ep = PickUnconnectedEndPointSilent(p, t); if (ep != -1) { + if (GetTrkGauge(t) != GetScaleTrackGauge(GetLayoutCurScale())) { + wBeep(); + InfoMessage(_("Track is different gauge")); + return C_CONTINUE; + } Dl.trk = t; Dl.ep = ep; pos = GetTrkEndPos(t, ep); found = TRUE; - } else { - InfoMessage(_("No unconnected end-point on track - Try again or release Shift and click")); - Dl.pos0=pos; - Dl.pos1=pos; - return C_CONTINUE; } - } else { - InfoMessage(_("Not on a track - Try again or release Shift and click")); - Dl.pos0=pos; - Dl.pos1=pos; - return C_CONTINUE; } } Dl.down = TRUE; @@ -96,10 +111,25 @@ static STATUS_T CmdStraight( wAction_t action, coOrd pos ) return C_CONTINUE; case C_MOVE: - if (!Dl.down) return C_CONTINUE; - DrawSegs( &tempD, zero, 0.0, &tempSegs(0), tempSegs_da.cnt, trackGauge, wDrawColorBlack ); + case wActionMove: + DYNARR_RESET(trkSeg_t,anchors_da); + if (!Dl.down) { + if (((MyGetKeyState() & WKEY_ALT) == 0) == magneticSnap) { + p = pos; + if ((t = OnTrack(&p, FALSE, TRUE)) != NULL) { + if (GetTrkGauge(t) == GetScaleTrackGauge(GetLayoutCurScale())) { + EPINX_T ep = PickUnconnectedEndPointSilent(pos, t); + if (ep != -1) { + if (GetTrkGauge(t) == GetScaleTrackGauge(GetLayoutCurScale())) + CreateEndAnchor(GetTrkEndPos(t,ep),FALSE); + } + } + } + } + return C_CONTINUE; + } ANGLE_T angle, angle2; - if (Dl.trk) { + if (Dl.trk && !(MyGetKeyState() & WKEY_SHIFT)) { angle = NormalizeAngle(GetTrkEndAngle( Dl.trk, Dl.ep)); angle2 = NormalizeAngle(FindAngle(pos, Dl.pos0)-angle); if (angle2 > 90.0 && angle2 < 270.0) @@ -112,14 +142,13 @@ static STATUS_T CmdStraight( wAction_t action, coOrd pos ) PutAngle(FindAngle( Dl.pos0, pos )) ); tempSegs(0).u.l.pos[1] = pos; tempSegs_da.cnt = 1; - DrawSegs( &tempD, zero, 0.0, &tempSegs(0), tempSegs_da.cnt, trackGauge, wDrawColorBlack ); return C_CONTINUE; case C_UP: + DYNARR_RESET(trkSeg_t,anchors_da); if (!Dl.down) return C_CONTINUE; - DrawSegs( &tempD, zero, 0.0, &tempSegs(0), tempSegs_da.cnt, trackGauge, wDrawColorBlack ); tempSegs_da.cnt = 0; - if (Dl.trk) { + if (Dl.trk && !(MyGetKeyState() & WKEY_SHIFT)) { angle = NormalizeAngle(GetTrkEndAngle( Dl.trk, Dl.ep)); angle2 = NormalizeAngle(FindAngle(pos, Dl.pos0)-angle); if (angle2 > 90.0 && angle2 < 270.0) @@ -132,7 +161,7 @@ static STATUS_T CmdStraight( wAction_t action, coOrd pos ) } UndoStart( _("Create Straight Track"), "newStraight" ); t = NewStraightTrack( Dl.pos0, pos ); - if (Dl.trk) { + if (Dl.trk && !(MyGetKeyState() & WKEY_SHIFT)) { ConnectTracks(Dl.trk, Dl.ep, t, 0); } UndoEnd(); @@ -140,8 +169,12 @@ static STATUS_T CmdStraight( wAction_t action, coOrd pos ) return C_TERMINATE; case C_REDRAW: + if (anchors_da.cnt) + DrawSegs( &tempD, zero, 0.0, &anchors(0), anchors_da.cnt, trackGauge, wDrawColorBlack ); + if (Dl.down) + DrawSegs( &tempD, zero, 0.0, &tempSegs(0), tempSegs_da.cnt, trackGauge, wDrawColorBlack ); + return C_CONTINUE; case C_CANCEL: - DrawSegs( &tempD, zero, 0.0, &tempSegs(0), tempSegs_da.cnt, trackGauge, wDrawColorBlack ); Dl.down = FALSE; return C_CONTINUE; @@ -155,5 +188,5 @@ static STATUS_T CmdStraight( wAction_t action, coOrd pos ) void InitCmdStraight( wMenu_p menu ) { - AddMenuButton( menu, CmdStraight, "cmdStraight", _("Straight Track"), wIconCreatePixMap(straight_xpm), LEVEL0_50, IC_STICKY|IC_POPUP2, ACCL_STRAIGHT, NULL ); + AddMenuButton( menu, CmdStraight, "cmdStraight", _("Straight Track"), wIconCreatePixMap(straight_xpm), LEVEL0_50, IC_STICKY|IC_POPUP2|IC_WANT_MOVE, ACCL_STRAIGHT, NULL ); } -- cgit v1.2.3