diff options
Diffstat (limited to 'src/ui/inputwidget.c')
-rw-r--r-- | src/ui/inputwidget.c | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/src/ui/inputwidget.c b/src/ui/inputwidget.c index 6c05dbd1..19623d74 100644 --- a/src/ui/inputwidget.c +++ b/src/ui/inputwidget.c | |||
@@ -11,6 +11,7 @@ static const int REFRESH_INTERVAL = 256; | |||
11 | struct Impl_InputWidget { | 11 | struct Impl_InputWidget { |
12 | iWidget widget; | 12 | iWidget widget; |
13 | enum iInputMode mode; | 13 | enum iInputMode mode; |
14 | iBool isSensitive; | ||
14 | size_t maxLen; | 15 | size_t maxLen; |
15 | iArray text; /* iChar[] */ | 16 | iArray text; /* iChar[] */ |
16 | iArray oldText; /* iChar[] */ | 17 | iArray oldText; /* iChar[] */ |
@@ -30,6 +31,7 @@ void init_InputWidget(iInputWidget *d, size_t maxLen) { | |||
30 | init_Array(&d->oldText, sizeof(iChar)); | 31 | init_Array(&d->oldText, sizeof(iChar)); |
31 | d->font = uiInput_FontId; | 32 | d->font = uiInput_FontId; |
32 | d->cursor = 0; | 33 | d->cursor = 0; |
34 | d->isSensitive = iFalse; | ||
33 | setMaxLen_InputWidget(d, maxLen); | 35 | setMaxLen_InputWidget(d, maxLen); |
34 | if (maxLen == 0) { | 36 | if (maxLen == 0) { |
35 | /* Caller must arrange the width. */ | 37 | /* Caller must arrange the width. */ |
@@ -52,6 +54,10 @@ void setMode_InputWidget(iInputWidget *d, enum iInputMode mode) { | |||
52 | d->mode = mode; | 54 | d->mode = mode; |
53 | } | 55 | } |
54 | 56 | ||
57 | void setSensitive_InputWidget(iInputWidget *d, iBool isSensitive) { | ||
58 | d->isSensitive = isSensitive; | ||
59 | } | ||
60 | |||
55 | const iString *text_InputWidget(const iInputWidget *d) { | 61 | const iString *text_InputWidget(const iInputWidget *d) { |
56 | return collect_String(newUnicodeN_String(constData_Array(&d->text), size_Array(&d->text))); | 62 | return collect_String(newUnicodeN_String(constData_Array(&d->text), size_Array(&d->text))); |
57 | } | 63 | } |
@@ -277,17 +283,27 @@ static iBool processEvent_InputWidget_(iInputWidget *d, const SDL_Event *ev) { | |||
277 | return processEvent_Widget(w, ev); | 283 | return processEvent_Widget(w, ev); |
278 | } | 284 | } |
279 | 285 | ||
286 | static const iChar sensitiveChar_ = 0x25cf; /* black circle */ | ||
287 | |||
280 | static void draw_InputWidget_(const iInputWidget *d) { | 288 | static void draw_InputWidget_(const iInputWidget *d) { |
281 | const uint32_t time = frameTime_Window(get_Window()); | 289 | const uint32_t time = frameTime_Window(get_Window()); |
282 | const iInt2 padding = init_I2(gap_UI / 2, gap_UI / 2); | 290 | const iInt2 padding = init_I2(gap_UI / 2, gap_UI / 2); |
283 | iRect bounds = adjusted_Rect(bounds_Widget(constAs_Widget(d)), padding, neg_I2(padding)); | 291 | iRect bounds = adjusted_Rect(bounds_Widget(constAs_Widget(d)), padding, neg_I2(padding)); |
284 | const iBool isFocused = isFocused_Widget(constAs_Widget(d)); | 292 | const iBool isFocused = isFocused_Widget(constAs_Widget(d)); |
285 | const iBool isHover = isHover_Widget(constAs_Widget(d)) && | 293 | const iBool isHover = isHover_Widget(constAs_Widget(d)) && |
286 | contains_Widget(constAs_Widget(d), mouseCoord_Window(get_Window())); | 294 | contains_Widget(constAs_Widget(d), mouseCoord_Window(get_Window())); |
287 | iPaint p; | 295 | iPaint p; |
288 | init_Paint(&p); | 296 | init_Paint(&p); |
289 | iString text; | 297 | iString text; |
290 | initUnicodeN_String(&text, constData_Array(&d->text), size_Array(&d->text)); | 298 | if (!d->isSensitive) { |
299 | initUnicodeN_String(&text, constData_Array(&d->text), size_Array(&d->text)); | ||
300 | } | ||
301 | else { | ||
302 | init_String(&text); | ||
303 | for (size_t i = 0; i < size_Array(&d->text); ++i) { | ||
304 | appendChar_String(&text, sensitiveChar_); | ||
305 | } | ||
306 | } | ||
291 | fillRect_Paint(&p, bounds, black_ColorId); | 307 | fillRect_Paint(&p, bounds, black_ColorId); |
292 | drawRect_Paint(&p, | 308 | drawRect_Paint(&p, |
293 | adjusted_Rect(bounds, neg_I2(one_I2()), zero_I2()), | 309 | adjusted_Rect(bounds, neg_I2(one_I2()), zero_I2()), |
@@ -322,7 +338,12 @@ static void draw_InputWidget_(const iInputWidget *d) { | |||
322 | const iRect curRect = { curPos, addX_I2(emSize, 1) }; | 338 | const iRect curRect = { curPos, addX_I2(emSize, 1) }; |
323 | iString cur; | 339 | iString cur; |
324 | if (d->cursor < size_Array(&d->text)) { | 340 | if (d->cursor < size_Array(&d->text)) { |
325 | initUnicodeN_String(&cur, constAt_Array(&d->text, d->cursor), 1); | 341 | if (!d->isSensitive) { |
342 | initUnicodeN_String(&cur, constAt_Array(&d->text, d->cursor), 1); | ||
343 | } | ||
344 | else { | ||
345 | initUnicodeN_String(&cur, &sensitiveChar_, 1); | ||
346 | } | ||
326 | } | 347 | } |
327 | else { | 348 | else { |
328 | initCStr_String(&cur, " "); | 349 | initCStr_String(&cur, " "); |