Refactoring FOptiMove::relativeMove

This commit is contained in:
Markus Gans 2018-01-03 22:58:07 +01:00
parent 9bb22e7d7b
commit f53efc90c5
3 changed files with 186 additions and 168 deletions

View File

@ -1,4 +1,5 @@
2017-01-02 Markus Gans <guru.mail@muenster.de>
* Refactoring FOptiMove::relativeMove
* Refactoring attribute settings in FOptiAttr
* Refactoring FTerm::parseKeyString and timeout settings

View File

@ -135,6 +135,8 @@ class FOptiMove
int capDurationToLength (int);
int repeatedAppend (const capability&, volatile int, char*);
int relativeMove (char[], int, int, int, int);
int verticalMove (char[], int, int);
int horizontalMove (char[], int, int);
bool isWideMove (int, int, int, int);
bool isMethod0Faster (int&, int, int);
bool isMethod1Faster (int&, int, int, int, int);

View File

@ -677,16 +677,44 @@ int FOptiMove::relativeMove ( char move[]
, int from_x, int from_y
, int to_x, int to_y )
{
int num
, vtime = 0
, htime = 0;
int vtime = 0;
int htime = 0;
if ( move )
move[0] = '\0';
if ( to_y != from_y ) // vertical move
{
vtime = LONG_DURATION;
vtime = verticalMove (move, from_y, to_y);
if ( vtime >= LONG_DURATION )
return LONG_DURATION;
}
if ( to_x != from_x ) // horizontal move
{
char hmove[sizeof(move_buf)] = {};
htime = horizontalMove (hmove, from_x, to_x);
if ( htime >= LONG_DURATION )
return LONG_DURATION;
if ( move )
{
if ( *move )
std::strncat (move, hmove, sizeof(move_buf) - std::strlen(move) - 1);
else
std::strncpy (move, hmove, sizeof(move_buf) - 1);
}
}
return vtime + htime;
}
//----------------------------------------------------------------------
inline int FOptiMove::verticalMove (char move[], int from_y, int to_y)
{
int vtime = LONG_DURATION;
if ( F_row_address.cap )
{
@ -700,7 +728,7 @@ int FOptiMove::relativeMove ( char move[]
if ( to_y > from_y )
{
num = to_y - from_y;
int num = to_y - from_y;
if ( F_parm_down_cursor.cap && F_parm_down_cursor.duration < vtime )
{
@ -722,7 +750,7 @@ int FOptiMove::relativeMove ( char move[]
}
else // to_y < from_y
{
num = from_y - to_y;
int num = from_y - to_y;
if ( F_parm_up_cursor.cap && F_parm_up_cursor.duration < vtime )
{
@ -743,15 +771,14 @@ int FOptiMove::relativeMove ( char move[]
}
}
if ( vtime >= LONG_DURATION )
return LONG_DURATION;
}
return vtime;
}
if ( to_x != from_x ) // horizontal move
{
//----------------------------------------------------------------------
inline int FOptiMove::horizontalMove (char hmove[], int from_x, int to_x)
{
char str[sizeof(move_buf)] = {};
char hmove[sizeof(move_buf)] = {};
htime = LONG_DURATION;
int htime = LONG_DURATION;
if ( F_column_address.cap )
{
@ -763,7 +790,7 @@ int FOptiMove::relativeMove ( char move[]
if ( to_x > from_x )
{
num = to_x - from_x;
int num = to_x - from_x;
if ( F_parm_right_cursor.cap && F_parm_right_cursor.duration < htime )
{
@ -812,7 +839,7 @@ int FOptiMove::relativeMove ( char move[]
}
else // to_x < from_x
{
num = from_x - to_x;
int num = from_x - to_x;
if ( F_parm_left_cursor.cap && F_parm_left_cursor.duration < htime )
{
@ -860,19 +887,7 @@ int FOptiMove::relativeMove ( char move[]
}
}
if ( htime >= LONG_DURATION )
return LONG_DURATION;
if ( move )
{
if ( *move )
std::strncat (move, hmove, sizeof(move_buf) - std::strlen(move) - 1);
else
std::strncpy (move, hmove, sizeof(move_buf) - 1);
}
}
return vtime + htime;
return htime;
}
//----------------------------------------------------------------------