Esempio n. 1
0
    def on_expose_event(self, widget, event):
        cr = widget.window.cairo_create()
        rect = widget.allocation
        rect.x = rect.y = 0

        cr.set_source_rgb(1, 1, 1)
        cr.rectangle(rect.x, rect.y, rect.width, rect.height)
        cr.fill()

        if not self.channel_infos:
            render_text(
                cr,
                self.prompt_text,
                rect.x,
                rect.y,
                rect.width,
                rect.height,
                text_color=app_theme.get_color("labelText").get_color(),
                alignment=pango.ALIGN_CENTER)
            return True

        if self.active_alpha > 0.0:
            self.draw_channel_info(cr, rect, self.active_index,
                                   self.active_alpha)

        if self.target_index != None and self.target_alpha > 0.0:
            self.draw_channel_info(cr, rect, self.target_index,
                                   self.target_alpha)

        if self.mask_flag:
            draw_pixbuf(cr, self.mask_pixbuf, rect.x, rect.y)

        # Draw select pointer.
        for index in range(0, self.slide_number):
            if self.target_index == None:
                if self.active_index == index:
                    cr.set_source_rgba(*alpha_color_hex_to_cairo(("#9DD6C5",
                                                                  0.9)))
                else:
                    cr.set_source_rgba(*alpha_color_hex_to_cairo(("#D4E1DC",
                                                                  0.9)))
            else:
                if self.target_index == index:
                    cr.set_source_rgba(*alpha_color_hex_to_cairo(("#9DD6C5",
                                                                  0.9)))
                else:
                    cr.set_source_rgba(*alpha_color_hex_to_cairo(("#D4E1DC",
                                                                  0.9)))

            p_x = rect.x + rect.width + self.pointer_offset_x + index * self.pointer_padding
            p_y = rect.y + self.pointer_offset_y
            cr.arc(p_x, p_y, self.pointer_radious, 0, 2 * math.pi)

            cr.fill()

            pointer_rect = gtk.gdk.Rectangle(p_x - self.pointer_radious,
                                             p_y - self.pointer_radious,
                                             self.pointer_radious * 2,
                                             self.pointer_radious * 2)
            # Draw index number.
            render_text(cr,
                        str(index + 1),
                        pointer_rect.x,
                        pointer_rect.y,
                        pointer_rect.width,
                        pointer_rect.height,
                        text_size=9,
                        text_color="#444444",
                        alignment=pango.ALIGN_CENTER)
            pointer_rect.x -= rect.x
            pointer_rect.y -= rect.y
            self.pointer_coords[index] = pointer_rect

        return True
    def on_expose_event(self, widget, event):    
        cr = widget.window.cairo_create()
        rect = widget.allocation
        rect.x = rect.y = 0
        
        cr.set_source_rgb(1, 1, 1)
        cr.rectangle(rect.x, rect.y, rect.width,rect.height)
        cr.fill()
        
        if not self.channel_infos:
            render_text(cr, self.prompt_text, rect.x, rect.y, rect.width, rect.height,
                        text_color=app_theme.get_color("labelText").get_color(),
                        alignment=pango.ALIGN_CENTER)
            return True
            
        
        if self.active_alpha > 0.0:
            self.draw_channel_info(cr, rect, self.active_index, self.active_alpha)
            
        if self.target_index != None and self.target_alpha > 0.0:    
            self.draw_channel_info(cr, rect, self.target_index, self.target_alpha)
            
        if self.mask_flag:    
            draw_pixbuf(cr, self.mask_pixbuf, rect.x, rect.y)
        
        
        # Draw select pointer.
        for index in range(0, self.slide_number):
            if self.target_index == None:
                if self.active_index == index:
                    cr.set_source_rgba(*alpha_color_hex_to_cairo(("#9DD6C5", 0.9)))                    
                else:
                    cr.set_source_rgba(*alpha_color_hex_to_cairo(("#D4E1DC", 0.9)))
            else:
                if self.target_index == index:
                    cr.set_source_rgba(*alpha_color_hex_to_cairo(("#9DD6C5", 0.9)))                    
                else:
                    cr.set_source_rgba(*alpha_color_hex_to_cairo(("#D4E1DC", 0.9)))

            p_x =  rect.x + rect.width + self.pointer_offset_x + index * self.pointer_padding       
            p_y =  rect.y + self.pointer_offset_y
            cr.arc(p_x, p_y,
                   self.pointer_radious,
                   0, 
                   2 * math.pi)
            
            cr.fill()
            
            pointer_rect = gtk.gdk.Rectangle(p_x - self.pointer_radious,
                                             p_y - self.pointer_radious,
                                             self.pointer_radious * 2,
                                             self.pointer_radious * 2)
            # Draw index number.
            render_text(cr, str(index + 1), pointer_rect.x, pointer_rect.y,
                        pointer_rect.width, pointer_rect.height, text_size=9, text_color="#444444",
                        alignment=pango.ALIGN_CENTER
                        )
            pointer_rect.x -= rect.x
            pointer_rect.y -= rect.y
            self.pointer_coords[index] = pointer_rect
            
        return True
Esempio n. 3
0
    def draw_channel_info(self, cr, allocation, index, alpha):
        rect = gtk.gdk.Rectangle(*allocation)
        cr.push_group()

        # get channel_info
        channel_info = self.channel_infos[index]

        # get_pixbuf
        pixbuf = self.get_channel_pixbuf(channel_info)
        pixbuf_x = rect.x + (self.cover_size - pixbuf.get_width()) / 2
        pixbuf_y = rect.y + (self.cover_size - pixbuf.get_height()) / 2

        draw_pixbuf(cr, pixbuf, pixbuf_x, pixbuf_y)

        # get_contents
        text_contents = self.get_channel_contents(channel_info)

        pixbuf_width = self.cover_size
        cr.set_source_rgb(*color_hex_to_cairo("#EFF5F2"))
        cr.rectangle(rect.x + pixbuf_width, rect.y, rect.width - pixbuf_width,
                     rect.height)
        cr.fill()

        text_x = rect.x + pixbuf_width + self.text_padding_x
        text_y = rect.y + self.text_start_y
        text_width = rect.width - pixbuf_width - self.text_padding_x * 2

        for index, content in enumerate(text_contents):
            if index == 0:
                _width, _height = get_content_size(content, 12)
                render_text(cr,
                            content,
                            text_x,
                            text_y,
                            text_width,
                            _height,
                            text_size=12,
                            text_color="#79af8e")
                text_y += _height + self.text_interval_y

            elif index == 1 and content:
                _width, _height = get_content_size(content, 8)
                _height = _height * 2
                cr.save()
                cr.rectangle(text_x, text_y, text_width, _height)
                cr.clip()
                render_text(cr,
                            content,
                            text_x,
                            text_y,
                            text_width,
                            _height,
                            text_size=8,
                            text_color="#444444",
                            wrap_width=text_width)
                cr.restore()

                text_y += _height + self.text_interval_y

            elif index == 2 and content:
                _width, _height = get_content_size(content, 8)
                _height = _height * 2
                cr.save()
                cr.rectangle(text_x, text_y, text_width, _height)
                cr.clip()
                render_text(cr,
                            content,
                            text_x,
                            text_y,
                            text_width,
                            _height,
                            text_size=8,
                            text_color="#878787",
                            wrap_width=text_width)
                cr.restore()

                text_y += _height + self.text_interval_y

            elif index == 3 and content:
                _width, _height = get_content_size(content, 8)
                _height = _height * 2
                cr.save()
                cr.rectangle(text_x, text_y, text_width, _height)
                cr.clip()
                render_text(cr,
                            content,
                            text_x,
                            text_y,
                            text_width,
                            _height,
                            text_size=8,
                            text_color="#878787",
                            wrap_width=text_width)
                cr.restore()

        cr.pop_group_to_source()
        cr.paint_with_alpha(alpha)
    def draw_channel_info(self, cr, allocation, index, alpha):    
        rect = gtk.gdk.Rectangle(*allocation)
        cr.push_group()
        
        # get channel_info
        channel_info = self.channel_infos[index]
        
        # get_pixbuf
        pixbuf = self.get_channel_pixbuf(channel_info)
        pixbuf_x = rect.x + (self.cover_size - pixbuf.get_width()) / 2
        pixbuf_y = rect.y + (self.cover_size - pixbuf.get_height()) / 2
        
        draw_pixbuf(cr, pixbuf, pixbuf_x, pixbuf_y)
        
        # get_contents
        text_contents = self.get_channel_contents(channel_info)
        
        pixbuf_width = self.cover_size
        cr.set_source_rgb(*color_hex_to_cairo("#EFF5F2"))
        cr.rectangle(rect.x + pixbuf_width, rect.y, rect.width - pixbuf_width, rect.height)
        cr.fill()
        
        text_x = rect.x + pixbuf_width + self.text_padding_x 
        text_y = rect.y + self.text_start_y
        text_width = rect.width - pixbuf_width - self.text_padding_x * 2
        
        for index, content in enumerate(text_contents):
            if index == 0:
                _width, _height = get_content_size(content, 12)                
                render_text(cr, content, text_x, text_y, text_width, _height, text_size=12, 
                            text_color="#79af8e")
                text_y += _height + self.text_interval_y
                
            elif index == 1 and content:
                _width, _height = get_content_size(content, 8)                
                _height = _height * 2
                cr.save()
                cr.rectangle(text_x, text_y, text_width, _height)
                cr.clip()
                render_text(cr, content, text_x, text_y, text_width, _height, text_size=8, 
                            text_color="#444444", wrap_width=text_width)
                cr.restore()
                
                text_y += _height + self.text_interval_y
                
            elif index == 2 and content:    
                _width, _height = get_content_size(content, 8)                
                _height = _height * 2
                cr.save()
                cr.rectangle(text_x, text_y, text_width, _height)
                cr.clip()
                render_text(cr, content, text_x, text_y, text_width, _height, text_size=8, 
                            text_color="#878787", wrap_width=text_width)
                cr.restore()

                text_y += _height + self.text_interval_y
                
            elif index == 3 and content:    
                _width, _height = get_content_size(content, 8)                
                _height = _height * 2
                cr.save()
                cr.rectangle(text_x, text_y, text_width, _height)
                cr.clip()
                render_text(cr, content, text_x, text_y, text_width, _height, text_size=8, 
                            text_color="#878787", wrap_width=text_width)
                cr.restore()
                
        cr.pop_group_to_source()
        cr.paint_with_alpha(alpha)