Skip to content

Commit

Permalink
account for Nones, actually draw the bonus arcs
Browse files Browse the repository at this point in the history
This commit was sponsored by Derek Veit, zts, hacklschorsch, and my
other patrons.  If you want to join them, you can support my work at
https://glyph.im/patrons/.
  • Loading branch information
glyph committed Jul 11, 2024
1 parent 2a16453 commit 0f8be22
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
4 changes: 2 additions & 2 deletions IBFiles/IntentionEditor.xib
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
<slider horizontalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="bPN-TO-sTB">
<rect key="frame" x="15" y="32" width="24" height="517"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<sliderCell key="cell" continuous="YES" alignment="left" maxValue="100" doubleValue="50" tickMarkPosition="right" sliderType="linear" id="blJ-2d-DkX">
<sliderCell key="cell" continuous="YES" alignment="left" maxValue="1" doubleValue="0.25" tickMarkPosition="right" sliderType="linear" id="blJ-2d-DkX">
<font key="font" size="12" name="Helvetica"/>
</sliderCell>
<connections>
Expand All @@ -113,7 +113,7 @@
<slider horizontalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="NLA-2v-oRU">
<rect key="frame" x="91" y="32" width="24" height="517"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<sliderCell key="cell" continuous="YES" alignment="left" maxValue="100" doubleValue="50" tickMarkPosition="right" sliderType="linear" id="0aK-3R-tmq">
<sliderCell key="cell" continuous="YES" alignment="left" maxValue="1" doubleValue="0.34999999999999998" tickMarkPosition="right" sliderType="linear" id="0aK-3R-tmq">
<font key="font" size="12" name="Helvetica"/>
</sliderCell>
<connections>
Expand Down
39 changes: 36 additions & 3 deletions src/pomodouroboros/macos/progress_hud.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,15 @@ def setPercentage_(self, newPercentage: float) -> None:
self.setNeedsDisplay_(True)

def setBonusPercentage1_(self, newBonusPercentage: float) -> None:
print("bonus 1", newBonusPercentage)
if newBonusPercentage is None:
return
self._bonusPercentage1 = newBonusPercentage
self.setNeedsDisplay_(True)

def setBonusPercentage2_(self, newBonusPercentage: float) -> None:
print("bonus 2", newBonusPercentage)
if newBonusPercentage is None:
# TODO: why???
return
self._bonusPercentage2 = newBonusPercentage
self.setNeedsDisplay_(True)

Expand Down Expand Up @@ -595,6 +598,14 @@ def _circledTextWithAlpha(

clear = NSColor.clearColor()


def pct2deg(pct: float) -> float:
"""
Convert percentages to degrees.
"""
return ((360 * pct) + 90) % 360


class PieTimer(AbstractProgressView):
"""
A timer that draws itself as two large arcs.
Expand All @@ -614,6 +625,13 @@ def drawRect_(self, dirtyRect: NSRect) -> None:
self._alphaValue
)

bonus1Color = NSColor.blueColor().colorWithAlphaComponent_(
self._alphaValue
)
bonus2Color = NSColor.yellowColor().colorWithAlphaComponent_(
self._alphaValue
)

super().drawRect_(dirtyRect)

clear.set()
Expand All @@ -624,17 +642,32 @@ def drawRect_(self, dirtyRect: NSRect) -> None:
w, h = bounds.size.width / 2, bounds.size.height / 2
center = NSMakePoint(w, h)
radius = (min([w, h]) * 0.95) * (0.7 if TEST_MODE else 1.0)
startDegrees = ((360 * self._percentage) + 90) % 360
startDegrees = pct2deg(self._percentage)
endDegrees = 90

maker = ArcMaker(center, radius)
leftArc = maker.makeArc(endDegrees, startDegrees)
rightArc = maker.makeArc(startDegrees, endDegrees)

bonusMaker = ArcMaker(center, radius * 1.1)

bonus1start = pct2deg(self._bonusPercentage1)
bonus2start = pct2deg(self._bonusPercentage2)

bonus1Arc = maker.makeArc(endDegrees, bonus1start)
bonus2Arc = maker.makeArc(bonus1start, bonus2start + bonus1start)

leftWithAlpha.setFill()
leftArc.fill()
rightWithAlpha.setFill()
rightArc.fill()

bonus1Color.setFill()
bonus1Arc.fill()

bonus2Color.setFill()
bonus2Arc.fill()

lineAlpha = (self._alphaValue - DEFAULT_BASE_ALPHA) * 4

if lineAlpha > 0:
Expand Down

0 comments on commit 0f8be22

Please sign in to comment.