fork/m-overlay
git clone https://git.julia.blue/fork/m-overlay
a8034e9
v2.1.1b
1local PANEL =class . create ( "ToolTip" , "BasePanel" ) 2 3PANEL : ACCESSOR ( "Enabled" , "m_bEnabled" , true ) 4PANEL : ACCESSOR ( "ArrowX" , "m_iArrowX" , 0 ) 5PANEL : ACCESSOR ( "ArrowY" , "m_iArrowY" , 0 ) 6PANEL : ACCESSOR ( "TooltipColor" , "m_cTooltipColor" , color ( 240 , 240 , 240 )) 7 8function PANEL : ToolTip () 9self : super () -- Initialize our baseclass 10self : SetFocusable ( false ) -- Ignore focus 11 12self : SetSize ( 256 , 256 ) 13self : DockPadding ( 8 , 8 , 8 , 0 ) 14 15self . m_pTitle =self : Add ( "Label" ) 16self . m_pTitle : Dock ( DOCK_TOP ) 17self . m_pTitle : SetLineHeight ( 0.75 ) 18 19self . m_pTitle . Skin =function ( this ) 20gui . skinHook ( "Init" , "TooltipTitle" , this ) 21end 22 23self . m_pBody =self : Add ( "Label" ) 24self . m_pBody : Dock ( DOCK_FILL ) 25self . m_pBody : SetWrapped ( true ) 26self . m_pBody : SetFont ( "fonts/melee.otf" , 11 ) 27self . m_pBody : SetLineHeight ( 0.75 ) 28self . m_pBody : SetPos ( 8 , 16 + 24 ) 29self . m_pBody : SetSize ( 236 , 228 ) 30 31self . m_pBody . Skin =function ( this ) 32gui . skinHook ( "Init" , "TooltipBody" , this ) 33end 34end 35 36function PANEL : Skin () 37gui . skinHook ( "Init" , "Tooltip" , self ) 38end 39 40function PANEL : SetArrowPos ( x , y ) 41self . m_iArrowX =x 42self . m_iArrowY =y 43end 44 45function PANEL : GetArrowPos () 46return math . max ( 5 , math . min ( self : GetWidth () - 5 , self . m_iArrowX )), math . max ( 5 , math . min ( self : GetHeight () - 5 , self . m_iArrowY )) 47end 48 49function PANEL : SetTitle ( str ) 50self . m_pTitle : SetText ( str ) 51end 52 53function PANEL : SetBody ( str ) 54self . m_pBody : SetText ( str ) 55self . m_pBody : HeightToText () 56self : SizeToChildren ( false , true ) 57end 58 59function PANEL : Paint ( w , h ) 60graphics . setColor ( color ( 0 , 0 , 0 , 75 )) 61graphics . roundRect ( 8 , 8 , w - 8 , h - 8 , 4 ) 62 63graphics . setColor ( color_black ) 64graphics . roundRect ( 4 , 4 , w - 8 , h - 8 , 4 ) 65 66local s1 =5.65685424949 -- sqrt(4^2+4^2) 67local s2 =7.07106781187 -- sqrt(5^2+5^2) 68 69graphics . setColor ( self . m_cTooltipColor ) 70 71graphics . push () 72graphics . translate ( self : GetArrowPos ()) -- move relative (0,0) to (x,y) 73graphics . rotate ( math . rad ( 45 )) -- rotate coordinate system around relative (0,0) (absolute (x,y)) 74 75graphics . setColor ( color_black ) 76graphics . rectangle ( "fill" , - s2 / 2 , - s2 / 2 , s2 , s2 ) -- draw rectangle centered around relative (0,0) 77 78graphics . setColor ( self . m_cTooltipColor ) 79graphics . rectangle ( "fill" , - s1 / 2 , - s1 / 2 , s1 , s1 ) -- draw rectangle centered around relative (0,0) 80graphics . pop () 81 82graphics . setColor ( self . m_cTooltipColor ) 83graphics . roundRect ( 5 , 5 , w - 10 , h - 10 , 4 ) 84end