MCPcopy Create free account
hub / github.com/BespokeSynth/BespokeSynth / OnClicked

Method OnClicked

Source/TextEntry.cpp:220–260  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

218}
219
220void 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
262void TextEntry::MakeActiveTextEntry(bool setCaretToEnd)
263{

Callers

nothing calls this directly

Calls 1

GetStringWidthMethod · 0.80

Tested by

no test coverage detected