diff options
Diffstat (limited to 'app/bin/macro.c')
-rw-r--r-- | app/bin/macro.c | 1022 |
1 files changed, 531 insertions, 491 deletions
diff --git a/app/bin/macro.c b/app/bin/macro.c index 8db996d..7105e98 100644 --- a/app/bin/macro.c +++ b/app/bin/macro.c @@ -1,5 +1,5 @@ /** \file macro.c - + * * Macros */ @@ -18,57 +18,29 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include <assert.h> -#include <stdlib.h> -#include <stdio.h> -#ifndef WINDOWS -#include <unistd.h> -#include <dirent.h> -#include <errno.h> -#endif -#include <math.h> -#include <ctype.h> -#include <string.h> -#include <time.h> -#ifdef WINDOWS -#include <io.h> -#include <windows.h> -#else -#include <sys/stat.h> -#endif -#include <stdarg.h> -#ifndef WINDOWS -#include <sys/time.h> -#else -#include <sys/timeb.h> -#endif -#include <locale.h> - -#include <stdint.h> - #include "common.h" #include "compound.h" #include "cundo.h" #include "custom.h" #include "draw.h" #include "fileio.h" -#include "i18n.h" -#include "messages.h" #include "misc.h" -#include "param.h" +#include "param.h" #include "paths.h" #include "track.h" -#include "trackx.h" -#include "utility.h" #include "version.h" +#include "common-ui.h" + +#ifdef UTFCONVERT +#include "include/utf8convert.h" +#endif // UTFCONVERT EXPORT long adjTimer; static void DemoInitValues( void ); -extern char *userLocale; static int log_playbackCursor = 0; @@ -89,20 +61,23 @@ static paramTextData_t recordTextData = { 50, 16 }; static paramData_t recordPLs[] = { #define I_RECSTOP (0) #define recStopB ((wButton_p)recordPLs[I_RECSTOP].control) - { PD_BUTTON, (void*)DoRecordButton, "stop", PDO_NORECORD, NULL, N_("Stop"), 0, (void*)0 }, + { PD_BUTTON, DoRecordButton, "stop", PDO_NORECORD, NULL, N_("Stop"), 0, I2VP(0) }, #define I_RECMESSAGE (1) #define recMsgB ((wButton_p)recordPLs[I_RECMESSAGE].control) - { PD_BUTTON, (void*)DoRecordButton, "message", PDO_NORECORD|PDO_DLGHORZ, NULL, N_("Message"), 0, (void*)2 }, + { PD_BUTTON, DoRecordButton, "message", PDO_NORECORD|PDO_DLGHORZ, NULL, N_("Message"), 0, I2VP(2) }, #define I_RECEND (2) #define recEndB ((wButton_p)recordPLs[I_RECEND].control) - { PD_BUTTON, (void*)DoRecordButton, "end", PDO_NORECORD|PDO_DLGHORZ, NULL, N_("End"), BO_DISABLED, (void*)4 }, + { PD_BUTTON, DoRecordButton, "end", PDO_NORECORD|PDO_DLGHORZ, NULL, N_("End"), BO_DISABLED, I2VP(4) }, #define I_RECTEXT (3) #define recordT ((wText_p)recordPLs[I_RECTEXT].control) - { PD_TEXT, NULL, "text", PDO_NORECORD|PDO_DLGRESIZE, &recordTextData, NULL, BT_CHARUNITS|BO_READONLY} }; -static paramGroup_t recordPG = { "record", 0, recordPLs, sizeof recordPLs/sizeof recordPLs[0] }; + { PD_TEXT, NULL, "text", PDO_NORECORD|PDO_DLGRESIZE, &recordTextData, NULL, BT_CHARUNITS|BO_READONLY} +}; +static paramGroup_t recordPG = { "record", 0, recordPLs, COUNT( recordPLs ) }; #ifndef WINDOWS +#include <sys/time.h> + static struct timeval lastTim = {0,0}; static void ComputePause( void ) { @@ -111,35 +86,45 @@ static void ComputePause( void ) long msecs; gettimeofday( &tim, NULL ); secs = tim.tv_sec-lastTim.tv_sec; - if (secs > 10 || secs < 0) + if (secs > 10 || secs < 0) { return; + } msecs = secs * 1000 + (tim.tv_usec - lastTim.tv_usec)/1000; - if (msecs > 5000) + if (msecs > 5000) { msecs = 5000; - if (msecs > 1) + } + if (msecs > 1) { fprintf( recordF, "PAUSE %ld\n", msecs ); + } lastTim = tim; } #else -static struct _timeb lastTim; +#include <sys/types.h> +#include <sys/timeb.h> +#include <time.h> + +static struct __timeb64 lastTim; static void ComputePause( void ) { - struct _timeb tim; + struct __timeb64 tim; long secs, msecs; _ftime( &tim ); secs = (long)(tim.time - lastTim.time); - if (secs > 10 || secs < 0) + if (secs > 10 || secs < 0) { return; + } msecs = secs * 1000; if (tim.millitm >= lastTim.millitm) { msecs += (tim.millitm - lastTim.millitm); } else { msecs -= (lastTim.millitm - tim.millitm); } - if (msecs > 5000) + if (msecs > 5000) { msecs = 5000; - if (msecs > 1) + } + if (msecs > 1) { fprintf( recordF, "PAUSE %ld\n", msecs ); + } lastTim = tim; } #endif @@ -148,19 +133,21 @@ static void ComputePause( void ) EXPORT void RecordMouse( char * name, wAction_t action, POS_T px, POS_T py ) { int keyState; - if ( action == C_MOVE || action == C_RMOVE || (action&0xFF) == C_TEXT ) + if ( action == C_MOVE || action == C_RMOVE || (action&0xFF) == C_TEXT ) { ComputePause(); - else if ( action == C_DOWN || action == C_RDOWN ) + } else if ( action == C_DOWN || action == C_RDOWN ) #ifndef WINDOWS gettimeofday( &lastTim, NULL ); #else _ftime( &lastTim ); #endif - if (action == wActionMove && !recordMouseMoves) + if (action == wActionMove && !recordMouseMoves) { return; + } keyState = wGetKeyState(); - if (keyState) + if (keyState) { fprintf( recordF, "KEYSTATE %d\n", keyState ); + } fprintf( recordF, "%s %d %0.3f %0.3f\n", name, (int)action, px, py ); fflush( recordF ); } @@ -170,25 +157,30 @@ static int StartRecord( int cnt, char ** pathName, void * context ) { time_t clock; - assert( pathName != NULL ); - assert( cnt == 1 ); + CHECK( pathName != NULL ); + CHECK( cnt == 1 ); SetCurrentPath( MACROPATHKEY, pathName[0] ); recordF = fopen(pathName[0], "w"); if (recordF==NULL) { - NoticeMessage( MSG_OPEN_FAIL, _("Continue"), NULL, _("Recording"), pathName[0], strerror(errno) ); + NoticeMessage( MSG_OPEN_FAIL, _("Continue"), NULL, _("Recording"), pathName[0], + strerror(errno) ); return FALSE; } time(&clock); - fprintf(recordF, "# %s Version: %s, Date: %s\n", sProdName, sVersion, ctime(&clock) ); + fprintf(recordF, "# %s Version: %s, Date: %s\n", sProdName, sVersion, + ctime(&clock) ); fprintf(recordF, "VERSION %d\n", iParamVersion ); fprintf(recordF, "ROOMSIZE %0.1f x %0.1f\n", mapD.size.x, mapD.size.y ); fprintf(recordF, "SCALE %s\n", curScaleName ); - fprintf(recordF, "ORIG %0.3f %0.3f %0.3f\n", mainD.scale, mainD.orig.x, mainD.orig.y ); - if ( logClock != 0 ) + fprintf(recordF, "ORIG %0.3f %0.3f %0.3f\n", mainD.scale, mainD.orig.x, + mainD.orig.y ); + if ( logClock != 0 ) { fprintf( recordF, "# LOG CLOCK %s\n", ctime(&logClock) ); - if ( logTable_da.cnt > 11 ) + } + if ( logTable_da.cnt > 11 ) { lprintf( "StartRecord( %s ) @ %s\n", pathName, ctime(&clock) ); + } ParamStartRecord(); WriteTracks( recordF, TRUE ); WriteLayers( recordF ); @@ -208,7 +200,7 @@ static void DoRecordButton( void * context ) char * cp; int len; - switch( (int)(long)context ){ + switch( (int)VP2L(context) ) { case 0: /* Stop */ fprintf( recordF, "CLEAR\nMESSAGE\n"); fprintf( recordF, N_("End of Playback. Hit Step to exit\n")); @@ -225,11 +217,12 @@ static void DoRecordButton( void * context ) case 4: /* End */ if (recordingMessage) { len = wTextGetSize( recordT ); - if (len == 0) + if (len == 0) { break; + } cp = (char*)MyMalloc( len+2 ); wTextGetText( recordT, cp, len ); - if ( cp[len-1] == '\n' ) len--; + if ( cp[len-1] == '\n' ) { len--; } cp[len] = '\0'; fprintf( recordF, "%s\n%s\nSTEP\n", cp, END_MESSAGE ); MyFree( cp ); @@ -276,8 +269,10 @@ EXPORT void DoRecord( void * context ) { if (recordW == NULL) { char * title = MakeWindowTitle(_("Record")); - recordW = ParamCreateDialog( &recordPG, title, NULL, NULL, NULL, FALSE, NULL, F_RESIZE, NULL ); - recordFile_fs = wFilSelCreate( mainW, FS_SAVE, 0, title, sRecordFilePattern, StartRecord, NULL ); + recordW = ParamCreateDialog( &recordPG, title, NULL, NULL, NULL, FALSE, NULL, + F_RESIZE, NULL ); + recordFile_fs = wFilSelCreate( mainW, FS_SAVE, 0, title, sRecordFilePattern, + StartRecord, NULL ); } wTextClear( recordT ); wFilSelect( recordFile_fs, GetCurrentPath(MACROPATHKEY )); @@ -292,7 +287,7 @@ EXPORT void DoRecord( void * context ) static drawCmd_p playbackD = NULL; static wDrawBitMap_p playbackBm = NULL; static wDrawColor playbackColor; -static wPos_t playbackX, playbackY; +static coOrd playbackPos; static wBool_t bDoFlash = FALSE; static wDrawColor flashColor; @@ -335,7 +330,8 @@ int DBMCount=0; #define DRAWALL typedef enum { FLASH_PLUS, FLASH_MINUS, REDRAW, CLEAR, DRAW, RESET, ORIG, MOVE_PLYBCK1, MOVE_PLYBCK2, MOVE_PLYBCK3, MOVE_PLYBCK4, QUIT } DrawBitMap_e; -char * DrawBitMapToString(DrawBitMap_e dbm) { +char * DrawBitMapToString(DrawBitMap_e dbm) +{ switch(dbm) { case FLASH_PLUS: return "Flsh+"; @@ -367,20 +363,20 @@ char * DrawBitMapToString(DrawBitMap_e dbm) { } static void MacroDrawBitMap( - DrawBitMap_e dbm, - wDrawBitMap_p bm, - wPos_t x, - wPos_t y, - wDrawColor color ) + DrawBitMap_e dbm, + wDrawBitMap_p bm, + coOrd pos, + wDrawColor color ) { - wDrawBitMap( playbackD->d, bm, x, y, color, wDrawOptTemp|wDrawOptNoClip ); - wFlush(); + DrawBitMap( playbackD, pos, bm, color ); +// wFlush(); - LOG( log_playbackCursor, 1, ("%s %d DrawBitMap( %p %p %d %d %d %d )\n", DrawBitMapToString(dbm), DBMCount++, playbackD->d, bm, x, y, color, wDrawOptTemp|wDrawOptNoClip ) ); + LOG( log_playbackCursor, 2, ("%s %d DrawBitMap( %p %p [%0.3f %0.3f] %d )\n", + DrawBitMapToString(dbm), DBMCount++, playbackD->d, bm, pos, color ) ); } -static void Flash( drawCmd_p d, wPos_t x, wPos_t y, wDrawColor color ) +static void Flash( wDrawColor color ) { bDoFlash = TRUE; flashColor = color; @@ -391,7 +387,7 @@ EXPORT long playbackDelay = 100; static long playbackSpeed = 2; static void SetPlaybackSpeed( - wIndex_t inx ) + wIndex_t inx ) { switch (inx) { case 0: playbackDelay = 500; break; @@ -406,74 +402,70 @@ static void SetPlaybackSpeed( } -EXPORT void RedrawPlaybackCursor() { +EXPORT void RedrawPlaybackCursor() +{ if ( playbackD && playbackBm && inPlayback) { - wBool_t ret; - if ( playbackD->d != mainD.d ) - ret = wDrawSetTempMode( playbackD->d, TRUE ); + unsigned long options = playbackD->options; + playbackD->options |= DC_TEMP; + wBool_t bTemp = wDrawSetTempMode( playbackD->d, TRUE ); if ( bDoFlash && playbackTimer == 0 ) { - MacroDrawBitMap( FLASH_PLUS, flash_bm, playbackX, playbackY, flashColor ); + MacroDrawBitMap( FLASH_PLUS, flash_bm, playbackPos, flashColor ); + wDrawSetTempMode( playbackD->d, FALSE ); wPause( flashTO*2 ); + wDrawSetTempMode( playbackD->d, TRUE ); if ( flashTwice ) { - MacroDrawBitMap( FLASH_PLUS, flash_bm, playbackX, playbackY, flashColor ); + MacroDrawBitMap( FLASH_PLUS, flash_bm, playbackPos, flashColor ); + wDrawSetTempMode( playbackD->d, FALSE ); wPause( flashTO*2 ); + wDrawSetTempMode( playbackD->d, TRUE ); } bDoFlash = FALSE; } - MacroDrawBitMap( DRAW, playbackBm, playbackX, playbackY, playbackColor ); - if ( playbackD->d != mainD.d ) - wDrawSetTempMode( playbackD->d, ret ); + MacroDrawBitMap( DRAW, playbackBm, playbackPos, playbackColor ); + wDrawSetTempMode( playbackD->d, bTemp ); + playbackD->options = options; + wFlush(); } } static void MoveCursor( - drawCmd_p d, - playbackProc proc, - wAction_t action, - coOrd pos, - wDrawBitMap_p bm, - wDrawColor color ) + drawCmd_p d, + playbackProc proc, + wAction_t action, + coOrd pos, + wDrawBitMap_p bm, + wDrawColor color ) { - DIST_T dist, dx, dy; - coOrd pos1, dpos; + DIST_T dist; + coOrd dpos; int i, steps; - wPos_t x, y; - wPos_t x0=playbackX; - wPos_t y0=playbackY; - if (d == NULL) + if (d == NULL) { return; - - d->CoOrd2Pix( d, pos, &x, &y ); + } if (playbackTimer == 0 /*&& !didPause*/) { playbackBm = bm; playbackColor = color; - dx = (DIST_T)(x-x0); - dy = (DIST_T)(y-y0); - dist = sqrt( dx*dx + dy*dy ); - steps = (int)(dist / PixelsPerStep ) + 1; - dx /= steps; - dy /= steps; - d->Pix2CoOrd( d, x0, y0, &pos1 ); - dpos.x = (pos.x-pos1.x)/steps; - dpos.y = (pos.y-pos1.y)/steps; - - for ( i=1; i<=steps; i++ ) { + dist = FindDistance( playbackPos, pos ); + steps = (int)(dist / (PixelsPerStep*d->scale/d->dpi)) + 1; + LOG( log_playbackCursor, 1, + ( "PBC: [%0.3f %0.3f] - [%0.3f %0.3f] Dist:%0.3f Steps:%d\n", playbackPos.x, + playbackPos.y, pos.x, pos.y, dist, steps ) ); - playbackX = x0+(wPos_t)(i*dx); - playbackY = y0+(wPos_t)(i*dy); + dpos.x = (pos.x-playbackPos.x)/steps; + dpos.y = (pos.y-playbackPos.y)/steps; - pos1.x += dpos.x; - pos1.y += dpos.y; + for ( i=1; i<=steps; i++ ) { + playbackPos.x += dpos.x; + playbackPos.y += dpos.y; if ( proc != NULL ) { - proc( action, pos1 ); + proc( action, playbackPos ); } else { TempRedraw(); } -// DrawPlaybackCursor( d, bm, xx, yy, color ); if ( d->d == mainD.d ) { - InfoPos( pos1 ); + InfoPos( playbackPos ); wFlush(); } // Simple mouse moves happen twice as fast @@ -484,91 +476,96 @@ static void MoveCursor( return; } } - } else { - playbackX = x; - playbackY = y; } + playbackPos = pos; } static void PlaybackCursor( - drawCmd_p d, - playbackProc proc, - wAction_t action, - coOrd pos, - wDrawColor color ) + drawCmd_p d, + playbackProc proc, + wAction_t action, + coOrd pos, + wDrawColor color ) { wDrawBitMap_p bm = playbackBm; playbackD = d; - wPos_t x, y; long time0, time1; time0 = wGetTimer(); - d->CoOrd2Pix( d, pos, &x, &y ); - - - switch( action&0xFF ) { case wActionMove: - bm = ((MyGetKeyState()&WKEY_SHIFT)?arrow0_shift_bm:(MyGetKeyState()&WKEY_CTRL)?arrow0_ctl_bm:arrow0_bm); //0 is normal, shift, ctrl + bm = ((MyGetKeyState()&WKEY_SHIFT)?arrow0_shift_bm:(MyGetKeyState()&WKEY_CTRL) + ?arrow0_ctl_bm:arrow0_bm); //0 is normal, shift, ctrl MoveCursor( d, proc, wActionMove, pos, bm, wDrawColorBlack ); break; case C_DOWN: - bm = ((MyGetKeyState()&WKEY_SHIFT)?arrow0_shift_bm:(MyGetKeyState()&WKEY_CTRL)?arrow0_ctl_bm:arrow0_bm); + bm = ((MyGetKeyState()&WKEY_SHIFT)?arrow0_shift_bm:(MyGetKeyState()&WKEY_CTRL) + ?arrow0_ctl_bm:arrow0_bm); MoveCursor( d, proc, wActionMove, pos, bm, wDrawColorBlack ); //Go to spot - bm = ((MyGetKeyState()&WKEY_SHIFT)?arrow3_shift_bm:(MyGetKeyState()&WKEY_CTRL)?arrow3_ctl_bm:arrow3_bm); - Flash( d, x, y, playbackColor=rightDragColor ); + bm = ((MyGetKeyState()&WKEY_SHIFT)?arrow3_shift_bm:(MyGetKeyState()&WKEY_CTRL) + ?arrow3_ctl_bm:arrow3_bm); + Flash( playbackColor=rightDragColor ); proc( action, pos ); - /* no break */ + /* no break */ case C_MOVE: - bm = ((MyGetKeyState()&WKEY_SHIFT)?arrow3_shift_bm:(MyGetKeyState()&WKEY_CTRL)?arrow3_ctl_bm:arrow3_bm); + bm = ((MyGetKeyState()&WKEY_SHIFT)?arrow3_shift_bm:(MyGetKeyState()&WKEY_CTRL) + ?arrow3_ctl_bm:arrow3_bm); MoveCursor( d, proc, C_MOVE, pos, bm, rightDragColor ); break; case C_UP: - bm = ((MyGetKeyState()&WKEY_SHIFT)?arrow3_shift_bm:(MyGetKeyState()&WKEY_CTRL)?arrow3_ctl_bm:arrow0_bm); + bm = ((MyGetKeyState()&WKEY_SHIFT)?arrow3_shift_bm:(MyGetKeyState()&WKEY_CTRL) + ?arrow3_ctl_bm:arrow0_bm); MoveCursor( d, proc, C_MOVE, pos, bm, rightDragColor ); - Flash( d, x, y, rightDragColor ); + Flash( rightDragColor ); proc( action, pos ); - bm = ((MyGetKeyState()&WKEY_SHIFT)?arrow0_shift_bm:(MyGetKeyState()&WKEY_CTRL)?arrow0_ctl_bm:arrow0_bm); + bm = ((MyGetKeyState()&WKEY_SHIFT)?arrow0_shift_bm:(MyGetKeyState()&WKEY_CTRL) + ?arrow0_ctl_bm:arrow0_bm); MoveCursor( d, NULL, 0, pos, bm, wDrawColorBlack ); break; case C_RDOWN: - bm = ((MyGetKeyState()&WKEY_SHIFT)?arrow0_shift_bm:(MyGetKeyState()&WKEY_CTRL)?arrow0_ctl_bm:arrow0_bm); + bm = ((MyGetKeyState()&WKEY_SHIFT)?arrow0_shift_bm:(MyGetKeyState()&WKEY_CTRL) + ?arrow0_ctl_bm:arrow0_bm); MoveCursor( d, proc, wActionMove, pos, bm, wDrawColorBlack ); //Go to spot - bm = ((MyGetKeyState()&WKEY_SHIFT)?arrowr3_shift_bm:(MyGetKeyState()&WKEY_CTRL)?arrowr3_ctl_bm:arrowr3_bm); - Flash( d, x, y, playbackColor=leftDragColor ); + bm = ((MyGetKeyState()&WKEY_SHIFT)?arrowr3_shift_bm:(MyGetKeyState()&WKEY_CTRL) + ?arrowr3_ctl_bm:arrowr3_bm); + Flash( playbackColor=leftDragColor ); proc( action, pos ); - /* no break */ + /* no break */ case C_RMOVE: - bm = ((MyGetKeyState()&WKEY_SHIFT)?arrowr3_shift_bm:(MyGetKeyState()&WKEY_CTRL)?arrowr3_ctl_bm:arrowr3_bm); + bm = ((MyGetKeyState()&WKEY_SHIFT)?arrowr3_shift_bm:(MyGetKeyState()&WKEY_CTRL) + ?arrowr3_ctl_bm:arrowr3_bm); MoveCursor( d, proc, C_RMOVE, pos, bm, leftDragColor ); break; case C_RUP: - bm = ((MyGetKeyState()&WKEY_SHIFT)?arrowr3_shift_bm:(MyGetKeyState()&WKEY_CTRL)?arrowr3_ctl_bm:arrowr3_bm); + bm = ((MyGetKeyState()&WKEY_SHIFT)?arrowr3_shift_bm:(MyGetKeyState()&WKEY_CTRL) + ?arrowr3_ctl_bm:arrowr3_bm); MoveCursor( d, proc, C_RMOVE, pos, bm, leftDragColor ); - Flash( d, x, y, leftDragColor ); + Flash( leftDragColor ); proc( action, pos ); - bm = ((MyGetKeyState()&WKEY_SHIFT)?arrow0_shift_bm:(MyGetKeyState()&WKEY_CTRL)?arrow0_ctl_bm:arrow0_bm); + bm = ((MyGetKeyState()&WKEY_SHIFT)?arrow0_shift_bm:(MyGetKeyState()&WKEY_CTRL) + ?arrow0_ctl_bm:arrow0_bm); MoveCursor( d, NULL, 0, pos, bm, wDrawColorBlack ); break; case C_REDRAW: proc( action, pos ); //Send Redraw to functions playbackD = &tempD; - MacroDrawBitMap( REDRAW, playbackBm, playbackX, playbackY, playbackColor ); + playbackPos = pos; + MacroDrawBitMap( REDRAW, playbackBm, playbackPos, playbackColor ); break; case C_TEXT: proc( action, pos); - char c = action>>8; +// char c = action>>8; bm = playbackBm; break; @@ -584,11 +581,11 @@ static void PlaybackCursor( EXPORT void PlaybackMouse( - playbackProc proc, - drawCmd_p d, - wAction_t action, - coOrd pos, - wDrawColor color ) + playbackProc proc, + drawCmd_p d, + wAction_t action, + coOrd pos, + wDrawColor color ) { PlaybackCursor( d, proc, action, pos, wDrawColorBlack ); didPause = FALSE; @@ -596,31 +593,44 @@ EXPORT void PlaybackMouse( EXPORT void MovePlaybackCursor( - drawCmd_p d, - wPos_t x, - wPos_t y, wBool_t direct, wControl_p control) + drawCmd_p d, + coOrd pos, + wBool_t direct, wControl_p control) { - coOrd pos; +#ifdef MOVECURSORTOCOMMANDBUTTON + // Show the cursor clicking on the command button + // Not possile with current structure playbackD = &tempD; - d->Pix2CoOrd( d, x, y, &pos ); - d->CoOrd2Pix( d, pos, &x, &y ); - if (!direct) + if (!direct) { MoveCursor( d, NULL, wActionMove, pos, arrow0_bm, wDrawColorBlack ); - wBool_t ret = wDrawSetTempMode( d->d, TRUE ); - MacroDrawBitMap( MOVE_PLYBCK1, arrow0_bm, x, y, wDrawColorBlack ); - MacroDrawBitMap( MOVE_PLYBCK2, arrow3_bm, x, y, rightDragColor ); - - Flash( d, x, y, rightDragColor ); + } + unsigned long options = d->options; + d->options |= DC_TEMP; + wBool_t bTemp = wDrawSetTempMode( d->d, TRUE ); + DoCurCommand( C_REDRAW, zero ); + MacroDrawBitMap( MOVE_PLYBCK1, arrow0_bm, pos, wDrawColorBlack ); + MacroDrawBitMap( MOVE_PLYBCK2, arrow3_bm, pos, rightDragColor ); + + Flash( rightDragColor ); if (direct) { wControlHilite(control,TRUE); } - MacroDrawBitMap( MOVE_PLYBCK3, arrow3_bm, x, y, rightDragColor ); - MacroDrawBitMap( MOVE_PLYBCK4, arrow0_bm, x, y, wDrawColorBlack ); + MacroDrawBitMap( MOVE_PLYBCK3, arrow3_bm, pos, rightDragColor ); + MacroDrawBitMap( MOVE_PLYBCK4, arrow0_bm, pos, wDrawColorBlack ); if (direct) { wPause(1000); wControlHilite(control,FALSE); } - wDrawSetTempMode( d->d, ret ); + wDrawSetTempMode( d->d, bTemp ); + d->options = options; +#else + // Just hilight the button + if ( control ) { + wControlHilite( control, TRUE ); + wPause( 1000 ); + wControlHilite( control, FALSE ); + } +#endif } /***************************************************************************** @@ -635,18 +645,18 @@ EXPORT wWin_p demoW; EXPORT int curDemo = -1; typedef struct { - char * title; - char * fileName; - } demoList_t; + char * title; + char * fileName; +} demoList_t; static dynArr_t demoList_da; #define demoList(N) DYNARR_N( demoList_t, demoList_da, N ) static struct wFilSel_t * playbackFile_fs; typedef struct { - char * label; - playbackProc_p proc; - void * data; - } playbackProc_t; + char * label; + playbackProc_p proc; + void * data; +} playbackProc_t; static dynArr_t playbackProc_da; #define playbackProc(N) DYNARR_N( playbackProc_t, playbackProc_da, N ) @@ -673,27 +683,29 @@ static paramTextData_t demoTextData = { 50, 16 }; static paramData_t demoPLs[] = { #define I_DEMOSTEP (0) #define demoStep ((wButton_p)demoPLs[I_DEMOSTEP].control) - { PD_BUTTON, (void*)DoDemoButton, "step", PDO_NORECORD, NULL, N_("Step"), BB_DEFAULT, (void*)0 }, + { PD_BUTTON, DoDemoButton, "step", PDO_NORECORD, NULL, N_("Step"), BB_DEFAULT, I2VP(0) }, #define I_DEMONEXT (1) #define demoNext ((wButton_p)demoPLs[I_DEMONEXT].control) - { PD_BUTTON, (void*)DoDemoButton, "next", PDO_NORECORD|PDO_DLGHORZ, NULL, N_("Next"), 0, (void*)1 }, + { PD_BUTTON, DoDemoButton, "next", PDO_NORECORD|PDO_DLGHORZ, NULL, N_("Next"), 0, I2VP(1) }, #define I_DEMOQUIT (2) #define demoQuit ((wButton_p)demoPLs[I_DEMOQUIT].control) - { PD_BUTTON, (void*)DoDemoButton, "quit", PDO_NORECORD|PDO_DLGHORZ, NULL, N_("Quit"), BB_CANCEL, (void*)3 }, + { PD_BUTTON, DoDemoButton, "quit", PDO_NORECORD|PDO_DLGHORZ, NULL, N_("Quit"), BB_CANCEL, I2VP(3) }, #define I_DEMOSPEED (3) #define demoSpeedL ((wList_p)demoPLs[I_DEMOSPEED].control) - { PD_DROPLIST, &playbackSpeed, "speed", PDO_NORECORD|PDO_LISTINDEX|PDO_DLGHORZ, (void*)80, N_("Speed") }, + { PD_DROPLIST, &playbackSpeed, "speed", PDO_NORECORD|PDO_LISTINDEX|PDO_DLGHORZ, I2VP(80), N_("Speed") }, #define I_DEMOTEXT (4) #define demoT ((wText_p)demoPLs[I_DEMOTEXT].control) - { PD_TEXT, NULL, "text", PDO_NORECORD|PDO_DLGRESIZE, &demoTextData, NULL, BT_CHARUNITS|BO_READONLY} }; -static paramGroup_t demoPG = { "demo", 0, demoPLs, sizeof demoPLs/sizeof demoPLs[0] }; + { PD_TEXT, NULL, "text", PDO_NORECORD|PDO_DLGRESIZE, &demoTextData, NULL, BT_CHARUNITS|BO_READONLY} +}; +static paramGroup_t demoPG = { "demo", 0, demoPLs, COUNT( demoPLs ) }; EXPORT int MyGetKeyState( void ) { - if (inPlayback) + if (inPlayback) { return playbackKeyState; - else + } else { return wGetKeyState(); + } } @@ -709,8 +721,9 @@ EXPORT void AddPlaybackProc( char * label, playbackProc_p proc, void * data ) static void PlaybackQuit( void ) { long playbackSpeed1 = playbackSpeed; - if (paramFile) + if (paramFile) { fclose( paramFile ); + } paramFile = NULL; inPlaybackQuit = TRUE; wPrefReset(); @@ -732,8 +745,8 @@ static void PlaybackQuit( void ) ClearTracks(); checkPtMark = changed = 0; RestoreTrackState(); - inPlaybackQuit = FALSE; DoSetScale( oldScaleName ); + inPlaybackQuit = FALSE; DoChangeNotification( CHANGE_ALL ); CloseDemoWindows(); curDemo = -1; @@ -749,13 +762,14 @@ static int documentEnable = 0; static int documentAutoSnapshot = 0; static drawCmd_t snapshot_d = { - NULL, - &screenDrawFuncs, - 0, - 16.0, - 0, - {0.0, 0.0}, {1.0, 1.0}, - Pix2CoOrd, CoOrd2Pix }; + NULL, + &screenDrawFuncs, + 0, + 16.0, + 0, + {0.0, 0.0}, {1.0, 1.0}, + Pix2CoOrd, CoOrd2Pix +}; static int documentSnapshotNum = 1; static int documentCopy = 0; static FILE * documentFile; @@ -764,31 +778,39 @@ static BOOL_T snapshotMouse = FALSE; EXPORT void TakeSnapshot( drawCmd_t * d ) { char * cp; - wPos_t ix, iy; - if (d->dpi < 0) + wWinPix_t ix, iy; + if (d->dpi < 0) { d->dpi = mainD.dpi; - if (d->scale < 0) + } + if (d->scale < 0) { d->scale = mainD.scale; - if (d->orig.x < 0 || d->orig.y < 0) + } + if (d->orig.x < 0 || d->orig.y < 0) { d->orig = mainD.orig; - if (d->size.x < 0 || d->size.y < 0) + } + if (d->size.x < 0 || d->size.y < 0) { d->size = mainD.size; - ix = (wPos_t)(d->dpi*d->size.x/d->scale); - iy = (wPos_t)(d->dpi*d->size.y/d->scale); + } + ix = (wWinPix_t)(d->dpi*d->size.x/d->scale); + iy = (wWinPix_t)(d->dpi*d->size.y/d->scale); d->d = wBitMapCreate( ix, iy, 8 ); if (d->d == (wDraw_p)0) { return; } DrawTracks( d, d->scale, d->orig, d->size ); - if ( snapshotMouse && playbackBm ) - wDrawBitMap( d->d, playbackBm, playbackX, playbackY, playbackColor, 0 ); - wDrawLine( d->d, 0, 0, ix-1, 0, 0, wDrawLineSolid, wDrawColorBlack, 0 ); - wDrawLine( d->d, ix-1, 0, ix-1, iy-1, 0, wDrawLineSolid, wDrawColorBlack, 0 ); - wDrawLine( d->d, ix-1, iy-1, 0, iy-1, 0, wDrawLineSolid, wDrawColorBlack, 0 ); - wDrawLine( d->d, 0, iy-1, 0, 0, 0, wDrawLineSolid, wDrawColorBlack, 0 ); + if ( snapshotMouse && playbackBm ) { + DrawBitMap( d, playbackPos, playbackBm, playbackColor ); + } + coOrd p0, s1; + DIST_T off = 0.02; + p0.x = off * d->scale; + p0.y = off * d->scale; + s1.x = d->size.x-off*2 * d->scale; + s1.y = d->size.y-off*2 * d->scale; + DrawRectangle( d, p0, s1, wDrawColorBlack, DRAW_CLOSED ); strcpy( message, paramFileName ); cp = message+strlen(message)-4; - sprintf( cp, "-%4.4d.xpm", documentSnapshotNum ); + sprintf( cp, "-%4.4d.png", documentSnapshotNum ); wBitMapWriteFile( d->d, message ); wBitMapDelete( d->d ); documentSnapshotNum++; @@ -803,7 +825,7 @@ EXPORT void TakeSnapshot( drawCmd_t * d ) * Regression test */ static int log_regression = 0; -wBool_t bWriteEndPtDirectIndex; +static int nRegressionFail = 0; static BOOL_T DoRegression( char * sFileName ) { @@ -813,115 +835,56 @@ static BOOL_T DoRegression( char * sFileName ) long regressVersion; FILE * fRegression; char * sRegressionFile = NULL; - wBool_t bWroteActualTracks; +// wBool_t bWroteActualTracks; eRegression = log_regression > 0 ? logTable(log_regression).level : 0; char * cp; regressVersion = strtol( paramLine+16, &cp, 10 ); - if (cp == paramLine+16 ) + if (cp == paramLine+16 ) { regressVersion = PARAMVERSION; + } LOG( log_regression, 1, ("REGRESSION %s %d %s:%d %s\n", - eRegression==REGRESSION_SAVE?"SAVE":"CHECK", - regressVersion, - sFileName, paramLineNum, - cp ) ); + eRegression==REGRESSION_SAVE?"SAVE":"CHECK", + regressVersion, + sFileName, paramLineNum, + cp ) ); MakeFullpath( &sRegressionFile, workingDir, "xtrkcad.regress", NULL ); - switch ( eRegression ){ + switch ( eRegression ) { case REGRESSION_SAVE: fRegression = fopen( sRegressionFile, "a" ); if ( fRegression == NULL ) { - NoticeMessage( MSG_OPEN_FAIL, _("Continue"), NULL, _("Regression"), sFileName, strerror(errno) ); + NoticeMessage( MSG_OPEN_FAIL, _("Continue"), NULL, _("Regression"), sFileName, + strerror(errno) ); } else { fprintf( fRegression, "REGRESSION START %d %s\n", - PARAMVERSION, cp ); + PARAMVERSION, cp ); fprintf( fRegression, "# %s - %d\n", sFileName, paramLineNum ); WriteTracks( fRegression, FALSE ); fprintf( fRegression, "REGRESSION END\n" ); fclose( fRegression ); } while ( fgets(paramLine, STR_LONG_SIZE, paramFile) != NULL ) { - if ( strncmp( paramLine, "REGRESSION END", 14 ) == 0) + if ( strncmp( paramLine, "REGRESSION END", 14 ) == 0) { break; + } } break; case REGRESSION_CHECK: case REGRESSION_QUIET: oldParamVersion = paramVersion; - paramVersion = regressVersion; - bWroteActualTracks = FALSE; - track_p to_first_save = to_first; - track_p* to_last_save = to_last; - while ( GetNextLine() ) { - if ( paramLine[0] == '#' ) - continue; - // Read Expected track - to_first = NULL; - to_last = &to_first; - paramVersion = regressVersion; - if ( !ReadTrack( paramLine ) ) { - if ( paramFile == NULL ) - return FALSE; - break; - } - if ( to_first == NULL ) { - // Something bad happened - break; - } - track_cp tExpected = to_first; - to_first = to_first_save; - // Find corresponding Actual track - track_cp tActual = FindTrack( GetTrkIndex( tExpected ) ); - strcat( message, "Regression " ); - if ( ! CompareTrack( tActual, tExpected ) ) { - // Actual doesn't match Expected - LOG( log_regression, 1, (" FAIL: %s", message) ); - fRegression = fopen( sRegressionFile, "a" ); - if ( fRegression == NULL ) { - NoticeMessage( MSG_OPEN_FAIL, _("Continue"), NULL, _("Regression"), sRegressionFile, strerror(errno) ); - break; - } - fprintf( fRegression, "REGRESSION FAIL %d\n", - PARAMVERSION ); - fprintf( fRegression, "# %s - %d\n", sFileName, paramLineNum ); - fprintf( fRegression, "# %s", message ); - if ( !bWroteActualTracks ) { - // Print Actual tracks - fprintf( fRegression, "Actual Tracks\n" ); - paramVersion = PARAMVERSION; - WriteTracks( fRegression, FALSE ); - bWroteActualTracks = TRUE; - } - // Print Expected track - to_first = tExpected; - fprintf( fRegression, "Expected Track\n" ); - WriteTracks( fRegression, FALSE ); - fclose( fRegression ); - strcat( message, "Continue test?" ); - if ( eRegression == REGRESSION_CHECK ) { - int rc = wNoticeEx( NT_ERROR, message, _("Stop"), _("Continue") ); - if ( !rc ) { - while ( GetNextLine() && - strncmp( paramLine, "REGRESSION END", 14 ) != 0 ) - ; - break; - } - } - } - // Delete Expected track - to_first = tExpected; - to_last = &to_first; - FreeTrack( tExpected ); - } - to_first = to_first_save; - to_last = to_last_save; - if ( strncmp( paramLine, "REGRESSION END", 14 ) != 0 ) - InputError( "Expected REGRESSION END", TRUE ); + int nFail = CheckRegressionResult( regressVersion, sFileName, + eRegression == REGRESSION_QUIET ); paramVersion = oldParamVersion; + if ( nFail < 0 ) { + return FALSE; + } + nRegressionFail += nFail; break; case REGRESSION_NONE: default: while ( GetNextLine() ) { - if ( strncmp( paramLine, "REGRESSION END", 14 ) == 0 ) + if ( strncmp( paramLine, "REGRESSION END", 14 ) == 0 ) { break; + } } break; } @@ -931,7 +894,7 @@ static BOOL_T DoRegression( char * sFileName ) } static void EnableButtons( - BOOL_T enable ) + BOOL_T enable ) { wButtonSetBusy( demoStep, !enable ); wButtonSetBusy( demoNext, !enable ); @@ -943,7 +906,7 @@ static void EnableButtons( } EXPORT void PlaybackMessage( - char * line ) + char * line ) { char * cp; wTextAppend( demoT, _(line) ); @@ -975,7 +938,7 @@ static void PlaybackSetup( void ) wTextClear( demoT ); wShow( demoW ); wFlush(); - wPrefFlush(); + wPrefFlush(""); wWinSetBusy( mainW, TRUE ); wWinSetBusy( mapW, TRUE ); ParamSaveAll(); @@ -985,14 +948,14 @@ static void PlaybackSetup( void ) oldMainSize = mainD.size; oldMainScale = mainD.scale; oldScaleName = curScaleName; - playbackX = 0; - playbackY = 0; + playbackPos = zero; Reset(); paramVersion = -1; playbackColor=wDrawColorBlack; paramTogglePlaybackHilite = FALSE; CompoundClearDemoDefns(); SaveLayers(); + nRegressionFail = 0; } @@ -1002,8 +965,8 @@ static void Playback( void ) POS_T zoom; wIndex_t inx; long timeout; - static enum { pauseCmd, mouseCmd, otherCmd } thisCmd, lastCmd; - int len; + static enum { pauseCmd, mouseCmd, otherCmd } thisCmd/*, lastCmd*/; + size_t len; static wBool_t demoWinOnTop = FALSE; coOrd roomSize; char * cp, * cq; @@ -1012,20 +975,21 @@ static void Playback( void ) useCurrentLayer = FALSE; inPlayback = TRUE; EnableButtons( FALSE ); - lastCmd = otherCmd; +// lastCmd = otherCmd; playbackTimer = 0; if (demoWinOnTop) { wWinTop( mainW ); demoWinOnTop = FALSE; } - char * oldLocale = NULL; - oldLocale = SaveLocale( "C" ); + SetCLocale(); while (TRUE) { if ( ! inPlayback ) // User pressed Quit + { break; + } if ( paramFile == NULL || - fgets(paramLine, STR_LONG_SIZE, paramFile) == NULL ) { + fgets(paramLine, STR_LONG_SIZE, paramFile) == NULL ) { paramTogglePlaybackHilite = FALSE; CloseDemoWindows(); if (paramFile) { @@ -1037,17 +1001,20 @@ static void Playback( void ) documentFile = NULL; } Reset(); - if (curDemo < 0 || curDemo >= demoList_da.cnt) + if (curDemo < 0 || curDemo >= demoList_da.cnt) { break; + } demoFileName = strdup(demoList(curDemo).fileName ); paramFile = fopen( demoFileName, "r" ); if ( paramFile == NULL ) { - NoticeMessage( MSG_OPEN_FAIL, _("Continue"), NULL, _("Demo"), demoFileName, strerror(errno) ); - RestoreLocale( oldLocale ); + NoticeMessage( MSG_OPEN_FAIL, _("Continue"), NULL, _("Demo"), demoFileName, + strerror(errno) ); inPlayback = FALSE; + SetUserLocale(); return; } - + + paramFileName = strdup( demoFileName ); playbackColor=wDrawColorBlack; paramLineNum = 0; wWinSetTitle( demoW, demoList( curDemo ).title ); @@ -1059,11 +1026,12 @@ static void Playback( void ) DoChangeNotification( CHANGE_ALL ); CompoundClearDemoDefns(); if ( fgets(paramLine, STR_LONG_SIZE, paramFile) == NULL ) { - NoticeMessage( MSG_CANT_READ_DEMO, _("Continue"), NULL, sProdName, demoFileName ); + NoticeMessage( MSG_CANT_READ_DEMO, _("Continue"), NULL, sProdName, + demoFileName ); fclose( paramFile ); paramFile = NULL; - RestoreLocale( oldLocale ); inPlayback = FALSE; + SetUserLocale(); return; } free(demoFileName); @@ -1081,8 +1049,9 @@ static void Playback( void ) } thisCmd = otherCmd; paramLineNum++; - if (showParamLineNum) + if (showParamLineNum) { InfoCount( paramLineNum ); + } Stripcr( paramLine ); if (paramLine[0] == '#') { /* comment */ @@ -1104,15 +1073,16 @@ static void Playback( void ) demoWinOnTop = TRUE; } if ( documentAutoSnapshot ) { - snapshot_d.dpi=snapshot_d.scale=snapshot_d.orig.x=snapshot_d.orig.y=snapshot_d.size.x=snapshot_d.size.y=-1; + snapshot_d.dpi=snapshot_d.scale=snapshot_d.orig.x=snapshot_d.orig.y= + snapshot_d.size.x=snapshot_d.size.y=-1; TakeSnapshot(&snapshot_d); } if (playbackNonStop) { wPause( 1000 ); EnableButtons( FALSE ); } else { - RestoreLocale( oldLocale ); inPlayback = FALSE; + SetUserLocale(); return; } } else if (strncmp( paramLine, "CLEAR", 5 ) == 0) { @@ -1123,26 +1093,31 @@ static void Playback( void ) demoWinOnTop = TRUE; while ( ( fgets( paramLine, STR_LONG_SIZE, paramFile ) ) != NULL ) { paramLineNum++; - if ( IsEND( END_MESSAGE ) ) +#ifdef UTFCONVERT + ConvertUTF8ToSystem(paramLine); +#endif + if ( IsEND( END_MESSAGE ) ) { break; + } if ( strncmp(paramLine, "STEP", 3) == 0 ) { wWinTop( demoW ); demoWinOnTop = TRUE; EnableButtons( TRUE ); - RestoreLocale( oldLocale ); inPlayback = FALSE; + SetUserLocale(); return; } PlaybackMessage( paramLine ); } } else if (strncmp( paramLine, "ROOMSIZE ", 9 ) == 0) { - if (ParseRoomSize( paramLine+9, &roomSize )) + if (ParseRoomSize( paramLine+9, &roomSize )) { SetRoomSize( roomSize ); + } } else if (strncmp( paramLine, "SCALE ", 6 ) == 0) { DoSetScale( paramLine+6 ); } else if (strncmp( paramLine, "REDRAW", 6 ) == 0) { ResolveIndex(); - RecomputeElevations(); + RecomputeElevations(NULL); DoRedraw(); /*DoChangeNotification( CHANGE_ALL );*/ } else if (strncmp( paramLine, "COMMAND ", 8 ) == 0) { @@ -1155,24 +1130,28 @@ static void Playback( void ) } else if (strncmp( paramLine, "VERSION", 7 ) == 0) { paramVersion = atol( paramLine+8 ); if ( paramVersion > iParamVersion ) { - NoticeMessage( MSG_PLAYBACK_VERSION_UPGRADE, _("Ok"), NULL, paramVersion, iParamVersion, sProdName ); + NoticeMessage( MSG_PLAYBACK_VERSION_UPGRADE, _("Ok"), NULL, paramVersion, + iParamVersion, sProdName ); break; } if ( paramVersion < iMinParamVersion ) { - NoticeMessage( MSG_PLAYBACK_VERSION_DOWNGRADE, _("Ok"), NULL, paramVersion, iMinParamVersion, sProdName ); + NoticeMessage( MSG_PLAYBACK_VERSION_DOWNGRADE, _("Ok"), NULL, paramVersion, + iMinParamVersion, sProdName ); break; } } else if (strncmp( paramLine, "ORIG ", 5 ) == 0) { - if ( !GetArgs( paramLine+5, "fff", &zoom, &x, &y ) ) + if ( !GetArgs( paramLine+5, "fff", &zoom, &x, &y ) ) { continue; + } if (zoom == 0.0) { double scale_x = mapD.size.x/(mainD.size.x/mainD.scale); double scale_y = mapD.size.y/(mainD.size.y/mainD.scale); - if (scale_x<scale_y) + 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; + if (scale_x < 1) { scale_x = 1; } + if (scale_x > MAX_MAIN_SCALE) { scale_x = MAX_MAIN_SCALE; } zoom = scale_x; } mainD.scale = zoom; @@ -1190,12 +1169,15 @@ static void Playback( void ) paramTogglePlaybackHilite = TRUE; didPause = TRUE; - if ( !GetArgs( paramLine+6, "l", &timeout ) ) + if ( !GetArgs( paramLine+6, "l", &timeout ) ) { continue; - if (timeout > 10000) + } + if (timeout > 10000) { timeout = 1000; - if (playbackTimer == 0) + } + if (playbackTimer == 0) { wPause( timeout*playbackDelay/100 ); + } wFlush(); if (demoWinOnTop) { wWinTop( mainW ); @@ -1207,12 +1189,26 @@ static void Playback( void ) if (playbackTimer == 0) { timeout = bigPause*playbackDelay/100; - if (timeout <= dragTimeout) + if (timeout <= dragTimeout) { timeout = dragTimeout+1; + } wPause( timeout ); } } else if (strncmp( paramLine, "KEYSTATE ", 9 ) == 0 ) { - playbackKeyState = atoi( paramLine+9 ); + if ( strchr( "0123456789", paramLine[9] ) ) { + playbackKeyState = atoi( paramLine+9 ); + } else { + playbackKeyState = 0; + if ( strchr( paramLine+9, 'S' ) ) { + playbackKeyState |= WKEY_SHIFT; + } + if ( strchr( paramLine+9, 'C' ) ) { + playbackKeyState |= WKEY_CTRL; + } + if ( strchr( paramLine+9, 'A' ) ) { + playbackKeyState |= WKEY_ALT; + } + } } else if (strncmp( paramLine, "TIMESTART", 9 ) == 0 ) { playbackTimer = wGetTimer(); } else if (strncmp( paramLine, "TIMEEND", 7 ) == 0 ) { @@ -1228,23 +1224,26 @@ static void Playback( void ) wTextAppend( demoT, wMemStats() ); wTextAppend( demoT, "\n" ); } else if (strncmp( paramLine, "SNAPSHOT", 8 ) == 0 ) { - if ( !documentEnable ) + if ( !documentEnable ) { continue; - snapshot_d.dpi=snapshot_d.scale=snapshot_d.orig.x=snapshot_d.orig.y=snapshot_d.size.x=snapshot_d.size.y=-1; + } + snapshot_d.dpi=snapshot_d.scale=snapshot_d.orig.x=snapshot_d.orig.y= + snapshot_d.size.x=snapshot_d.size.y=-1; cp = paramLine+8; - while (*cp && isspace((unsigned char)*cp)) cp++; - if (snapshot_d.dpi = strtod( cp, &cq ), cp == cq) + while (*cp && isspace((unsigned char)*cp)) { cp++; } + if (snapshot_d.dpi = strtod( cp, &cq ), cp == cq) { snapshot_d.dpi = -1; - else if (snapshot_d.scale = strtod( cq, &cp ), cp == cq) + } else if (snapshot_d.scale = strtod( cq, &cp ), cp == cq) { snapshot_d.scale = -1; - else if (snapshot_d.orig.x = strtod( cp, &cq ), cp == cq) + } else if (snapshot_d.orig.x = strtod( cp, &cq ), cp == cq) { snapshot_d.orig.x = -1; - else if (snapshot_d.orig.y = strtod( cq, &cp ), cp == cq) + } else if (snapshot_d.orig.y = strtod( cq, &cp ), cp == cq) { snapshot_d.orig.y = -1; - else if (snapshot_d.size.x = strtod( cp, &cq ), cp == cq) + } else if (snapshot_d.size.x = strtod( cp, &cq ), cp == cq) { snapshot_d.size.x = -1; - else if (snapshot_d.size.y = strtod( cq, &cp ), cp == cq) + } else if (snapshot_d.size.y = strtod( cq, &cp ), cp == cq) { snapshot_d.size.y = -1; + } TakeSnapshot(&snapshot_d); } else if (strncmp( paramLine, "DOCUMENT ON", 11 ) == 0 ) { documentCopy = documentEnable; @@ -1253,16 +1252,18 @@ static void Playback( void ) } else if (strncmp( paramLine, "DOCUMENT COPY", 13 ) == 0 ) { while ( ( fgets( paramLine, STR_LONG_SIZE, paramFile ) ) != NULL ) { paramLineNum++; - if ( IsEND( END_MESSAGE ) ) + if ( IsEND( END_MESSAGE ) ) { break; - if ( documentCopy && documentFile ) + } + if ( documentCopy && documentFile ) { fprintf( documentFile, "%s", paramLine ); + } } } else if ( strncmp( paramLine, "DEMOINIT", 8 ) == 0 ) { DemoInitValues(); } else if ( strncmp( paramLine, "REGRESSION START", 16 ) == 0 ) { DoRegression( curDemo < 1 ? paramFileName : - demoList(curDemo-1).fileName ); + demoList(curDemo-1).fileName ); } else { if (strncmp( paramLine, "MOUSE ", 6 ) == 0) { thisCmd = mouseCmd; @@ -1270,14 +1271,18 @@ static void Playback( void ) if (strncmp( paramLine, "MAP ", 6 ) == 0) { thisCmd = mouseCmd; } +#ifdef UTFCONVERT + ConvertUTF8ToSystem(paramLine); +#endif for ( inx=0; inx<playbackProc_da.cnt; inx++ ) { len = strlen(playbackProc(inx).label); if (strncmp( paramLine, playbackProc(inx).label, len ) == 0) { if (playbackProc(inx).data == NULL) { - while (paramLine[len] == ' ') len++; + while (paramLine[len] == ' ') { len++; } playbackProc(inx).proc( paramLine+len ); - } else + } else { playbackProc(inx).proc( (char*)playbackProc(inx).data ); + } break; } } @@ -1289,13 +1294,13 @@ static void Playback( void ) NoticeMessage( MSG_PLAYBACK_UNK_CMD, _("Ok"), NULL, paramLineNum, paramLine ); } } - lastCmd = thisCmd; +// lastCmd = thisCmd; wFlush(); if (pauseDemo) { EnableButtons( TRUE ); pauseDemo = FALSE; - RestoreLocale( oldLocale ); inPlayback = FALSE; + SetUserLocale(); return; } } @@ -1309,19 +1314,20 @@ static void Playback( void ) } inPlayback = FALSE; PlaybackQuit(); - RestoreLocale( oldLocale ); + SetUserLocale(); } static int StartPlayback( int cnt, char **pathName, void * context ) { - assert( pathName != NULL ); - assert( cnt ==1 ); + CHECK( pathName != NULL ); + CHECK( cnt ==1 ); SetCurrentPath( MACROPATHKEY, pathName[0] ); paramFile = fopen( pathName[0], "r" ); if ( paramFile == NULL ) { - NoticeMessage( MSG_OPEN_FAIL, _("Continue"), NULL, _("Playback"), pathName[0], strerror(errno) ); + NoticeMessage( MSG_OPEN_FAIL, _("Continue"), NULL, _("Playback"), pathName[0], + strerror(errno) ); return FALSE; } @@ -1341,11 +1347,10 @@ static int StartPlayback( int cnt, char **pathName, void * context ) static void DoDemoButton( void * command ) { - switch( (int)(long)command ) { + switch( VP2L(command) ) { case 0: /* step */ playbackNonStop = (wGetKeyState() & WKEY_SHIFT) != 0; - paramHiliteFast = (wGetKeyState() & WKEY_CTRL) != 0; Playback(); break; case 1: @@ -1353,15 +1358,17 @@ static void DoDemoButton( void * command ) DoSaveAs( NULL ); } else { /* next */ - if (paramFile) + if (paramFile) { fclose(paramFile); + } paramFile = NULL; wTextClear( demoT ); if ( (wGetKeyState()&WKEY_SHIFT)!=0 ) { - if ( curDemo >= 2 ) + if ( curDemo >= 2 ) { curDemo -= 2; - else + } else { curDemo = 0; + } } Playback(); } @@ -1389,11 +1396,11 @@ static void DoDemoButton( void * command ) static void DemoDlgUpdate( - paramGroup_p pg, - int inx, - void * valueP ) + paramGroup_p pg, + int inx, + void * valueP ) { - if ( inx != I_DEMOSPEED ) return; + if ( inx != I_DEMOSPEED ) { return; } SetPlaybackSpeed( (wIndex_t)*(long*)valueP ); } @@ -1401,23 +1408,26 @@ static void DemoDlgUpdate( static void CreateDemoW( void ) { char * title = MakeWindowTitle(_("Demo")); - demoW = ParamCreateDialog( &demoPG, title, NULL, NULL, NULL, FALSE, NULL, F_RESIZE, DemoDlgUpdate ); - - wListAddValue( demoSpeedL, _("Slowest"), NULL, (void*)0 ); - wListAddValue( demoSpeedL, _("Slow"), NULL, (void*)1 ); - wListAddValue( demoSpeedL, _("Normal"), NULL, (void*)2 ); - wListAddValue( demoSpeedL, _("Fast"), NULL, (void*)3 ); - wListAddValue( demoSpeedL, _("Faster"), NULL, (void*)4 ); - wListAddValue( demoSpeedL, _("Fastest"), NULL, (void*)5 ); + demoW = ParamCreateDialog( &demoPG, title, NULL, NULL, NULL, FALSE, NULL, + F_RESIZE, DemoDlgUpdate ); + + wListAddValue( demoSpeedL, _("Slowest"), NULL, I2VP(0) ); + wListAddValue( demoSpeedL, _("Slow"), NULL, I2VP(1) ); + wListAddValue( demoSpeedL, _("Normal"), NULL, I2VP(2) ); + wListAddValue( demoSpeedL, _("Fast"), NULL, I2VP(3) ); + wListAddValue( demoSpeedL, _("Faster"), NULL, I2VP(4) ); + wListAddValue( demoSpeedL, _("Fastest"), NULL, I2VP(5) ); wListSetIndex( demoSpeedL, (wIndex_t)playbackSpeed ); - playbackFile_fs = wFilSelCreate( mainW, FS_LOAD, 0, title, sRecordFilePattern, StartPlayback, NULL ); + playbackFile_fs = wFilSelCreate( mainW, FS_LOAD, 0, title, sRecordFilePattern, + StartPlayback, NULL ); } EXPORT void DoPlayBack( void * context ) { - if (demoW == NULL) + if (demoW == NULL) { CreateDemoW(); + } wButtonSetLabel( demoNext, _("Save") ); wFilSelect( playbackFile_fs, GetCurrentPath(MACROPATHKEY)); } @@ -1431,81 +1441,84 @@ EXPORT void DoPlayBack( void * context ) */ static char * demoInitParams[] = { - "layout title1 XTrackCAD", - "layout title2 Demo", - "GROUP layout", - "display tunnels 1", - "display endpt 2", - "display labelenable 0", - "display description-fontsize 48", - "display labelscale 8", - "display layoutlabels 6", - "display tworailscale 16", - "display tiedraw 0", - "pref mingridspacing 5", - "pref balloonhelp 1", - "display hotbarlabels 1", - "display mapscale 64", - "display livemap 0", - "display carhotbarlabels 1", - "display hideTrainsInTunnels 0", - "GROUP display", - "pref turntable-angle 15.00", - "cmdopt preselect 1", - "pref coupling-speed-max 100", - "cmdopt rightclickmode 0", - "GROUP cmdopt", - "pref checkpoint 0", - "pref units 0", - "pref dstfmt 1", - "pref anglesystem 0", - "pref minlength 0.100", - "pref connectdistance 0.100", - "pref connectangle 1.000", - "pref dragpixels 20", - "pref dragtimeout 500", - "display autoPan 0", - "display listlabels 7", - "layout mintrackradius 1.000", - "layout maxtrackgrade 5.000", - "display trainpause 300", - "GROUP pref", - "rgbcolor snapgrid 65280", - "rgbcolor marker 16711680", - "rgbcolor border 0", - "rgbcolor crossmajor 16711680", - "rgbcolor crossminor 255", - "rgbcolor normal 0", - "rgbcolor selected 16711680", - "rgbcolor profile 16711935", - "rgbcolor exception 16711808", - "rgbcolor tie 16744448", - "GROUP rgbcolor", - "easement val 0.000", - "easement r 0.000", - "easement x 0.000", - "easement l 0.000", - "GROUP easement", - "grid horzspacing 12.000", - "grid horzdivision 12", - "grid horzenable 0", - "grid vertspacing 12.000", - "grid vertdivision 12", - "grid vertenable 0", - "grid origx 0.000", - "grid origy 0.000", - "grid origa 0.000", - "grid show 0", - "GROUP grid", - "misc toolbarset 65535", - "GROUP misc", - "sticky set 67108479", /* 0x3fffe7f - all but Helix and Turntable */ - "GROUP sticky", - "turnout hide 0", - "layer button-count 10", - "cmdopt selectmode 0", - "cmdopt selectzero 1", - NULL }; + "layout title1 XTrackCAD", + "layout title2 Demo", + "GROUP layout", + "display tunnels 1", + "display endpt 2", + "display labelenable 0", + "display description-fontsize 48", + "display labelscale 8", + "display layoutlabels 6", + "display tworailscale 16", + "display tiedraw 0", + "pref mingridspacing 5", + "pref balloonhelp 1", + "display hotbarlabels 1", + "display mapscale 64", + "display livemap 0", + "display carhotbarlabels 1", + "display hideTrainsInTunnels 0", + "GROUP display", + "pref turntable-angle 15.00", + "cmdopt preselect 1", + "pref coupling-speed-max 100", + "cmdopt rightclickmode 0", + "GROUP cmdopt", + "pref checkpoint 0", + "pref units 0", + "pref dstfmt 1", + "pref anglesystem 0", + "pref minlength 0.100", + "pref connectdistance 0.100", + "pref connectangle 1.000", + "pref dragpixels 20", + "pref dragtimeout 500", + "display autoPan 0", + "display listlabels 7", + "layout mintrackradius 1.000", + "layout maxtrackgrade 5.000", + "display trainpause 300", + "GROUP pref", + "rgbcolor snapgrid 65280", + "rgbcolor marker 16711680", + "rgbcolor border 0", + "rgbcolor crossmajor 16711680", + "rgbcolor crossminor 255", + "rgbcolor normal 0", + "rgbcolor selected 16711680", + "rgbcolor profile 16711935", + "rgbcolor exception 16711808", + "rgbcolor tie 16744448", + "GROUP rgbcolor", + "easement val 0.000", + "easement r 0.000", + "easement x 0.000", + "easement l 0.000", + "GROUP easement", + "grid horzspacing 12.000", + "grid horzdivision 12", + "grid horzenable 0", + "grid vertspacing 12.000", + "grid vertdivision 12", + "grid vertenable 0", + "grid origx 0.000", + "grid origy 0.000", + "grid origa 0.000", + "grid show 0", + "GROUP grid", + "misc toolbarset 65535", + "misc cur-turnout-ep 0", + "GROUP misc", + "sticky set 67108479", /* 0x3fffe7f - all but Helix and Turntable */ + "GROUP sticky", + "newFixedTrack hide 0", + "layer button-count 10", + "cmdopt selectmode 0", + "cmdopt selectzero 1", + "rescale change-dim 0", + NULL +}; static void DemoInitValues( void ) { @@ -1526,11 +1539,13 @@ static void DemoInitValues( void ) strcpy( scaleName, "DEMO" ); DoSetScale( scaleName ); if ( paramPlaybackProc == NULL ) { - wNoticeEx( NT_INFORMATION, _("Can not find PARAMETER playback proc"), _("Ok"), NULL ); + wNoticeEx( NT_INFORMATION, _("Can not find PARAMETER playback proc"), _("Ok"), + NULL ); return; } - for ( cpp = demoInitParams; *cpp; cpp++ ) + for ( cpp = demoInitParams; *cpp; cpp++ ) { paramPlaybackProc( *cpp ); + } // Have to do this manually oldMagneticSnap = MagneticSnap( TRUE ); } @@ -1539,10 +1554,11 @@ static void DemoInitValues( void ) static void DoDemo( void * demoNumber ) { - if (demoW == NULL) + if (demoW == NULL) { CreateDemoW(); + } wButtonSetLabel( demoNext, _("Next") ); - curDemo = (int)(long)demoNumber; + curDemo = (int)VP2L(demoNumber); if ( curDemo < 0 || curDemo >= demoList_da.cnt ) { NoticeMessage( MSG_DEMO_BAD_NUM, _("Ok"), NULL, curDemo ); return; @@ -1555,47 +1571,43 @@ static void DoDemo( void * demoNumber ) static BOOL_T ReadDemo( - char * line ) + char * line ) { - static wMenu_p m; - char * cp; - char *oldLocale = NULL; - char *path; - - if ( m == NULL ) - m = demoM; - - if ( strncmp( line, "DEMOGROUP ", 10 ) == 0 ) { - if (userLocale) - oldLocale = SaveLocale(userLocale); - m = wMenuMenuCreate( demoM, NULL, _(line+10) ); - if (oldLocale) - RestoreLocale(oldLocale); - } else if ( strncmp( line, "DEMO ", 5 ) == 0 ) { - if (line[5] != '"') - goto error; - cp = line+6; - while (*cp && *cp != '"') cp++; - if ( !*cp ) - goto error; - *cp++ = '\0'; - while (*cp && *cp == ' ') cp++; - if ( strlen(cp)==0 ) - goto error; - DYNARR_APPEND( demoList_t, demoList_da, 10 ); - if (userLocale) - oldLocale = SaveLocale(userLocale); - demoList( demoList_da.cnt-1 ).title = MyStrdup( _(line+6) ); - MakeFullpath(&path, libDir, "demos", cp, NULL); - demoList(demoList_da.cnt - 1).fileName = path; - wMenuPushCreate( m, NULL, _(line+6), 0, DoDemo, (void*)(intptr_t)(demoList_da.cnt-1) ); - if (oldLocale) - RestoreLocale(oldLocale); + static wMenu_p m = NULL; + char * cp; + char *path; + + if ( m == NULL ) { + m = demoM; + } + + if ( strncmp( line, "DEMOGROUP ", 10 ) == 0 ) { + m = wMenuMenuCreate( demoM, NULL, _(line+10) ); + + } else if ( strncmp( line, "DEMO ", 5 ) == 0 ) { + if (line[5] != '"') { + goto error; + } + cp = line+6; + while (*cp && *cp != '"') { cp++; } + if ( !*cp ) { + goto error; } - return TRUE; + *cp++ = '\0'; + while (*cp && *cp == ' ') { cp++; } + if ( strlen(cp)==0 ) { + goto error; + } + DYNARR_APPEND( demoList_t, demoList_da, 10 ); + demoList( demoList_da.cnt-1 ).title = MyStrdup( _(line+6) ); + MakeFullpath(&path, libDir, "demos", cp, NULL); + demoList(demoList_da.cnt - 1).fileName = path; + wMenuPushCreate( m, NULL, _(line+6), 0, DoDemo, I2VP(demoList_da.cnt-1) ); + } + return TRUE; error: - InputError( "Expected 'DEMO \"<Demo Name>\" <File Name>'", TRUE ); - return FALSE; + InputError( "Expected 'DEMO \"<Demo Name>\" <File Name>'", TRUE ); + return FALSE; } @@ -1610,17 +1622,28 @@ EXPORT BOOL_T MacroInit( void ) rightDragColor = drawColorRed; leftDragColor = drawColorBlue; - arrow0_bm = wDrawBitMapCreate( mainD.d, arrow0_width, arrow0_height, 12, 12, arrow0_bits ); - arrow0_shift_bm = wDrawBitMapCreate( mainD.d, arrow0_shift_width, arrow0_shift_height, 12, 12, arrow0_shift_bits ); - arrow0_ctl_bm = wDrawBitMapCreate( mainD.d, arrow0_ctl_width, arrow0_ctl_height, 12, 12, arrow0_ctl_bits ); - arrow3_bm = wDrawBitMapCreate( mainD.d, arrow3_width, arrow3_height, 12, 12, arrow3_bits ); - arrow3_shift_bm = wDrawBitMapCreate( mainD.d, arrow3_shift_width, arrow3_shift_height, 12, 12, arrow3_shift_bits ); - arrow3_ctl_bm = wDrawBitMapCreate( mainD.d, arrow3_ctl_width, arrow3_ctl_height, 12, 12, arrow3_ctl_bits ); - arrowr3_bm = wDrawBitMapCreate( mainD.d, arrowr3_width, arrowr3_height, 12, 12, arrowr3_bits ); - arrowr3_shift_bm = wDrawBitMapCreate( mainD.d, arrowr3_shift_width, arrowr3_shift_height, 12, 12, arrowr3_shift_bits ); - arrowr3_ctl_bm = wDrawBitMapCreate( mainD.d, arrowr3_ctl_width, arrowr3_ctl_height, 12, 12, arrowr3_ctl_bits ); - arrows_bm = wDrawBitMapCreate( mainD.d, arrows_width, arrows_height, 12, 12, arrows_bits ); - flash_bm = wDrawBitMapCreate( mainD.d, flash_width, flash_height, 12, 12, flash_bits ); + arrow0_bm = wDrawBitMapCreate( mainD.d, arrow0_width, arrow0_height, 12, 12, + arrow0_bits ); + arrow0_shift_bm = wDrawBitMapCreate( mainD.d, arrow0_shift_width, + arrow0_shift_height, 12, 12, arrow0_shift_bits ); + arrow0_ctl_bm = wDrawBitMapCreate( mainD.d, arrow0_ctl_width, arrow0_ctl_height, + 12, 12, arrow0_ctl_bits ); + arrow3_bm = wDrawBitMapCreate( mainD.d, arrow3_width, arrow3_height, 12, 12, + arrow3_bits ); + arrow3_shift_bm = wDrawBitMapCreate( mainD.d, arrow3_shift_width, + arrow3_shift_height, 12, 12, arrow3_shift_bits ); + arrow3_ctl_bm = wDrawBitMapCreate( mainD.d, arrow3_ctl_width, arrow3_ctl_height, + 12, 12, arrow3_ctl_bits ); + arrowr3_bm = wDrawBitMapCreate( mainD.d, arrowr3_width, arrowr3_height, 12, 12, + arrowr3_bits ); + arrowr3_shift_bm = wDrawBitMapCreate( mainD.d, arrowr3_shift_width, + arrowr3_shift_height, 12, 12, arrowr3_shift_bits ); + arrowr3_ctl_bm = wDrawBitMapCreate( mainD.d, arrowr3_ctl_width, + arrowr3_ctl_height, 12, 12, arrowr3_ctl_bits ); + arrows_bm = wDrawBitMapCreate( mainD.d, arrows_width, arrows_height, 12, 12, + arrows_bits ); + flash_bm = wDrawBitMapCreate( mainD.d, flash_width, flash_height, 12, 12, + flash_bits ); ParamRegister( &recordPG ); ParamRegister( &demoPG ); @@ -1630,3 +1653,20 @@ EXPORT BOOL_T MacroInit( void ) return TRUE; } + + +/** + * Run all regression tests + * + * return number of failed tests + */ +EXPORT int RegressionTestAll() +{ + playbackNonStop = TRUE; + playbackSpeed = 5; + CreateDemoW(); + curDemo = 0; + PlaybackSetup(); + Playback(); + return nRegressionFail; +} |