Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow user to select a smaller size for the HUD progress ring to reduce distraction #45

Draft
wants to merge 1 commit into
base: trunk
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion runme
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash -ex

mypy ./src;
#mypy ./src;
rm -fr ./build ./dist;
# https://github.com/ronaldoussoren/py2app/issues/444
python setup.py py2app --alias | cat;
Expand Down
23 changes: 17 additions & 6 deletions src/pomodouroboros/macos/progress_hud.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import math
from ..storage import TEST_MODE
from ..model.hud import HudParameters, HudSize, Position, get_drawing_params

from objc import super

Expand Down Expand Up @@ -134,13 +135,23 @@ def wantsDefaultClipping(self) -> bool:
return False


def fullScreenSizer(screen: NSScreen) -> NSRect:
PARAMETERS = HudParameters(
size=HudSize.MEDIUM,
h_position=Position.END,
v_position=Position.END,
full=False,
)

def screenSizer(screen: NSScreen) -> NSRect:
""" """
frame = screen.visibleFrame()
return NSRect(
(frame.origin[0] + 50, frame.origin[1] + 50),
(frame.size.width - 100, frame.size.height - 100),
bounding_box, _ignored = get_drawing_params(
PARAMETERS, screen.visibleFrame()
)
(top_x, top_y), (bottom_x, bottom_y) = bounding_box
width = bottom_x - top_x
height = bottom_y - top_y
print("woohoo", top_x, top_y, width, height, screen.visibleFrame())
return NSRect((top_x, top_y), (width, height))


def midScreenSizer(screen: NSScreen) -> NSRect:
Expand Down Expand Up @@ -196,7 +207,7 @@ class ProgressController(object):
progressViewFactory: Callable[
[], AbstractProgressView
] = lambda: PieTimer.alloc().init()
windowSizer: Callable[[NSScreen], NSRect] = fullScreenSizer
windowSizer: Callable[[NSScreen], NSRect] = screenSizer
progressViews: List[AbstractProgressView] = field(default_factory=list)
hudWindows: List[HUDWindow] = field(default_factory=list)
alphaValue: float = 0.1
Expand Down
114 changes: 114 additions & 0 deletions src/pomodouroboros/model/hud.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
from __future__ import annotations

from dataclasses import dataclass, field
from typing import Tuple, TypeVar, Protocol
from enum import unique, Enum, auto

OffsetType = TypeVar("OffsetType")
Coordinates = Tuple[OffsetType, OffsetType]
BoundingBox = Tuple[Coordinates[OffsetType], Coordinates[OffsetType]]
Grid = int
Frame = float

@unique
class HudSize(Enum):
SMALL = auto()
MEDIUM = auto()
LARGE = auto()

@unique
class Position(Enum):
BEGINNING = 0
MIDDLE = 1
END = 2

@dataclass(frozen=True)
class HudParameters:
size: HudSize
h_position: Position
v_position: Position
full: bool

@dataclass(frozen=True)
class RingParams:
center: Coordinates[Frame]
inner_radius: float
outer_radius: float

class Size(Protocol):
width: float
height: float

class VisibleFrame(Protocol):
origin: Tuple[float, float]
size: Size


def get_drawing_params(parameters: HudParameters, frame: VisibleFrame) -> Tuple[BoundingBox[Frame], RingParams]:
circle = _Circle.from_parameters(parameters)
frame_values = (
(frame.origin[0], frame.origin[1]),
(frame.origin[0] + frame.size.width, frame.origin[1] + frame.size.height),
)
relative_box = circle.relativize(frame_values)
(top_x, top_y), (bottom_x, bottom_y) = relative_box
mid_x = (top_x + bottom_x) / 2
mid_y = (top_y + bottom_y) / 2
center = (mid_x, mid_y)
outer_radius = mid_x - top_x
inner_radius = 0.9 * outer_radius if not circle.full else 0
ring_params = RingParams(center=center, outer_radius=outer_radius, inner_radius=inner_radius)
return relative_box, ring_params


@dataclass(frozen=True)
class _Circle:
top_x: Offset[Grid] = field(default=0)
top_y: Offset[Grid] = field(default=0)
bottom_x: Offset[Grid] = field(default=15)
full: bool = field(default=False)

@classmethod
def from_parameters(cls, parameters: HudParameters) -> Circle:
if parameters.size == HudSize.SMALL:
top_x = int(parameters.h_position.value * 7.5)
top_y = int(parameters.v_position.value * 7.5)
bottom_x = top_x + 4
elif parameters.size == HudSize.LARGE:
top_x = 0
top_y = 0
bottom_x = top_x + 16
elif parameters.size == HudSize.MEDIUM:
top_x = int(parameters.h_position.value * 6)
top_y = int(parameters.v_position.value * 6)
bottom_x = top_x + 8
return cls(top_x=top_x, top_y=top_y, bottom_x=bottom_x, full=parameters.full)

@property
def bounding_box(self) -> BoundingBox[Grid]:
bottom_y = bottom_x + (top_y - top_x)
return (top_x, top_y), (bottom_x, bottom_y)

def relativize(self, frame: BoundingBox[Frame]) -> BoundingBox[Frame]:
bottom_x, top_y, top_x, = self.bottom_x, self.top_x, self.top_y
bottom_y = bottom_x + (top_y - top_x)
(raw_top_x, raw_top_y), (raw_bottom_x, raw_bottom_y) = frame
raw_x_size = raw_bottom_x - raw_top_x
x_grid_step = raw_x_size / 16
raw_y_size = raw_bottom_y - raw_top_y
y_grid_step = raw_y_size / 16
base_top_x = raw_top_x + x_grid_step * self.top_x
base_top_y = raw_top_y + y_grid_step * self.top_y
base_bottom_x = raw_top_x + x_grid_step * self.bottom_x
base_bottom_y = raw_top_y + y_grid_step * bottom_y
mid_x = (base_top_x + base_bottom_x) / 2
mid_y = (base_top_y + base_bottom_y) / 2
x_head_room = mid_x - base_top_x
y_head_room = mid_y - base_top_y
head_room = min(x_head_room, y_head_room)
effective_head_room = 0.9 * head_room
ret_top_x = mid_x - effective_head_room / 2
ret_top_y = mid_y - effective_head_room / 2
ret_bottom_x = mid_x + effective_head_room / 2
ret_bottom_y = mid_y + effective_head_room / 2
return (ret_top_x, ret_top_y), (ret_bottom_x, ret_bottom_y)