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