summaryrefslogtreecommitdiff
path: root/app/bin/draw.c
diff options
context:
space:
mode:
Diffstat (limited to 'app/bin/draw.c')
-rw-r--r--app/bin/draw.c1612
1 files changed, 1030 insertions, 582 deletions
diff --git a/app/bin/draw.c b/app/bin/draw.c
index 1a0a74f..343ae3f 100644
--- a/app/bin/draw.c
+++ b/app/bin/draw.c
@@ -50,18 +50,32 @@
#include "param.h"
#include "track.h"
#include "utility.h"
+#include "layout.h"
static void DrawRoomWalls( wBool_t );
-EXPORT void DrawMarkers( void );
-static void ConstraintOrig( coOrd *, coOrd );
+static void DrawMarkers( void );
+static void ConstraintOrig( coOrd *, coOrd, int, int );
+static void DoMouse( wAction_t action, coOrd pos );
+static void DDrawPoly(
+ drawCmd_p d,
+ int cnt,
+ coOrd * pts,
+ int * types,
+ wDrawColor color,
+ wDrawWidth width,
+ int fill,
+ int open );
+static void DrawMapBoundingBox( BOOL_T set );
+static void DrawTicks( drawCmd_p d, coOrd size );
-static int log_pan = 0;
+EXPORT int log_pan = 0;
static int log_zoom = 0;
static int log_mouse = 0;
+static int log_redraw = 0;
-static wFontSize_t drawMaxTextFontSize = 100;
+static BOOL_T hideBox = FALSE;
-extern long zoomCorner;
+static wFontSize_t drawMaxTextFontSize = 100;
/****************************************************************************
*
@@ -69,12 +83,6 @@ extern long zoomCorner;
*
*/
-#define INIT_MAIN_SCALE (8.0)
-#define INIT_MAP_SCALE (64.0)
-#define MAX_MAIN_SCALE (256.0)
-#define MIN_MAIN_SCALE (1.0)
-#define MIN_MAIN_MACRO (0.10)
-
// static char FAR message[STR_LONG_SIZE];
EXPORT wPos_t closePixels = 10;
@@ -83,14 +91,31 @@ EXPORT long drawCount;
EXPORT BOOL_T drawEnable = TRUE;
EXPORT long currRedraw = 0;
+EXPORT coOrd panCenter;
+EXPORT coOrd menuPos;
+
EXPORT wDrawColor drawColorBlack;
EXPORT wDrawColor drawColorWhite;
EXPORT wDrawColor drawColorRed;
EXPORT wDrawColor drawColorBlue;
EXPORT wDrawColor drawColorGreen;
EXPORT wDrawColor drawColorAqua;
+EXPORT wDrawColor drawColorPreviewSelected;
+EXPORT wDrawColor drawColorPreviewUnselected;
+EXPORT wDrawColor drawColorPowderedBlue;
EXPORT wDrawColor drawColorPurple;
EXPORT wDrawColor drawColorGold;
+EXPORT wDrawColor drawColorGrey10;
+EXPORT wDrawColor drawColorGrey20;
+EXPORT wDrawColor drawColorGrey30;
+EXPORT wDrawColor drawColorGrey40;
+EXPORT wDrawColor drawColorGrey50;
+EXPORT wDrawColor drawColorGrey60;
+EXPORT wDrawColor drawColorGrey70;
+EXPORT wDrawColor drawColorGrey80;
+EXPORT wDrawColor drawColorGrey90;
+
+
EXPORT DIST_T pixelBins = 80;
@@ -104,6 +129,7 @@ static wPos_t infoHeight;
static wPos_t textHeight;
EXPORT wWin_p mapW;
EXPORT BOOL_T mapVisible;
+EXPORT BOOL_T magneticSnap;
EXPORT wDrawColor markerColor;
EXPORT wDrawColor borderColor;
@@ -148,15 +174,17 @@ static int mousePositionx, mousePositiony; /**< position of mouse pointer */
static int delayUpdate = 1;
-static char xLabel[] = "X : ";
-static char yLabel[] = "Y : ";
-static char zoomLabel[] = "Zoom : ";
+static char xLabel[] = "X: ";
+static char yLabel[] = "Y: ";
+static char zoomLabel[] = "Zoom: ";
static struct {
char * name;
double value;
wMenuRadio_p pdRadio;
wMenuRadio_p btRadio;
+ wMenuRadio_p ctxRadio1;
+ wMenuRadio_p panRadio;
} zoomList[] = {
{ "1:10", 1.0 / 10.0 },
{ "1:9", 1.0 / 9.0 },
@@ -293,9 +321,26 @@ static void DDrawLine(
d->CoOrd2Pix(d,p0,&x0,&y0);
d->CoOrd2Pix(d,p1,&x1,&y1);
drawCount++;
+ wDrawLineType_e lineOpt = wDrawLineSolid;
+ unsigned long NotSolid = DC_NOTSOLIDLINE;
+ unsigned long opt = d->options&NotSolid;
+ if (opt == DC_DASH)
+ lineOpt = wDrawLineDash;
+ else if(opt == DC_DOT)
+ lineOpt = wDrawLineDot;
+ else if(opt == DC_DASHDOT)
+ lineOpt = wDrawLineDashDot;
+ else if (opt == DC_DASHDOTDOT)
+ lineOpt = wDrawLineDashDotDot;
+ else if(opt == DC_CENTER)
+ lineOpt = wDrawLineCenter;
+ else if (opt == DC_PHANTOM)
+ lineOpt = wDrawLinePhantom;
+
if (drawEnable) {
wDrawLine( d->d, x0, y0, x1, y1,
- width, ((d->options&DC_DASH)==0)?wDrawLineSolid:wDrawLineDash,
+ width,
+ lineOpt,
color, (wDrawOpts)d->funcs->options );
}
}
@@ -311,37 +356,78 @@ static void DDrawArc(
wDrawWidth width,
wDrawColor color )
{
- wPos_t x, y;
- ANGLE_T da;
- coOrd p0, p1;
- DIST_T rr;
- int i, cnt;
-
- if (d == &mapD && !mapVisible)
- return;
- rr = (r / d->scale) * d->dpi + 0.5;
- if (rr > wDrawGetMaxRadius(d->d)) {
- da = (maxArcSegStraightLen * 180) / (M_PI * rr);
- cnt = (int)(angle1/da) + 1;
- da = angle1 / cnt;
- PointOnCircle( &p0, p, r, angle0 );
- for ( i=1; i<=cnt; i++ ) {
- angle0 += da;
- PointOnCircle( &p1, p, r, angle0 );
- DrawLine( d, p0, p1, width, color );
- p0 = p1;
- }
- return;
- }
- if (d->angle!=0.0 && angle1 < 360.0)
- angle0 = NormalizeAngle( angle0-d->angle );
- d->CoOrd2Pix(d,p,&x,&y);
- drawCount++;
- if (drawEnable) {
- wDrawArc( d->d, x, y, (wPos_t)(rr), angle0, angle1, drawCenter,
- width, ((d->options&DC_DASH)==0)?wDrawLineSolid:wDrawLineDash,
- color, (wDrawOpts)d->funcs->options );
- }
+ wPos_t x, y;
+ ANGLE_T da;
+ coOrd p0, p1;
+ DIST_T rr;
+ int i, cnt;
+
+ if (d == &mapD && !mapVisible)
+ {
+ return;
+ }
+ rr = (r / d->scale) * d->dpi + 0.5;
+ if (rr > wDrawGetMaxRadius(d->d))
+ {
+ da = (maxArcSegStraightLen * 180) / (M_PI * rr);
+ cnt = (int)(angle1/da) + 1;
+ da = angle1 / cnt;
+ coOrd min,max;
+ min = d->orig;
+ max.x = min.x + d->size.x;
+ max.y = min.y + d->size.y;
+ PointOnCircle(&p0, p, r, angle0);
+ for (i=1; i<=cnt; i++) {
+ angle0 += da;
+ PointOnCircle(&p1, p, r, angle0);
+ if (d->angle == 0.0 &&
+ ((p0.x >= min.x &&
+ p0.x <= max.x &&
+ p0.y >= min.y &&
+ p0.y <= max.y) ||
+ (p1.x >= min.x &&
+ p1.x <= max.x &&
+ p1.y >= min.y &&
+ p1.y <= max.y))) {
+ DrawLine(d, p0, p1, width, color);
+ } else {
+ coOrd clip0 = p0, clip1 = p1;
+ if (ClipLine(&clip0, &clip1, d->orig, d->angle, d->size)) {
+ DrawLine(d, clip0, clip1, width, color);
+ }
+ }
+
+ p0 = p1;
+ }
+ return;
+ }
+ if (d->angle!=0.0 && angle1 < 360.0)
+ {
+ angle0 = NormalizeAngle(angle0-d->angle);
+ }
+ d->CoOrd2Pix(d,p,&x,&y);
+ drawCount++;
+ wDrawLineType_e lineOpt = wDrawLineSolid;
+ unsigned long NotSolid = DC_NOTSOLIDLINE;
+ unsigned long opt = d->options&NotSolid;
+ if (opt == DC_DASH)
+ lineOpt = wDrawLineDash;
+ else if(opt == DC_DOT)
+ lineOpt = wDrawLineDot;
+ else if(opt == DC_DASHDOT)
+ lineOpt = wDrawLineDashDot;
+ else if (opt == DC_DASHDOTDOT)
+ lineOpt = wDrawLineDashDotDot;
+ else if(opt == DC_CENTER)
+ lineOpt = wDrawLineCenter;
+ else if (opt == DC_PHANTOM)
+ lineOpt = wDrawLinePhantom;
+ if (drawEnable)
+ {
+ wDrawArc(d->d, x, y, (wPos_t)(rr), angle0, angle1, drawCenter,
+ width, lineOpt,
+ color, (wDrawOpts)d->funcs->options);
+ }
}
@@ -357,30 +443,76 @@ static void DDrawString(
wPos_t x, y;
if (d == &mapD && !mapVisible)
return;
- fontSize /= d->scale;
d->CoOrd2Pix(d,p,&x,&y);
- wDrawString( d->d, x, y, d->angle-a, s, fp, fontSize, color, (wDrawOpts)d->funcs->options );
+ if ( color == wDrawColorWhite ) {
+ wPos_t width, height, descent, ascent;
+ coOrd pos[4], size;
+ double scale = 1.0;
+ wDrawGetTextSize( &width, &height, &descent, &ascent, d->d, s, fp, fontSize );
+ pos[0] = p;
+ size.x = SCALEX(mainD,width)*scale;
+ size.y = SCALEY(mainD,height)*scale;
+ pos[1].x = p.x+size.x;
+ pos[1].y = p.y;
+ pos[2].x = p.x+size.x;
+ pos[2].y = p.y+size.y;
+ pos[3].x = p.x;
+ pos[3].y = p.y+size.y;
+ Rotate( &pos[1], pos[0], a );
+ Rotate( &pos[2], pos[0], a );
+ Rotate( &pos[3], pos[0], a );
+ DDrawPoly( d, 4, pos, NULL, color, 0, 1, 0 );
+ } else {
+ fontSize /= d->scale;
+ wDrawString( d->d, x, y, d->angle-a, s, fp, fontSize, color, (wDrawOpts)d->funcs->options );
+ }
}
-static void DDrawFillPoly(
+static void DDrawPoly(
drawCmd_p d,
int cnt,
coOrd * pts,
- wDrawColor color )
+ int * types,
+ wDrawColor color,
+ wDrawWidth width,
+ int fill,
+ int open )
{
typedef wPos_t wPos2[2];
static dynArr_t wpts_da;
+ static dynArr_t wpts_type_da;
int inx;
wPos_t x, y;
DYNARR_SET( wPos2, wpts_da, cnt * 2 );
+ DYNARR_SET( int, wpts_type_da, cnt);
#define wpts(N) DYNARR_N( wPos2, wpts_da, N )
+#define wtype(N) DYNARR_N( wPolyLine_e, wpts_type_da, N )
for ( inx=0; inx<cnt; inx++ ) {
d->CoOrd2Pix( d, pts[inx], &x, &y );
wpts(inx)[0] = x;
wpts(inx)[1] = y;
+ if (!types)
+ wtype(inx) = 0;
+ else
+ wtype(inx) = (wPolyLine_e)types[inx];
}
- wDrawFilledPolygon( d->d, &wpts(0), cnt, color, (wDrawOpts)d->funcs->options );
+ wDrawLineType_e lineOpt = wDrawLineSolid;
+ unsigned long NotSolid = DC_NOTSOLIDLINE;
+ unsigned long opt = d->options&NotSolid;
+ if (opt == DC_DASH)
+ lineOpt = wDrawLineDash;
+ else if(opt == DC_DOT)
+ lineOpt = wDrawLineDot;
+ else if(opt == DC_DASHDOT)
+ lineOpt = wDrawLineDashDot;
+ else if (opt == DC_DASHDOTDOT)
+ lineOpt = wDrawLineDashDotDot;
+ else if(opt == DC_CENTER)
+ lineOpt = wDrawLineCenter;
+ else if (opt == DC_PHANTOM)
+ lineOpt = wDrawLinePhantom;
+ wDrawPolygon( d->d, &wpts(0), &wtype(0), cnt, color, width, lineOpt, (wDrawOpts)d->funcs->options, fill, open );
}
@@ -420,24 +552,20 @@ static void DDrawFillCircle(
}
-EXPORT void DrawHilight( drawCmd_p d, coOrd p, coOrd s )
+EXPORT void DrawHilight( drawCmd_p d, coOrd p, coOrd s, BOOL_T add )
{
wPos_t x, y, w, h;
if (d == &mapD && !mapVisible)
return;
-#ifdef LATER
- if (d->options&DC_TEMPSEGS) {
- return;
- }
- if (d->options&DC_PRINT)
- return;
-#endif
w = (wPos_t)((s.x/d->scale)*d->dpi+0.5);
h = (wPos_t)((s.y/d->scale)*d->dpi+0.5);
d->CoOrd2Pix(d,p,&x,&y);
- wDrawFilledRectangle( d->d, x, y, w, h, wDrawColorBlack, wDrawOptTemp );
-}
+ if ( add )
+ wDrawFilledRectangle( d->d, x, y, w, h, drawColorPowderedBlue, wDrawOptTemp|wDrawOptTransparent );
+ else
+ wDrawFilledRectangle( d->d, x, y, w, h, selectedColor, wDrawOptTemp|wDrawOptTransparent );
+}
EXPORT void DrawHilightPolygon( drawCmd_p d, coOrd *p, int cnt )
{
@@ -454,7 +582,10 @@ EXPORT void DrawHilightPolygon( drawCmd_p d, coOrd *p, int cnt )
for (i=0; i<cnt; i++) {
d->CoOrd2Pix(d,p[i],&q[i][0],&q[i][1]);
}
- wDrawFilledPolygon( d->d, q, cnt, wDrawColorBlack, wDrawOptTemp );
+ static wDrawColor color = 0;
+ if ( color == 0 )
+ color = wDrawColorGray( 70 );
+ wDrawPolygon( d->d, q, NULL, cnt, color, 0, 0, wDrawOptTemp|wDrawOptTransparent, 1, 0 );
}
@@ -467,13 +598,14 @@ EXPORT void DrawMultiString(
wDrawColor color,
ANGLE_T a,
coOrd * lo,
- coOrd * hi)
+ coOrd * hi,
+ BOOL_T boxed)
{
char * cp;
char * cp1;
POS_T lineH, lineW;
coOrd size, textsize, posl, orig;
- POS_T descent;
+ POS_T descent, ascent;
char *line;
if (!text || !*text) {
@@ -481,9 +613,9 @@ EXPORT void DrawMultiString(
}
line = malloc(strlen(text) + 1);
- DrawTextSize2( &mainD, "Aqjlp", fp, fs, TRUE, &textsize, &descent);
- POS_T ascent = textsize.y-descent;
- lineH = ascent+descent*1.5;
+ DrawTextSize2( &mainD, "Aqjlp", fp, fs, TRUE, &textsize, &descent, &ascent);
+ //POS_T ascent = textsize.y-descent;
+ lineH = (ascent+descent)*1.0;
size.x = 0.0;
size.y = 0.0;
orig.x = pos.x;
@@ -494,7 +626,7 @@ EXPORT void DrawMultiString(
while (*text != '\0' && *text != '\n')
*cp++ = *text++;
*cp = '\0';
- DrawTextSize2( &mainD, cp1, fp, fs, TRUE, &textsize, &descent);
+ DrawTextSize2( &mainD, cp1, fp, fs, TRUE, &textsize, &descent, &ascent);
lineW = textsize.x;
if (lineW>size.x)
size.x = lineW;
@@ -515,7 +647,25 @@ EXPORT void DrawMultiString(
}
if (hi) {
hi->x = posl.x+size.x;
- hi->y = posl.y+ascent;
+ hi->y = orig.y+ascent;
+ }
+ if (boxed && (d != &mapD)) {
+ int bw=2, bh=2, br=1, bb=1;
+ size.x += bw*d->scale/d->dpi;
+ size.y = fabs(orig.y-posl.y)+bh*d->scale/d->dpi;
+ size.y += descent+ascent;
+ coOrd p[4];
+ p[0] = orig; p[0].x -= (bw-br)*d->scale/d->dpi; p[0].y += (bh-bb)*d->scale/d->dpi+ascent;
+ p[1] = p[0]; p[1].x += size.x;
+ p[2] = p[1]; p[2].y -= size.y;
+ p[3] = p[2]; p[3].x = p[0].x;
+ for (int i=0;i<4;i++) {
+ Rotate( &p[i], orig, a);
+ }
+ DrawLine( d, p[0], p[1], 0, color );
+ DrawLine( d, p[1], p[2], 0, color );
+ DrawLine( d, p[2], p[3], 0, color );
+ DrawLine( d, p[3], p[0], 0, color );
}
free(line);
@@ -532,24 +682,25 @@ EXPORT void DrawBoxedString(
ANGLE_T a )
{
coOrd size, p[4], p0=pos, p1, p2;
- static int bw=5, bh=4, br=2, bb=2;
+ static int bw=2, bh=2, br=1, bb=1;
static double arrowScale = 0.5;
- long options = d->options;
- POS_T descent;
+ unsigned long options = d->options;
+ POS_T descent, ascent;
/*DrawMultiString( d, pos, text, fp, fs, color, a, &lo, &hi );*/
if ( fs < 2*d->scale )
return;
#ifndef WINDOWS
if ( ( d->options & DC_PRINT) != 0 ) {
double scale = ((FLOAT_T)fs)/((FLOAT_T)drawMaxTextFontSize)/72.0;
- wPos_t w, h, d;
- wDrawGetTextSize( &w, &h, &d, mainD.d, text, fp, drawMaxTextFontSize );
+ wPos_t w, h, d, a;
+ wDrawGetTextSize( &w, &h, &d, &a, mainD.d, text, fp, drawMaxTextFontSize );
size.x = w*scale;
size.y = h*scale;
descent = d*scale;
+ ascent = a*scale;
} else
#endif
- DrawTextSize2( &mainD, text, fp, fs, TRUE, &size, &descent );
+ DrawTextSize2( &mainD, text, fp, fs, TRUE, &size, &descent, &ascent );
#ifdef WINDOWS
/*h -= 15;*/
#endif
@@ -561,10 +712,9 @@ EXPORT void DrawBoxedString(
}
size.x += bw*d->scale/d->dpi;
size.y += bh*d->scale/d->dpi;
- size.y += descent;
p[0] = p0;
p[0].x -= br*d->scale/d->dpi;
- p[0].y -= bb*d->scale/d->dpi+descent;
+ p[0].y -= (bb*d->scale/d->dpi+descent);
p[1].y = p[0].y;
p[2].y = p[3].y = p[0].y + size.y;
p[1].x = p[2].x = p[0].x + size.x;
@@ -589,12 +739,12 @@ EXPORT void DrawBoxedString(
DrawString( d, p0, 0.0, text, fp, fs, color );
break;
case BOX_INVERT:
- DrawFillPoly( d, 4, p, color );
+ DrawPoly( d, 4, p, NULL, color, 0, 1, 0);
if ( color != wDrawColorWhite )
- DrawString( d, p0, 0.0, text, fp, fs, wDrawColorWhite );
+ DrawString( d, p0, 0.0, text, fp, fs, wDrawColorGray( 94 ) );
break;
case BOX_BACKGROUND:
- DrawFillPoly( d, 4, p, wDrawColorWhite );
+ DrawPoly( d, 4, p, NULL, wDrawColorWhite, 0, 1, 0 );
DrawString( d, p0, 0.0, text, fp, fs, color );
break;
}
@@ -609,9 +759,10 @@ EXPORT void DrawTextSize2(
wFontSize_t fs,
BOOL_T relative,
coOrd * size,
- POS_T * descent )
+ POS_T * descent,
+ POS_T * ascent)
{
- wPos_t w, h, d;
+ wPos_t w, h, d, a;
FLOAT_T scale = 1.0;
if ( relative )
fs /= dp->scale;
@@ -619,14 +770,16 @@ EXPORT void DrawTextSize2(
scale = ((FLOAT_T)fs)/((FLOAT_T)drawMaxTextFontSize);
fs = drawMaxTextFontSize;
}
- wDrawGetTextSize( &w, &h, &d, dp->d, text, fp, fs );
+ wDrawGetTextSize( &w, &h, &d, &a, dp->d, text, fp, fs );
size->x = SCALEX(mainD,w)*scale;
size->y = SCALEY(mainD,h)*scale;
*descent = SCALEY(mainD,d)*scale;
+ *ascent = SCALEY(mainD,a)*scale;
if ( relative ) {
size->x *= dp->scale;
size->y *= dp->scale;
*descent *= dp->scale;
+ *ascent *=dp->scale;
}
/* printf( "DTS2(\"%s\",%0.3f,%d) = (w%d,h%d,d%d) *%0.3f x%0.3f y%0.3f %0.3f\n", text, fs, relative, w, h, d, scale, size->x, size->y, *descent );*/
}
@@ -639,8 +792,8 @@ EXPORT void DrawTextSize(
BOOL_T relative,
coOrd * size )
{
- POS_T descent;
- DrawTextSize2( dp, text, fp, fs, relative, size, &descent );
+ POS_T descent, ascent;
+ DrawTextSize2( dp, text, fp, fs, relative, size, &descent, &ascent );
}
EXPORT void DrawMultiLineTextSize(
@@ -652,15 +805,14 @@ EXPORT void DrawMultiLineTextSize(
coOrd * size,
coOrd * lastline )
{
- POS_T descent, lineW, lineH;
+ POS_T descent, ascent, lineW, lineH;
coOrd textsize, blocksize;
char *cp;
char *line = malloc(strlen(text) + 1);
- DrawTextSize2( &mainD, "Aqlip", fp, fs, TRUE, &textsize, &descent);
- POS_T ascent = textsize.y-descent;
- lineH = ascent+descent*1.5;
+ DrawTextSize2( &mainD, "Aqlip", fp, fs, TRUE, &textsize, &descent, &ascent);
+ lineH = (ascent+descent)*1.0;
blocksize.x = 0;
blocksize.y = 0;
lastline->x = 0;
@@ -671,17 +823,20 @@ EXPORT void DrawMultiLineTextSize(
*cp++ = *text++;
*cp = '\0';
blocksize.y += lineH;
- DrawTextSize2( &mainD, line, fp, fs, TRUE, &textsize, &descent);
+ DrawTextSize2( &mainD, line, fp, fs, TRUE, &textsize, &descent, &ascent);
lineW = textsize.x;
if (lineW>blocksize.x)
blocksize.x = lineW;
lastline->x = textsize.x;
if (*text =='\n') {
+ blocksize.y += lineH;
lastline->y -= lineH;
lastline->x = 0;
}
- if (*text == '\0')
+ if (*text == '\0') {
+ blocksize.y += textsize.y;
break;
+ }
text++;
}
size->x = blocksize.x;
@@ -760,6 +915,7 @@ static void TempSegString(
DYNARR_APPEND( trkSeg_t, tempSegs_da, 10 );
tempSegs(tempSegs_da.cnt-1).type = SEG_TEXT;
tempSegs(tempSegs_da.cnt-1).color = color;
+ tempSegs(tempSegs_da.cnt-1).u.t.boxed = FALSE;
tempSegs(tempSegs_da.cnt-1).width = 0;
tempSegs(tempSegs_da.cnt-1).u.t.pos = p;
tempSegs(tempSegs_da.cnt-1).u.t.angle = a;
@@ -769,22 +925,33 @@ static void TempSegString(
}
-static void TempSegFillPoly(
+static void TempSegPoly(
drawCmd_p d,
int cnt,
coOrd * pts,
- wDrawColor color )
+ int * types,
+ wDrawColor color,
+ wDrawWidth width,
+ int fill,
+ int open )
{
-#ifdef LATER
- pts is not guaranteed to valid
- DYNARR_APPEND( trkSeg_t, tempSegs_da, 10 );
- tempSegs(tempSegs_da.cnt-1).type = SEG_FILPOLY;
+ DYNARR_APPEND( trkSeg_t, tempSegs_da, 1);
+ tempSegs(tempSegs_da.cnt-1).type = fill?SEG_FILPOLY:SEG_POLY;
tempSegs(tempSegs_da.cnt-1).color = color;
- tempSegs(tempSegs_da.cnt-1).width = 0;
+ if (d->options&DC_SIMPLE)
+ tempSegs(tempSegs_da.cnt-1).width = 0;
+ else
+ tempSegs(tempSegs_da.cnt-1).width = width*d->scale/d->dpi;
+ tempSegs(tempSegs_da.cnt-1).u.p.polyType = open?POLYLINE:FREEFORM;
tempSegs(tempSegs_da.cnt-1).u.p.cnt = cnt;
- tempSegs(tempSegs_da.cnt-1).u.p.pts = pts;
-#endif
- return;
+ tempSegs(tempSegs_da.cnt-1).u.p.orig = zero;
+ tempSegs(tempSegs_da.cnt-1).u.p.angle = 0.0;
+ tempSegs(tempSegs_da.cnt-1).u.p.pts = (pts_t *)MyMalloc(cnt*sizeof(pts_t));
+ for (int i=0;i<=cnt-1;i++) {
+ tempSegs(tempSegs_da.cnt-1).u.p.pts[i].pt = pts[i];
+ tempSegs(tempSegs_da.cnt-1).u.p.pts[i].pt_type = (d->options&DC_SIMPLE)==0?types[i]:wPolyLineStraight;
+ }
+
}
@@ -817,7 +984,7 @@ EXPORT drawFuncs_t screenDrawFuncs = {
DDrawArc,
DDrawString,
DDrawBitMap,
- DDrawFillPoly,
+ DDrawPoly,
DDrawFillCircle };
EXPORT drawFuncs_t tempDrawFuncs = {
@@ -826,7 +993,7 @@ EXPORT drawFuncs_t tempDrawFuncs = {
DDrawArc,
DDrawString,
DDrawBitMap,
- DDrawFillPoly,
+ DDrawPoly,
DDrawFillCircle };
EXPORT drawFuncs_t printDrawFuncs = {
@@ -835,7 +1002,7 @@ EXPORT drawFuncs_t printDrawFuncs = {
DDrawArc,
DDrawString,
NoDrawBitMap,
- DDrawFillPoly,
+ DDrawPoly,
DDrawFillCircle };
EXPORT drawFuncs_t tempSegDrawFuncs = {
@@ -844,17 +1011,17 @@ EXPORT drawFuncs_t tempSegDrawFuncs = {
TempSegArc,
TempSegString,
NoDrawBitMap,
- TempSegFillPoly,
+ TempSegPoly,
TempSegFillCircle };
EXPORT drawCmd_t mainD = {
NULL, &screenDrawFuncs, DC_TICKS, INIT_MAIN_SCALE, 0.0, {0.0,0.0}, {0.0,0.0}, MainPix2CoOrd, MainCoOrd2Pix };
EXPORT drawCmd_t tempD = {
- NULL, &tempDrawFuncs, DC_TICKS|DC_SIMPLE, INIT_MAIN_SCALE, 0.0, {0.0,0.0}, {0.0,0.0}, MainPix2CoOrd, MainCoOrd2Pix };
+ NULL, &tempDrawFuncs, DC_TICKS, INIT_MAIN_SCALE, 0.0, {0.0,0.0}, {0.0,0.0}, MainPix2CoOrd, MainCoOrd2Pix };
EXPORT drawCmd_t mapD = {
- NULL, &screenDrawFuncs, 0, INIT_MAP_SCALE, 0.0, {0.0,0.0}, {96.0,48.0}, Pix2CoOrd, CoOrd2Pix };
+ NULL, &screenDrawFuncs, DC_SIMPLE, INIT_MAP_SCALE, 0.0, {0.0,0.0}, {96.0,48.0}, Pix2CoOrd, CoOrd2Pix };
/*****************************************************************************
@@ -919,7 +1086,7 @@ EXPORT void InitInfoBar( void )
{
wPos_t width, height, y, yb, ym, x, boxH;
wWinGetSize( mainW, &width, &height );
- infoHeight = 3 + wStatusGetHeight( COMBOBOX ) + 3;
+ infoHeight = 2 + wStatusGetHeight( COMBOBOX ) + 2 ;
textHeight = wStatusGetHeight(0L);
y = height - max(infoHeight,textHeight)-10;
@@ -927,8 +1094,8 @@ EXPORT void InitInfoBar( void )
y -= 19; /* Kludge for MSW */
#endif
- infoD.pos_w = GetInfoPosWidth() + 2;
- infoD.scale_w = wStatusGetWidth( "999:1" ) + wStatusGetWidth( zoomLabel ) + 6;
+ infoD.pos_w = GetInfoPosWidth();
+ infoD.scale_w = wStatusGetWidth( "999:1" ) + wStatusGetWidth( zoomLabel );
/* we do not use the count label for the moment */
infoD.count_w = 0;
infoD.info_w = width - 20 - infoD.pos_w*2 - infoD.scale_w - infoD.count_w - 45; // Allow Window to resize down
@@ -941,13 +1108,13 @@ EXPORT void InitInfoBar( void )
x = 2;
infoD.scale_b = wBoxCreate( mainW, x, yb, NULL, wBoxBelow, infoD.scale_w, boxH );
infoD.scale_m = wStatusCreate( mainW, x+info_xm_offset, ym, "infoBarScale", infoD.scale_w-six, zoomLabel);
- x += infoD.scale_w + 10;
+ x += infoD.scale_w + 2;
infoD.posX_b = wBoxCreate( mainW, x, yb, NULL, wBoxBelow, infoD.pos_w, boxH );
infoD.posX_m = wStatusCreate( mainW, x+info_xm_offset, ym, "infoBarPosX", infoD.pos_w-six, xLabel );
- x += infoD.pos_w + 5;
+ x += infoD.pos_w + 2;
infoD.posY_b = wBoxCreate( mainW, x, yb, NULL, wBoxBelow, infoD.pos_w, boxH );
infoD.posY_m = wStatusCreate( mainW, x+info_xm_offset, ym, "infoBarPosY", infoD.pos_w-six, yLabel );
- x += infoD.pos_w + 10;
+ x += infoD.pos_w + 2;
messageOrControlX = x+info_xm_offset; //Remember Position
messageOrControlY = ym;
infoD.info_b = wBoxCreate( mainW, x, yb, NULL, wBoxBelow, infoD.info_w, boxH );
@@ -966,10 +1133,10 @@ static void SetInfoBar( void )
y = height - max(infoHeight,textHeight)-10;
newDistanceFormat = GetDistanceFormat();
if ( newDistanceFormat != oldDistanceFormat ) {
- infoD.pos_w = GetInfoPosWidth() + 2;
- wBoxSetSize( infoD.posX_b, infoD.pos_w, infoHeight-5 );
+ infoD.pos_w = GetInfoPosWidth();
+ wBoxSetSize( infoD.posX_b, infoD.pos_w, infoHeight-3 );
wStatusSetWidth( infoD.posX_m, infoD.pos_w-six );
- wBoxSetSize( infoD.posY_b, infoD.pos_w, infoHeight-5 );
+ wBoxSetSize( infoD.posY_b, infoD.pos_w, infoHeight-3 );
wStatusSetWidth( infoD.posY_m, infoD.pos_w-six );
}
infoD.info_w = width - 20 - infoD.pos_w*2 - infoD.scale_w - infoD.count_w - 40 + 4;
@@ -1028,13 +1195,12 @@ EXPORT void InfoCount( wIndex_t count )
EXPORT void InfoPos( coOrd pos )
{
- DrawMarkers();
sprintf( message, "%s%s", xLabel, FormatDistance(pos.x) );
wStatusSetValue( infoD.posX_m, message );
sprintf( message, "%s%s", yLabel, FormatDistance(pos.y) );
wStatusSetValue( infoD.posY_m, message );
+
oldMarker = pos;
- DrawMarkers();
}
static wControl_p deferSubstituteControls[NUM_INFOCTL+1];
@@ -1071,7 +1237,11 @@ EXPORT void InfoSubstituteControls(
for ( inx=0; controls[inx]; inx++ ) {
curInfoLabelWidth[inx] = wLabelWidth(_(labels[inx]));
x += curInfoLabelWidth[inx];
- int y_this = y + (textHeight/2) - (wControlGetHeight( controls[inx] )/2);
+#ifdef WINDOWS
+ int y_this = y + (infoHeight/2) - (textHeight / 2 );
+#else
+ int y_this = y + (infoHeight / 2) - (wControlGetHeight(controls[inx]) / 2) - 2;
+#endif
wControlSetPos( controls[inx], x, y_this );
x += wControlGetWidth( controls[inx] );
wControlSetLabel( controls[inx], _(labels[inx]) );
@@ -1090,39 +1260,23 @@ EXPORT void SetMessage( char * msg )
}
-static void ChangeMapScale( void )
+static void ChangeMapScale( BOOL_T reset )
{
wPos_t w, h;
wPos_t dw, dh;
FLOAT_T fw, fh;
- wGetDisplaySize( &dw, &dh );
- dw /= 2;
- dh /= 2;
- fw = ((mapD.size.x/mapD.scale)*mapD.dpi + 0.5)+2;
- fh = ((mapD.size.y/mapD.scale)*mapD.dpi + 0.5)+2;
- if (fw > dw || fh > dh) {
- if (fw/dw > fh/dh) {
- mapD.scale = ceil(mapD.size.x*mapD.dpi/dw);
- } else {
- mapD.scale = ceil(mapD.size.y*mapD.dpi/dh);
- }
- mapScale = (long)mapD.scale;
- fw = ((mapD.size.x/mapD.scale)*mapD.dpi + 0.5)+2;
- fh = ((mapD.size.y/mapD.scale)*mapD.dpi + 0.5)+2;
- } else if ( fw < 100.0 && fh < 100.0 ) {
- if (fw > fh) {
- mapD.scale = ceil(mapD.size.x*mapD.dpi/100);
- } else {
- mapD.scale = ceil(mapD.size.y*mapD.dpi/100);
- }
- mapScale = (long)mapD.scale;
- fw = ((mapD.size.x/mapD.scale)*mapD.dpi + 0.5)+2;
- fh = ((mapD.size.y/mapD.scale)*mapD.dpi + 0.5)+2;
- }
+
+ fw = (((mapD.size.x/mapD.scale)*mapD.dpi) + 0.5)+2;
+ fh = (((mapD.size.y/mapD.scale)*mapD.dpi) + 0.5)+2;
+
w = (wPos_t)fw;
h = (wPos_t)fh;
- wWinSetSize( mapW, w+DlgSepLeft+DlgSepRight, h+DlgSepTop+DlgSepBottom );
+ if (reset) {
+ wGetDisplaySize( &dw, &dh );
+ wSetGeometry(mapW, 50, dw, 50, dh, -1, -1, mapD.size.x/mapD.size.y);
+ wWinSetSize( mapW, w+DlgSepLeft+DlgSepRight, h+DlgSepTop+DlgSepBottom);
+ }
wDrawSetSize( mapD.d, w, h, NULL );
}
@@ -1137,12 +1291,10 @@ EXPORT BOOL_T SetRoomSize( coOrd size )
mapD.size.y == size.y )
return TRUE;
mapD.size = size;
+ SetLayoutRoomSize(size);
if ( mapW == NULL)
return TRUE;
- ChangeMapScale();
- ConstraintOrig( &mainD.orig, mainD.size );
- tempD.orig = mainD.orig;
- /*MainRedraw();*/
+ ChangeMapScale(TRUE);
wPrefSetFloat( "draw", "roomsizeX", mapD.size.x );
wPrefSetFloat( "draw", "roomsizeY", mapD.size.y );
return TRUE;
@@ -1155,23 +1307,21 @@ EXPORT void GetRoomSize( coOrd * froomSize )
}
-EXPORT void MapRedraw( void )
+static void MapRedraw()
{
if (inPlaybackQuit)
return;
-#ifdef VERBOSE
-lprintf("MapRedraw\n");
-#endif
+ static int cMR = 0;
+ LOG( log_redraw, 2, ( "MapRedraw: %d\n", cMR++ ) );
if (!mapVisible)
return;
-
if (delayUpdate)
wDrawDelayUpdate( mapD.d, TRUE );
- wSetCursor( wCursorWait );
+ //wSetCursor( mapD.d, wCursorWait );
wDrawClear( mapD.d );
DrawTracks( &mapD, mapD.scale, mapD.orig, mapD.size );
DrawMapBoundingBox( TRUE );
- wSetCursor( wCursorNormal );
+ //wSetCursor( mapD.d, defaultCursor );
wDrawDelayUpdate( mapD.d, FALSE );
}
@@ -1179,7 +1329,7 @@ lprintf("MapRedraw\n");
static void MapResize( void )
{
mapD.scale = mapScale;
- ChangeMapScale();
+ ChangeMapScale(TRUE);
MapRedraw();
}
@@ -1222,25 +1372,107 @@ EXPORT void SetMainSize( void )
tempD.size = mainD.size;
}
+// Hack to switch between TempRedraw and MainRedraw
+extern wBool_t wDrawDoTempDraw;
+/* Update temp_surface after executing a command
+ */
+EXPORT void TempRedraw( void ) {
+
+ static int cTR = 0;
+ LOG( log_redraw, 2, ( "TempRedraw: %d\n", cTR++ ) );
+if (wDrawDoTempDraw == FALSE) {
+ // Remove this after windows supports GTK
+ MainRedraw(); // TempRedraw - windows
+} else {
+ wDrawDelayUpdate( tempD.d, TRUE );
+ wDrawSetTempMode( tempD.d, TRUE );
+ DrawMarkers();
+ DoCurCommand( C_REDRAW, zero );
+ RulerRedraw( FALSE );
+ RedrawPlaybackCursor(); //If in playback
+ wDrawSetTempMode( tempD.d, FALSE );
+ wDrawDelayUpdate( tempD.d, FALSE );
+}
+}
+
+/*
+* Redraw contents on main window
+*/
EXPORT void MainRedraw( void )
{
+ coOrd orig, size;
+
+ static int cMR = 0;
+ LOG( log_redraw, 1, ( "MainRedraw: %d\n", cMR++ ) );
+ if (delayUpdate)
+ wDrawDelayUpdate( mainD.d, TRUE );
+
+ wDrawClear( mainD.d );
+
+ //mainD.d->option = 0;
+ //mainD.options = 0;
+ mainD.funcs->options = 0; //Force MainD back from Temp
+
+ orig = mainD.orig;
+ size = mainD.size;
+ orig.x -= LBORDER/mainD.dpi*mainD.scale;
+ orig.y -= BBORDER/mainD.dpi*mainD.scale;
+ wPos_t back_x,back_y;
+ coOrd back_pos = GetLayoutBackGroundPos();
+ back_x = (wPos_t)((back_pos.x-orig.x)/mainD.scale*mainD.dpi);
+ back_y = (wPos_t)((back_pos.y-orig.y)/mainD.scale*mainD.dpi);
+ wPos_t back_width = (wPos_t)(GetLayoutBackGroundSize()/mainD.scale*mainD.dpi);
+
+ DrawRoomWalls( TRUE );
+ if (GetLayoutBackGroundScreen() < 100.0 && GetLayoutBackGroundVisible()) {
+ wDrawShowBackground( mainD.d, back_x, back_y, back_width, GetLayoutBackGroundAngle(), GetLayoutBackGroundScreen());
+ }
+ orig = mainD.orig;
+ size = mainD.size;
+ orig.x -= RBORDER/mainD.dpi*mainD.scale;
+ orig.y -= BBORDER/mainD.dpi*mainD.scale;
+ size.x += (RBORDER+LBORDER)/mainD.dpi*mainD.scale;
+ size.y += (BBORDER+TBORDER)/mainD.dpi*mainD.scale;
+ DrawTracks( &mainD, mainD.scale, orig, size );
+
+ DrawRoomWalls( FALSE );
+ currRedraw++;
+ DrawSnapGrid( &mainD, mapD.size, TRUE );
+
+ //wSetCursor( mainD.d, defaultCursor );
+ InfoScale();
+ // The remainder is from TempRedraw
+ wDrawSetTempMode( tempD.d, TRUE );
+ DrawMarkers();
+ DoCurCommand( C_REDRAW, zero );
+ RulerRedraw( FALSE );
+ RedrawPlaybackCursor(); //If in playback
+ wDrawSetTempMode( tempD.d, FALSE );
+ wDrawDelayUpdate( mainD.d, FALSE );
+}
+
+/*
+* Layout main window in response to Pan/Zoom
+*
+* \param bRedraw Redraw mainD
+* \param bNoBorder Don't allow mainD.orig to go negative
+*/
+EXPORT void MainLayout(
+ wBool_t bRedraw,
+ wBool_t bNoBorder )
+{
#ifdef LATER
wPos_t ww, hh;
DIST_T w, h;
#endif
- coOrd orig, size;
DIST_T t1;
if (inPlaybackQuit)
return;
-#ifdef VERBOSE
-lprintf("mainRedraw\n");
-#endif
+ static int cML = 0;
+ LOG( log_redraw, 1, ( "MainLayout: %d\n", cML++ ) );
- wSetCursor( wCursorWait );
- if (delayUpdate)
- wDrawDelayUpdate( mainD.d, TRUE );
#ifdef LATER
wDrawGetSize( mainD.d, &ww, &hh );
w = ww/mainD.dpi;
@@ -1269,25 +1501,32 @@ lprintf("mainRedraw\n");
pixelBins /= 2.0;
}
}
- ConstraintOrig( &mainD.orig, mainD.size );
+ ConstraintOrig( &mainD.orig, mainD.size, bNoBorder, FALSE );
tempD.orig = mainD.orig;
- wDrawClear( mainD.d );
- currRedraw++;
- DrawSnapGrid( &tempD, mapD.size, TRUE );
- DrawRoomWalls( TRUE );
- orig = mainD.orig;
- size = mainD.size;
- orig.x -= RBORDER/mainD.dpi*mainD.scale;
- orig.y -= BBORDER/mainD.dpi*mainD.scale;
- size.x += (RBORDER+LBORDER)/mainD.dpi*mainD.scale;
- size.y += (BBORDER+TBORDER)/mainD.dpi*mainD.scale;
- DrawTracks( &mainD, mainD.scale, orig, size );
- RulerRedraw( FALSE );
- DoCurCommand( C_REDRAW, zero );
- DrawMarkers();
- wSetCursor( wCursorNormal );
- InfoScale();
- wDrawDelayUpdate( mainD.d, FALSE );
+ tempD.size = mainD.size;
+ mainCenter.x = mainD.orig.x + mainD.size.x/2.0;
+ mainCenter.y = mainD.orig.y + mainD.size.y/2.0;
+ DrawMapBoundingBox( TRUE );
+
+ if ( bRedraw )
+ MainRedraw();
+
+ if ( bRedraw && wDrawDoTempDraw ) { // Temporary until mswlib supports TempDraw
+ wAction_t action = wActionMove;
+ coOrd pos;
+ if ( mouseState == mouseLeft )
+ action = wActionLDrag;
+ if ( mouseState == mouseRight )
+ action = wActionRDrag;
+ mainD.Pix2CoOrd( &mainD, mousePositionx, mousePositiony, &pos );
+ // Prevent recursion if curCommand calls MainLayout when action if a Move or Drag
+ // ie CmdPan
+ static int iRecursion = 0;
+ iRecursion++;
+ if ( iRecursion == 1 )
+ DoMouse( action, pos );
+ iRecursion--;
+ }
}
/**
@@ -1305,7 +1544,6 @@ void MainProc( wWin_p win, winProcEvent e, void * refresh, void * data )
case wResize_e:
if (mainD.d == NULL)
return;
- if (refresh) DrawMapBoundingBox( FALSE );
wWinGetSize( mainW, &width, &height );
LayoutToolBar(refresh);
height -= (toolbarHeight+max(infoHeight,textHeight)+10);
@@ -1313,13 +1551,11 @@ void MainProc( wWin_p win, winProcEvent e, void * refresh, void * data )
wDrawSetSize( mainD.d, width-20, height, refresh );
wControlSetPos( (wControl_p)mainD.d, 0, toolbarHeight );
SetMainSize();
- ConstraintOrig( &mainD.orig, mainD.size );
- tempD.orig = mainD.orig;
SetInfoBar();
- if (!refresh) {
- MainRedraw();
- MapRedraw();
- } else DrawMapBoundingBox( TRUE );
+ panCenter.x = mainD.orig.x + mainD.size.x/2.0;
+ panCenter.y = mainD.orig.y + mainD.size.y/2.0;
+ LOG( log_pan, 2, ( "PanCenter:%d %0.3f %0.3f\n", __LINE__, panCenter.x, panCenter.y ) );
+ MainLayout( !refresh, TRUE ); // MainProc: wResize_e event
wPrefSetInteger( "draw", "mainwidth", width );
wPrefSetInteger( "draw", "mainheight", height );
} else DrawMapBoundingBox( TRUE );
@@ -1363,7 +1599,7 @@ EXPORT void DoRedraw( void )
#endif
#endif
MapRedraw();
- MainRedraw();
+ MainRedraw(); // DoRedraw
#ifdef WINDOWS
#ifndef WIN32
if (profRedraw)
@@ -1381,31 +1617,54 @@ EXPORT void DoRedraw( void )
*/
-static void DrawRoomWalls( wBool_t t )
+static void DrawRoomWalls( wBool_t drawBackground )
{
- coOrd p01, p11, p10;
+ coOrd p00, p01, p11, p10;
+ int p0,p1,p2,p3;
if (mainD.d == NULL)
return;
- DrawTicks( &mainD, mapD.size );
+ if (drawBackground) {
+ mainD.CoOrd2Pix(&mainD,mainD.orig,&p0,&p1);
+ coOrd end;
+ end.x = mainD.orig.x + mainD.size.x;
+ end.y = mainD.orig.y + mainD.size.y;
+ mainD.CoOrd2Pix(&mainD,end,&p2,&p3);
+ p2 -= p0;
+ p3 -= p1;
+ wDrawFilledRectangle( mainD.d, p0, p1, p2, p3, drawColorGrey80, 0 );
+
+ mainD.CoOrd2Pix(&mainD,zero,&p0,&p1);
+ mainD.CoOrd2Pix(&mainD,mapD.size,&p2,&p3);
+ p2 -= p0;
+ p3 -= p1;
+ wDrawFilledRectangle( mainD.d, p0, p1, p2, p3, drawColorWhite, 0 );
+
+ } else {
+
+ DrawTicks( &mainD, mapD.size );
- p01.x = p10.y = 0.0;
- p11.x = p10.x = mapD.size.x;
- p01.y = p11.y = mapD.size.y;
- DrawLine( &mainD, p01, p11, 3, t?borderColor:wDrawColorWhite );
- DrawLine( &mainD, p11, p10, 3, t?borderColor:wDrawColorWhite );
+ p00.x = 0.0; p00.y = 0.0;
+ p01.x = p10.y = 0.0;
+ p11.x = p10.x = mapD.size.x;
+ p01.y = p11.y = mapD.size.y;
+ DrawLine( &mainD, p01, p11, 3, borderColor );
+ DrawLine( &mainD, p11, p10, 3, borderColor );
+ DrawLine( &mainD, p00, p01, 3, borderColor );
+ DrawLine( &mainD, p00, p10, 3, borderColor );
+ }
}
-EXPORT void DrawMarkers( void )
+static void DrawMarkers( void )
{
wPos_t x, y;
mainD.CoOrd2Pix(&mainD,oldMarker,&x,&y);
- wDrawLine( mainD.d, 0, y, (wPos_t)LBORDER, y,
+ wDrawLine( tempD.d, 0, y, (wPos_t)LBORDER, y,
0, wDrawLineSolid, markerColor, wDrawOptTemp );
- wDrawLine( mainD.d, x, 0, x, (wPos_t)BBORDER,
+ wDrawLine( tempD.d, x, 0, x, (wPos_t)BBORDER,
0, wDrawLineSolid, markerColor, wDrawOptTemp );
}
@@ -1433,9 +1692,9 @@ EXPORT void DrawRuler(
wFontSize_t fs;
long mm, mm0, mm1, power;
wPos_t x0, y0, x1, y1;
- long dxn, dyn;
- static int lengths[8] = {
- 0, 2, 4, 2, 6, 2, 4, 2 };
+
+ static double lengths[16] = {
+ 0, 2.0, 4.0, 2.0, 6.0, 2.0, 4.0, 2.0, 8.0, 2.0, 4.0, 2.0, 6.0, 2.0, 4.0, 2.0 };
int fraction, incr, firstFraction, lastFraction;
int majorLength;
coOrd p0, p1;
@@ -1445,17 +1704,8 @@ EXPORT void DrawRuler(
Translate( &pos0, pos0, a, offset );
Translate( &pos1, pos1, a, offset );
aa = NormalizeAngle(a+(tickSide==0?+90:-90));
- if (aa > 90.0 && aa < 270.0) {
-#ifdef WINDOWS
- dyn = -17;
-#else
- dyn = -12;
-#endif
- } else {
- dyn = +3;
- }
sin_aa = sin(D2R(aa));
- dxn = (long)floor(10.0*sin_aa);
+
end = FindDistance( pos0, pos1 );
if (end < 0.1)
return;
@@ -1479,7 +1729,7 @@ EXPORT void DrawRuler(
if (units == UNITS_METRIC) {
mm0 = (int)ceil(start*25.4-0.5);
mm1 = (int)floor(end*25.4+0.5);
- len = 2;
+ len = 5;
if (d->scale <= 1) {
power = 1;
} else if (d->scale <= 8) {
@@ -1501,7 +1751,7 @@ EXPORT void DrawRuler(
wDrawLine( d->d, x0, y0, x1, y1,
0, wDrawLineSolid, color, (wDrawOpts)d->funcs->options );
- if (!number)
+ if (!number || (d->scale>40 && mm != 0.0))
continue;
if ( (power>=1000) ||
(d->scale<=8 && power>=100) ||
@@ -1509,15 +1759,21 @@ EXPORT void DrawRuler(
if (mm%100 != 0) {
sprintf(message, "%ld", mm/10%10 );
fs = rulerFontSize*2/3;
- p0.x = p1.x+4*dxn/10*d->scale/mainD.dpi;
- p0.y = p1.y+dyn*d->scale/mainD.dpi;
+ Translate( &p0, p0, aa, (fs/2.0+len)*d->scale/mainD.dpi );
+ Translate( &p0, p0, 225, fs*d->scale/mainD.dpi );
+ //p0.x = p1.x+4*dxn/10*d->scale/mainD.dpi;
+ //p0.y = p1.y+dyn*d->scale/mainD.dpi;
} else {
sprintf(message, "%0.1f", mm/1000.0 );
fs = rulerFontSize;
- p0.x = p0.x+((-(LBORDER-2)/2)+((LBORDER-2)/2+2)*sin_aa)*d->scale/mainD.dpi;
- p0.y = p1.y+dyn*d->scale/mainD.dpi;
+ Translate( &p0, p0, aa, (fs/2.0+len)*d->scale/mainD.dpi );
+ Translate( &p0, p0, 225, 1.5*fs*d->scale/mainD.dpi );
+ //p0.x = p0.x+((-(LBORDER-2)/2)+((LBORDER-2)/2+2)*sin_aa)*d->scale/mainD.dpi;
+ //p0.y = p1.y+dyn*d->scale/mainD.dpi;
}
d->CoOrd2Pix( d, p0, &x0, &y0 );
+ if (x0<0) x0 = 0;
+ if (y0<0) y0 = 0;
wDrawString( d->d, x0, y0, d->angle, message, rulerFp,
fs, color, (wDrawOpts)d->funcs->options );
}
@@ -1526,41 +1782,50 @@ EXPORT void DrawRuler(
}
} else {
if (d->scale <= 1)
- incr = 1;
- else if (d->scale <= 2)
- incr = 2;
- else if (d->scale <= 4)
- incr = 4;
+ incr = 1; //16ths
+ else if (d->scale <= 3)
+ incr = 2; //8ths
+ else if (d->scale <= 5)
+ incr = 4; //4ths
+ else if (d->scale <= 7)
+ incr = 8; //1/2ths
+ else if (d->scale <= 48)
+ incr = 32;
else
- incr = 8;
+ incr = 16; //Inches
lastInch = (int)floor(end);
- lastFraction = 7;
+ lastFraction = 16;
inch = (int)ceil(start);
- firstFraction = (((int)((inch-start)*8/*+1*/)) / incr) * incr;
+ firstFraction = (((int)((inch-start)*16/*+1*/)) / incr) * incr;
if (firstFraction > 0) {
inch--;
- firstFraction = 8 - firstFraction;
+ firstFraction = 16 - firstFraction;
}
for ( ; inch<=lastInch; inch++){
if (inch % 12 == 0) {
- lengths[0] = 10;
+ lengths[0] = 12;
majorLength = 16;
digit = (int)(inch/12);
fs = rulerFontSize;
quote = '\'';
} else if (d->scale <= 8) {
- lengths[0] = 8;
- majorLength = 13;
+ lengths[0] = 12;
+ majorLength = 16;
digit = (int)(inch%12);
fs = rulerFontSize*(2.0/3.0);
quote = '"';
+ } else if (d->scale <= 16){
+ lengths[0] = 10;
+ majorLength = 12;
+ digit = (int)(inch%12);
+ fs = rulerFontSize*(1.0/2.0);
} else {
continue;
}
if (inch == lastInch)
- lastFraction = (((int)((end - lastInch)*8)) / incr) * incr;
+ lastFraction = (((int)((end - lastInch)*16)) / incr) * incr;
for ( fraction = firstFraction; fraction<=lastFraction; fraction += incr ) {
- Translate( &p0, orig, a, inch+fraction/8.0 );
+ Translate( &p0, orig, a, inch+fraction/16.0 );
Translate( &p1, p0, aa, lengths[fraction]*d->scale/72.0 );
d->CoOrd2Pix( d, p0, &x0, &y0 );
d->CoOrd2Pix( d, p1, &x1, &y1 );
@@ -1571,13 +1836,17 @@ EXPORT void DrawRuler(
/* KLUDGE: can't draw invertable strings on windows */
if ( (opts&DO_TEMP) == 0)
#endif
- if ( fraction == 0 && number == TRUE) {
- if (inch % 12 == 0 || d->scale <= 2) {
- Translate( &p0, p0, aa, majorLength*d->scale/72.0 );
- Translate( &p0, p0, 225, 11*d->scale/72.0 );
- sprintf(message, "%d%c", digit, quote );
- d->CoOrd2Pix( d, p0, &x0, &y0 );
- wDrawString( d->d, x0, y0, d->angle, message, rulerFp, fs, color, (wDrawOpts)d->funcs->options );
+ if (fraction == 0) {
+ if ( (number == TRUE && d->scale<40) || (digit==0)) {
+ if (inch % 12 == 0 || d->scale <= 2) {
+ Translate( &p0, p0, aa, majorLength*d->scale/mainD.dpi );
+ Translate( &p0, p0, 225, fs*d->scale/mainD.dpi );
+ sprintf(message, "%d%c", digit, quote );
+ d->CoOrd2Pix( d, p0, &x0, &y0 );
+ if (x0<0) x0 = 0;
+ if (y0<0) y0 = 0;
+ wDrawString( d->d, x0, y0, d->angle, message, rulerFp, fs, color, (wDrawOpts)d->funcs->options );
+ }
}
}
firstFraction = 0;
@@ -1587,28 +1856,49 @@ EXPORT void DrawRuler(
}
-EXPORT void DrawTicks( drawCmd_p d, coOrd size )
+static void DrawTicks( drawCmd_p d, coOrd size )
{
coOrd p0, p1;
DIST_T offset;
offset = 0.0;
- if ( d->orig.x<0.0 )
- offset = d->orig.x;
- p0.x = 0.0/*d->orig.x*/; p1.x = size.x;
- p0.y = p1.y = /*max(d->orig.y,0.0)*/ d->orig.y;
+ double blank_zone = 40*d->scale/72.0;
+
+ if ( d->orig.x<0.0-blank_zone ) {
+ p0.y = 0.0; p1.y = mapD.size.y;
+ p0.x = p1.x = 0.0;
+ DrawRuler( d, p0, p1, offset, FALSE, TRUE, borderColor );
+ }
+ if (d->orig.x+d->size.x>mapD.size.x+blank_zone) {
+ p0.y = 0.0; p1.y = mapD.size.y;
+ p0.x = p1.x = mapD.size.x;
+ DrawRuler( d, p0, p1, offset, FALSE, FALSE, borderColor );
+ }
+ p0.x = 0.0; p1.x = d->size.x;
+ offset = d->orig.x;
+ p0.y = p1.y = d->orig.y;
DrawRuler( d, p0, p1, offset, TRUE, FALSE, borderColor );
- p0.y = p1.y = min(d->orig.y + d->size.y, size.y);
+ p0.y = p1.y = d->size.y+d->orig.y;
DrawRuler( d, p0, p1, offset, FALSE, TRUE, borderColor );
+
offset = 0.0;
- if ( d->orig.y<0.0 )
- offset = d->orig.y;
- p0.y = 0.0/*d->orig.y*/; p1.y = max(size.y,0.0);
+ if ( d->orig.y<0.0-blank_zone) {
+ p0.x = 0.0; p1.x = mapD.size.x;
+ p0.y = p1.y = 0.0;
+ DrawRuler( d, p0, p1, offset, FALSE, FALSE, borderColor );
+ }
+ if (d->orig.y+d->size.y>mapD.size.y+blank_zone) {
+ p0.x = 0.0; p1.x = mapD.size.x;
+ p0.y = p1.y = mapD.size.y;
+ DrawRuler( d, p0, p1, offset, FALSE, TRUE, borderColor );
+ }
+ p0.y = 0.0; p1.y = d->size.y;
+ offset = d->orig.y;
p0.x = p1.x = d->orig.x;
DrawRuler( d, p0, p1, offset, TRUE, TRUE, borderColor );
- p0.x = p1.x = min(d->orig.x + d->size.x, size.x);
+ p0.x = p1.x = d->size.x+d->orig.x;
DrawRuler( d, p0, p1, offset, FALSE, FALSE, borderColor );
}
@@ -1621,54 +1911,74 @@ EXPORT void DrawTicks( drawCmd_p d, coOrd size )
EXPORT coOrd mainCenter;
-EXPORT void DrawMapBoundingBox( BOOL_T set )
+static void DrawMapBoundingBox( BOOL_T set )
{
if (mainD.d == NULL || mapD.d == NULL)
return;
- DrawHilight( &mapD, mainD.orig, mainD.size );
+ wDrawSetTempMode( mapD.d, TRUE );
+ DrawHilight( &mapD, mainD.orig, mainD.size, TRUE );
+ wDrawSetTempMode( mapD.d, FALSE );
}
-static void ConstraintOrig( coOrd * orig, coOrd size )
+static void ConstraintOrig( coOrd * orig, coOrd size, wBool_t bNoBorder, wBool_t round )
{
LOG( log_pan, 2, ( "ConstraintOrig [ %0.3f, %0.3f ] RoomSize(%0.3f %0.3f), WxH=%0.3fx%0.3f",
orig->x, orig->y, mapD.size.x, mapD.size.y,
size.x, size.y ) )
- if (orig->x+size.x > mapD.size.x ) {
- orig->x = mapD.size.x-size.x;
- orig->x += (units==UNITS_ENGLISH?1.0:(1.0/2.54));
+ coOrd bound = zero;
+
+ if ( !bNoBorder ) {
+ bound.x = size.x/2;
+ bound.y = size.y/2;
}
- if (orig->x < 0)
- orig->x = 0;
- if (orig->y+size.y > mapD.size.y ) {
- orig->y = mapD.size.y-size.y;
- orig->y += (units==UNITS_ENGLISH?1.0:1.0/2.54);
+
+
+ if (orig->x > 0.0) {
+ if ((orig->x+size.x) > (mapD.size.x+bound.x)) {
+ orig->x = mapD.size.x-size.x+bound.x;
+ //orig->x += (units==UNITS_ENGLISH?1.0:(1.0/2.54));
+ }
}
- if (orig->y < 0)
- orig->y = 0;
- if (mainD.scale >= 1.0) {
- if (units == UNITS_ENGLISH) {
- orig->x = floor(orig->x*4)/4; //>1:1 = 1/4 inch
- orig->y = floor(orig->y*4)/4;
- } else {
- orig->x = floor(orig->x*2.54*2)/(2.54*2); //>1:1 = 0.5 cm
- orig->y = floor(orig->y*2.54*2)/(2.54*2);
+ if (orig->x < (0-bound.x))
+ orig->x = 0-bound.x;
+
+ if (orig->y > 0.0) {
+ if ((orig->y+size.y) > (mapD.size.y+bound.y) ) {
+ orig->y = mapD.size.y-size.y+bound.y;
+ //orig->y += (units==UNITS_ENGLISH?1.0:1.0/2.54);
+
}
- } else {
- if (units == UNITS_ENGLISH) {
- orig->x = floor(orig->x*64)/64; //<1:1 = 1/64 inch
- orig->y = floor(orig->y*64)/64;
+ }
+
+ if (orig->y < (0-bound.y))
+ orig->y = 0-bound.y;
+
+ if (round) {
+ if (mainD.scale >= 1.0) {
+ if (units == UNITS_ENGLISH) {
+ orig->x = floor(orig->x*4)/4; //>1:1 = 1/4 inch
+ orig->y = floor(orig->y*4)/4;
+ } else {
+ orig->x = floor(orig->x*2.54*2)/(2.54*2); //>1:1 = 0.5 cm
+ orig->y = floor(orig->y*2.54*2)/(2.54*2);
+ }
} else {
- orig->x = floor(orig->x*25.4*2)/(25.4*2); //>1:1 = 0.5 mm
- orig->y = floor(orig->y*25.4*2)/(25.4*2);
+ if (units == UNITS_ENGLISH) {
+ orig->x = floor(orig->x*64)/64; //<1:1 = 1/64 inch
+ orig->y = floor(orig->y*64)/64;
+ } else {
+ orig->x = floor(orig->x*25.4*2)/(25.4*2); //>1:1 = 0.5 mm
+ orig->y = floor(orig->y*25.4*2)/(25.4*2);
+ }
}
}
- orig->x = (long)(orig->x*pixelBins+0.5)/pixelBins;
- orig->y = (long)(orig->y*pixelBins+0.5)/pixelBins;
-LOG( log_pan, 2, ( " = [ %0.3f %0.3f ]\n", orig->y, orig->y ) )
+ //orig->x = (long)(orig->x*pixelBins+0.5)/pixelBins;
+ //orig->y = (long)(orig->y*pixelBins+0.5)/pixelBins;
+ LOG( log_pan, 2, ( " = [ %0.3f %0.3f ]\n", orig->y, orig->y ) )
}
/**
@@ -1676,18 +1986,29 @@ LOG( log_pan, 2, ( " = [ %0.3f %0.3f ]\n", orig->y, orig->y ) )
*
* \param IN zoomM Menu to which radio button is added
* \param IN zoomSubM Second menu to which radio button is added, ignored if NULL
+ * \param IN ctxMenu1
+ * \param IN ctxMenu2
*
*/
-EXPORT void InitCmdZoom( wMenu_p zoomM, wMenu_p zoomSubM )
+EXPORT void InitCmdZoom( wMenu_p zoomM, wMenu_p zoomSubM, wMenu_p ctxMenu1, wMenu_p panMenu )
{
int inx;
for ( inx=0; inx<sizeof zoomList/sizeof zoomList[0]; inx++ ) {
- if( zoomList[ inx ].value >= 1.0 ) {
- zoomList[inx].btRadio = wMenuRadioCreate( zoomM, "cmdZoom", zoomList[inx].name, 0, (wMenuCallBack_p)DoZoom, (void *)(&(zoomList[inx].value)));
+ if( (zoomList[ inx ].value >= 1.0 && zoomList[ inx ].value<=10 ) ||
+ (ceil(log2(zoomList[ inx ].value)) == floor(log2(zoomList[ inx ].value))))
+ {
+ if (zoomM)
+ zoomList[inx].btRadio = wMenuRadioCreate( zoomM, "cmdZoom", zoomList[inx].name, 0, (wMenuCallBack_p)DoZoom, (void *)(&(zoomList[inx].value)));
if( zoomSubM )
zoomList[inx].pdRadio = wMenuRadioCreate( zoomSubM, "cmdZoom", zoomList[inx].name, 0, (wMenuCallBack_p)DoZoom, (void *)(&(zoomList[inx].value)));
+ if (panMenu)
+ zoomList[inx].panRadio = wMenuRadioCreate( panMenu, "cmdZoom", zoomList[inx].name, 0, (wMenuCallBack_p)DoZoom, (void *)(&(zoomList[inx].value)));
+ }
+ if ((zoomList[inx].value >=1.0 && zoomList[inx].value <= 10.0) || (ceil(log2(zoomList[ inx ].value)) == floor(log2(zoomList[ inx ].value)))) {
+ if (ctxMenu1)
+ zoomList[inx].ctxRadio1 = wMenuRadioCreate( ctxMenu1, "cmdZoom", zoomList[inx].name, 0, (wMenuCallBack_p)DoZoom, (void *)(&(zoomList[inx].value)));
}
}
}
@@ -1706,11 +2027,14 @@ static void SetZoomRadio( DIST_T scale )
for ( inx=0; inx<sizeof zoomList/sizeof zoomList[0]; inx++ ) {
if( curScale == zoomList[inx].value ) {
-
- wMenuRadioSetActive( zoomList[inx].btRadio );
+ if (zoomList[inx].btRadio)
+ wMenuRadioSetActive( zoomList[inx].btRadio );
if( zoomList[inx].pdRadio )
wMenuRadioSetActive( zoomList[inx].pdRadio );
-
+ if (zoomList[inx].ctxRadio1)
+ wMenuRadioSetActive( zoomList[inx].ctxRadio1 );
+ if (zoomList[inx].panRadio)
+ wMenuRadioSetActive( zoomList[inx].panRadio );
/* activate / deactivate zoom buttons when appropriate */
wControlLinkedActive( (wControl_p)zoomUpB, ( inx != 0 ) );
wControlLinkedActive( (wControl_p)zoomDownB, ( inx < (sizeof zoomList/sizeof zoomList[0] - 1)));
@@ -1768,7 +2092,6 @@ static void DoNewScale( DIST_T scale )
if (scale > MAX_MAIN_SCALE)
scale = MAX_MAIN_SCALE;
- DrawHilight( &mapD, mainD.orig, mainD.size );
tempD.scale = mainD.scale = scale;
mainD.dpi = wDrawGetDPI( mainD.d );
if ( mainD.dpi == 75 ) {
@@ -1781,21 +2104,10 @@ static void DoNewScale( DIST_T scale )
SetZoomRadio( scale );
InfoScale();
SetMainSize();
- if (zoomCorner) {
- mainCenter.x = mainD.orig.x + mainD.size.x/2.0;
- mainCenter.y = mainD.orig.y + mainD.size.y/2.0;
- } else {
- mainD.orig.x = mainCenter.x - mainD.size.x/2.0;
- mainD.orig.y = mainCenter.y - mainD.size.y/2.0;
- }
- ConstraintOrig( &mainD.orig, mainD.size );
- MainRedraw();
- tempD.orig = mainD.orig;
+ PanHere( (void*)1 );
LOG( log_zoom, 1, ( "center = [%0.3f %0.3f]\n", mainCenter.x, mainCenter.y ) )
- /*SetFont(0);*/
sprintf( tmp, "%0.3f", mainD.scale );
wPrefSetString( "draw", "zoom", tmp );
- DrawHilight( &mapD, mainD.orig, mainD.size );
if (recordF) {
fprintf( recordF, "ORIG %0.3f %0.3f %0.3f\n",
mainD.scale, mainD.orig.x, mainD.orig.y );
@@ -1814,6 +2126,7 @@ EXPORT void DoZoomUp( void * mode )
long newScale;
int i;
+ LOG( log_zoom, 2, ( "DoZoomUp KS:%x\n", MyGetKeyState() ) );
if ( mode != NULL || (MyGetKeyState()&WKEY_SHIFT) == 0) {
i = ScaleInx( mainD.scale );
if (i < 0) i = NearestScaleInx(mainD.scale, TRUE);
@@ -1826,12 +2139,12 @@ EXPORT void DoZoomUp( void * mode )
if (mainD.scale <=1.0)
InfoMessage(_("Macro Zoom Mode"));
else
- InfoMessage(_("Use Shift+PageDwn to jump to preset Zoom In"));
+ InfoMessage("");
DoNewScale( zoomList[ i - 1 ].value );
- } else InfoMessage("Min Macro Zoom");
+ } else InfoMessage("Minimum Macro Zoom");
} else {
- InfoMessage(_("Scale 1:1 - Use Ctrl+PageDwn to go to Macro Zoom Mode"));
+ InfoMessage(_("Scale 1:1 - Use Ctrl+ to go to Macro Zoom Mode"));
}
} else if ( (MyGetKeyState()&WKEY_CTRL) == 0 ) {
wPrefGetInteger( "misc", "zoomin", &newScale, 4 );
@@ -1843,6 +2156,22 @@ EXPORT void DoZoomUp( void * mode )
}
}
+EXPORT void DoZoomExtents( void * mode) {
+
+ DIST_T scale_x, scale_y;
+ scale_x = mapD.size.x/(mainD.size.x/mainD.scale);
+ scale_y = mapD.size.y/(mainD.size.y/mainD.scale);
+ if (scale_x<scale_y)
+ scale_x = scale_y;
+ scale_x = ceil(scale_x);
+ if (scale_x < 1) scale_x = 1;
+ if (scale_x > MAX_MAIN_SCALE) scale_x = MAX_MAIN_SCALE;
+ mainD.orig = zero;
+ DoNewScale(scale_x);
+ MainLayout(TRUE,TRUE);
+
+}
+
/**
* User selected zoom out, via mouse wheel, button or pulldown.
@@ -1855,11 +2184,12 @@ EXPORT void DoZoomDown( void * mode)
long newScale;
int i;
+ LOG( log_zoom, 2, ( "DoZoomDown KS:%x\n", MyGetKeyState() ) );
if ( mode != NULL || (MyGetKeyState()&WKEY_SHIFT) == 0 ) {
i = ScaleInx( mainD.scale );
if (i < 0) i = NearestScaleInx(mainD.scale, TRUE);
if( i>= 0 && i < ( sizeof zoomList/sizeof zoomList[0] - 1 )) {
- InfoMessage(_("Use Shift+PageUp to jump to preset Zoom Out"));
+ InfoMessage("");
DoNewScale( zoomList[ i + 1 ].value );
} else
InfoMessage(_("At Maximum Zoom Out"));
@@ -1913,11 +2243,102 @@ EXPORT void CoOrd2Pix(
*y = (wPos_t)((pos.y-d->orig.y)/d->scale*d->dpi);
}
+/*
+* Position mainD based on panCenter
+* \param mode control effect of constrainMain and CTRL key
+*
+* mode:
+* - 0: constrain if constrainMain==1 or CTRL is pressed
+* - 1: same as 0, but ignore CTRL
+* - 2: same as 0, plus liveMap
+* - 3: Take position from menuPos
+*/
+EXPORT void PanHere(void * mode) {
+ if ( 3 == (long)mode) {
+ panCenter = menuPos;
+ LOG( log_pan, 2, ( "MCenter:Mod-%d %0.3f %0.3f\n", __LINE__, panCenter.x, panCenter.y ) );
+ }
+ mainD.orig.x = panCenter.x - mainD.size.x/2.0;
+ mainD.orig.y = panCenter.y - mainD.size.y/2.0;
+ wBool_t bNoBorder = (constrainMain != 0);
+ if ( 1 != (long)mode )
+ if ( (MyGetKeyState()&WKEY_CTRL)!= 0 )
+ bNoBorder = !bNoBorder;
+ wBool_t bLiveMap = TRUE;
+ if ( 2 == (long)mode )
+ bLiveMap = liveMap;
+
+ MainLayout( bLiveMap, bNoBorder ); // PanHere
+}
+
+
+static void DoPanKeyAction( wAction_t action )
+{
+ switch ((wAccelKey_e)(action>>8)) {
+ case wAccelKey_Del:
+ SelectDelete();
+ return;
+#ifndef WINDOWS
+ case wAccelKey_Pgdn:
+ DoZoomUp(NULL);
+ break;
+ case wAccelKey_Pgup:
+ DoZoomDown(NULL);
+ break;
+#endif
+ case wAccelKey_Right:
+ panCenter.x = mainD.orig.x + mainD.size.x/2;
+ panCenter.y = mainD.orig.y + mainD.size.y/2;
+ if ((MyGetKeyState() & WKEY_SHIFT) != 0)
+ panCenter.x += 0.25*mainD.scale; //~1cm in 1::1, 1ft in 30:1, 1mm in 10:1
+ else
+ panCenter.x += mainD.size.x/2;
+ LOG( log_pan, 2, ( "PanCenter:%d %0.3f %0.3f\n", __LINE__, panCenter.x, panCenter.y ) );
+ PanHere((void*)0);
+ break;
+
+ case wAccelKey_Left:
+ panCenter.x = mainD.orig.x + mainD.size.x/2;
+ panCenter.y = mainD.orig.y + mainD.size.y/2;
+ if ((MyGetKeyState() & WKEY_SHIFT) != 0)
+ panCenter.x -= 0.25*mainD.scale;
+ else
+ panCenter.x -= mainD.size.x/2;
+ LOG( log_pan, 2, ( "PanCenter:%d %0.3f %0.3f\n", __LINE__, panCenter.x, panCenter.y ) );
+ PanHere((void*)0);
+ break;
+
+ case wAccelKey_Up:
+ panCenter.x = mainD.orig.x + mainD.size.x/2;
+ panCenter.y = mainD.orig.y + mainD.size.y/2;
+ if ((MyGetKeyState() & WKEY_SHIFT) != 0)
+ panCenter.y += 0.25*mainD.scale;
+ else
+ panCenter.y += mainD.size.y/2;
+ LOG( log_pan, 2, ( "PanCenter:%d %0.3f %0.3f\n", __LINE__, panCenter.x, panCenter.y ) );
+ PanHere((void*)0);
+ break;
+
+ case wAccelKey_Down:
+ panCenter.x = mainD.orig.x + mainD.size.x/2;
+ panCenter.y = mainD.orig.y + mainD.size.y/2;
+ if ((MyGetKeyState() & WKEY_SHIFT) != 0)
+ panCenter.y -= 0.25*mainD.scale;
+ else
+ panCenter.y -= mainD.size.y/2;
+ LOG( log_pan, 2, ( "PanCenter:%d %0.3f %0.3f\n", __LINE__, panCenter.x, panCenter.y ) );
+ PanHere((void*)0);
+ break;
+
+ default:
+ return;
+ }
+}
+
static void DoMapPan( wAction_t action, coOrd pos )
{
static coOrd mapOrig;
- static coOrd oldOrig, newOrig;
static coOrd size;
static DIST_T xscale, yscale;
static enum { noPan, movePan, resizePan } mode = noPan;
@@ -1930,34 +2351,21 @@ static void DoMapPan( wAction_t action, coOrd pos )
mode = movePan;
else
break;
- mapOrig = pos;
- size = mainD.size;
- newOrig = oldOrig = mainD.orig;
-LOG( log_pan, 1, ( "ORIG = [ %0.3f, %0.3f ]\n", mapOrig.x, mapOrig.y ) )
- break;
case C_MOVE:
if ( mode != movePan )
break;
- DrawHilight( &mapD, newOrig, size );
-LOG( log_pan, 2, ( "NEW = [ %0.3f, %0.3f ] \n", pos.x, pos.y ) )
- newOrig.x = oldOrig.x + pos.x-mapOrig.x;
- newOrig.y = oldOrig.y + pos.y-mapOrig.y;
- ConstraintOrig( &newOrig, mainD.size );
- if (liveMap) {
- tempD.orig = mainD.orig = newOrig;
- MainRedraw();
- }
- DrawHilight( &mapD, newOrig, size );
+// mainD.orig.x = pos.x - mainD.size.x/2.0;
+// mainD.orig.y = pos.y - mainD.size.y/2.0;
+ panCenter = pos;
+LOG( log_pan, 1, ( "%s = [ %0.3f, %0.3f ]\n", action == C_DOWN? "START":"MOVE", mainD.orig.x, mainD.orig.y ) )
+ PanHere( (void*)2 );
break;
case C_UP:
if ( mode != movePan )
break;
- tempD.orig = mainD.orig = newOrig;
- mainCenter.x = newOrig.x + mainD.size.x/2.0;
- mainCenter.y = newOrig.y + mainD.size.y/2.0;
- if (!liveMap)
- MainRedraw();
-LOG( log_pan, 1, ( "FINAL = [ %0.3f, %0.3f ]\n", pos.x, pos.y ) )
+ panCenter = pos;
+ PanHere( (void*)0 );
+LOG( log_pan, 1, ( "FINAL = [ %0.3f, %0.3f ]\n", mainD.orig.x, mainD.orig.y ) )
mode = noPan;
break;
@@ -1966,21 +2374,17 @@ LOG( log_pan, 1, ( "FINAL = [ %0.3f, %0.3f ]\n", pos.x, pos.y ) )
mode = resizePan;
else
break;
- DrawHilight( &mapD, mainD.orig, mainD.size );
- newOrig = pos;
- oldOrig = newOrig;
- xscale = 1;
- size.x = mainD.size.x/mainD.scale;
+ mapOrig = pos;
+ size.x = mainD.size.x/mainD.scale; //How big screen?
size.y = mainD.size.y/mainD.scale;
- newOrig.x -= size.x/2.0;
- newOrig.y -= size.y/2.0;
- DrawHilight( &mapD, newOrig, size );
+ xscale = mainD.scale; //start at current
+ panCenter = pos;
+LOG( log_pan, 1, ( "START %0.3fx%0.3f %0.3f+%0.3f\n", mapOrig.x, mapOrig.y, size.x, size.y ) )
break;
case C_RMOVE:
if ( mode != resizePan )
break;
- DrawHilight( &mapD, newOrig, size );
if (pos.x < 0)
pos.x = 0;
if (pos.x > mapD.size.x)
@@ -1989,103 +2393,42 @@ LOG( log_pan, 1, ( "FINAL = [ %0.3f, %0.3f ]\n", pos.x, pos.y ) )
pos.y = 0;
if (pos.y > mapD.size.y)
pos.y = mapD.size.y;
- size.x = (pos.x - oldOrig.x)*2.0;
- size.y = (pos.y - oldOrig.y)*2.0;
- if (size.x < 0) {
- size.x = - size.x;
- }
- if (size.y < 0) {
- size.y = - size.y;
- }
- xscale = size.x / (mainD.size.x/mainD.scale);
- yscale = size.y / (mainD.size.y/mainD.scale);
+
+ xscale = fabs((pos.x-mapOrig.x)*2.0/size.x);
+ yscale = fabs((pos.y-mapOrig.y)*2.0/size.y);
if (xscale < yscale)
xscale = yscale;
xscale = ceil( xscale );
- if (xscale < 1)
- xscale = 1;
+
+ if (xscale < 0.01)
+ xscale = 0.01;
if (xscale > 64)
xscale = 64;
- size.x = (mainD.size.x/mainD.scale) * xscale;
- size.y = (mainD.size.y/mainD.scale) * xscale;
- newOrig = oldOrig;
- newOrig.x -= size.x/2.0;
- newOrig.y -= size.y/2.0;
- DrawHilight( &mapD, newOrig, size );
- break;
+
+ mainD.size.x = size.x * xscale;
+ mainD.size.y = size.y * xscale;
+ mainD.orig.x = mapOrig.x - mainD.size.x / 2.0;
+ mainD.orig.y = mapOrig.y - mainD.size.y / 2.0;
+ tempD.scale = mainD.scale = xscale;
+ PanHere( (void*)2 );
+LOG( log_pan, 1, ( "MOVE SCL:%0.3f %0.3fx%0.3f %0.3f+%0.3f\n", xscale, mainD.orig.x, mainD.orig.y, mainD.size.x, mainD.size.y ) )
+ InfoScale();
+ break;
case C_RUP:
if ( mode != resizePan )
break;
- tempD.size = mainD.size = size;
- tempD.orig = mainD.orig = newOrig;
- mainCenter.x = newOrig.x + mainD.size.x/2.0;
- mainCenter.y = newOrig.y + mainD.size.y/2.0;
DoNewScale( xscale );
mode = noPan;
break;
- case wActionExtKey:
- mainD.CoOrd2Pix(&mainD,pos,&x,&y);
- switch ((wAccelKey_e)(action>>8)) {
-#ifndef WINDOWS
- case wAccelKey_Pgdn:
- DoZoomUp(NULL);
- return;
- case wAccelKey_Pgup:
- DoZoomDown(NULL);
- return;
- case wAccelKey_F5:
- MainRedraw();
- MapRedraw();
- return;
-#endif
- case wAccelKey_Right:
- //DrawHilight( &mapD, mainD.orig, mainD.size );
- mainD.orig.x += mainD.size.x/2;
- ConstraintOrig( &mainD.orig, mainD.size );
- mainCenter.x = mainD.orig.x + mainD.size.x/2.0;
- mainCenter.y = mainD.orig.y + mainD.size.y/2.0;
- MainRedraw();
- MapRedraw();
- //DrawHilight( &mapD, mainD.orig, mainD.size );
- break;
- case wAccelKey_Left:
- //DrawHilight( &mapD, mainD.orig, mainD.size );
- mainD.orig.x -= mainD.size.x/2;
- ConstraintOrig( &mainD.orig, mainD.size );
- mainCenter.x = mainD.orig.x + mainD.size.x/2.0;
- mainCenter.y = mainD.orig.y + mainD.size.y/2.0;
- MainRedraw();
- MapRedraw();
- //DrawHilight( &mapD, mainD.orig, mainD.size );
- break;
- case wAccelKey_Up:
- //DrawHilight( &mapD, mainD.orig, mainD.size );
- mainD.orig.y += mainD.size.y/2;
- ConstraintOrig( &mainD.orig, mainD.size );
- mainCenter.x = mainD.orig.x + mainD.size.x/2.0;
- mainCenter.y = mainD.orig.y + mainD.size.y/2.0;
- MainRedraw();
- MapRedraw();
- //DrawHilight( &mapD, mainD.orig, mainD.size );
- break;
- case wAccelKey_Down:
- //DrawHilight( &mapD, mainD.orig, mainD.size );
- mainD.orig.y -= mainD.size.y/2;
- ConstraintOrig( &mainD.orig, mainD.size );
- mainCenter.x = mainD.orig.x + mainD.size.x/2.0;
- mainCenter.y = mainD.orig.y + mainD.size.y/2.0;
- MainRedraw();
- MapRedraw();
- //DrawHilight( &mapD, mainD.orig, mainD.size );
- break;
- default:
- return;
- }
- mainD.Pix2CoOrd( &mainD, x, y, &pos );
- InfoPos( pos );
- return;
+ case wActionExtKey:
+ mainD.CoOrd2Pix(&mainD,pos,&x,&y);
+ DoPanKeyAction( action );
+ mainD.Pix2CoOrd( &mainD, x, y, &pos );
+ InfoPos( pos );
+ return;
+
default:
return;
}
@@ -2106,7 +2449,7 @@ EXPORT BOOL_T IsClose(
*
*/
-static int ignoreMoves = 1;
+static int ignoreMoves = 0;
EXPORT void ResetMouseState( void )
{
@@ -2136,6 +2479,31 @@ GetMousePosition( int *x, int *y )
}
}
+coOrd minIncrementSizes() {
+ double x,y;
+ if (mainD.scale >= 1.0) {
+ if (units == UNITS_ENGLISH) {
+ x = 0.25; //>1:1 = 1/4 inch
+ y = 0.25;
+ } else {
+ x = 1/(2.54*2); //>1:1 = 0.5 cm
+ y = 1/(2.54*2);
+ }
+ } else {
+ if (units == UNITS_ENGLISH) {
+ x = 1/64; //<1:1 = 1/64 inch
+ y = 1/64;
+ } else {
+ x = 1/(25.4*2); //>1:1 = 0.5 mm
+ y = 1/(25.4*2);
+ }
+ }
+ coOrd ret;
+ ret.x = x*1.5;
+ ret.y = y*1.5;
+ return ret;
+}
+
static void DoMouse( wAction_t action, coOrd pos )
{
@@ -2149,6 +2517,8 @@ static void DoMouse( wAction_t action, coOrd pos )
RecordMouse( "MOUSE", action, pos.x, pos.y );
}
+
+
switch (action&0xFF) {
case C_UP:
if (mouseState != mouseLeft)
@@ -2196,6 +2566,12 @@ static void DoMouse( wAction_t action, coOrd pos )
if ( deferSubstituteControls[0] )
InfoSubstituteControls( deferSubstituteControls, deferSubstituteLabels );
+// panCenter.y = mainD.orig.y + mainD.size.y/2;
+// panCenter.x = mainD.orig.x + mainD.size.x/2;
+//printf( "PanCenter:%d %0.3f %0.3f\n", __LINE__, panCenter.x, panCenter.y );
+
+ coOrd min = minIncrementSizes();
+
switch ( action&0xFF ) {
case C_DOWN:
case C_RDOWN:
@@ -2209,80 +2585,17 @@ static void DoMouse( wAction_t action, coOrd pos )
case wActionExtKey:
mainD.CoOrd2Pix(&mainD,pos,&x,&y);
if ((MyGetKeyState() &
- (WKEY_SHIFT | WKEY_CTRL)) == (WKEY_SHIFT | WKEY_CTRL)) break; //Allow SHIFT+CTRL for Move
+ (WKEY_SHIFT | WKEY_CTRL)) == (WKEY_SHIFT | WKEY_CTRL) &&
+ ( action>>8 == wAccelKey_Up ||
+ action>>8 == wAccelKey_Down ||
+ action>>8 == wAccelKey_Left ||
+ action>>8 == wAccelKey_Right ))
+ break; //Allow SHIFT+CTRL for Move
if (((action>>8)&0xFF) == wAccelKey_LineFeed) {
action = C_TEXT+((int)(0x0A<<8));
break;
}
- switch ((wAccelKey_e)(action>>8)) {
- case wAccelKey_Del:
- SelectDelete();
- return;
-#ifndef WINDOWS
- case wAccelKey_Pgdn:
- DoZoomUp(NULL);
- break;
- case wAccelKey_Pgup:
- DoZoomDown(NULL);
- break;
-#endif
- case wAccelKey_Right:
- //DrawHilight( &mapD, mainD.orig, mainD.size );
- if ((MyGetKeyState() & WKEY_SHIFT) != 0)
- mainD.orig.x += 0.25*mainD.scale; //~1cm in 1::1, 1ft in 30:1, 1mm in 10:1
- else
- mainD.orig.x += mainD.size.x/2;
- ConstraintOrig( &mainD.orig, mainD.size );
- mainCenter.x = mainD.orig.x + mainD.size.x/2.0;
- mainCenter.y = mainD.orig.y + mainD.size.y/2.0;
- MainRedraw();
- MapRedraw();
- //DrawHilight( &mapD, mainD.orig, mainD.size );
- break;
- case wAccelKey_Left:
- //DrawHilight( &mapD, mainD.orig, mainD.size );
- if ((MyGetKeyState() & WKEY_SHIFT) != 0)
- mainD.orig.x -= 0.25*mainD.scale;
- else
- mainD.orig.x -= mainD.size.x/2;
- ConstraintOrig( &mainD.orig, mainD.size );
- mainCenter.x = mainD.orig.x + mainD.size.x/2.0;
- mainCenter.y = mainD.orig.y + mainD.size.y/2.0;
- MainRedraw();
- MapRedraw();
- //DrawHilight( &mapD, mainD.orig, mainD.size );
- break;
- case wAccelKey_Up:
- //DrawHilight( &mapD, mainD.orig, mainD.size );
- if ((MyGetKeyState() & WKEY_SHIFT) != 0)
- mainD.orig.y += 0.25*mainD.scale;
- else
- mainD.orig.y += mainD.size.y/2;
- ConstraintOrig( &mainD.orig, mainD.size );
- mainCenter.x = mainD.orig.x + mainD.size.x/2.0;
- mainCenter.y = mainD.orig.y + mainD.size.y/2.0;
- MainRedraw();
- MapRedraw();
- //DrawHilight( &mapD, mainD.orig, mainD.size );
- break;
- case wAccelKey_Down:
- //DrawHilight( &mapD, mainD.orig, mainD.size );
- if ((MyGetKeyState() & WKEY_SHIFT) != 0)
- mainD.orig.y -= 0.25*mainD.scale;
- else
- mainD.orig.y -= mainD.size.y/2;
- ConstraintOrig( &mainD.orig, mainD.size );
- mainCenter.x = mainD.orig.x + mainD.size.x/2.0;
- mainCenter.y = mainD.orig.y + mainD.size.y/2.0;
- MainRedraw();
- MapRedraw();
- //DrawHilight( &mapD, mainD.orig, mainD.size );
- break;
- default:
- return;
- }
- mainD.Pix2CoOrd( &mainD, x, y, &pos );
- InfoPos( pos );
+ DoPanKeyAction( action );
return;
case C_TEXT:
if ((action>>8) == 0x0D) {
@@ -2291,10 +2604,12 @@ static void DoMouse( wAction_t action, coOrd pos )
ConfirmReset( TRUE );
return;
}
+ case C_MODKEY:
case C_MOVE:
case C_UP:
case C_RMOVE:
case C_RUP:
+ case C_LDOUBLE:
InfoPos( pos );
/*DrawTempTrack();*/
break;
@@ -2304,6 +2619,26 @@ static void DoMouse( wAction_t action, coOrd pos )
case C_WDOWN:
DoZoomDown((void *)1L);
break;
+ case C_SCROLLUP:
+ panCenter.y = panCenter.y + ((mainD.size.y/20>min.y)?mainD.size.y/20:min.y);
+ LOG( log_pan, 2, ( "PanCenter:%d %0.3f %0.3f\n", __LINE__, panCenter.x, panCenter.y ) );
+ PanHere((void*)1);
+ break;
+ case C_SCROLLDOWN:
+ panCenter.y = panCenter.y - ((mainD.size.y/20>min.y)?mainD.size.y/20:min.y);
+ LOG( log_pan, 2, ( "PanCenter:%d %0.3f %0.3f\n", __LINE__, panCenter.x, panCenter.y ) );
+ PanHere((void*)1);
+ break;
+ case C_SCROLLLEFT:
+ panCenter.x = panCenter.x - ((mainD.size.x/20>min.x)?mainD.size.x/20:min.x);
+ LOG( log_pan, 2, ( "PanCenter:%d %0.3f %0.3f\n", __LINE__, panCenter.x, panCenter.y ) );
+ PanHere((void*)1);
+ break;
+ case C_SCROLLRIGHT:
+ panCenter.x = panCenter.x + ((mainD.size.x/20>min.x)?mainD.size.x/20:min.x);
+ LOG( log_pan, 2, ( "PanCenter:%d %0.3f %0.3f\n", __LINE__, panCenter.x, panCenter.y ) );
+ PanHere((void*)1);
+ break;
default:
NoticeMessage( MSG_DOMOUSE_BAD_OP, _("Ok"), NULL, action&0xFF );
break;
@@ -2382,16 +2717,13 @@ static void DoMousew( wDraw_p d, void * context, wAction_t action, wPos_t x, wPo
}
}
}
- ConstraintOrig( &orig, mainD.size );
- if ( orig.x != mainD.orig.x || orig.y != mainD.orig.y ) {
- //DrawMapBoundingBox( FALSE );
- mainD.orig = orig;
- MainRedraw();
- MapRedraw();
- /*DrawSegs( &tempD, zero, 0.0, &tempSegs(0), tempSegs_da.cnt, trackGauge, wDrawColorBlack );*/
- //DrawMapBoundingBox( TRUE );
- wFlush();
- }
+ mainD.orig = orig;
+ panCenter.x = mainD.orig.x + mainD.size.x/2.0;
+ panCenter.y = mainD.orig.y + mainD.size.y/2.0;
+ LOG( log_pan, 2, ( "PanCenter:%d %0.3f %0.3f\n", __LINE__, panCenter.x, panCenter.y ) );
+ MainLayout( TRUE, TRUE ); // DoMouseW: autopan
+ tempD.orig = mainD.orig;
+ wFlush();
}
}
lastX = x;
@@ -2399,8 +2731,21 @@ static void DoMousew( wDraw_p d, void * context, wAction_t action, wPos_t x, wPo
}
}
mainD.Pix2CoOrd( &mainD, x, y, &pos );
- mousePositionx = x;
- mousePositiony = y;
+ switch (action & 0xFF) {
+ case wActionMove:
+ case wActionLDown:
+ case wActionLDrag:
+ case wActionLUp:
+ case wActionRDown:
+ case wActionRDrag:
+ case wActionRUp:
+ case wActionLDownDouble:
+ mousePositionx = x;
+ mousePositiony = y;
+ break;
+ default:
+ break;
+ }
DoMouse( action, pos );
}
@@ -2413,6 +2758,7 @@ static wBool_t PlaybackMain( char * line )
char *oldLocale = NULL;
oldLocale = SaveLocale("C");
+
rc=sscanf( line, "%d " SCANF_FLOAT_FORMAT SCANF_FLOAT_FORMAT, &action, &pos.x, &pos.y);
RestoreLocale(oldLocale);
@@ -2423,6 +2769,27 @@ static wBool_t PlaybackMain( char * line )
}
return TRUE;
}
+
+static wBool_t PlaybackKey( char * line )
+{
+ int rc;
+ int action = C_TEXT;
+ coOrd pos;
+ char *oldLocale = NULL;
+ int c;
+
+ oldLocale = SaveLocale("C");
+ rc=sscanf( line, "%d " SCANF_FLOAT_FORMAT SCANF_FLOAT_FORMAT, &c, &pos.x, &pos.y );
+ RestoreLocale(oldLocale);
+
+ if (rc != 3) {
+ SyntaxError( "MOUSE", rc, 3 );
+ } else {
+ action = action||c<<8;
+ PlaybackMouse( DoMouse, &mainD, (wAction_t)action, pos, wDrawColorBlack );
+ }
+ return TRUE;
+}
/*****************************************************************************
*
@@ -2440,8 +2807,40 @@ static void MapDlgUpdate(
int inx,
void * valueP )
{
- if ( inx == -1 ) {
- MapWindowShow( FALSE );
+ int width,height;
+ switch(inx) {
+ case wResize_e:
+ if (mapD.d == NULL)
+ return;
+ wWinGetSize( mapW, &width, &height );
+ if (height >= 100) {
+ wControlSetPos( (wControl_p)mapD.d, 0, 0 );
+ double scaleX = (mapD.size.x/((width-DlgSepLeft-DlgSepRight-10)/mapD.dpi));
+ double scaleY = (mapD.size.y/((height-DlgSepTop-DlgSepBottom-10)/mapD.dpi));
+ double scale;
+
+ if (scaleX<scaleY) scale = scaleX;
+ else scale = scaleY;
+
+ if (scale > 256.0) scale = 256.0;
+ if (scale < 0.01) scale = 0.01;
+
+ mapScale = (long)scale;
+
+ mapD.scale = mapScale;
+ ChangeMapScale(FALSE);
+
+ if (mapVisible) {
+ MapRedraw();
+ }
+ wPrefSetInteger( "draw", "mapscale", (long)mapD.scale );
+ }
+ break;
+ case -1:
+ MapWindowShow( FALSE );
+ break;
+ default:
+ break;
}
}
@@ -2449,8 +2848,7 @@ static void MapDlgUpdate(
static void DrawChange( long changes )
{
if (changes & CHANGE_MAIN) {
- MainRedraw();
- MapRedraw();
+ MainLayout( TRUE, FALSE ); // DrawChange: CHANGE_MAIN
}
if (changes &CHANGE_UNITS)
SetInfoBar();
@@ -2459,6 +2857,13 @@ static void DrawChange( long changes )
}
+static void MainLayoutCB(
+ wDraw_p bd, void * pContex, wPos_t px, wPos_t py )
+{
+ MainLayout( TRUE, FALSE );
+}
+
+
EXPORT void DrawInit( int initialZoom )
{
wPos_t w, h;
@@ -2469,9 +2874,9 @@ EXPORT void DrawInit( int initialZoom )
h = h - (toolbarHeight+max(textHeight,infoHeight)+10);
if ( w <= 0 ) w = 1;
if ( h <= 0 ) h = 1;
- tempD.d = mainD.d = wDrawCreate( mainW, 0, toolbarHeight, "", BD_TICKS,
+ tempD.d = mainD.d = wDrawCreate( mainW, 0, toolbarHeight, "", BD_TICKS|BD_MODKEYS,
w, h, &mainD,
- (wDrawRedrawCallBack_p)MainRedraw, DoMousew );
+ (wDrawRedrawCallBack_p)MainLayoutCB, DoMousew );
if (initialZoom == 0) {
WDOUBLE_T tmpR;
@@ -2497,17 +2902,21 @@ EXPORT void DrawInit( int initialZoom )
tempD.dpi = mainD.dpi;
SetMainSize();
+ panCenter.x = mainD.size.x/2 +mainD.orig.x;
+ panCenter.y = mainD.size.y/2 +mainD.orig.y;
mapD.scale = mapScale;
/*w = (wPos_t)((mapD.size.x/mapD.scale)*mainD.dpi + 0.5)+2;*/
/*h = (wPos_t)((mapD.size.y/mapD.scale)*mainD.dpi + 0.5)+2;*/
ParamRegister( &mapPG );
- mapW = ParamCreateDialog( &mapPG, MakeWindowTitle(_("Map")), NULL, NULL, NULL, FALSE, NULL, 0, MapDlgUpdate );
- ChangeMapScale();
+ mapW = ParamCreateDialog( &mapPG, MakeWindowTitle(_("Map")), NULL, NULL, NULL, FALSE, NULL, F_RESIZE, MapDlgUpdate );
+ ChangeMapScale(TRUE);
log_pan = LogFindIndex( "pan" );
log_zoom = LogFindIndex( "zoom" );
log_mouse = LogFindIndex( "mouse" );
+ log_redraw = LogFindIndex( "redraw" );
AddPlaybackProc( "MOUSE ", (playbackProc_p)PlaybackMain, NULL );
+ AddPlaybackProc( "KEY ", (playbackProc_p)PlaybackKey, NULL );
rulerFp = wStandardFont( F_HELV, FALSE, FALSE );
@@ -2524,6 +2933,8 @@ EXPORT void DrawInit( int initialZoom )
#include "bitmaps/pan.xpm"
+EXPORT static wMenu_p panPopupM;
+
static STATUS_T CmdPan(
wAction_t action,
coOrd pos )
@@ -2544,19 +2955,23 @@ static STATUS_T CmdPan(
switch (action&0xFF) {
case C_START:
start_pos = zero;
- panmode = NONE; InfoMessage(_("Left Drag to Pan, Right Drag to Zoom, 0 to set Origin to 0,0, 1-9 to Zoom#, e to set to Extent"));
+ panmode = NONE;
+ InfoMessage(_("Left-Drag to pan, Ctrl+Left-Drag to zoom, 0 to set origin to zero, 1-9 to zoom#, e to set to extents"));
+ wSetCursor(mainD.d,wCursorSizeAll);
break;
case C_DOWN:
- panmode = PAN;
- start_pos = pos;
- InfoMessage(_("Pan Mode - drag point to new position"));
- break;
- case C_RDOWN:
- panmode = ZOOM;
- start_pos = pos;
- base = pos;
- size = zero;
- InfoMessage(_("Zoom Mode - drag Area to Zoom"));
+ if ((MyGetKeyState()&WKEY_CTRL) == 0) {
+ panmode = PAN;
+ start_pos = pos;
+ InfoMessage(_("Pan Mode - drag point to new position"));
+ break;
+ } else {
+ panmode = ZOOM;
+ start_pos = pos;
+ base = pos;
+ size = zero;
+ InfoMessage(_("Zoom Mode - drag area to zoom"));
+ }
break;
case C_MOVE:
if (panmode == PAN) {
@@ -2575,20 +2990,18 @@ static STATUS_T CmdPan(
}
}
if ((fabs(pos.x-start_pos.x) > min_inc) || (fabs(pos.y-start_pos.y) > min_inc)) {
- DrawMapBoundingBox( TRUE );
+ coOrd oldOrig = mainD.orig;
mainD.orig.x -= (pos.x - start_pos.x);
mainD.orig.y -= (pos.y - start_pos.y);
- ConstraintOrig( &mainD.orig, mainD.size );
- tempD.orig = mainD.orig;
- mainCenter.x = mainD.orig.x + mainD.size.x/2.0;
- mainCenter.y = mainD.orig.y + mainD.size.y/2.0;
- DrawMapBoundingBox( TRUE );
+ if ((MyGetKeyState()&WKEY_SHIFT) != 0)
+ ConstraintOrig(&mainD.orig,mainD.size,TRUE,FALSE);
+ if ((oldOrig.x == mainD.orig.x) && (oldOrig.y == mainD.orig.y))
+ InfoMessage(_("Can't move any further in that direction"));
+ else
+ InfoMessage(_("Left click to pan, right click to zoom, 'o' for origin, 'e' for extents"));
}
}
- MainRedraw();
- break;
- case C_RMOVE:
- if (panmode == ZOOM) {
+ else if (panmode == ZOOM) {
base = start_pos;
size.x = pos.x - base.x;
if (size.x < 0) {
@@ -2601,90 +3014,125 @@ static STATUS_T CmdPan(
base.y = pos.y;
}
}
- MainRedraw();
+ panCenter.x = mainD.orig.x + mainD.size.x/2.0;
+ panCenter.y = mainD.orig.y + mainD.size.y/2.0;
+ PanHere( (void*)0 );
break;
- case C_RUP:
+ case C_UP:
+ if (panmode == ZOOM) {
+ scale_x = size.x/mainD.size.x*mainD.scale;
+ scale_y = size.y/mainD.size.y*mainD.scale;
- scale_x = size.x/mainD.size.x*mainD.scale;
- scale_y = size.y/mainD.size.y*mainD.scale;
+ DIST_T oldScale = mainD.scale;
- if (scale_x<scale_y)
- scale_x = scale_y;
- if (scale_x>1) scale_x = ceil( scale_x );
- else scale_x = 1/(ceil(1/scale_x));
+ if (scale_x<scale_y)
+ scale_x = scale_y;
+ if (scale_x>1) scale_x = ceil( scale_x );
+ else scale_x = 1/(ceil(1/scale_x));
- if (scale_x > MAX_MAIN_SCALE) scale_x = MAX_MAIN_SCALE;
- if (scale_x < MIN_MAIN_MACRO) scale_x = MIN_MAIN_MACRO;
+ if (scale_x > MAX_MAIN_SCALE) scale_x = MAX_MAIN_SCALE;
+ if (scale_x < MIN_MAIN_MACRO) scale_x = MIN_MAIN_MACRO;
- mainCenter.x = base.x + size.x/2.0; //Put center for scale in center of square
- mainCenter.y = base.y + size.y/2.0;
- mainD.orig.x = base.x;
- mainD.orig.y = base.y;
+ mainD.orig.x = base.x;
+ mainD.orig.y = base.y;
- panmode = NONE;
- DoNewScale(scale_x);
- MapRedraw();
- break;
- case C_UP:
- panmode = NONE;
+ panmode = NONE;
+ InfoMessage(_("Left Drag to Pan, +CTRL to Zoom, 0 to set Origin to 0,0, 1-9 to Zoom#, e to set to Extent"));
+ DoNewScale(scale_x);
+ break;
+ } else if (panmode == PAN) {
+ panCenter.x = mainD.orig.x + mainD.size.x/2.0;
+ panCenter.y = mainD.orig.y + mainD.size.y/2.0;
+ LOG( log_pan, 2, ( "PanCenter:%d %0.3f %0.3f\n", __LINE__, panCenter.x, panCenter.y ) );
+ panmode = NONE;
+ }
break;
case C_REDRAW:
if (panmode == ZOOM) {
if (base.x && base.y && size.x && size.y)
- DrawHilight( &mainD, base, size );
+ DrawHilight( &tempD, base, size, TRUE );
}
break;
case C_CANCEL:
base = zero;
+ wSetCursor(mainD.d,defaultCursor);
return C_TERMINATE;
case C_TEXT:
panmode = NONE;
- if ((action>>8) == 0x65) { //"e"
- scale_x = mapD.size.x/(mainD.size.x/mainD.scale);
- scale_y = mapD.size.y/(mainD.size.y/mainD.scale);
- if (scale_x<scale_y)
- scale_x = scale_y;
- scale_x = ceil(scale_x);
- if (scale_x < 1) scale_x = 1;
- if (scale_x > MAX_MAIN_SCALE) scale_x = MAX_MAIN_SCALE;
- mainD.orig = zero;
- mainCenter.x = mainD.orig.x + mapD.size.x/2.0;
- mainCenter.y = mainD.orig.y + mapD.size.y/2.0;
- DoNewScale(scale_x);
- ConstraintOrig( &mainD.orig, mainD.size );
- mainCenter.x = mainD.orig.x + mainD.size.x/2.0;
- mainCenter.y = mainD.orig.y + mainD.size.y/2.0;
- MapRedraw();
- MainRedraw();
- }
- if ((action>>8) == 0x30) { //"0"
+
+ if ((action>>8) == 'e') { //"e"
+ DoZoomExtents(0);
+ } else if (((action>>8) == '0') || ((action>>8) == 'o')) { //"0" or "o"
mainD.orig = zero;
- ConstraintOrig( &mainD.orig, mainD.size );
- mainCenter.x = mainD.orig.x + mainD.size.x/2.0;
- mainCenter.y = mainD.orig.y + mainD.size.y/2.0;
- MapRedraw();
- MainRedraw();
- }
- if ((action>>8) >= 0x31 && (action>>8) <= 0x39) { //"1" to "9"
+ panCenter.x = mainD.size.x/2.0;
+ panCenter.y = mainD.size.y/2.0;
+ LOG( log_pan, 2, ( "PanCenter:%d %0.3f %0.3f\n", __LINE__, panCenter.x, panCenter.y ) );
+ MainLayout( TRUE, TRUE ); // CmdPan C_TEXT '0' 'o'
+ } else if ((action>>8) >= '1' && (action>>8) <= '9') { //"1" to "9"
scale_x = (action>>8)&0x0F;
DoNewScale(scale_x);
- MapRedraw();
- MainRedraw();
+ } else if ((action>>8) == 'c') { // "c"
+ panCenter = pos;
+ LOG( log_pan, 2, ( "PanCenter:%d %0.3f %0.3f\n", __LINE__, panCenter.x, panCenter.y ) );
+ PanHere( (void*)0 ); // CmdPan C_TEXT 'c'
}
+
if ((action>>8) == 0x0D) {
+ wSetCursor(mainD.d,defaultCursor);
return C_TERMINATE;
- }
- else if ((action>>8) == 0x1B) {
+ } else if ((action>>8) == 0x1B) {
+ wSetCursor(mainD.d,defaultCursor);
return C_TERMINATE;
}
break;
+ case C_CMDMENU:
+ menuPos = pos;
+ wMenuPopupShow( panPopupM );
+ return C_CONTINUE;
+ break;
}
return C_CONTINUE;
}
+static wMenuPush_p zoomExtents,panOrig,panHere;
+static wMenuPush_p zoomLvl1,zoomLvl2,zoomLvl3,zoomLvl4,zoomLvl5,zoomLvl6,zoomLvl7,zoomLvl8,zoomLvl9;
+
+EXPORT void PanMenuEnter(int key) {
+ int action;
+ action = C_TEXT;
+ action |= key<<8;
+ CmdPan(action,zero);
+}
+
+extern wIndex_t selectCmdInx;
+extern wIndex_t describeCmdInx;
+extern wIndex_t joinCmdInx;
+extern wIndex_t modifyCmdInx;
EXPORT void InitCmdPan( wMenu_p menu )
{
panCmdInx = AddMenuButton( menu, CmdPan, "cmdPan", _("Pan/Zoom"), wIconCreatePixMap(pan_xpm),
- LEVEL0, IC_CANCEL|IC_POPUP|IC_LCLICK|IC_RCLICK|IC_CMDMENU, ACCL_PAN, NULL );
+ LEVEL0, IC_CANCEL|IC_POPUP|IC_LCLICK|IC_CMDMENU, ACCL_PAN, NULL );
+}
+EXPORT void InitCmdPan2( wMenu_p menu )
+{
+ panPopupM = MenuRegister( "Pan Options" );
+ wMenuPushCreate(panPopupM, "cmdSelectMode", GetBalloonHelpStr("cmdSelectMode"), 0, DoCommandB, (void*) (intptr_t) selectCmdInx);
+ wMenuPushCreate(panPopupM, "cmdDescribeMode", GetBalloonHelpStr("cmdDescribeMode"), 0, DoCommandB, (void*) (intptr_t) describeCmdInx);
+ wMenuPushCreate(panPopupM, "cmdModifyMode", GetBalloonHelpStr("cmdModifyMode"), 0, DoCommandB, (void*) (intptr_t) modifyCmdInx);
+ wMenuSeparatorCreate(panPopupM);
+ zoomExtents = wMenuPushCreate( panPopupM, "", _("Zoom to extents - 'e'"), 0, (wMenuCallBack_p)PanMenuEnter, (void*) 'e');
+ zoomLvl1 = wMenuPushCreate( panPopupM, "", _("Zoom to 1:1 - '1'"), 0, (wMenuCallBack_p)PanMenuEnter, (void*) '1');
+ zoomLvl2 = wMenuPushCreate( panPopupM, "", _("Zoom to 1:2 - '2'"), 0, (wMenuCallBack_p)PanMenuEnter, (void*) '2');
+ zoomLvl3 = wMenuPushCreate( panPopupM, "", _("Zoom to 1:3 - '3'"), 0, (wMenuCallBack_p)PanMenuEnter, (void*) '3');
+ zoomLvl4 = wMenuPushCreate( panPopupM, "", _("Zoom to 1:4 - '4'"), 0, (wMenuCallBack_p)PanMenuEnter, (void*) '4');
+ zoomLvl5 = wMenuPushCreate( panPopupM, "", _("Zoom to 1:5 - '5'"), 0, (wMenuCallBack_p)PanMenuEnter, (void*) '5');
+ zoomLvl6 = wMenuPushCreate( panPopupM, "", _("Zoom to 1:6 - '6'"), 0, (wMenuCallBack_p)PanMenuEnter, (void*) '6');
+ zoomLvl7 = wMenuPushCreate( panPopupM, "", _("Zoom to 1:7 - '7'"), 0, (wMenuCallBack_p)PanMenuEnter, (void*) '7');
+ zoomLvl8 = wMenuPushCreate( panPopupM, "", _("Zoom to 1:8 - '8'"), 0, (wMenuCallBack_p)PanMenuEnter, (void*) '8');
+ zoomLvl9 = wMenuPushCreate( panPopupM, "", _("Zoom to 1:9 - '9'"), 0, (wMenuCallBack_p)PanMenuEnter, (void*) '9');
+ panOrig = wMenuPushCreate( panPopupM, "", _("Pan to Origin - 'o'/'0'"), 0, (wMenuCallBack_p)PanMenuEnter, (void*) 'o');
+ wMenu_p zoomPanM = wMenuMenuCreate(panPopupM, "", _("&Zoom"));
+ InitCmdZoom(NULL, NULL, NULL, zoomPanM);
+ panHere = wMenuPushCreate( panPopupM, "", _("Pan center here - 'c'"), 0, (wMenuCallBack_p)PanHere, (void*) 3);
}