コード例 #1
0
ファイル: fbo.py プロジェクト: hansent/pymt
    def bind(self):
        super(SoftwareFbo, self).bind()

        # Save current buffer
        w = pymt.getWindow()
        glReadBuffer(GL_BACK)
        self.pixels = glReadPixels(0, 0, w.width, w.height, GL_RGBA, GL_UNSIGNED_BYTE)

        # Push current attrib
        glPushAttrib(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_TEST | GL_STENCIL_BUFFER_BIT)
        glDisable(GL_STENCIL_TEST)

        # Save viewport if asked
        if self.push_viewport:
            glPushAttrib(GL_VIEWPORT_BIT)
            glViewport(0, 0, self.size[0], self.size[1])

        # Draw old Framebuffer
        set_color(1, 1, 1)
        drawTexturedRectangle(self.texture, size=self.size)
コード例 #2
0
ファイル: fbo.py プロジェクト: gavine199/pymt
    def bind(self):
        super(SoftwareFbo, self).bind()

        # Save current buffer
        w = pymt.getWindow()
        glReadBuffer(GL_BACK)
        self.pixels = glReadPixels(0, 0, w.width, w.height, GL_RGBA, GL_UNSIGNED_BYTE)

        # Push current attrib
        glPushAttrib(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_TEST | GL_STENCIL_BUFFER_BIT)
        glDisable(GL_STENCIL_TEST)

        # Save viewport if asked
        if self.push_viewport:
            glPushAttrib(GL_VIEWPORT_BIT)
            glViewport(0, 0, self.size[0], self.size[1])

        # Draw old Framebuffer
        set_color(1, 1, 1)
        drawTexturedRectangle(self.texture, size=self.size)
コード例 #3
0
ファイル: capture.py プロジェクト: estemenson/CMAP
    def draw(self):
        # draw background
        set_color(*self.bgcolor)
        drawRectangle(pos=self.pos, size=self.size)

        # draw current trace
        set_color(1,1,1)
        for trace in self.points:
            l = []
            for p in self.points[trace]:
                l.append(p[0])
                l.append(p[1])
            drawLine(l)
        labeltext = ''
        if self.lastbest:
            labeltext = 'Creating : %s' % self.lastbest[1].label
        
        s = self.width *.1
        drawLabel(label=labeltext, pos=(self.pos[0] + s*3, self.pos[1] + \
                            self.height + s * 0.8 + self.height * 0.07),
                font_size=self.height * 0.07, center=False)
コード例 #4
0
ファイル: borders.py プロジェクト: estemenson/CMAP
    def draw(self):
        scaled_border = self.get_scaled_border()
        border_color=self.style.get('border-color')
        if not self.isMinimized:
            # select color from number of touch
            if len(self._touches) == 0:
                set_color(*self.style.get('bg-color'))
            elif len(self._touches) == 1:
                border_color = self.style.get('bg-color-move') 
                set_color(*border_color) #IGNORE:W0142
            else:
                border_color = self.style.get('bg-color-full') 
                set_color(*border_color) #IGNORE:W0142

            # draw border
            drawRoundedRectangle(
                pos=(-scaled_border, -scaled_border*2*self.scale),
                size=(self.width+scaled_border*2, self.height+scaled_border*3*self.scale),
                #size=(self.width+scaled_border*2, self.height+control_height*2),
                radius=15. / self.scale
            )
#            pos = ((self.width/2 - control_width/2),
#                   -scaled_border * 2)
#            size=(control_width, 
#                  control_height) 
#            corners=(True, True, False, False)
        else:
            pos = (0,-scaled_border)
            size=scale_tuple(self.size,-.1,-.5)
            l_pos = (size[0]/2, size[1] - 15 - scaled_border)
            corners=(True, True, True, True)
            drawLabel(label=self.minimized_label, pos=l_pos, 
                      color=self.style.get('font-color'))
            border_color=parse_color(self.style.get('min-border-color'))
            # draw control background
            drawRoundedRectangle(
                pos=pos,
                size=size,
                radius=15. / self.scale,
                corners=corners, color=border_color
            )
コード例 #5
0
ファイル: css.py プロジェクト: gavine199/pymt
def drawCSSRectangle(pos=(0, 0), size=(100, 100), style=dict(), prefix=None, state=None):
    '''Draw a rectangle with CSS
    
    :Parameters:
        `state`: if a certain state string is passed, we will use styles with this postifx instead.
            for example:  style[bg-color] and style[bg-color-down] are both set.
            if state == "down", we wil use bg-color-down instead of bg-color

    :Styles:
        * alpha-background (color)
        * border-radius (float)
        * border-radius-precision (float)
        * border-width (float)
        * draw-alpha-background (bool)
        * draw-background (bool)
        * draw-border (bool)

    '''

    bg_image = style.get('bg-image-'+str(state))
    if not bg_image:
        bg_image = style.get('bg-image')

    # Check if we have a cached version
    cache_id = '%s:%s:%s:%s:%s' % (pos, size, style, prefix, state)
    cache = Cache.get('pymt.cssrect', cache_id)
    if cache:
        cache.draw()
        if bg_image:
            bg_image.size = size
            bg_image.pos = pos
            bg_image.draw()
        return


    # lets use the ones for given state,
    # and ignore the regular ones if the state ones are there
    if state:
        state = "-" + state
        newstyle = {}
        overwrites = []
        for s in style:
            if state in s:
                overwrite  = s.replace(state, '')
                newstyle[overwrite] = style[s]
                overwrites.append(overwrite)
            if s not in overwrites:
                newstyle[s] = style[s]
        style = newstyle

    # hack to remove prefix in style
    if prefix is not None:
        prefix += '-'
        newstyle = {}
        for k in style:
            newstyle[k] = style[k]
        for k in style:
            if prefix in k:
                newstyle[k.replace(prefix, '')] = style[k]
        style = newstyle

    style.setdefault('border-width', 1.5)
    style.setdefault('border-radius', 0)
    style.setdefault('border-radius-precision', .1)
    style.setdefault('draw-border', 0)
    style.setdefault('draw-background', 1)
    style.setdefault('draw-alpha-background', 0)
    style.setdefault('alpha-background', (1, 1, .5, .5))

    k = { 'pos': pos, 'size': size }

    new_cache = GlDisplayList()
    with new_cache:

        if state:
            set_color(*style['bg-color']) #hack becasue old widgets set this themselves

        linewidth = style.get('border-width')

        bordercolor = None
        if 'border-color' in style:
            bordercolor = style['border-color']

        if style['border-radius'] > 0:
            k.update({
                'radius': style['border-radius'],
                'precision': style['border-radius-precision']
            })
            if style['draw-background']:
                drawRoundedRectangle(**k)
            if style['draw-border']:
                if linewidth:
                    glPushAttrib(GL_LINE_BIT)
                    glLineWidth(linewidth)
                if bordercolor:
                    with gx_color(*bordercolor):
                        drawRoundedRectangle(style=GL_LINE_LOOP, **k)
                else:
                    drawRoundedRectangle(style=GL_LINE_LOOP, **k)
                if linewidth:
                    glPopAttrib()
            if style['draw-alpha-background']:
                drawRoundedRectangleAlpha(alpha=style['alpha-background'], **k)
        else:
            if style['draw-background']:
                drawRectangle(**k)
            if style['draw-border']:
                if linewidth:
                    glPushAttrib(GL_LINE_BIT)
                    glLineWidth(linewidth)
                if bordercolor:
                    with gx_color(*bordercolor):
                        drawRectangle(style=GL_LINE_LOOP, **k)
                else:
                    drawRectangle(style=GL_LINE_LOOP, **k)
                if linewidth:
                    glPopAttrib()
            if style['draw-alpha-background']:
                drawRectangleAlpha(alpha=style['alpha-background'], **k)


    # if the drawCSSRectangle is already inside a display list
    # compilation will not happen, but drawing yes.
    # so, store only if a cache is created !
    if new_cache.is_compiled():
        Cache.append('pymt.cssrect', cache_id, new_cache)
        new_cache.draw()

    if bg_image:
        bg_image.size = size
        bg_image.pos = pos
        bg_image.draw()
コード例 #6
0
ファイル: decorators.py プロジェクト: estemenson/CMAP
 def draw(self):
     set_color(*self.style['bg-color'])
     drawCSSRectangle(pos=self.pos, size=self.size,style=self.style)