aboutsummaryrefslogtreecommitdiff
path: root/sp/src/game/client/game_controls/mouseoverhtmlbutton.h
diff options
context:
space:
mode:
authorJoe Ludwig <[email protected]>2013-06-26 15:22:04 -0700
committerJoe Ludwig <[email protected]>2013-06-26 15:22:04 -0700
commit39ed87570bdb2f86969d4be821c94b722dc71179 (patch)
treeabc53757f75f40c80278e87650ea92808274aa59 /sp/src/game/client/game_controls/mouseoverhtmlbutton.h
downloadsource-sdk-2013-39ed87570bdb2f86969d4be821c94b722dc71179.tar.xz
source-sdk-2013-39ed87570bdb2f86969d4be821c94b722dc71179.zip
First version of the SOurce SDK 2013
Diffstat (limited to 'sp/src/game/client/game_controls/mouseoverhtmlbutton.h')
-rw-r--r--sp/src/game/client/game_controls/mouseoverhtmlbutton.h119
1 files changed, 119 insertions, 0 deletions
diff --git a/sp/src/game/client/game_controls/mouseoverhtmlbutton.h b/sp/src/game/client/game_controls/mouseoverhtmlbutton.h
new file mode 100644
index 00000000..b4143029
--- /dev/null
+++ b/sp/src/game/client/game_controls/mouseoverhtmlbutton.h
@@ -0,0 +1,119 @@
+//========= Copyright Valve Corporation, All rights reserved. ============//
+//
+// Purpose:
+//
+// $NoKeywords: $
+//=============================================================================//
+
+#ifndef MOUSEOVERHTMLBUTTON_H
+#define MOUSEOVERHTMLBUTTON_H
+#ifdef _WIN32
+#pragma once
+#endif
+
+
+//-----------------------------------------------------------------------------
+// Purpose: Triggers a new html page when the mouse goes over the button
+//-----------------------------------------------------------------------------
+class MouseOverHTMLButton : public vgui::Button
+{
+public:
+ MouseOverHTMLButton(vgui::Panel *parent, const char *panelName, vgui::HTML *html, const char *page) :
+ Button( parent, panelName, "MouseOverHTMLButton")
+ {
+ m_pHTML = html;
+ m_iClass = 0;
+ m_iIndex = -1;
+ m_bAddShortCut = true;
+ if ( page )
+ {
+ Q_strncpy( m_sPage, page, sizeof( m_sPage ) );
+ }
+ else
+ {
+ memset(m_sPage, 0x0, sizeof( m_sPage ) );
+ }
+ }
+
+ void SetClass(int pClass, int index) { m_iClass = pClass; m_iIndex = index;}
+ int GetClass() { return m_iClass; }
+
+ void SetAddHotKey( bool state ) { m_bAddShortCut = state; }
+
+ void SetPage( const char *page )
+ {
+ if ( page )
+ {
+ Q_strncpy( m_sPage, page, sizeof( m_sPage ) );
+ }
+ else
+ {
+ memset(m_sPage, 0x0, sizeof( m_sPage ) );
+ }
+ }
+
+ void SetHTML( vgui::HTML *html)
+ {
+ m_pHTML = html;
+ }
+
+
+private:
+
+ virtual void OnCursorEntered()
+ {
+ Button::OnCursorEntered();
+ if ( m_pHTML && strlen(m_sPage) > 0 )
+ {
+ m_pHTML->OpenURL(m_sPage);
+ }
+ }
+
+ virtual void SetText(const char *text)
+ {
+ if ( m_iIndex != -1 )
+ {
+ wchar_t newText[ 128 ];
+ wchar_t localizeText[ 128 ];
+ wchar_t *ansiLocal;
+ if ( text[0] == '#' && ( ansiLocal = g_pVGuiLocalize->Find( text ) ) )
+ {
+ // wcsncpy will crash if ansiLocal is null... *sigh*
+ wcsncpy(localizeText, ansiLocal, sizeof(localizeText)/sizeof(wchar_t));
+ }
+ else
+ {
+ g_pVGuiLocalize->ConvertANSIToUnicode( text, localizeText, sizeof( localizeText ) );
+ }
+
+ if ( m_bAddShortCut )
+ {
+#ifdef WIN32
+ _snwprintf( newText, sizeof( newText )/ sizeof( wchar_t ), L"&%i %s", m_iIndex, localizeText);
+#else
+ _snwprintf( newText, sizeof( newText )/ sizeof( wchar_t ), L"&%i %S", m_iIndex, localizeText);
+#endif
+
+ }
+ else
+ {
+ memcpy( newText, localizeText, sizeof( newText ) );
+ }
+
+ Button::SetText( newText );
+ }
+ else
+ {
+ Button::SetText( text );
+ }
+ }
+
+ vgui::HTML *m_pHTML;
+ char m_sPage[ 255 ];
+ int m_iClass;
+ int m_iIndex;
+ bool m_bAddShortCut;
+};
+
+
+#endif // MOUSEOVERHTMLBUTTON_H