def whole(self, mapper, x, y, what): if mapper.is_touched(what): # Store mouse position if pad was just touched if self.orig_position is None: if self.osd_enabled: x1, y1, x2, y2 = self.transform_osd_coords(mapper) self.execute(mapper, int(x1), int(y1), int(x2), int(y2)) self.orig_position = X.get_mouse_pos(mapper.get_xdisplay()) # Compute coordinates specified from other side of screen if needed x1, y1, x2, y2 = self.transform_coords(mapper) # Transform position on circne to position on rectangle x = x / float(STICK_PAD_MAX) y = y / float(STICK_PAD_MAX) x, y = circle_to_square(x, y) # Perform magic x = max(0, (x + 1.0) * 0.5) y = max(0, (1.0 - y) * 0.5) w = float(x2 - x1) h = float(y2 - y1) x = int(x1 + w * x) y = int(y1 + h * y) # Set position self.set_mouse(mapper, x, y) elif mapper.was_touched(what): # Pad just released X.set_mouse_pos(mapper.get_xdisplay(), *self.orig_position) if self.osd_enabled: self.execute_named("clear_osd", mapper) self.orig_position = None
def whole(self, mapper, x, y, what): if mapper.is_touched(what): # Store mouse position if pad was just touched if self.orig_position is None: if self.osd_enabled: x1, x2, y1, y2 = self.transform_osd_coords(mapper) self.execute(mapper, int(x1), int(y1), int(x2), int(y2)) self.orig_position = X.get_mouse_pos(mapper.xdisplay) # Compute coordinates specified from other side of screen if needed x1, x2, y1, y2 = self.transform_coords(mapper) # Transform position on circne to position on rectangle x = x / float(STICK_PAD_MAX) y = y / float(STICK_PAD_MAX) x, y = circle_to_square(x, y) # Perform magic x = max(0, (x + 1.0) * 0.5) y = max(0, (1.0 - y) * 0.5) w = float(x2 - x1) h = float(y2 - y1) x = int(x1 + w * x) y = int(y1 + h * y) # Set position self.set_mouse(mapper, x, y) elif mapper.was_touched(what): # Pad just released X.set_mouse_pos(mapper.xdisplay, *self.orig_position) if self.osd_enabled: self.execute_named("clear_osd", mapper) self.orig_position = None
def set_cursor_position(self, x, y, cursor, limit): """ Moves cursor image. """ w = limit[2] - (cursor.get_allocation().width * 0.5) h = limit[3] - (cursor.get_allocation().height * 0.5) x = x / float(STICK_PAD_MAX) y = y / float(STICK_PAD_MAX) * -1.0 x, y = circle_to_square(x, y) x = clamp( cursor.get_allocation().width * 0.5, (limit[0] + w * 0.5) + x * w * 0.5, self.get_allocation().width - cursor.get_allocation().width ) - cursor.get_allocation().width * 0.5 y = clamp( cursor.get_allocation().height * 0.5, (limit[1] + h * 0.5) + y * h * 0.5, self.get_allocation().height - cursor.get_allocation().height ) - cursor.get_allocation().height * 0.5 cursor.position = int(x), int(y) self.f.move(cursor, *cursor.position) for a in self.background.areas: if a.contains(x, y): if a != self._hovers[cursor]: self._hovers[cursor] = a if self._pressed[cursor] is not None: self.mapper.keyboard.releaseEvent([ self._pressed[cursor] ]) self.key_from_cursor(cursor, True) if not self.timer_active('redraw'): self.timer('redraw', 0.01, self.redraw_background) break
def _move_cursor(self, cursor, x, y): if (x, y) == (0, 0): cursor.set_visible(False) return cursor.set_visible(True) pad_w = cursor.get_allocation().width * 0.5 pad_h = cursor.get_allocation().height * 0.5 max_w = self.grid.get_allocation().width - 2 * pad_w max_h = self.grid.get_allocation().height - 2 * pad_h x, y = circle_to_square(x / (STICK_PAD_MAX * 2.0), y / (STICK_PAD_MAX * 2.0)) x = clamp(pad_w, (pad_w + max_w) * 0.5 + x * max_w, max_w - pad_w) y = clamp(pad_h, (pad_h + max_h) * 0.5 + y * max_h * -1, max_h - pad_h) x += self.grid.get_allocation().x y += self.grid.get_allocation().y self.f.move(cursor, int(x), int(y)) for i in self._buttons: if point_in_gtkrect(i.get_allocation(), x, y): if cursor.selected: cursor.selected.set_name("osd-key-buton") cursor.selected = i cursor.selected.set_name("osd-key-buton-hilight") break
def set_cursor_position(self, x, y, cursor, limit): """ Moves cursor image. """ if cursor not in self._hovers: return w = limit[2] - (cursor.get_allocation().width * 0.5) h = limit[3] - (cursor.get_allocation().height * 0.5) x = x / float(STICK_PAD_MAX) y = y / float(STICK_PAD_MAX) * -1.0 x, y = circle_to_square(x, y) x = clamp(cursor.get_allocation().width * 0.5, (limit[0] + w * 0.5) + x * w * 0.5, self.get_allocation().width - cursor.get_allocation().width) y = clamp( cursor.get_allocation().height * 0.5, (limit[1] + h * 0.5) + y * h * 0.5, self.get_allocation().height - cursor.get_allocation().height) cursor.position = int(x), int(y) self.f.move(cursor, x - cursor.get_allocation().width * 0.5, y - cursor.get_allocation().height * 0.5) for button in self.background.buttons: if button.contains(x, y): if button != self._hovers[cursor]: self._hovers[cursor] = button if self._pressed[cursor] is not None: self.mapper.keyboard.releaseEvent( [self._pressed[cursor]]) self.key_from_cursor(cursor, True) if not self.timer_active('update'): self.timer('update', 0.01, self.update_background) break
def set_cursor_position(self, x, y, cursor, limit): """ Moves cursor image. """ w = limit[2] - (cursor.get_allocation().width * 0.5) h = limit[3] - (cursor.get_allocation().height * 0.5) x = x / float(STICK_PAD_MAX) y = y / float(STICK_PAD_MAX) * -1.0 x, y = circle_to_square(x, y) x = clamp(cursor.get_allocation().width * 0.5, (limit[0] + w * 0.5) + x * w * 0.5, self.get_allocation().width - cursor.get_allocation().width ) - cursor.get_allocation().width * 0.5 y = clamp( cursor.get_allocation().height * 0.5, (limit[1] + h * 0.5) + y * h * 0.5, self.get_allocation().height - cursor.get_allocation().height ) - cursor.get_allocation().height * 0.5 cursor.position = int(x), int(y) self.f.move(cursor, *cursor.position) for a in self.background.areas: if a.contains(x, y): if a != self._hovers[cursor]: self._hovers[cursor] = a if self._pressed[cursor] is not None: self.mapper.keyboard.releaseEvent( [self._pressed[cursor]]) self.key_from_cursor(cursor, True) if not self.timer_active('redraw'): self.timer('redraw', 0.01, self.redraw_background) break
def on_event(self, daemon, what, data): if self._submenu: return self._submenu.on_event(daemon, what, data) if what == self._control_with: x, y = data if self._use_cursor: # Special case, both confirm_with and cancel_with # can be set to STICK if self._cancel_with == STICK and self._control_with == STICK: if self._control_equals_cancel(daemon, x, y): return pad_w = self.cursor.get_allocation().width * 0.5 pad_h = self.cursor.get_allocation().height * 0.5 max_w = self.get_allocation().width - 2 * pad_w max_h = self.get_allocation().height - 2 * pad_h x, y = circle_to_square(x / (STICK_PAD_MAX * 2.0), y / (STICK_PAD_MAX * 2.0)) x = clamp(pad_w, (pad_w + max_w) * 0.5 + x * max_w, max_w - pad_w) y = clamp(pad_h, (pad_h + max_h) * 0.5 + y * max_h * -1, max_h - pad_h) self.f.move(self.cursor, int(x), int(y)) for i in self.items: if point_in_gtkrect(i.widget.get_allocation(), x, y): self.select(self.items.index(i)) else: self._scon.set_stick(x, y) elif what == self._cancel_with: if data[0] == 0: # Button released self.quit(-1) elif what == self._confirm_with: if data[0] == 0: # Button released if self._selected and self._selected.callback: self._selected.callback(self, self.daemon, self.controller, self._selected) elif self._selected: self.quit(0) else: self.quit(-1)
def on_event(self, daemon, what, data): if self._submenu: return self._submenu.on_event(daemon, what, data) if what == self._control_with or what == "LEFT" and self._control_with_dpad: x, y = data if self._use_cursor: # Special case, both confirm_with and cancel_with # can be set to STICK if self._cancel_with == STICK and self._control_with == STICK: if self._control_equals_cancel(daemon, x, y): return pad_w = self.cursor.get_allocation().width * 0.5 pad_h = self.cursor.get_allocation().height * 0.5 max_w = self.get_allocation().width - 2 * pad_w max_h = self.get_allocation().height - 2 * pad_h x, y = circle_to_square(x / (STICK_PAD_MAX * 2.0), y / (STICK_PAD_MAX * 2.0)) x = clamp(pad_w, (pad_w + max_w) * 0.5 + x * max_w, max_w - pad_w) y = clamp(pad_h, (pad_h + max_h) * 0.5 + y * max_h * -1, max_h - pad_h) self.f.move(self.cursor, int(x), int(y)) for i in self.items: if point_in_gtkrect(i.widget.get_allocation(), x, y): self.select(self.items.index(i)) else: self._scon.set_stick(x, y) elif what == self._cancel_with: if data[0] == 0: # Button released self.quit(-1) elif what == self._confirm_with: if data[0] == 0: # Button released if self._selected and self._selected.callback: self._selected.callback(self, self.daemon, self.controller, self._selected) elif self._selected: self.quit(0) else: self.quit(-1)
def set_cursor_position(self, x, y, cursor, limit): """ Moves cursor image. """ if cursor not in self._hovers: return w = limit[2] - (cursor.get_allocation().width * 0.5) h = limit[3] - (cursor.get_allocation().height * 0.5) x = x / float(STICK_PAD_MAX) y = y / float(STICK_PAD_MAX) * -1.0 x, y = circle_to_square(x, y) x = clamp( cursor.get_allocation().width * 0.5, (limit[0] + w * 0.5) + x * w * 0.5, self.get_allocation().width - cursor.get_allocation().width ) y = clamp( cursor.get_allocation().height * 0.5, (limit[1] + h * 0.5) + y * h * 0.5, self.get_allocation().height - cursor.get_allocation().height ) cursor.position = int(x), int(y) self.f.move(cursor, x - cursor.get_allocation().width * 0.5, y - cursor.get_allocation().height * 0.5) for button in self.background.buttons: if button.contains(x, y): if button != self._hovers[cursor]: self._hovers[cursor] = button if self._pressed[cursor] is not None: self.mapper.keyboard.releaseEvent([ self._pressed[cursor] ]) self.key_from_cursor(cursor, True) if not self.timer_active('update'): self.timer('update', 0.01, self.update_background) break