Seite 1 von 1

RoundBoxedGradient()

Verfasst: 22.06.2010 01:35
von STARGÅTE
Auch wenn es RoundBoxedGradient() irgendwann geben wird,
hier schon mal ein Include dafür.
RoundBoxedGradient arbeitet von genauso wie RoundBox (Darstellung) bzw. BoxedGradient (GradientFarben)
RoundX und RoundY können also auch unterschiedlich sein!

Kleiner Unterscheid: Wird bei RoundBoxedGradient() RoundY weggelassen wird RoundY = RoundX gesetzt.

Code: Alles auswählen

Structure RoundBoxedGradient
  x.i
  y.i
  Width.i
  Height.i
  RoundX.i
  RoundY.i
EndStructure


Procedure.f RoundBoxedGradientCallback(x.i, y.i)
  Shared RoundBoxedGradient.RoundBoxedGradient
  With RoundBoxedGradient
    x - \x
    y - \y
    If x < \RoundX 
      If y < \RoundY
        ProcedureReturn Sqr(Pow((\RoundX-x)/\RoundX,2)+Pow((\RoundY-y)/\RoundY,2))
      ElseIf y >= \Height-\RoundY
        ProcedureReturn Sqr(Pow((\RoundX-x)/\RoundX,2)+Pow((\RoundY+y+1-\Height)/\RoundY,2))
      Else
        ProcedureReturn (\RoundX-x)/\RoundX
      EndIf
    ElseIf x >= \Width-\RoundX
      If y < \RoundY
        ProcedureReturn Sqr(Pow((\RoundX+x+1-\Width)/\RoundX,2)+Pow((\RoundY-y)/\RoundY,2))
      ElseIf y >= \Height-\RoundY
        ProcedureReturn Sqr(Pow((\RoundX+x+1-\Width)/\RoundX,2)+Pow((\RoundY+y+1-\Height)/\RoundY,2))
      Else
        ProcedureReturn (\RoundX+x+1-\Width)/\RoundX
      EndIf
    Else
      If y < \RoundY
        ProcedureReturn (\RoundY-y)/\RoundY
      ElseIf y >= \Height-\RoundY
        ProcedureReturn (\RoundY+y+1-\Height)/\RoundY
      Else
        ProcedureReturn 0
      EndIf   
    EndIf
  EndWith
EndProcedure


Procedure RoundBoxedGradient(x.i, y.i, Width.i, Height.i, RoundX.i, RoundY.i=#PB_Default)
  Shared RoundBoxedGradient.RoundBoxedGradient
  With RoundBoxedGradient
    \x = x
    \y = y
    \Width = Width
    \Height = Height
    \RoundX = RoundX
    \RoundY = RoundY
    If RoundY=#PB_Default : \RoundY = RoundX : EndIf
    If \RoundX < 0 : \RoundX = 0 : EndIf
    If \RoundY < 0 : \RoundY = 0 : EndIf
    If \RoundX*2 > Width : \RoundX = Width/2 : EndIf
    If \RoundY*2 > Height : \RoundY = Height/2 : EndIf
  EndWith
  CustomGradient(@RoundBoxedGradientCallback())
EndProcedure
Hier ein Beispiel:

Code: Alles auswählen

Enumeration
  #Window : #Gadget : #Image
EndEnumeration

CreateImage(#Image, 400, 400, 24)

StartDrawing(ImageOutput(#Image))
  DrawingMode(#PB_2DDrawing_Gradient)
  GradientColor(1.0, $FF0000)
  GradientColor(0.0, $0000FF)
  RoundBoxedGradient(0,0,200,200,50,50)
  RoundBox(0,0,200,200,50,50)
  RoundBoxedGradient(200,0,200,400,100,100)
  RoundBox(200,0,200,400,100,100)
  RoundBoxedGradient(0,200,200,200,80,40)
  RoundBox(0,200,200,200,80,40)
StopDrawing()

OpenWindow(#Window, 0, 0, ImageWidth(#Image), ImageHeight(#Image), "Image", #PB_Window_MinimizeGadget|#PB_Window_ScreenCentered)
  ImageGadget(#Gadget, 0, 0, ImageWidth(#Image), ImageHeight(#Image), ImageID(#Image))

Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
Bild

Re: RoundBoxedGradient()

Verfasst: 22.06.2010 08:56
von Dostej
netter Code
thx

Re: RoundBoxedGradient()

Verfasst: 22.06.2010 10:50
von rolaf
:allright:
Ist der Code nicht Verscheibungsplichtig? Die damit erstellten Drops sehen verdammt toxisch aus. :wink: