Drawing a Triangular Button


#1

I'm trying to draw a triangular button.  It seems simple but there must be something I'm missing because I can't for the life of me get it to work.  I've set up a custom look and feel and tried overriding the button methods.  Currently, I'm using drawButtonBackground, but I've tried all the others with no success.  This is the code I have inside my drawButtonBackground function:

int x = button.getScreenX(); 
int y = button.getScreenY(); 
int width = button.getWidth(); 
int height = button.getHeight(); 

g.setColour(Colour(255,255,255)); 
Path triangle; 
triangle.addTriangle(x, y + height / 2, x + width, y, x + width, y + height); 
g.fillPath(triangle);

When I run this, I know the function is getting called because I've printed out debug statements.  Yet nothing renders on the screen.  Still fairly new to JUCE, I have no idea what's going wrong and could really use some advice.  Thanks in advance!


#2

Using getScreenX and getScreenY is most likely a problem.  Painting should be local coordinates for the component that's being painted.


#3

You therefore also shouldn't add the width to the x, and same for height and y.  So, regardless of where your button is on the screen, to fill in the entire background you'd use x:0, y:0, width:width, height:height.


#4

That fixed everything! I feel like an idiot for not trying that earlier, but oh well.  Thank you so much for your help!!