Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed password option #532

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Modules/Contents/UI/Include/PolyUITextInput.h
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,8 @@ namespace Polycode {
void doMultilineResize();

static void setMenuSingleton(UIGlobalMenu *_globalMenu);

void setPassword(bool password);

protected:

Expand Down Expand Up @@ -486,6 +488,7 @@ namespace Polycode {
int maxRedoIndex;
bool isTypingWord;

bool password;
bool multiLine;
Timer *blinkTimer;
UIBox *inputRect;
Expand Down
55 changes: 46 additions & 9 deletions Modules/Contents/UI/Source/PolyUITextInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,8 @@ UITextInput::UITextInput(bool multiLine, Number width, Number height) : UIElemen
indentType = INDENT_TAB;

core->getInput()->addEventListener(this, InputEvent::EVENT_KEYDOWN);

setPassword(false);
}

void UITextInput::checkBufferLines() {
Expand Down Expand Up @@ -974,16 +976,39 @@ void UITextInput::updateCaretPosition() {
setActualLineOffset();
}

caretImagePosition = 0;
if(caretPosition == 0) {
if(password) {
caretImagePosition = 0;
} else if(caretPosition > wordWrapLines[lineOffset].text.length()) {
caretPosition = wordWrapLines[lineOffset].text.length();
String caretSubString = wordWrapLines[lineOffset].text.substr(0,caretPosition);
caretImagePosition = bufferLines[0]->getTextWidthForString(caretSubString);
String passText = "";

if(caretPosition == 0) {
caretImagePosition = 0;
} else if(caretPosition > wordWrapLines[lineOffset].text.length()) {
caretPosition = wordWrapLines[lineOffset].text.length();
String caretSubString = wordWrapLines[lineOffset].text.substr(0,caretPosition);
for(int i = 0; i < caretSubString.length(); i++) {
passText += "*";
}
caretImagePosition = bufferLines[0]->getTextWidthForString(passText);
} else {
String caretSubString = wordWrapLines[lineOffset].text.substr(0,caretPosition);
for(int i = 0; i < caretSubString.length(); i++) {
passText += "*";
}
caretImagePosition = bufferLines[0]->getTextWidthForString(passText);
}
} else {
String caretSubString = wordWrapLines[lineOffset].text.substr(0,caretPosition);
caretImagePosition = bufferLines[0]->getTextWidthForString(caretSubString);
caretImagePosition = 0;

if(caretPosition == 0) {
caretImagePosition = 0;
} else if(caretPosition > wordWrapLines[lineOffset].text.length()) {
caretPosition = wordWrapLines[lineOffset].text.length();
String caretSubString = wordWrapLines[lineOffset].text.substr(0,caretPosition);
caretImagePosition = bufferLines[0]->getTextWidthForString(caretSubString);
} else {
String caretSubString = wordWrapLines[lineOffset].text.substr(0,caretPosition);
caretImagePosition = bufferLines[0]->getTextWidthForString(caretSubString);
}
}

if(!hasSelection) {
Expand Down Expand Up @@ -2424,8 +2449,16 @@ void UITextInput::readjustBuffer(int lineStart, int lineEnd) {
}
}
}
// if(bufferOffset+i >= lineStart && bufferOffset+i <= lineEnd) {
// if(bufferOffset+i >= lineStart && bufferOffset+i <= lineEnd) {
if(password) {
String passText = "";
for(int pst = 0; pst < wordWrapLines[bufferOffset+i].text.length(); pst++) {
passText += "*";
}
bufferLines[i]->setText(passText);
} else {
bufferLines[i]->setText(wordWrapLines[bufferOffset+i].text);
}
// }
bufferLines[i]->visible = true;
} else {
Expand Down Expand Up @@ -2651,4 +2684,8 @@ void UITextInput::convertIndentToTabs() {

//TODO
}
}

void UITextInput::setPassword(bool password) {
this->password = password;
}