コード例 #1
0
ファイル: text.py プロジェクト: 602p/spacegame
 def screen(self,surface,pos,fgcolor=(128,128,125),font=None,interline=0):
     fgcolor = [fgcolor]
     px,y = pos
     mono = True
     if not font: font = Text.defaultfont
     if font.size('i')!=font.size('x'): mono = False
     char_w,char_h = font.size(' ')
     char_h += interline
     style_cmd = {'+':True,'-':False,'b':font.set_bold,'i':font.set_italic,'u':font.set_underline}
     bz = self.baliz
     def set_style(pos):
         while True:
             if bz and pos == bz[0][0]: 
                 _,mode,style,color,value = bz.pop(0)
                 if mode: style_cmd[style](style_cmd[mode])
                 elif color:
                     if value: fgcolor.append(Color(int(value,16)<<8))
                     else: fgcolor.pop()
             else: break
     rec = Rect(pos,(0,0))
     pos = 0
     set_style(pos)
     if mono:
         for lines in self:
             for line in lines:
                 x = px
                 for char in line:
                     rec = rec.unionall([(surface.blit(font.render(char,1,fgcolor[-1]),(x,y))),rec])
                     x += char_w
                     pos += 1
                     set_style(pos)
                 y += char_h
             pos += 1
             set_style(pos)
         return rec
     for lines in self:
         for line in lines:
             x = px
             for char in line:
                 x = surface.blit(font.render(char,1,fgcolor[-1]),(x,y))
                 rec = rec.unionall([x,rec])
                 x = x.right
                 pos += 1
                 set_style(pos)
             y += char_h
         pos += 1
         set_style(pos)
     return rec
コード例 #2
0
ファイル: rect_test.py プロジェクト: annie60/Xilarius
    def test_unionall(self):
        r1 = Rect(0, 0, 1, 1)
        r2 = Rect(-2, -2, 1, 1)
        r3 = Rect(2, 2, 1, 1)

        r4 = r1.unionall([r2, r3])
        self.assertEqual(Rect(-2, -2, 5, 5), r4)
コード例 #3
0
ファイル: rect_test.py プロジェクト: CTPUG/pygame_cffi
 def test_unionall( self ):
     r1 = Rect( 0, 0, 1, 1 )
     r2 = Rect( -2, -2, 1, 1 )
     r3 = Rect( 2, 2, 1, 1 )
     
     r4 = r1.unionall( [r2,r3] )
     self.assertEqual( Rect(-2, -2, 5, 5), r4 )
コード例 #4
0
    def update (self, **kwargs):
        """V.update (...) -> None

        Updates the ViewPort.

        Updates the ViewPort and causes its parent to update itself on
        demand.
        """
        if not self.dirty:
            border = base.GlobalStyle.get_border_size \
                     (self.__class__, self.style,
                      StyleInformation.get ("VIEWPORT_BORDER"))
            resize = kwargs.get ("resize", False)

            children = kwargs.get ("children", {})
            blit = self.image.blit
            items = children.items ()

            # Clean up the dirty areas on the widget.
            vals = []
            for child, rect in items:
                blit (self._bg, rect, rect)

                # r will be the area for the blit.
                r = Rect (abs (self.hadjustment), abs (self.vadjustment),
                          self.width - 2 * border, self.height - 2 * border)
                blit (child.image, (border, border), r)
                vals.append (r)

            # If a parent's available, reassign the child rects, so that
            # they point to the absolute position on the widget and build
            # one matching them all for an update.
            if self.parent:
                rect = Rect (self._oldrect)
                if len (vals) != 0:
                    for r in vals:
                        r.x += self.x
                        r.y += self.y
                    rect.unionall (vals[1:])
                self.parent.update (children={ self : rect }, resize=resize)
            self._lock = max (self._lock - 1, 0)
        else:
            Bin.update (self, **kwargs)
コード例 #5
0
    def update(self, **kwargs):
        """V.update (...) -> None

        Updates the ViewPort.

        Updates the ViewPort and causes its parent to update itself on
        demand.
        """
        if not self.dirty:
            border = base.GlobalStyle.get_border_size \
                     (self.__class__, self.style,
                      StyleInformation.get ("VIEWPORT_BORDER"))
            resize = kwargs.get("resize", False)

            children = kwargs.get("children", {})
            blit = self.image.blit
            items = children.items()

            # Clean up the dirty areas on the widget.
            vals = []
            for child, rect in items:
                blit(self._bg, rect, rect)

                # r will be the area for the blit.
                r = Rect(abs(self.hadjustment), abs(self.vadjustment),
                         self.width - 2 * border, self.height - 2 * border)
                blit(child.image, (border, border), r)
                vals.append(r)

            # If a parent's available, reassign the child rects, so that
            # they point to the absolute position on the widget and build
            # one matching them all for an update.
            if self.parent:
                rect = Rect(self._oldrect)
                if len(vals) != 0:
                    for r in vals:
                        r.x += self.x
                        r.y += self.y
                    rect.unionall(vals[1:])
                self.parent.update(children={self: rect}, resize=resize)
            self._lock = max(self._lock - 1, 0)
        else:
            Bin.update(self, **kwargs)
コード例 #6
0
ファイル: text.py プロジェクト: 602p/spacegame
    def screen(self,
               surface,
               pos,
               fgcolor=(128, 128, 125),
               font=None,
               interline=0):
        fgcolor = [fgcolor]
        px, y = pos
        mono = True
        if not font: font = Text.defaultfont
        if font.size('i') != font.size('x'): mono = False
        char_w, char_h = font.size(' ')
        char_h += interline
        style_cmd = {
            '+': True,
            '-': False,
            'b': font.set_bold,
            'i': font.set_italic,
            'u': font.set_underline
        }
        bz = self.baliz

        def set_style(pos):
            while True:
                if bz and pos == bz[0][0]:
                    _, mode, style, color, value = bz.pop(0)
                    if mode: style_cmd[style](style_cmd[mode])
                    elif color:
                        if value: fgcolor.append(Color(int(value, 16) << 8))
                        else: fgcolor.pop()
                else: break

        rec = Rect(pos, (0, 0))
        pos = 0
        set_style(pos)
        if mono:
            for lines in self:
                for line in lines:
                    x = px
                    for char in line:
                        rec = rec.unionall([
                            (surface.blit(font.render(char, 1, fgcolor[-1]),
                                          (x, y))), rec
                        ])
                        x += char_w
                        pos += 1
                        set_style(pos)
                    y += char_h
                pos += 1
                set_style(pos)
            return rec
        for lines in self:
            for line in lines:
                x = px
                for char in line:
                    x = surface.blit(font.render(char, 1, fgcolor[-1]), (x, y))
                    rec = rec.unionall([x, rec])
                    x = x.right
                    pos += 1
                    set_style(pos)
                y += char_h
            pos += 1
            set_style(pos)
        return rec