def on_touch_move(self, touch): if self.collide_point(*touch.pos): pos = [min(touch.pos[n], touch.opos[n]) for n in [0, 1]] size = [abs(touch.pos[n] - touch.opos[n]) for n in [0, 1]] if self.drawing_rectangle is None: self.drawing_rectangle = SelectionBox(pos=pos, size=size, image_pane=self) self.add_new_rectangle(self.drawing_rectangle) else: self.drawing_rectangle.pos = pos self.drawing_rectangle.size = size
class ImagePane(Image): drawing_rectangle = None rectangles = [] def __init__(self, **kwargs): super(ImagePane, self).__init__(**kwargs) self.register_event_type('on_store_rectangles') def on_store_rectangles(self, *args, **kwargs): pass def on_touch_move(self, touch): if self.collide_point(*touch.pos): pos = [min(touch.pos[n], touch.opos[n]) for n in [0, 1]] size = [abs(touch.pos[n] - touch.opos[n]) for n in [0, 1]] if self.drawing_rectangle is None: self.drawing_rectangle = SelectionBox(pos=pos, size=size, image_pane=self) self.add_new_rectangle(self.drawing_rectangle) else: self.drawing_rectangle.pos = pos self.drawing_rectangle.size = size def on_touch_up(self, touch): if self.drawing_rectangle: self.drawing_rectangle.compute_unit_coordinates() self.drawing_rectangle = None self.store_rectangles() def add_new_rectangle(self, rect): self.add_widget(rect) self.rectangles.append(rect) def delete_last_rectangle(self): if self.rectangles: bad_rectangle = self.rectangles.pop() self.remove_widget(bad_rectangle) self.store_rectangles() def clear_rectangles(self): self.rectangles = [] self.clear_widgets() def store_rectangles(self): self.dispatch('on_store_rectangles', rectangles=self.rectangles) def redraw_rectangles(self): for rect in self.rectangles: rect.compute_screen_coordinates()
def __init__(self, menu, sprites=[]): MenuState.__init__(self, menu, sprites) self.sprites = [self.fileNameLabel, self.miniMap] self.buttons = [] self.panel = StaticImage(loadImage("devmenu.png", 2), (10, 10)) self.addSprite(self.panel) self.addBoundButton = AddBoundaryButton(self) self.addButton(self.addBoundButton) self.removeBoundButton = RemoveBoundaryButton(self) self.addButton(self.removeBoundButton) self.snapToGridButton = SnapToGridButton(self) self.addButton(self.snapToGridButton) self.buttonSelectionBox = SelectionBox(self.addBoundButton.rect, self) self.addSprite(self.buttonSelectionBox) self.gridButtonSelectionBox = None self.addingMode = True self.removingMode = False self.curStart = None tmpGrdRect = self.menu.playState.floor.tileSet.getTiles( )[0].image.get_rect() self.gridX, self.gridY = tmpGrdRect.w, tmpGrdRect.h self.snapToGrid = False
def addMode(self): self.addingMode = True self.removingMode = False self.removeSprite(self.buttonSelectionBox) self.buttonSelectionBox = SelectionBox(self.addBoundButton.rect, self) self.addSprite(self.buttonSelectionBox) self.menu.loadMenuState(self)
def applySelectionBox( self, button ): if self.tileSelectionBox in self.sprites: self.removeSprite( self.tileSelectionBox ) self.tileSelectionBox = SelectionBox( button.rect, self ) self.addSprite( self.tileSelectionBox ) self.curSelectedButton = button self.menu.loadMenuState( self )
def toggleHardBlit( self ): self.hardBlit = not self.hardBlit if self.hardBlitSelectionBox is None: self.hardBlitSelectionBox = SelectionBox( self.hardBlitButton.rect, self ) self.addSprite( self.hardBlitSelectionBox ) else: self.removeSprite( self.hardBlitSelectionBox ) self.hardBlitSelectionBox = None self.menu.loadMenuState( self )
def toggleSnapToGrid( self ): self.snapToGrid = not self.snapToGrid if self.gridButtonSelectionBox is None: self.gridButtonSelectionBox = SelectionBox( self.snapToGridButton.rect, self ) self.addSprite( self.gridButtonSelectionBox ) else: self.removeSprite( self.gridButtonSelectionBox ) self.gridButtonSelectionBox = None self.menu.loadMenuState( self )
def toggleRemove(self): self.removingMode = not self.removingMode if self.removeButtonSelectionBox is None: self.removeButtonSelectionBox = SelectionBox( self.removeButton.rect, self) self.addSprite(self.removeButtonSelectionBox) else: self.removeSprite(self.removeButtonSelectionBox) self.removeButtonSelectionBox = None self.menu.loadMenuState(self)
def toggleGridFill(self): self.gridFill = not self.gridFill if self.gridFillButtonSelectionBox is None: self.gridFillButtonSelectionBox = SelectionBox( self.gridFillButton.rect, self) self.addSprite(self.gridFillButtonSelectionBox) else: self.removeSprite(self.gridFillButtonSelectionBox) self.gridFillButtonSelectionBox = None self.menu.loadMenuState(self)
def toggleSensor(self): self.sensorMode = not self.sensorMode if self.sensorButtonSelectionBox is None: self.sensorButtonSelectionBox = SelectionBox( self.sensorButton.rect, self) self.addSprite(self.sensorButtonSelectionBox) self.carryMeOverSprites.append(self.sensorButtonSelectionBox) else: self.carryMeOverSprites.remove(self.sensorButtonSelectionBox) self.removeSprite(self.sensorButtonSelectionBox) self.sensorButtonSelectionBox = None self.menu.loadMenuState(self)
def load_rectangles(self): self.all_rectangles = {} try: with open(self.rectangles_filename) as fd: all_rectangles_dict = json.load(fd) for book_id, book_rectangles in all_rectangles_dict.items(): self.all_rectangles[book_id] = {} for page, rectangles in book_rectangles.items(): self.all_rectangles[book_id][page] = \ [SelectionBox(image_pane=self.image_pane, **rect) for rect in rectangles] except IOError: print("Can't find rectangles file!")
def push(self, clickKey, click): """This method sets the parent state (which should always be EntityEditState)\n""" \ """ to be using this Button's given entity in the Entity-placing functionality.""" if clickKey is 'mouse1up': #print self.entNum if self.parentState.selectedButton is self: return None self.parentState.selectedButton = self self.parentState.entNum = self.entNum self.parentState.removeSprite(self.parentState.entSelectionBox) self.parentState.entSelectionBox = SelectionBox( self.rect, self.parentState) self.parentState.addSprite(self.parentState.entSelectionBox) self.parentState.menu.loadMenuState(self.parentState)
def __init__(self, menu, sprites=[]): MenuState.__init__(self, menu, sprites) self.entNum = 0 self.sprites = [self.fileNameLabel, self.miniMap] self.buttons = [] self.panel = StaticImage(loadImage("devmenu.png", 2), (10, 10)) self.addSprite(self.panel) self.scrollNextButton = ScrollNextButton(self) self.addButton(self.scrollNextButton) self.scrollBackButton = ScrollBackButton(self) self.addButton(self.scrollBackButton) self.snapToGridButton = SnapToGridButtonEnt(self) self.addButton(self.snapToGridButton) self.gridFillButton = GridFillButtonEnt(self) self.addButton(self.gridFillButton) self.curEntNum = 0 self.xPos = 0 self.yPos = 0 self.tallest = 0 self.processedEnts = [] self.pages = {0: []} self.curPage = 0 self.maxPage = 0 self.generateButtons() self.snapToGrid = False self.gridButtonSelectionBox = None self.gridFill = False self.gridFillButtonSelectionBox = None self.gridFillStart = None self.selectedButton = self.buttons[self.entNum + 4] self.entSelectionBox = SelectionBox(self.selectedButton.rect, self) self.addSprite(self.entSelectionBox) self.curGrabbedEnt = None self.lastMouseSpot = (0, 0) self.whereEntWasGrabbed = None
def __init__( self, menu, sprites=[] ): MenuState.__init__( self, menu, sprites ) self.buttons = [] self.sprites = [self.fileNameLabel, self.miniMap] self.panel = StaticImage( loadImage( "devmenu.png", 2 ), ( 10, 10 ) ) self.addSprite( self.panel ) self.undoButton = UndoButton( self ) self.addButton( self.undoButton ) self.redoButton = RedoButton( self ) self.addButton( self.redoButton ) self.scrollNextButton = ScrollNextButtonTiles( self ) self.addButton( self.scrollNextButton ) self.scrollBackButton = ScrollBackButtonTiles( self ) self.addButton( self.scrollBackButton ) self.removeFloorButton = RemoveFloorButton( self ) self.addButton( self.removeFloorButton ) self.addFloorButton = AddFloorButton( self ) self.addButton( self.addFloorButton ) self.editFloorButton = EditFloorButton( self ) self.addButton( self.editFloorButton ) self.topLeftLayerClamp = TopLeftLayerClamp( self ) self.bottomRightLayerClamp = BottomRightLayerClamp( self ) self.snapToGridButton = SnapToGridButtonFloor( self ) self.addButton( self.snapToGridButton ) self.hardBlitButton = HardBlitButton( self ) self.addButton( self.hardBlitButton ) #A local copy to prevent excessive look ups. self.floor = self.menu.playState.floor self.currentFloorLayer = 0 self.currentLayerIsGrabbed = False self.grabPoint = None self.snapToGrid = False self.gridButtonSelectionBox = None self.hardBlit = False self.hardBlitSelectionBox = None self.currentlyGrabbedClamp = None #Edit modes are zero for tiles, 1 for creating/editing layers, 2 for select/edit, and 3 for removing self.editMode = 0 self.tileNum = 0 self.tileFillRect = None self.xPos = 0 self.yPos = 0 self.tallest = 0 self.pages = {0:[]} self.curPage = 0 self.processedTiles = [] self.generateButtons() #For the tile placing functionality. self.startOfBlock = None self.tileSelectionBox = SelectionBox( self.pages[self.curPage][0].rect, self ) self.addSprite( self.tileSelectionBox ) self.curSelectedButton = self.pages[self.curPage][0] self.gridX, self.gridY = self.curSelectedButton.rect.w, self.curSelectedButton.rect.h self.setClamps()