fork/m-overlay
git clone https://git.julia.blue/fork/m-overlay
a8034e9
main
1local PANEL =class . create ( "Frame" , "Panel" ) 2 3PANEL : ACCESSOR ( "Grabbed" , "m_bGrabbed" , false ) 4PANEL : ACCESSOR ( "Draggable" , "m_bDraggable" , true ) 5PANEL : ACCESSOR ( "HideOnClose" , "m_bHideOnClose" , false ) 6 7function PANEL : Frame () 8self : super () -- Initialize our baseclass 9 10self : DockPadding ( 4 , 36 , 4 , 4 ) 11 12self . m_pTitle =self : Add ( "Label" ) 13self . m_pTitle : SetText ( "Window" ) 14self . m_pTitle : SetTextAlignmentX ( "center" ) 15 16self . m_pClose =self : Add ( "Button" ) 17self . m_pClose : SetText ( "x" ) 18 19self . m_pClose . OnClick =function ( this , but ) 20self : OnClosed () 21if self . m_bHideOnClose then 22self : SetVisible ( false ) 23else 24self : Remove () 25end 26end 27end 28 29function PANEL : Skin () 30gui . skinHook ( "Init" , "ExitButton" , self . m_pClose ) 31end 32 33function PANEL : SetTitle ( s ) 34self . m_pTitle : SetText ( s ) 35end 36 37function PANEL : PerformLayout () 38self . m_pTitle : SetPos ( 2 , 2 ) 39self . m_pTitle : SetSize ( self : GetWidth () - 48 , 28 ) 40 41self . m_pClose : SetPos ( self : GetWidth () - 46 , 4 ) 42self . m_pClose : SetSize ( 42 , 24 ) 43end 44 45function PANEL : Paint ( w , h ) 46gui . skinHook ( "Paint" , "Frame" , self , w , h ) 47end 48 49function PANEL : OnMousePressed ( x , y , but ) 50self : BringToFront () 51if not self . m_bDraggable or not self : HasFocus () then return end 52if y > 32 then return end -- Only allow them to move using the top bar 53self : SetGrabbed ( true ) 54self . m_tGrabbedOffset ={ x =x , y =y } 55end 56 57function PANEL : OnMouseReleased ( x , y , but ) 58if not self . m_bDraggable then return end 59self : SetGrabbed ( false ) 60end 61 62function PANEL : Think ( dt ) 63if not self : IsGrabbed () then return end 64 65local mx , my =love . mouse . getPosition () 66local gx , gy =self . m_tGrabbedOffset . x , self . m_tGrabbedOffset . y 67 68self : SetPos ( mx - gx , my - gy ) 69end 70 71function PANEL : OnClosed () 72-- Override 73end