package main // Drawing the radar picture inside the weather panel, and stepping the loop. import ( "unsafe" ) var ( pStretchDIBits = gdi32.NewProc("StretchDIBits") pSetViewportOrgEx = gdi32.NewProc("SetViewportOrgEx") ) // wxRadarFits reports whether the panel with its radar picture fits on the // screen, with some room left for the bar. On a small or heavily scaled screen // the radar is left out and the rest of the panel stays as it was. func wxRadarFits() bool { _, sh := screenSize() return px(wxFullH+wxRadarH) <= sh-px(90) } // radarAdvance moves the loop to its next frame. The newest frame is held for a // few beats before it starts over. func radarAdvance() { if !wxShown || !wxRadarFits() { return } rs := radarSnapshot() n := len(rs.frames) if n < 2 { return } rdIdx %= n if rdIdx == n-1 && rdHold < 3 { rdHold++ return } rdHold = 0 rdIdx = (rdIdx + 1) % n flyRefresh(wxHwnd) } func radarBox(hdc uintptr, r rect) { t := px(1) fillRaw(hdc, rect{r.Left, r.Top, r.Right, r.Top + t}, colRule) fillRaw(hdc, rect{r.Left, r.Bottom - t, r.Right, r.Bottom}, colRule) fillRaw(hdc, rect{r.Left, r.Top, r.Left + t, r.Bottom}, colRule) fillRaw(hdc, rect{r.Right - t, r.Top, r.Right, r.Bottom}, colRule) } // radarDraw paints the radar picture (or a short message while there isn't one) // into the rectangle r. The panel is painted at double size, so px() here is // already the double size distance. func radarDraw(hdc uintptr, r rect) { rs := radarSnapshot() w, h := r.Right-r.Left, r.Bottom-r.Top if len(rs.frames) == 0 { fillRaw(hdc, r, rgb(22, 22, 27)) msg := "Loading radar..." if rs.err != "" { msg = rs.err } wxText(hdc, msg, r, fText, colDim, dtCenter|dtVCenter|dtSingleLine) radarBox(hdc, r) return } i := rdIdx % len(rs.frames) bmi := bitmapInfoHeader{Width: radarW, Height: -radarH, Planes: 1, BitCount: 32} bmi.Size = uint32(unsafe.Sizeof(bmi)) pSetStretchBltMode.Call(hdc, halftone) pSetBrushOrgEx.Call(hdc, 0, 0, 0) pStretchDIBits.Call(hdc, uintptr(r.Left), uintptr(r.Top), uintptr(w), uintptr(h), 0, 0, radarW, radarH, uintptr(unsafe.Pointer(&rs.frames[i][0])), uintptr(unsafe.Pointer(&bmi)), 0, srcCopy) // You are here. cx, cy := center(r) circleRaw(hdc, cx, cy, px(5), rgb(245, 245, 245)) circleRaw(hdc, cx, cy, px(3), rgb(235, 70, 70)) // When this frame is from. back := rgb(22, 22, 27) label := "Radar" if i < len(rs.times) { label += " " + rs.times[i].Format("3:04 PM") } fillRaw(hdc, rect{r.Left, r.Top, r.Left + px(104), r.Top + px(19)}, back) wxText(hdc, label, rect{r.Left + px(6), r.Top, r.Left + px(104), r.Top + px(19)}, fSmall, colText, dtLeft|dtVCenter|dtSingleLine) // Where the pictures come from. fillRaw(hdc, rect{r.Right - px(92), r.Bottom - px(14), r.Right, r.Bottom}, back) wxText(hdc, "RainViewer, Esri", rect{r.Right - px(92), r.Bottom - px(14), r.Right - px(4), r.Bottom}, fTiny, colDim, dtRight|dtVCenter|dtSingleLine) radarBox(hdc, r) }