| 286 | } |
| 287 | |
| 288 | void UIEdit::DrawText() { |
| 289 | char buffer[EDIT_BUFLEN_MAX]; |
| 290 | int str_w, i, cursor_w; |
| 291 | |
| 292 | if (m_FontHandle > -1) |
| 293 | ui_DrawSetFont(m_FontHandle); |
| 294 | |
| 295 | // I need an extra character. |
| 296 | ASSERT(strlen(m_TextBuf) < sizeof(buffer)); |
| 297 | |
| 298 | if (m_Flags & UIED_PASSWORD) { |
| 299 | memset(buffer, '*', strlen(m_TextBuf)); |
| 300 | buffer[strlen(m_TextBuf)] = 0; |
| 301 | } else { |
| 302 | strcpy(buffer, m_TextBuf); |
| 303 | } |
| 304 | |
| 305 | if (m_Active || HasFocus()) |
| 306 | ui_SetCharAlpha(255); |
| 307 | else |
| 308 | ui_SetCharAlpha(164); |
| 309 | |
| 310 | if (IsDisabled()) |
| 311 | ui_SetCharAlpha(96); |
| 312 | |
| 313 | // we must set StartPos if StartPos is -1 |
| 314 | if (m_StartPos < 0) { |
| 315 | m_StartPos = 0; |
| 316 | cursor_w = ui_GetTextWidth("_"); |
| 317 | str_w = ui_GetTextWidth(&buffer[m_StartPos]); |
| 318 | while ((m_X1b + str_w) > (m_X2b - cursor_w)) { |
| 319 | m_StartPos++; |
| 320 | str_w = ui_GetTextWidth(&buffer[m_StartPos]); |
| 321 | } |
| 322 | } |
| 323 | |
| 324 | // determine how much of string to draw at one time. |
| 325 | i = 0; |
| 326 | |
| 327 | cursor_w = ui_GetTextWidth("_") * 2; |
| 328 | str_w = ui_GetTextWidth(&buffer[m_StartPos]); |
| 329 | while ((m_X1b + str_w) > (m_X2b - cursor_w) && ((int)strlen(buffer) > m_StartPos)) { |
| 330 | buffer[strlen(buffer) - 1] = 0; |
| 331 | str_w = ui_GetTextWidth(&buffer[m_StartPos]); |
| 332 | i++; |
| 333 | } |
| 334 | |
| 335 | // if i is > 0, then the string displayed overlaps the boundaries of the listbox |
| 336 | m_ScrollThresh = i ? (strlen(buffer)) : 0; |
| 337 | |
| 338 | if (m_ScrollThresh && m_UpdateCount) { |
| 339 | m_StartPos++; |
| 340 | m_UpdateCount = false; |
| 341 | } |
| 342 | |
| 343 | // if cursor position is outside viewing region, we must adjust the viewing region. |
| 344 | // i = strlen(buffer); |
| 345 | // while (m_CurPos > i) |
no test coverage detected