Author Topic: Rounded Rects  (Read 5229 times)

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10667
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Rounded Rects
« on: 2008-May-06 »
Code: GLBasic [Select]


LOADFONT "smalfont.png", 0
        FOR i=0 TO 100
                RoundRect(RND(500),RND(400),40+RND(200),40+RND(200),24,RGB(RND(255),255,RND(255)))
        NEXT
        USEASBMP

        WHILE TRUE
       
                MOUSESTATE mx, my, b1, b2
                RoundRectBorder(mx,my, 250,150, 16, 8, RGB(0x80, 0x80, 0xff), RGB(0xff,0xff,0xff), 16)
                RoundRectBorder(mx,my, 250, 40, 16, 8, RGB(0x80, 0xff, 0x80), RGB(0xff,0xff,0xff), 0)
                PRINT "OBJECTIVE:", mx+12, my+12
                PRINT "Draw round rectangles", mx+12, my+60
                PRINT "for your menu or whatever", mx+12, my+80
                SHOWSCREEN
        WEND



FUNCTION RoundRectBorder: x,y,w,h,r,border,col, col_border, shadow_offset
        IF shadow_offset
                ALPHAMODE -.5
                RoundRect(x+shadow_offset,y+shadow_offset,w,h,r,RGB(0,0,0))
        ENDIF
        ALPHAMODE 0
        RoundRect(x,y,w,h,r,col_border)
        RoundRect(x+border,y+border, w-2*border, h-2*border, r-border, col)
ENDFUNCTION



FUNCTION RoundRect: x,y,w,h,r,col
        // polyvector way of doing it:
        STARTPOLY -1
        RRCircle(x+r,  y+r,    90,180, r,col)
        RRCircle(x+r,  y+h-r, 180,270, r,col)
        RRCircle(x+w-r,y+h-r, 270,360, r,col)
        RRCircle(x+w-r,y+r,   360,450, r,col)

        ENDPOLY
ENDFUNCTION

FUNCTION RRCircle: x,y,phi1, phi2, r, col
LOCAL p
        FOR p=phi1 TO phi2+0.00001 STEP (phi2-phi1)/16
                POLYVECTOR x+COS(p)*r, y-SIN(p)*r, 0,0,col
        NEXT
ENDFUNCTION
 



[attachment deleted by admin]
« Last Edit: 2008-May-06 by Gernot Frisch »

Offline AndyH

  • Dr. Type
  • ****
  • Posts: 383
    • View Profile
    • http://www.ovine.net/
Re: Rounded Rects
« Reply #1 on: 2008-May-06 »
Very nice!

Offline mentalthink

  • Prof. Inline
  • *****
  • Posts: 3341
  • Integrated Brain
    • View Profile
Re: Rounded Rects
« Reply #2 on: 2013-Oct-21 »
Very Usefull for buttons, I never see this post... (some ordner in the forum I think it's needed some list or something)