Page 1 of 1
Line draw canvas
Posted: Mon Oct 20, 2025 4:24 pm
by rndrei
Why Line(0, 1, WindowWidth(#WIN),1, #Black) draws a line on the floor of the window, and should on the entire width of the window!?
Code: Select all
#win=100
#CANVAS=101
Procedure DrawStatus(p)
StartDrawing(CanvasOutput(p))
Line(0, 1, WindowWidth(#WIN),1, #Black)
DrawingFont(FontID(20))
DrawText(0, 0, "test status_bar", #Gray,#White)
StopDrawing()
EndProcedure
If OpenWindow(#WIN,0, 0, 640, 480, "PB custom statusbar", #PB_Window_SystemMenu|#PB_Window_SizeGadget)
CanvasGadget(#CANVAS,0,WindowHeight(#WIN)-20, WindowWidth(#WIN),WindowHeight(#WIN)-20 )
LoadFont(20,"Arial",16)
DrawStatus(#CANVAS)
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_Event_CloseWindow
End
EndSelect
ForEver
EndIf
Re: Line draw canvas
Posted: Mon Oct 20, 2025 5:12 pm
by mk-soft
No Bug. Move to Code Questions
Wrong coordinates and over draw with text ...
Gimmick with own StatusBar structure
Update
Code: Select all
;-TOP
Enumeration FormWindow
#win
EndEnumeration
Enumeration FormGadgets
#CANVAS
EndEnumeration
Enumeration Fonts
#FontStatus
EndEnumeration
Structure udtStatusBarField
Width.i
Text.s
EndStructure
Structure udtStatusBar
Gadget.i
FontID.i
colorText.l
colorBackground.l
colorLine.l
List Field.udtStatusBarField()
EndStructure
Global StatusBar1.udtStatusBar
; ----
CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
Procedure NSColorByNameToRGB(NSColorName.s, CalculateAlpha = #True)
Protected.cgfloat red, green, blue, alpha
Protected nscolorspace, rgb
nscolorspace = CocoaMessage(0, CocoaMessage(0, 0, "NSColor " + NSColorName), "colorUsingColorSpaceName:$", @"NSCalibratedRGBColorSpace")
If nscolorspace
CocoaMessage(@red, nscolorspace, "redComponent")
CocoaMessage(@green, nscolorspace, "greenComponent")
CocoaMessage(@blue, nscolorspace, "blueComponent")
If CalculateAlpha
CocoaMessage(@alpha, nscolorspace, "alphaComponent")
rgb = RGB(red * 255.0 * alpha, green * 255.0 * alpha, blue * 255.0 * alpha)
Else
rgb = RGB(red * 255.0, green * 255.0, blue * 255.0)
EndIf
ProcedureReturn rgb
EndIf
EndProcedure
CompilerEndIf
; ----
Procedure DrawStatus(*Status.udtStatusBar)
Protected x.d, y.d, dx.d, dy.d
With *Status
dx = DesktopScaledX(GadgetWidth(\Gadget))
dy = DesktopScaledY(GadgetHeight(\Gadget))
StartDrawing(CanvasOutput(\Gadget))
Box(0, 0, dx, dy, \colorBackground)
Line(0, 0, dx, 1, \colorLine)
DrawingFont(\FontID)
x = 0
ForEach \Field()
DrawText(DesktopScaledX(x + 4), DesktopScaledY(1.0), \Field()\Text, \colorText, \colorBackground)
x + \Field()\Width
If \Field()\Width <> #PB_Ignore
Line(DesktopScaledX(x), 0, 1 , dy, \colorLine)
EndIf
Next
StopDrawing()
EndWith
EndProcedure
; ----
Procedure UpdateWindow()
Protected dx, dy
dx = WindowWidth(#win)
dy = WindowHeight(#win)
ResizeGadget(#CANVAS, 0, dy-24, dx, 24)
DrawStatus(@StatusBar1)
EndProcedure
; ----
; Init StatusBar Data
LoadFont(#FontStatus,"Arial",12)
StatusBar1\Gadget = #CANVAS
StatusBar1\FontID = FontID(#FontStatus)
CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
StatusBar1\colorText = NSColorByNameToRGB("controlTextColor")
StatusBar1\colorBackground = NSColorByNameToRGB("controlColor")
StatusBar1\colorLine = #Gray ; NSColorByNameToRGB("controlTextColor")
CompilerElse
StatusBar1\colorText = $00000000; NSColorByNameToRGB("controlTextColor")
StatusBar1\colorBackground = $00E5E5E5; NSColorByNameToRGB("controlColor")
StatusBar1\colorLine = #Gray ; NSColorByNameToRGB("controlTextColor")
CompilerEndIf
AddElement(StatusBar1\Field())
StatusBar1\Field()\Width = 100
StatusBar1\Field()\Text = "My Status"
AddElement(StatusBar1\Field())
StatusBar1\Field()\Width = 220
StatusBar1\Field()\Text = "Hello World"
AddElement(StatusBar1\Field())
StatusBar1\Field()\Width = #PB_Ignore
StatusBar1\Field()\Text = "Last Field"
;- Main
If OpenWindow(#WIN,0, 0, 640, 480, "PB custom statusbar", #PB_Window_SystemMenu|#PB_Window_SizeGadget)
CanvasGadget(#CANVAS,0,WindowHeight(#WIN)-24, WindowWidth(#WIN),24 )
DrawStatus(@StatusBar1)
BindEvent(#PB_Event_SizeWindow, @UpdateWindow(), #win)
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_Event_CloseWindow
Break
EndSelect
ForEver
EndIf
End
Re: Line draw canvas
Posted: Mon Oct 20, 2025 6:08 pm
by rndrei
Thank you for the example, it works! I still don't understand why my code doesn't work?
Re: Line draw canvas
Posted: Mon Oct 20, 2025 6:28 pm
by mk-soft
You draw with DrawText over your line.
Re: Line draw canvas
Posted: Mon Oct 20, 2025 6:51 pm
by rndrei
It's the same with your example, the red line stops on half of the window!?

Re: Line draw canvas
Posted: Mon Oct 20, 2025 10:17 pm
by mk-soft
DPI ? 4k Monitor ?
Update top code ...
viewtopic.php?p=646839#p646839
Re: Line draw canvas
Posted: Tue Oct 21, 2025 1:27 am
by rndrei
It"s work!
My screen resolution is 2560 × 1664
Re: Line draw canvas
Posted: Tue Oct 21, 2025 11:42 am
by mk-soft
There are always two monitor resolutions.
Once the one for the program windows and gadgets, and the one for Pixel Drawing.
In percent ...