Updated to use the vector drawing functions and some of the comments below.
This is the latest version.
Code: Select all
Global Window_0
Global cvsRuler
Declare Repaint()
LoadFont(0, "Times New Roman", 8)
Window_0 = OpenWindow(#PB_Any, x, y, 600, 70, "", #PB_Window_SystemMenu | #PB_Window_SizeGadget)
cvsRuler = CanvasGadget(#PB_Any, 10, 10, 580, 50)
WindowBounds(Window_0, 400, 70, #PB_Ignore, #PB_Ignore)
BindEvent(#PB_Event_SizeWindow, @RePaint(),Window_0)
Procedure DrawRuler()
If StartVectorDrawing(CanvasVectorOutput(cvsRuler,#PB_Unit_Millimeter))
;Uncomment these lines if you wish to clear the canvas first
VectorSourceColor(RGBA(255, 255, 255, 255))
AddPathBox(0,0,GadgetWidth(cvsRuler),GadgetHeight(cvsRuler))
FillPath()
VectorFont(FontID(0), 3)
For i = 0 To VectorOutputWidth()
If Mod(i, 10) = 0
MovePathCursor(i, 0)
AddPathLine(i,8)
MovePathCursor(i + 0.5,4)
AddPathText(Str(i/10))
ElseIf Mod(i, 5) = 0
MovePathCursor(i, 0)
AddPathLine(i,4)
Else
MovePathCursor(i, 0)
AddPathLine(i,2)
EndIf
Next i
EndIf
VectorSourceColor(RGBA(100,100,100, 255))
StrokePath(0.000000001)
StopVectorDrawing()
EndProcedure
Procedure RePaint()
; Resize canvas
W = WindowWidth(Window_0) - 20
ResizeGadget(cvsRuler, #PB_Ignore, #PB_Ignore, W, #PB_Ignore)
DrawRuler()
EndProcedure
DrawRuler()
RePaint()
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow