MirrorBar+ 9: bar color, more icon colors, upright logo on vertical bar

Part of MirrorBar+ 9 (bar color, logo shapes, clock size and bold, hide battery, volume and wifi).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JW57ZsfD68JfyDt93j58v9
This commit is contained in:
2026-11-12 22:38:54 +00:00
co-authored by Claude Sonnet 5.5
parent fc1d82d790
commit 2a76d1d9c9
+406 -392
View File
@@ -1,392 +1,406 @@
package main package main
// Painting the bar smoothly on a see-through background. // Painting the bar smoothly on a see-through background.
// //
// Drawing icons and text straight onto a dark bitmap leaves a dark fringe // Drawing icons and text straight onto a dark bitmap leaves a dark fringe
// around them once the background is made see-through. So the bar is painted // around them once the background is made see-through. So the bar is painted
// in layers: one layer with only the backgrounds, and the icons, text and // in layers: one layer with only the backgrounds, and the icons, text and
// symbols drawn twice (once on black, once on white) at double size. Comparing // symbols drawn twice (once on black, once on white) at double size. Comparing
// the two copies shows exactly how see-through every edge pixel is, and // the two copies shows exactly how see-through every edge pixel is, and
// shrinking back down gives smooth edges with no dark outline. // shrinking back down gives smooth edges with no dark outline.
import ( import (
"math" "math"
"os" "os"
"path/filepath" "path/filepath"
"strconv" "strconv"
"strings" "strings"
"unsafe" "unsafe"
) )
const ( const (
superSample = 2 superSample = 2
mfPopup = 0x0010 mfPopup = 0x0010
menuLogoColorBase = 100 menuLogoColorBase = 100
menuClockColorBase = 120 menuClockColorBase = 120
menuIconColorBase = 140 menuIconColorBase = 140
) )
var ( var (
fontTime2 uintptr fontTime2 uintptr
fontApp2 uintptr fontApp2 uintptr
) )
// initSuperFonts makes the double size fonts used for the smooth pass. // initSuperFonts makes the double size fonts used for the smooth pass.
func initSuperFonts() { func initSuperFonts() {
scale *= superSample scale *= superSample
fontTime2 = makeFont(px(13), 400) fontTime2 = makeFont(px(13), 400)
fontApp2 = makeFont(px(12), 600) fontApp2 = makeFont(px(12), 600)
scale /= superSample scale /= superSample
} }
// ---------- colors ---------- // ---------- colors ----------
type namedColor struct { type namedColor struct {
name string name string
r, g, b int r, g, b int
} }
var palette = []namedColor{ var palette = []namedColor{
{"White", 245, 245, 245}, {"White", 245, 245, 245},
{"Blue", 0, 120, 212}, {"Blue", 0, 120, 212},
{"Sky blue", 90, 190, 255}, {"Sky blue", 90, 190, 255},
{"Green", 70, 200, 110}, {"Green", 70, 200, 110},
{"Yellow", 255, 205, 60}, {"Yellow", 255, 205, 60},
{"Orange", 255, 140, 40}, {"Orange", 255, 140, 40},
{"Red", 235, 70, 70}, {"Red", 235, 70, 70},
{"Pink", 255, 125, 195}, {"Pink", 255, 125, 195},
{"Purple", 175, 115, 240}, {"Purple", 175, 115, 240},
{"Black", 0, 0, 0}, {"Black", 0, 0, 0},
} {"Dark green", 20, 120, 55},
{"Teal", 0, 160, 160},
var ( {"Navy", 30, 60, 160},
logoIdx = 1 // Blue, like the real Windows logo {"Maroon", 140, 30, 50},
clockIdx = 0 // White {"Gray", 140, 140, 150},
iconIdx = 0 // White: battery, volume, wifi and the hidden-icons arrow {"Lime", 150, 220, 40},
) }
func colorOf(i int) uintptr { var (
if i < 0 || i >= len(palette) { logoIdx = 1 // Blue, like the real Windows logo
i = 0 clockIdx = 0 // White
} iconIdx = 0 // White: battery, volume, wifi and the hidden-icons arrow
c := palette[i] )
r, g, b := styleColor(c.r, c.g, c.b)
return rgb(r, g, b) func colorOf(i int) uintptr {
} if i < 0 || i >= len(palette) {
i = 0
func logoColor() uintptr { return colorOf(logoIdx) } }
func clockColor() uintptr { return colorOf(clockIdx) } c := palette[i]
func iconColor() uintptr { return colorOf(iconIdx) } r, g, b := styleColor(c.r, c.g, c.b)
return rgb(r, g, b)
// iconDim is the color of the "off" bars on the volume and wifi icons. }
func iconDim() uintptr {
c := palette[iconIdx] func logoColor() uintptr { return colorOf(logoIdx) }
if c.r+c.g+c.b < 300 { // a dark icon color: the off bars are lighter func clockColor() uintptr { return colorOf(clockIdx) }
return rgb(140, 140, 150) func iconColor() uintptr { return colorOf(iconIdx) }
}
return rgb(110, 110, 120) // iconDim is the color of the "off" bars on the volume and wifi icons.
} func iconDim() uintptr {
c := palette[iconIdx]
func colorsFile() string { return filepath.Join(dataDir(), "colors.txt") } if c.r+c.g+c.b < 300 { // a dark icon color: the off bars are lighter
return rgb(140, 140, 150)
func loadColors() { }
b, err := os.ReadFile(colorsFile()) return rgb(110, 110, 120)
if err != nil { }
return
} func colorsFile() string { return filepath.Join(dataDir(), "colors.txt") }
parts := strings.Split(strings.TrimSpace(string(b)), ",")
if len(parts) < 2 || len(parts) > 3 { func loadColors() {
return b, err := os.ReadFile(colorsFile())
} if err != nil {
vals := []int{0, 0, 0} return
for i, p := range parts { }
n, err := strconv.Atoi(p) parts := strings.Split(strings.TrimSpace(string(b)), ",")
if err != nil || n < 0 || n >= len(palette) { if len(parts) < 2 || len(parts) > 3 {
return return
} }
vals[i] = n vals := []int{0, 0, 0}
} for i, p := range parts {
logoIdx, clockIdx, iconIdx = vals[0], vals[1], vals[2] n, err := strconv.Atoi(p)
} if err != nil || n < 0 || n >= len(palette) {
return
func saveColors() { }
_ = os.MkdirAll(dataDir(), 0o755) vals[i] = n
_ = os.WriteFile(colorsFile(), []byte(strconv.Itoa(logoIdx)+","+strconv.Itoa(clockIdx)+","+strconv.Itoa(iconIdx)), 0o644) }
} logoIdx, clockIdx, iconIdx = vals[0], vals[1], vals[2]
}
// addColorMenus adds the two color pickers as sub menus.
func addColorMenus(menu uintptr) { func saveColors() {
build := func(base uintptr, cur int, title string) { _ = os.MkdirAll(dataDir(), 0o755)
sub, _, _ := pCreatePopupMenu.Call() _ = os.WriteFile(colorsFile(), []byte(strconv.Itoa(logoIdx)+","+strconv.Itoa(clockIdx)+","+strconv.Itoa(iconIdx)), 0o644)
for i, c := range palette { }
var flags uintptr
if i == cur { // addColorMenus adds the two color pickers as sub menus.
flags = mfChecked func addColorMenus(menu uintptr) {
} build := func(base uintptr, cur int, title string) {
pAppendMenu.Call(sub, flags, base+uintptr(i), uintptr(unsafe.Pointer(u16(c.name)))) sub, _, _ := pCreatePopupMenu.Call()
} for i, c := range palette {
pAppendMenu.Call(menu, mfPopup, sub, uintptr(unsafe.Pointer(u16(title)))) var flags uintptr
} if i == cur {
build(menuLogoColorBase, logoIdx, "Windows logo color") flags = mfChecked
build(menuClockColorBase, clockIdx, "Clock color") }
build(menuIconColorBase, iconIdx, "Tray icon color") pAppendMenu.Call(sub, flags, base+uintptr(i), uintptr(unsafe.Pointer(u16(c.name))))
addStyleMenu(menu) }
} pAppendMenu.Call(menu, mfPopup, sub, uintptr(unsafe.Pointer(u16(title))))
}
func handleColorCommand(cmd uintptr) bool { build(menuLogoColorBase, logoIdx, "Windows logo color")
n := uintptr(len(palette)) build(menuClockColorBase, clockIdx, "Clock color")
switch { build(menuIconColorBase, iconIdx, "Tray icon color")
case cmd >= menuLogoColorBase && cmd < menuLogoColorBase+n: addStyleMenu(menu)
logoIdx = int(cmd - menuLogoColorBase) }
case cmd >= menuClockColorBase && cmd < menuClockColorBase+n:
clockIdx = int(cmd - menuClockColorBase) func handleColorCommand(cmd uintptr) bool {
case cmd >= menuIconColorBase && cmd < menuIconColorBase+n: n := uintptr(len(palette))
iconIdx = int(cmd - menuIconColorBase) switch {
case handleStyleCommand(cmd): case cmd >= menuLogoColorBase && cmd < menuLogoColorBase+n:
return true logoIdx = int(cmd - menuLogoColorBase)
default: case cmd >= menuClockColorBase && cmd < menuClockColorBase+n:
return false clockIdx = int(cmd - menuClockColorBase)
} case cmd >= menuIconColorBase && cmd < menuIconColorBase+n:
saveColors() iconIdx = int(cmd - menuIconColorBase)
return true case handleStyleCommand(cmd):
} return true
default:
// ---------- painting ---------- return false
}
// renderLayer paints one layer of the bar (w by h in the horizontal layout) saveColors()
// and returns its pixels at the real orientation. fills and fg choose which return true
// parts are painted; base is the color everything is painted onto. }
func renderLayer(screen uintptr, w, h int32, fills, fg bool, base uintptr) []uint32 {
layerFills, layerFg = fills, fg // ---------- painting ----------
defer func() { layerFills, layerFg = true, true }()
// renderLayer paints one layer of the bar (w by h in the horizontal layout)
mem, _, _ := pCreateCompatibleDC.Call(screen) // and returns its pixels at the real orientation. fills and fg choose which
defer pDeleteDC.Call(mem) // parts are painted; base is the color everything is painted onto.
bmi := bitmapInfoHeader{Width: w, Height: -h, Planes: 1, BitCount: 32} func renderLayer(screen uintptr, w, h int32, fills, fg bool, base uintptr) []uint32 {
bmi.Size = uint32(unsafe.Sizeof(bmi)) layerFills, layerFg = fills, fg
var bits unsafe.Pointer defer func() { layerFills, layerFg = true, true }()
bmp, _, _ := pCreateDIBSection.Call(screen, uintptr(unsafe.Pointer(&bmi)), 0,
uintptr(unsafe.Pointer(&bits)), 0, 0) mem, _, _ := pCreateCompatibleDC.Call(screen)
if bmp == 0 || bits == nil { defer pDeleteDC.Call(mem)
return nil bmi := bitmapInfoHeader{Width: w, Height: -h, Planes: 1, BitCount: 32}
} bmi.Size = uint32(unsafe.Sizeof(bmi))
defer pDeleteObject.Call(bmp) var bits unsafe.Pointer
old, _, _ := pSelectObject.Call(mem, bmp) bmp, _, _ := pCreateDIBSection.Call(screen, uintptr(unsafe.Pointer(&bmi)), 0,
defer pSelectObject.Call(mem, old) uintptr(unsafe.Pointer(&bits)), 0, 0)
if bmp == 0 || bits == nil {
fillRaw(mem, rect{0, 0, w, h}, base) return nil
sr := startRect(w, h) }
if hoverStart { defer pDeleteObject.Call(bmp)
fill(mem, sr, rgb(58, 58, 68)) old, _, _ := pSelectObject.Call(mem, bmp)
} defer pSelectObject.Call(mem, old)
drawLogo(mem, sr)
drawApps(mem, w, h) fillRaw(mem, rect{0, 0, w, h}, base)
drawTray(mem, w, h) sr := startRect(w, h)
pGdiFlush.Call() if hoverStart {
fill(mem, sr, rgb(58, 58, 68))
src := unsafe.Slice((*uint32)(bits), int(w)*int(h)) }
if !vertical { drawLogo(mem, sr)
out := make([]uint32, len(src)) drawApps(mem, w, h)
copy(out, src) drawTray(mem, w, h)
return out pGdiFlush.Call()
}
src := unsafe.Slice((*uint32)(bits), int(w)*int(h))
// Turn a quarter turn, then put the icons and symbols back on upright. if !vertical {
fw, fh := h, w out := make([]uint32, len(src))
bmiV := bitmapInfoHeader{Width: fw, Height: -fh, Planes: 1, BitCount: 32} copy(out, src)
bmiV.Size = uint32(unsafe.Sizeof(bmiV)) return out
var bitsV unsafe.Pointer }
bmpV, _, _ := pCreateDIBSection.Call(screen, uintptr(unsafe.Pointer(&bmiV)), 0,
uintptr(unsafe.Pointer(&bitsV)), 0, 0) // Turn a quarter turn, then put the icons and symbols back on upright.
if bmpV == 0 || bitsV == nil { fw, fh := h, w
return nil bmiV := bitmapInfoHeader{Width: fw, Height: -fh, Planes: 1, BitCount: 32}
} bmiV.Size = uint32(unsafe.Sizeof(bmiV))
defer pDeleteObject.Call(bmpV) var bitsV unsafe.Pointer
memV, _, _ := pCreateCompatibleDC.Call(screen) bmpV, _, _ := pCreateDIBSection.Call(screen, uintptr(unsafe.Pointer(&bmiV)), 0,
defer pDeleteDC.Call(memV) uintptr(unsafe.Pointer(&bitsV)), 0, 0)
oldV, _, _ := pSelectObject.Call(memV, bmpV) if bmpV == 0 || bitsV == nil {
defer pSelectObject.Call(memV, oldV) return nil
}
dst := unsafe.Slice((*uint32)(bitsV), int(w)*int(h)) defer pDeleteObject.Call(bmpV)
for y := int32(0); y < h; y++ { memV, _, _ := pCreateCompatibleDC.Call(screen)
for x := int32(0); x < w; x++ { defer pDeleteDC.Call(memV)
dst[int(x)*int(fw)+int(h-1-y)] = src[int(y)*int(w)+int(x)] oldV, _, _ := pSelectObject.Call(memV, bmpV)
} defer pSelectObject.Call(memV, oldV)
}
if fg { dst := unsafe.Slice((*uint32)(bitsV), int(w)*int(h))
for i, r := range appRects(w, h) { for y := int32(0); y < h; y++ {
if i < len(apps) { for x := int32(0); x < w; x++ {
drawAppGlyph(memV, mapRect(rect{r.Left + px(2), r.Top + px(3), r.Right - px(2), r.Bottom - px(3)}, h), apps[i]) dst[int(x)*int(fw)+int(h-1-y)] = src[int(y)*int(w)+int(x)]
} }
} }
for _, it := range trayItems(w, h) { if fg {
r := mapRect(it.r, h) if logoStyle != 0 {
switch it.kind { drawLogoStyle(memV, mapRect(sr, h))
case trayBattery: }
drawBattery(memV, r) for i, r := range appRects(w, h) {
case trayVolume: if i < len(apps) {
drawVolume(memV, r) drawAppGlyph(memV, mapRect(rect{r.Left + px(2), r.Top + px(3), r.Right - px(2), r.Bottom - px(3)}, h), apps[i])
case trayWifi: }
drawNetwork(memV, r) }
case trayChevron: for _, it := range trayItems(w, h) {
drawChevron(memV, r) r := mapRect(it.r, h)
case trayWeather: switch it.kind {
drawWeatherIcon(memV, r) case trayBattery:
case trayNews: drawBattery(memV, r)
drawNewsIcon(memV, r) case trayVolume:
case traySys: drawVolume(memV, r)
drawSysIcon(memV, r) case trayWifi:
case trayGM: drawNetwork(memV, r)
drawGMIcon(memV, r) case trayChevron:
} drawChevron(memV, r)
} case trayWeather:
pGdiFlush.Call() drawWeatherIcon(memV, r)
} case trayNews:
out := make([]uint32, len(dst)) drawNewsIcon(memV, r)
copy(out, dst) case traySys:
return out drawSysIcon(memV, r)
} case trayGM:
drawGMIcon(memV, r)
// avg4 averages the superSample x superSample block of pixels that makes up }
// one real pixel, one color channel at a time. }
func avg4(p []uint32, stride, x, y int) (r, g, b uint32) { pGdiFlush.Call()
var sr, sg, sb uint32 }
for dy := 0; dy < superSample; dy++ { out := make([]uint32, len(dst))
for dx := 0; dx < superSample; dx++ { copy(out, dst)
c := p[(y*superSample+dy)*stride+x*superSample+dx] return out
sr += c >> 16 & 0xFF }
sg += c >> 8 & 0xFF
sb += c & 0xFF // avg4 averages the superSample x superSample block of pixels that makes up
} // one real pixel, one color channel at a time.
} func avg4(p []uint32, stride, x, y int) (r, g, b uint32) {
n := uint32(superSample * superSample) var sr, sg, sb uint32
return sr / n, sg / n, sb / n for dy := 0; dy < superSample; dy++ {
} for dx := 0; dx < superSample; dx++ {
c := p[(y*superSample+dy)*stride+x*superSample+dx]
// redraw paints the whole bar and hands it to Windows as a layered window sr += c >> 16 & 0xFF
// with a transparency value for every pixel. sg += c >> 8 & 0xFF
func redraw(hwnd uintptr) { sb += c & 0xFF
if hwnd == 0 { }
return }
} n := uint32(superSample * superSample)
// Shrink or grow the pill to fit what is in it, staying centered where it is. return sr / n, sg / n, sb / n
pw, ph := pillSize() }
var crc rect
pGetClientRect.Call(hwnd, uintptr(unsafe.Pointer(&crc))) // redraw paints the whole bar and hands it to Windows as a layered window
if (crc.Right != pw || crc.Bottom != ph) && !dragging { // with a transparency value for every pixel.
x, y := pillPos(pw, ph) func redraw(hwnd uintptr) {
pMoveWindow.Call(hwnd, uintptr(x), uintptr(y), uintptr(pw), uintptr(ph), 0) if hwnd == 0 {
} return
w, h := clientSize(hwnd) }
if w <= 0 || h <= 0 { // Shrink or grow the pill to fit what is in it, staying centered where it is.
return pw, ph := pillSize()
} var crc rect
fw, fh := w, h pGetClientRect.Call(hwnd, uintptr(unsafe.Pointer(&crc)))
if vertical { if (crc.Right != pw || crc.Bottom != ph) && !dragging {
fw, fh = h, w x, y := pillPos(pw, ph)
} pMoveWindow.Call(hwnd, uintptr(x), uintptr(y), uintptr(pw), uintptr(ph), 0)
}
screen, _, _ := pGetDC.Call(0) w, h := clientSize(hwnd)
defer pReleaseDC.Call(0, screen) if w <= 0 || h <= 0 {
return
// Layer 1: backgrounds, at real size. }
bgPix := renderLayer(screen, w, h, true, false, rgb(22, 22, 26)) fw, fh := w, h
if vertical {
// Layers 2 and 3: icons, text and symbols on black and on white, at double size. fw, fh = h, w
savedScale, savedTime, savedApp := scale, fontTime, fontApp }
scale *= superSample
fontTime, fontApp = fontTime2, fontApp2 screen, _, _ := pGetDC.Call(0)
onBlack := renderLayer(screen, w*superSample, h*superSample, false, true, rgb(0, 0, 0)) defer pReleaseDC.Call(0, screen)
onWhite := renderLayer(screen, w*superSample, h*superSample, false, true, rgb(255, 255, 255))
scale, fontTime, fontApp = savedScale, savedTime, savedApp // Layer 1: backgrounds, at real size.
bgPix := renderLayer(screen, w, h, true, false, rgb(22, 22, 26))
n := int(fw) * int(fh)
if len(bgPix) != n || len(onBlack) != n*superSample*superSample || len(onWhite) != len(onBlack) { // Layers 2 and 3: icons, text and symbols on black and on white, at double size.
return savedScale, savedTime, savedApp := scale, fontTime, fontApp
} scale *= superSample
fontTime, fontApp = fontTime2, fontApp2
// The finished bitmap that Windows will show. onBlack := renderLayer(screen, w*superSample, h*superSample, false, true, rgb(0, 0, 0))
mem, _, _ := pCreateCompatibleDC.Call(screen) onWhite := renderLayer(screen, w*superSample, h*superSample, false, true, rgb(255, 255, 255))
defer pDeleteDC.Call(mem) scale, fontTime, fontApp = savedScale, savedTime, savedApp
bmi := bitmapInfoHeader{Width: fw, Height: -fh, Planes: 1, BitCount: 32}
bmi.Size = uint32(unsafe.Sizeof(bmi)) n := int(fw) * int(fh)
var bits unsafe.Pointer if len(bgPix) != n || len(onBlack) != n*superSample*superSample || len(onWhite) != len(onBlack) {
bmp, _, _ := pCreateDIBSection.Call(screen, uintptr(unsafe.Pointer(&bmi)), 0, return
uintptr(unsafe.Pointer(&bits)), 0, 0) }
if bmp == 0 || bits == nil {
return // The finished bitmap that Windows will show.
} mem, _, _ := pCreateCompatibleDC.Call(screen)
defer pDeleteObject.Call(bmp) defer pDeleteDC.Call(mem)
old, _, _ := pSelectObject.Call(mem, bmp) bmi := bitmapInfoHeader{Width: fw, Height: -fh, Planes: 1, BitCount: 32}
defer pSelectObject.Call(mem, old) bmi.Size = uint32(unsafe.Sizeof(bmi))
pix := unsafe.Slice((*uint32)(bits), n) var bits unsafe.Pointer
bmp, _, _ := pCreateDIBSection.Call(screen, uintptr(unsafe.Pointer(&bmi)), 0,
a := uint32(bgAlpha) uintptr(unsafe.Pointer(&bits)), 0, 0)
hoverA := max(a, 120) if bmp == 0 || bits == nil {
length := float64(max(fw, fh)) return
rad := float64(min(fw, fh)) / 2 }
stride := int(fw) * superSample defer pDeleteObject.Call(bmp)
old, _, _ := pSelectObject.Call(mem, bmp)
for i := range pix { defer pSelectObject.Call(mem, old)
x, y := i%int(fw), i/int(fw) pix := unsafe.Slice((*uint32)(bits), n)
// Background layer: the pill color or a hover highlight, at its own see-through level. a := uint32(bgAlpha)
c := bgPix[i] & 0x00FFFFFF hoverA := max(a, 120)
bgA := a barC := barRGB()
if c != colBg { lightBar := barIsLight()
bgA = hoverA length := float64(max(fw, fh))
} rad := float64(min(fw, fh)) / 2
bgR := (c >> 16 & 0xFF) * bgA / 255 stride := int(fw) * superSample
bgG := (c >> 8 & 0xFF) * bgA / 255
bgB := (c & 0xFF) * bgA / 255 for i := range pix {
x, y := i%int(fw), i/int(fw)
// Foreground: how solid is this pixel, and what color is it.
br, bgn, bb := avg4(onBlack, stride, x, y) // Background layer: the pill color or a hover highlight, at its own see-through level.
wr, wg, wb := avg4(onWhite, stride, x, y) c := bgPix[i] & 0x00FFFFFF
d := (sub0(wr, br) + sub0(wg, bgn) + sub0(wb, bb)) / 3 bgA := a
fa := 255 - min(d, 255) // 255 where the two copies match (solid), 0 where they differ fully if c != colBg {
fr, fg, fb := min(br, fa), min(bgn, fa), min(bb, fa) bgA = hoverA
c = hoverTint(c, lightBar)
// Foreground over background. } else {
inv := 255 - fa c = barC
oa := fa + bgA*inv/255 }
or := fr + bgR*inv/255 bgR := (c >> 16 & 0xFF) * bgA / 255
og := fg + bgG*inv/255 bgG := (c >> 8 & 0xFF) * bgA / 255
ob := fb + bgB*inv/255 bgB := (c & 0xFF) * bgA / 255
// Rounded ends: how much of this pixel is inside the pill. // Foreground: how solid is this pixel, and what color is it.
along := float64(x) + 0.5 br, bgn, bb := avg4(onBlack, stride, x, y)
across := float64(y) + 0.5 wr, wg, wb := avg4(onWhite, stride, x, y)
if vertical { d := (sub0(wr, br) + sub0(wg, bgn) + sub0(wb, bb)) / 3
along, across = across, along fa := 255 - min(d, 255) // 255 where the two copies match (solid), 0 where they differ fully
} fr, fg, fb := min(br, fa), min(bgn, fa), min(bb, fa)
da := 0.0
if along < rad { // Foreground over background.
da = rad - along inv := 255 - fa
} else if along > length-rad { oa := fa + bgA*inv/255
da = along - (length - rad) or := fr + bgR*inv/255
} og := fg + bgG*inv/255
cov := math.Max(0, math.Min(1, rad-math.Hypot(da, across-rad)+0.5)) ob := fb + bgB*inv/255
sc := func(v uint32) uint32 { return uint32(float64(v) * cov) }
pix[i] = sc(oa)<<24 | sc(or)<<16 | sc(og)<<8 | sc(ob) // Rounded ends: how much of this pixel is inside the pill.
} along := float64(x) + 0.5
across := float64(y) + 0.5
var wr rect if vertical {
pGetWindowRect.Call(hwnd, uintptr(unsafe.Pointer(&wr))) along, across = across, along
dst := point{wr.Left, wr.Top} }
sz := size{fw, fh} da := 0.0
src := point{0, 0} if along < rad {
blend := blendFunction{Op: 0, Flags: 0, Alpha: 255, Format: 1} // AC_SRC_OVER, AC_SRC_ALPHA da = rad - along
pUpdateLayeredWindow.Call(hwnd, screen, } else if along > length-rad {
uintptr(unsafe.Pointer(&dst)), uintptr(unsafe.Pointer(&sz)), da = along - (length - rad)
mem, uintptr(unsafe.Pointer(&src)), 0, }
uintptr(unsafe.Pointer(&blend)), ulwAlpha) cov := math.Max(0, math.Min(1, rad-math.Hypot(da, across-rad)+0.5))
} sc := func(v uint32) uint32 { return uint32(float64(v) * cov) }
pix[i] = sc(oa)<<24 | sc(or)<<16 | sc(og)<<8 | sc(ob)
func sub0(a, b uint32) uint32 { }
if a > b {
return a - b var wr rect
} pGetWindowRect.Call(hwnd, uintptr(unsafe.Pointer(&wr)))
return 0 dst := point{wr.Left, wr.Top}
} sz := size{fw, fh}
src := point{0, 0}
blend := blendFunction{Op: 0, Flags: 0, Alpha: 255, Format: 1} // AC_SRC_OVER, AC_SRC_ALPHA
pUpdateLayeredWindow.Call(hwnd, screen,
uintptr(unsafe.Pointer(&dst)), uintptr(unsafe.Pointer(&sz)),
mem, uintptr(unsafe.Pointer(&src)), 0,
uintptr(unsafe.Pointer(&blend)), ulwAlpha)
}
func sub0(a, b uint32) uint32 {
if a > b {
return a - b
}
return 0
}