Can you help me?

Sorry to bother y’all but y’see my code here has a itty bitty problem… I cannot get the text to show inside the rounded rectangle. I haven’t been able to solve it… Can you help me?


--# Main
-- RoundRect

-- Use this function to perform your initial setup
function setup()
    print("Hello World!")
    parameter.text("Text", "ExampleText") 
    parameter.number("xPosition", 0, 690, 0 )
    parameter.number("yPosition", 0, HEIGHT - 60, 0)
    parameter.number("Width", 60, WIDTH, 60)
    parameter.number("Height", 60, HEIGHT, 21)
    parameter.number("Radius", 0, 30, 30)
    parameter.number("AmountofRed", 0, 250, 250)
    parameter.number("AmountofGreen", 0, 250, 250)
    parameter.number("AmountofBlue", 0, 250, 250)
    parameter.number("AmountofOpacity", 0, 250, 250)
end

-- This function gets called once every frame
function draw()
background(100, 120, 160)
font("Georgia")
fill(0, 0, 0, 255)
fontSize(20)
textWrapWidth(70)
text(Text, xPosition, yPosition)
    -- This sets a dark background color 
    background(0, 0, 0, 0)

    -- This sets the line thickness
    strokeWidth(10)
    
    -- Do your drawing here
    fill(255, 0, 0, 255)
    fill(AmountofRed, AmountofGreen, AmountofBlue, AmountofOpacity)
    strokeWidth(5)
    roundRect(xPosition, yPosition, Width, Height, Radius)
end

--# RoundRect
function roundRect(x,y,w,h,r)
    pushStyle()
    
    insetPos = vec2(x+r,y+r)
    insetSize = vec2(w-2*r,h-2*r)
    
    --Copy fill into stroke
    local red,green,blue,a = fill()
    stroke(red,green,blue,a)
    
    noSmooth()
    rectMode(CORNER)
    rect(insetPos.x,insetPos.y,insetSize.x,insetSize.y)
    
    if r > 0 then
        smooth()
        lineCapMode(ROUND)
        strokeWidth(r*2)

        line(insetPos.x, insetPos.y, 
             insetPos.x + insetSize.x, insetPos.y)
        line(insetPos.x, insetPos.y,
             insetPos.x, insetPos.y + insetSize.y)
        line(insetPos.x, insetPos.y + insetSize.y,
             insetPos.x + insetSize.x, insetPos.y + insetSize.y)
        line(insetPos.x + insetSize.x, insetPos.y,
             insetPos.x + insetSize.x, insetPos.y + insetSize.y)            
    end
    popStyle()
end

Thank y’all in advance.

@TheRogueBatcher, you draw your text, and then you draw your rounded rectangle on top of it… You should first draw the rectange

Also, you’ll probably want this in the setup

textMode(CORNER)

(the rounded rectangle uses Corner possitiosn, so text at Center possition, would work, but then you have to change some things so that you don’t draw it at the coordinates of the rounded rectangle

I hope this makes sense xd

The first part does XD after that I’m lost im afraid…

@stevon8ter is right - your drawing the rectangle on top of the text

Try adding the following just before the end of the draw function

    textWrapWidth(Width)
    fill(0)
    text(Text, xPosition+Width/2, yPosition+Height/2)

Thanks

Try this draw routine.


function draw()
    background(100, 120, 160)
    strokeWidth(10)
    fill(255, 0, 0, 255)
    fill(AmountofRed, AmountofGreen, AmountofBlue, AmountofOpacity)
    strokeWidth(5)
    roundRect(xPosition, yPosition, Width, Height, Radius)
    font("Georgia")
    fill(0, 0, 0, 255)
    fontSize(20)
    textWrapWidth(70)
    text(Text, xPosition+Width/2, yPosition+Height/2)
end

thanks…?..?..,.,!,!,l…