30.09.2025, 01:58 PM
Jules
I have a new ASUS laptop, but not had time yet to install PowerBASIC on it (Only VS2022).
Thus about your problem
Short answer: the three destination points you pass to PlgBlt don’t correspond to the expected corners of the source rectangle.
PlgBlt maps the source RECT (0,0,w,h) to a parallelogram whose corners must be given in this order:
pts(0) → upper-left of the dest parallelogram (maps source (0,0))
pts(1) → upper-right (maps source (w,0))
pts(2) → lower-left (maps source (0,h))
Your code sets pts(0) at the needle tip and the other two as small offsets around the center, so the source bitmap (which has base on top and tip at the bottom) is being warped incorrectly. You also use the full needleWidth instead of half-width for the side offsets.
Fix
Keep the source bitmap exactly as you drew it (base at the top, tip at the bottom). Compute a unit vector along the needle (u) and a perpendicular unit vector (v), then place the three corners as a rotated rectangle whose top edge is the base and whose bottom edge reaches the tip.
PowerBASIC-style math (same symbols you used):
' angle already in radians, pointing from center to tip
ux = COS(angle) : uy = -SIN(angle) ' forward (toward tip)
vx = COS(angle + cherryPi/2) : vy = -SIN(angle + cherryPi/2) ' left normal
halfW = needleWidth / 2
h = needleHeight
' Base is at the gauge center (cx,cy)
baseX = cx : baseY = cy
' === Parallelogram corners for PlgBlt ===
' UL (maps source 0,0) → base - halfW * v
pts(0).x = baseX - halfW * vx
pts(0).y = baseY - halfW * vy
' UR (maps source w,0) → base + halfW * v
pts(1).x = baseX + halfW * vx
pts(1).y = baseY + halfW * vy
' LL (maps source 0,h) → base + h * u - halfW * v
pts(2).x = baseX + h * ux - halfW * vx
pts(2).y = baseY + h * uy - halfW * vy
PlgBlt hDC, pts(0), hMemDC, 0, 0, needleWidth, needleHeight, hMaskBitmap, 0, 0
Mask note
You create a 1-bit mask and paint the same triangle white on black. That’s fine for PlgBlt (white bits in the mask select the pixels to transfer). If you see inverted transparency, just invert the mask (fill white, draw the triangle black).
Other small nits
Use half width for the side offsets (fixed above).
SetStretchBltMode(hDC, %HALFTONE) is harmless here but not required unless you actually stretch the source.
Ensure you re-select the old bitmap/brush/pen into the DCs before deleting (you already do that—good).
With the corrected corner mapping the needle will rotate cleanly around (cx,cy) while still using your triangular source + mask.
I have a new ASUS laptop, but not had time yet to install PowerBASIC on it (Only VS2022).
Thus about your problem
Short answer: the three destination points you pass to PlgBlt don’t correspond to the expected corners of the source rectangle.
PlgBlt maps the source RECT (0,0,w,h) to a parallelogram whose corners must be given in this order:
pts(0) → upper-left of the dest parallelogram (maps source (0,0))
pts(1) → upper-right (maps source (w,0))
pts(2) → lower-left (maps source (0,h))
Your code sets pts(0) at the needle tip and the other two as small offsets around the center, so the source bitmap (which has base on top and tip at the bottom) is being warped incorrectly. You also use the full needleWidth instead of half-width for the side offsets.
Fix
Keep the source bitmap exactly as you drew it (base at the top, tip at the bottom). Compute a unit vector along the needle (u) and a perpendicular unit vector (v), then place the three corners as a rotated rectangle whose top edge is the base and whose bottom edge reaches the tip.
PowerBASIC-style math (same symbols you used):
' angle already in radians, pointing from center to tip
ux = COS(angle) : uy = -SIN(angle) ' forward (toward tip)
vx = COS(angle + cherryPi/2) : vy = -SIN(angle + cherryPi/2) ' left normal
halfW = needleWidth / 2
h = needleHeight
' Base is at the gauge center (cx,cy)
baseX = cx : baseY = cy
' === Parallelogram corners for PlgBlt ===
' UL (maps source 0,0) → base - halfW * v
pts(0).x = baseX - halfW * vx
pts(0).y = baseY - halfW * vy
' UR (maps source w,0) → base + halfW * v
pts(1).x = baseX + halfW * vx
pts(1).y = baseY + halfW * vy
' LL (maps source 0,h) → base + h * u - halfW * v
pts(2).x = baseX + h * ux - halfW * vx
pts(2).y = baseY + h * uy - halfW * vy
PlgBlt hDC, pts(0), hMemDC, 0, 0, needleWidth, needleHeight, hMaskBitmap, 0, 0
Mask note
You create a 1-bit mask and paint the same triangle white on black. That’s fine for PlgBlt (white bits in the mask select the pixels to transfer). If you see inverted transparency, just invert the mask (fill white, draw the triangle black).
Other small nits
Use half width for the side offsets (fixed above).
SetStretchBltMode(hDC, %HALFTONE) is harmless here but not required unless you actually stretch the source.
Ensure you re-select the old bitmap/brush/pen into the DCs before deleting (you already do that—good).
With the corrected corner mapping the needle will rotate cleanly around (cx,cy) while still using your triangular source + mask.
www.objreader.com
GDImage.dll (graphics library), WinLIFT.dll (skin engine)
GDImage.dll (graphics library), WinLIFT.dll (skin engine)