FindBar::FindBar() : UIElement() { barBg = new ScreenShape(ScreenShape::SHAPE_RECT, 30,30); barBg->setPositionMode(ScreenEntity::POSITION_TOPLEFT); barBg->setColorInt(255, 222, 0, 255); addChild(barBg); this->height = 30; ScreenLabel *findLabel = new ScreenLabel("Find:", 16); addChild(findLabel); findLabel->setColor(0.0, 0.0, 0.0, 0.3); findLabel->setPosition(10,4); ScreenLabel *replaceLabel = new ScreenLabel("Replace:", 16); addChild(replaceLabel); replaceLabel->setColor(0.0, 0.0, 0.0, 0.3); replaceLabel->setPosition(200,4); processInputEvents = true; findInput = new UITextInput(false, 120, 12); addChild(findInput); findInput->setPosition(60, 4); replaceInput = new UITextInput(false, 120, 12); addChild(replaceInput); replaceInput->setPosition(280, 4); replaceAllButton = new UIImageButton("Images/replaceAll.png"); addChild(replaceAllButton); replaceAllButton->setPosition(420, 5); closeButton = new UIImageButton("Images/barClose.png"); addChild(closeButton); }
void UITextInput::insertText(String text) { vector<String> strings = text.split("\n"); int numLines = lines.size(); for(int i=0; i < strings.size(); i++) { if(i < numLines) { lines[i]->setText(strings[i]); } else { numLines++; ScreenLabel *newLine = new ScreenLabel(L"", fontSize, fontName, Label::ANTIALIAS_FULL); newLine->setColor(0,0,0,1); addChild(newLine); lines.push_back(newLine); newLine->setText(strings[i]); } } restructLines(); }
int UITextInput::insertLine(bool after) { numLines++; ScreenLabel *newLine = new ScreenLabel(L"", fontSize, fontName, Label::ANTIALIAS_FULL); newLine->setColor(0,0,0,1); lineHeight = newLine->getHeight(); addChild(newLine); if(after) { if(currentLine) { String ctext = currentLine->getText(); String text2 = ctext.substr(caretPosition, ctext.length()-caretPosition); ctext = ctext.substr(0,caretPosition); currentLine->setText(ctext); newLine->setText(text2); caretPosition=0; } currentLine = newLine; vector<ScreenLabel*>::iterator it; it = lines.begin(); for(int i=0; i < lineOffset+1; i++) { it++; } lineOffset = lineOffset + 1; lines.insert(it,newLine); restructLines(); } else { // do we even need that? I don't think so. } dispatchEvent(new UIEvent(), UIEvent::CHANGE_EVENT); return 1; }