void idEditWindow::Activate(bool activate, idStr &act) { idWindow::Activate(activate, act); if ( activate ) { UpdateCvar( true, true ); EnsureCursorVisible(); } }
void idEditWindow::Draw( int time, float x, float y ) { idVec4 color = foreColor; UpdateCvar( true ); int len = text.Length(); if ( len != lastTextLength ) { scroller->SetValue( 0.0f ); EnsureCursorVisible(); lastTextLength = len; } float scale = textScale; idStr pass; const char* buffer; if ( password ) { const char* temp = text; for ( ; *temp; temp++ ) { pass += "*"; } buffer = pass; } else { buffer = text; } if ( cursorPos > len ) { cursorPos = len; } idRectangle rect = textRect; rect.x -= paintOffset; rect.w += paintOffset; if ( wrap && scroller->GetHigh() > 0.0f ) { float lineHeight = GetMaxCharHeight( ) + 5; rect.y -= scroller->GetValue() * lineHeight; rect.w -= sizeBias; rect.h = ( breaks.Num() + 1 ) * lineHeight; } if ( hover && !noEvents && Contains(gui->CursorX(), gui->CursorY()) ) { color = hoverColor; } else { hover = false; } if ( flags & WIN_FOCUS ) { color = hoverColor; } dc->DrawText( buffer, scale, 0, color, rect, wrap, (flags & WIN_FOCUS) ? cursorPos : -1); }
void idEditWindow::PostParse() { idWindow::PostParse(); if ( maxChars == 0 ) { maxChars = 10; } if ( sourceFile.Length() ) { void *buffer; fileSystem->ReadFile( sourceFile, &buffer ); text = (char *) buffer; fileSystem->FreeFile( buffer ); } InitCvar(); InitScroller(false); EnsureCursorVisible(); flags |= WIN_CANFOCUS; }
WEBC_BOOL WebEditBox::GetFocusRect (WebRect* rect) { WebGraphics *gc = GetGraphics(); WebFont font = mFont.GetFont(); if (gc && font && mpText && (mEditFlags & EDIT_FLAG_ENSURE_CURSOR_VISIBLE)) { EnsureCursorVisible(); DISPLAY_INT cursorX = gc->TextWidthLen(mpText + GetLineOffset(miCurrentLine), font, miCursorPos - GetLineOffset(miCurrentLine)) - miXOffset; DISPLAY_INT cursorY = WEB_FONT_HEIGHT(font)*miCurrentLine - miYOffset; GetTextRect(rect); rect->Shift(cursorX, cursorY); rect->SizeTo(5, WEB_FONT_HEIGHT(font)); return WEBC_TRUE; } return WEBC_FALSE; }
/* ============= idEditWindow::HandleEvent ============= */ const char* idEditWindow::HandleEvent( const sysEvent_t* event, bool* updateVisuals ) { static char buffer[ MAX_EDITFIELD ]; if( wrap ) { // need to call this to allow proper focus and capturing on embedded children const char* ret = idWindow::HandleEvent( event, updateVisuals ); if( ret != NULL && *ret != NULL ) { return ret; } } if( ( event->evType != SE_CHAR && event->evType != SE_KEY ) ) { return ""; } idStr::Copynz( buffer, text.c_str(), sizeof( buffer ) ); int key = event->evValue; int len = text.Length(); if( event->evType == SE_CHAR ) { if( key == '`' ) { return ""; } if( updateVisuals ) { *updateVisuals = true; } if( maxChars && len > maxChars ) { len = maxChars; } if( readonly ) { return ""; } // // ignore any non printable chars (except enter when wrap is enabled) // if( wrap && ( key == K_ENTER || key == K_KP_ENTER ) ) { } else if( !idStr::CharIsPrintable( key ) ) { return ""; } if( numeric ) { if( ( key < '0' || key > '9' ) && key != '.' ) { return ""; } } if( dc->GetOverStrike() ) { if( maxChars && cursorPos >= maxChars ) { return ""; } } else { if( ( len == MAX_EDITFIELD - 1 ) || ( maxChars && len >= maxChars ) ) { return ""; } memmove( &buffer[ cursorPos + 1 ], &buffer[ cursorPos ], len + 1 - cursorPos ); } buffer[ cursorPos ] = key; text = buffer; UpdateCvar( false ); RunScript( ON_ACTION ); if( cursorPos < len + 1 ) { cursorPos++; } EnsureCursorVisible(); } else if( event->evType == SE_KEY && event->evValue2 ) { if( updateVisuals ) { *updateVisuals = true; } if( key == K_DEL ) { if( readonly ) { return ""; } if( cursorPos < len ) { memmove( &buffer[cursorPos], &buffer[cursorPos + 1], len - cursorPos ); text = buffer; UpdateCvar( false ); RunScript( ON_ACTION ); } return ""; } if( key == K_BACKSPACE ) // ctrl-h is backspace { if( readonly ) { return ""; } if( cursorPos > 0 ) { if( cursorPos >= len ) { buffer[len - 1] = 0; cursorPos = len - 1; } else { memmove( &buffer[ cursorPos - 1 ], &buffer[ cursorPos ], len + 1 - cursorPos ); cursorPos--; } text = buffer; UpdateCvar( false ); RunScript( ON_ACTION ); } return ""; } if( key == K_RIGHTARROW ) { if( cursorPos < len ) { if( ( idKeyInput::IsDown( K_LCTRL ) || idKeyInput::IsDown( K_RCTRL ) ) ) { // skip to next word while( ( cursorPos < len ) && ( buffer[ cursorPos ] != ' ' ) ) { cursorPos++; } while( ( cursorPos < len ) && ( buffer[ cursorPos ] == ' ' ) ) { cursorPos++; } } else { if( cursorPos < len ) { cursorPos++; } } } EnsureCursorVisible(); return ""; } if( key == K_LEFTARROW ) { if( ( idKeyInput::IsDown( K_LCTRL ) || idKeyInput::IsDown( K_RCTRL ) ) ) { // skip to previous word while( ( cursorPos > 0 ) && ( buffer[ cursorPos - 1 ] == ' ' ) ) { cursorPos--; } while( ( cursorPos > 0 ) && ( buffer[ cursorPos - 1 ] != ' ' ) ) { cursorPos--; } } else { if( cursorPos > 0 ) { cursorPos--; } } EnsureCursorVisible(); return ""; } if( key == K_HOME ) { if( ( idKeyInput::IsDown( K_LCTRL ) || idKeyInput::IsDown( K_RCTRL ) ) || cursorLine <= 0 || ( cursorLine >= breaks.Num() ) ) { cursorPos = 0; } else { cursorPos = breaks[cursorLine]; } EnsureCursorVisible(); return ""; } if( key == K_END ) { if( ( idKeyInput::IsDown( K_LCTRL ) || idKeyInput::IsDown( K_RCTRL ) ) || ( cursorLine < -1 ) || ( cursorLine >= breaks.Num() - 1 ) ) { cursorPos = len; } else { cursorPos = breaks[cursorLine + 1] - 1; } EnsureCursorVisible(); return ""; } if( key == K_INS ) { if( !readonly ) { dc->SetOverStrike( !dc->GetOverStrike() ); } return ""; } if( key == K_DOWNARROW ) { if( ( idKeyInput::IsDown( K_LCTRL ) || idKeyInput::IsDown( K_RCTRL ) ) ) { scroller->SetValue( scroller->GetValue() + 1.0f ); } else { if( cursorLine < breaks.Num() - 1 ) { int offset = cursorPos - breaks[cursorLine]; cursorPos = breaks[cursorLine + 1] + offset; EnsureCursorVisible(); } } } if( key == K_UPARROW ) { if( ( idKeyInput::IsDown( K_LCTRL ) || idKeyInput::IsDown( K_RCTRL ) ) ) { scroller->SetValue( scroller->GetValue() - 1.0f ); } else { if( cursorLine > 0 ) { int offset = cursorPos - breaks[cursorLine]; cursorPos = breaks[cursorLine - 1] + offset; EnsureCursorVisible(); } } } if( key == K_ENTER || key == K_KP_ENTER ) { RunScript( ON_ACTION ); RunScript( ON_ENTER ); return cmd; } if( key == K_ESCAPE ) { RunScript( ON_ESC ); return cmd; } } else if( event->evType == SE_KEY && !event->evValue2 ) { if( key == K_ENTER || key == K_KP_ENTER ) { RunScript( ON_ENTERRELEASE ); return cmd; } else { RunScript( ON_ACTIONRELEASE ); } } return ""; }
void idEditWindow::GainFocus() { cursorPos = text.Length(); EnsureCursorVisible(); }