Permalink
Browse files

GWEN* functions now accept material override

Allows them to be used outside of a Derma Skin.
1 parent 0c37380 commit 0634b731d3b25b284ab6857989914e70f13325d0 @robotboy655 robotboy655 committed Jun 24, 2016
Showing with 58 additions and 57 deletions.
  1. +14 −14 garrysmod/lua/derma/derma.lua
  2. +34 −33 garrysmod/lua/derma/derma_gwen.lua
  3. +10 −10 garrysmod/lua/derma/derma_menus.lua
@@ -1,18 +1,18 @@
-local table = table
-local vgui = vgui
-local concommand = concommand
-local Msg = Msg
-local setmetatable = setmetatable
-local _G = _G
-local hook = hook
-local gamemode = gamemode
-local debug = debug
-local pairs = pairs
-local ispanel = ispanel
-local isfunction = isfunction
-local istable = istable
-local PrintTable = PrintTable
+local table = table
+local vgui = vgui
+local concommand = concommand
+local Msg = Msg
+local setmetatable = setmetatable
+local _G = _G
+local hook = hook
+local gamemode = gamemode
+local debug = debug
+local pairs = pairs
+local ispanel = ispanel
+local isfunction = isfunction
+local istable = istable
+local PrintTable = PrintTable
module( "derma" )
@@ -3,18 +3,19 @@ local meta = FindMetaTable( "Panel" )
GWEN = {}
-function GWEN.CreateTextureBorder( _x, _y, _w, _h, l, t, r, b )
+function GWEN.CreateTextureBorder( _xo, _yo, _wo, _ho, l, t, r, b, material_override )
- local mat = SKIN.GwenTexture
- local tex = mat:GetTexture( "$basetexture" )
-
- _x = _x / tex:Width()
- _y = _y / tex:Height()
- _w = _w / tex:Width()
- _h = _h / tex:Height()
+ local mat = SKIN && SKIN.GwenTexture || material_override
+ if ( material_override && !material_override:IsError() ) then mat = material_override end
return function( x, y, w, h, col )
+ local tex = mat:GetTexture( "$basetexture" )
+ local _x = _xo / tex:Width()
+ local _y = _yo / tex:Height()
+ local _w = _wo / tex:Width()
+ local _h = _ho / tex:Height()
+
surface.SetMaterial( mat )
if ( col ) then
surface.SetDrawColor( col )
@@ -51,18 +52,19 @@ function GWEN.CreateTextureBorder( _x, _y, _w, _h, l, t, r, b )
end
-function GWEN.CreateTextureNormal( _x, _y, _w, _h )
+function GWEN.CreateTextureNormal( _xo, _yo, _wo, _ho, material_override )
- local mat = SKIN.GwenTexture
- local tex = mat:GetTexture( "$basetexture" )
-
- _x = _x / tex:Width()
- _y = _y / tex:Height()
- _w = _w / tex:Width()
- _h = _h / tex:Height()
+ local mat = SKIN && SKIN.GwenTexture || material_override
+ if ( material_override && !material_override:IsError() ) then mat = material_override end
return function( x, y, w, h, col )
+ local tex = mat:GetTexture( "$basetexture" )
+ _x = _xo / tex:Width()
+ _y = _yo / tex:Height()
+ _w = _wo / tex:Width()
+ _h = _ho / tex:Height()
+
surface.SetMaterial( mat )
if ( col ) then
@@ -77,25 +79,23 @@ function GWEN.CreateTextureNormal( _x, _y, _w, _h )
end
-function GWEN.CreateTextureCentered( _x, _y, _w, _h )
+function GWEN.CreateTextureCentered( _xo, _yo, _wo, _ho, material_override )
- local mat = SKIN.GwenTexture
- local tex = mat:GetTexture( "$basetexture" )
-
- local width = _w
- local height = _h
-
- _x = _x / tex:Width()
- _y = _y / tex:Height()
- _w = _w / tex:Width()
- _h = _h / tex:Height()
+ local mat = SKIN && SKIN.GwenTexture || material_override
+ if ( material_override && !material_override:IsError() ) then mat = material_override end
return function( x, y, w, h, col )
- x = x + ( w - width ) * 0.5
- y = y + ( h - height ) * 0.5
- w = width
- h = height
+ local tex = mat:GetTexture( "$basetexture" )
+ _x = _xo / tex:Width()
+ _y = _yo / tex:Height()
+ _w = _wo / tex:Width()
+ _h = _ho / tex:Height()
+
+ x = x + ( w - _wo ) * 0.5
+ y = y + ( h - _ho ) * 0.5
+ w = _wo
+ h = _ho
surface.SetMaterial( mat )
@@ -111,9 +111,10 @@ function GWEN.CreateTextureCentered( _x, _y, _w, _h )
end
-function GWEN.TextureColor( x, y )
+function GWEN.TextureColor( x, y, material_override )
- local mat = SKIN.GwenTexture
+ local mat = SKIN && SKIN.GwenTexture || material_override
+ if ( material_override && !material_override:IsError() ) then mat = material_override end
return mat:GetColor( x, y )
end
@@ -1,31 +1,31 @@
local tblOpenMenus = {}
-function RegisterDermaMenuForClose( menu )
+function RegisterDermaMenuForClose( dmenu )
- table.insert( tblOpenMenus, menu )
+ table.insert( tblOpenMenus, dmenu )
end
function DermaMenu( parentmenu )
- if (!parentmenu) then CloseDermaMenus() end
+ if ( !parentmenu ) then CloseDermaMenus() end
- local menu = vgui.Create( "DMenu" )
+ local dmenu = vgui.Create( "DMenu" )
- return menu
+ return dmenu
end
function CloseDermaMenus()
- for k, menu in pairs( tblOpenMenus ) do
+ for k, dmenu in pairs( tblOpenMenus ) do
- if ( IsValid( menu ) ) then
+ if ( IsValid( dmenu ) ) then
- menu:SetVisible( false )
- if ( menu:GetDeleteSelf() ) then
- menu:Remove()
+ dmenu:SetVisible( false )
+ if ( dmenu:GetDeleteSelf() ) then
+ dmenu:Remove()
end
end

0 comments on commit 0634b73

Please sign in to comment.