| 218 | } |
| 219 | |
| 220 | void TextEntry::OnClicked(float x, float y, bool right) |
| 221 | { |
| 222 | if (right) |
| 223 | return; |
| 224 | |
| 225 | float xOffset = 2; |
| 226 | if (mDrawLabel) |
| 227 | xOffset += mLabelSize; |
| 228 | |
| 229 | if (sKeyboardFocusBeforeClick != this) |
| 230 | { |
| 231 | SelectAll(); |
| 232 | } |
| 233 | else |
| 234 | { |
| 235 | mCaretPosition = 0; |
| 236 | |
| 237 | char caretCheck[MAX_TEXTENTRY_LENGTH]; |
| 238 | size_t checkLength = strnlen(mString, MAX_TEXTENTRY_LENGTH); |
| 239 | strncpy(caretCheck, mString, checkLength); |
| 240 | int lastSubstrWidth = gFontFixedWidth.GetStringWidth(caretCheck, 12); |
| 241 | for (int i = (int)checkLength - 1; i >= 0; --i) |
| 242 | { |
| 243 | caretCheck[i] = 0; //shorten string by one |
| 244 | |
| 245 | int substrWidth = gFontFixedWidth.GetStringWidth(caretCheck, 12); |
| 246 | //ofLog() << x << " " << i << " " << (xOffset + substrWidth); |
| 247 | if (x > xOffset + ((substrWidth + lastSubstrWidth) * .5f)) |
| 248 | { |
| 249 | mCaretPosition = i + 1; |
| 250 | break; |
| 251 | } |
| 252 | |
| 253 | lastSubstrWidth = substrWidth; |
| 254 | } |
| 255 | |
| 256 | mCaretPosition2 = mCaretPosition; |
| 257 | } |
| 258 | |
| 259 | MakeActiveTextEntry(false); |
| 260 | } |
| 261 | |
| 262 | void TextEntry::MakeActiveTextEntry(bool setCaretToEnd) |
| 263 | { |
nothing calls this directly
no test coverage detected