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 on_event(self, daemon, what, data): if what == self._control_with: x, y = data if self._use_cursor: max_w = self.get_allocation().width - (self.cursor.get_allocation().width * 0.8) max_h = self.get_allocation().height - (self.cursor.get_allocation().height * 1.0) x = ((x / (STICK_PAD_MAX * 2.0)) + 0.5) * max_w y = (0.5 - (y / (STICK_PAD_MAX * 2.0))) * max_h x -= self.cursor.get_allocation().width * 0.5 y -= self.cursor.get_allocation().height * 0.5 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: if y < STICK_PAD_MIN / 3 and self._direction != 1: self._direction = 1 self.on_move() if y > STICK_PAD_MAX / 3 and self._direction != -1: self._direction = -1 self.on_move() if y < STICK_PAD_MAX / 3 and y > STICK_PAD_MIN / 3 and self._direction != 0: self._direction = 0 self.cancel_timer("move") 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 self.quit(0)
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 max_w = self.get_allocation().width - (self.cursor.get_allocation().width * 0.8) max_h = self.get_allocation().height - (self.cursor.get_allocation().height * 1.0) x = ((x / (STICK_PAD_MAX * 2.0)) + 0.5) * max_w y = (0.5 - (y / (STICK_PAD_MAX * 2.0))) * max_h x -= self.cursor.get_allocation().width * 0.5 y -= self.cursor.get_allocation().height * 0.5 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: if y < STICK_PAD_MIN / 3 and self._direction != 1: self._direction = 1 self.on_move() if y > STICK_PAD_MAX / 3 and self._direction != -1: self._direction = -1 self.on_move() if y < STICK_PAD_MAX / 3 and y > STICK_PAD_MIN / 3 and self._direction != 0: self._direction = 0 self.cancel_timer("move") 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._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: 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: 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 max_w = self.get_allocation().width - ( self.cursor.get_allocation().width * 0.8) max_h = self.get_allocation().height - ( self.cursor.get_allocation().height * 1.0) x = ((x / (STICK_PAD_MAX * 2.0)) + 0.5) * max_w y = (0.5 - (y / (STICK_PAD_MAX * 2.0))) * max_h x -= self.cursor.get_allocation().width * 0.5 y -= self.cursor.get_allocation().height * 0.5 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._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: x, y = data if self._use_cursor: max_w = self.get_allocation().width - ( self.cursor.get_allocation().width * 0.8) max_h = self.get_allocation().height - ( self.cursor.get_allocation().height * 1.0) x = ((x / (STICK_PAD_MAX * 2.0)) + 0.5) * max_w y = (0.5 - (y / (STICK_PAD_MAX * 2.0))) * max_h x -= self.cursor.get_allocation().width * 0.5 y -= self.cursor.get_allocation().height * 0.5 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: if y < STICK_PAD_MIN / 3 and self._direction != 1: self._direction = 1 self.on_move() if y > STICK_PAD_MAX / 3 and self._direction != -1: self._direction = -1 self.on_move() if y < STICK_PAD_MAX / 3 and y > STICK_PAD_MIN / 3 and self._direction != 0: self._direction = 0 self.cancel_timer("move") 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.callback: self._selected.callback(self, self.daemon, self._selected) else: self.quit(0)
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 _get_under_cursor(self, cursor): x, y = self.f.child_get(cursor, "x", "y") for i in self._buttons: if point_in_gtkrect(i.get_allocation(), x, y): return i return None