def set_pos(self, x, y): # set absolute position # update text and rect position self.show() self.x = x self.y = y draw.set_pos(self.rect, draw.go.RECT, x, y) draw.set_pos(self.tid, draw.go.TEXT, x + self.w / 2, y + self.h / 2) self.status = 0 draw.rect_color(self.rect, self.c)
def step(): # change highlighted object global list_object if len(list_object) > 1: global index index += 1 global list_types if index >= len(list_object): index = 0 pos = draw.get_pos(list_object[index], list_types[index]) size = draw.size(list_object[index], list_types[index]) if list_types[index] == draw.go.TEXT: if draw.text_center( list_object[index] ): pos = (pos[0] - (size[0] / 2), pos[1]) draw.set_pos(hl_rect, draw.go.RECT, pos[0], pos[1]) draw.rect_resize(hl_rect, size[0],size[1])
def add_objects( list_found): global list_object global list_types global list_str global index global hl_rect for no in list_found: # only add if allow_offset is True if not draw.allow_offset(no[0],no[1]): continue lin = 0 already = False for lo in list_object: if lo == no[0] and list_types[lin] == no[1]: # already being tracked already = True break lin+=1 if not already: list_object.append( no[0] ) list_types.append( no[1] ) list_str.append( draw.name( no[0], no[1])) index = len(list_object) - 1 pos = draw.get_pos(no[0], no[1]) size = draw.size(no[0], no[1]) if no[1] == draw.go.TEXT: if draw.text_center( no[0] ): pos = (pos[0] - (size[0] / 2), pos[1]) if hl_rect == None: # create new highlight rect hl_rect = draw.create_rect(pos[0], pos[1],size[0], size[1],color=(255,255,0,150 ), group=groups.offsetter) else: # replace old highlight rect draw.set_pos(hl_rect, draw.go.RECT, pos[0], pos[1]) draw.rect_resize(hl_rect, size[0],size[1])
def add_object(obj, obj_type, name=""): # check if that object is already tracked global list_object global list_types global index global hl_rect lin = 0 for lo in list_object: if lo == obj and list_types[lin] == obj_type: print("this object is already being tracked") # highlight it though index = lin pos = draw.get_pos(obj, obj_type) size = draw.size(obj, obj_type) draw.set_pos(hl_rect, draw.go.RECT, pos[0], pos[1]) size = draw.size(obj, obj_type) draw.rect_resize(hl_rect, size[0],size[1]) return lin+=1 list_object.append(obj) list_types.append(obj_type) global list_str index = len(list_object) - 1 if name == "": list_str.append(draw.name(obj, obj_type)) print("added ["+ draw.go.name(obj_type) +"] object "+ list_str[index] + " to offsetter") pos = draw.get_pos(obj, obj_type) size = draw.size(obj, obj_type) if hl_rect == None: # create new highlight rect hl_rect = draw.create_rect(pos[0], pos[1],size[0], size[1],color=(255,255,0,150 )) else: # replace old highlight rect draw.set_pos(hl_rect, draw.go.RECT, pos[0], pos[1]) draw.rect_resize(hl_rect, size[0],size[1])
def set_pos(self, x, y): self.x = x self.y = y draw.set_pos(self.rect, draw.go.RECT, x, y)