Ejemplo n.º 1
0
 def refreshBuffer(self):
     X, Y = self.scroll
     cw, ch = self.charSize
     sl, sr, st, sb = 5, 15, 5, 5
     cl, rw = self.screenSize
     dc = MemoryDC()
     dc.SelectObject(self.bmpBuf)
     dc.SetBackground(self.brushes['bkgd'])
     dc.Clear()
     x3, x4 = 0 * cw, cl * cw
     x1, y1 = (sl - 0.5) * cw, (st - 0.5) * ch
     x2, y2 = (cl - sr + 0.5) * cw, (rw - sb + 0.5) * ch
     dc.SetPen(self.pens['margin'])
     dc.DrawLine(x1, y1, x1, y2)
     dc.DrawLine(x2, y1, x2, y2)
     dc.DrawLine(x3, y1, x4, y1)
     dc.DrawLine(x3, y2, x4, y2)
     c1, r1, c2, r2 = self.getBlockGeometry()
     dc.SetBrush(Brush(Colour(100, 100, 100)))
     dc.SetPen(self.pens['transparent'])
     x, y = 0, -1
     for line in self.chrBuf[Y:]:
         y += 1
         if y + st >= rw - sb: break
         self.drawText(dc, f'{y+Y:4d}', 0, y + st, self.numberChars)
         if y + Y < r1 or y + Y > r2:
             self.drawText(dc, line[X:], x + sl, y + st, self.normalChars)
             continue
         if r1 == r2:
             self.drawText(dc, line[X:], x + sl, y + st, self.normalChars)
             self.drawText(dc, line[X:c2], x + sl, y + st,
                           self.selectedChars)
             self.drawText(dc, line[X:c1], x + sl, y + st, self.normalChars)
             continue
         if y + Y == r1:
             self.drawText(dc, line[X:] + '¶', x + sl, y + st,
                           self.selectedChars)
             self.drawText(dc, line[X:c1], x + sl, y + st, self.normalChars)
             continue
         if y + Y == r2:
             self.drawText(dc, line[X:], x + sl, y + st, self.normalChars)
             self.drawText(dc, line[X:c2], x + sl, y + st,
                           self.selectedChars)
             continue
         self.drawText(dc, line[X:] + '¶', x + sl, y + st,
                       self.selectedChars)
     x, y = self.cursor
     x1, y1, y2 = (x + sl) * cw, (y + st) * ch, (y + st + 1) * ch - 1
     dc.SetPen(self.pens['cursor'])
     dc.DrawLine(x1, y1, x1, y2)
     dc.SelectObject(NullBitmap)
     return
Ejemplo n.º 2
0
    def refreshBuffer(self):
        # get geometry
        X, Y = self.scroll
        cw, ch = self.charSize
        sl, sr, st, sb = 5, 15, 5, 5
        cl, rw = self.screenSize
        # create device context
        dc = MemoryDC()               
        # select
        dc.SelectObject(self.bmpBuf)
        # set background
        dc.SetBackground(self.brushes['bkgd'])
        # and clear buffer
        dc.Clear()
        # draw margins
        x3, x4 = 0*cw, cl*cw
        x1, y1 = (sl-0.5)*cw, (st-0.5)*ch
        x2, y2 = (cl-sr+0.5)*cw, (rw-sb+0.5)*ch
        dc.SetPen(self.pens['margin'])
        dc.DrawLine(x1, y1, x1, y2)
        dc.DrawLine(x2, y1, x2, y2)
        dc.DrawLine(x3, y1, x4, y1)
        dc.DrawLine(x3, y2, x4, y2)
        # get block geometry
        c1, r1, c2, r2 = self.getBlockGeometry()
        # set brush
        dc.SetBrush(Brush(Colour(100,100,100)))
        dc.SetPen(self.pens['transparent'])
        # draw text
        x, y = 0, -1
        for line in self.chrBuf[Y:]:
            y += 1
            if y+st >= rw-sb: break
            # draw line number
            self.drawText(dc, f'{y+Y:4d}', 0, y+st, self.numberChars)
            # the line is outside of the block
            if y+Y < r1 or y+Y > r2:
                self.drawText(dc, line[X:], x+sl, y+st, self.normalChars)
                continue
            # block is inside if the line
            if r1 == r2:
                self.drawText(dc, line[X:],   x+sl, y+st, self.normalChars)
                self.drawText(dc, line[X:c2], x+sl, y+st, self.selectedChars)
                self.drawText(dc, line[X:c1], x+sl, y+st, self.normalChars)
                continue
            # line at the start of the block
            if y+Y == r1:
                self.drawText(dc, line[X:]+'¶',   x+sl, y+st, self.selectedChars)
                self.drawText(dc, line[X:c1], x+sl, y+st, self.normalChars)
                continue
            # line at the end of the block
            if y+Y == r2:
                self.drawText(dc, line[X:],   x+sl, y+st, self.normalChars)
                self.drawText(dc, line[X:c2], x+sl, y+st, self.selectedChars)
                continue
            # line is inside the block
            self.drawText(dc, line[X:]+'¶', x+sl, y+st, self.selectedChars)

        # draw cursor
        x, y = self.cursor
        x1, y1, y2 = (x+sl)*cw, (y+st)*ch, (y+st+1)*ch-1
        dc.SetPen(self.pens['cursor'])
        dc.DrawLine(x1, y1, x1, y2)
        # done
        dc.SelectObject(NullBitmap)
        return
Ejemplo n.º 3
0
    def refreshBuffer(self):
        # get geometry
        X, Y = self.scroll
        cw, ch = self.charSize
        sl, sr, st, sb = 5, 15, 5, 5
        cl, rw = self.screenSize
        # create device context
        dc = MemoryDC()
        # select
        dc.SelectObject(self.bitmapBuffer)
        # set background
        dc.SetBackground(self.brushes['bkgd'])
        # and clear buffer
        dc.Clear()
        # draw margins
        x3, x4 = 0 * cw, cl * cw
        x1, y1 = (sl - 0.5) * cw, (st - 0.5) * ch
        x2, y2 = (cl - sr + 0.5) * cw, (rw - sb + 0.5) * ch
        dc.SetPen(self.pens['margin'])
        dc.DrawLine(x1, y1, x1, y2)
        dc.DrawLine(x2, y1, x2, y2)
        dc.DrawLine(x3, y1, x4, y1)
        dc.DrawLine(x3, y2, x4, y2)

        # get block geometry
        r1, c1 = self.blockBegin
        r2, c2 = self.blockEnd
        block = False

        # draw text
        x, y = 0, 0
        for line in self.characterBuffer[Y:]:
            # draw line number
            self.drawText(dc, f'{y+Y:4d}', 0, y + st, self.numberChars)
            # the line is outside of the block
            if y + Y < r1 or y + Y > r2:
                self.drawText(dc, line[X:], x + sl, y + st, self.normalChars)
                # done
                y += 1
                if y + st >= rw - sb: break
                continue
            # block is inside if the line
            if r1 == r2:
                # draw normal text
                # self.drawText(dc, line[X:], x+sl, y+st, self.normalChars)
                # # block has size zero
                # if c1 == c2:
                #     # done
                #     y += 1
                #     if y+st >= rw-sb: break
                #     continue
                # block has finite size
                self.drawText(dc, line[X:], x + sl, y + st, self.normalChars)
                self.drawText(dc, line[X:c2], x + sl, y + st,
                              self.selectedChars)
                self.drawText(dc, line[X:c1], x + sl, y + st, self.normalChars)
                # done
                y += 1
                if y + st >= rw - sb: break
                continue
            # line at the start of the block
            if y + Y == r1:
                self.drawText(dc, line[X:], x + sl, y + st, self.selectedChars)
                self.drawText(dc, line[X:c1], x + sl, y + st, self.normalChars)
                # done
                y += 1
                if y + st >= rw - sb: break
                continue
            # line at the end of the block
            if y + Y == r2:
                self.drawText(dc, line[X:], x + sl, y + st, self.normalChars)
                self.drawText(dc, line[X:c2], x + sl, y + st,
                              self.selectedChars)
                # done
                y += 1
                if y + st >= rw - sb: break
                continue
            # line in the middle of the block
            self.drawText(dc, line[X:], x + sl, y + st, self.selectedChars)
            y += 1
            if y + st >= rw - sb: break

        # draw cursor
        x, y = self.cursor
        x1, y1, y2 = (x + sl) * cw, (y + st) * ch, (y + st + 1) * ch - 1
        dc.SetPen(self.pens['cursor'])
        dc.DrawLine(x1, y1, x1, y2)

        # done
        dc.SelectObject(NullBitmap)
        return