From aca4e2c08c28b10fdd7f699bb4a9357e18efe00b Mon Sep 17 00:00:00 2001 From: Moritz Biering Date: Thu, 27 May 2021 15:15:02 +0200 Subject: [PATCH] Add support for big clock widgets --- widget.go | 5 ++++- widget_clock.go | 53 +++++++++++++++++++++++++++++++++++-------------- 2 files changed, 42 insertions(+), 16 deletions(-) diff --git a/widget.go b/widget.go index 43e19d0..532eccd 100644 --- a/widget.go +++ b/widget.go @@ -65,7 +65,10 @@ func NewWidget(index uint8, id string, action *ActionConfig, actionHold *ActionC } case "clock": - return &ClockWidget{bw} + return &ClockWidget{ + BaseWidget: bw, + mode: config["mode"], + } case "date": return &DateWidget{bw} diff --git a/widget_clock.go b/widget_clock.go index 4ff366a..2046f0d 100644 --- a/widget_clock.go +++ b/widget_clock.go @@ -10,6 +10,7 @@ import ( type ClockWidget struct { BaseWidget + mode string } func (w *ClockWidget) Update(dev *streamdeck.Device) { @@ -18,27 +19,49 @@ func (w *ClockWidget) Update(dev *streamdeck.Device) { img := image.NewRGBA(image.Rect(0, 0, size, size)) height := size - (margin * 2) pt := (float64(height) / 3.0) * 72.0 / float64(dev.DPI) + ptfull := float64(height) * 72.0 / float64(dev.DPI) t := time.Now() hour := t.Format("15") min := t.Format("04") sec := t.Format("05") - drawString(img, image.Rectangle{image.Pt(0, margin), image.Pt(size, margin+(height/3))}, - ttfBoldFont, - hour, - pt, - image.Pt(-1, -1)) - drawString(img, image.Rectangle{image.Pt(0, (height/3)+margin), image.Pt(size, margin+(height/3)*2)}, - ttfFont, - min, - pt, - image.Pt(-1, -1)) - drawString(img, image.Rectangle{image.Pt(0, (height/3)*2+margin), image.Pt(size, margin+height)}, - ttfThinFont, - sec, - pt, - image.Pt(-1, -1)) + switch w.mode { + case "hour": + drawString(img, image.Rect(0, 0, size, size), + ttfBoldFont, + hour, + ptfull, + image.Pt(-1, -1)) + case "min": + drawString(img, image.Rect(0, 0, size, size), + ttfFont, + min, + ptfull, + image.Pt(-1, -1)) + case "sec": + drawString(img, image.Rect(0, 0, size, size), + ttfThinFont, + sec, + ptfull, + image.Pt(-1, -1)) + default: + drawString(img, image.Rectangle{image.Pt(0, margin), image.Pt(size, margin+(height/3))}, + ttfBoldFont, + hour, + pt, + image.Pt(-1, -1)) + drawString(img, image.Rectangle{image.Pt(0, (height/3)+margin), image.Pt(size, margin+(height/3)*2)}, + ttfFont, + min, + pt, + image.Pt(-1, -1)) + drawString(img, image.Rectangle{image.Pt(0, (height/3)*2+margin), image.Pt(size, margin+height)}, + ttfThinFont, + sec, + pt, + image.Pt(-1, -1)) + } err := dev.SetImage(w.key, img) if err != nil {