Sources PureBasic
Sources PureBasicConsultez toutes les sources
Nombre d'auteurs : 41, nombre de sources : 88, dernière mise à jour : 13 août 2011
Sélectionnez
EnableExplicit
Define
ScrollStep.F
CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_Linux
ProcedureC
ScrollBarCallback(*
Range.GtkRange, ScrollType.L, NewValue.D, UserData.L)
Shared
ScrollStep.F
GrabImage(0
, 1
, Int(GetGadgetState(1
) *
ScrollStep), 0
, GadgetWidth(0
) -
4
, ImageHeight(0
))
SetGadgetState(0
, ImageID(1
))
EndProcedure
CompilerCase #PB_OS_MacOS
ImportC
""
CreateScrollBarControl(WindowRef.L, *
BoundsRect, CurrentValue.L, MinimumValue.L, MaximumValue.L, ViewSize.L, LiveTracking.L, LiveTrackingProc.L, *
ControlRef)
GetControl32BitMaximum(ControlRef.L)
GetControl32BitMinimum(ControlRef.L)
GetControl32BitValue(ControlRef.L)
SetControl32BitValue(ControlRef.L, NewValue.L)
ShowControl(ControlRef.L)
EndImport
#kControlDownButtonPart
=
21
#kControlUpButtonPart
=
20
Structure
Rect
Top.W
Left.W
Bottom.W
Right.W
EndStructure
ProcedureC
ScrollBarCallback(ControlRef.L, PartCode.L)
Shared
ScrollStep.F
Protected
CurrentPosition.L
Select
PartCode
Case
#kControlUpButtonPart
CurrentPosition =
GetControl32BitValue(ControlRef)
If
CurrentPosition >
GetControl32BitMinimum(ControlRef)
SetControl32BitValue(ControlRef.L, CurrentPosition -
Int(ScrollStep))
EndIf
Case
#kControlDownButtonPart
CurrentPosition =
GetControl32BitValue(ControlRef)
If
CurrentPosition <
GetControl32BitMaximum(ControlRef)
SetControl32BitValue(ControlRef.L, CurrentPosition +
Int(ScrollStep))
EndIf
EndSelect
GrabImage(0
, 1
, Int(GetControl32BitValue(ControlRef) *
ScrollStep), 0
, GadgetWidth(0
) -
4
, ImageHeight(0
))
SetGadgetState(0
, ImageID(1
))
EndProcedure
CompilerCase #PB_OS_Windows
Procedure
WindowCallback(WindowHandle.I, Msg.I, WParam.I, LParam.I)
Shared
ScrollStep.F
If
LParam =
GadgetID(1
)
If
Msg =
#WM_HSCROLL
GrabImage(0
, 1
, Int(GetGadgetState(1
) *
ScrollStep), 0
, GadgetWidth(0
) -
4
, ImageHeight(0
))
SetGadgetState(0
, ImageID(1
))
EndIf
EndIf
ProcedureReturn
#PB_ProcessPureBasicEvents
EndProcedure
CompilerEndSelect
If
LoadImage(0
, #PB_Compiler_Home
+
"/examples/sources/Data/PureBasicLogo.bmp"
)
OpenWindow(0
, 200
, 100
, 172
, 100
, "Live tracking"
, #PB_Window_SystemMenu
)
ImageGadget(0
, 5
, 5
, WindowWidth(0
) -
9
, ImageHeight(0
), 0
, #PB_Image_Border
)
CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
Define
Bounds.Rect
Define
ScrollBarRef.L
Bounds\Left =
5
Bounds\Top =
WindowHeight(0
) -
20
Bounds\Right =
WindowWidth(0
) -
5
Bounds\Bottom =
WindowHeight(0
) -
5
If
CreateScrollBarControl(WindowID(0
), @Bounds, 0
, 0
, GadgetWidth(0
), GadgetWidth(0
), #True
, @ScrollBarCallback(), @ScrollBarRef) =
0
ShowControl(ScrollBarRef)
GrabImage(0
, 1
, GetControl32BitValue(ScrollBarRef), 0
, GadgetWidth(0
) -
4
, ImageHeight(0
))
ScrollStep =
(ImageWidth(0
) -
GadgetWidth(0
)) /
GadgetWidth(0
)
EndIf
CompilerElse
Define
ViewSize.I
ScrollStep =
ImageWidth(0
) /
GadgetWidth(0
)
ViewSize =
Int(0
.0
+
GadgetWidth(0
) /
ImageWidth(0
) *
GadgetWidth(0
))
ScrollBarGadget(1
, 5
, WindowHeight(0
) -
20
, WindowWidth(0
) -
10
, 15
, 0
, GadgetWidth(0
), ViewSize)
GrabImage(0
, 1
, GetGadgetState(1
), 0
, GadgetWidth(0
) -
4
, ImageHeight(0
))
CompilerEndIf
SetGadgetState(0
, ImageID(1
))
CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_Linux
g_signal_connect_data_(GadgetID(1
), "change-value"
, @ScrollBarCallback(), 0
, 0
, 0
)
CompilerCase #PB_OS_Windows
SetWindowCallback(@WindowCallback(), 0
)
CompilerEndSelect
Repeat
Until
WaitWindowEvent() =
#PB_Event_CloseWindow
EndIf
Créé le 18 juin 2011 par Shardik