# Path: tft/driver/ugui.py
# class Touchable(NoTouch):
#     def __init__(self, location, font, height, width, fgcolor, bgcolor, fontcolor, border, can_drag, value, initial_value):
#         super().__init__(location, font, height, width, fgcolor, bgcolor, fontcolor, border, value, initial_value)
#         self.can_drag = can_drag
#         self.busy = False
#         self.was_touched = False
# 
#     def _set_callbacks(self, cb, args, cb_end=None, cbe_args=None):
#         self.callback = cb
#         self.args = args
#         if cb_end is not None:
#             self.cb_end = cb_end
#             self.cbe_args = cbe_args
# 
#     def greyed_out(self, val=None):
#         if val is not None and self._greyed_out != val:
#             self._greyed_out = val
#             self.draw_border()
#             self.redraw = True
#             self.show_if_current()
#         return self._greyed_out
# 
#     def _trytouch(self, x, y): # If touched in bounding box, process it otherwise do nothing
#         x0 = self.location[0]
#         x1 = self.location[0] + self.width
#         y0 = self.location[1]
#         y1 = self.location[1] + self.height
#         if x0 <= x <= x1 and y0 <= y <= y1:
#             self.was_touched = True
#             if not self.busy or self.can_drag:
#                 self._touched(x, y) # Called repeatedly for draggable objects
#                 self.busy = True # otherwise once only
# 
#     def _untouched(self): # Default if not defined in subclass
#         self.cb_end(self, *self.cbe_args) # Callback not a bound method so pass self
# 
# def dolittle(*_):
#     pass
# 
# TWOPI = 2 * math.pi


import math
from tft.driver.ugui import Touchable, dolittle, TWOPI
from tft.driver.constants import *
# knob.py For TFT driver.
# Adapted for (and requires) uasyncio V3

# Released under the MIT License (MIT). See LICENSE.
# Copyright (c) 2016-2020 Peter Hinch


# *********** CONTROL KNOB CLASS ***********

class Knob(Touchable):
    def __init__(self, location, *, height=100, arc=TWOPI, ticks=9, value=0.0,
                 fgcolor=None, bgcolor=None, color=None, border=None,
                 cb_end=dolittle, cbe_args=[], cb_move=dolittle, cbm_args=[]):
        Touchable.__init__(self, location, None, height, height, fgcolor, bgcolor, None, border, True,  None, value)
        border = self.border # Geometry: border width
        radius = height / 2 - border

# Path: tft/driver/ugui.py
# class Touchable(NoTouch):
#     def __init__(self, location, font, height, width, fgcolor, bgcolor, fontcolor, border, can_drag, value, initial_value):
#         super().__init__(location, font, height, width, fgcolor, bgcolor, fontcolor, border, value, initial_value)
#         self.can_drag = can_drag
#         self.busy = False
#         self.was_touched = False
# 
#     def _set_callbacks(self, cb, args, cb_end=None, cbe_args=None):
#         self.callback = cb
#         self.args = args
#         if cb_end is not None:
#             self.cb_end = cb_end
#             self.cbe_args = cbe_args
# 
#     def greyed_out(self, val=None):
#         if val is not None and self._greyed_out != val:
#             self._greyed_out = val
#             self.draw_border()
#             self.redraw = True
#             self.show_if_current()
#         return self._greyed_out
# 
#     def _trytouch(self, x, y): # If touched in bounding box, process it otherwise do nothing
#         x0 = self.location[0]
#         x1 = self.location[0] + self.width
#         y0 = self.location[1]
#         y1 = self.location[1] + self.height
#         if x0 <= x <= x1 and y0 <= y <= y1:
#             self.was_touched = True
#             if not self.busy or self.can_drag:
#                 self._touched(x, y) # Called repeatedly for draggable objects
#                 self.busy = True # otherwise once only
# 
#     def _untouched(self): # Default if not defined in subclass
#         self.cb_end(self, *self.cbe_args) # Callback not a bound method so pass self
# 
# def dolittle(*_):
#     pass
# 
# TWOPI = 2 * math.pi


# Path: tft/widgets/knob.py
import math
from tft.driver.ugui import Touchable, dolittle, TWOPI
from tft.driver.constants import *

# knob.py For TFT driver.
# Adapted for (and requires) uasyncio V3

# Released under the MIT License (MIT). See LICENSE.
# Copyright (c) 2016-2020 Peter Hinch


# *********** CONTROL KNOB CLASS ***********

class Knob(Touchable):
    def __init__(self, location, *, height=100, arc=TWOPI, ticks=9, value=0.0,
                 fgcolor=None, bgcolor=None, color=None, border=None,
                 cb_end=dolittle, cbe_args=[], cb_move=dolittle, cbm_args=[]):
        Touchable.__init__(self, location, None, height, height, fgcolor, bgcolor, None, border, True,  None, value)
        border = self.border # Geometry: border width
        radius = height / 2 - border

        self.arc = min(max(arc, 0), TWOPI) # Usable angle of control