I made a try at a MacOS program. I'm not very familiar with the OSX environment yet so please be patient with my noobish approach to everything. (in particular I didn't spend a lot of time on the rotation angles so if the thing suddenly goes berserk or takes on a mind of its own don't be too shocked )
You will need this image: http://lloydsplace.com/clockface-blue.png
And then make it available to this code:
Code: Select all
;///////////////////////////////////////////////////////////////
; Program: SimpleClock
; Author: Lloyd Gallant (netmaestro)
; Date: February 28, 2016
; Target OS: Mac OSX (not sure the version req'd)
; Compiler Used: PureBasic 5.42 LTS Beta 4
; License: Unlimited, do as you like with it
;///////////////////////////////////////////////////////////////
;
;===================================
; DECLARATIONS
;===================================
Declare RightClickHandler()
Declare MenuHandler()
Declare InitializeEvents()
Declare InitializeWindow()
Declare UpdateClock()
;===================================
; CONSTANTS
;===================================
Enumeration
#Output
#Face
#Hour
#Minute
#Second
EndEnumeration
;===================================
; GLOBALS
;===================================
Global UserRequest_Quit=0
;===================================
; RESOURCES
;===================================
DataSection
clockface:
IncludeBinary "clockface-blue.png"
EndDataSection
UsePNGImageDecoder()
CatchImage(#Face, ?clockface)
CreateImage(#Hour, 128, 128, 32, #PB_Image_Transparent)
StartVectorDrawing(ImageVectorOutput(#Hour))
MovePathCursor(63,73)
VectorSourceColor(RGBA(230, 230, 230, 255))
AddPathLine(63, 42)
StrokePath(5, #PB_Path_RoundEnd)
FillPath()
StopVectorDrawing()
CreateImage(#Minute, 128, 128, 32, #PB_Image_Transparent)
StartVectorDrawing(ImageVectorOutput(#Minute))
MovePathCursor(63,73)
VectorSourceColor(RGBA(180, 180, 180, 255))
AddPathLine(63, 25)
StrokePath(5, #PB_Path_RoundEnd)
FillPath()
StopVectorDrawing()
CreateImage(#Second, 128, 128, 32, #PB_Image_Transparent)
StartVectorDrawing(ImageVectorOutput(#Second))
MovePathCursor(63,73)
VectorSourceColor(RGBA(255, 0, 0, 255))
AddPathLine(63, 20)
StrokePath(1.5, #PB_Path_RoundEnd)
FillPath()
StopVectorDrawing()
;===================================
; MAIN LOOP
;===================================
InitializeWindow()
Repeat : EventID = WaitWindowEvent() : Until UserRequest_Quit
;===================================
; CALLED PROCEDURES
;===================================
Procedure UpdateClock()
Static LastSecond.i, ms.i, Delta.i
Protected Hour.i, Minute.i, Second.i, Angle_Hour.d, Angle_Minute.d, Angle_Second.d
Hour = Hour(Date()):If Hour>12:Hour-12:EndIf
Minute = Minute(Date())
Second = Second(Date())
If Second<>LastSecond
LastSecond=Second
ms=ElapsedMilliseconds()
Delta=0
Else
delta=ElapsedMilliseconds()-ms
EndIf
Angle_Minute = (Minute / 60) * 360
Angle_Hour = (Hour / 12) * 360 + (Angle_Minute/360)*(360/12)
Angle_Second = ((Second+(Delta/1000)) / 60) * 360
CopyImage(#Face, #Output)
StartVectorDrawing(ImageVectorOutput(#Output))
ResetCoordinates()
RotateCoordinates(63,63,Angle_Hour)
MovePathCursor(0,0)
DrawVectorImage(ImageID(#Hour))
ResetCoordinates()
RotateCoordinates(63,63,Angle_Minute)
MovePathCursor(0,0)
DrawVectorImage(ImageID(#Minute))
ResetCoordinates()
RotateCoordinates(63,63,Angle_Second)
MovePathCursor(0,0)
DrawVectorImage(ImageID(#Second))
StopVectorDrawing()
CocoaMessage(0, WindowID(0), "setBackgroundColor:", CocoaMessage(0, 0, "NSColor colorWithPatternImage:", ImageID(#Output)))
EndProcedure
Procedure InitializeEvents()
BindEvent(#PB_Event_Timer, @UpdateClock())
BindEvent(#PB_Event_RightClick, @RightClickHandler())
BindEvent(#PB_Event_Menu, @MenuHandler())
EndProcedure
Procedure InitializeWindow()
OpenWindow(0, 0, 0, 128, 128, "", #PB_Window_BorderLess|#PB_Window_ScreenCentered|#PB_Window_Invisible)
CocoaMessage(0, WindowID(0), "setOpaque:", #NO)
CocoaMessage(0, WindowID(0), "setMovableByWindowBackground:", #YES)
CocoaMessage(0, WindowID(0), "setHasShadow:", #YES)
UpdateClock()
CreatePopupMenu(0)
MenuItem(9, "Close the clock")
MenuItem(10, "Cancel")
InitializeEvents()
HideWindow(0, 0)
AddWindowTimer(0, 1, 50)
EndProcedure
Procedure RightClickHandler()
DisplayPopupMenu(0, WindowID(0))
EndProcedure
Procedure MenuHandler()
Select EventMenu()
Case 9
UserRequest_Quit = #True
EndSelect
EndProcedure