fork/m-overlay
git clone https://git.julia.blue/fork/m-overlay
7d53a4b
settings-overhaul
1local PANEL =class . create ( "BasePanel" ) 2 3require ( "extensions.table" ) 4 5function PANEL : BasePanel () 6self . m_tChildren ={} 7self . m_tOrphans ={} 8self . m_iWorldPosX =0 9self . m_iWorldPosY =0 10self . m_fScaleX =1 11self . m_fScaleY =1 12self . m_iPosX =0 13self . m_iPosY =0 14self . m_iWidth =42 15self . m_iHeight =24 16self . m_bHovered =false 17self . m_pParent =nil 18self . m_iZPos =0 19self . m_bScissorEnabled =true 20self . m_bValidated =false 21self . m_bVisible =true 22self . m_bFocusable =true 23self . m_bOrphaned =false 24self . m_bDeleted =false 25self . m_iDock =DOCK_NONE 26self . m_iCenter =CENTER_NONE 27self . m_tDockMargins ={ left =2 , top =2 , right =2 , bottom =2 } 28self . m_tDockPadding ={ left =2 , top =2 , right =2 , bottom =2 } 29end 30 31function PANEL : GetClassName () 32return self . __classname 33end 34 35function PANEL : __tostring () 36return ( "Panel[%q]" ): format ( self . __classname ) 37end 38 39function PANEL : GetConfig () 40local w , h =self : GetPixelSize () 41local sx , sy =self : GetScale () 42 43local config ={ 44classname =self : GetClassName (), 45pos ={ x =self : GetX (), y =self : GetY (), z =self : GetZPos () } , 46size ={ width =w , height =h } , 47scale ={ x =sx , y =sy } , 48visible =self : IsVisible (), 49accessors =self . __accessors , 50} 51 52if self . m_iDock ~= 0 then 53config . dock ={ 54mode =self . m_iDock , 55margins =self . m_tDockMargins , 56padding =self . m_tDockPadding , 57} 58end 59 60return config 61end 62 63function PANEL : SetVisible ( b ) 64self . m_bVisible =b 65end 66 67function PANEL : IsVisible () 68return self . m_bVisible 69end 70 71function PANEL : SetFocusable ( b ) 72self . m_bFocusable =b 73end 74 75function PANEL : IsFocusable () 76return self . m_bFocusable 77end 78 79function PANEL : BringToFront () 80local parent =self . m_pParent 81if not parent then return end -- There's nothing for it to go in front of! 82 83local highest =nil 84 85for _ , child in ipairs ( parent . m_tChildren ) do 86if not highest or child : GetZPos () > highest : GetZPos () then 87highest =child 88end 89end 90 91-- No panels or the highest is already ourself 92if not highest or highest == self then return end 93 94-- Get the position of the highest panel 95local replace =highest : GetZPos () 96 97-- Set the highest panel to our current position 98highest : SetZPos ( self : GetZPos ()) 99 100-- Set our position to where the highest panel used to be 101self : SetZPos ( replace ) 102end 103 104function PANEL : Dock ( i ) 105self . m_iDock =i 106self : InvalidateLayout () 107end 108 109function PANEL : GetDock () 110return self . m_iDock 111end 112 113function PANEL : DockMargin ( left , top , right , bottom ) 114self . m_tDockMargins . left =left 115self . m_tDockMargins . top =top 116self . m_tDockMargins . right =right 117self . m_tDockMargins . bottom =bottom 118end 119 120function PANEL : GetDockMargin () 121return self . m_tDockMargins 122end 123 124function PANEL : DockPadding ( left , top , right , bottom ) 125self . m_tDockPadding . left =left 126self . m_tDockPadding . top =top 127self . m_tDockPadding . right =right 128self . m_tDockPadding . bottom =bottom 129end 130 131function PANEL : GetDockPadding () 132return self . m_tDockPadding 133end 134 135function PANEL : GetWidthPlusMargin () 136if not self : IsVisible () then return 0 end 137local margins =self : GetDockMargin () 138return margins . left + margins . right + self : GetWidth () 139end 140 141function PANEL : GetHeightPlusMargin () 142if not self : IsVisible () then return 0 end 143local margins =self : GetDockMargin () 144return margins . top + margins . bottom + self : GetHeight () 145end 146 147function PANEL : GetSizePlusMargin () 148local w , h =self : GetWidthPlusMargin (), self : GetHeightPlusMargin () 149 150--[[for _,child in ipairs(self.m_tChildren) do 151if child:IsVisible() then 152margins = child:GetDockMargin() 153padding = child:GetDockPadding() 154w = w + margins.left + margins.right + padding.left + padding.right 155h = h + margins.top + margins.bottom + padding.top + padding.bottom 156end 157end]] 158 159return w , h 160end 161 162--[[function PANEL:GetSpaceAround(panel) 163local margins = panel:GetDockMargin() 164local padding = panel:GetDockPadding() 165 166local w = margins.left + margins.right + padding.left + padding.right 167local h = margins.top + margins.bottom + padding.top + padding.bottom 168 169for _,child in ipairs(self.m_tChildren) do 170if child ~= panel and child:IsVisible() then 171local margins = child:GetDockMargin() 172local padding = child:GetDockPadding() 173w = w + margins.left + margins.right + padding.left + padding.right + child:GetWidth() 174h = h + margins.top + margins.bottom + padding.top + padding.bottom + child:GetHeight() 175end 176end 177 178local width, height = self:GetSize() 179 180return w, h 181end]] 182 183function PANEL : SetZPos ( i ) 184self . m_iZPos =i 185self : GetParent (): ReorderChildren () 186end 187 188function PANEL : ReorderChildren () 189table . sort ( self . m_tChildren , function ( a , b ) return a . m_iZPos < b . m_iZPos end ) 190end 191 192function PANEL : GetZPos () 193return self . m_iZPos 194end 195 196function PANEL : CallAll ( func , ... ) 197if not self : IsVisible () then return end 198self [ func ]( self , ... ) 199for _ , child in ipairs ( self . m_tChildren ) do 200child : CallAll ( func , ... ) 201end 202end 203 204function PANEL : CallSelfAndParents ( func , ... ) 205if not self : IsVisible () then return end 206if self [ func ]( self , ... ) then return end 207local parent =self . m_pParent 208if not parent then return end 209parent : CallSelfAndParents ( func , ... ) 210end 211 212function PANEL : Remove () 213local parent =self : GetParent () 214if parent then 215parent : OnChildRemoved ( self ) 216end 217 218self . m_bDeleted =true 219self : OnRemoved () 220 221for zpos , child in ipairs ( self . m_tChildren ) do 222child : Remove () 223end 224end 225 226function PANEL : Clear () 227for zpos , child in ipairs ( self . m_tChildren ) do 228child : Remove () 229end 230end 231 232function PANEL : InvalidateLayout () 233self . m_bValidated =false 234for _ , child in ipairs ( self . m_tChildren ) do 235child : InvalidateLayout () 236end 237end 238 239function PANEL : InvalidateParent () 240if not self . m_pParent then return end 241self . m_pParent : InvalidateLayout () 242end 243 244function PANEL : MarkAsOrphan () 245self . m_bOrphaned =true 246end 247 248function PANEL : CleanupOrphans () 249for key , child in reversedipairs ( self . m_tChildren ) do 250child : CleanupOrphans () 251if child . m_bOrphaned then 252table . remove ( self . m_tChildren , key ) 253end 254end 255end 256 257function PANEL : CleanupDeleted () 258for key , child in reversedipairs ( self . m_tChildren ) do 259child : CleanupDeleted () 260if child . m_bDeleted then 261self . m_tChildren [ key ] =nil 262table . remove ( self . m_tChildren , key ) 263end 264end 265end 266 267function PANEL : SetParent ( parent ) 268if self . m_pParent then 269self : MarkAsOrphan () 270end 271self . m_pParent =parent 272if parent then 273table . insert ( parent . m_tChildren , self ) 274parent : OnChildAdded ( self ) 275self : SetZPos ( # parent . m_tChildren ) 276end 277end 278 279function PANEL : HasParent () 280return self : GetParent () ~= nil 281end 282 283function PANEL : GetParent () 284return self . m_pParent 285end 286 287function PANEL : GetParents () 288local parents ={} 289 290local parent =self : GetParent () 291 292while parent do 293table . insert ( parents , parent ) 294parent =parent : GetParent () 295end 296return parents 297end 298 299function PANEL : GetChildren () 300return self . m_tChildren 301end 302 303function PANEL : GetFamily ( family ) 304local family =family or {} 305 306local children =self . m_tChildren 307family [ self ] =children 308 309for _ , child in ipairs ( children ) do 310child : GetFamily ( family [ self ]) 311end 312 313return family 314end 315 316function PANEL : SizeToScreen () 317self : SetSize ( graphics . getPixelDimensions ()) 318end 319 320function PANEL : SizeToParent () 321local parent =self : GetParent () 322 323if parent then 324self : SetSize ( parent : GetSize ()) 325end 326end 327 328function PANEL : SizeToChildren ( doWidth , doHeight ) 329local all =doWidth == nil and doHeight == nil 330local w , h =0 , 0 331local padding =self : GetDockPadding () 332 333w =padding . left + padding . right 334h =padding . top + padding . bottom 335 336local lw , lh =0 , 0 337 338for _ , child in ipairs ( self . m_tChildren ) do 339if child : IsVisible () then 340local x , y =child : GetPos () 341local margin =child : GetDockMargin () 342local cw , ch =child : GetPixelSize () 343 344-- Position + size + margins = maximum bounds 345cw =x + cw + margin . left + margin . right 346ch =y + ch + margin . top + margin . bottom 347 348-- Update the largest widths and heights 349if cw > lw then lw =cw end 350if ch > lh then lh =ch end 351end 352end 353-- Don't use SetWidth/SetHeight so we don't invalidate the layout.. 354if all or doWidth then self . m_iWidth =w + lw end 355if all or doHeight then self . m_iHeight =h + lh end 356end 357 358function PANEL : Add ( class ) 359return gui . create ( class , self ) 360end 361 362function PANEL : SetScale ( x , y ) 363y =y or x 364self . m_fScaleX , self . m_fScaleY =x , y 365end 366 367function PANEL : GetScale () 368return self . m_fScaleX , self . m_fScaleY 369end 370 371function PANEL : SetPos ( x , y ) 372self . m_iPosX , self . m_iPosY =math . floor ( x + 0.5 ), math . floor ( y + 0.5 ) 373end 374 375function PANEL : GetPos () 376return self . m_iPosX , self . m_iPosY 377end 378 379function PANEL : SetWorldPos ( x , y ) 380self . m_iWorldPosX , self . m_iWorldPosY =x , y 381end 382 383function PANEL : GetWorldPos () 384return self . m_iWorldPosX , self . m_iWorldPosY 385end 386 387function PANEL : LocalToWorld ( x , y ) 388local sx , sy =self : GetPos () 389x =x + sx 390y =y + sy 391 392local parent =self : GetParent () 393 394while parent do 395local px , py =parent : GetPos () 396x =x + px 397y =y + py 398parent =parent : GetParent () 399end 400 401return x , y 402end 403 404function PANEL : WorldToLocal ( x , y ) 405local sx , sy =self : LocalToWorld ( 0 , 0 ) 406return x - sx , y - sy 407end 408 409function PANEL : SetX ( x ) 410self . m_iPosX =math . floor ( x + 0.5 ) 411end 412 413function PANEL : GetX () 414return self . m_iPosX 415end 416 417function PANEL : SetY ( y ) 418self . m_iPosY =math . floor ( y + 0.5 ) 419end 420 421function PANEL : GetY () 422return self . m_iPosY 423end 424 425function PANEL : SetSize ( w , h ) 426self : SetWidth ( w ) 427self : SetHeight ( h ) 428self : OnResize ( w , h ) 429end 430 431function PANEL : GetSize () 432return self : GetWidth (), self : GetHeight () 433end 434 435function PANEL : GetPixelSize () 436return math . max ( 0 , self . m_iWidth ), math . max ( 0 , self . m_iHeight ) 437end 438 439function PANEL : SetWidth ( w ) 440w =math . max ( 0 , math . floor ( w + 0.5 )) 441if self . m_iWidth ~= w then 442self . m_iWidth =w 443self : InvalidateLayout () 444end 445end 446 447function PANEL : GetActualWidth () 448return math . max ( 0 , self . m_iWidth ) 449end 450 451function PANEL : GetWidth () 452return self : GetActualWidth () * self . m_fScaleX 453end 454 455function PANEL : SetHeight ( h ) 456h =math . max ( 0 , math . floor ( h + 0.5 )) 457if self . m_iHeight ~= h then 458self . m_iHeight =h 459self : InvalidateLayout () 460end 461end 462 463function PANEL : GetActualHeight () 464return math . max ( 0 , self . m_iHeight ) 465end 466 467function PANEL : GetHeight () 468return self : GetActualHeight () * self . m_fScaleY 469end 470 471function PANEL : IsWorldPointInside ( x , y ) 472local px , py =self : LocalToWorld ( 0 , 0 ) 473return x > px and x < px + self : GetWidth () and y > py and y < py + self : GetHeight () 474end 475 476function PANEL : Render () 477if not self : IsVisible () then return end 478 479local x , y =self : LocalToWorld ( 0 , 0 ) 480local w , h =self : GetSize () 481 482local parent =self : GetParent () 483 484-- Start the scissor position and size with our own values 485local sx , sy =x , y 486local sw , sh =w , h 487 488while self . m_bScissorEnabled and parent do 489-- If we have a parent, fit the scissor to fit inside their bounds 490local px , py =parent : LocalToWorld ( 0 , 0 ) 491local pw , ph =parent : GetSize () 492 493if sx < px then 494sw =math . max ( 0 , sw + sx - px ) 495sx =px 496end 497if sx + sw > px + pw then 498sw =math . max ( 0 , sw - (( sx + sw ) - ( px + pw ))) 499sx =math . min ( sx , px + pw ) 500end 501if sy < py then 502sh =math . max ( 0 , sh + sy - py ) 503sy =py 504end 505if sy + sh > py + ph then 506sh =math . max ( 0 , sh - (( sy + sh ) - ( py + ph ))) 507sy =math . min ( sy , py + ph ) 508end 509 510parent =parent : GetParent () 511end 512 513self : SetWorldPos ( sx , sy ) 514 515-- Only bother to render if the panel is visible within the scissor 516if math . max ( x , sx ) < math . min ( x + w , sx + sw ) and math . max ( y , sy ) < math . min ( y + h , sy + sh ) then 517local rsx , rsy =self : GetScale () 518 519if self . m_bScissorEnabled then 520graphics . setScissor ( sx , sy , sw , sh ) 521end 522 523graphics . push ( "all" ) -- Push the current graphics state 524graphics . translate ( x , y ) -- Translate so Paint has localized position values for drawing objects 525graphics . scale ( rsx , rsy ) 526 527local uw , uh =self : GetPixelSize () 528graphics . setColor ( 255 , 255 , 255 , 255 ) 529self : PrePaint ( uw , uh ) 530graphics . setColor ( 255 , 255 , 255 , 255 ) 531self : Paint ( uw , uh ) 532graphics . setColor ( 255 , 255 , 255 , 255 ) 533self : PostPaint ( uw , uh ) 534 535graphics . origin () 536 537-- recently added panels are drawn last, thus, ontop of older panels 538for _ , child in ipairs ( self . m_tChildren ) do 539child : Render () 540end 541 542graphics . translate ( x , y ) -- Translate so Paint has localized position values for drawing objects 543graphics . scale ( rsx , rsy ) 544graphics . setColor ( 255 , 255 , 255 , 255 ) 545self : PaintOverlay ( self : GetPixelSize ()) 546 547graphics . origin () 548graphics . pop () -- Reset the graphics state to what it was 549 550if self . m_bDebug then 551-- Debug the scissor rect 552graphics . setColor ( 255 , 0 , 0 , 25 ) 553graphics . rectangle ( "fill" , sx , sy , sw , sh ) 554end 555 556graphics . setScissor () 557end 558end 559 560function PANEL : DisableScissor () 561self . m_bScissorEnabled =false 562end 563 564function PANEL : ValidateLayout () 565if self : IsVisible () and not self . m_bValidated then 566self . m_bValidated =true 567self : CenterLayout () 568self : DockLayout () 569self : PerformLayout () 570end 571 572for _ , child in ipairs ( self . m_tChildren ) do 573child : ValidateLayout () 574end 575end 576 577function PANEL : CenterLayout () 578local parent =self : GetParent () 579 580local w , h =self : GetSize () 581local pw , ph =graphics . getPixelDimensions () -- Default to window size if no parent 582if parent then 583pw , ph =parent : GetSize () 584end 585 586local vertical =bit . band ( self . m_iCenter , CENTER_VERTICAL ) == CENTER_VERTICAL 587local horizontal =bit . band ( self . m_iCenter , CENTER_HORIZONTAL ) == CENTER_HORIZONTAL 588 589if vertical == true then 590self : SetY (( ph / 2 ) - ( h / 2 )) 591end 592if horizontal == true then 593self : SetX (( pw / 2 ) - ( w / 2 )) 594end 595end 596 597function PANEL : Center ( vertical , horizontal ) 598self : CenterVertical ( vertical ) 599self : CenterHorizontal ( horizontal ) 600end 601 602function PANEL : CenterVertical ( center ) 603self . m_iCenter =bit . bor ( self . m_iCenter , CENTER_VERTICAL ) 604self : InvalidateLayout () 605end 606 607function PANEL : CenterHorizontal ( center ) 608self . m_iCenter =bit . bor ( self . m_iCenter , CENTER_HORIZONTAL ) 609self : InvalidateLayout () 610end 611 612function PANEL : DockLayout () 613local x , y =0 , 0 614local w , h =self : GetPixelSize () 615 616local padding =self . m_tDockPadding 617 618for _ , child in ipairs ( self . m_tChildren ) do 619local margin =child . m_tDockMargins 620 621local dx =x + padding . left 622local dy =y + padding . top 623local dw =w - ( padding . left + padding . right ) 624local dh =h - ( padding . top + padding . bottom ) 625 626local dock =child . m_iDock 627if dock ~= DOCK_NONE then 628local cw , ch =child : GetPixelSize () 629if ( dock == DOCK_TOP ) then 630child : SetPos ( dx + margin . left , dy + margin . top ) 631child : SetSize ( dw - margin . left - margin . right , ch ) 632if child : IsVisible () then 633local height =margin . top + margin . bottom + ch 634y =y + height 635h =h - height 636end 637elseif ( dock == DOCK_LEFT ) then 638child : SetPos ( dx + margin . left , dy + margin . top ) 639child : SetSize ( cw , dh - margin . top - margin . bottom ) 640if child : IsVisible () then 641local width =margin . left + margin . right + cw 642x =x + width 643w =w - width 644end 645elseif ( dock == DOCK_RIGHT ) then 646child : SetPos (( dx + dw ) - cw - margin . right , dy + margin . top ) 647child : SetSize ( cw , dh - margin . top - margin . bottom ) 648if child : IsVisible () then 649local width =margin . left + margin . right + cw 650w =w - width 651end 652elseif ( dock == DOCK_BOTTOM ) then 653child : SetPos ( dx + margin . left , ( dy + dh ) - ch - margin . bottom ) 654child : SetSize ( dw - margin . left - margin . right , ch ) 655if child : IsVisible () then 656h =h - ( ch + margin . bottom + margin . top ) 657end 658end 659end 660end 661 662for _ , child in ipairs ( self . m_tChildren ) do 663local dock =child . m_iDock 664 665if dock ~= DOCK_NONE then 666local margin =child . m_tDockMargins 667 668local dx =x + padding . left 669local dy =y + padding . top 670local dw =w - ( padding . left + padding . right ) 671local dh =h - ( padding . top + padding . bottom ) 672 673if ( dock == DOCK_FILL ) then 674child : SetPos ( dx + margin . left , dy + margin . top ) 675child : SetSize ( dw - margin . left - margin . right , dh - margin . top - margin . bottom ) 676end 677end 678end 679end 680 681function PANEL : GiveFocus () 682gui . setFocusedPanel ( self ) 683end 684 685function PANEL : MakePopup () 686self : BringToFront () 687self : GiveFocus () 688end 689 690function PANEL : HasFocus ( checkchildren ) 691if checkchildren then 692for _ , child in ipairs ( self . m_tChildren ) do 693if child : HasFocus ( checkchildren ) then 694return true 695end 696end 697end 698return gui . getFocusedPanel () == self 699end 700 701function PANEL : IsHovered () 702return gui . getHoveredPanel () == self 703end 704 705function PANEL : GetHoveredChild ( x , y , ignore ) 706local panel =nil 707for _ , child in reversedipairs ( self . m_tChildren ) do 708if child : IsVisible () and child : IsFocusable () and child : IsWorldPointInside ( x , y ) and (( ignore and child ~= ignore ) or not ignore ) then 709panel =child : GetHoveredPanel ( x , y ) 710break 711end 712end 713return panel 714end 715 716function PANEL : GetHoveredPanel ( x , y , ignore ) 717local panel =self 718for _ , child in reversedipairs ( self . m_tChildren ) do 719if child : IsVisible () and child : IsFocusable () and child : IsWorldPointInside ( x , y ) and (( ignore and child ~= ignore ) or not ignore ) then 720panel =child : GetHoveredPanel ( x , y ) 721break 722end 723end 724return panel 725end 726 727-- Tries to get find a position that can fit "other" somehwere around ourself without clipping outside our world 728function PANEL : SetPosAround ( other , world ) 729world =world or gui . getWorldPanel () 730 731local pw , ph =self : GetPixelSize () 732 733local ox , oy =other : GetWorldPos () 734local ow , oh =other : GetPixelSize () 735 736local sx , sy =world : GetWorldPos () 737local sw , sh =world : GetPixelSize () 738 739local canFitAbove =( oy - sy ) >= ph 740local canFitBelow =(( sy + sh ) - ( oy + oh )) >= ph 741local canFitLeft =( ox - sx ) >= pw 742local canFitRight =(( sx + sw ) - ( ox + ow )) >= pw 743 744local finalX , finalY =0 , 0 745local midX , midY =0 , 0 746 747if canFitAbove or canFitBelow then -- Prefer above or below 748midX =ox + ow / 2 749 750-- set our x position centered against our other 751finalX =midX - pw / 2 752 753-- fit our x position within our world 754finalX =math . min ( sx + sw - pw , math . max ( sx , finalX )) 755if canFitAbove then 756-- set y above 757finalY =oy - ph 758midY =oy 759else 760-- set y below 761finalY =oy + oh 762midY =finalY 763end 764elseif canFitLeft or canFitRight then -- Try left or right if above and below fails 765midY =oy + oh / 2 766 767-- set our y position centered against our other 768finalY =midY - ph / 2 769 770-- fit our y position within our world 771finalY =math . min ( sy + sh - ph , math . max ( sy , finalY )) 772if canFitLeft then 773-- set y left 774finalX =ox - pw 775midX =ox 776else 777-- set y right 778finalX =ox + ow 779midX =finalX 780end 781end 782 783-- return our position as a local position within the given world 784finalX , finalY =world : WorldToLocal ( finalX , finalY ) 785self : SetPos ( finalX , finalY ) 786return self : WorldToLocal ( midX , midY ) 787end 788 789-- PANEL OVERRIDE DEFAULTS 790 791function PANEL : PerformLayout () 792-- Called when we are Validating the layout. 793-- Good for manually positioning child panels. 794end 795 796function PANEL : PrePaint ( w , h ) 797end 798 799function PANEL : Paint ( w , h ) 800-- Called every frame, when we are drawing the panel to the screen. 801-- Used to draw custom things within the panel. 802end 803 804function PANEL : PostPaint ( w , h ) 805end 806 807function PANEL : PaintOverlay ( w , h ) 808end 809 810function PANEL : OnResize ( w , h ) 811-- Called when the size of the panel has changed. 812-- Good for manually positioning child panels, like in PerformLayout. 813end 814 815function PANEL : OnFocusChanged ( b ) 816-- Called when the panels focus has either been gained or lost 817end 818 819function PANEL : OnHoveredChanged ( b ) 820-- Called when the panels hovered state has either been gained or lost 821end 822 823function PANEL : OnKeyPressed ( key , hex ) 824-- Called when the panel is focused, and a keyboard key has been pressed 825end 826 827function PANEL : OnKeyReleased ( key ) 828-- Called when the panel is focused, and a keyboard key has been released 829end 830 831function PANEL : OnHoveredKeyPressed ( key , hex ) 832-- Called when the panel is hovered over, and a keyboard key has been pressed 833end 834 835function PANEL : OnHoveredKeyReleased ( key ) 836-- Called when the panel is hovered over, and a keyboard key has been released 837end 838 839function PANEL : OnTextInput ( text ) 840-- Called when the panel is focused. 841-- Good for a text input panel. 842end 843 844function PANEL : OnHoveredTextInput ( text ) 845-- Called when the panel is hovered. 846-- Good for a text input panel. 847end 848 849function PANEL : OnJoyPressed ( joy , but ) 850-- Override 851end 852 853function PANEL : OnJoyReleased ( joy , but ) 854-- Override 855end 856 857function PANEL : OnMouseMoved ( x , y , dx , dy , istouch ) 858--[[ 859Called when when the mouse has been moved. 860 861number x 862The mouse position on the x-axis. 863number y 864The mouse position on the y-axis. 865number dx 866The amount moved along the x-axis since the last time love.mousemoved was called. 867number dy 868The amount moved along the y-axis since the last time love.mousemoved was called. 869 870Returning true will stop the event from going up the family tree 871Child->Parent->Parent->Parent->etc, etc.. 872]] 873 874return false 875end 876 877function PANEL : OnMousePressed ( x , y , button , istouch , presses ) 878--[[ 879Called when a mouse press event has been made. 880 881number x 882The mouse position on the x-axis. 883number y 884The mouse position on the y-axis. 885number dx 886The amount moved along the x-axis since the last time love.mousemoved was called. 887number dy 888The amount moved along the y-axis since the last time love.mousemoved was called. 889 890Returning true will stop the event from going up the family tree 891Child->Parent->Parent->Parent->etc, etc.. 892]] 893 894return false 895end 896 897function PANEL : OnMouseReleased ( x , y , button , istouch , presses ) 898--[[ 899Called when a mouse release event has been made. 900 901number x 902The mouse position on the x-axis. 903number y 904The mouse position on the y-axis. 905number dx 906The amount moved along the x-axis since the last time love.mousemoved was called. 907number dy 908The amount moved along the y-axis since the last time love.mousemoved was called. 909 910Returning true will stop the event from going up the family tree 911Child->Parent->Parent->Parent->etc, etc.. 912]] 913 914return false 915end 916 917function PANEL : OnMouseWheeled ( x , y ) 918--[[ 919Called when the scrollwheel has been turned. 920 921number x 922Amount of horizontal mouse wheel movement. Positive values indicate movement to the right. 923number y 924Amount of vertical mouse wheel movement. Positive values indicate upward movement. 925 926See an example in.. 927gui/panels/scrollpanel.lua 928& 929gui/panels/scrollbar.lua 930 931Returning true will stop the event from going up the family tree 932Child->Parent->Parent->Parent->etc, etc.. 933]] 934 935return false 936end 937 938function PANEL : OnChildAdded ( panel ) 939-- Called when a panel has been added 940end 941 942function PANEL : OnRemoved () 943 944end 945 946function PANEL : OnChildRemoved ( panel ) 947-- Called when a panel has been removed 948end 949 950function PANEL : Think ( dt ) 951-- Called every frame 952end 953 954function PANEL : OnQuertyTooltip () 955-- Called when the user has hovered over the panel for more than a second 956end