
if ( SERVER ) then return end

/*---------------------------------------------------------
   Name: vgui extensions
---------------------------------------------------------*/

/*

  -------
   Panel
  -------
  
   PANEL:Init()
	Overrides paint function for panel.
	Return true to cause it to not draw the default panel
  
  PANEL:Paint()
	Overrides paint function for panel.
	Return true to cause it to not draw the default panel
	
  PANEL:PaintOver()
	Like Paint except drawn after everything else has drawn.
	
  PANEL:OnMousePressed( mousecode )
  PANEL:OnMouseReleased( mousecode )
    Called when the mouse is pressed/released on the panel.
	Return true to not allow any default actions
	
  PANEL:OnMouseWheeled( delta )
    Called when the mouse is wheeled over the panel
	
  PANEL:OnKeyCodePressed( keycode )
    Called when a key is pressed
	Return true to swallow the key
	
  PANEL:OnKeyCodeTyped( keycode )
    Called when a key is typed
	Return true to swallow the key
	
  PANEL:Think()
    Called every frame the panel is visible
	
  PANEL:ApplySchemeSettings( ///todo/// )
    You should use this to apply colours/fonts to your panel and its children

  PANEL:PerformLayout( )
    Use this to position your panel and its children
	
  PANEL:ActionSignal( key, value, ... )
    Receive an ActionSignal (various things are broadcast here)
	
  PANEL:OnCursorEntered()
    Cursor has entered the panel
	
  PANEL:OnCursorExited()
    Cursor has exited the panel
	
  PANEL:OnCursorMoved( x, y )
    Cursor has moved inside panel (or the panel has exclusive focus)
	Return a bool to override default CursorMoved route
	
  PANEL:OnFocusChanged( bLost )
    The panel has lost or gained focus
	
  --------
   Button
  --------
	
  PANEL::DoClick( local_x, local_y )
    Called when a the button is clicked
	
  ------
   HTML
  ------
  
  PANEL::StatusChanged( text )
    The text in the status bar has changed
	
  PANEL::ProgressChanged( progress )
    Loading progress changed
	
  PANEL::FinishedURL( url )
    Finished loading a specific URL
	
  PANEL::OpeningURL( url, target )
    Page wants to open URL.
	Return true to not load URL.
    
 ---------------
 - Member Vars -
 ---------------
	
  All
	Hovered			- 	bool (true if panel is hovered)
	
  Button
	Selected		-	bool (true if button is selected)
	Depressed		-	bool (true if button is depressed)
	Armed			-	bool (true if button is hovered)
	DefaultButton	-	bool (true if button is default button)
	
  HTML
    Progress		-	float (Progress bar amount between 0-1)
	Status			-	string (Status Bar Text)
	URL				-	string (Current URL)
	
*/



local PanelFactory = {}

// Keep the old function
vgui.CreateX = vgui.Create

function vgui.Create( classname, parent, name, ... )

	// Is this a user-created panel?
	if ( PanelFactory[ classname ] ) then
	
		local metatable = PanelFactory[ classname ]
		
		local panel = vgui.Create( metatable.Base, parent, name )
		
		table.Merge( panel:GetTable(), metatable )
		panel.BaseClass = PanelFactory[ metatable.Base ]
		panel.ClassName = classname
		
		// Call the Init function if we have it
		if ( panel.Init ) then
			local b, e = pcall( panel.Init, panel )
			if (!b) then Msg( "vgui.Create: Error when calling '", classname ,"':Init (", e, ")\n" ) end
		end
		
		return panel
	
	end
	
	return vgui.CreateX( classname, parent, name )

end


function vgui.Register( name, mtable, base )

	// Default base is Panel
	base = base or "Panel"
	
	mtable.Base = base
	
	PanelFactory[ name ] = mtable

end
