MirrorBar+ part 1: weather radar, outline color, show/hide switches, README
This commit is contained in:
@@ -26,9 +26,11 @@ var (
|
||||
const (
|
||||
wxLayoutW = 340.0 // panel width, in 96 dpi units
|
||||
wxFullH = 428.0 // panel height when there is a forecast to show
|
||||
wxRadarH = 158.0 // extra height when the radar picture fits on the screen
|
||||
wxShortH = 150.0 // panel height for the "add a ZIP code" and error messages
|
||||
|
||||
wxPollTimerID = 1
|
||||
wxAnimTimerID = 2
|
||||
vkRButton = 0x02
|
||||
srcCopy = 0x00CC0020
|
||||
halftone = 4
|
||||
@@ -41,8 +43,10 @@ var (
|
||||
wxShown bool
|
||||
wxPrevBtn bool // a mouse button was down at the last look
|
||||
|
||||
wxFontsMade bool
|
||||
fBig, fMed, fText, fBold, fSmall uintptr
|
||||
wxFontsMade bool
|
||||
fBig, fMed, fText, fBold, fSmall, fTiny uintptr
|
||||
|
||||
rdHold int // how many beats the newest radar frame has been held for
|
||||
)
|
||||
|
||||
// ---------- the button on the bar ----------
|
||||
@@ -125,6 +129,10 @@ func weatherProc(hwnd, m, wparam, lparam uintptr) (result uintptr) {
|
||||
wxPaint(hwnd)
|
||||
return 0
|
||||
case wmTimer:
|
||||
if wparam == wxAnimTimerID {
|
||||
radarAdvance()
|
||||
return 0
|
||||
}
|
||||
weatherPoll()
|
||||
return 0
|
||||
case wmLButtonUp:
|
||||
@@ -141,15 +149,19 @@ func weatherToggle() {
|
||||
weatherHide()
|
||||
return
|
||||
}
|
||||
if wxHwnd == 0 {
|
||||
if wxHwnd == 0 || !showWeather {
|
||||
return
|
||||
}
|
||||
previewHide()
|
||||
newsHide() // one panel at a time
|
||||
sysHide()
|
||||
weatherRefresh(false)
|
||||
wxShown = true
|
||||
wxPrevBtn = true // ignore a button that is still held from the click that opened this
|
||||
weatherPlace()
|
||||
pSetTimer.Call(wxHwnd, wxPollTimerID, 80, 0)
|
||||
pSetTimer.Call(wxHwnd, wxAnimTimerID, 450, 0)
|
||||
radarEnsure(false)
|
||||
}
|
||||
|
||||
func weatherHide() {
|
||||
@@ -158,6 +170,7 @@ func weatherHide() {
|
||||
}
|
||||
wxShown = false
|
||||
pKillTimer.Call(wxHwnd, wxPollTimerID)
|
||||
pKillTimer.Call(wxHwnd, wxAnimTimerID)
|
||||
pShowWindow.Call(wxHwnd, swHide)
|
||||
}
|
||||
|
||||
@@ -170,21 +183,7 @@ func weatherShutdown() {
|
||||
}
|
||||
|
||||
// weatherAnchor is where the cloud sits on the screen.
|
||||
func weatherAnchor() rect {
|
||||
var wr rect
|
||||
pGetWindowRect.Call(hwndMain, uintptr(unsafe.Pointer(&wr)))
|
||||
w, h := clientSize(hwndMain)
|
||||
for _, it := range trayItems(w, h) {
|
||||
if it.kind == trayWeather {
|
||||
r := it.r
|
||||
if vertical {
|
||||
r = mapRect(r, h)
|
||||
}
|
||||
return rect{wr.Left + r.Left, wr.Top + r.Top, wr.Left + r.Right, wr.Top + r.Bottom}
|
||||
}
|
||||
}
|
||||
return wr
|
||||
}
|
||||
func weatherAnchor() rect { return trayAnchor(trayWeather) }
|
||||
|
||||
// weatherPlace sizes the panel for what it has to show and puts it next to the
|
||||
// cloud: above a horizontal bar, to the left of a vertical one.
|
||||
@@ -196,6 +195,9 @@ func weatherPlace() {
|
||||
lh := wxShortH
|
||||
if s.ok && wxZip != "" {
|
||||
lh = wxFullH
|
||||
if wxRadarFits() {
|
||||
lh += wxRadarH
|
||||
}
|
||||
}
|
||||
cw, ch := px(wxLayoutW), px(lh)
|
||||
|
||||
@@ -257,8 +259,10 @@ func weatherClick() {
|
||||
|
||||
// weatherDone runs when a lookup finishes.
|
||||
func weatherDone() {
|
||||
newsDone()
|
||||
if wxShown {
|
||||
weatherPlace()
|
||||
radarEnsure(false)
|
||||
}
|
||||
settingsZipStatusUpdate()
|
||||
}
|
||||
@@ -292,10 +296,15 @@ func wxMakeFonts() {
|
||||
fText = makeFont(px(13), 400)
|
||||
fBold = makeFont(px(13), 600)
|
||||
fSmall = makeFont(px(11), 400)
|
||||
fTiny = makeFont(px(9), 400)
|
||||
wxFontsMade = true
|
||||
}
|
||||
|
||||
func wxPaint(hwnd uintptr) {
|
||||
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.
|
||||
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)))
|
||||
@@ -325,7 +334,7 @@ func wxPaint(hwnd uintptr) {
|
||||
defer func() { scale = saved }()
|
||||
scale *= ss
|
||||
wxMakeFonts()
|
||||
wxDraw(mem, W*ss, H*ss)
|
||||
draw(mem, W*ss, H*ss)
|
||||
scale = saved
|
||||
|
||||
pSetStretchBltMode.Call(hdc, halftone)
|
||||
@@ -335,7 +344,6 @@ func wxPaint(hwnd uintptr) {
|
||||
|
||||
var (
|
||||
colBack = rgb(28, 28, 34)
|
||||
colEdge = rgb(78, 78, 92)
|
||||
colRule = rgb(52, 52, 62)
|
||||
colText = rgb(240, 240, 245)
|
||||
colDim = rgb(150, 150, 165)
|
||||
@@ -354,7 +362,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}, colEdge)
|
||||
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)
|
||||
|
||||
pad := u(14)
|
||||
@@ -431,6 +439,15 @@ func wxDraw(hdc uintptr, W, H int32) {
|
||||
cell(2, 1, "UV index", strconv.Itoa(int(math.Round(today.uv))))
|
||||
rule(u(218))
|
||||
|
||||
// Radar, when the panel is tall enough to have room for it. Everything below it
|
||||
// is drawn the same way, just moved down.
|
||||
if H >= u(wxFullH+wxRadarH-1) {
|
||||
radarDraw(hdc, rect{pad, u(226), W - pad, u(226) + u(150)})
|
||||
rule(u(382))
|
||||
pSetViewportOrgEx.Call(hdc, 0, uintptr(u(wxRadarH)), 0)
|
||||
defer pSetViewportOrgEx.Call(hdc, 0, 0, 0)
|
||||
}
|
||||
|
||||
// Moon.
|
||||
moon := moonAt(time.Now())
|
||||
wxMoonDraw(hdc, pad+u(24), u(254), u(22), moon, s.lat >= 0)
|
||||
|
||||
Reference in New Issue
Block a user