This is a input float, use mousewheel to change the valor in the gadget.
Instructions:
Move the mouse over the gadget and use wheel to change int number.
Press SHIFT to change decenes.
Press CTRL to change centenes.
The license is bigger tha the code
Hey idle this is better!
Code: Select all
; LICENSE:
; Copyright 2025 - Toni M. AKA'minimy'
; Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
; files (the "Software"), to deal in the Software without restriction, including without limitation the rights to
; use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
; to whom the Software is furnished to do so, subject to the following conditions:
;
; The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
; FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
; WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Structure gadgetFloat_data
g.i
EndStructure
Global NewList gadgetFl.gadgetFloat_data()
Procedure gadgetFloatCallback(hwnd, msg, wParam, lParam)
Protected pt.POINT
Protected rect.RECT
Protected.f f,a=1
Protected ng,delta
Select msg
Case #WM_MOUSEWHEEL
GetCursorPos_(@pt)
ForEach gadgetFl()
If IsGadget(gadgetFl()\g)
GetWindowRect_(GadgetID(gadgetFl()\g), @rect)
If pt\x >= rect\left And pt\x <= rect\right And pt\y >= rect\top And pt\y <= rect\bottom
delta = PeekW(@wParam + 2)
If GetAsyncKeyState_(#VK_LSHIFT) & $8000
a= 0.1
ElseIf GetAsyncKeyState_(#VK_LCONTROL) & $8000
a= 0.01
EndIf
If delta > 0
SetGadgetText(gadgetFl()\g, StrF(ValF(GetGadgetText(gadgetFl()\g))+a,2))
SetGadgetData(gadgetFl()\g, ValF(GetGadgetText(gadgetFl()\g))*100)
ElseIf delta < 0
SetGadgetText(gadgetFl()\g, StrF(ValF(GetGadgetText(gadgetFl()\g))-a,2))
SetGadgetData(gadgetFl()\g, ValF(GetGadgetText(gadgetFl()\g))*100)
EndIf
PostEvent(#PB_Event_Gadget,EventWindow(),gadgetFl()\g,#PB_EventType_Change)
EndIf
EndIf
Next
EndSelect
ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure
Procedure gadgetFloat(g,x,y,w,h,s.s,flags=0)
Static ng=1
AddElement(gadgetFl())
If g=#PB_Any: While IsGadget(ng):ng+1:Wend:gadgetFl()\g=ng:Else:gadgetFl()\g=g:EndIf
StringGadget(gadgetFl()\g,x,y,w,h,s,flags)
ProcedureReturn gadgetFl()\g
EndProcedure
OpenWindow(0,0,0,800,400,"Test",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
EditorGadget(1,0,0,100,80)
SetGadgetText(1,"Use mousewheel"+#LF$+"SHIFT Dec"+#LF$+"CTRL Cent")
SetWindowCallback(@gadgetFloatCallback())
gf1= gadgetFloat(#PB_Any,0,100,100,20,"1.00")
gf2= gadgetFloat(#PB_Any,0,120,100,20,"2.40")
gf3= gadgetFloat(#PB_Any,0,140,100,20,"3.87")
Repeat
ev = WaitWindowEvent()
Select ev
Case #PB_Event_Gadget
eg= EventGadget()
et= EventType()
Select eg
Case gf1,gf2,gf3
Debug "OK"
If et= #PB_EventType_Change
Debug "G: "+Str(eg)+" Float: "+GetGadgetText(eg)
Debug "F: "+StrF(GetGadgetData(eg)/100,2)
EndIf
EndSelect
Case #PB_Event_CloseWindow
ew= EventWindow()
If ew= 0: Break: EndIf
EndSelect
ForEver
End
