def on_mouse_press_left(self, event): """ Evento tasto sinistro del mouse premuto :param event: """ if DEBUG: print("on_mouse_press_left") # se non è stato aperto un livello non fa niente event.Skip() if self.__current_mode == MODE_NONE: return # se sono sulla griglia if Griglia.is_on_grid(self.mouse_pos): # click sulla griglia p = Griglia.get_index_from_mouse(self.mouse_pos) # se sono in modalità EDIT, inserisce la modalità PAINT # veifica che la postazione sia libera e che sia stato selezionato un colore # crea un nuovo brick if self.__current_mode == MODE_EDIT: self.__current_mode = MODE_PAINTING self.statusbar_set_text("Modalità PAINTING") if DEBUG: print("Modalità PAINTING") tipo, colore = self.parent.get_brick_select() if self.__level.is_position_free( p) and colore is not None: # paint self.new_brick() # se sono nella modalità MOVE, inserisce la modalità DRAGGING # salva le informazioni self.__drag_drop elif self.__current_mode == MODE_MOVE and not self.__level.is_position_free( p): # drag and drop self.__current_mode = MODE_DRAGGING self.statusbar_set_text("Modalità DRAGGING") if DEBUG: print("Modalità DRAGGING") brk = self.__level.take_brick(p) x, y = brk.get_position_on_screen() self.__drag_drop = dict(brk=brk, idx_old=p, offset_x=abs(self.mouse_pos[0] - x), offset_y=abs(self.mouse_pos[1] - y)) # se sono in modalità DELETE, inserisce la modalita ERESING # cancella il brick elif self.__current_mode == MODE_DELETE: # cancella self.__current_mode = MODE_ERASING self.statusbar_set_text("Modalità ERESING") if DEBUG: print("Modalità ERESING") self.delete_brick() # se sono in modalità SELECT, seleziona o deseleziona il brick elif self.__current_mode == MODE_SELECT: pos = Griglia.get_xy_from_mouse(self.mouse_pos) if not self.__select_brick[ 'idx'] == -1 and self.is_equal_position( pos, self.__select_brick['xy']): self.select_none() else: self.select_brick(p)
def on_mouse_release_left(self, event): """ Evento tasto sinistro del mouse rilasciato :param event: """ if DEBUG: print("on_mouse_release_left") event.Skip() # se non è stato aperto un livello non fa niente if self.__current_mode == MODE_NONE: return # se sono in modalità DRAGGING, torno alla modalità MOVE # se sono sulla griglia e la posizione è libera, aggiorno le proprietà del brick, # altrimenti setta idx al vecchio indice dell'array # posiziona il brick all'indice corretto, cancella la struttura self.__drag_drop if self.__current_mode == MODE_DRAGGING: self.__current_mode = MODE_MOVE self.statusbar_set_text("Modalità MOVE ripristinata ") if DEBUG: print("Modalità MOVE ripristinata ") idx = Griglia.get_index_from_mouse(self.mouse_pos) if Griglia.is_on_grid( self.mouse_pos) and self.__level.is_position_free(idx): xy = Griglia.get_xy_from_mouse(self.mouse_pos) rc = Griglia.get_row_column_from_mouse(self.mouse_pos) # aggiorna la coda undo con l'operazione eseguita log = (ID_MOVE, idx, self.__drag_drop['idx_old'], self.__drag_drop['brk'], xy, self.__drag_drop['brk'].get_position_on_screen(), rc, self.__drag_drop['brk'].get_position_on_grid()) self.__queue_log.put_undo(log) self.__queue_log.clear_redo() if DEBUG: print("log: " + str(log)) self.__drag_drop['brk'].change_pos(xy, rc) self.__level.set_context_modified() self.statusbar_set_text("Il brick è stato spostato") else: idx = self.__drag_drop['idx_old'] self.__level.put_brick(self.__drag_drop['brk'], idx) self.__drag_drop = None # se sono in modalità ERASING, torno in modalità DELETE elif self.__current_mode == MODE_ERASING: self.__current_mode = MODE_DELETE if DEBUG: print("Modalità DELETE ripristinata ") self.statusbar_set_text("Modalità DELETE ripristinata") # se sono in modalità PAINT, torno in modalità EDIT elif self.__current_mode == MODE_PAINTING: self.__current_mode = MODE_EDIT if DEBUG: print("Modalità EDIT ripristinata ") self.statusbar_set_text("Modalità EDIT ripristinata")
def on_mouse_press_right(self, event): """ Evento tasto destro del mouse premuto :param event: :return: """ if DEBUG: print("on_mouse_press_right") # se non è stato aperto un livello non fa niente if self.__current_mode == MODE_NONE: return # se sono sulla griglia seleziono la casella e apro il menu a tendina if Griglia.is_on_grid(self.mouse_pos): p = Griglia.get_index_from_mouse(self.mouse_pos) self.select_brick(p) self.PopupMenu(MyPopupMenu(self), event.GetPosition())
def delete_brick(self): """ cancella il brick sotto il puntatore del mouse :return """ if DEBUG: print("delete_brick") # se non è stato creato un livello non fa niente if self.__current_mode == MODE_NONE: return p = Griglia.get_index_from_mouse(self.mouse_pos) brk = self.__level.delete_brick(p) if brk is not None: brk = brk.copy_brk() self.__level.set_context_modified() # aggiorna la coda undo con l'operazione eseguita log = (ID_DELETE, p, brk) self.__queue_log.put_undo(log) self.statusbar_set_text("Brick cancellato") if DEBUG: print("log: " + str(log))