;----------------- ; AngleGadget ;----------------- Structure AngleGadget Window.i Gadget.i Image.i Ticks.i State.f Width.i Radius.i Flags.i EndStructure Global NewMap AngleGadgetList.AngleGadget() Global *AngleGadget_Active = 0 #PB_Angle_Ticks = 1 Macro AngleGadget_ModF(Value, Factor) ( (Value) - Int((Value)/(Factor))*(Factor) ) EndMacro Procedure.f AngleGadget_RealAngle(Angle.f) If Angle < 0 ProcedureReturn AngleGadget_ModF(Angle, 360) + 360 Else ProcedureReturn AngleGadget_ModF(Angle, 360) EndIf EndProcedure Procedure AngleGadget_LineRA(x, y, Radius1.f, Angle1.f, Radius2.f, Angle2.f, Color) LineXY(Cos(Angle1)*Radius1+x, Sin(Angle1)*Radius1+y, Cos(Angle2)*Radius2+x, Sin(Angle2)*Radius2+y, Color) EndProcedure Procedure AngleGadget_Draw(*AngleGadget.AngleGadget) Protected Angle.f, Tick.i, dAngle.f = #PI*3/4 Protected TickColor.q = GetSysColor_(#COLOR_3DDKSHADOW) + $FF<<24 Protected HilightColor.q = GetSysColor_(#COLOR_3DHILIGHT) + $FF<<24 Protected ShadowColor.q = GetSysColor_(#COLOR_3DSHADOW) + $FF<<24 With *AngleGadget Protected TickSize = Sqr(\Radius/2) StartDrawing(ImageOutput(\Image)) DrawingMode(#PB_2DDrawing_AlphaChannel) Box(0, 0, \Width, \Width, 0) DrawingMode(#PB_2DDrawing_AlphaBlend) If \Flags & #PB_Angle_Ticks For Tick = 1 To \Ticks Angle = 2*#PI*Tick/\Ticks AngleGadget_LineRA(\Radius, \Radius, \Radius, Angle, \Radius-TickSize, Angle, TickColor) Next EndIf Angle = \State*#PI/180 If Angle < 0 Or Angle => #PI : Color = ShadowColor : Else : Color = HilightColor : EndIf AngleGadget_LineRA(\Radius, \Radius, \Radius*0.3, Angle-dAngle, \Radius*0.3, Angle+dAngle, Color) If Angle < #PI/2 Or Angle => #PI+#PI/2 : Color = ShadowColor : Else : Color = HilightColor : EndIf AngleGadget_LineRA(\Radius, \Radius, \Radius*0.7, Angle, \Radius*0.3, Angle+dAngle, Color) If Angle < 2*#PI-#PI/2 And Angle => #PI-#PI/2 : Color = ShadowColor : Else : Color = HilightColor : EndIf AngleGadget_LineRA(\Radius, \Radius, \Radius*0.7, Angle, \Radius*0.3, Angle-dAngle, Color) StopDrawing() SetGadgetState(\Gadget, ImageID(\Image)) EndWith EndProcedure Procedure AngleGadget(Gadget, x, y, Width, Ticks, Flags=#False) Protected Result.i Protected Image.i = CreateImage(#PB_Any, Width, Width, 32) If Image If Gadget = #PB_Any Gadget = ImageGadget(#PB_Any, x, y, Width, Height, ImageID(Image)) Result = Gadget Else Result = ImageGadget(Gadget, x, y, Width, Height, ImageID(Image)) EndIf If Result With AngleGadgetList(Str(GadgetID(Gadget))) \Window = GetActiveWindow() \Gadget = Gadget \Image = Image \Ticks = Ticks \Width = Width \State = 0 \Radius = Int((Width-1)/2) \Flags = Flags EndWith AngleGadget_Draw(AngleGadgetList(Str(GadgetID(Gadget)))) EndIf EndIf ProcedureReturn Result EndProcedure Procedure GetAngleGadgetState(Gadget) Protected *AngleGadget.AngleGadget = FindMapElement(AngleGadgetList(), Str(GadgetID(Gadget))) If *AngleGadget ProcedureReturn *AngleGadget\State EndIf EndProcedure Procedure SetAngleGadgetState(Gadget, State.f) Protected *AngleGadget.AngleGadget = FindMapElement(AngleGadgetList(), Str(GadgetID(Gadget))) If *AngleGadget *AngleGadget\State = Round(State/(360/*AngleGadget\Ticks),#PB_Round_Nearest)*(360/*AngleGadget\Ticks) *AngleGadget\State = AngleGadget_RealAngle(*AngleGadget\State) AngleGadget_Draw(*AngleGadget) EndIf EndProcedure Procedure AngleGadgetCallback(WindowID, Message, wParam, lParam) Protected *AngleGadget.AngleGadget, x, y With *AngleGadget If Message = 273 *AngleGadget = FindMapElement(AngleGadgetList(), Str(lParam)) If *AngleGadget x = WindowMouseX(\Window)-GadgetX(\Gadget)-\Radius y = WindowMouseY(\Window)-GadgetY(\Gadget)-\Radius \State = ATan(y/x)*180/#PI If x < 0 : \State + 180 : EndIf \State = Round(\State/(360/\Ticks),#PB_Round_Nearest)*(360/\Ticks) \State = AngleGadget_RealAngle(\State) *AngleGadget_Active = *AngleGadget AngleGadget_Draw(*AngleGadget) EndIf EndIf EndWith ProcedureReturn #PB_ProcessPureBasicEvents EndProcedure SetWindowCallback(@AngleGadgetCallback()) ; Beispiel ;------------ OpenWindow(0, 0, 0, 400, 400, "AngleGadget", #PB_Window_MinimizeGadget|#PB_Window_ScreenCentered) AngleGadget(0, 10, 10, 50, 8, #PB_Angle_Ticks) AngleGadget(1, 100, 10, 70, 24, #PB_Angle_Ticks) Text = TextGadget(#PB_Any, 100, 100, 70, 20, "0") Angle = AngleGadget(#PB_Any, 200, 10, 70, 12, #PB_Angle_Ticks) StringGadget(4, 200, 100, 70, 20, "0") Repeat Event = WaitWindowEvent() Select Event Case #PB_Event_CloseWindow End Case #PB_Event_Gadget Select EventGadget() Case 1 SetGadgetText(Text, Str(GetAngleGadgetState(1))) Case 4 SetAngleGadgetState(Angle, Val(GetGadgetText(4))) EndSelect EndSelect ForEver ; IDE Options = PureBasic 4.40 (Windows - x86) ; CursorPosition = 135 ; FirstLine = 114 ; EnableXP