Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove arguments overloading in SetDrawColor and SetTextColor #3157

Merged
merged 2 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lua/entities/base_wire_entity.lua
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ if CLIENT then
-- This is overridable by other wire entities which want to customize the overlay, but generally you shouldn't override it
function ENT:DrawWorldTipOutline( pos )
draw.NoTexture()
surface.SetDrawColor(Color(25,25,25,200))
surface.SetDrawColor(25, 25, 25, 200)
Copy link
Contributor

@deltamolfar deltamolfar Oct 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why that, instead of creating local color beforehand on outer scope, if color is static?

Copy link
Contributor Author

@Astralcircle Astralcircle Oct 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no difference, and we also save a bit of code performance because we don't call __index method.
Also check this

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well that's interesting. Thanks for sharing :)


local poly = {
{x = pos.min.x + edgesize, y = pos.min.y, u = 0, v = 0 },
Expand All @@ -119,7 +119,7 @@ if CLIENT then
render.CullMode(MATERIAL_CULLMODE_CCW)
surface.DrawPoly( poly )

surface.SetDrawColor(Color(0,0,0,255))
surface.SetDrawColor(0, 0, 0, 255)

for i=1,#poly-1 do
surface.DrawLine( poly[i].x, poly[i].y, poly[i+1].x, poly[i+1].y )
Expand Down Expand Up @@ -201,7 +201,7 @@ if CLIENT then
self:DrawWorldTipBody( pos )
offset = offset + h_body + edgesize

surface.SetDrawColor( Color(0,0,0,255) )
surface.SetDrawColor(0, 0, 0, 255)
surface.DrawLine( pos.min.x, offset, pos.max.x, offset )
end

Expand Down
4 changes: 2 additions & 2 deletions lua/entities/gmod_wire_colorer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ if CLIENT then
local black = Color(0,0,0,255)

local function drawColorBox( color, x, y )
surface.SetDrawColor( color )
surface.SetDrawColor(color.r, color.g, color.b, color.a)
surface.DrawRect( x, y, color_box_size, color_box_size )

local size = color_box_size

surface.SetDrawColor( black )
surface.SetDrawColor(0, 0, 0)
surface.DrawLine( x, y, x + size, y )
surface.DrawLine( x + size, y, x + size, y + size )
surface.DrawLine( x + size, y + size, x, y + size )
Expand Down
20 changes: 8 additions & 12 deletions lua/entities/gmod_wire_expression2/cl_init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,6 @@ function ENT:DrawWorldTipBody( pos )

local txt = data.txt .. "\nauthor: " .. self:GetPlayerName()
local err = data.error -- this isn't used (yet), might do something with it later

local white = Color(255,255,255,255)
local black = Color(0,0,0,255)

local w_total, yoffset = 0, pos.min.y

-------------------
Expand All @@ -171,13 +167,13 @@ function ENT:DrawWorldTipBody( pos )
h = math.min(h,pos.size.h - (h_of_lower+pos.footersize.h))

render.SetScissorRect( pos.min.x + 16, pos.min.y, pos.max.x - 16, pos.min.y + h, true )
draw.DrawText( txt, "GModWorldtip", pos.min.x + pos.size.w/2, yoffset + 9, white, TEXT_ALIGN_CENTER )
draw.DrawText( txt, "GModWorldtip", pos.min.x + pos.size.w/2, yoffset + 9, color_white, TEXT_ALIGN_CENTER )
render.SetScissorRect( 0, 0, ScrW(), ScrH(), false )

w_total = math.max( w_total, w )
yoffset = yoffset + h

surface.SetDrawColor( black )
surface.SetDrawColor(0, 0, 0)
surface.DrawLine( pos.min.x, yoffset, pos.max.x, yoffset )

-------------------
Expand All @@ -196,7 +192,7 @@ function ENT:DrawWorldTipBody( pos )
-- ops text
local hardtext = (prfcount / e2_hardquota > 0.33) and "(+" .. tostring(math.Round(prfcount / e2_hardquota * 100)) .. "%)" or ""
local str = string.format("%i ops, %i%% %s", prfbench, prfbench / e2_softquota * 100, hardtext)
draw.DrawText( str, "GModWorldtip", pos.min.x + pos.size.w/2, yoffset + 9, white, TEXT_ALIGN_CENTER )
draw.DrawText( str, "GModWorldtip", pos.min.x + pos.size.w/2, yoffset + 9, color_white, TEXT_ALIGN_CENTER )

local _,h = surface.GetTextSize( str )
yoffset = yoffset + h + pos.edgesize
Expand All @@ -207,16 +203,16 @@ function ENT:DrawWorldTipBody( pos )
local quota_width = softquota_width * math.min(prfbench/e2_softquota,1) + (w - softquota_width + 1) * (prfcount/e2_hardquota)

local y = yoffset
surface.SetDrawColor( Color(0,170,0,255) )
surface.SetDrawColor(0, 170, 0, 255)
surface.DrawRect( pos.min.x + pos.edgesize, y, softquota_width, 20 )

surface.SetDrawColor( Color(170,0,0,255) )
surface.SetDrawColor(170, 0, 0, 255)
surface.DrawRect( pos.min.x + pos.edgesize + softquota_width - 1, y, w - softquota_width + 2, 20 )

surface.SetDrawColor( Color(0,0,0,200) )
surface.SetDrawColor(0, 0, 0, 200)
surface.DrawRect( pos.min.x + pos.edgesize, y, quota_width, 20 )

surface.SetDrawColor( black )
surface.SetDrawColor(0, 0, 0)
surface.DrawLine( pos.min.x + pos.edgesize, y, pos.min.x + pos.edgesize + w, y )
surface.DrawLine( pos.min.x + pos.edgesize + w, y, pos.min.x + pos.edgesize + w, y + 20 )
surface.DrawLine( pos.min.x + pos.edgesize + w, y + 20, pos.min.x + pos.edgesize, y + 20 )
Expand All @@ -226,5 +222,5 @@ function ENT:DrawWorldTipBody( pos )

-- cpu time text
local str = string.format("cpu time: %ius", timebench*1000000)
draw.DrawText( str, "GModWorldtip", pos.min.x + pos.size.w/2, yoffset + 9, white, TEXT_ALIGN_CENTER )
draw.DrawText( str, "GModWorldtip", pos.min.x + pos.size.w/2, yoffset + 9, color_white, TEXT_ALIGN_CENTER )
end
15 changes: 6 additions & 9 deletions lua/entities/gmod_wire_indicator.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,8 @@ if CLIENT then
return 400,80
end

local white = Color(255,255,255,255)
local black = Color(0,0,0,255)

local function drawSquare( x,y,w,h )
surface.SetDrawColor( black )
surface.SetDrawColor(0, 0, 0)
surface.DrawLine( x, y, x + w, y )
surface.DrawLine( x + w, y, x + w, y + h )
surface.DrawLine( x + w, y + h, x, y + h )
Expand All @@ -38,7 +35,7 @@ if CLIENT then
local function drawColorSlider( x, y, w, h, self )
if self.a == self.b then -- no infinite loops!
draw.DrawText( "Can't draw color bar because A == B",
"GModWorldtip", x + w / 2, y + h / 2, white, TEXT_ALIGN_CENTER )
"GModWorldtip", x + w / 2, y + h / 2, color_white, TEXT_ALIGN_CENTER )

return
end
Expand All @@ -63,7 +60,7 @@ if CLIENT then
end
end

surface.SetDrawColor( color )
surface.SetDrawColor(color.r, color.g, color.b, color.a)
surface.DrawRect( pos_x, y, math.ceil(w/50), h )
end

Expand Down Expand Up @@ -93,17 +90,17 @@ if CLIENT then

-- A
local color_text = string.format("A color: %d,%d,%d,%d\nA value: %d",self.ar,self.ag,self.ab,self.aa,self.a)
draw.DrawText( color_text, "GModWorldtip", pos.min.x + pos.edgesize, pos.min.y + pos.edgesize, white, TEXT_ALIGN_LEFT )
draw.DrawText( color_text, "GModWorldtip", pos.min.x + pos.edgesize, pos.min.y + pos.edgesize, color_white, TEXT_ALIGN_LEFT )

-- B
local color_text = string.format("B color: %d,%d,%d,%d\nB value: %d",self.br,self.bg,self.bb,self.ba,self.b)
draw.DrawText( color_text, "GModWorldtip", pos.max.x - pos.edgesize, pos.min.y + pos.edgesize, white, TEXT_ALIGN_RIGHT )
draw.DrawText( color_text, "GModWorldtip", pos.max.x - pos.edgesize, pos.min.y + pos.edgesize, color_white, TEXT_ALIGN_RIGHT )

-- Percent
local factor = math.Clamp((self.value-self.a)/(self.b-self.a), 0, 1)
local color_text = string.format("%s (%d%%)",math.Round(self.value,2),factor*100)
local w,h = surface.GetTextSize(color_text)
draw.DrawText( color_text, "GModWorldtip", pos.center.x + 40, pos.min.y + pos.edgesize + h, white, TEXT_ALIGN_RIGHT )
draw.DrawText( color_text, "GModWorldtip", pos.center.x + 40, pos.min.y + pos.edgesize + h, color_white, TEXT_ALIGN_RIGHT )

-- Slider
drawColorSlider( pos.min.x + pos.edgesize, pos.min.y + pos.edgesize + 46, 401, 16, self )
Expand Down
9 changes: 3 additions & 6 deletions lua/entities/gmod_wire_light.lua
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,14 @@ if CLIENT then

return w_total, h_total
end

local white = Color(255,255,255,255)
local black = Color(0,0,0,255)


local function drawColorBox( color, x, y )
surface.SetDrawColor( color )
surface.DrawRect( x, y, color_box_size, color_box_size )

local size = color_box_size

surface.SetDrawColor( black )
surface.SetDrawColor(0, 0, 0)
surface.DrawLine( x, y, x + size, y )
surface.DrawLine( x + size, y, x + size, y + size )
surface.DrawLine( x + size, y + size, x, y + size )
Expand All @@ -119,7 +116,7 @@ if CLIENT then
local color_text = string.format("Color:\n%d,%d,%d",color.r,color.g,color.b)

local w,h = surface.GetTextSize( color_text )
draw.DrawText( color_text, "GModWorldtip", pos.center.x, pos.min.y + pos.edgesize, white, TEXT_ALIGN_CENTER )
draw.DrawText( color_text, "GModWorldtip", pos.center.x, pos.min.y + pos.edgesize, color_white, TEXT_ALIGN_CENTER )

-- color box
drawColorBox( color, pos.center.x - color_box_size / 2, pos.min.y + pos.edgesize * 1.5 + h )
Expand Down
10 changes: 3 additions & 7 deletions lua/entities/gmod_wire_screen.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ if CLIENT then
self.GPU:Finalize()
end

local header_color = Color(100,100,150,255)
local text_color = Color(255,255,255,255)
local background_color = Color(0,0,0,255)

local large_font = "Trebuchet36"
local small_font = "Trebuchet18"
local value_large_font = "screen_font_single"
Expand All @@ -64,11 +60,11 @@ if CLIENT then
value_font = value_large_font
end

surface.SetDrawColor( header_color )
surface.SetDrawColor(100, 100, 150, 255)
surface.DrawRect( x, y, w, header_height )

surface.SetFont( header_font )
surface.SetTextColor( text_color )
surface.SetTextColor( 255, 255, 255 )
local _w,_h = surface.GetTextSize( header )
surface.SetTextPos( x + w / 2 - _w / 2, y + 2 )
surface.DrawText( header, header_font )
Expand Down Expand Up @@ -96,7 +92,7 @@ if CLIENT then
self:DrawModel()

self.GPU:RenderToWorld(nil, 188, function(x, y, w, h)
surface.SetDrawColor(background_color)
surface.SetDrawColor(0, 0, 0, 255)
surface.DrawRect(x, y, w, h)

if self:GetSingleValue() then
Expand Down
10 changes: 5 additions & 5 deletions lua/weapons/gmod_tool/stools/wire_adv.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1054,10 +1054,10 @@ elseif CLIENT then
y = y + 2

local temp,_ = surface.GetTextSize( name .. ":" )
surface.SetTextColor( Color(255,255,255,255) )
surface.SetTextColor( 255, 255, 255 )
surface.SetTextPos( x-temp/2+w/2, y )
surface.DrawText( name .. ":" )
surface.SetDrawColor( Color(255,255,255,255) )
surface.SetDrawColor( 255, 255, 255 )
surface.DrawLine( x, y + fonth+2, x+w, y + fonth+2 )

y = y + 6
Expand All @@ -1075,11 +1075,11 @@ elseif CLIENT then
end

if tbl[i][4] == true then
surface.SetTextColor( Color(255,0,0,255) )
surface.SetTextColor(255, 0, 0, 255)
elseif self:IsBlocked( name, tbl, ent, i ) then
surface.SetTextColor( Color(255,255,255,32) )
surface.SetTextColor(255, 255, 255, 32)
else
surface.SetTextColor( Color(255,255,255,255) )
surface.SetTextColor(255, 255, 255)
end

if tbl[i][9] and tbl[i][9] > 1 then
Expand Down
6 changes: 3 additions & 3 deletions lua/weapons/gmod_tool/stools/wire_debugger.lua
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,9 @@ if CLIENT then
for _, port in ipairs(inputs) do
surface.SetTextPos(boxx,boxy+port.y)
if port[4] then
surface.SetTextColor(Color(255,0,0,255))
surface.SetTextColor(255, 0, 0)
else
surface.SetTextColor(Color(255,255,255,255))
surface.SetTextColor(255, 255, 255)
end
surface.DrawText(port.text)
port.text = nil
Expand Down Expand Up @@ -216,7 +216,7 @@ if CLIENT then

for _, port in ipairs(outputs) do
surface.SetTextPos(boxx,boxy+port.y)
surface.SetTextColor(Color(255,255,255,255))
surface.SetTextColor(255, 255, 255)
surface.DrawText(port.text)
port.text = nil
port.y = nil
Expand Down
2 changes: 1 addition & 1 deletion lua/wire/client/e2helper.lua
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ function E2Helper.Create(reset)

if const.description then
E2Helper.DescriptionEntry:SetText(const.description)
E2Helper.DescriptionEntry:SetTextColor(Color(0, 0, 0))
E2Helper.DescriptionEntry:SetTextColor(color_black)
else
E2Helper.DescriptionEntry:SetText("No description found :(")
E2Helper.DescriptionEntry:SetTextColor(Color(128, 128, 128))
Expand Down
19 changes: 10 additions & 9 deletions lua/wire/client/text_editor/issue_viewer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ function PANEL:Init()

function self.Dragger:Paint(w, h)
if self.Hovered or self.Held then
surface_SetDrawColor(base.ValidationColorDragger)
local color = base.ValidationColorDragger
surface_SetDrawColor(color.r, color.g, color.b, color.a)
else
surface_SetDrawColor(48, 48, 48, 255)
end
Expand Down Expand Up @@ -111,10 +112,9 @@ function PANEL:Init()
n.Label.Paint = function(_, _, _) end
return n
end

local IssuesView_BackgroundColor = Color(32, 32, 32)

function self.IssuesView:Paint(w, h)
surface_SetDrawColor(IssuesView_BackgroundColor)
surface_SetDrawColor(32, 32, 32)
surface_DrawRect(0, 0, w, h)
end

Expand All @@ -133,11 +133,12 @@ function PANEL:Init()
else
validation_color = base.ValidationColorBackground
end

surface_SetDrawColor(validation_color)
surface_SetDrawColor(validation_color.r, validation_color.g, validation_color.b, validation_color.a)
surface_DrawRect(0, 0, w, h)

surface_SetDrawColor(base.ValidationColorOutline)

local color = base.ValidationColorOutline
surface_SetDrawColor(color.r, color.g, _color.b, color.a)
surface_DrawOutlinedRect(0, 0, w, h, 2)

draw_SimpleText(base.ValidationText, "DermaDefault", w / 2, h / 2, color_white, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER )
Expand Down Expand Up @@ -188,7 +189,7 @@ function PANEL:Init()

function self.TogglePopupButton:Paint(w, h)

surface_SetDrawColor(color_white)
surface_SetDrawColor(255, 255, 255)
local centerX, centerY = w / 2, h / 2
local arrowWidth, arrowHeight = 6, 3 * (base.IsCollapsed and -1 or 1)

Expand Down
3 changes: 1 addition & 2 deletions lua/wire/client/text_editor/texteditor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2941,8 +2941,7 @@ function EDITOR:AC_FillList()
end

surface_DrawRect(0, 0, w, h)

surface_SetDrawColor(backgroundColor)
surface_SetDrawColor(backgroundColor.r, backgroundColor.g, backgroundColor.b, backgroundColor.a)
surface_DrawRect(0, 0, 4, h)

surface.SetFont(self.CurrentFont)
Expand Down
Loading