Created
May 26, 2014 20:21
-
-
Save apocalyptech/84916102e2afa9582e29 to your computer and use it in GitHub Desktop.
Eschalon rectangle selection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/eschalon/mapgui.py b/eschalon/mapgui.py | |
index 78c098a..6fa5eee 100644 | |
--- a/eschalon/mapgui.py | |
+++ b/eschalon/mapgui.py | |
@@ -1187,6 +1187,10 @@ class MapGUI(BaseGUI): | |
self.MODE_SCRIPT_ED: None, | |
self.MODE_COPY: gtk.gdk.Cursor(gtk.gdk.BASED_ARROW_UP), | |
} | |
+ self.selection_1 = None | |
+ self.selection_2 = None | |
+ self.selection_nw = None | |
+ self.selection_se = None | |
# Initialize item stuff | |
self.curitemcategory = self.ITEM_MAP | |
@@ -4431,6 +4435,64 @@ class MapGUI(BaseGUI): | |
if (event.button not in self.mouse_action_maps[self.edit_mode]): | |
return | |
+ cur_sel_1 = self.selection_1 | |
+ cur_sel_2 = self.selection_2 | |
+ cur_sel_nw = self.selection_nw | |
+ cur_sel_se = self.selection_se | |
+ if self.selection_1 is None and self.selection_2 is None: | |
+ self.selection_1 = (self.tile_x, self.tile_y) | |
+ elif self.selection_1 is not None and self.selection_2 is None: | |
+ self.selection_2 = (self.tile_x, self.tile_y) | |
+ sel_1_even = ((self.selection_1[1] % 2) == 0) | |
+ sel_2_even = ((self.selection_2[1] % 2) == 0) | |
+ comp_x = (self.selection_1[0], self.selection_2[0]) | |
+ if sel_1_even == sel_2_even: | |
+ comp_y_nw = (self.selection_1[1], self.selection_2[1]) | |
+ comp_y_se = (self.selection_1[1], self.selection_2[1]) | |
+ else: | |
+ if sel_1_even: | |
+ comp_y_nw = (self.selection_1[1], self.selection_2[1]-1) | |
+ comp_y_se = (self.selection_1[1]+1, self.selection_2[1]) | |
+ else: | |
+ comp_y_nw = (self.selection_1[1]-1, self.selection_2[1]) | |
+ comp_y_se = (self.selection_1[1], self.selection_2[1]+1) | |
+ self.selection_nw = (min(comp_x), min(comp_y_nw)) | |
+ self.selection_se = (max(comp_x), max(comp_y_se)) | |
+ | |
+ sel_nw_even = ((self.selection_nw[1] % 2) == 0) | |
+ sel_se_even = ((self.selection_se[1] % 2) == 0) | |
+ if sel_nw_even != sel_se_even: | |
+ if sel_nw_even: | |
+ self.selection_se = (self.selection_se[0]+1, self.selection_se[1]+1) | |
+ else: | |
+ self.selection_nw = (self.selection_nw[0], self.selection_nw[0]-1) | |
+ else: | |
+ self.selection_1 = None | |
+ self.selection_2 = None | |
+ self.selection_nw = None | |
+ self.selection_se = None | |
+ if self.selection_1 != cur_sel_1: | |
+ if cur_sel_1 is not None: | |
+ self.redraw_tile(cur_sel_1[0], cur_sel_1[1]) | |
+ if self.selection_1 is not None: | |
+ self.redraw_tile(self.selection_1[0], self.selection_1[1]) | |
+ if self.selection_2 != cur_sel_2: | |
+ if cur_sel_2 is not None: | |
+ self.redraw_tile(cur_sel_2[0], cur_sel_2[1]) | |
+ if self.selection_2 is not None: | |
+ self.redraw_tile(self.selection_2[0], self.selection_2[1]) | |
+ if self.selection_nw != cur_sel_nw: | |
+ if cur_sel_nw is not None: | |
+ self.redraw_tile(cur_sel_nw[0], cur_sel_nw[1]) | |
+ if self.selection_nw is not None: | |
+ self.redraw_tile(self.selection_nw[0], self.selection_nw[1]) | |
+ if self.selection_se != cur_sel_se: | |
+ if cur_sel_se is not None: | |
+ self.redraw_tile(cur_sel_se[0], cur_sel_se[1]) | |
+ if self.selection_se is not None: | |
+ self.redraw_tile(self.selection_se[0], self.selection_se[1]) | |
+ return | |
+ | |
action = self.mouse_action_maps[self.edit_mode][event.button] | |
if (action == self.ACTION_DRAG): | |
adjust = self.mainscroll.get_hadjustment() | |
@@ -5150,17 +5212,31 @@ class MapGUI(BaseGUI): | |
tile_ctx.set_source_surface(self.basictile) | |
tile_ctx.paint() | |
- # Draw Barrier Highlights | |
- if (drawbarrier): | |
- self.composite_simple(op_ctx, op_surf, barrier) | |
+ # Testing selections | |
+ selection = None | |
+ if self.selection_nw is not None and self.selection_nw[0] == x and self.selection_nw[1] == y: | |
+ selection = (0, 1, 0, 0.5) | |
+ if self.selection_se is not None and self.selection_se[0] == x and self.selection_se[1] == y: | |
+ selection = (0, 1, 0, 0.5) | |
+ if self.selection_1 is not None and self.selection_1[0] == x and self.selection_1[1] == y: | |
+ selection = (1, 0, 0, 0.5) | |
+ if self.selection_2 is not None and self.selection_2[0] == x and self.selection_2[1] == y: | |
+ selection = (1, 0, 0, 0.5) | |
+ | |
+ if (selection): | |
+ self.composite_simple(op_ctx, op_surf, selection) | |
+ else: | |
+ # Draw Barrier Highlights | |
+ if (drawbarrier): | |
+ self.composite_simple(op_ctx, op_surf, barrier) | |
- # Draw Tilecontent Highlights | |
- if (drawtilecontent): | |
- self.composite_simple(op_ctx, op_surf, tilecontent) | |
+ # Draw Tilecontent Highlights | |
+ if (drawtilecontent): | |
+ self.composite_simple(op_ctx, op_surf, tilecontent) | |
- # Draw Entity Highlights | |
- if (drawentity): | |
- self.composite_simple(op_ctx, op_surf, entity) | |
+ # Draw Entity Highlights | |
+ if (drawentity): | |
+ self.composite_simple(op_ctx, op_surf, entity) | |
# Now draw the pixbuf onto our pixmap | |
if (do_main_paint): |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment