MirrorBar+ panels follow the bar transparency, part 1

This commit is contained in:
2026-11-08 03:52:53 +00:00
parent db0249bc14
commit 572d64c280
5 changed files with 55 additions and 56 deletions
+42 -42
View File
@@ -106,7 +106,7 @@ func weatherInit(inst uintptr) {
wc.Size = uint32(unsafe.Sizeof(wc))
pRegisterClassEx.Call(uintptr(unsafe.Pointer(&wc)))
wxHwnd, _, _ = pCreateWindowEx.Call(
wsExToolWindow|wsExTopmost|wsExNoActivate,
wsExToolWindow|wsExTopmost|wsExNoActivate|wsExLayered,
uintptr(unsafe.Pointer(className)),
uintptr(unsafe.Pointer(u16(""))),
wsPopup,
@@ -223,7 +223,7 @@ func weatherPlace() {
x = clampI(x, 0, sw-cw)
y = clampI(y, 0, sh-ch)
pSetWindowPos.Call(wxHwnd, hwndTopmost, uintptr(x), uintptr(y), uintptr(cw), uintptr(ch), swpNoActivate|swpShowWindow)
pInvalidateRect.Call(wxHwnd, 0, 1)
flyRefresh(wxHwnd)
}
// weatherPoll closes the panel when a mouse button goes down anywhere outside
@@ -302,44 +302,13 @@ func wxMakeFonts() {
func wxPaint(hwnd uintptr) { flyPaint(hwnd, wxDraw) }
// flyPaint paints a panel at double size into a memory bitmap with the given
// drawing function, then shrinks it onto the window.
// flyPaint answers a paint request: the panel is rendered see-through (see
// flyrender.go) instead of being painted by Windows.
func flyPaint(hwnd uintptr, draw func(hdc uintptr, W, H int32)) {
var ps paintStruct
hdc, _, _ := pBeginPaint.Call(hwnd, uintptr(unsafe.Pointer(&ps)))
defer pEndPaint.Call(hwnd, uintptr(unsafe.Pointer(&ps)))
var rc rect
pGetClientRect.Call(hwnd, uintptr(unsafe.Pointer(&rc)))
W, H := rc.Right-rc.Left, rc.Bottom-rc.Top
if W <= 0 || H <= 0 {
return
}
const ss = 2
mem, _, _ := pCreateCompatibleDC.Call(hdc)
defer pDeleteDC.Call(mem)
bmi := bitmapInfoHeader{Width: W * ss, Height: -(H * ss), Planes: 1, BitCount: 32}
bmi.Size = uint32(unsafe.Sizeof(bmi))
var bits unsafe.Pointer
bmp, _, _ := pCreateDIBSection.Call(hdc, uintptr(unsafe.Pointer(&bmi)), 0, uintptr(unsafe.Pointer(&bits)), 0, 0)
if bmp == 0 || bits == nil {
return
}
defer pDeleteObject.Call(bmp)
old, _, _ := pSelectObject.Call(mem, bmp)
defer pSelectObject.Call(mem, old)
saved := scale
defer func() { scale = saved }()
scale *= ss
wxMakeFonts()
draw(mem, W*ss, H*ss)
scale = saved
pSetStretchBltMode.Call(hdc, halftone)
pSetBrushOrgEx.Call(hdc, 0, 0, 0)
pStretchBlt.Call(hdc, 0, 0, uintptr(W), uintptr(H), mem, 0, 0, uintptr(W*ss), uintptr(H*ss), srcCopy)
pBeginPaint.Call(hwnd, uintptr(unsafe.Pointer(&ps)))
pEndPaint.Call(hwnd, uintptr(unsafe.Pointer(&ps)))
flyRender(hwnd, draw)
}
var (
@@ -362,8 +331,7 @@ func wxText(hdc uintptr, s string, r rect, font, col, flags uintptr) {
// here is a double size distance.
func wxDraw(hdc uintptr, W, H int32) {
u := px
fillRaw(hdc, rect{0, 0, W, H}, iconColor()) // the outline follows the tray icon color
fillRaw(hdc, rect{u(1), u(1), W - u(1), H - u(1)}, colBack)
flyFrame(hdc, W, H) // outline in the tray icon color; the background is added when painting
pad := u(14)
inner := W - 2*pad
@@ -512,8 +480,40 @@ func wxSunGlyph(hdc uintptr, cx, cy, s float64) {
}
func wxCrescent(hdc uintptr, cx, cy, rad float64) {
wxCircle(hdc, cx, cy, rad, rgb(235, 232, 205))
wxCircle(hdc, cx+0.45*rad, cy-0.25*rad, 0.85*rad, colBack)
brush, _, _ := pCreateSolidBrush.Call(rgb(235, 232, 205))
defer pDeleteObject.Call(brush)
ix, iy, ir := cx+0.45*rad, cy-0.25*rad, 0.85*rad // the circle that is cut out
top := int32(math.Round(cy))
r := int32(math.Ceil(rad))
for dy := -r; dy <= r; dy++ {
y := top + dy
oh2 := rad*rad - float64(dy)*float64(dy)
if oh2 <= 0 {
continue
}
oh := math.Sqrt(oh2)
x0, x1 := cx-oh, cx+oh
var segs [][2]float64
fy := float64(y) + 0.5 - iy
if ih2 := ir*ir - fy*fy; ih2 > 0 {
ih := math.Sqrt(ih2)
if l := ix - ih; l > x0 {
segs = append(segs, [2]float64{x0, math.Min(l, x1)})
}
if rr := ix + ih; rr < x1 {
segs = append(segs, [2]float64{math.Max(rr, x0), x1})
}
} else {
segs = append(segs, [2]float64{x0, x1})
}
for _, sg := range segs {
if sg[1]-sg[0] < 0.5 {
continue
}
line := rect{int32(math.Round(sg[0])), y, int32(math.Round(sg[1])), y + 1}
pFillRect.Call(hdc, uintptr(unsafe.Pointer(&line)), brush)
}
}
}
// wxIcon draws the picture for a kind of weather inside the square r.