def mouse_move(self, gameloop, event): if not self.component_info: return # Start panning if large movement is detected if not self.is_pan and self.start_event is not None: dx = event.MouseMove.X * xratio - self.start_event[0] dy = event.MouseMove.Y - self.start_event[1] dist = dx * dx + dy * dy if dist >= self.radius_to_pan: self._start_pan() if self.is_pan: #print "PANNING", self.component origc = self.component_info[0] if origc.signal_pan.is_enabled(): origc.signal_pan.call(\ signalslot.Event("DoPanEvent", component = origc, x = event.MouseMove.X *xratio, y = event.MouseMove.Y)) else: # BUG OBSOLETE DO NOT USE self.component_info[0].do_pan( (event.MouseMove.X * xratio, event.MouseMove.Y))
def mousebutton_released(self, gameloop, event): self.start_event = None try: if not self.component_info: return c = self._component_at(event) if self.is_pan: #print "END PAN", self.component origc = self.component_info[0] if origc.signal_pan.is_enabled(): origc.signal_pan.call(\ signalslot.Event("EndPanEvent", component = origc, x = event.MouseButton.X * xratio, y = event.MouseButton.Y)) else: # BUG OBSOLETE DO NOT USE self.component_info[0].end_pan( (event.MouseButton.X * xratio, event.MouseButton.Y)) else: if c and c[0] == self.component_info[0]: #print "USER HIT", self.component # BUG drop onto "c" component print "uihelp: mousereleased on", self.component_info x = self.component_info[1] y = self.component_info[2] self.component_info[0].user_hit(gameloop, x, y) finally: self.component_info = None self.is_pan = False
def _call_timers(self): e = None while self.timers and self.timers[0][0] <= self.time_now: if e is None: e = signalslot.Event("TimerEvent", now=self.time_now) ts = heapq.heappop(self.timers)[1] ts.call(e)
def set_active(self, idx): """Sets the active object. @idx can be either an integer [0..size-1] or one of the actual objects.""" i = None try: i = self.objs.index(idx) except ValueError: pass if self.active_idx == idx: return if self.active_idx != -1: w = self.objs[self.active_idx] w.deactivate() w.set_visible(False) if i is not None: idx = i self.active_idx = idx w = self.objs[self.active_idx] w.activate() w.set_visible(True) e = signalslot.Event("ChangerClickEvent", component = self, active = w) self.signal_click.call(e)
def set_language_string(self, langstring): assert langstring in all_languages.keys() assert self._languagesupport.get_language(langstring) self._language_string = langstring self.signal_language_changed.call(\ signalslot.Event("LanguageChangeEvent", language = langstring)) print "Calling LanguageChangeEvent", \ langstring, \ self.signal_language_changed.targets
def _hit_key(self, key): keyinfo = key.keyinfo s = self.whitestr.get_string() if "extra" in keyinfo: e = keyinfo["extra"] if 0: pass elif e == "DEL": s = s[:-1] elif e == "ENTER": # Accepts the string and sends it no observers e = signalslot.Event("text_entered", text=self.whitestr.get_string()) self.signal_text_entered.call(e) uiactions.move_out(self, 50) elif e == "SHIFTLEFT" or e == "SHIFTRIGHT": self.kconfig.is_shifted ^= True value = "key" if self.kconfig.is_shifted: value = "shift" for key in self.kconfig.keys: if "extra" in key.keyinfo: e = key.keyinfo["extra"] if e == "SHIFTLEFT" or e == "SHIFTRIGHT": if self.kconfig.is_shifted: c = sf.Color(200, 200, 200, 255) else: c = sf.Color(255, 255, 255, 255) key._sprite.SetColor(c) continue if value in key.keyinfo: # BUG this should be automatic u = key k = u.keysprite yfuzz = -4 xfuzz = 0 k.set_string(key.keyinfo[value]) k.SetPosition(u.GetPosition()[0] + \ u._get_width()/2.0 - \ k._get_width()/2.0 + xfuzz, u.GetPosition()[1] + \ u._get_height()/2.0 - \ k._get_height()/2.0 + yfuzz) else: assert 0 else: if self.whitestr._get_width() >= self.maxlength: return s += key.keysprite.get_string() self.whitestr.set_string(s)
def user_hit(self, gameloop, localx, localy): """ Called when user hits the component, and set_enabled_hit(True) has been called. You probably should not override this, and instead just hook into the signal_click signal instead. See tf.signalslot for details. """ self.signal_click.call(signalslot.Event("ClickEvent", component = self, x = localx, y = localy))
def set_zoom(self, newzoom): if newzoom > self.maxzoom: newzoom = self.maxzoom elif newzoom < self.minzoom: newzoom = self.minzoom if self.zoom != newzoom: self.zoom = newzoom cx, cy = self.view.GetCenter() self.signal_zoom_change.call(signalslot.Event("ZoomChangeEvent", view = self, zoom = self.zoom, centerx = cx, centery = cy)) self._fix_zoom()
def activate_button(self, button): if isinstance(button, int): button = self.buttons[button] newidx = self.buttons.index(button) if newidx == self.active_idx: return if self.active_idx != -1: self.buttons[self.active_idx].deactivate() self.active_idx = newidx if self.active_idx != -1: print "ACTIVATE", button, self.active_idx self.buttons[self.active_idx].activate() e = signalslot.Event("ButtonGroupEvent", component = self, button = self.buttons[self.active_idx]) self.signal_activate_button.call(e)
def call_key(self, keycode, has_alt, has_ctrl, has_shift): k = (keycode, has_alt, has_ctrl, has_shift) #print "K", k #print self._keyboard_shortcuts if k not in self._keyboard_shortcuts \ or len(self._keyboard_shortcuts[k]) == 0: print "tf: no shortcut on key", k return e = signalslot.Event("KeypressEvent", key=keycode) for func in self._keyboard_shortcuts[k]: func(e)
def _start_pan(self): assert self.component_info c = self.component_info[0] # BUG start_pan is an obsolete interface if hasattr(c, "start_pan"): #print "START PANNING", self.component self.is_pan = True c.start_pan(self.start_event) else: if c.signal_pan.is_enabled(): self.is_pan = True c.signal_pan.call(\ signalslot.Event("StartPanEvent", component = c, x = self.start_event[0], y = self.start_event[1])) else: print "Can't pan on", self.component_info[0], \ "I'll click instead on mousereleased" #self.component = None pass
def recenter_view(self, cx, cy): cntr = self.view.GetCenter() h = self.view.GetHalfSize() hx = h[0] hy = h[1] if cx - hx < 0: cx += -(cx-hx) if cy - hy < 0: cy += -(cy-hy) if cx + hx > self.content_width: cx += self.content_width-(cx+hx) if cy + hy > self.content_height: cy += self.content_height-(cy+hy) if cx == cntr[0] and cy == cntr[1]: return self.view.SetCenter(cx, cy) e = signalslot.Event("PositionChange", zoom = self.zoom, centerx = cx, centery = cy) self.signal_position.call(e)
def notify_all_ui(self, newrotation): self.signal_notifier.call(\ signalslot.Event("UiRotationEvent", component = self, rotation = newrotation))
def set_dice_value(self, v): self.dice_value = v print "Set dice value to ", v e = signalslot.Event("DiceRollEvent", dice = self.dice_value) self.signal_dice_rolled.call(e)