Smooth edges, logo/clock/tray colors, hidden icons fix
This commit is contained in:
@@ -22,7 +22,6 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"math"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
@@ -677,10 +676,30 @@ func appIndexAt(hwnd uintptr, x int32) int {
|
||||
return -1
|
||||
}
|
||||
|
||||
// The bar is painted in layers (see render.go): one layer holds only the
|
||||
// backgrounds and hover fills, another only the icons, text and symbols.
|
||||
var layerFills, layerFg = true, true
|
||||
|
||||
// fill paints a background or hover rectangle (background layer only).
|
||||
func fill(hdc uintptr, r rect, color uintptr) {
|
||||
b, _, _ := pCreateSolidBrush.Call(color)
|
||||
pFillRect.Call(hdc, uintptr(unsafe.Pointer(&r)), b)
|
||||
pDeleteObject.Call(b)
|
||||
if layerFills {
|
||||
fillRaw(hdc, r, color)
|
||||
}
|
||||
}
|
||||
|
||||
// fillFg paints a solid piece of a symbol (foreground layer only).
|
||||
func fillFg(hdc uintptr, r rect, color uintptr) {
|
||||
if layerFg {
|
||||
fillRaw(hdc, r, color)
|
||||
}
|
||||
}
|
||||
|
||||
func fillRaw(hdc uintptr, r rect, color uintptr) {
|
||||
{
|
||||
b, _, _ := pCreateSolidBrush.Call(color)
|
||||
pFillRect.Call(hdc, uintptr(unsafe.Pointer(&r)), b)
|
||||
pDeleteObject.Call(b)
|
||||
}
|
||||
}
|
||||
|
||||
func drawTextFmt(hdc uintptr, s string, r rect, format uintptr) {
|
||||
@@ -707,17 +726,17 @@ func drawLogo(hdc uintptr, r rect) {
|
||||
total := sq*2 + gap
|
||||
x := r.Left + (r.Right-r.Left-total)/2
|
||||
y := r.Top + (r.Bottom-r.Top-total)/2
|
||||
c := rgb(0, 120, 212)
|
||||
fill(hdc, rect{x, y, x + sq, y + sq}, c)
|
||||
fill(hdc, rect{x + sq + gap, y, x + total, y + sq}, c)
|
||||
fill(hdc, rect{x, y + sq + gap, x + sq, y + total}, c)
|
||||
fill(hdc, rect{x + sq + gap, y + sq + gap, x + total, y + total}, c)
|
||||
c := logoColor()
|
||||
fillFg(hdc, rect{x, y, x + sq, y + sq}, c)
|
||||
fillFg(hdc, rect{x + sq + gap, y, x + total, y + sq}, c)
|
||||
fillFg(hdc, rect{x, y + sq + gap, x + sq, y + total}, c)
|
||||
fillFg(hdc, rect{x + sq + gap, y + sq + gap, x + total, y + total}, c)
|
||||
}
|
||||
|
||||
func drawClock(hdc uintptr, r rect) {
|
||||
now := time.Now()
|
||||
pSetBkMode.Call(hdc, transparent)
|
||||
pSetTextColor.Call(hdc, rgb(245, 245, 245))
|
||||
pSetTextColor.Call(hdc, clockColor())
|
||||
// Time and date on one line, like "11:32 PM 11/5/2026".
|
||||
old, _, _ := pSelectObject.Call(hdc, fontTime)
|
||||
drawText(hdc, now.Format("3:04 PM 1/2/2006"), r)
|
||||
@@ -744,7 +763,7 @@ func drawApps(hdc uintptr, w, h int32) {
|
||||
fill(hdc, inner, rgb(40, 40, 48))
|
||||
}
|
||||
|
||||
if !vertical {
|
||||
if !vertical && layerFg {
|
||||
drawAppGlyph(hdc, inner, a)
|
||||
}
|
||||
}
|
||||
@@ -773,152 +792,6 @@ func premul(c uint32, a uint32) uint32 {
|
||||
return a<<24 | r<<16 | g<<8 | b
|
||||
}
|
||||
|
||||
// redraw paints the whole bar into a 32 bit bitmap, sets each pixel's
|
||||
// transparency (background pixels get the chosen see-through level, everything
|
||||
// drawn on top stays solid) and hands it to Windows as a layered window.
|
||||
// A vertical bar is drawn horizontally first and then turned a quarter turn;
|
||||
// the icons and symbols are then drawn again upright on top.
|
||||
func redraw(hwnd uintptr) {
|
||||
if hwnd == 0 {
|
||||
return
|
||||
}
|
||||
// Shrink or grow the pill to fit what is in it, staying centered where it is.
|
||||
pw, ph := pillSize()
|
||||
var crc rect
|
||||
pGetClientRect.Call(hwnd, uintptr(unsafe.Pointer(&crc)))
|
||||
if (crc.Right != pw || crc.Bottom != ph) && !dragging {
|
||||
x, y := pillPos(pw, ph)
|
||||
pMoveWindow.Call(hwnd, uintptr(x), uintptr(y), uintptr(pw), uintptr(ph), 0)
|
||||
}
|
||||
w, h := clientSize(hwnd)
|
||||
if w <= 0 || h <= 0 {
|
||||
return
|
||||
}
|
||||
|
||||
screen, _, _ := pGetDC.Call(0)
|
||||
defer pReleaseDC.Call(0, screen)
|
||||
mem, _, _ := pCreateCompatibleDC.Call(screen)
|
||||
defer pDeleteDC.Call(mem)
|
||||
|
||||
bmi := bitmapInfoHeader{Width: w, Height: -h, Planes: 1, BitCount: 32}
|
||||
bmi.Size = uint32(unsafe.Sizeof(bmi))
|
||||
var bits unsafe.Pointer
|
||||
bmp, _, _ := pCreateDIBSection.Call(screen, 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)
|
||||
|
||||
rc := rect{0, 0, w, h}
|
||||
fill(mem, rc, rgb(22, 22, 26))
|
||||
cx := w / 2
|
||||
sr := rect{cx - startWidth(), 0, cx, h}
|
||||
if hoverStart {
|
||||
fill(mem, sr, rgb(58, 58, 68))
|
||||
}
|
||||
drawLogo(mem, sr)
|
||||
drawApps(mem, w, h)
|
||||
drawTray(mem, w, h)
|
||||
pGdiFlush.Call()
|
||||
|
||||
// The finished picture: same as above for a horizontal bar.
|
||||
fmem, fbits, fw, fh := mem, bits, w, h
|
||||
if vertical {
|
||||
fw, fh = h, w
|
||||
bmiV := bitmapInfoHeader{Width: fw, Height: -fh, Planes: 1, BitCount: 32}
|
||||
bmiV.Size = uint32(unsafe.Sizeof(bmiV))
|
||||
var bitsV unsafe.Pointer
|
||||
bmpV, _, _ := pCreateDIBSection.Call(screen, uintptr(unsafe.Pointer(&bmiV)), 0,
|
||||
uintptr(unsafe.Pointer(&bitsV)), 0, 0)
|
||||
if bmpV == 0 || bitsV == nil {
|
||||
return
|
||||
}
|
||||
defer pDeleteObject.Call(bmpV)
|
||||
memV, _, _ := pCreateCompatibleDC.Call(screen)
|
||||
defer pDeleteDC.Call(memV)
|
||||
oldV, _, _ := pSelectObject.Call(memV, bmpV)
|
||||
defer pSelectObject.Call(memV, oldV)
|
||||
|
||||
src := unsafe.Slice((*uint32)(bits), int(w)*int(h))
|
||||
dst := unsafe.Slice((*uint32)(bitsV), int(w)*int(h))
|
||||
for y := int32(0); y < h; y++ {
|
||||
for x := int32(0); x < w; x++ {
|
||||
dst[int(x)*int(fw)+int(h-1-y)] = src[int(y)*int(w)+int(x)]
|
||||
}
|
||||
}
|
||||
// Icons and symbols go back on upright.
|
||||
for i, r := range appRects(w, h) {
|
||||
if i < len(apps) {
|
||||
drawAppGlyph(memV, mapRect(rect{r.Left + px(2), r.Top + px(3), r.Right - px(2), r.Bottom - px(3)}, h), apps[i])
|
||||
}
|
||||
}
|
||||
for _, it := range trayItems(w, h) {
|
||||
r := mapRect(it.r, h)
|
||||
switch it.kind {
|
||||
case trayBattery:
|
||||
drawBattery(memV, r)
|
||||
case trayVolume:
|
||||
drawVolume(memV, r)
|
||||
case trayWifi:
|
||||
drawNetwork(memV, r)
|
||||
case trayChevron:
|
||||
drawChevron(memV, r)
|
||||
}
|
||||
}
|
||||
pGdiFlush.Call()
|
||||
fmem, fbits = memV, bitsV
|
||||
}
|
||||
|
||||
pix := unsafe.Slice((*uint32)(fbits), int(fw)*int(fh))
|
||||
a := uint32(bgAlpha)
|
||||
hoverA := max(a, 120)
|
||||
activeA := max(a, 150)
|
||||
length := float64(max(fw, fh))
|
||||
rad := float64(min(fw, fh)) / 2
|
||||
for i, p := range pix {
|
||||
c := p & 0x00FFFFFF
|
||||
// Pill shape: how much of this pixel is inside the rounded ends.
|
||||
along := float64(i%int(fw)) + 0.5
|
||||
across := float64(i/int(fw)) + 0.5
|
||||
if vertical {
|
||||
along, across = across, along
|
||||
}
|
||||
da := 0.0
|
||||
if along < rad {
|
||||
da = rad - along
|
||||
} else if along > length-rad {
|
||||
da = along - (length - rad)
|
||||
}
|
||||
cov := rad - math.Hypot(da, across-rad) + 0.5
|
||||
cov = math.Max(0, math.Min(1, cov))
|
||||
sc := func(v uint32) uint32 { return uint32(float64(v) * cov) }
|
||||
switch c {
|
||||
case colBg:
|
||||
pix[i] = premul(c, sc(a))
|
||||
case colHStart, colHApp:
|
||||
pix[i] = premul(c, sc(hoverA))
|
||||
case colActive:
|
||||
pix[i] = premul(c, sc(activeA))
|
||||
default:
|
||||
pix[i] = premul(c, sc(255))
|
||||
}
|
||||
}
|
||||
|
||||
var wr rect
|
||||
pGetWindowRect.Call(hwnd, uintptr(unsafe.Pointer(&wr)))
|
||||
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)),
|
||||
fmem, uintptr(unsafe.Pointer(&src)), 0,
|
||||
uintptr(unsafe.Pointer(&blend)), ulwAlpha)
|
||||
}
|
||||
|
||||
func inStart(hwnd uintptr, x int32) bool {
|
||||
w, _ := clientSize(hwnd)
|
||||
cx := w / 2
|
||||
@@ -1029,6 +902,8 @@ func showMenu(hwnd uintptr, appIdx int, trayKind int) {
|
||||
add(flags, uintptr(menuLevelBase+i), "Background: "+l.name)
|
||||
}
|
||||
sep()
|
||||
addColorMenus(menu)
|
||||
sep()
|
||||
orientText := "Switch to vertical"
|
||||
if vertical {
|
||||
orientText = "Switch to horizontal"
|
||||
@@ -1067,6 +942,8 @@ func showMenu(hwnd uintptr, appIdx int, trayKind int) {
|
||||
pDestroyWindow.Call(hwnd)
|
||||
case cmd == menuResetPosID:
|
||||
resetPos(hwnd)
|
||||
case handleColorCommand(cmd):
|
||||
redraw(hwnd)
|
||||
case cmd == menuOrientID:
|
||||
vertical = !vertical
|
||||
saveOrient()
|
||||
@@ -1281,6 +1158,8 @@ func main() {
|
||||
fontTime = makeFont(px(13), 400)
|
||||
fontDate = makeFont(px(11), 400)
|
||||
fontApp = makeFont(px(12), 600)
|
||||
initSuperFonts()
|
||||
loadColors()
|
||||
|
||||
autoQuit = autoQuitDef
|
||||
if hasArg("--forever") || strings.Contains(name, "forever") {
|
||||
|
||||
Reference in New Issue
Block a user