Is it possible to 'draw' a button? Like a clickable draw.RoundedBox

Yeah I know I like draw.RoundedBox. A lot. And it’s flat so that’s all good, but DButtons, well… not so much. Also IIRC they aren’t perfectly square. I want to either:

  • ‘draw’ a clickable/hoverable draw.RoundedBox
    or
  • Make a flat color, perfectly square and customizable DButton

You can just override the paint method of the DButton.

[lua]
yourButton.paint = function(){
–Draw your button here, using draw.RoundedBox
}
[/lua]

Has been a while so that syntax might be correct, but that’s the idea

Heh, I tried using the standard method of painting, didn’t work, will try your code.

[editline]a[/editline]
Ah, same error as before…
[lua]button.Paint() = function(){
draw.RoundedBox( 0, ScrW() / 2 - 180, ScrH() / 2 - 101, 128, 128, Color( 200,200,200,255 ) )
end}[/lua]


Tried to use invalid object (type Panel) (Object was NULL or not of the right type)


Remove the paren’s from .Paint(). It’s a function pointer, you’re not assigning an anonymous function to another function.

-unsnip-
On second thought it’s still broken, the box doesn’t draw at all now…

Well, the button text does but not my roundedbox.

Also, I can’t parent it without it breaking. I NEED to do that because it’s parented to a DPanel and I want it to be removed upon DPanel being removed.

[lua]button.Paint = function(self, w, h)
draw.RoundedBox(0, 0, 0, w, h, Color(200, 200, 200, 255))
end[/lua]

gg

[editline]12th October 2014[/editline]

wait
[lua]button.Paint = function(self, w, h)
draw.RoundedBox(0, ScrW() / 2, ScrH() / 2, 256, 256, Color(200, 200, 200, 255))
end[/lua]
Why exactly does that not show up…? It’s like it literally disappears out of the code if I use ScrW() or ScrH() or anything in it’s Paint. :suicide:

I think it’s setting it’s position not locally to the already defined pos of the button so that will make it go off the screen if the pos of the button is past ScrW() / 2 and ScrH() / 2

Also, I have always learnt to use * 0.5 instead of / 2, I think the computer can calculate multiplication faster than division.

Lua -> Same speed
LuaJIT -> Multiplication is 5% faster

Coordinates for panel drawing (Panel.Paint) are relative to the panel, not the screen.

Another question, didn’t feel I needed to make a whole new thread… What about painting a DComboBox?

[editline]yay[/editline]
Okay, apparently I can easily paint it (with draw.RoundedBox), but what about painting the text of the current selection? And also draw.RoundedBox painting doesn’t work when you go into the actual dropdown.

hey

Ronan, seriously stop, we don’t want to spoon the fed
You have 2 arms, 2 eyeballs, one brain, a wiki, garrysmod.org, steam workshop

WHY you can’t discover and code by yourself

Because I don’t have any examples and for some reason, googling does nothing. The wiki is short of examples.

I realized it’s easy to override the paint function of a DComboBox. Because it’s a DComboBox, not a… Well what IS the name of the dropdown of DComboBox? (lemme guess, it doesn’t have one…)

So you’re saying I can paint a DropButton or whatever it’s called?
How would I even variablize it? :S

guys stop variablizing the issue and help this man

DComboBox.DropButton.Paint