Code: Alles auswählen
Structure ITEMRECT
x.i
y.i
width.i
height.i
EndStructure
Structure ITEM
text.s
textColor.i
rect.ITEMRECT
EndStructure
Procedure DrawItems(x,y,List items.ITEM(),linespacing=0)
itemCount = ListSize( items() )
If itemCount = 0
ProcedureReturn
EndIf
ForEach items()
items()\rect\width = TextWidth( items()\text )+4
items()\rect\height = TextHeight( items()\text )+4+linespacing
Next
FirstElement( items() )
If itemCount = 1
items()\rect\x = x - items()\rect\width * 0.5
items()\rect\y = y - items()\rect\height * 0.5
ElseIf itemCount = 2
items()\rect\x = x - items()\rect\width * 0.5
items()\rect\y = y - items()\rect\height - 1
NextElement( items() )
items()\rect\x = x - items()\rect\width * 0.5
items()\rect\y = y + 1
Else
mod = ((itemCount - 2) % 2)
left = (itemCount - 2) / 2 + mod
right = itemCount - 2 - left
height = left * (items()\rect\height)
items()\rect\x = x - items()\rect\width * 0.5
items()\rect\y = y - items()\rect\height - 4 - (height * 0.5)
isLeft = 1 : new_y = y - height * 0.5
line = 1
items = left
winkel.f = 180/(items+1)
For i = 1 To itemCount - 2
NextElement( items() )
If isLeft
x_off = Cos(Radian(-90+(line)*winkel)) * height * 0.5
items()\rect\x = x - items()\rect\width - 1 - x_off
items()\rect\y = new_y
isLeft ! 1
Else
items()\rect\x = x + 1 + x_off ;+ items()\rect\height * 0.5
items()\rect\y = new_y
isLeft ! 1
new_y + items()\rect\height + 2
line + 1
EndIf
Next
If NextElement( items() )
If left = right
;new_y + items()\rect\height + 2
items()\rect\x = x - items()\rect\width * 0.5
items()\rect\y = new_y
Else
items()\rect\x = x + 1 + x_off ;+ items()\rect\height * 0.5
items()\rect\y = new_y
EndIf
EndIf
EndIf
ForEach items()
DrawingMode(#PB_2DDrawing_Gradient)
ResetGradientColors()
BackColor(RGB(0,0,255))
FrontColor(RGB(255,0,0))
LinearGradient(items()\rect\x, items()\rect\y, items()\rect\x+items()\rect\width, items()\rect\y+items()\rect\height)
Box(items()\rect\x, items()\rect\y, items()\rect\width, items()\rect\height-linespacing)
DrawingMode(#PB_2DDrawing_Transparent)
DrawText( items()\rect\x+2, items()\rect\y+2, items()\text, items()\textColor)
Next
EndProcedure
Procedure GenerateEntries(count,List items.ITEM())
ClearList( items() )
If count
For i=1 To count
AddElement(Items())
Items()\text = "Menu "+Str(i)+" "
For j = 0 To Random(50)
items()\text + Chr(Random(25)+'a')
Next
Items()\textColor = RGB(255,255,255)
Next
EndIf
EndProcedure
NewList Items.ITEM()
OpenWindow(0, 0, 0, 800, 600, "", #PB_Window_ScreenCentered|#PB_Window_SystemMenu)
CanvasGadget(0, 0, 0, WindowWidth(0)-100, WindowHeight(0))
SpinGadget(1,WindowWidth(0)-90,10,80,20,1,50)
SetGadgetState(1,8)
SetGadgetText(1,Str(GetGadgetState(1)))
LoadFont(1,"Arial",20)
GenerateEntries(GetGadgetState(1),Items())
If StartDrawing( CanvasOutput(0) )
DrawingFont(FontID(1))
DrawItems( OutputWidth()*0.5, OutputHeight()*0.5, Items(), 2 )
StopDrawing()
EndIf
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
End
Case #PB_Event_Gadget
If EventGadget()=1
count = GetGadgetState(1)
SetGadgetText(1,Str(count))
GenerateEntries(count,Items())
If StartDrawing( CanvasOutput(0) )
Box(0,0,OutputWidth(),OutputHeight(),RGB(255,255,255))
DrawingFont(FontID(1))
DrawItems( OutputWidth()*0.5, OutputHeight()*0.5, Items(), 5 )
StopDrawing()
EndIf
EndIf
EndSelect
ForEver