def scroll_up(self, args): if state.get_shift_pressed(): offset = state.get_base_offset() self.hscroll_base(offset[0] - state.get_grid_step()[0]) elif state.get_ctrl_pressed(): offset = state.get_base_offset() self.vscroll_base(offset[1] - state.get_grid_step()[1]) else: scale = state.get_scale() state.set_scale((scale[0] + 0.1, scale[1] + 0.1)) self.mw.widget.update() scale = state.get_scale() self.mw.scale_label.set_text("Scale: %.1f:%.1f" % (scale[0], scale[1]))
def scroll_up(self, args): if state.get_shift_pressed(): offset = state.get_base_offset() self.hscroll_base(offset[0]-state.get_grid_step()[0]) elif state.get_ctrl_pressed(): offset = state.get_base_offset() self.vscroll_base(offset[1]-state.get_grid_step()[1]) else: scale = state.get_scale() state.set_scale((scale[0]+0.1, scale[1]+0.1)) self.mw.widget.update() scale = state.get_scale() self.mw.scale_label.set_text("Scale: %.1f:%.1f"%(scale[0], scale[1]))
def screen_left_press(self, args): offset = state.get_offset() scale = state.get_scale() cx = (args[0][0]-offset[0])/scale[0] cy = (args[0][1]-offset[1])/scale[1] state.set_left_press_start((cx, cy)) grid_step = state.get_grid_step() layer = state.get_active_layer()
def screen_left_press(self, args): offset = state.get_offset() scale = state.get_scale() cx = (args[0][0] - offset[0]) / scale[0] cy = (args[0][1] - offset[1]) / scale[1] state.set_left_press_start((cx, cy)) grid_step = state.get_grid_step() layer = state.get_active_layer()
def pointer_motion(self, args): offset = state.get_offset() scale = state.get_scale() cx = (args[0][0] - offset[0]) / scale[0] cy = (args[0][1] - offset[1]) / scale[1] pointer_position = (cx, cy) grid_step = state.get_grid_step() nx = int(pointer_position[0] / grid_step[0]) * grid_step[0] ny = int(pointer_position[1] / grid_step[1]) * grid_step[1] pointer_position = [nx, ny] layer = state.get_active_layer() if layer != None: if state.get_put_layer_object(): self.mw.widget.update() if state.get_left_press_start() != None: prev_position = state.get_pointer_position() proxys = layer.get_selected_proxys() for p in proxys: if not p in self.relative_coords: self.relative_coords[p] = utils.mk_vect( (cx, cy), p.get_position()) nx = cx + self.relative_coords[p][0] ny = cy + self.relative_coords[p][1] p.set_position((int(nx / grid_step[0]) * grid_step[0], int(ny / grid_step[1]) * grid_step[1])) layer.resort_all_proxys() if state.is_selection_mode(): if state.get_update_selection_box_selection(): state.update_selection_box(nx, ny) sb = state.get_selection_box() select_aabb = utils.AABB(sb[0], sb[1], sb[2], sb[3]) self.deselect_all(None, noupdate=True) for p in layer.get_proxy_lst(): p_aabb = p.get_aabb() if (p_aabb != None): #print "proxy_aabb:", p_aabb #print "select:", select_aabb overlap = select_aabb.aabb_in_aabb(p_aabb) #print "overlap",overlap if (overlap != utils.OverlapEnum.no_overlap) and ( overlap != utils.OverlapEnum.fully_lays_inside): p.set_selected() layer.add_proxy_to_selected_fast(p) self.mw.widget.update() state.set_pointer_position(pointer_position) self.mw.cursor_pos_label.set_text("Pos: %.3f:%.3f" % (cx, cy))
def do_expose_event(self, event): # Create the cairo context #state.offset = (self.allocation.width/2,self.allocation.height/2) state.set_screen_offset( (self.allocation.width / 2, self.allocation.height / 2)) scale = state.get_scale() offset = state.get_offset() cr_gdk = self.window.cairo_create() surface = cr_gdk.get_target() cr_surf = cairo.ImageSurface(cairo.FORMAT_ARGB32, int(state.atlas_size * scale[0]), int(state.atlas_size * scale[1])) cr = cairo.Context(cr_surf) # Restrict Cairo to the exposed area; avoid extra work cr.rectangle(event.area.x, event.area.y, event.area.width, event.area.height) cr.clip() cr.set_source_rgb(1.0, 1.0, 1.0) cr.rectangle(0, 0, int(state.atlas_size * scale[0]), int(state.atlas_size * scale[1])) cr.fill() cr.set_source_rgb(0, 0, 0) cr.set_line_width(0.1) cr.translate(offset[0], offset[1]) cr.scale(scale[0], scale[1]) grid_step = state.get_grid_step() for y in range(0, int(self.allocation.height / scale[1]), grid_step[1]): cr.move_to(0, y) cr.line_to(self.allocation.width / scale[0], y) for x in range(0, int(self.allocation.width / scale[0]), grid_step[0]): cr.move_to(x, 0) cr.line_to(x, self.allocation.height / scale[1]) cr.stroke() cr.identity_matrix() images = state.get_images() cr.translate(offset[0], offset[1]) cr.scale(state.scale[0], state.scale[1]) for img in images: img.draw(cr) cr.identity_matrix() cr_gdk.set_source_surface(cr_surf) cr_gdk.paint()
def pointer_motion(self, args): offset = state.get_offset() scale = state.get_scale() cx = (args[0][0]-offset[0])/scale[0] cy = (args[0][1]-offset[1])/scale[1] pointer_position = (cx, cy) grid_step = state.get_grid_step() nx = int(pointer_position[0]/grid_step[0])*grid_step[0] ny = int(pointer_position[1]/grid_step[1])*grid_step[1] pointer_position = [nx, ny] layer = state.get_active_layer() if layer != None: if state.get_put_layer_object(): self.mw.widget.update() if state.get_left_press_start() != None: prev_position = state.get_pointer_position() proxys = layer.get_selected_proxys() for p in proxys: if not p in self.relative_coords: self.relative_coords[p] = utils.mk_vect((cx, cy), p.get_position()) nx = cx + self.relative_coords[p][0] ny = cy + self.relative_coords[p][1] p.set_position((int(nx/grid_step[0])*grid_step[0], int(ny/grid_step[1])*grid_step[1])) layer.resort_all_proxys() if state.is_selection_mode(): if state.get_update_selection_box_selection(): state.update_selection_box(nx, ny) sb = state.get_selection_box() select_aabb = utils.AABB(sb[0], sb[1], sb[2], sb[3]) self.deselect_all(None, noupdate=True) for p in layer.get_proxy_lst(): p_aabb = p.get_aabb() if (p_aabb != None): #print "proxy_aabb:", p_aabb #print "select:", select_aabb overlap = select_aabb.aabb_in_aabb(p_aabb) #print "overlap",overlap if (overlap != utils.OverlapEnum.no_overlap) and (overlap != utils.OverlapEnum.fully_lays_inside): p.set_selected() layer.add_proxy_to_selected_fast(p) self.mw.widget.update() state.set_pointer_position(pointer_position) self.mw.cursor_pos_label.set_text("Pos: %.3f:%.3f"%(cx, cy))
def do_expose_event(self, event): # Create the cairo context #state.offset = (self.allocation.width/2,self.allocation.height/2) state.set_screen_offset((self.allocation.width/2, self.allocation.height/2)) scale = state.get_scale() offset = state.get_offset() cr_gdk = self.window.cairo_create() surface = cr_gdk.get_target() cr_surf = cairo.ImageSurface(cairo.FORMAT_ARGB32, int(state.atlas_size*scale[0]), int(state.atlas_size*scale[1])) cr = cairo.Context(cr_surf) # Restrict Cairo to the exposed area; avoid extra work cr.rectangle(event.area.x, event.area.y, event.area.width, event.area.height) cr.clip() cr.set_source_rgb(1.0, 1.0, 1.0) cr.rectangle(0, 0, int(state.atlas_size*scale[0]), int(state.atlas_size*scale[1])) cr.fill() cr.set_source_rgb(0, 0, 0) cr.set_line_width(0.1) cr.translate(offset[0], offset[1]) cr.scale(scale[0], scale[1]) grid_step = state.get_grid_step() for y in range(0, int(self.allocation.height/scale[1]), grid_step[1]): cr.move_to(0, y) cr.line_to(self.allocation.width/scale[0], y) for x in range(0, int(self.allocation.width/scale[0]), grid_step[0]): cr.move_to(x, 0) cr.line_to(x, self.allocation.height/scale[1]) cr.stroke() cr.identity_matrix() images = state.get_images() cr.translate(offset[0], offset[1]) cr.scale(state.scale[0], state.scale[1]) for img in images: img.draw(cr) cr.identity_matrix() cr_gdk.set_source_surface(cr_surf) cr_gdk.paint()
def pointer_motion(self, args): offset = state.get_offset() scale = state.get_scale() cx = (args[0][0]-offset[0])/scale[0] cy = (args[0][1]-offset[1])/scale[1] pointer_position = (cx, cy) if state.get_left_press_start() != None: prev_position = state.get_pointer_position() grid_step = state.get_grid_step() images = state.get_selected_images() for i in images: nx = cx + self.relative_coords[i][0] ny = cy + self.relative_coords[i][1] i.set_origin((int(nx/grid_step[0])*grid_step[0], int(ny/grid_step[1])*grid_step[1])) self.mw.widget.update() state.set_pointer_position(pointer_position) self.mw.cursor_pos_label.set_text("%.3f:%.3f"%(cx, cy))
def pointer_motion(self, args): offset = state.get_offset() scale = state.get_scale() cx = (args[0][0] - offset[0]) / scale[0] cy = (args[0][1] - offset[1]) / scale[1] pointer_position = (cx, cy) if state.get_left_press_start() != None: prev_position = state.get_pointer_position() grid_step = state.get_grid_step() images = state.get_selected_images() for i in images: nx = cx + self.relative_coords[i][0] ny = cy + self.relative_coords[i][1] i.set_origin((int(nx / grid_step[0]) * grid_step[0], int(ny / grid_step[1]) * grid_step[1])) self.mw.widget.update() state.set_pointer_position(pointer_position) self.mw.cursor_pos_label.set_text("%.3f:%.3f" % (cx, cy))
def deserialize(self, data): from state import state self.name = data["name"] self.layer_type = data["layer_type"] self.adjacency_dct = {} for k, v in data["adjacency_dct"].iteritems(): self.adjacency_dct[int(k)] = v for p in data["proxys"]: if self.layer_type == LayerType.meta: m = Meta("", state.get_grid_step()) proxy = Proxy(sprite=m, state=state, data=p) m.name = str(proxy.id) m.update_text() else: proxy = Proxy(state=state, data=p) self.proxy_dct[proxy.id] = proxy #print "proxy_dct:", self.proxy_dct if len(self.proxy_dct.keys()) > 0: self.last_id = max(self.proxy_dct.keys()) + 1 else: self.last_id = 0
def deserialize(self, data): from state import state self.name = data["name"] self.layer_type = data["layer_type"] self.adjacency_dct = {} for k, v in data["adjacency_dct"].iteritems(): self.adjacency_dct[int(k)] = v for p in data["proxys"]: if self.layer_type == LayerType.meta: m = Meta("", state.get_grid_step()) proxy = Proxy(sprite=m, state=state, data=p) m.name= str(proxy.id) m.update_text() else: proxy = Proxy(state=state, data=p) self.proxy_dct[proxy.id] = proxy #print "proxy_dct:", self.proxy_dct if len(self.proxy_dct.keys()) > 0: self.last_id = max(self.proxy_dct.keys())+1 else: self.last_id = 0
def get_new_meta(self): from state import state return Meta(str(self.last_id), state.get_grid_step())
def do_expose_event(self, event): # Create the cairo context #state.offset = (self.allocation.width/2,self.allocation.height/2) #state.set_screen_offset((self.allocation.width/2, self.allocation.height/2)) state.set_screen_offset((0, 0)) scale = state.get_scale() offset = state.get_offset() cr_gdk = self.window.cairo_create() surface = cr_gdk.get_target() size = state.get_map_size_px() cr_surf = cairo.ImageSurface(cairo.FORMAT_ARGB32, event.area.width, event.area.height) cr = cairo.Context(cr_surf) # Restrict Cairo to the exposed area; avoid extra work cr.rectangle(event.area.x, event.area.y, event.area.width, event.area.height) cr.clip() cr.set_source_rgb(1.0, 1.0, 1.0) cr.rectangle(0, 0, int(size[0]*scale[0]), int(size[1]*scale[1])) cr.fill() layers = state.get_layers() pointer = state.get_pointer_position() if len(layers) == 0: cr.set_source_rgb(0.1, 0.1, 0.1) f_size = 13 cr.set_font_size(f_size) text = "There is no layer yet, add one please" (x, y, width, height, dx, dy) = cr.text_extents(text) cr.move_to(self.allocation.width/2-width/2, self.allocation.height/2) cr.show_text(text); else: layer = state.get_active_layer() if state.get_put_layer_object(): lo = layer.get_selected_layer_object() cr.translate(offset[0]+pointer[0], offset[1]+pointer[1]) cr.scale(scale[0], scale[1]) lo.draw_preview(cr) cr.identity_matrix() for l in layers: cr.translate(offset[0], offset[1]) cr.scale(scale[0], scale[1]) if l == layer: l.draw(cr, 1.0) else: l.draw(cr, 0.8) cr.identity_matrix() cr.set_source_rgb(0, 0, 0) cr.set_line_width(0.1) cr.translate(offset[0], offset[1]) cr.scale(scale[0], scale[1]) grid_step = state.get_grid_step() for y in range(0, int(size[1]), grid_step[1]): cr.move_to(0, y) cr.line_to(size[0], y) for x in range(0, int(size[0]), grid_step[0]): cr.move_to(x, 0) cr.line_to(x, size[1]) cr.stroke() cr.identity_matrix() screen_size = state.get_screen_size() cr.set_source_rgba(0.5, 0.5, 0.5, 0.5) cr.rectangle(int(screen_size[0]*scale[0]), 0, event.area.width, event.area.height) cr.fill() cr.set_source_rgba(0.5, 0.5, 0.5, 0.5) cr.rectangle(0, int(screen_size[1]*scale[1]), event.area.width, event.area.height) cr.fill() sel_box = state.get_selection_box() if state.is_selection_mode(): sx = min(sel_box[0], sel_box[2]) ex = max(sel_box[0], sel_box[2]) sy = min(sel_box[1], sel_box[3]) ey = max(sel_box[1], sel_box[3]) w = ex - sx h = ey - sy sel_box = [sx, sy, w, h] #print "sel_box:", sel_box #print "offset:", offset, "scale:", scale cr.set_source_rgba(0.7, 0.7, 0.9, 0.5) cr.rectangle(int(sel_box[0]*scale[0]), int(sel_box[1]*scale[1]), int(sel_box[2]*scale[0]), int(sel_box[3]*scale[1])) cr.fill() cr_gdk.set_source_surface(cr_surf) cr_gdk.paint()
def screen_left_release(self, args): offset = state.get_offset() scale = state.get_scale() cx = (args[0][0]-offset[0])/scale[0] cy = (args[0][1]-offset[1])/scale[1] grid_step = state.get_grid_step() layer = state.get_active_layer() if layer != None: if state.is_selection_mode(): pass else: if state.get_put_layer_object(): state.unset_put_layer_object() nx = int(cx/grid_step[0])*grid_step[0] ny = int(cy/grid_step[1])*grid_step[1] pt = [nx, ny] layer.add_proxy(pt) self.update_layer_objects_list(None) proxy_lst = layer.get_proxy_lst() if state.get_shift_pressed(): for p in proxy_lst: if p.point_in_aabb([cx, cy]): if not p.get_selected(): self.general_set_selected_element({"lst": self.mw.lo_gtklist, "name": p.name, "element": p}) layer.add_proxy_to_selected(p) layer.set_ignore_next_selection_change() else: if p in self.relative_coords: del self.relative_coords[p] self.general_unselect_element({"lst": self.mw.lo_gtklist, "name": p.name}) layer.remove_proxy_from_selected(p) else: selected = None for p in proxy_lst: if p.point_in_aabb([cx, cy]): selected = p if selected != None: if selected.get_selected(): self.relative_coords = {} self.general_unselect_all_elements({"lst": self.mw.lo_gtklist}) print "click" layer.unselect_all_proxys() else: self.relative_coords = {} self.general_set_selected_element({"lst": self.mw.lo_gtklist, "name": selected.name, "element": selected}) layer.add_proxy_to_selected(p) layer.set_ignore_next_selection_change() self.mw.widget.update() selected_proxys = layer.get_selected_proxys() if len(selected_proxys) == 2: if layer.get_layer_type() == LayerType.meta: self.mw.layer_set_child_button.set_sensitive(True) self.relative_coords = {} for p in selected_proxys: self.relative_coords[p] = utils.mk_vect((cx, cy), p.get_position()) state.unset_left_press_start()
def screen_left_release(self, args): offset = state.get_offset() scale = state.get_scale() cx = (args[0][0] - offset[0]) / scale[0] cy = (args[0][1] - offset[1]) / scale[1] grid_step = state.get_grid_step() layer = state.get_active_layer() if layer != None: if state.is_selection_mode(): pass else: if state.get_put_layer_object(): state.unset_put_layer_object() nx = int(cx / grid_step[0]) * grid_step[0] ny = int(cy / grid_step[1]) * grid_step[1] pt = [nx, ny] layer.add_proxy(pt) self.update_layer_objects_list(None) proxy_lst = layer.get_proxy_lst() if state.get_shift_pressed(): for p in proxy_lst: if p.point_in_aabb([cx, cy]): if not p.get_selected(): self.general_set_selected_element({ "lst": self.mw.lo_gtklist, "name": p.name, "element": p }) layer.add_proxy_to_selected(p) layer.set_ignore_next_selection_change() else: if p in self.relative_coords: del self.relative_coords[p] self.general_unselect_element({ "lst": self.mw.lo_gtklist, "name": p.name }) layer.remove_proxy_from_selected(p) else: selected = None for p in proxy_lst: if p.point_in_aabb([cx, cy]): selected = p if selected != None: if selected.get_selected(): self.relative_coords = {} self.general_unselect_all_elements( {"lst": self.mw.lo_gtklist}) print "click" layer.unselect_all_proxys() else: self.relative_coords = {} self.general_set_selected_element({ "lst": self.mw.lo_gtklist, "name": selected.name, "element": selected }) layer.add_proxy_to_selected(p) layer.set_ignore_next_selection_change() self.mw.widget.update() selected_proxys = layer.get_selected_proxys() if len(selected_proxys) == 2: if layer.get_layer_type() == LayerType.meta: self.mw.layer_set_child_button.set_sensitive(True) self.relative_coords = {} for p in selected_proxys: self.relative_coords[p] = utils.mk_vect((cx, cy), p.get_position()) state.unset_left_press_start()
def get_new_meta(self): from state import state return Meta(str(self.last_id), state.get_grid_step())