void idEditWindow::Activate(bool activate, idStr &act) { idWindow::Activate(activate, act); if ( activate ) { UpdateCvar( true, true ); EnsureCursorVisible(); } }
const char *idSliderWindow::HandleEvent(const sysEvent_t *event, bool *updateVisuals) { if (!(event->evType == SE_KEY && event->evValue2)) { return ""; } int key = event->evValue; if ( event->evValue2 && key == K_MOUSE1 ) { SetCapture(this); RouteMouseCoords(0.0f, 0.0f); return ""; } if ( key == K_RIGHTARROW || key == K_KP_RIGHTARROW || ( key == K_MOUSE2 && gui->CursorY() > thumbRect.y ) ) { value = value + stepSize; } if ( key == K_LEFTARROW || key == K_KP_LEFTARROW || ( key == K_MOUSE2 && gui->CursorY() < thumbRect.y ) ) { value = value - stepSize; } if (buddyWin) { buddyWin->HandleBuddyUpdate(this); } else { gui->SetStateFloat( cvarStr, value ); UpdateCvar( false ); } return ""; }
/* ============ idEditWindow::RunNamedEvent ============ */ void idEditWindow::RunNamedEvent( const char* eventName ) { idStr event, group; if ( !idStr::Cmpn( eventName, "cvar read ", 10 ) ) { event = eventName; group = event.Mid( 10, event.Length() - 10 ); if ( !group.Cmp( cvarGroup ) ) { UpdateCvar( true, true ); } } else if ( !idStr::Cmpn( eventName, "cvar write ", 11 ) ) { event = eventName; group = event.Mid( 11, event.Length() - 11 ); if ( !group.Cmp( cvarGroup ) ) { UpdateCvar( false, true ); } } }
void idSliderWindow::Activate( bool activate, idStr& act ) { idWindow::Activate( activate, act ); if( activate ) { UpdateCvar( true, true ); } }
void idSliderWindow::Draw(int time, float x, float y) { idVec4 color = foreColor; if ( !cvar && !buddyWin ) { return; } if ( !thumbWidth || !thumbHeight ) { thumbWidth = thumbMat->GetImageWidth(); thumbHeight = thumbMat->GetImageHeight(); } UpdateCvar( true ); if ( value > high ) { value = high; } else if ( value < low ) { value = low; } float range = high - low; if ( range <= 0.0f ) { return; } float thumbPos = (range) ? (value - low) / range : 0.0; if (vertical) { if ( verticalFlip ) { thumbPos = 1.f - thumbPos; } thumbPos *= drawRect.h - thumbHeight; thumbPos += drawRect.y; thumbRect.y = thumbPos; thumbRect.x = drawRect.x; } else { thumbPos *= drawRect.w - thumbWidth; thumbPos += drawRect.x; thumbRect.x = thumbPos; thumbRect.y = drawRect.y; } thumbRect.w = thumbWidth; thumbRect.h = thumbHeight; if ( hover && !noEvents && Contains(gui->CursorX(), gui->CursorY()) ) { color = hoverColor; } else { hover = false; } if ( flags & WIN_CAPTURE ) { color = hoverColor; hover = true; } dc->DrawMaterial(thumbRect.x, thumbRect.y, thumbRect.w, thumbRect.h, thumbMat, color); if ( flags & WIN_FOCUS ) { dc->DrawRect(thumbRect.x+1.0f, thumbRect.y+1.0f, thumbRect.w-2.0f, thumbRect.h-2.0f, 1.0f, color); } }
const char *idSliderWindow::RouteMouseCoords(float xd, float yd) { float pct; if (!(flags & WIN_CAPTURE)) { return ""; } idRectangle r = drawRect; r.x = actualX; r.y = actualY; r.x += thumbWidth / 2.0; r.w -= thumbWidth; if (vertical) { r.y += thumbHeight / 2; r.h -= thumbHeight; if (gui->CursorY() >= r.y && gui->CursorY() <= r.Bottom()) { pct = (gui->CursorY() - r.y) / r.h; if ( verticalFlip ) { pct = 1.f - pct; } value = low + (high - low) * pct; } else if (gui->CursorY() < r.y) { if ( verticalFlip ) { value = high; } else { value = low; } } else { if ( verticalFlip ) { value = low; } else { value = high; } } } else { r.x += thumbWidth / 2; r.w -= thumbWidth; if (gui->CursorX() >= r.x && gui->CursorX() <= r.Right()) { pct = (gui->CursorX() - r.x) / r.w; value = low + (high - low) * pct; } else if (gui->CursorX() < r.x) { value = low; } else { value = high; } } if (buddyWin) { buddyWin->HandleBuddyUpdate(this); } else { gui->SetStateFloat( cvarStr, value ); } UpdateCvar( false ); return ""; }
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); }
/* ============= 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 ""; }