diff options
Diffstat (limited to 'app/bin/ccornu.c')
-rw-r--r-- | app/bin/ccornu.c | 102 |
1 files changed, 55 insertions, 47 deletions
diff --git a/app/bin/ccornu.c b/app/bin/ccornu.c index fd51755..f447d64 100644 --- a/app/bin/ccornu.c +++ b/app/bin/ccornu.c @@ -79,18 +79,13 @@ #include "cstraigh.h" #include "drawgeom.h" #include "cjoin.h" -#include "i18n.h" #include "common.h" -#include "utility.h" -#include "math.h" #include "param.h" #include "layout.h" #include "cundo.h" -#include "messages.h" #include "cselect.h" #include "fileio.h" - -#include <stdint.h> +#include "common-ui.h" extern drawCmd_t tempD; extern TRKTYP_T T_BEZIER; @@ -194,7 +189,7 @@ static char * CmdCornuHotBarProc( case HB_SELECT: CmdCornu( C_CANCEL, zero ); curCornu = trkseg; - DoCommandB( (void*)(intptr_t)cornuHotBarCmdInx ); + DoCommandB( I2VP(cornuHotBarCmdInx) ); return NULL; case HB_LISTTITLE: sprintf(message,_("%s FlexTrack"),GetScaleName(GetLayoutCurScale())); @@ -253,7 +248,7 @@ EXPORT void AddHotBarCornu( void ) hotB.txt.u.t.boxed = TRUE; hotB.txt.u.t.string = MyStrdup(_(" FLEX ")); hotB.txt.u.t.fontP = NULL; - hotB.txt.u.t.fontSize = 160.0*ratio; + hotB.txt.u.t.fontSize = 160*mainD.dpi/72.0*ratio; hotB.txt.u.t.angle = 0.0; char * label = MyMalloc(256); @@ -342,7 +337,7 @@ int createEndPoint( endHandle->end_curve = zero; endHandle->end_valid = TRUE; endHandle->mid_disp = 0.0; - DIST_T end_length = 20*trackGauge; + DIST_T end_length = tempD.scale*2.0; Translate(&endHandle->end_curve,pos0,angle,end_length); Translate(&endHandle->end_center,pos0,angle,end_length/2); if (radius>0.0) { @@ -358,7 +353,7 @@ int createEndPoint( Rotate(&cm,endHandle->end_curve,-a ); endHandle->mid_disp = cm.x-endHandle->end_curve.x; curveData_t curveData; - PlotCurve(crvCmdFromCenter,pos0,endHandle->end_center, endHandle->end_curve, &curveData, FALSE); + PlotCurve(crvCmdFromCenter,pos0,endHandle->end_center, endHandle->end_curve, &curveData, FALSE, 0.0); if (curveData.type == curveTypeStraight) { coOrd pos_line[2]; Translate(&pos_line[0],pos0,FindAngle(pos0,endHandle->end_curve)+90,trackGauge/2); @@ -486,7 +481,6 @@ static void CreateCornuEndAnchor(coOrd p, wBool_t lock) { anchors(i).u.c.a0 = 0.0; anchors(i).u.c.a1 = 360.0; anchors(i).width = 0; - } static void CreateCornuExtendAnchor(coOrd p, ANGLE_T a, wBool_t selected) { @@ -992,9 +986,6 @@ track_p CreateCornuFromPoints(coOrd pos[2],BOOL_T track_end[2]) { } -struct extraData { - cornuData_t cornuData; - }; ANGLE_T GetOpenAngle(coOrd pos[2],ANGLE_T angle[2],int moved) { ANGLE_T a = FindAngle(pos[1-moved],pos[moved]); @@ -1017,12 +1008,12 @@ static paramData_t cornuModPLs[] = { #define cornuModEndAnglePD (cornuModPLs[0]) #define cornuModEndAngle 0 - { PD_FLOAT, &cornuModCmdContext.angle, "End Angle", PDO_NORECORD|BO_ENTER, &r0_360, N_("End Angle") }, + { PD_FLOAT, &cornuModCmdContext.angle, "endangle", PDO_NORECORD|BO_ENTER, &r0_360, N_("End Angle") }, #define cornuModEndRadiusPD (cornuModPLs[1]) #define cornuModEndRadius 1 - { PD_FLOAT, &cornuModCmdContext.radius, "End Radius", PDO_DIM|PDO_NORECORD|BO_ENTER, &r10000_10000, N_("End Radius") }, + { PD_FLOAT, &cornuModCmdContext.radius, "endradius", PDO_DIM|PDO_NORECORD|BO_ENTER, &r10000_10000, N_("End Radius") }, }; -static paramGroup_t cornuModPG = { "cornuMod", 0, cornuModPLs, sizeof cornuModPLs/sizeof cornuModPLs[0] }; +static paramGroup_t cornuModPG = { "cornuMod", 0, cornuModPLs, COUNT( cornuModPLs ) }; /* * AdjustCornuCurve @@ -1050,7 +1041,7 @@ EXPORT STATUS_T AdjustCornuCurve( wControl_p controls[5]; //Always needs a NULL last entry char * labels[4]; - Da.cmdType = (long)commandContext; + Da.cmdType = VP2L(commandContext); if (Da.state != PICK_POINT && Da.state != POINT_PICKED && Da.state != TRACK_SELECTED) return C_CONTINUE; @@ -1095,6 +1086,7 @@ EXPORT STATUS_T AdjustCornuCurve( case wActionMove: if (Da.state == NONE || Da.state == PICK_POINT) { + wSetCursor(mainD.d,defaultCursor); DYNARR_RESET(trkSeg_t,anchors_da); for(int i=0;i<2;i++) { if (IsClose(FindDistance(pos,Da.pos[i]))) { @@ -1113,6 +1105,7 @@ EXPORT STATUS_T AdjustCornuCurve( d = FindDistance(DYNARR_N(coOrd,Da.mid_points,i),pos); if (IsClose(d)) { CreateCornuAnchor(DYNARR_N(coOrd,Da.mid_points,i),FALSE); + wSetCursor(mainD.d,wCursorNone); return C_CONTINUE; } } @@ -1121,6 +1114,7 @@ EXPORT STATUS_T AdjustCornuCurve( d = FindDistance(Da.endHandle[i].end_center,pos); if (IsClose(d)) { CreateCornuAnchor(Da.endHandle[i].end_center, FALSE); + wSetCursor(mainD.d,wCursorNone); return C_CONTINUE; } } @@ -1129,13 +1123,14 @@ EXPORT STATUS_T AdjustCornuCurve( d = FindDistance(Da.endHandle[i].end_curve,pos); if (IsClose(d)) { CreateCornuAnchor(Da.endHandle[i].end_curve, FALSE); + wSetCursor(mainD.d,wCursorNone); return C_CONTINUE; } } coOrd temp_pos = pos; if (IsClose(DistanceSegs(zero,0.0,Da.crvSegs_da.cnt,(trkSeg_p)Da.crvSegs_da.ptr,&temp_pos,NULL))) { CreateCornuAnchor(temp_pos, TRUE); - } + } else wSetCursor(mainD.d,defaultCursor); } return C_CONTINUE; @@ -1371,7 +1366,6 @@ EXPORT STATUS_T AdjustCornuCurve( if (((MyGetKeyState() & WKEY_SHIFT) != 0) && Da.selectTrack) { //Extend end locked SetUpCornuParms(&cp); CallCornuM(Da.mid_points,Da.ends,Da.pos,&cp,&Da.crvSegs_da,FALSE); - struct extraData *xx = GetTrkExtraData(Da.selectTrack); if (Da.radius[sel] == 0) { //Straight Da.extendSeg[sel].type = SEG_STRTRK; Da.extendSeg[sel].width = 0; @@ -1786,6 +1780,7 @@ EXPORT STATUS_T AdjustCornuCurve( if (anchors_da.cnt) { DrawSegs( &tempD, zero, 0.0, &anchors(0), anchors_da.cnt, trackGauge, wDrawColorBlack ); } + if (Da.state == POINT_PICKED) wSetCursor(mainD.d,wCursorNone); return C_CONTINUE; case C_CANCEL: case C_FINISH: @@ -1826,7 +1821,6 @@ static void cornuModDlgUpdate( * */ STATUS_T CmdCornuModify (track_p trk, wAction_t action, coOrd pos, DIST_T trackG ) { - struct extraData *xx = GetTrkExtraData(trk); Da.trackGauge = trackG; @@ -1871,11 +1865,11 @@ STATUS_T CmdCornuModify (track_p trk, wAction_t action, coOrd pos, DIST_T trackG else Da.ep[0] = -1; } if (prior) { - struct extraData *xx0 = GetTrkExtraData(prior); - Da.pos[0] = xx0->cornuData.pos[ep0]; //Copy parms from FIRST CORNU trk - Da.radius[0] = xx0->cornuData.r[ep0]; - Da.angle[0] = xx0->cornuData.a[ep0]; - Da.center[0] = xx0->cornuData.c[ep0]; + struct extraDataCornu_t *xx0 = GET_EXTRA_DATA(prior, T_CORNU, extraDataCornu_t); + Da.pos[0] = xx0->pos[ep0]; //Copy parms from FIRST CORNU trk + Da.radius[0] = xx0->r[ep0]; + Da.angle[0] = xx0->a[ep0]; + Da.center[0] = xx0->c[ep0]; } //Move to RHS @@ -1897,11 +1891,11 @@ STATUS_T CmdCornuModify (track_p trk, wAction_t action, coOrd pos, DIST_T trackG } if (next) { - struct extraData *xx1 = GetTrkExtraData(next); - Da.pos[1] = xx1->cornuData.pos[ep1]; //Copy parms from LAST CORNU trk - Da.radius[1] = xx1->cornuData.r[ep1]; - Da.angle[1] = xx1->cornuData.a[ep1]; - Da.center[1] = xx1->cornuData.c[ep1]; + struct extraDataCornu_t *xx1 = GET_EXTRA_DATA(next, T_CORNU, extraDataCornu_t); + Da.pos[1] = xx1->pos[ep1]; //Copy parms from LAST CORNU trk + Da.radius[1] = xx1->r[ep1]; + Da.angle[1] = xx1->a[ep1]; + Da.center[1] = xx1->c[ep1]; } InfoMessage(_("Now Select or Add (+Shift) a Point")); @@ -1987,7 +1981,7 @@ STATUS_T CmdCornuModify (track_p trk, wAction_t action, coOrd pos, DIST_T trackG Da.state = NONE; return C_TERMINATE; } - + CopyAttributes(Da.selectTrack,Da.trk[i]); } } BOOL_T end_point[2]; @@ -2008,7 +2002,7 @@ STATUS_T CmdCornuModify (track_p trk, wAction_t action, coOrd pos, DIST_T trackG Da.center[1].x,Da.center[1].y, Da.angle[0],Da.angle[1], FormatDistance(Da.radius[0]),FormatDistance(Da.radius[1])); - UndoUndo(); + UndoUndo(NULL); Da.state = NONE; return C_TERMINATE; } @@ -2038,7 +2032,7 @@ STATUS_T CmdCornuModify (track_p trk, wAction_t action, coOrd pos, DIST_T trackG Da.center[1].x,Da.center[1].y, Da.angle[0],Da.angle[1], FormatDistance(Da.radius[0]),FormatDistance(Da.radius[1])); - UndoUndo(); + UndoUndo(NULL); Da.state = NONE; return C_TERMINATE; } @@ -2073,7 +2067,7 @@ STATUS_T CmdCornuModify (track_p trk, wAction_t action, coOrd pos, DIST_T trackG if (Da.ep[i]>= 0) ConnectTracks(i==0?first_trk:trk1,i,Da.trk[i],Da.ep[i]); } else { - UndoUndo(); + UndoUndo(NULL); wBeep(); InfoMessage(_("Connected Track End Adjust for end %d failed"),i); return C_TERMINATE; @@ -2140,7 +2134,7 @@ DIST_T CornuOffsetLength(dynArr_t segs, double offset) { } DIST_T CornuMinRadius(coOrd pos[4],dynArr_t segs) { - DIST_T r = 100000.0, rr; + DIST_T r = DIST_INF, rr; if (segs.cnt == 0 ) return r; for (int i = 0;i<segs.cnt;i++) { trkSeg_t t = DYNARR_N(trkSeg_t, segs, i); @@ -2148,7 +2142,7 @@ DIST_T CornuMinRadius(coOrd pos[4],dynArr_t segs) { rr = fabs(t.u.c.radius); } else if (t.type == SEG_BEZLIN || t.type == SEG_BEZTRK) { rr = CornuMinRadius(t.u.b.pos, t.bezSegs); - } else rr = 100000.00; + } else rr = DIST_INF; if (rr<r) r = rr; } return r; @@ -2208,6 +2202,8 @@ STATUS_T CmdCornu( wAction_t action, coOrd pos ) track_p t = NULL; cornuParm_t cp; + static BOOL_T lock; + Da.commandType = CORNU_CREATE; Da.width = (double)lineWidth/mainD.dpi; @@ -2218,7 +2214,8 @@ STATUS_T CmdCornu( wAction_t action, coOrd pos ) switch (action&0xFF) { case C_START: - Da.cmdType = (long)commandContext; + lock = FALSE; + Da.cmdType = VP2L(commandContext); Da.state = NONE; Da.selectEndPoint = -1; Da.selectMidPoint = -1; @@ -2298,7 +2295,7 @@ STATUS_T CmdCornu( wAction_t action, coOrd pos ) Da.angle[end] = GetTrkEndAngle(t,ep); } else if (t == NULL) { //end not on Track, OK for CreateCornu -> empty end point pos = p; //Reset to initial - SnapPos( &pos ); + if (lock) SnapPos( &pos ); //Only snap if snapped in move if (Da.cmdType == cornuCmdCreateTrack || Da.cmdType == cornuCmdHotBar) { Da.trk[end] = NULL; Da.pos[end] = pos; @@ -2385,6 +2382,7 @@ STATUS_T CmdCornu( wAction_t action, coOrd pos ) return C_CONTINUE; case wActionMove: + lock = FALSE; DYNARR_RESET(trkSeg_t,anchors_da); if (Da.state != NONE && Da.state != LOC_2) return C_CONTINUE; if (Da.trk[0] && Da.trk[1]) return C_CONTINUE; @@ -2421,6 +2419,9 @@ STATUS_T CmdCornu( wAction_t action, coOrd pos ) Translate(&pos,tp.ttcenter,a,tp.ttradius); CreateCornuEndAnchor(pos,TRUE); } else CreateCornuEndAnchor(pos,TRUE); + } else if (SnapPos(&pos)) { + CreateCornuEndAnchor(pos,FALSE); + lock = TRUE; } return C_CONTINUE; @@ -2542,10 +2543,14 @@ STATUS_T CmdCornu( wAction_t action, coOrd pos ) Da.pos[i] = zero; Da.endHandle[i].end_valid = FALSE; } + SetAllTrackSelect( FALSE ); } return rc; case C_REDRAW: + wSetCursor(mainD.d,defaultCursor); + DrawHighlightBoxes(FALSE,FALSE,NULL); + HighlightSelectedTracks(NULL, TRUE, TRUE); if ( Da.state != NONE ) { DrawCornuCurve(NULL,Da.ep1Segs,Da.ep1Segs_da_cnt,Da.ep2Segs,Da.ep2Segs_da_cnt,(trkSeg_t *)Da.crvSegs_da.ptr,Da.crvSegs_da_cnt, NULL, Da.extend[0]?&Da.extendSeg[0]:NULL,Da.extend[1]?&Da.extendSeg[1]:NULL,(trkSeg_t *)Da.midSegs.ptr,Da.midSegs.cnt,wDrawColorBlack); @@ -2554,6 +2559,8 @@ STATUS_T CmdCornu( wAction_t action, coOrd pos ) DrawSegs( &tempD, zero, 0.0, &anchors(0), anchors_da.cnt, trackGauge, wDrawColorBlack ); if (MyGetKeyState()&WKEY_SHIFT) DrawHighlightBoxes(FALSE,FALSE,NULL); + if (Da.state == POINT_PICKED) wSetCursor(mainD.d,wCursorNone); + return C_CONTINUE; case C_CANCEL: @@ -2572,6 +2579,7 @@ STATUS_T CmdCornu( wAction_t action, coOrd pos ) } //DYNARR_FREE(trkSeg_t,Da.crvSegs_da); } + SetAllTrackSelect( FALSE ); Da.state = NONE; if (infoSubst) { InfoSubstituteControls( NULL, NULL ); @@ -2589,12 +2597,12 @@ STATUS_T CmdCornu( wAction_t action, coOrd pos ) BOOL_T GetTracksFromCornuTrack(track_p trk, track_p newTracks[2]) { track_p trk_old = NULL; newTracks[0] = NULL, newTracks[1] = NULL; - struct extraData * xx = GetTrkExtraData(trk); + struct extraDataCornu_t * xx = GET_EXTRA_DATA(trk, T_CORNU, extraDataCornu_t); if (!IsTrack(trk)) return FALSE; - for (int i=0; i<xx->cornuData.arcSegs.cnt;i++) { + for (int i=0; i<xx->arcSegs.cnt;i++) { track_p bezTrack[2]; bezTrack[0] = NULL, bezTrack[1] = NULL; - trkSeg_p seg = &DYNARR_N(trkSeg_t,xx->cornuData.arcSegs,i); + trkSeg_p seg = &DYNARR_N(trkSeg_t,xx->arcSegs,i); if (seg->type == SEG_BEZTRK) { DYNARR_RESET(trkSeg_t,seg->bezSegs); FixUpBezierSeg(seg->u.b.pos,seg,TRUE); @@ -2690,7 +2698,7 @@ static STATUS_T cmdCornuCreate( /* no break */ case C_START: createState = 0; - commandContext = (void *)cornuCmdHotBar; + commandContext = I2VP(cornuCmdHotBar); rc = CmdCornu(C_START, pos); Da.prevSelected = -1; Da.selectEndHandle = -1; @@ -3039,14 +3047,14 @@ static STATUS_T CmdConvertFrom( } } -#include "bitmaps/convertto.xpm" -#include "bitmaps/convertfr.xpm" +#include "bitmaps/convert-to.xpm" +#include "bitmaps/convert-from.xpm" EXPORT void InitCmdCornu( wMenu_p menu ) { ButtonGroupBegin( _("Convert"), "cmdConvertSetCmd", _("Convert") ); - AddMenuButton( menu, CmdConvertTo, "cmdConvertTo", _("Convert To Cornu"), wIconCreatePixMap(convertto_xpm), LEVEL0_50, IC_STICKY|IC_LCLICK|IC_POPUP3|IC_WANT_MOVE,ACCL_CONVERTTO, NULL ); - AddMenuButton( menu, CmdConvertFrom, "cmdConvertFrom", _("Convert From Cornu"), wIconCreatePixMap(convertfr_xpm), LEVEL0_50, IC_STICKY|IC_LCLICK|IC_POPUP3|IC_WANT_MOVE,ACCL_CONVERTFR, NULL ); + AddMenuButton( menu, CmdConvertTo, "cmdConvertTo", _("Convert To Cornu"), wIconCreatePixMap(convert_to_xpm[iconSize]), LEVEL0_50, IC_STICKY|IC_LCLICK|IC_POPUP3|IC_WANT_MOVE,ACCL_CONVERTTO, NULL ); + AddMenuButton( menu, CmdConvertFrom, "cmdConvertFrom", _("Convert From Cornu"), wIconCreatePixMap(convert_from_xpm[iconSize]), LEVEL0_50, IC_STICKY|IC_LCLICK|IC_POPUP3|IC_WANT_MOVE,ACCL_CONVERTFR, NULL ); cornuHotBarCmdInx = AddMenuButton(menu, cmdCornuCreate, "cmdCornuCreate", "", NULL, LEVEL0_50, IC_STICKY|IC_POPUP3|IC_WANT_MOVE, 0, NULL); ButtonGroupEnd(); ParamCreateControls( &cornuModPG, cornuModDlgUpdate) ; |