RoundedBox() function; might be useful

Share your advanced PureBasic knowledge/code with the community.
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

RoundedBox() function; might be useful

Post by Psychophanta »

Code updated For 5.20+

Code: Select all

bitplanes.b=32:RX.w=1024:RY.w=768
If InitMouse()=0 Or InitSprite()=0 Or  InitKeyboard()=0
  MessageRequester("Error","Can't open DirectX",0):End
EndIf
While OpenScreen(RX.w,RY.w,bitplanes.b,"Masses")=0
  If bitplanes.b>16:bitplanes.b-8
  ElseIf RY.w>600:RX.w=800:RY.w=600
  ElseIf RY.w>480:RX.w=640:RY.w=480
  ElseIf RY.w>400:RX.w=640:RY.w=400
  ElseIf RY.w>240:RX.w=320:RY.w=240
  ElseIf RY.w>200:RX.w=320:RY.w=200
  Else:MessageRequester("VGA limitation","Can't open Screen!",0):End
  EndIf
Wend
Global Mass_Geometry.l,Mass_Type.l,SCREENWIDTH.l,SCREENHEIGHT.l,FixMode.s
SCREENWIDTH.l=GetSystemMetrics_(#SM_CXFULLSCREEN):SCREENHEIGHT.l=GetSystemMetrics_(#SM_CYFULLSCREEN)
Procedure.f MinF(n1.f,n2.f)
  If n1<n2:ProcedureReturn n1:EndIf
  ProcedureReturn n2
EndProcedure
Procedure.f MaxF(n1.f,n2.f)
  If n1>n2:ProcedureReturn n1:EndIf
  ProcedureReturn n2
EndProcedure
Procedure RoundedBox(x.l,y.l,w.l,h.l,thickness.l,radUL.l,radUR.l,radDL.l,radDR.l,innercolor.l,color.l)
  Box(x+2*MaxF(radUL,radDL),y+2*MaxF(radUL,radUR),w-2*MaxF(radUL,radDL)-2*MaxF(radUR,radDR),h-2*MaxF(radUL,radUR)-2*MaxF(radDL,radDR),color)
  Circle(x+radUL,y+radUL,radUL,color);Up Left
  Circle(x+w-radUR-1,y+radUR,radUR,color);Up Right
  Circle(x+w-radDR-1,y+h-radDR-1,radDR,color);Down Right
  Circle(x+radDL,y+h-radDL-1,radDL,color);Down Left
  Box(x+radUL,y,w-radUR-radUL,2*MaxF(radUR,radUL),color)
  Box(x+w-2*MaxF(radUR,radDR),y+radUR,2*MaxF(radUR,radDR),h-radUR-radDR,color)
  Box(x+radDL,y+h-2*MaxF(radDL,radDR),w-radDL-radDR,2*MaxF(radDL,radDR),color)
  Box(x,y+radUL,2*MaxF(radUL,radDL),h-radUL-radDL,color)
  x+thickness:y+thickness:w-2*thickness:h-2*thickness:color=innercolor
  radUL-thickness:radUR-thickness:radDL-thickness:radDR-thickness
  If radUL<1:radUL=1:EndIf:If radUR<1:radUR=1:EndIf:If radDL<1:radDL=1:EndIf:If radDR<1:radDR=1:EndIf
  Box(x+2*MaxF(radUL,radDL),y+2*MaxF(radUL,radUR),w-2*MaxF(radUL,radDL)-2*MaxF(radUR,radDR),h-2*MaxF(radUL,radUR)-2*MaxF(radDL,radDR),color)
  Circle(x+radUL,y+radUL,radUL,color);Up Left
  Circle(x+w-radUR-1,y+radUR,radUR,color);Up Right
  Circle(x+w-radDR-1,y+h-radDR-1,radDR,color);Down Right
  Circle(x+radDL,y+h-radDL-1,radDL,color);Down Left
  Box(x+radUL,y,w-radUR-radUL,2*MaxF(radUR,radUL),color)
  Box(x+w-2*MaxF(radUR,radDR),y+radUR,2*MaxF(radUR,radDR),h-radUR-radDR,color)
  Box(x+radDL,y+h-2*MaxF(radDL,radDR),w-radDL-radDR,2*MaxF(radDL,radDR),color)
  Box(x,y+radUL,2*MaxF(radUL,radDL),h-radUL-radDL,color)
EndProcedure

Repeat
  ExamineKeyboard():ExamineMouse()
  StartDrawing(ScreenOutput())
  RoundedBox(100,100,400,600,25,12,81,55,21,$220000,$aaaaaa)
  StopDrawing()
  FlipBuffers():Delay(15)
Until KeyboardPushed(#PB_Key_Escape)