Exemple #1
0
    def touch(self, event, pos):
        pos = rotate(pos)

        state = self.state
        if state == BTN_DISABLED:
            return

        if event == io.TOUCH_START:
            if contains(self.area, pos):
                self.state = BTN_ACTIVE
                self.tainted = True

        elif event == io.TOUCH_MOVE:
            if contains(self.area, pos):
                if state == BTN_FOCUSED:
                    self.state = BTN_ACTIVE
                    self.tainted = True
            else:
                if state == BTN_ACTIVE:
                    self.state = BTN_FOCUSED
                    self.tainted = True

        elif event == io.TOUCH_END:
            if state != BTN_INITIAL:
                self.state = BTN_INITIAL
                self.tainted = True
                if state == BTN_ACTIVE and contains(self.area, pos):
                    return BTN_CLICKED
Exemple #2
0
    def touch(self, event, pos):

        if not self.absolute:
            pos = rotate(pos)

        if event == io.TOUCH_MOVE and self.start_pos is not None:
            pdx = pos[0] - self.start_pos[0]
            pdy = pos[1] - self.start_pos[1]

            pdxa = abs(pdx)
            pdya = abs(pdy)
            if pdxa > pdya and self.directions & SWIPE_HORIZONTAL:
                # Horizontal direction
                if (pdx > 0 and self.directions & SWIPE_RIGHT) or (
                        pdx < 0 and self.directions & SWIPE_LEFT):
                    ui.display.backlight(
                        ui.lerpi(
                            self.light_origin, self.light_target, pdxa /
                            _SWIPE_DISTANCE if pdxa < _SWIPE_DISTANCE else 1))
            elif pdxa < pdya and self.directions & SWIPE_VERTICAL:
                # Vertical direction
                if (pdy > 0 and self.directions & SWIPE_DOWN) or (
                        pdy < 0 and self.directions & SWIPE_UP):
                    ui.display.backlight(
                        ui.lerpi(
                            self.light_origin, self.light_target, pdya /
                            _SWIPE_DISTANCE if pdya < _SWIPE_DISTANCE else 1))

        elif event == io.TOUCH_START and contains(self.area, pos):
            self.start_pos = pos
            self.light_origin = ui.BACKLIGHT_NORMAL

        elif event == io.TOUCH_END and self.start_pos is not None:
            pdx = pos[0] - self.start_pos[0]
            pdy = pos[1] - self.start_pos[1]
            pdxa = abs(pdx)
            pdya = abs(pdy)
            if pdxa > pdya and self.directions & SWIPE_HORIZONTAL:
                # Horizontal direction
                ratio = pdxa / _SWIPE_DISTANCE if pdxa < _SWIPE_DISTANCE else 1
                if ratio * 100 >= self.treshold:
                    if pdx > 0 and self.directions & SWIPE_RIGHT:
                        return SWIPE_RIGHT
                    elif pdx < 0 and self.directions & SWIPE_LEFT:
                        return SWIPE_LEFT
            elif pdxa < pdya and self.directions & SWIPE_VERTICAL:
                # Vertical direction
                ratio = pdya / _SWIPE_DISTANCE if pdya < _SWIPE_DISTANCE else 1
                if ratio * 100 >= self.treshold:
                    if pdy > 0 and self.directions & SWIPE_DOWN:
                        return SWIPE_DOWN
                    elif pdy < 0 and self.directions & SWIPE_UP:
                        return SWIPE_UP
            # No swipe, reset the state
            self.start_pos = None
            ui.display.backlight(self.light_origin)
Exemple #3
0
 def touch(self, event, pos):
     if self.state & BTN_DISABLED:
         return
     if not self.absolute:
         pos = rotate(pos)
     if event == io.TOUCH_START:
         if contains(self.area, pos):
             self.state = BTN_STARTED | BTN_DIRTY | BTN_ACTIVE
     elif event == io.TOUCH_MOVE and self.state & BTN_STARTED:
         if contains(self.area, pos):
             if not self.state & BTN_ACTIVE:
                 self.state = BTN_STARTED | BTN_DIRTY | BTN_ACTIVE
         else:
             if self.state & BTN_ACTIVE:
                 self.state = BTN_STARTED | BTN_DIRTY
     elif event == io.TOUCH_END and self.state & BTN_STARTED:
         self.state = BTN_DIRTY
         if contains(self.area, pos):
             return BTN_CLICKED