Code: Select all
;
; Win32 / Multimedia / Joystick
;
Enumeration ; #JOYCAPS_
#JOYCAPS_HASZ = 1
#JOYCAPS_HASR = 2
#JOYCAPS_HASU = 4
#JOYCAPS_HASV = 8
#JOYCAPS_HASPOV = 16
#JOYCAPS_POV4DIR = 32
#JOYCAPS_POVCTS = 64
EndEnumeration
Procedure.l MyDraw(*caps.JOYCAPS, *info.JOYINFOEX)
TextColor = $F0F0F0
LineColor = $966E47
FrontColor = $A77F58
iw = ImageWidth(0)
ih = ImageHeight(0)
iw2 = iw - 50
ih2 = ih - 50
If StartDrawing(ImageOutput(0))
x = (*info\dwXpos*iw2)/*caps\wXmax
y = (*info\dwYpos*ih2)/*caps\wYmax
w = (*info\dwRpos*iw2)/*caps\wRmax
h = (*info\dwZpos*ih2)/*caps\wZmax
DrawingMode(1)
DrawingFont(FontID(0))
Box(0,0,iw,ih,FrontColor)
Line(iw/2-2,0,0,ih,LineColor)
Line(0,ih/2-2,iw,0,LineColor)
Box(25,25,iw2,ih2,LineColor)
Line(iw/2-2,25,0,ih2,FrontColor)
Line(25,ih/2-2,iw2,0,FrontColor)
Line(x+25,0,0,ih,FrontColor)
Line(0,y+25,iw,0,FrontColor)
Ellipse(25+x,25+y,w/2,h/2,LineColor)
Ellipse(25+x,25+y,(w/2)-5,(h/2)-5,FrontColor)
Line(x+25,y-h/2+25,0,h,LineColor)
Line(x-w/2+25,y+25,w,0,LineColor)
y = 15
For i = 0 To *caps\wMaxButtons - 1
If (i % 4) = 0
x = iw-145 : y + 26
EndIf
x + 26
button = Pow(2,i)
If (*info\dwButtons & button)
Circle(x,y,12,FrontColor)
Circle(x,y,10,$193CC0)
Else
DrawingMode(4)
Circle(x,y,12,FrontColor)
Circle(x,y,11,LineColor)
DrawingMode(1)
EndIf
If (i<*caps\wNumButtons)
DrawText(x-7,y-6,RSet(Str(i+1),2,"0"),TextColor)
Else
DrawText(x-7,y-6,RSet(Str(i+1),2,"0"),FrontColor)
EndIf
Next
x = 10
DrawText(x,10,"Name: "+PeekS(@*caps\szPname),TextColor)
DrawText(x,25,"Manufacturer: 0x"+Hex(*caps\wMid),TextColor)
DrawText(x,40,"Product: 0x"+Hex(*caps\wPid),TextColor)
DrawText(x,55,"RegKey: "+PeekS(@*caps\szRegKey),TextColor)
DrawText(x,70,"OEM: "+PeekS(@*caps\szOEMVxD),TextColor)
DrawText(x,105,"Nb Axes: "+Str(*caps\wNumAxes)+"/"+Str(*caps\wMaxAxes),TextColor)
DrawText(x,120,"Period: "+Str(*caps\wPeriodMin)+"/"+Str(*caps\wPeriodMax)+" ms",TextColor)
DrawText(x,150,"HasZ: "+Str((*caps\wCaps & #JOYCAPS_HASZ)/#JOYCAPS_HASZ),TextColor)
DrawText(x,165,"HasR: "+Str((*caps\wCaps & #JOYCAPS_HASR)/#JOYCAPS_HASR),TextColor)
DrawText(x,180,"HasU: "+Str((*caps\wCaps & #JOYCAPS_HASU)/#JOYCAPS_HASU),TextColor)
DrawText(x,195,"HasV: "+Str((*caps\wCaps & #JOYCAPS_HASV)/#JOYCAPS_HASV),TextColor)
DrawText(x,210,"HasPOV: "+Str((*caps\wCaps & #JOYCAPS_HASPOV)/#JOYCAPS_HASPOV),TextColor)
DrawText(x,225,"POV4DIR: "+Str((*caps\wCaps & #JOYCAPS_POV4DIR)/#JOYCAPS_POV4DIR),TextColor)
DrawText(x,240,"POVCTS: "+Str((*caps\wCaps & #JOYCAPS_POVCTS)/#JOYCAPS_POVCTS),TextColor)
DrawText(x,255,"Caps: %"+RSet(Bin(*caps\wCaps),7,"0"),TextColor)
DrawText(x,285,"POV: "+Str(*info\dwPOV),TextColor)
DrawText(x,315,"X: "+RSet(Str(*info\dwXpos),5,"0")+" ("+Str(*caps\wXmin)+","+Str(*caps\wXmax)+")",TextColor)
DrawText(x,330,"Y: "+RSet(Str(*info\dwYpos),5,"0")+" ("+Str(*caps\wYmin)+","+Str(*caps\wYmax)+")",TextColor)
DrawText(x,345,"Z: "+RSet(Str(*info\dwZpos),5,"0")+" ("+Str(*caps\wZmin)+","+Str(*caps\wZmax)+")",TextColor)
DrawText(x,360,"R: "+RSet(Str(*info\dwRpos),5,"0")+" ("+Str(*caps\wRmin)+","+Str(*caps\wRmax)+")",TextColor)
DrawText(x,375,"U: "+RSet(Str(*info\dwUpos),5,"0")+" ("+Str(*caps\wUmin)+","+Str(*caps\wUmax)+")",TextColor)
DrawText(x,390,"V: "+RSet(Str(*info\dwVpos),5,"0")+" ("+Str(*caps\wVmin)+","+Str(*caps\wVmax)+")",TextColor)
DrawText(iw-175,ih-15,"Buttons: %"+RSet(Bin(*info\dwButtons),16,"0"),TextColor)
StopDrawing()
SetGadgetState(0,ImageID(0))
EndIf
EndProcedure
iw = 640
ih = 480
If OpenWindow(0,0,0,iw,ih,#PB_Window_SystemMenu|#PB_Window_ScreenCentered,"Joystick (Win32)")
If CreateGadgetList(WindowID(0))
CreateImage(0,iw,ih)
ImageGadget(0,0,0,iw,ih,ImageID(0))
LoadFont(0,"Verdana",7,#PB_Font_HighQuality)
EndIf
If joySetCapture_(WindowID(0),#JOYSTICKID1,#Null,#False) = #JOYERR_NOERROR
If joyGetDevCaps_(#JOYSTICKID1,joyCaps.JOYCAPS,SizeOf(JOYCAPS)) = #JOYERR_NOERROR
; done
EndIf
EndIf
joyInfoEx.JOYINFOEX
joyInfoEx\dwFlags = #JOY_RETURNALL
joyInfoEx\dwSize = SizeOf(JOYINFOEX)
Repeat
Select WaitWindowEvent(50)
Case #PB_Event_CloseWindow: Break
EndSelect
If joyGetPosEx_(#JOYSTICKID1,joyInfoEx) = #JOYERR_NOERROR
MyDraw(joyCaps,joyInfoEx)
EndIf
Delay(1)
ForEver
If joyReleaseCapture_(#JOYSTICKID1) = #JOYERR_NOERROR
; done
EndIf
EndIf