//----------------------------------------------------------------------------- // Purpose: Constructor //----------------------------------------------------------------------------- Tooltip::Tooltip(Panel *parent, const char *text) { if (!s_TooltipWindow.Get()) { s_TooltipWindow = new TextEntry(NULL, "tooltip"); } 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); _displayOnOneLine = false; _makeVisible = false; _isDirty = false; _tooltipDelay = 500; // default delay for opening tooltips _delay = 0; }
//----------------------------------------------------------------------------- // 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: Display the tooltip //----------------------------------------------------------------------------- void Tooltip::HideTooltip() { if ( s_TooltipWindow.Get() ) { s_TooltipWindow->SetVisible(false); } _makeVisible = false; }
//----------------------------------------------------------------------------- // Purpose: Display the tooltip //----------------------------------------------------------------------------- void TextTooltip::HideTooltip() { if ( s_TooltipWindow.Get() ) { s_TooltipWindow->SetVisible(false); } BaseTooltip::HideTooltip(); }
//----------------------------------------------------------------------------- // Sets a panel to be the main panel //----------------------------------------------------------------------------- void CVsVGuiWindow::SetMainPanel( vgui::EditablePanel * pPanel ) { Assert( m_hMainPanel.Get() == NULL ); Assert( m_hVGuiContext == vgui::DEFAULT_VGUI_CONTEXT ); m_hMainPanel = pPanel; m_hMainPanel->SetParent( vgui::surface()->GetEmbeddedPanel() ); m_hMainPanel->SetVisible( true ); m_hMainPanel->SetCursor( vgui::dc_arrow ); m_hVGuiContext = vgui::ivgui()->CreateContext(); vgui::ivgui()->AssociatePanelWithContext( m_hVGuiContext, m_hMainPanel->GetVPanel() ); pPanel->InvalidateLayout(); EnableWindow( m_hWnd, true ); SetFocus( m_hWnd ); }
//----------------------------------------------------------------------------- // Purpose: Display the tooltip //----------------------------------------------------------------------------- void TextTooltip::PerformLayout() { if ( !ShouldLayout() ) return; // we're ready, just make us visible if ( !s_TooltipWindow.Get() ) return; _isDirty = false; s_TooltipWindow->SetVisible(true); s_TooltipWindow->MakePopup( false, true ); s_TooltipWindow->SetKeyBoardInputEnabled( false ); s_TooltipWindow->SetMouseInputEnabled( false ); // relayout the textwindow immediately so that we know it's size //m_pTextEntry->InvalidateLayout(true); SizeTextWindow(); PositionWindow( s_TooltipWindow ); }
//----------------------------------------------------------------------------- // 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 ); } } }
CASW_VGUI_Info_Message::CASW_VGUI_Info_Message( vgui::Panel *pParent, const char *pElementName, C_ASW_Info_Message* pMessage ) : vgui::Panel( pParent, pElementName ), CASW_VGUI_Ingame_Panel() { //input->MouseEvent(0, false); // unclick all our mouse buttons when this panel pops up (so firing doesn't get stuck on) if (g_hCurrentInfoPanel.Get()) { g_hCurrentInfoPanel->MarkForDeletion(); g_hCurrentInfoPanel->SetVisible(false); } g_hCurrentInfoPanel = this; m_hMessage = pMessage; for (int i=0;i<4;i++) { m_pLine[i] = new vgui::WrappedLabel(this, "InfoMessageLabel", ""); m_pLine[i]->SetContentAlignment(vgui::Label::a_northwest); m_pLine[i]->SetMouseInputEnabled(false); } m_pOkayButton = new ImageButton(this, "OkayButton", "#asw_close"); m_pOkayButton->AddActionSignalTarget(this); KeyValues *msg = new KeyValues("Command"); msg->SetString("command", "OkayButton"); m_pOkayButton->SetCommand(msg); m_pMessageImage = new vgui::ImagePanel(this, "MessageImage"); m_pMessageImage->SetVisible(false); m_pMessageImage->SetShouldScaleImage(true); m_szImageName[0] = '\0'; if (ShouldAddLogButton()) { m_pLogButton = new ImageButton(this, "LogButton", "#asw_message_log"); m_pLogButton->AddActionSignalTarget(this); KeyValues *msg = new KeyValues("Command"); msg->SetString("command", "MessageLog"); m_pLogButton->SetCommand(msg); } else { Msg(" so not adding it\n"); m_pLogButton = NULL; } // find use key bind char lkeybuffer[12]; Q_snprintf(lkeybuffer, sizeof(lkeybuffer), "%s", ASW_FindKeyBoundTo("+use")); Q_strupr(lkeybuffer); // copy the found key into wchar_t format (localize it if it's a token rather than a normal keyname) wchar_t keybuffer[24]; if (lkeybuffer[0] == '#') { const wchar_t *pLocal = g_pVGuiLocalize->Find(lkeybuffer); if (pLocal) wcsncpy(keybuffer, pLocal, 24); else g_pVGuiLocalize->ConvertANSIToUnicode(lkeybuffer, keybuffer, sizeof(keybuffer)); } else g_pVGuiLocalize->ConvertANSIToUnicode(lkeybuffer, keybuffer, sizeof(keybuffer)); // look up close text localised const wchar_t *pLocal = g_pVGuiLocalize->Find("#asw_close"); if (pLocal) { // join use key and close text together wchar_t buffer[ 256 ]; g_pVGuiLocalize->ConstructString( buffer, sizeof(buffer), g_pVGuiLocalize->Find("#asw_use_icon_format"), 2, keybuffer, pLocal ); // set label m_pOkayButton->SetText(buffer); } if (GetControllerFocus()) { GetControllerFocus()->AddToFocusList(m_pOkayButton); GetControllerFocus()->SetFocusPanel(m_pOkayButton); if (m_pLogButton) { GetControllerFocus()->AddToFocusList(m_pLogButton); } } m_bClosingMessage = false; CLocalPlayerFilter filter; // check for a special sound in the info message const char *pszSound = pMessage ? pMessage->GetSound() : NULL; if (pszSound && Q_strlen(pszSound) > 0) { StopInfoMessageSound(); EmitSound_t ep; ep.m_pSoundName = pszSound; ep.m_flVolume = 1.0f; ep.m_nPitch = PITCH_NORM; ep.m_SoundLevel = SNDLVL_NONE; ep.m_nChannel = CHAN_STATIC; C_BaseEntity::EmitSound( filter, SOUND_FROM_LOCAL_PLAYER, ep ); g_LastInfoSoundGUID = enginesound->GetGuidForLastSoundEmitted(); } UpdateMessage(); SetAlpha(0); vgui::GetAnimationController()->RunAnimationCommand(this, "Alpha", 255, 0.0f, 0.3f, vgui::AnimationController::INTERPOLATOR_LINEAR); SetKeyBoardInputEnabled(true); SetMouseInputEnabled(true); RequestFocus(); ASWInput()->SetCameraFixed( true ); g_asw_iGUIWindowsOpen++; }