From 480d87215c6667ccf1ea837409965cd7671d3169 Mon Sep 17 00:00:00 2001 From: amartin Date: Wed, 08 Aug 2007 08:11:33 +0000 Subject: Jam drawing fixes --- (limited to 'Jam') diff --git a/Jam/Block.py b/Jam/Block.py index d2b30a8..dff54bf 100644 --- a/Jam/Block.py +++ b/Jam/Block.py @@ -162,20 +162,20 @@ class Block(): self.owner.invalidate_rect( self.x, self.y, self.width, self.height, base ) def draw( self, startX, startY, stopX, stopY, pixmap ): - if stopY < self.y or startY > self.endY: + if stopY <= self.y or startY >= self.endY: return False self._drawB( startX, startY, stopX, stopY, pixmap ) def _drawB( self, startX, startY, stopX, stopY, pixmap ): - if stopX < self.x: + if stopX <= self.x: return False if self.child: self.child._drawB( startX, startY, stopX, stopX, pixmap ) - if startX > self.endX: + if startX >= self.endX: return False self._doDraw( startX, startY, stopX, stopY, pixmap ) @@ -206,17 +206,24 @@ class Instrument(Block): pass def _doDraw( self, startX, startY, stopX, stopY, pixmap ): + x = max( startX, self.x ) + y = max( startY, self.y ) + endX = min( stopX, self.endX ) + endY = min( stopY, self.endY ) + width = endX - x + height = endY - y + # draw border if self.active: self.gc.foreground = self.owner.colors["Border_Active"] else: self.gc.foreground = self.owner.colors["Border_Inactive"] self.gc.set_clip_origin( self.x-Instrument.MASK_START, self.y ) - pixmap.draw_rectangle( self.gc, True, self.x, self.y, self.width, self.height ) + pixmap.draw_rectangle( self.gc, True, x, y, width, height ) # draw block if self.active: self.gc.foreground = self.owner.colors["Bg_Active"] else: self.gc.foreground = self.owner.colors["Bg_Inactive"] self.gc.set_clip_origin( self.x-Instrument.MASK_START, self.y-self.height ) - pixmap.draw_rectangle( self.gc, True, self.x, self.y, self.width, self.height ) + pixmap.draw_rectangle( self.gc, True, x, y, width, height ) def drawHighlight( self, startX, startY, stopX, stopY, pixmap ): self.gc.foreground = self.owner.colors["Border_Highlight"] @@ -240,17 +247,24 @@ class Drum(Block): pass def _doDraw( self, startX, startY, stopX, stopY, pixmap ): + x = max( startX, self.x ) + y = max( startY, self.y ) + endX = min( stopX, self.endX ) + endY = min( stopY, self.endY ) + width = endX - x + height = endY - y + # draw border if self.active: self.gc.foreground = self.owner.colors["Border_Active"] else: self.gc.foreground = self.owner.colors["Border_Inactive"] self.gc.set_clip_origin( self.x-Drum.MASK_START, self.y ) - pixmap.draw_rectangle( self.gc, True, self.x, self.y, self.width, self.height ) + pixmap.draw_rectangle( self.gc, True, x, y, width, height ) # draw block if self.active: self.gc.foreground = self.owner.colors["Bg_Active"] else: self.gc.foreground = self.owner.colors["Bg_Inactive"] self.gc.set_clip_origin( self.x-Drum.MASK_START, self.y-self.height ) - pixmap.draw_rectangle( self.gc, True, self.x, self.y, self.width, self.height ) + pixmap.draw_rectangle( self.gc, True, x, y, width, height ) def drawHighlight( self, startX, startY, stopX, stopY, pixmap ): self.gc.foreground = self.owner.colors["Border_Highlight"] @@ -289,70 +303,98 @@ class Loop(Block): pass def _doDraw( self, startX, startY, stopX, stopY, pixmap ): + y = max( startY, self.y ) + endY = min( stopY, self.endY ) + height = endY - y #-- draw head ----------------------------------------- - # draw border - if self.active: self.gc.foreground = self.owner.colors["Border_Active"] - else: self.gc.foreground = self.owner.colors["Border_Inactive"] - self.gc.set_clip_origin( self.x-Loop.MASK_START, self.y ) - pixmap.draw_rectangle( self.gc, True, self.x, self.y, Loop.HEAD, self.height ) + if self.x + Loop.HEAD > startX: + x = max( startX, self.x ) + endX = min( stopX, self.x + Loop.HEAD ) + width = endX - x - # draw block - if self.active: self.gc.foreground = self.owner.colors["Bg_Active"] - else: self.gc.foreground = self.owner.colors["Bg_Inactive"] - self.gc.set_clip_origin( self.x-Loop.MASK_START, self.y-self.height ) - pixmap.draw_rectangle( self.gc, True, self.x, self.y, Loop.HEAD, self.height ) - - #-- draw beats ---------------------------------------- - - beats = self.data["beats"] - 1 # last beat is drawn with the tail - x = self.x + Loop.HEAD - while beats > 3: # draw border if self.active: self.gc.foreground = self.owner.colors["Border_Active"] else: self.gc.foreground = self.owner.colors["Border_Inactive"] - self.gc.set_clip_origin( x-Loop.MASK_BEAT, self.y ) - pixmap.draw_rectangle( self.gc, True, x, self.y, Loop.BEAT_MUL3, self.height ) + self.gc.set_clip_origin( self.x-Loop.MASK_START, self.y ) + pixmap.draw_rectangle( self.gc, True, x, y, width, height ) # draw block if self.active: self.gc.foreground = self.owner.colors["Bg_Active"] else: self.gc.foreground = self.owner.colors["Bg_Inactive"] - self.gc.set_clip_origin( x-Loop.MASK_BEAT, self.y-self.height ) - pixmap.draw_rectangle( self.gc, True, x, self.y, Loop.BEAT_MUL3, self.height ) + self.gc.set_clip_origin( self.x-Loop.MASK_START, self.y-self.height ) + pixmap.draw_rectangle( self.gc, True, x, y, width, height ) - x += Loop.BEAT_MUL3 + #-- draw beats ---------------------------------------- + + beats = self.data["beats"] - 1 # last beat is drawn with the tail + curx = self.x + Loop.HEAD + while beats > 3: + if curx >= stopX: + return + elif curx + Loop.BEAT_MUL3 > startX: + x = max( startX, curx ) + endX = min( stopX, curx + Loop.BEAT_MUL3 ) + width = endX - x + + # draw border + if self.active: self.gc.foreground = self.owner.colors["Border_Active"] + else: self.gc.foreground = self.owner.colors["Border_Inactive"] + self.gc.set_clip_origin( curx-Loop.MASK_BEAT, self.y ) + pixmap.draw_rectangle( self.gc, True, x, y, width, height ) + + # draw block + if self.active: self.gc.foreground = self.owner.colors["Bg_Active"] + else: self.gc.foreground = self.owner.colors["Bg_Inactive"] + self.gc.set_clip_origin( curx-Loop.MASK_BEAT, self.y-self.height ) + pixmap.draw_rectangle( self.gc, True, x, y, width, height ) + + curx += Loop.BEAT_MUL3 beats -= 3 if beats: - width = Loop.BEAT*beats - - # draw border - if self.active: self.gc.foreground = self.owner.colors["Border_Active"] - else: self.gc.foreground = self.owner.colors["Border_Inactive"] - self.gc.set_clip_origin( x-Loop.MASK_BEAT, self.y ) - pixmap.draw_rectangle( self.gc, True, x, self.y, width, self.height ) + if curx >= stopX: + return + endX = curx + Loop.BEAT*beats + if endX > startX: + x = max( startX, curx ) + endX = min( stopX, endX ) + width = endX - x + + # draw border + if self.active: self.gc.foreground = self.owner.colors["Border_Active"] + else: self.gc.foreground = self.owner.colors["Border_Inactive"] + self.gc.set_clip_origin( curx-Loop.MASK_BEAT, self.y ) + pixmap.draw_rectangle( self.gc, True, x, y, width, height ) + + # draw block + if self.active: self.gc.foreground = self.owner.colors["Bg_Active"] + else: self.gc.foreground = self.owner.colors["Bg_Inactive"] + self.gc.set_clip_origin( curx-Loop.MASK_BEAT, self.y-self.height ) + pixmap.draw_rectangle( self.gc, True, x, y, width, height ) + + curx += Loop.BEAT*beats - # draw block - if self.active: self.gc.foreground = self.owner.colors["Bg_Active"] - else: self.gc.foreground = self.owner.colors["Bg_Inactive"] - self.gc.set_clip_origin( x-Loop.MASK_BEAT, self.y-self.height ) - pixmap.draw_rectangle( self.gc, True, x, self.y, width, self.height ) + #-- draw tail ----------------------------------------- - x += width + if curx >= stopX: + return - #-- draw tail ----------------------------------------- + x = max( startX, curx ) + endX = min( stopX, self.endX ) + width = endX - x # draw border if self.active: self.gc.foreground = self.owner.colors["Border_Active"] else: self.gc.foreground = self.owner.colors["Border_Inactive"] - self.gc.set_clip_origin( x-Loop.MASK_TAIL, self.y ) - pixmap.draw_rectangle( self.gc, True, x, self.y, Loop.TAIL, self.height ) + self.gc.set_clip_origin( curx-Loop.MASK_TAIL, self.y ) + pixmap.draw_rectangle( self.gc, True, x, y, width, height ) # draw block if self.active: self.gc.foreground = self.owner.colors["Bg_Active"] else: self.gc.foreground = self.owner.colors["Bg_Inactive"] - self.gc.set_clip_origin( x-Loop.MASK_TAIL, self.y-self.height ) - pixmap.draw_rectangle( self.gc, True, x, self.y, Loop.TAIL, self.height ) + self.gc.set_clip_origin( curx-Loop.MASK_TAIL, self.y-self.height ) + pixmap.draw_rectangle( self.gc, True, x, y, width, height ) def drawHighlight( self, startX, startY, stopX, stopY, pixmap ): diff --git a/Jam/Desktop.py b/Jam/Desktop.py index 4b5f7c4..0a71d6f 100644 --- a/Jam/Desktop.py +++ b/Jam/Desktop.py @@ -146,11 +146,11 @@ class Desktop( gtk.EventBox ): self.dragging = False if self.possibleParent: - self.possibleParent.invalidate_rect( False ) self.possibleParent.addChild( self.clickedBlock ) root = self.possibleParent.getRoot() self.blocks.remove(root) self.blocks.append(root) + root.invalidateBranch( True ) self.possibleParent = None else: self.blocks.append( self.clickedBlock ) -- cgit v0.9.1