From: <Ult...@us...> - 2009-04-04 20:42:33
|
Revision: 1131 http://opengate.svn.sourceforge.net/opengate/?rev=1131&view=rev Author: Ultrasick Date: 2009-04-04 20:42:20 +0000 (Sat, 04 Apr 2009) Log Message: ----------- fixed some bugs Modified Paths: -------------- branches/ogEditor/data/modules/texturizer/scripts/main/textures.py branches/ogEditor/data/modules/texturizer/scripts/screens/project/face_editor/frames/layers.py branches/ogEditor/data/modules/texturizer/scripts/screens/project/face_editor/frames/view_the_face.py Modified: branches/ogEditor/data/modules/texturizer/scripts/main/textures.py =================================================================== --- branches/ogEditor/data/modules/texturizer/scripts/main/textures.py 2009-04-02 19:07:04 UTC (rev 1130) +++ branches/ogEditor/data/modules/texturizer/scripts/main/textures.py 2009-04-04 20:42:20 UTC (rev 1131) @@ -12,7 +12,7 @@ def initialize(self): # select the right object as the drawing area - self.drawing_area = screen.preview.preview.window + self.drawing_area = screen.canvas.preview.window # save the blue self.drawing_area.colors['#00013C'] = self.drawing_area.new_gc(foreground = self.drawing_area.get_colormap().alloc_color(gtk.gdk.color_parse('#00013C'))) @@ -32,8 +32,8 @@ class panels: def initialize_step_1(self): - # don't reload the preview image for now - screen.preview.preview.handler_block(screen.preview.refresh_id) + # don't reload the image of the canvas for now + screen.canvas.preview.handler_block(screen.canvas.refresh_id) # create an array for the faces of the bounding box faces = [] @@ -254,7 +254,7 @@ def get_color(self, vertice, face): # select the right object as the drawing area - self.drawing_area = screen.preview.preview.window + self.drawing_area = screen.canvas.preview.window # select the color map self.color_map = self.drawing_area.get_colormap() @@ -426,12 +426,12 @@ # store the pixels model['textures']['Tauseti']['dark background']['z_max'] = file_selection_window.return_value - # make the preview image reload again - screen.preview.preview.handler_unblock(screen.preview.refresh_id) + # make the image of the canvas reload again + screen.canvas.preview.handler_unblock(screen.canvas.refresh_id) def get_color(self, vertice, face): # select the right object as the drawing area - self.drawing_area = screen.preview.preview.window + self.drawing_area = screen.canvas.preview.window # select the color map self.color_map = self.drawing_area.get_colormap() Modified: branches/ogEditor/data/modules/texturizer/scripts/screens/project/face_editor/frames/layers.py =================================================================== --- branches/ogEditor/data/modules/texturizer/scripts/screens/project/face_editor/frames/layers.py 2009-04-02 19:07:04 UTC (rev 1130) +++ branches/ogEditor/data/modules/texturizer/scripts/screens/project/face_editor/frames/layers.py 2009-04-04 20:42:20 UTC (rev 1131) @@ -29,24 +29,28 @@ # get the path to the selected row row_path = treeview.get_cursor()[0] - # get the treestore - treestore = screen.layers_used.treestore + # get the treemodel + treemodel = treeview.get_model() # get the "iter" to the selected row - row_iter = treestore.get_iter(row_path) + row_iter = treemodel.get_iter(row_path) # get the caption of the selected row - row_caption = treestore.get_value(row_iter, 0) + row_caption = treemodel.get_value(row_iter, 0) - # split the caption - row_caption = row_caption.split(' - ') + if '-' in row_caption: + # split the caption + row_caption = row_caption.split(' - ') - # get the category name and the texture name - self.category_name = row_caption[0] - self.texture_name = row_caption[1] + # get the category name and the texture name + self.category_name = row_caption[0] + self.texture_name = row_caption[1] - # update the preview image - self.preview.set_from_file(path[0] + '/graphic/textures/preview/' + self.category_name.lower().replace(' ', '_') + '/' + self.texture_name.lower().replace(' ', '_') + '.png') + # update the preview image + self.preview.set_from_file(path[0] + '/graphic/textures/preview/' + self.category_name.lower().replace(' ', '_') + '/' + self.texture_name.lower().replace(' ', '_') + '.png') + else: + # clear the preview image + self.preview.clear() screen.layer_preview = layer_preview(table) @@ -68,6 +72,8 @@ # connect the functions self.treeview.connect('cursor-changed', screen.layer_preview.refresh) self.treeview.connect('row-activated', self.remove) + self.treeview.connect('drag-begin', lambda x, y: screen.canvas.deactivate()) + self.treeview.connect('drag-end', self.get_new_list_order) # show "used layers:" self.column = gtk.TreeViewColumn('used layers:') @@ -81,25 +87,23 @@ # refresh the list self.refresh(true) - def remove(self, treeview, row_path, column): - # get the "iter" to the selected row - row_iter = self.treestore.get_iter(row_path) + def get_new_list_order(self, treeview, drag_context): + # create an array for the used masks + used_masks = {} - # get the caption of the selected row - row_caption = self.treestore.get_value(row_iter, 0) + for layer in self.face['layers']: + if type(layer)==dict: + used_masks[layer['number']] = layer - # get the index of the layer - layer_index = self.face['layers'].index(row_caption) + # reset the layers array + self.face['layers'] = [] - # remove the layer - del(self.face['layers'][layer_index]) + # store the entry + self.treestore.foreach(self.store_list_entry, used_masks) - # refresh the list - self.refresh() + # reactivate the redrawing of the image of the canvas + screen.canvas.reactivate() - # clear the preview image - screen.layer_preview.preview.clear() - def refresh(self, fast = false): # clear the list self.treestore.clear() @@ -115,9 +119,85 @@ self.treestore.append(mask, [child]) if fast==false: - # update the big preview image - screen.preview.draw() + # update the big image on the canvas + screen.canvas.draw() + def remove(self, treeview, row_path, column): + # get the "iter" to the selected row + row_iter = self.treestore.get_iter(row_path) + + # get the caption of the selected row + row_caption = self.treestore.get_value(row_iter, 0) + + if row_caption[:4]=='mask': + # get the mask number + mask_number = int(row_caption[6:]) + + for layer_index, layer_content in enumerate(self.face['layers']): + if type(layer_content)==str: + continue + + if layer_content['number']==mask_number: + # remove the layer from the array + del(self.face['layers'][layer_index]) + + break + else: + try: + # get the index of the layer + layer_index = self.face['layers'].index(row_caption) + + # remove the layer from the array + del(self.face['layers'][layer_index]) + except: + for layer_index, layer_content in enumerate(self.face['layers']): + if type(layer_content)==str: + continue + + try: + child_index = layer_content['children'].index(row_caption) + + # remove the layer from the array + del(self.face['layers'][layer_index]['children'][child_index]) + + break + except: + pass + + # refresh the list + self.refresh() + + # clear the preview image + screen.layer_preview.preview.clear() + + def store_list_entry(self, treemodel, row_path, row_iter, used_masks): + # get the caption of the current row + row_caption = treemodel.get_value(row_iter, 0) + + # work-around for a bug in GTk+ + if row_caption==none: + return + + # get the iter of the parent + parent_iter = treemodel.iter_parent(row_iter) + + # check if this entry has a parent + if parent_iter==none: + if '-' in row_caption: + self.face['layers'].append(row_caption) + else: + # get the mask number + mask_number = row_caption[6:] + + # store the mask + self.face['layers'].append({'number' : int(mask_number), 'triangles' : used_masks[int(mask_number)]['triangles'], 'children' : []}) + else: + # get the index of parent + parent_index = len(self.face['layers']) - 1 + + # store the texture + self.face['layers'][parent_index]['children'].append(row_caption) + screen.layers_used = layers_used(table) class tools: Modified: branches/ogEditor/data/modules/texturizer/scripts/screens/project/face_editor/frames/view_the_face.py =================================================================== --- branches/ogEditor/data/modules/texturizer/scripts/screens/project/face_editor/frames/view_the_face.py 2009-04-02 19:07:04 UTC (rev 1130) +++ branches/ogEditor/data/modules/texturizer/scripts/screens/project/face_editor/frames/view_the_face.py 2009-04-04 20:42:20 UTC (rev 1131) @@ -12,7 +12,7 @@ frame.add(table) table.show() -class preview: +class canvas: def __init__(self, parent): # show preview image self.preview = gtk.DrawingArea() @@ -21,7 +21,7 @@ self.preview.show() # set autoredraw - self.refresh_id = self.preview.connect('expose_event', self.draw) + self.refresh_id = self.preview.connect('expose_event', lambda x, y: self.draw()) # select the right object as the drawing area self.drawing_area = self.preview.window @@ -50,7 +50,22 @@ # get the planes of the triangles self.get_planes() - def draw(self, widget = none, event = none): + def center_position(self, x, y): + # center the coordinates + x += self.x_center + y += self.y_center + + # round the coordinates + x = int(round(x)) + y = int(round(y)) + + return (x, y) + + def deactivate(self): + # don't redraw the image for now + self.preview.handler_block(self.refresh_id) + + def draw(self): # clear the drawing area self.drawing_area.clear() @@ -58,11 +73,11 @@ self.draw_border() # insert the layers - for layer in self.face['layers']: + for layer in self.face['layers'][::-1]: if type(layer)==str: self.draw_texture(layer) else: - for child in layer['children']: + for child in layer['children'][::-1]: self.draw_texture(child) def draw_border(self): @@ -197,19 +212,15 @@ return (vector_x, vector_y) - def center_position(self, x, y): - # center the coordinates - x += self.x_center - y += self.y_center + def reactivate(self): + # redraw the image + self.draw() - # round the coordinates - x = int(round(x)) - y = int(round(y)) + # redraw the image again + self.preview.handler_unblock(self.refresh_id) - return (x, y) +screen.canvas = canvas(table) -screen.preview = preview(table) - class tools: def __init__(self, parent): # create an empty toolbar This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |