string CVMState::getStringLine(string coinType, int current, int total) { stringstream ss, currentSS, totalSS; currentSS << coinType << current; string currentString = currentSS.str(); totalSS << coinType << total; string totalString = totalSS.str(); ss << "| " << currentString << getRightPadding(currentString, 19); ss << " | " << totalString << getRightPadding(totalString, 19); ss << " |" << endl; /* int stringSize = coinType.size(); ss << "| " << coinType << current; int digits = numDigits(current); for (int i = 19-stringSize; i > digits; i--) { ss << " "; } ss << " | " << coinType << total; digits = numDigits(total); for (int i = 19-stringSize; i > digits; i--) { ss << " "; } ss << " |" << endl; */ return ss.str(); }
void TextField::resizeWidthToContents() { setSize(getFont()->getTextWidth(getText()) + getLeftPadding() + getRightPadding() + getMargin(SIDE_LEFT) + getMargin(SIDE_RIGHT), getSize().getHeight()); positionCaret(0); }
void TextField::paintComponent( const PaintEvent &paintEvent ) { int caretLoc = getCaretLocation(); int textLoc = getTextOffset(); Rectangle sideclip = getInnerRectangle(); sideclip = Rectangle(sideclip.getX() + getLeftPadding() , sideclip.getY() + 2,sideclip.getSize().getWidth() - getLeftPadding() - getRightPadding() + 1, sideclip.getHeight() - 4); if(isReadOnly()) { paintEvent.graphics()->drawFilledRectangle( getSizeRectangle(),frameColor); } else { paintEvent.graphics()->drawFilledRectangle( getSizeRectangle(),getBackColor()); } paintEvent.graphics()->pushClippingRect(sideclip); if(getSelectionStart() != getSelectionEnd() && (isFocused() || !isHidingSelection()) ) { Rectangle selRect = Rectangle( getSelectionLocation(), (getInnerHeight() / 2) - (getFont()->getLineHeight() / 2), getSelectionWidth(), getFont()->getLineHeight()); paintEvent.graphics()->drawFilledRectangle( selRect,getSelectionBackColor()); } paintEvent.graphics()->drawText(Point(textLoc, + ((getInnerSize().getHeight() - getFont()->getLineHeight()) / 2)),getText().c_str(), getFontColor(),getFont()); if(isFocused()) { if(isBlinking()) paintEvent.graphics()->drawLine(Point(caretLoc + 1, ((getInnerSize().getHeight() / 2) + (getFont()->getLineHeight() / 2))), Point(caretLoc + 1, ((getInnerSize().getHeight() / 2) - (getFont()->getLineHeight() / 2))), Color(0,0,0)); } paintEvent.graphics()->popClippingRect(); }
string CVMState::getString() { stringstream ss; ss << " ------------------------------------------- " << endl; ss << "|------------ Simulation State -------------|" << endl; ss << "|-------------------------------------------|" << endl; if (isChangeSelected()) { ss << "| |" << endl; ss << "| ----------------------------- |" << endl; ss << "| /-------------------------------\\ |" << endl; ss << "| |-------- Change Selected --------| |" << endl; ss << "| \\-------------------------------/ |" << endl; ss << "| ----------------------------- |" << endl; ss << "| |" << endl; } else { ss << "| |" << endl; ss << "| |" << endl; ss << "| |" << endl; ss << "| Change Not Selected |" << endl; ss << "| |" << endl; ss << "| |" << endl; ss << "| |" << endl; } ss << "|-------------------------------------------|" << endl; ss << "| Transaction Storage | Master Storage |" << endl; ss << "|---------------------|---------------------|" << endl; ss << "| | |" << endl; int currentCents = getCurrentCents(); int totalCents = getTotalCents(); stringstream currentCentsStream, totalCentsStream; currentCentsStream << "$" << (double)currentCents/100; totalCentsStream << "$" << (double)totalCents/100; string currentCentsString = currentCentsStream.str(); string totalCentsString = totalCentsStream.str(); ss << "| " << currentCentsString << getRightPadding(currentCentsString, 19); ss << " | " << totalCentsString << getRightPadding(totalCentsString, 19); ss << " |" << endl; // Pad ss << getStringLine("Quarters: ", currentQuarters, totalQuarters); ss << getStringLine("Dimes: ", currentDimes, totalDimes); ss << getStringLine("Nickels: ", currentNickels, totalNickels); ss << "| | |" << endl; ss << " ------------------------------------------- " << endl; return ss.str(); }
/** * Retrieve the padding value for all borders. * * @param[in] type Coordinate type in which padding must be returned. * * @return Padding values. */ Padding::Values Padding::getPaddingValues(const Type &type) const { Values values; values.left = getLeftPadding(type); values.right = getRightPadding(type); values.bottom = getBottomPadding(type); values.top = getTopPadding(type); return values; }
void MenuSystem::printTopMenu(char* val, int width){ clearLine(1); for(int i = 0; i < getLeftPadding(val, width); i++){ print(" "); } print(val); for(int i = 0; i < getRightPadding(val, width); i++){ print(" "); } }
int TextField::getAdjustedWidth() const { int w = getInnerSize().getWidth() - getLeftPadding() - getRightPadding(); if(w > 0) { return w; } return 0; }
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); }