peut être une solution utiliser un scrollareagadget avec le code de Stargate joint
Code : Tout sélectionner
;
; !! PureBasic 4.60 !!
;http://www.purebasic.fr/german/viewtopic.php?f=3&t=24527
Enumeration
#Window
EndEnumeration
Enumeration
#Gadget
#Scroll
EndEnumeration
EnableExplicit
Structure Appointment
TimeStamp.i ; in Sekunden
Length.i ; in Stunden
Color.i
Text.s
EndStructure
Global NewList Appointment.Appointment()
Procedure AddAppointment(TimeStamp.i, Length.i, Color.i, Text.s)
AddElement(Appointment())
Appointment()\TimeStamp = TimeStamp - TimeStamp%3600
Appointment()\Length = Length
If Hour(Appointment()\TimeStamp) + Length > 24
Appointment()\Length = 24-Hour(Appointment()\TimeStamp)
EndIf
Appointment()\Color = Color
Appointment()\Text = Text
EndProcedure
#HeaderWidth = 64
#HeaderHeight = 32
Procedure DrawCanvasContent(Gadget.i)
Protected DayWidth.i, HourHeight.i, Text.s
Protected Date = Date() : Date - Date%(24*60*60)
Protected Day.i, Hour.i, X.i, Y.i
StartDrawing(CanvasOutput(Gadget))
Box(0, 0, OutputWidth(), OutputHeight(), $FFFFFF)
DrawingMode(#PB_2DDrawing_AlphaBlend|#PB_2DDrawing_Transparent)
DayWidth = (OutputWidth()-#HeaderWidth)/7
HourHeight = (OutputHeight()-#HeaderHeight)/24
Box(0, 0, OutputWidth(), #HeaderHeight, $FFF0F0F0)
Box(0, #HeaderHeight, #HeaderWidth, OutputHeight()-#HeaderHeight, $FFF0F0F0)
For Day = 0 To 6
X = Day*DayWidth+#HeaderWidth
Line(X, 0, 1, OutputHeight(), $FFD0D0D0)
Text = FormatDate("%dd.%mm.", Date+Day*24*60*60)
DrawText(X+DayWidth*0.5-TextWidth(Text)*0.5, #HeaderHeight*0.5-TextHeight(Text)*0.5, Text, $FFC0C0C0)
Next
For Hour = 0 To 23
Y = Hour*HourHeight+#HeaderHeight
Line(0, Y, OutputWidth(), 1, $FFD0D0D0)
If Hour % 2 = 0
Text = RSet(Str(Hour),2,"0")+" Uhr"
DrawText(#HeaderWidth*0.5-TextWidth(Text)*0.5, Y, Text, $FFC0C0C0)
EndIf
Next
ForEach Appointment()
With Appointment()
Day = DayOfYear(\TimeStamp)-DayOfYear(Date)
Hour = Hour(\TimeStamp)
X = Day*DayWidth+#HeaderWidth
Y = Hour*HourHeight+#HeaderHeight
DrawingMode(#PB_2DDrawing_AlphaBlend|#PB_2DDrawing_Transparent)
RoundBox(X+2, Y+2, DayWidth-3, \Length*HourHeight-3, 8, 8, \Color&$FFFFFF|$80<<24)
DrawText(X+DayWidth*0.5-TextWidth(\Text)*0.5, Y+4, \Text, \Color&$FFFFFF|$FF<<24)
DrawingMode(#PB_2DDrawing_AlphaBlend|#PB_2DDrawing_Outlined)
RoundBox(X+2, Y+2, DayWidth-3, \Length*HourHeight-3, 8, 8, \Color&$FFFFFF|$80<<24)
EndWith
Next
StopDrawing()
EndProcedure
Procedure CanvasContentEvent(Gadget.i, EventType.i)
Static *ActiveAppointment.Appointment
Static ShiftY.i, SaveLength.i, SaveTimeStamp.i
Protected DayWidth.i, HourHeight.i, Text.s, TimeStamp.i
Protected Date = Date() : Date - Date%(24*60*60)
Protected Day.i, Hour.i, X.i, Y.i, Length.i
Protected MouseX.i = GetGadgetAttribute(Gadget, #PB_Canvas_MouseX)
Protected MouseY.i = GetGadgetAttribute(Gadget, #PB_Canvas_MouseY)
Protected *Appointment.Appointment
Static Mode = #Null
StartDrawing(CanvasOutput(Gadget))
DayWidth = (OutputWidth()-#HeaderWidth)/7
HourHeight = (OutputHeight()-#HeaderHeight)/24
StopDrawing()
If *ActiveAppointment = #Null
ForEach Appointment()
With Appointment()
Day = DayOfYear(\TimeStamp)-DayOfYear(Date)
Hour = Hour(\TimeStamp)
X = Day*DayWidth+#HeaderWidth
Y = Hour*HourHeight+#HeaderHeight
Length = \Length*HourHeight
If MouseX > X And MouseX < X+DayWidth And MouseY > Y And MouseY < Y+Length
*Appointment = @Appointment()
ShiftY = (MouseY-Y)/HourHeight
If MouseY < Y+8 : Mode = -1 : ElseIf MouseY > Y+Length-8 : Mode = 1 : Else : Mode = 0 : EndIf
EndIf
EndWith
Next
If *Appointment
Select Mode
Case 0 : SetGadgetAttribute(Gadget, #PB_Canvas_Cursor, #PB_Cursor_Arrows)
Case -1, 1 : SetGadgetAttribute(Gadget, #PB_Canvas_Cursor, #PB_Cursor_UpDown)
EndSelect
If EventType = #PB_EventType_LeftButtonDown
*ActiveAppointment = *Appointment
SaveTimeStamp = *ActiveAppointment\TimeStamp
SaveLength = *ActiveAppointment\Length
EndIf
Else
SetGadgetAttribute(Gadget, #PB_Canvas_Cursor, #PB_Cursor_Default)
EndIf
EndIf
If EventType = #PB_EventType_LeftButtonUp
*ActiveAppointment = #Null
EndIf
If *ActiveAppointment And EventType = #PB_EventType_MouseMove
Select Mode
Case 0
Day = (MouseX-#HeaderWidth)/DayWidth
If Day < 0 : Day = 0 : ElseIf Day > 6 : Day = 6 : EndIf
Hour = (MouseY-#HeaderHeight)/HourHeight-ShiftY
If Hour < 0 : Hour = 0 : ElseIf Hour+*ActiveAppointment\Length > 23 : Hour = 24-*ActiveAppointment\Length : EndIf
*ActiveAppointment\TimeStamp = Date
*ActiveAppointment\TimeStamp = AddDate(*ActiveAppointment\TimeStamp, #PB_Date_Day, Day)
*ActiveAppointment\TimeStamp = AddDate(*ActiveAppointment\TimeStamp, #PB_Date_Hour, Hour)
Case -1
Day = DayOfYear(SaveTimeStamp)-DayOfYear(Date)
Hour = (MouseY-#HeaderHeight)/HourHeight
If Hour < 0 : Hour = 0 : ElseIf Hour > 23 : Hour = 23 : EndIf
*ActiveAppointment\TimeStamp = Date
*ActiveAppointment\TimeStamp = AddDate(*ActiveAppointment\TimeStamp, #PB_Date_Day, Day)
*ActiveAppointment\TimeStamp = AddDate(*ActiveAppointment\TimeStamp, #PB_Date_Hour, Hour)
*ActiveAppointment\Length = SaveLength - (*ActiveAppointment\TimeStamp-SaveTimeStamp)/60/60
If *ActiveAppointment\Length < 1
*ActiveAppointment\TimeStamp - 1 + *ActiveAppointment\Length*60*60
*ActiveAppointment\Length = 1
EndIf
Case 1
Day = DayOfYear(SaveTimeStamp)-DayOfYear(Date)
Hour = (MouseY-#HeaderHeight)/HourHeight
If Hour < 0 : Hour = 0 : ElseIf Hour > 23 : Hour = 23 : EndIf
TimeStamp = Date
TimeStamp = AddDate(TimeStamp, #PB_Date_Day, Day)
TimeStamp = AddDate(TimeStamp, #PB_Date_Hour, Hour)
*ActiveAppointment\Length = 1+(TimeStamp-SaveTimeStamp)/60/60
If *ActiveAppointment\Length < 1
*ActiveAppointment\Length = 1
EndIf
EndSelect
DrawCanvasContent(Gadget)
EndIf
EndProcedure
Define n.i
OpenWindow(#Window, 0, 0, 589, 632, "Fenster",#PB_Window_ScreenCentered| #PB_Window_MinimizeGadget | #PB_Window_SizeGadget)
ScrollAreaGadget(#Scroll, 0, 0,WindowWidth(#Window),WindowHeight(#Window),WindowWidth(#Window)*2,WindowHeight(#Window)*2,30)
SetGadgetColor(#Scroll,#PB_Gadget_BackColor,#White)
SetGadgetAttribute(#Scroll,#PB_ScrollArea_X,0)
SetGadgetAttribute(#Scroll,#PB_ScrollArea_Y,0)
CanvasGadget(#Gadget, 0, 0, WindowWidth(#Window), WindowHeight(#Window))
RandomSeed(1)
For n = 1 To 10
AddAppointment(Date()+Random(6*24*60*60), Random(6)+1, RGB(Random($80),Random($80),Random($80)), "Termin "+Str(n))
Next
DrawCanvasContent(#Gadget)
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
End
Case #PB_Event_Gadget
Select EventGadget()
Case #Gadget
CanvasContentEvent(#Gadget, EventType())
EndSelect
Case #PB_Event_SizeWindow
ResizeGadget(#Scroll,#PB_Ignore,#PB_Ignore,WindowWidth(#Window),WindowHeight(#Window))
EndSelect
ForEver