static void *bwd_tab( VTAB *vtab, VTABAREA *curr, unsigned wrap ) { VTABAREA *chase, *hold; hold = NULL; chase = vtab->first; while( chase != curr ) { if( _tab( chase ) ) { hold = chase; } chase = _next( chase ); } if( hold == NULL ) { if( wrap ) { while( chase != NULL ) { if( _tab( chase ) ) { hold = chase; } chase = _next( chase ); } } else { hold = NULL; } } return( hold ); }
// returns zero if char must not be echoed on the screen static inline int _putc(char c, bool display) { switch (c) { case '\n': _line_feed(); break; case '\t': _tab(); break; case '\r': _kill(); break; case 127: console_clear(); break; case '\b': _del_ibuf(); break; default: // not a control character if (display) _putc_attr(c, _.attr); return 1; } return 0; }
static void *fwd_tab( VTAB *vtab, VTABAREA *curr, unsigned wrap ) { VTABAREA *chase; if( curr == NULL ) { chase = vtab->first; } else { chase = _next( curr ); } for( ; ; ) { if( chase == NULL ) { if( wrap ) { chase = vtab->first; } else { chase = NULL; break; } } if( _tab( chase ) ) break; if( chase == curr ) { chase = NULL; break; } chase = _next( chase ); } return( chase ); }
static void flipHoriz( const uchar* src, size_t sstep, uchar* dst, size_t dstep, Size size, size_t esz ) { int i, j, limit = (int)(((size.width + 1)/2)*esz); AutoBuffer<int> _tab(size.width*esz); int* tab = _tab; for( i = 0; i < size.width; i++ ) for( size_t k = 0; k < esz; k++ ) tab[i*esz + k] = (int)((size.width - i - 1)*esz + k); for( ; size.height--; src += sstep, dst += dstep ) { for( i = 0; i < limit; i++ ) { j = tab[i]; uchar t0 = src[i], t1 = src[j]; dst[i] = t1; dst[j] = t0; } } }
static void copyMakeBorder_8u(const uchar* src, size_t srcstep, Size srcroi, uchar* dst, size_t dststep, Size dstroi, int top, int left, int cn, int borderType) { const int isz = (int)sizeof(int); int i, j, k, elemSize = 1; bool intMode = false; if ((cn | srcstep | dststep | (size_t)src | (size_t)dst) % isz == 0) { cn /= isz; elemSize = isz; intMode = true; } AutoBuffer<int> _tab((dstroi.width - srcroi.width)*cn); int* tab = _tab; int right = dstroi.width - srcroi.width - left; int bottom = dstroi.height - srcroi.height - top; for (i = 0; i < left; i++) { j = borderInterpolate<int>(i - left, srcroi.width, borderType)*cn; for (k = 0; k < cn; k++) tab[i*cn + k] = j + k; } for (i = 0; i < right; i++) { j = borderInterpolate<int>(srcroi.width + i, srcroi.width, borderType)*cn; for (k = 0; k < cn; k++) tab[(i + left)*cn + k] = j + k; } srcroi.width *= cn; dstroi.width *= cn; left *= cn; right *= cn; uchar* dstInner = dst + dststep*top + left*elemSize; for (i = 0; i < srcroi.height; i++, dstInner += dststep, src += srcstep) { if (dstInner != src) memcpy(dstInner, src, srcroi.width*elemSize); if (intMode) { const int* isrc = (int*)src; int* idstInner = (int*)dstInner; for (j = 0; j < left; j++) idstInner[j - left] = isrc[tab[j]]; for (j = 0; j < right; j++) idstInner[j + srcroi.width] = isrc[tab[j + left]]; } else { for (j = 0; j < left; j++) dstInner[j - left] = src[tab[j]]; for (j = 0; j < right; j++) dstInner[j + srcroi.width] = src[tab[j + left]]; } } dstroi.width *= elemSize; dst += dststep*top; for (i = 0; i < top; i++) { j = borderInterpolate<int>(i - top, srcroi.height, borderType); memcpy(dst + (i - top)*dststep, dst + j*dststep, dstroi.width); } for (i = 0; i < bottom; i++) { j = borderInterpolate<int>(i + srcroi.height, srcroi.height, borderType); memcpy(dst + (i + srcroi.height)*dststep, dst + j*dststep, dstroi.width); } }
EVENT uitabfilter( EVENT ev, VTAB *vtab ) /***************************************/ { VTABAREA *curr, *best, *chase; ORD r, c; unsigned fwd; EVENT retev; retev = EV_NO_EVENT; if( vtab->first != NULL ) { if( vtab->curr == NULL ) { curr = fwd_tab( vtab, NULL, TRUE ); if( curr == NULL ) return( ev ); vtab->home = curr->area.col; } else { curr = vtab->curr; } switch( ev ) { case EV_NO_EVENT : break; case EV_MOUSE_PRESS : case EV_MOUSE_DRAG : case EV_MOUSE_RELEASE : if( _mouse( &r, &c ) ) { chase = vtab->first; best = NULL; while( chase != NULL ) { if( r < chase->area.row ) break; if( r == chase->area.row && c >= chase->area.col && c < chase->area.col + chase->area.width ) { best = chase; break; } chase = _next( chase ); } if( ev != EV_MOUSE_RELEASE ) { vtab->other = best; if( best == curr || best == NULL ) { /* mouse has no tabbing effect */ } else if( _tab( best ) ) { curr = best; } } retev = ev; } break; case EV_HOME : curr = fwd_tab( vtab, NULL, TRUE ); break; case EV_END : curr = bwd_tab( vtab, NULL, TRUE ); break; case EV_ENTER : if( !vtab->enter ) return( ev ); vtab->home = 0; ev = EV_CURSOR_DOWN; case EV_CURSOR_UP: case EV_CURSOR_DOWN: best = NULL; chase = curr; fwd = ( ev == EV_CURSOR_DOWN ); for( ; ; ) { chase = fwd ? fwd_tab( vtab, chase, vtab->wrap ) : bwd_tab( vtab, chase, vtab->wrap ); if( chase == NULL ) { if( best == NULL ) { retev = ( fwd ? EV_BOTTOM : EV_TOP ); } else { curr = best; } break; } else if( chase == curr ) { if( best != NULL ) { curr = best; } break; } else if( chase->area.row != curr->area.row ) { if( best == NULL ) { best = chase; } else if( chase->area.row != best->area.row ) { curr = best; break; } else if( abs( chase->area.col - vtab->home ) < abs( best->area.col - vtab->home ) ) { best = chase; } else { curr = best; break; } } } break; case EV_CURSOR_RIGHT : case EV_TAB_FORWARD : curr = fwd_tab( vtab, curr, TRUE ); break; case EV_CURSOR_LEFT : case EV_TAB_BACKWARD : curr = bwd_tab( vtab, curr, TRUE ); break; default: return( ev ); } if( vtab->curr != curr ) { if( ev != EV_CURSOR_UP && ev != EV_CURSOR_DOWN ) { vtab->home = curr->area.col; } retev = EV_FIELD_CHANGE; vtab->other = vtab->curr; vtab->curr = curr; } return( retev ); } return( ev ); }