int TextField::solveCaretRetPos( int initialAmount, int retOffset ) { int tempResult = retOffset + alignOffset - initialAmount; int tempCaret = getFont()->getTextWidth(unicodeFunctions.subStr(getText(), 0,getCaretPosition())) + tempResult; if(tempCaret > getAdjustedWidth() + getLeftPadding() || tempCaret < getLeftPadding()) { return getFont()->getTextWidth(unicodeFunctions.subStr(getText(), 0, getCaretPosition() + 1 )) - getAdjustedWidth(); } else { return initialAmount; } }
const RECT TwoDRenderer::getBoundingBox() { RECT boundingBox; boundingBox.left = posVector.x; boundingBox.right = posVector.x + getAdjustedWidth(); boundingBox.top = posVector.y; boundingBox.bottom = posVector.y + getAdjustedHeight(); return boundingBox; }
void TextField::scrollToCaret(bool negetiveChange, bool reposition) { int retOffset = getLeftPadding(); int textWidth = getFont()->getTextWidth(getText()); if(textWidth < getAdjustedWidth()) { switch(getTextAlignment()) { case ALIGN_LEFT: alignOffset = 0; break; case ALIGN_CENTER: alignOffset = (getAdjustedWidth() - textWidth) / 2; break; case ALIGN_RIGHT: alignOffset = getAdjustedWidth() - textWidth; break; default: break; } } else { alignOffset = 0; } if(getTextLength() == 0 || getCaretPosition() == 0) { tOffset = retOffset; setTextOffset(retOffset + alignOffset); return; } if(reposition) { //do we need to move? if(getFont()->getTextWidth(unicodeFunctions.subStr(getText(), 0,getCaretPosition())) > -tOffset + getAdjustedWidth() + getLeftPadding() ) { //scroll to end if(getTextLength() < getCaretPosition() + getMaxCharacterSkip()) { retOffset -= solveCaretRetPos(getFont()->getTextWidth(getText()) - getAdjustedWidth(), retOffset); } else { int initialPlace = getFont()->getTextWidth(unicodeFunctions.subStr(getText(), 0, getCaretPosition() + getMaxCharacterSkip() )) - getAdjustedWidth(); retOffset -= solveCaretRetPos(initialPlace,retOffset); } tOffset = retOffset; setTextOffset(retOffset + alignOffset); return; } else if(tOffset + getFont()->getTextWidth(unicodeFunctions.subStr(getText(), 0,getCaretPosition())) <= leftPadding) { if(getCaretPosition() - getMaxCharacterSkip() > 0) { int initialPlace = getFont()->getTextWidth(unicodeFunctions.subStr(getText(), 0, getCaretPosition() - getMaxCharacterSkip() )); retOffset -= solveCaretRetPos(initialPlace,retOffset); } tOffset = retOffset; setTextOffset(retOffset + alignOffset); return; } else if(negetiveChange ) { int change = getCaretLocation() - getFont()->getTextWidth(unicodeFunctions.subStr(getText(), 0, getCaretPosition() )) ; if(change <= getLeftPadding()) { tOffset = change; setTextOffset(change); } else { tOffset = leftPadding; setTextOffset(leftPadding + alignOffset); } return; } } //if there is more text than width //but theres not enough to fill the width //then fill the width int a = getAdjustedWidth() + getLeftPadding(); int b = getTextOffset() + textWidth; if(a > b && getTextOffset() < getLeftPadding()) { retOffset = -textWidth + getInnerSize().getWidth() - getRightPadding(); tOffset = retOffset; } else if(getTextOffset() >= getLeftPadding() ) { tOffset = leftPadding; setTextOffset(leftPadding + alignOffset); return; } setTextOffset(tOffset + alignOffset); }