Could someone tell me if this works on a Mac?

Everything else that doesn't fall into one of the other PB categories.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8452
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Could someone tell me if this works on a Mac?

Post by netmaestro »

My research shows the Bernard MT Condensed font is available in cocoa but I have no machine to test with. Could someone see if this code looks good on the Mac Please?

Code: Select all

Macro DrawNumber(angle)
  SaveVectorState()
    RotateCoordinates(0.5000*sz,0.5000*sz, angle)
    MovePathCursor(0.5000*sz,0.0500*sz)
    x.d=PathPointX(0) : y.d=PathPointY(0)
  RestoreVectorState()
EndMacro

Procedure ClockFace(sz.d)
  Structure offset
    x.d
    y.d
  EndStructure
  
  DataSection
    offsets:
    Data.d 0.0000,0.0000,0.0250,0.0000,0.0500,0.0000,0.0833,0.0333,0.0833,0.0583,0.0833
    Data.d 0.0833,0.0333,0.0917,0.0083,0.0833,0.0000,0.0783,0.0000,0.0533,0.0117,0.0333
  EndDataSection
  
  Protected x.d, y.d, offsetx.d, offsety.d
  
  Dim offsets.offset(11)
  Restore offsets
  For i = 1 To 11
    Read.d offsets(i)\x
    Read.d offsets(i)\y
  Next
  
  numbers=LoadFont(#PB_Any, "Bernard MT Condensed", 0.1000*sz)
  result = CreateImage(#PB_Any, sz,sz,32,#PB_Image_Transparent)
  StartVectorDrawing(ImageVectorOutput(result))
    VectorSourceColor(RGBA(255,255,255,255))
    AddPathCircle(0.5000*sz,0.5000*sz,0.5000*sz)
    FillPath()
    AddPathCircle(0.5000*sz,0.5000*sz,0.2000*sz)
    VectorSourceColor($FF707070)
    For i=0 To 355 Step 5
      MovePathCursor(0.5000*sz,0.5000*sz)
      SaveVectorState()
        RotateCoordinates(0.5000*sz,0.5000*sz,i)
        AddPathLine(0.5000*sz,0.0100*sz)
        StrokePath(0.0067*sz)
      RestoreVectorState()
    Next
    AddPathCircle(0.5000*sz,0.5000*sz,0.4583*sz)
    VectorSourceColor(RGBA(255,255,255,255))
    FillPath()
    VectorSourceColor(RGBA(0,0,0,255))
    For i=0 To 330 Step 30
      MovePathCursor(0.5000*sz,0.5000*sz)
      SaveVectorState()
        RotateCoordinates(0.5000*sz,0.5000*sz,i)
        AddPathLine(0.5000*sz,0.0100*sz)
        StrokePath(0.0133*sz)
      RestoreVectorState()
    Next      
    AddPathCircle(0.5000*sz,0.5000*sz,0.4417*sz)
    VectorSourceColor(RGBA(255,255,255,255))
    FillPath()
    VectorSourceColor(RGBA(0,0,0,255))
    VectorFont(FontID(numbers),  0.1000*sz)
    offset.d = VectorTextWidth("12")/2
    MovePathCursor(0.5000*sz-offset,0.0500*sz)
    AddPathText("12")
    count.d = 333
    For i=1 To 11
      DrawNumber(count):count-30:If i=6:count-5:EndIf
      MovePathCursor(x-offsets(i)\x*sz,y-offsets(i)\y*sz)
      AddPathText(Str(i))
    Next
    FillPath()
  StopVectorDrawing()
  ProcedureReturn result
EndProcedure

Procedure Crystal(sz)
  crystal = CreateImage(#PB_Any,sz,sz,32,#PB_Image_Transparent)
  StartVectorDrawing(ImageVectorOutput(crystal))
    AddPathCircle(0.5000*sz,0.5000*sz,0.5000*sz)
    VectorSourceCircularGradient(0.5000*sz,0.5000*sz,0.5000*sz)
    VectorSourceGradientColor(RGBA(0,0,0,0),0.0)
    VectorSourceGradientColor(RGBA(0,0,0,0),0.82)
    VectorSourceGradientColor(RGBA(0,0,0,40),0.88)
    VectorSourceGradientColor(RGBA(0,0,0,70),0.92)
    VectorSourceGradientColor(RGBA(0,0,0,240),1.0)
    FillPath(#PB_Path_Preserve)
    VectorSourceColor(RGBA(140,220,255,16))
    FillPath()
    AddPathCircle(0.5000*sz,0.4417*sz,0.4167*sz,300,240,#PB_Path_CounterClockwise)
    VectorSourceColor(RGBA(255,0,0,255))
    AddPathCurve(0.4167*sz,0.0417*sz,0.5833*sz,0.0417*sz,0.7083*sz,0.0833*sz)
    VectorSourceColor(RGBA(255,255,255,190))
    FillPath()
  StopVectorDrawing()
  ProcedureReturn crystal
EndProcedure

;Test

size    = 600
face    = ClockFace(size)
crystal = Crystal(size)

OpenWindow(0, 0, 0, size,size, "VectorDrawing", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
CanvasGadget(0,0,0,size,size)
StartVectorDrawing(CanvasVectorOutput(0))
  MovePathCursor(0,0) : DrawVectorImage(ImageID(face))
  MovePathCursor(0,0) : DrawVectorImage(ImageID(crystal))
StopVectorDrawing()

Repeat:Until WaitWindowEvent() = #PB_Event_CloseWindow
BERESHEIT
User avatar
mk-soft
Always Here
Always Here
Posts: 6411
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Could someone tell me if this works on a Mac?

Post by mk-soft »

The font is not available under macOS and Linux.
It is best to calculate the position of the numbers, because they do not fit from the table

Nice Clock :wink:

Code: Select all

CompilerSelect #PB_Compiler_OS
    CompilerCase #PB_OS_Windows
      numbers=LoadFont(#PB_Any, "Bernard MT Condensed", 0.1000*sz)
    CompilerCase #PB_OS_MacOS
      numbers=LoadFont(#PB_Any, "Charter", 0.1000*sz)
    CompilerCase #PB_OS_Linux
      numbers=LoadFont(#PB_Any, "FreeSerif", 0.1000*sz)
  CompilerEndSelect
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Post Reply