diff --git a/utils/resedit/space.py b/utils/resedit/space.py index 212381e..4eead70 100644 --- a/utils/resedit/space.py +++ b/utils/resedit/space.py @@ -69,7 +69,9 @@ class space: col.add_attribute(cell, 'text', 0) self.__swidget("treSystems").set_model(self.tree_systems) + # Custom widget drawing area thingy. self.zoom = 1 + self.space_sel = "" area = self.__swidget("draSpace") area.set_events(gtk.gdk.EXPOSURE_MASK | gtk.gdk.LEAVE_NOTIFY_MASK @@ -187,8 +189,11 @@ class space: # Important thingies. tree = self.__swidget("treSystems") model = tree.get_model() - iter = tree.get_selection().get_selected()[1] - p = model.iter_parent(iter) + try: + iter = tree.get_selection().get_selected()[1] + p = model.iter_parent(iter) + except: + return None if p == None: return model.get_value(iter, 0) else: @@ -202,6 +207,7 @@ class space: def __space_reset(self, wgt=None, event=None): self.x = self.y = 0 + self.space_sel = "" self.__space_draw() def __space_down(self, wgt, event): @@ -209,20 +215,29 @@ class space: x = event.x y = event.y + wx, wy, ww, wh = self.__swidget("draSpace").get_allocation() + mx = x - (self.x*self.zoom + ww/2) + my = y - (self.y*self.zoom + wh/2) + # Modify the current position. if self.__swidget("butReposition").get_active() and self.cur_system != "": - wx, wy, ww, wh = self.__swidget("draSpace").get_allocation() - - mx = x - (self.x*self.zoom + ww/2) - my = y - (self.y*self.zoom + wh/2) - system = self.systems[self.cur_system] - system["pos"]["x"] = str(mx) - system["pos"]["y"] = str(-my) + system["pos"]["x"] = str(int(mx)) + system["pos"]["y"] = str(int(-my)) self.__space_draw() self.__swidget("butReposition").set_active(False) + else: + r = 15 + for name, sys in self.systems.items(): + sx = int(sys["pos"]["x"]) + sy = -int(sys["pos"]["y"]) + + if abs(sx-mx) < r and abs(sy-my) < r: + self.space_sel = name + self.__space_draw() + break self.lx = x self.ly = y @@ -266,17 +281,28 @@ class space: def __space_draw(self, wgt=None, event=None): area = self.__swidget("draSpace") - style = area.get_style() - gc = style.fg_gc[gtk.STATE_NORMAL] - bg_gc = style.bg_gc[gtk.STATE_NORMAL] wx, wy, ww, wh = area.get_allocation() cx = self.x*self.zoom + ww/2 cy = self.y*self.zoom + wh/2 r = 15 + # Colour stuff. + sys_gc = area.window.new_gc() + col = area.get_colormap().alloc_color("yellow") + sys_gc.foreground = col + bg_gc = area.window.new_gc() + col = area.get_colormap().alloc_color("black") + bg_gc.foreground = col + jmp_gc = area.window.new_gc() + col = area.get_colormap().alloc_color("blue") + jmp_gc.foreground = col + sel_gc = area.window.new_gc() + col = area.get_colormap().alloc_color("red") + sel_gc.foreground = col + # Cleanup. area.window.draw_rectangle(bg_gc, True, 0, 0, ww, wh) - area.window.draw_rectangle(gc, False, 0, 0, ww-1, wh-1) + area.window.draw_rectangle(sys_gc, False, 0, 0, ww-1, wh-1) for sys_name, system in self.systems.items(): sx = int(system["pos"]["x"]) @@ -291,11 +317,20 @@ class space: jdx = int(cx+jsx*self.zoom) jdy = int(cy+jsy*self.zoom) - area.window.draw_line(gc, dx, dy, jdx, jdy) + area.window.draw_line(jmp_gc, dx, dy, jdx, jdy) # Draw circle. + if sys_name == self.space_sel: + gc = sel_gc + else: + gc = sys_gc + if sys_name == self.__curSystem(): + gc2 = jmp_gc + else: + gc2 = bg_gc + area.window.draw_arc(gc, True, dx-r/2, dy-r/2, r, r, 0, 360*64) - area.window.draw_arc(bg_gc, True, dx-r/2+2, dy-r/2+2, r-4, r-4, 0, 360*64) + area.window.draw_arc(gc2, True, dx-r/2+2, dy-r/2+2, r-4, r-4, 0, 360*64) # Draw name. layout = area.create_pango_layout(sys_name) diff --git a/utils/resedit/space.pyc b/utils/resedit/space.pyc index cdc9586..04156e6 100644 Binary files a/utils/resedit/space.pyc and b/utils/resedit/space.pyc differ