//----------------------------------------------------------------------------- // Purpose: Constructor //----------------------------------------------------------------------------- TextTooltip::TextTooltip(Panel *parent, const char *text) : BaseTooltip( parent, text ) { if (!s_TooltipWindow.Get()) { s_TooltipWindow = new TextEntry(NULL, "tooltip"); s_TooltipWindow->InvalidateLayout(false, true); // this bit of hackery is necessary because tooltips don't get ApplySchemeSettings called from their parents IScheme *pScheme = scheme()->GetIScheme( s_TooltipWindow->GetScheme() ); s_TooltipWindow->SetBgColor(s_TooltipWindow->GetSchemeColor("Tooltip.BgColor", s_TooltipWindow->GetBgColor(), pScheme)); s_TooltipWindow->SetFgColor(s_TooltipWindow->GetSchemeColor("Tooltip.TextColor", s_TooltipWindow->GetFgColor(), pScheme)); s_TooltipWindow->SetBorder(pScheme->GetBorder("ToolTipBorder")); s_TooltipWindow->SetFont( pScheme->GetFont("DefaultSmall", s_TooltipWindow->IsProportional())); } s_iTooltipWindowCount++; // this line prevents the main window from losing focus // when a tooltip pops up s_TooltipWindow->MakePopup(false, true); s_TooltipWindow->SetKeyBoardInputEnabled( false ); s_TooltipWindow->SetMouseInputEnabled( false ); SetText(text); s_TooltipWindow->SetText(m_Text.Base()); s_TooltipWindow->SetEditable(false); s_TooltipWindow->SetMultiline(true); s_TooltipWindow->SetVisible(false); }
//----------------------------------------------------------------------------- // Purpose: Return the full size of the contained content //----------------------------------------------------------------------------- void Label::GetContentSize(int &wide, int &tall) { if( GetFont() == INVALID_FONT ) // we haven't loaded our font yet, so load it now { IScheme *pScheme = scheme()->GetIScheme( GetScheme() ); if ( pScheme ) { SetFont( pScheme->GetFont( "Default", IsProportional() ) ); } } int tx0, ty0, tx1, ty1; ComputeAlignment(tx0, ty0, tx1, ty1); // the +8 is padding to the content size // the code which uses it should really set that itself; // however a lot of existing code relies on this wide = (tx1 - tx0) + _textInset[0]; // get the size of the text image and remove it int iWide, iTall; _textImage->GetSize(iWide, iTall); wide -= iWide; // get the full, untruncated (no elipsis) size of the text image. _textImage->GetContentSize(iWide, iTall); wide += iWide; // addin the image offsets as well for (int i=0; i < _imageDar.Size(); i++) wide += _imageDar[i].offset; tall = max((ty1 - ty0) + _textInset[1], iTall); }
//----------------------------------------------------------------------------- // Purpose: lays out controls //----------------------------------------------------------------------------- void CConsolePanel::PerformLayout() { BaseClass::PerformLayout(); // setup tab ordering GetFocusNavGroup().SetDefaultButton(m_pSubmit); IScheme *pScheme = scheme()->GetIScheme( GetScheme() ); m_pEntry->SetBorder(pScheme->GetBorder("DepressedButtonBorder")); m_pHistory->SetBorder(pScheme->GetBorder("DepressedButtonBorder")); // layout controls int wide, tall; GetSize(wide, tall); if ( !m_bStatusVersion ) { const int inset = 8; const int entryHeight = 24; const int topHeight = 4; const int entryInset = 4; const int submitWide = 64; const int submitInset = 7; // x inset to pull the submit button away from the frame grab m_pHistory->SetPos(inset, inset + topHeight); m_pHistory->SetSize(wide - (inset * 2), tall - (entryInset * 2 + inset * 2 + topHeight + entryHeight)); m_pHistory->InvalidateLayout(); int nSubmitXPos = wide - ( inset + submitWide + submitInset ); m_pSubmit->SetPos( nSubmitXPos, tall - (entryInset * 2 + entryHeight)); m_pSubmit->SetSize( submitWide, entryHeight); m_pEntry->SetPos( inset, tall - (entryInset * 2 + entryHeight) ); m_pEntry->SetSize( nSubmitXPos - entryInset - 2 * inset, entryHeight); } else { const int inset = 2; int entryWidth = wide / 2; if ( wide > 400 ) { entryWidth = 200; } m_pEntry->SetBounds( inset, inset, entryWidth, tall - 2 * inset ); m_pHistory->SetBounds( inset + entryWidth + inset, inset, ( wide - entryWidth ) - inset, tall - 2 * inset ); } UpdateCompletionListPosition(); }
void MenuBar::Paint() { IScheme *pScheme = scheme()->GetIScheme( GetScheme() ); for ( int i = 0; i < m_pMenuButtons.Count(); i++) { if (!m_pMenuButtons[i]->IsArmed()) m_pMenuButtons[i]->SetDefaultBorder(NULL); else { m_pMenuButtons[i]->SetDefaultBorder(pScheme->GetBorder( "ButtonBorder")); } } }
//----------------------------------------------------------------------------- // Purpose: Applies designer settings from res file //----------------------------------------------------------------------------- void ImagePanel::ApplySettings(KeyValues *inResourceData) { delete [] m_pszImageName; delete [] m_pszFillColorName; m_pszImageName = NULL; m_pszFillColorName = NULL; m_bScaleImage = inResourceData->GetInt("scaleImage", 0); m_fScaleAmount = inResourceData->GetFloat("scaleAmount", 0.0f); m_bTileImage = inResourceData->GetInt("tileImage", 0); m_bTileHorizontally = inResourceData->GetInt("tileHorizontally", m_bTileImage); m_bTileVertically = inResourceData->GetInt("tileVertically", m_bTileImage); const char *imageName = inResourceData->GetString("image", ""); if (*imageName) { SetImage( imageName ); } const char *pszFillColor = inResourceData->GetString("fillcolor", ""); if (*pszFillColor) { int r = 0, g = 0, b = 0, a = 255; int len = Q_strlen(pszFillColor) + 1; m_pszFillColorName = new char[ len ]; Q_strncpy( m_pszFillColorName, pszFillColor, len ); if (sscanf(pszFillColor, "%d %d %d %d", &r, &g, &b, &a) >= 3) { // it's a direct color m_FillColor = Color(r, g, b, a); } else { IScheme *pScheme = scheme()->GetIScheme( GetScheme() ); m_FillColor = pScheme->GetColor(pszFillColor, Color(0, 0, 0, 0)); } } const char *pszBorder = inResourceData->GetString("border", ""); if (*pszBorder) { IScheme *pScheme = scheme()->GetIScheme( GetScheme() ); SetBorder(pScheme->GetBorder(pszBorder)); } BaseClass::ApplySettings(inResourceData); }
void ImageButton::UpdateColors() { if (m_bButtonEnabled) { if (m_pLabel) { if (!IsCursorOver() || !m_bDoMouseOvers) m_pLabel->SetFgColor(m_TextColor); else m_pLabel->SetFgColor(m_MouseOverTextColor); } if (m_pBackdrop) { m_pBackdrop->SetDrawColor(m_ImageColor); } IScheme *pScheme = scheme()->GetIScheme( GetScheme() ); if (pScheme) { int bg = GetPaintBackgroundType(); SetBorder(pScheme->GetBorder(m_szBorder)); SetPaintBackgroundType(bg); } } else { if (m_pLabel) { m_pLabel->SetFgColor(m_DisabledTextColor); } if (m_pBackdrop) { m_pBackdrop->SetDrawColor(m_DisabledImageColor); } IScheme *pScheme = scheme()->GetIScheme( GetScheme() ); if (pScheme) { int bg = GetPaintBackgroundType(); SetBorder(pScheme->GetBorder(m_szBorderDisabled)); SetPaintBackgroundType(bg); } } }
//----------------------------------------------------------------------------- // Purpose: Draw Tick labels under the ticks. //----------------------------------------------------------------------------- void CLabeledSlider::DrawTickLabels() { int x, y; int wide,tall; GetTrackRect( x, y, wide, tall ); // Figure out how to draw the ticks GetPaintSize( wide, tall ); float fwide = (float)wide; float fnobsize = 8; float freepixels = fwide - fnobsize; float leftpixel = fnobsize / 2.0f; float pixelspertick = freepixels / ( m_nNumTicks ); y = y + (int)fnobsize + 4; // Draw Start and end range values surface()->DrawSetTextColor( Color( 127, 140, 127, 255 ) ); surface()->DrawSetTextPos( 0, y); IScheme *pScheme = scheme()->GetIScheme( scheme()->GetDefaultScheme() ); if ( m_szTickCaptions[ 0 ][ 0 ] ) { surface()->DrawSetTextFont(pScheme->GetFont("DefaultVerySmall")); surface()->DrawPrintText( (const unsigned short *)m_szTickCaptions[ 0 ], strlen( m_szTickCaptions[ 0 ] ) ); } if ( m_szTickCaptions[ 1 ][ 0 ] ) { surface()->DrawSetTextFont(pScheme->GetFont("DefaultVerySmall")); // was 5 * now is 2 * surface()->DrawSetTextPos( (int)( m_nNumTicks * pixelspertick - 2 * strlen( m_szTickCaptions[ 1 ] ) ), y); surface()->DrawPrintText((const unsigned short *) m_szTickCaptions[ 1 ], strlen( m_szTickCaptions[ 1 ] ) ); } }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- Color CHudChat::GetTextColorForClient( TextColor colorNum, int clientIndex ) { IScheme *pScheme = scheme()->GetIScheme( GetScheme() ); if ( pScheme == NULL ) return Color( 255, 255, 255, 255 ); Color c; switch ( colorNum ) { case COLOR_PLAYERNAME: c = GetClientColor( clientIndex ); break; case COLOR_LOCATION: c = g_ColorDarkGreen; break; case COLOR_ACHIEVEMENT: { IScheme *pSourceScheme = scheme()->GetIScheme( scheme()->GetScheme( "SourceScheme" ) ); if ( pSourceScheme ) { c = pSourceScheme->GetColor( "SteamLightGreen", GetBgColor() ); } else { c = pScheme->GetColor( "TFColors.ChatTextYellow", GetBgColor() ); } } break; default: c = pScheme->GetColor( "TFColors.ChatTextYellow", GetBgColor() ); } return Color( c[0], c[1], c[2], 255 ); }
//----------------------------------------------------------------------------- Color CHudChat::GetClientColor( int clientIndex ) { IScheme *pScheme = scheme()->GetIScheme( GetScheme() ); if ( pScheme == NULL ) return Color( 255, 255, 255, 255 ); if ( clientIndex == 0 ) // console msg { return g_ColorGreen; } else if( g_PR ) { int iTeam = g_PR->GetTeam( clientIndex ); C_TFPlayer *pPlayer = ToTFPlayer( UTIL_PlayerByIndex( clientIndex ) ); C_TFPlayer *pLocalPlayer = C_TFPlayer::GetLocalTFPlayer(); if ( IsVoiceSubtitle() == true ) { // if this player is on the other team, disguised as my team, show disguised color if ( pPlayer && pLocalPlayer && pPlayer->m_Shared.InCond( TF_COND_DISGUISED ) && pPlayer->m_Shared.GetDisguiseTeam() == pLocalPlayer->GetTeamNumber() ) { iTeam = pPlayer->m_Shared.GetDisguiseTeam(); } } switch ( iTeam ) { case TF_TEAM_RED : return pScheme->GetColor( "TFColors.ChatTextRed", g_ColorRed ); case TF_TEAM_BLUE : return pScheme->GetColor( "TFColors.ChatTextBlue", g_ColorBlue );; default : return g_ColorGrey; } } return g_ColorYellow; }
// This style is like the IE "back" button where the left side acts like a regular button, the the right side has a little // combo box dropdown indicator and presents and submenu void MenuButton::SetDropMenuButtonStyle( bool state ) { bool changed = m_bDropMenuButtonStyle != state; m_bDropMenuButtonStyle = state; if ( !changed ) return; if ( state ) { m_pDropMenuImage = new TextImage( "u" ); IScheme *pScheme = scheme()->GetIScheme( GetScheme() ); m_pDropMenuImage->SetFont(pScheme->GetFont("Marlett", IsProportional())); // m_pDropMenuImage->SetContentAlignment(Label::a_west); // m_pDropMenuImage->SetTextInset(3, 0); m_nImageIndex = AddImage( m_pDropMenuImage, 0 ); } else { ResetToSimpleTextImage(); delete m_pDropMenuImage; m_pDropMenuImage = NULL; m_nImageIndex = -1; } }
//----------------------------------------------------------------------------- // Purpose: Display the tooltip //----------------------------------------------------------------------------- void Tooltip::PerformLayout() { if (!_makeVisible) return; if (_delay > system()->GetTimeMillis()) return; // we're ready, just make us visible if ( !s_TooltipWindow.Get() ) return; // We only need to layout when we first become visible if ( !_isDirty ) return; _isDirty = false; s_TooltipWindow->SetVisible(true); s_TooltipWindow->MakePopup( false, true ); s_TooltipWindow->SetKeyBoardInputEnabled( false ); s_TooltipWindow->SetMouseInputEnabled( false ); IScheme *pScheme = scheme()->GetIScheme( s_TooltipWindow->GetScheme() ); s_TooltipWindow->SetBgColor(s_TooltipWindow->GetSchemeColor("Tooltip.BgColor", s_TooltipWindow->GetBgColor(), pScheme)); s_TooltipWindow->SetFgColor(s_TooltipWindow->GetSchemeColor("Tooltip.TextColor", s_TooltipWindow->GetFgColor(), pScheme)); s_TooltipWindow->SetBorder(pScheme->GetBorder("ToolTipBorder")); // get cursor position int cursorX, cursorY; input()->GetCursorPos(cursorX, cursorY); // relayout the textwindow immediately so that we know it's size //m_pTextEntry->InvalidateLayout(true); SizeTextWindow(); int menuWide, menuTall; s_TooltipWindow->GetSize(menuWide, menuTall); // work out where the cursor is and therefore the best place to put the menu int wide, tall; surface()->GetScreenSize(wide, tall); if (wide - menuWide > cursorX) { cursorY += 20; // menu hanging right if (tall - menuTall > cursorY) { // menu hanging down s_TooltipWindow->SetPos(cursorX, cursorY); } else { // menu hanging up s_TooltipWindow->SetPos(cursorX, cursorY - menuTall - 20); } } else { // menu hanging left if (tall - menuTall > cursorY) { // menu hanging down s_TooltipWindow->SetPos(cursorX - menuWide, cursorY); } else { // menu hanging up s_TooltipWindow->SetPos(cursorX - menuWide, cursorY - menuTall - 20 ); } } }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void Label::ApplySettings( KeyValues *inResourceData ) { BaseClass::ApplySettings( inResourceData ); // label settings const char *labelText = inResourceData->GetString( "labelText", NULL ); if ( labelText ) { if (labelText[0] == '%' && labelText[strlen(labelText) - 1] == '%') { // it's a variable, set it to be a special variable localized string wchar_t unicodeVar[256]; g_pVGuiLocalize->ConvertANSIToUnicode(labelText, unicodeVar, sizeof(unicodeVar)); char var[256]; _snprintf(var, sizeof(var), "#var_%s", labelText); g_pVGuiLocalize->AddString(var + 1, unicodeVar, ""); SetText(var); } else { SetText(labelText); } } // text alignment const char *alignmentString = inResourceData->GetString( "textAlignment", "" ); int align = -1; if ( !stricmp(alignmentString, "north-west") ) { align = a_northwest; } else if ( !stricmp(alignmentString, "north") ) { align = a_north; } else if ( !stricmp(alignmentString, "north-east") ) { align = a_northeast; } else if ( !stricmp(alignmentString, "west") ) { align = a_west; } else if ( !stricmp(alignmentString, "center") ) { align = a_center; } else if ( !stricmp(alignmentString, "east") ) { align = a_east; } else if ( !stricmp(alignmentString, "south-west") ) { align = a_southwest; } else if ( !stricmp(alignmentString, "south") ) { align = a_south; } else if ( !stricmp(alignmentString, "south-east") ) { align = a_southeast; } if ( align != -1 ) { SetContentAlignment( (Alignment)align ); } // the control we are to be associated with may not have been created yet, // so keep a pointer to it's name and calculate it when we can const char *associateName = inResourceData->GetString("associate", ""); if (associateName[0] != 0) { int len = Q_strlen(associateName) + 1; _associateName = new char[ len ]; Q_strncpy( _associateName, associateName, len ); } if (inResourceData->GetInt("dulltext", 0) == 1) { SetTextColorState(CS_DULL); } else if (inResourceData->GetInt("brighttext", 0) == 1) { SetTextColorState(CS_BRIGHT); } else { SetTextColorState(CS_NORMAL); } // font settings const char *overrideFont = inResourceData->GetString("font", ""); IScheme *pScheme = scheme()->GetIScheme( GetScheme() ); if (*overrideFont) { delete [] _fontOverrideName; int len = Q_strlen(overrideFont) + 1; _fontOverrideName = new char[ len ]; Q_strncpy(_fontOverrideName, overrideFont, len ); SetFont(pScheme->GetFont(_fontOverrideName, IsProportional())); } else if (_fontOverrideName) { delete [] _fontOverrideName; _fontOverrideName = NULL; SetFont(pScheme->GetFont("Default", IsProportional())); } bool bWrapText = inResourceData->GetInt("centerwrap", 0) > 0; SetCenterWrap( bWrapText ); m_bAutoWideToContents = inResourceData->GetInt("auto_wide_tocontents", 0) > 0; bWrapText = inResourceData->GetInt("wrap", 0) > 0; SetWrap( bWrapText ); int inset_x = inResourceData->GetInt("textinsetx", _textInset[0]); int inset_y = inResourceData->GetInt("textinsety", _textInset[1]); // Had to play it safe and add a new key for backwards compatibility m_bUseProportionalInsets = inResourceData->GetInt("use_proportional_insets", 0) > 0; if ( m_bUseProportionalInsets ) { inset_x = scheme()->GetProportionalScaledValueEx( GetScheme(), inset_x ); } SetTextInset( inset_x, inset_y ); bool bAllCaps = inResourceData->GetInt("allcaps", 0) > 0; SetAllCaps( bAllCaps ); InvalidateLayout(true); }
//----------------------------------------------------------------------------- // Purpose: Applies designer settings from res file //----------------------------------------------------------------------------- void ImagePanel::ApplySettings(KeyValues *inResourceData) { delete [] m_pszImageName; delete [] m_pszFillColorName; delete [] m_pszDrawColorName; // HPE addition m_pszImageName = NULL; m_pszFillColorName = NULL; m_pszDrawColorName = NULL; // HPE addition //Center image isn't implemented in Source 2013. - Solokiller m_bCenterImage = inResourceData->GetInt( "centerImage", 0 ) != 0; m_bScaleImage = inResourceData->GetInt("scaleImage", 0) != 0; m_fScaleAmount = inResourceData->GetFloat( "scaleAmount", 0.0f ); m_bTileImage = inResourceData->GetInt( "tileImage", 0 ) != 0; m_bTileHorizontally = inResourceData->GetInt( "tileHorizontally", m_bTileImage ) != 0; m_bTileVertically = inResourceData->GetInt( "tileVertically", m_bTileImage ) != 0; const char *imageName = inResourceData->GetString("image", ""); if (*imageName) { SetImage( imageName ); } const char *pszFillColor = inResourceData->GetString("fillcolor", ""); if (*pszFillColor) { int r = 0, g = 0, b = 0, a = 255; int len = Q_strlen(pszFillColor) + 1; m_pszFillColorName = new char[ len ]; Q_strncpy( m_pszFillColorName, pszFillColor, len ); if (sscanf(pszFillColor, "%d %d %d %d", &r, &g, &b, &a) >= 3) { // it's a direct color m_FillColor = SDK_Color(r, g, b, a); } else { IScheme *pScheme = scheme()->GetIScheme( GetScheme() ); m_FillColor = pScheme->GetColor(pszFillColor, SDK_Color(0, 0, 0, 0)); } } //============================================================================= // HPE_BEGIN: // [pfreese] Added support for specifying drawcolor //============================================================================= const char *pszDrawColor = inResourceData->GetString( "drawcolor", "" ); if( *pszDrawColor ) { int r = 255, g = 255, b = 255, a = 255; int len = Q_strlen( pszDrawColor ) + 1; m_pszDrawColorName = new char[ len ]; Q_strncpy( m_pszDrawColorName, pszDrawColor, len ); if( sscanf( pszDrawColor, "%d %d %d %d", &r, &g, &b, &a ) >= 3 ) { // it's a direct color m_DrawColor = SDK_Color( r, g, b, a ); } else { IScheme *pScheme = scheme()->GetIScheme( GetScheme() ); m_DrawColor = pScheme->GetColor( pszDrawColor, SDK_Color( 255, 255, 255, 255 ) ); } } //============================================================================= // HPE_END //============================================================================= const char *pszBorder = inResourceData->GetString("border", ""); if (*pszBorder) { IScheme *pScheme = scheme()->GetIScheme( GetScheme() ); SetBorder(pScheme->GetBorder(pszBorder)); } BaseClass::ApplySettings(inResourceData); }
void CViewport::LoadDictionary(void) { CSV::CSVDocument doc; CSV::CSVDocument::row_index_type row_count; //Parse from the document try { row_count = doc.load_file("captionmod/dictionary.csv"); } catch(std::exception &err) { Sys_ErrorEx("%s\n%s", "LoadDictionary: ", err.what()); } if(row_count < 2) return; IScheme *ischeme = scheme()->GetIScheme(GetScheme()); if(!ischeme) return; Color defaultColor = ischeme->GetColor("BaseText", Color(255, 255, 255, 200)); //Initialize the dictionary hashtable m_StringsHashTable.SetSize(2048); for (int i = 0; i < m_StringsHashTable.Count(); i++) m_StringsHashTable[i].next = NULL; EmptyDictionaryHash(); int nRowCount = row_count; //parse the dictionary line by line... for (int i = 1;i < nRowCount; ++i) { CSV::CSVDocument::row_type row = doc.get_row(i); if(row.size() < 1) continue; const char *title = row[0].c_str(); if(!title || !title[0]) continue; CDictionary *Dict = new CDictionary; Dict->Load(row, defaultColor, ischeme); m_Dictionary.AddToTail(Dict); AddDictionaryHash(Dict, Dict->m_szTitle); } //Link the dictionaries for(int i = 0; i < m_Dictionary.Count(); ++i) { CDictionary *Dict = m_Dictionary[i]; if(Dict->m_szNext[0]) { Dict->m_pNext = FindDictionary(Dict->m_szNext); } } }
//----------------------------------------------------------------------------- // Purpose: parses a script into sequences //----------------------------------------------------------------------------- bool AnimationController::ParseScriptFile(char *pMem, int length) { // get the scheme (for looking up color names) IScheme *scheme = vgui::scheme()->GetIScheme(GetScheme()); // get our screen size (for left/right/center alignment) int screenWide = m_nScreenBounds[ 2 ]; int screenTall = m_nScreenBounds[ 3 ]; // start by getting the first token char token[512]; pMem = ParseFile(pMem, token, NULL); while (token[0]) { bool bAccepted = true; // should be 'event' if (stricmp(token, "event")) { Warning("Couldn't parse script file: expected 'event', found '%s'\n", token); return false; } // get the event name pMem = ParseFile(pMem, token, NULL); if (strlen(token) < 1) { Warning("Couldn't parse script file: expected <event name>, found nothing\n"); return false; } int seqIndex; UtlSymId_t nameIndex = g_ScriptSymbols.AddString(token); // Create a new sequence seqIndex = m_Sequences.AddToTail(); AnimSequence_t &seq = m_Sequences[seqIndex]; seq.name = nameIndex; seq.duration = 0.0f; // get the open brace or a conditional pMem = ParseFile(pMem, token, NULL); if ( Q_stristr( token, "[$" ) ) { bAccepted = EvaluateConditional( token ); // now get the open brace pMem = ParseFile(pMem, token, NULL); } if (stricmp(token, "{")) { Warning("Couldn't parse script sequence '%s': expected '{', found '%s'\n", g_ScriptSymbols.String(seq.name), token); return false; } // walk the commands while (token && token[0]) { // get the command type pMem = ParseFile(pMem, token, NULL); // skip out when we hit the end of the sequence if (token[0] == '}') break; // create a new command int cmdIndex = seq.cmdList.AddToTail(); AnimCommand_t &animCmd = seq.cmdList[cmdIndex]; memset(&animCmd, 0, sizeof(animCmd)); if (!stricmp(token, "animate")) { animCmd.commandType = CMD_ANIMATE; // parse out the animation commands AnimCmdAnimate_t &cmdAnimate = animCmd.cmdData.animate; // panel to manipulate pMem = ParseFile(pMem, token, NULL); cmdAnimate.panel = g_ScriptSymbols.AddString(token); // variable to change pMem = ParseFile(pMem, token, NULL); cmdAnimate.variable = g_ScriptSymbols.AddString(token); // target value pMem = ParseFile(pMem, token, NULL); if (cmdAnimate.variable == m_sPosition) { // Get first token SetupPosition( cmdAnimate, &cmdAnimate.target.a, token, screenWide ); // Get second token from "token" char token2[32]; char *psz = ParseFile(token, token2, NULL); psz = ParseFile(psz, token2, NULL); psz = token2; // Position Y goes into ".b" SetupPosition( cmdAnimate, &cmdAnimate.target.b, psz, screenTall ); } else if ( cmdAnimate.variable == m_sXPos ) { // XPos and YPos both use target ".a" SetupPosition( cmdAnimate, &cmdAnimate.target.a, token, screenWide ); } else if ( cmdAnimate.variable == m_sYPos ) { // XPos and YPos both use target ".a" SetupPosition( cmdAnimate, &cmdAnimate.target.a, token, screenTall ); } else { // parse the floating point values right out if (0 == sscanf(token, "%f %f %f %f", &cmdAnimate.target.a, &cmdAnimate.target.b, &cmdAnimate.target.c, &cmdAnimate.target.d)) { // could be referencing a value in the scheme file, lookup Color col = scheme->GetColor(token, Color(0, 0, 0, 0)); cmdAnimate.target.a = col[0]; cmdAnimate.target.b = col[1]; cmdAnimate.target.c = col[2]; cmdAnimate.target.d = col[3]; } } // fix up scale if (cmdAnimate.variable == m_sSize) { if (IsProportional()) { cmdAnimate.target.a = static_cast<float>( vgui::scheme()->GetProportionalScaledValueEx(GetScheme(), cmdAnimate.target.a) ); cmdAnimate.target.b = static_cast<float>( vgui::scheme()->GetProportionalScaledValueEx(GetScheme(), cmdAnimate.target.b) ); } } else if (cmdAnimate.variable == m_sWide || cmdAnimate.variable == m_sTall ) { if (IsProportional()) { // Wide and tall both use.a cmdAnimate.target.a = static_cast<float>( vgui::scheme()->GetProportionalScaledValueEx(GetScheme(), cmdAnimate.target.a) ); } } // interpolation function pMem = ParseFile(pMem, token, NULL); if (!stricmp(token, "Accel")) { cmdAnimate.interpolationFunction = INTERPOLATOR_ACCEL; } else if (!stricmp(token, "Deaccel")) { cmdAnimate.interpolationFunction = INTERPOLATOR_DEACCEL; } else if ( !stricmp(token, "Spline")) { cmdAnimate.interpolationFunction = INTERPOLATOR_SIMPLESPLINE; } else if (!stricmp(token,"Pulse")) { cmdAnimate.interpolationFunction = INTERPOLATOR_PULSE; // frequencey pMem = ParseFile(pMem, token, NULL); cmdAnimate.interpolationParameter = (float)atof(token); } else if ( !stricmp( token, "Flicker")) { cmdAnimate.interpolationFunction = INTERPOLATOR_FLICKER; // noiseamount pMem = ParseFile(pMem, token, NULL); cmdAnimate.interpolationParameter = (float)atof(token); } else { cmdAnimate.interpolationFunction = INTERPOLATOR_LINEAR; } // start time pMem = ParseFile(pMem, token, NULL); cmdAnimate.startTime = (float)atof(token); // duration pMem = ParseFile(pMem, token, NULL); cmdAnimate.duration = (float)atof(token); // check max duration if (cmdAnimate.startTime + cmdAnimate.duration > seq.duration) { seq.duration = cmdAnimate.startTime + cmdAnimate.duration; } } else if (!stricmp(token, "runevent")) { animCmd.commandType = CMD_RUNEVENT; pMem = ParseFile(pMem, token, NULL); animCmd.cmdData.runEvent.event = g_ScriptSymbols.AddString(token); pMem = ParseFile(pMem, token, NULL); animCmd.cmdData.runEvent.timeDelay = (float)atof(token); } else if (!stricmp(token, "stopevent")) { animCmd.commandType = CMD_STOPEVENT; pMem = ParseFile(pMem, token, NULL); animCmd.cmdData.runEvent.event = g_ScriptSymbols.AddString(token); pMem = ParseFile(pMem, token, NULL); animCmd.cmdData.runEvent.timeDelay = (float)atof(token); } else if (!stricmp(token, "StopPanelAnimations")) { animCmd.commandType = CMD_STOPPANELANIMATIONS; pMem = ParseFile(pMem, token, NULL); animCmd.cmdData.runEvent.event = g_ScriptSymbols.AddString(token); pMem = ParseFile(pMem, token, NULL); animCmd.cmdData.runEvent.timeDelay = (float)atof(token); } else if (!stricmp(token, "stopanimation")) { animCmd.commandType = CMD_STOPANIMATION; pMem = ParseFile(pMem, token, NULL); animCmd.cmdData.runEvent.event = g_ScriptSymbols.AddString(token); pMem = ParseFile(pMem, token, NULL); animCmd.cmdData.runEvent.variable = g_ScriptSymbols.AddString(token); pMem = ParseFile(pMem, token, NULL); animCmd.cmdData.runEvent.timeDelay = (float)atof(token); } else if ( !stricmp( token, "SetFont" )) { animCmd.commandType = CMD_SETFONT; // Panel name pMem = ParseFile(pMem, token, NULL); animCmd.cmdData.runEvent.event = g_ScriptSymbols.AddString(token); // Font parameter pMem = ParseFile(pMem, token, NULL); animCmd.cmdData.runEvent.variable = g_ScriptSymbols.AddString(token); // Font name from scheme pMem = ParseFile(pMem, token, NULL); animCmd.cmdData.runEvent.variable2 = g_ScriptSymbols.AddString(token); // Set time pMem = ParseFile(pMem, token, NULL); animCmd.cmdData.runEvent.timeDelay = (float)atof(token); } else if ( !stricmp( token, "SetTexture" )) { animCmd.commandType = CMD_SETTEXTURE; // Panel name pMem = ParseFile(pMem, token, NULL); animCmd.cmdData.runEvent.event = g_ScriptSymbols.AddString(token); // Texture Id pMem = ParseFile(pMem, token, NULL); animCmd.cmdData.runEvent.variable = g_ScriptSymbols.AddString(token); // material name pMem = ParseFile(pMem, token, NULL); animCmd.cmdData.runEvent.variable2 = g_ScriptSymbols.AddString(token); // Set time pMem = ParseFile(pMem, token, NULL); animCmd.cmdData.runEvent.timeDelay = (float)atof(token); } else if ( !stricmp( token, "SetString" )) { animCmd.commandType = CMD_SETSTRING; // Panel name pMem = ParseFile(pMem, token, NULL); animCmd.cmdData.runEvent.event = g_ScriptSymbols.AddString(token); // String variable name pMem = ParseFile(pMem, token, NULL); animCmd.cmdData.runEvent.variable = g_ScriptSymbols.AddString(token); // String value to set pMem = ParseFile(pMem, token, NULL); animCmd.cmdData.runEvent.variable2 = g_ScriptSymbols.AddString(token); // Set time pMem = ParseFile(pMem, token, NULL); animCmd.cmdData.runEvent.timeDelay = (float)atof(token); } else { Warning("Couldn't parse script sequence '%s': expected <anim command>, found '%s'\n", g_ScriptSymbols.String(seq.name), token); return false; } // Look ahead one token for a conditional char *peek = ParseFile(pMem, token, NULL); if ( Q_stristr( token, "[$" ) ) { if ( !EvaluateConditional( token ) ) { seq.cmdList.Remove( cmdIndex ); } pMem = peek; } } if ( bAccepted ) { // Attempt to find a collision in the sequences, replacing the old one if found int seqIterator; for ( seqIterator = 0; seqIterator < m_Sequences.Count()-1; seqIterator++ ) { if ( m_Sequences[seqIterator].name == nameIndex ) { // Get rid of it, we're overriding it m_Sequences.Remove( seqIndex ); break; } } } else { // Dump the entire sequence m_Sequences.Remove( seqIndex ); } // get the next token, if any pMem = ParseFile(pMem, token, NULL); } return true; }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void Label::ApplySettings( KeyValues *inResourceData ) { Panel::ApplySettings( inResourceData ); // label settings const char *labelText = inResourceData->GetString( "labelText", NULL ); if ( labelText ) { if (labelText[0] == '%' && labelText[strlen(labelText) - 1] == '%') { // it's a variable, set it to be a special variable localized string wchar_t unicodeVar[256]; g_pVGuiLocalize->ConvertANSIToUnicode(labelText, unicodeVar, sizeof(unicodeVar)); char var[256]; _snprintf(var, sizeof(var), "#var_%s", labelText); g_pVGuiLocalize->AddString(var + 1, unicodeVar, ""); SetText(var); } else { SetText(labelText); } } // text alignment const char *alignmentString = inResourceData->GetString( "textAlignment", "" ); int align = -1; if ( !stricmp(alignmentString, "north-west") ) { align = a_northwest; } else if ( !stricmp(alignmentString, "north") ) { align = a_north; } else if ( !stricmp(alignmentString, "north-east") ) { align = a_northeast; } else if ( !stricmp(alignmentString, "west") ) { align = a_west; } else if ( !stricmp(alignmentString, "center") ) { align = a_center; } else if ( !stricmp(alignmentString, "east") ) { align = a_east; } else if ( !stricmp(alignmentString, "south-west") ) { align = a_southwest; } else if ( !stricmp(alignmentString, "south") ) { align = a_south; } else if ( !stricmp(alignmentString, "south-east") ) { align = a_southeast; } if ( align != -1 ) { SetContentAlignment( (Alignment)align ); } // the control we are to be associated with may not have been created yet, // so keep a pointer to it's name and calculate it when we can const char *associateName = inResourceData->GetString("associate", ""); if (associateName[0] != 0) { int len = Q_strlen(associateName) + 1; _associateName = new char[ len ]; Q_strncpy( _associateName, associateName, len ); } if (inResourceData->GetInt("dulltext", 0) == 1) { SetTextColorState(CS_DULL); } else if (inResourceData->GetInt("brighttext", 0) == 1) { SetTextColorState(CS_BRIGHT); } else { SetTextColorState(CS_NORMAL); } // font settings const char *overrideFont = inResourceData->GetString("font", ""); IScheme *pScheme = scheme()->GetIScheme( GetScheme() ); if (*overrideFont) { delete [] _fontOverrideName; int len = Q_strlen(overrideFont) + 1; _fontOverrideName = new char[ len ]; Q_strncpy(_fontOverrideName, overrideFont, len ); SetFont(pScheme->GetFont(_fontOverrideName, IsProportional())); } else if (_fontOverrideName) { delete [] _fontOverrideName; _fontOverrideName = NULL; SetFont(pScheme->GetFont("Default", IsProportional())); } bool bWrapText = inResourceData->GetInt("wrap", 0) > 0; SetWrap( bWrapText ); InvalidateLayout(true); }