Пример #1
0
    def draw_background(self, cr, rect):
        with cairo_disable_antialias(cr):
            # Draw frame.
            x, y, w, h = rect.x, rect.y, rect.width, rect.height
            cr.set_line_width(1)
            cr.set_source_rgb(
                *color_hex_to_cairo(self.frame_color.get_color()))
            cr.rectangle(x, y, w, h)
            cr.stroke()

            # Draw background.
            cr.set_source_rgba(*alpha_color_hex_to_cairo((
                ui_theme.get_color("combo_entry_background").get_color(),
                0.9)))
            cr.rectangle(x, y, w - 1, h - 1)
            cr.fill()

            # Draw mac dot.
            cr.set_source_rgba(0.5, 0.5, 0.5, 0.8)
            dot_distance = self.width / self.segment_number
            dot_bottom_padding = 18
            for index in range(0, self.last_segment_index):
                draw_text(
                    cr,
                    self.segment_split_char,
                    x + dot_distance * (index + 1) - self.dot_size / 2,
                    y + h - dot_bottom_padding,
                    self.dot_size,
                    self.dot_size,
                )
Пример #2
0
 def listview1_test_on_draw_column_heade(e):
     if e.single_columns == e.column:
         e.cr.set_source_rgba(*alpha_color_hex_to_cairo(("#ebebeb", 0.1)))
         e.text_color = "#000000"
     elif e.motion_columns == e.column:
         e.cr.set_source_rgba(*alpha_color_hex_to_cairo(("#0000FF", 0.1)))
         e.text_color = "#0000FF"
         e.cr.set_source_rgba(0, 0, 1, 0.1)
         e.cr.rectangle(e.x, e.y, e.w, e.h)
         e.fill()
     else:
         e.cr.set_source_rgba(*alpha_color_hex_to_cairo(("#FF00FF", 0.1)))
         e.text_color = "#FF00FF"
     e.cr.rectangle(e.x, e.y, e.w, e.h)
     e.cr.stroke()
     if listview1.columns[len(listview1.columns) - 1] == e.column:
         e.cr.set_source_rgba(*alpha_color_hex_to_cairo(("#FF00FF", 0.1)))
         e.cr.rectangle(e.x + e.w, e.y, listview1.allocation.width - e.x,
                        e.h)
         e.cr.stroke()
     # 画标题栏文本.
     draw_text(e.cr,
               e.text,
               e.x,
               e.y,
               e.w,
               e.h,
               text_color=e.text_color,
               alignment=Text.CENTER)
Пример #3
0
    def render(self, cr, rect):
        '''
        Render icon and name of DirItem.
        '''
        # Draw select background.
        if self.is_button_press == True:
            draw_vlinear(
                cr, rect.x, rect.y, rect.width, rect.height,
                ui_theme.get_shadow_color("listview_select").get_color_info())

        # Draw directory icon.
        draw_pixbuf(
            cr,
            self.pixbuf,
            rect.x + self.icon_size / 2,
            rect.y + (rect.height - self.icon_size) / 2,
        )

        # Draw directory name.
        draw_text(cr,
                  self.name,
                  rect.x,
                  rect.y + self.icon_size + ITEM_PADDING_Y * 2,
                  rect.width,
                  DEFAULT_FONT_SIZE,
                  DEFAULT_FONT_SIZE,
                  alignment=pango.ALIGN_CENTER)
Пример #4
0
 def expose_droplist_item(self, widget, event, item_content):
     '''Expose droplist item.'''
     # Init.
     cr = widget.window.cairo_create()
     rect = widget.allocation
     font_color = ui_theme.get_color("menu_font").get_color()
     
     # Draw select effect.
     if self.subdroplist_active or widget.state in [gtk.STATE_PRELIGHT, gtk.STATE_ACTIVE]:
         # Draw background.
         draw_vlinear(cr, rect.x, rect.y, rect.width, rect.height, 
                      ui_theme.get_shadow_color("menu_item_select").get_color_info())
         
         # Set font color.
         font_color = ui_theme.get_color("menu_select_font").get_color()
         
     # Draw item content.
     draw_text(cr, item_content, 
                 rect.x + self.item_padding_left,
                 rect.y,
                 rect.width,
                 rect.height,
                 self.font_size, font_color,
                 )
     
     # Propagate expose to children.
     propagate_expose(widget, event)
 
     return True
Пример #5
0
    def render(self, cr, rect):
        """
        Render icon and name of DirItem.
        """
        # Draw select background.
        if self.is_button_press == True:
            draw_vlinear(
                cr,
                rect.x,
                rect.y,
                rect.width,
                rect.height,
                ui_theme.get_shadow_color("listview_select").get_color_info(),
            )

        # Draw directory icon.
        draw_pixbuf(cr, self.pixbuf, rect.x + self.icon_size / 2, rect.y + (rect.height - self.icon_size) / 2)

        # Draw directory name.
        draw_text(
            cr,
            self.name,
            rect.x,
            rect.y + self.icon_size + ITEM_PADDING_Y * 2,
            rect.width,
            DEFAULT_FONT_SIZE,
            DEFAULT_FONT_SIZE,
            alignment=pango.ALIGN_CENTER,
        )
Пример #6
0
    def draw_background(self, cr, rect):
        with cairo_disable_antialias(cr):
            # Draw frame.
            x, y, w, h = rect.x, rect.y, rect.width, rect.height
            cr.set_line_width(1)
            cr.set_source_rgb(*color_hex_to_cairo(
                self.frame_color.get_color()))
            cr.rectangle(x, y, w, h)
            cr.stroke()

            # Draw background.
            cr.set_source_rgba(*alpha_color_hex_to_cairo(
                (ui_theme.get_color("combo_entry_background").get_color(), 0.9)))
            cr.rectangle(x, y, w - 1, h - 1)
            cr.fill()

            # Draw mac dot.
            cr.set_source_rgba(0.5, 0.5, 0.5, 0.8)
            dot_distance = self.width / self.segment_number
            dot_bottom_padding = 18
            for index in range(0, self.last_segment_index):
                draw_text(cr,
                          self.segment_split_char,
                          x + dot_distance * (index + 1) - self.dot_size / 2,
                          y + h - dot_bottom_padding,
                          self.dot_size,
                          self.dot_size,
                          )
 def listview1_test_on_draw_column_heade(e):
     if e.single_columns == e.column:
         e.cr.set_source_rgba(*alpha_color_hex_to_cairo(("#ebebeb", 0.1)))
         e.text_color = "#000000"
     elif e.motion_columns == e.column:
         e.cr.set_source_rgba(*alpha_color_hex_to_cairo(("#0000FF", 0.1)))
         e.text_color = "#0000FF"
         e.cr.set_source_rgba(0, 0, 1, 0.1)
         e.cr.rectangle(e.x, e.y, e.w, e.h)
         e.fill()
     else:
         e.cr.set_source_rgba(*alpha_color_hex_to_cairo(("#FF00FF", 0.1)))
         e.text_color = "#FF00FF"
     e.cr.rectangle(e.x, e.y, e.w, e.h)
     e.cr.stroke()
     if listview1.columns[len(listview1.columns)-1] == e.column:
         e.cr.set_source_rgba(*alpha_color_hex_to_cairo(("#FF00FF", 0.1)))
         e.cr.rectangle(e.x + e.w, e.y, listview1.allocation.width - e.x, e.h)
         e.cr.stroke()
     # 画标题栏文本.
     draw_text(e.cr, 
               e.text,
               e.x, e.y, e.w, e.h,
               text_color=e.text_color,
               alignment=Text.CENTER)
Пример #8
0
 def __expose_event(self, widget, event):
     cr = widget.window.cairo_create()
     rect = widget.allocation
     # 画背景.
     bg_pixbuf = self.bg.get_pixbuf().scale_simple(rect.width, rect.height,
                                                   gtk.gdk.INTERP_BILINEAR)
     x = rect.x
     y = rect.y
     draw_pixbuf(cr, bg_pixbuf, x, y)
     #
     if None != self.__index:
         cr.set_source_rgba(1, 1, 1, 0.1)
         cr.rectangle(x + 2, y + self.__index * self.__menu_height + 2,
                      rect.width - 4, self.__menu_height - 4)
         cr.fill()
     #
     index = 0
     for item in self.menu_items:
         pixbuf, text = item.pixbuf, item.text
         if pixbuf:
             draw_pixbuf(
                 cr, pixbuf, x + 8, y + index * self.__menu_height +
                 self.__menu_height / 2 - pixbuf.get_height() / 2)
         draw_text(
             cr, text, x + 35, y + index * self.__menu_height +
             self.__menu_height / 2 - get_text_size(text)[1] / 2)
         if item.child_menus:
             pixbuf = app_theme.get_pixbuf(
                 "screen_mid/menu_child.png").get_pixbuf()
             draw_pixbuf(
                 cr, pixbuf, x + rect.width - 10,
                 y + index * self.__menu_height + self.__menu_height / 2 -
                 pixbuf.get_height() / 2)
         index += 1
Пример #9
0
 def render_name(self, cr, rect):
     '''
     Render icon and name of DirItem.
     '''
     # Draw select background.
     if self.is_select:
         draw_vlinear(cr, rect.x ,rect.y, rect.width, rect.height,
                      ui_theme.get_shadow_color("listview_select").get_color_info())
     
     # Init.
     expand_indicator_pixbuf = ui_theme.get_pixbuf("treeview/arrow_right.png").get_pixbuf()
     
     # Draw directory icon.
     draw_pixbuf(cr, self.pixbuf, 
                 rect.x + COLUMN_OFFSET * self.column_index + INDICATOR_PADDING_LEFT + expand_indicator_pixbuf.get_width() + INDICATOR_PADDING_RIGHT + ICON_PADDING_LEFT,
                 rect.y + (rect.height - ICON_SIZE) / 2,
                 )
     
     # Draw directory name.
     draw_text(cr, self.name, 
               rect.x + COLUMN_OFFSET * self.column_index + INDICATOR_PADDING_LEFT + expand_indicator_pixbuf.get_width() + INDICATOR_PADDING_RIGHT + ICON_PADDING_LEFT + ICON_SIZE + ICON_PADDING_RIGHT,
               rect.y,
               rect.width, rect.height)
     
     # Draw drag line.
     if self.drag_line:
         with cairo_disable_antialias(cr):
             cr.set_line_width(1)
             if self.drag_line_at_bottom:
                 cr.rectangle(rect.x, rect.y + rect.height - 1, rect.width, 1)
             else:
                 cr.rectangle(rect.x, rect.y, rect.width, 1)
             cr.fill()
Пример #10
0
    def draw(self, screen):
        background_surface = pg.Surface(self.rect.size)
        background_surface.set_alpha(128)
        background_surface.fill(c.dark_grey)
        screen.blit(background_surface, self.pos)

        self.container.draw(screen=screen)

        line_spacing = self.message_font.get_linesize() + 4
        current_line_count = 0

        for message in self.messages[::
                                     -1]:  # Look through messages backwards, since we only show the most recent ones
            this_line_count = len(
                util.split_text(text=message[1],
                                font=self.message_font,
                                word_wrap_width=self.message_width))
            current_line_count += this_line_count
            draw.draw_text(target=screen,
                           text=message[0],
                           pos=(self.pos[0], self.pos[1] + self.log_height -
                                current_line_count * line_spacing),
                           font=self.name_font,
                           color=self.user_colors[message[0]],
                           word_wrap=False)
            draw.draw_text(
                target=screen,
                text=message[1],
                pos=(self.name_width + self.pos[0], self.pos[1] +
                     self.log_height - current_line_count * line_spacing),
                font=self.message_font,
                color=util.lighten_color(self.user_colors[message[0]], 0.5),
                word_wrap=True,
                word_wrap_width=self.message_width)
Пример #11
0
    def render_size(self, cr, rect):
        '''
        Render size of DirItem.
        '''
        # Draw select background.
        if self.is_select or self.is_highlight:
            draw_vlinear(cr, rect.x ,rect.y, rect.width, rect.height,
                         ui_theme.get_shadow_color("listview_select").get_color_info())

        # Draw directory size.
        draw_text(cr, self.size_name,
                  rect.x,
                  rect.y,
                  rect.width,
                  rect.height,
                  alignment=pango.ALIGN_RIGHT,
                  )

        # Draw drag line.
        if self.drag_line:
            with cairo_disable_antialias(cr):
                cr.set_line_width(1)
                if self.drag_line_at_bottom:
                    cr.rectangle(rect.x, rect.y + rect.height - 1, rect.width, 1)
                else:
                    cr.rectangle(rect.x, rect.y, rect.width, 1)
                cr.fill()
Пример #12
0
 def render_size(self, cr, rect):
     '''
     Render size of DirItem.
     '''
     # Draw select background.
     if self.is_select:
         draw_vlinear(cr, rect.x ,rect.y, rect.width, rect.height,
                      ui_theme.get_shadow_color("listview_select").get_color_info())
     
     # Draw directory size.
     draw_text(cr, self.size_name,
               rect.x,
               rect.y,
               rect.width, 
               rect.height,
               alignment=pango.ALIGN_RIGHT,
               )
     
     # Draw drag line.
     if self.drag_line:
         with cairo_disable_antialias(cr):
             cr.set_line_width(1)
             if self.drag_line_at_bottom:
                 cr.rectangle(rect.x, rect.y + rect.height - 1, rect.width, 1)
             else:
                 cr.rectangle(rect.x, rect.y, rect.width, 1)
             cr.fill()
Пример #13
0
Файл: Snake.py Проект: SDRU/had
def drawing():
    gl.glClear(gl.GL_COLOR_BUFFER_BIT)  # smaz obsah okna (vybarvi na cerno)
    gl.glColor3f(0, 1, 0)  # nastav barvu kresleni na zelenu

    ### Plots the snake body
    for i in range(0,len(snake_position)-1):
        draw_rectangle(PIECE*snake_position[i][0],PIECE*snake_position[i][1],PIECE*(snake_position[i][0]+1),PIECE*(snake_position[i][1]+1))

    ### Snake head in blue
    gl.glColor3f(0, 0, 1)
    draw_rectangle(PIECE*snake_position[-1][0],PIECE*snake_position[-1][1],PIECE*(snake_position[-1][0]+1),PIECE*(snake_position[-1][1]+1))
    
    ### Food
    draw_rectangle(PIECE*food_position[0],PIECE*food_position[1],PIECE*(food_position[0]+1),PIECE*(food_position[1]+1))
    ### Score
    draw_text(str(N-20),PIECE*SCORE_POSITION[0],PIECE*SCORE_POSITION[1],'left', PIECE*FONT_SIZE)
    ### Walls
    gl.glColor3f(0, 1, 0)  # nastav barvu kresleni na zelenu   
    draw_rectangle(0, 0, PIECE*WALL_THICKNESS, PIECE*HEIGHT)
    draw_rectangle(0, 0, PIECE*WIDTH, PIECE*WALL_THICKNESS)
    draw_rectangle(PIECE*WIDTH-PIECE*WALL_THICKNESS,0,PIECE*WIDTH,PIECE*HEIGHT)
    draw_rectangle(0,PIECE*HEIGHT-PIECE*WALL_THICKNESS,PIECE*WIDTH,PIECE*HEIGHT)

    if QUIT_SIGNAL==1:
        draw_text('GAME OVER',PIECE*WIDTH//2-PIECE*FONT_SIZE*4,PIECE*HEIGHT//2-PIECE*FONT_SIZE//2,'left', PIECE*FONT_SIZE)
Пример #14
0
    def render(self, cr, rect):
        font_color = ui_theme.get_color("menu_font").get_color()
        if isinstance(self.icon_normal_dpixbuf, gtk.gdk.Pixbuf):
            icon_pixbuf = self.icon_normal_dpixbuf
        elif isinstance(self.icon_normal_dpixbuf, DynamicPixbuf):
            icon_pixbuf = self.icon_normal_dpixbuf.get_pixbuf()

        if self.is_hover:
            # Draw background.
            draw_vlinear(cr, rect.x, rect.y, rect.width, rect.height,
                         ui_theme.get_shadow_color("menu_item_select").get_color_info())

            # Set icon pixbuf.
            if isinstance(self.icon_hover_dpixbuf, gtk.gdk.Pixbuf):
                icon_pixbuf = self.icon_hover_dpixbuf
            elif isinstance(self.icon_hover_dpixbuf, DynamicPixbuf):
                icon_pixbuf = self.icon_hover_dpixbuf.get_pixbuf()

            # Set font color.
            font_color = ui_theme.get_color("menu_select_font").get_color()

        draw_pixbuf(cr, icon_pixbuf,
                    rect.x + self.padding_x,
                    rect.y + (rect.height - icon_pixbuf.get_height()) / 2)

        draw_text(cr,
                  self.text,
                  rect.x + self.padding_x * 2 + self.icon_width,
                  rect.y,
                  rect.width - self.padding_x * 2,
                  rect.height,
                  text_color=font_color)
Пример #15
0
    def render(self, cr, rect):
        font_color = ui_theme.get_color("menu_font").get_color()
        if isinstance(self.icon_normal_dpixbuf, gtk.gdk.Pixbuf):
            icon_pixbuf = self.icon_normal_dpixbuf
        elif isinstance(self.icon_normal_dpixbuf, DynamicPixbuf):
            icon_pixbuf = self.icon_normal_dpixbuf.get_pixbuf()

        if self.is_hover:
            # Draw background.
            draw_vlinear(
                cr, rect.x, rect.y, rect.width, rect.height,
                ui_theme.get_shadow_color("menu_item_select").get_color_info())

            # Set icon pixbuf.
            if isinstance(self.icon_hover_dpixbuf, gtk.gdk.Pixbuf):
                icon_pixbuf = self.icon_hover_dpixbuf
            elif isinstance(self.icon_hover_dpixbuf, DynamicPixbuf):
                icon_pixbuf = self.icon_hover_dpixbuf.get_pixbuf()

            # Set font color.
            font_color = ui_theme.get_color("menu_select_font").get_color()

        draw_pixbuf(cr, icon_pixbuf, rect.x + self.padding_x,
                    rect.y + (rect.height - icon_pixbuf.get_height()) / 2)

        draw_text(cr,
                  self.text,
                  rect.x + self.padding_x * 2 + self.icon_width,
                  rect.y,
                  rect.width - self.padding_x * 2,
                  rect.height,
                  text_color=font_color)
Пример #16
0
 def __expose_event(self, widget, event):
     cr = widget.window.cairo_create()
     rect = widget.allocation
     # 画背景.
     bg_pixbuf = self.bg.get_pixbuf().scale_simple(rect.width, 
                                                   rect.height, 
                                                   gtk.gdk.INTERP_BILINEAR)
     x = rect.x
     y = rect.y
     draw_pixbuf(cr, bg_pixbuf, x, y)
     #
     if None != self.__index:
         cr.set_source_rgba(1, 1, 1, 0.1)
         cr.rectangle(x + 2, 
                      y + self.__index * self.__menu_height + 2, 
                      rect.width - 4, 
                      self.__menu_height - 4)
         cr.fill()
     #
     index = 0
     for item in self.menu_items:
         pixbuf, text = item.pixbuf, item.text
         if pixbuf:
             draw_pixbuf(cr, pixbuf, 
                         x + 8, 
                         y + index * self.__menu_height + self.__menu_height/2 - pixbuf.get_height()/2)
         draw_text(cr, text, 
                   x + 35, 
                   y + index * self.__menu_height + self.__menu_height/2 - get_text_size(text)[1]/2)
         if item.child_menus:
             pixbuf = app_theme.get_pixbuf("screen_mid/menu_child.png").get_pixbuf()
             draw_pixbuf(cr, pixbuf,
                         x + rect.width - 10, 
                         y + index * self.__menu_height + self.__menu_height/2 - pixbuf.get_height()/2)
         index += 1
Пример #17
0
 def draw_interface(self, window, font, y):
     text = f"#{self.id} {self.x} {self.y} {self.direction} {self.level} {self.team_name}"
     draw_text(window, font, text, 1600, y, self.color)
     text = f"#food: {self.food}, stones: "
     for stone in self.stones:
         text += f"{stone} "
     draw_text(window, font, text, 1600, y + 20, self.color)
Пример #18
0
    def draw_ip(self, cr, rect):
        x, y, w, h = rect.x, rect.y, rect.width, rect.height
        ip_segment_distance = self.width / self.segment_number
        for (ip_segment_index, ip_segment) in enumerate(self.ip.split(self.segment_split_char)):
            text_color = "#000000"
            if ip_segment_index == self.highlight_segment_index:
                (ip_segment_width, ip_segment_height) = get_content_size(ip_segment)

                if self.grab_focus_flag:
                    background_color = self.select_active_color.get_color_info()
                else:
                    background_color = self.select_inactive_color.get_color_info()
                draw_hlinear(
                    cr,
                    x + ip_segment_index * ip_segment_distance + (ip_segment_distance - ip_segment_width) / 2,
                    y + self.cursor_padding_y,
                    ip_segment_width + 1,
                    h - self.cursor_padding_y * 2,
                    background_color,
                    )

                text_color = "#FFFFFF"

            draw_text(cr, ip_segment,
                      x + ip_segment_index * ip_segment_distance,
                      y,
                      ip_segment_distance,
                      h,
                      alignment=pango.ALIGN_CENTER,
                      text_color=text_color,
                      )
Пример #19
0
    def expose_osd_tooltip(self, widget, event):
        '''
        Internal function to expose osd tooltip.

        @param widget: OSD tooltip widget.
        @param event: Expose event.
        '''
        # Update window size.
        self.move(self.tooltip_x, self.tooltip_y)
        self.resize(self.tooltip_width, self.tooltip_height)

        # Init.
        cr = widget.window.cairo_create()
        rect = widget.allocation

        # Clear color to transparent window.
        cr.set_source_rgba(0.0, 0.0, 0.0, 0.0)
        cr.set_operator(cairo.OPERATOR_SOURCE)
        cr.paint()

        # Draw font.
        draw_text(cr,
                  self.text,
                  rect.x,
                  rect.y,
                  rect.width,
                  rect.height,
                  self.text_size,
                  self.text_color.get_color(),
                  border_radious=self.border_radious,
                  border_color=self.border_color.get_color())

        return True
Пример #20
0
 def __title_expose_event(self, widget, event, show_check):
     cr = widget.window.cairo_create()
     rect = widget.allocation
     # draw background.
     if show_check:
         bg_color = "#272727"
     else:
         bg_color = "#1b1b1b"
     cr.set_source_rgba(*alpha_color_hex_to_cairo((bg_color, 1.0)))
     cr.rectangle(rect.x, rect.y, rect.width + 1, rect.height)
     cr.fill()
     # draw title name.
     text = widget.get_label()
     import pango
     if show_check:
         text_color = "#FFFFFF"
     else:
         text_color = "#A9A9A9"
     draw_text(cr,
               text,
               rect.x,
               rect.y,
               rect.width,
               rect.height,
               text_color=text_color,
               text_size=9,
               alignment=pango.ALIGN_CENTER)
Пример #21
0
    def expose_osd_tooltip(self, widget, event):
        '''
        Internal function to expose osd tooltip.

        @param widget: OSD tooltip widget.
        @param event: Expose event.
        '''
        # Update window size.
        self.move(self.tooltip_x, self.tooltip_y)
        self.resize(self.tooltip_width, self.tooltip_height)

        # Init.
        cr = widget.window.cairo_create()
        rect = widget.allocation

        # Clear color to transparent window.
        cr.set_source_rgba(0.0, 0.0, 0.0, 0.0)
        cr.set_operator(cairo.OPERATOR_SOURCE)
        cr.paint()

        # Draw font.
        draw_text(cr, self.text,
                  rect.x, rect.y, rect.width, rect.height,
                  self.text_size,
                  self.text_color.get_color(),
                  border_radious=self.border_radious,
                  border_color=self.border_color.get_color())

        return True
def render_pixbuf(widget, event, input_args):
    '''
    Render and save pixbuf.

    @param widget: Gtk.Widget instance.
    @param event: Expose event.
    @param input_args: Input arguments as format: (select_num, vlinear_color, text_color, filepath).
    '''
    # Init.
    (select_num, vlinear_color, text_color, filepath) = input_args

    cr = widget.window.cairo_create()
    rect = widget.allocation
    num_pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, True, 8, rect.width, rect.height)

    # Draw background.
    cr.set_operator(cairo.OPERATOR_OVER)
    draw_vlinear(cr, rect.x, rect.y, rect.width, rect.height, eval(vlinear_color))

    # Draw text.
    draw_text(cr, select_num, rect.x, rect.y, rect.width, rect.height, text_color=text_color,
              alignment=pango.ALIGN_CENTER)

    # Render pixbuf from drawing area.
    num_pixbuf.get_from_drawable(
        widget.window, widget.get_colormap(), 0, 0, 0, 0,
        rect.width, rect.height).save(filepath, "png")

    # Exit after generate png file.
    gtk.main_quit()
Пример #23
0
 def __on_draw_column_heade_hd(self, e):
     if e.single_columns == e.column:
         e.cr.set_source_rgba(*alpha_color_hex_to_cairo(("#ebebeb", 0.1)))
         e.text_color = "#000000"
     elif e.motion_columns == e.column:
         e.cr.set_source_rgba(*alpha_color_hex_to_cairo(("#0000FF", 0.1)))
         e.text_color = "#0000FF"
     else:
         e.cr.set_source_rgba(*alpha_color_hex_to_cairo(("#FF00FF", 0.1)))
         e.text_color = "#FF00FF"
     e.cr.rectangle(e.x, e.y, e.w, e.h)
     e.cr.stroke()
     if self.columns[len(self.columns) - 1] == e.column:
         e.cr.set_source_rgba(*alpha_color_hex_to_cairo(("#FF00FF", 0.1)))
         e.cr.rectangle(e.x + e.w, e.y, self.allocation.width - e.x, e.h)
         e.cr.stroke()
     # 画标题栏文本.
     draw_text(e.cr,
               e.text,
               e.x,
               e.y,
               e.w,
               e.h,
               text_color=e.text_color,
               alignment=Text.CENTER)
Пример #24
0
 def expose_button(self, widget, event):
     '''Expose button.'''
     # Init.
     cr = widget.window.cairo_create()
     rect = widget.allocation
     x, y, w, h = rect.x, rect.y, rect.width, rect.height
     
     # Get color info.
     if widget.state == gtk.STATE_NORMAL:
         text_color = ui_theme.get_color("button_font").get_color()
         border_color = ui_theme.get_color("button_border_normal").get_color()
         background_color = ui_theme.get_shadow_color("button_background_normal").get_color_info()
     elif widget.state == gtk.STATE_PRELIGHT:
         text_color = ui_theme.get_color("button_font").get_color()
         border_color = ui_theme.get_color("button_border_prelight").get_color()
         background_color = ui_theme.get_shadow_color("button_background_prelight").get_color_info()
     elif widget.state == gtk.STATE_ACTIVE:
         text_color = ui_theme.get_color("button_font").get_color()
         border_color = ui_theme.get_color("button_border_active").get_color()
         background_color = ui_theme.get_shadow_color("button_background_active").get_color_info()
     elif widget.state == gtk.STATE_INSENSITIVE:
         text_color = ui_theme.get_color("disable_text").get_color()
         border_color = ui_theme.get_color("disable_frame").get_color()
         disable_background_color = ui_theme.get_color("disable_background").get_color()
         background_color = [(0, (disable_background_color, 1.0)),
                             (1, (disable_background_color, 1.0))]
         
     # Draw background.
     draw_vlinear(
         cr,
         x + 1, y + 1, w - 2, h - 2,
         background_color)
     
     # Draw border.
     cr.set_source_rgb(*color_hex_to_cairo(border_color))
     draw_line(cr, x + 2, y + 1, x + w - 2, y + 1) # top
     draw_line(cr, x + 2, y + h, x + w - 2, y + h) # bottom
     draw_line(cr, x + 1, y + 2, x + 1, y + h - 2) # left
     draw_line(cr, x + w, y + 2, x + w, y + h - 2) # right
     
     # Draw four point.
     if widget.state == gtk.STATE_INSENSITIVE:
         top_left_point = ui_theme.get_pixbuf("button/disable_corner.png").get_pixbuf()
     else:
         top_left_point = ui_theme.get_pixbuf("button/corner.png").get_pixbuf()
     top_right_point = top_left_point.rotate_simple(270)
     bottom_right_point = top_left_point.rotate_simple(180)
     bottom_left_point = top_left_point.rotate_simple(90)
     
     draw_pixbuf(cr, top_left_point, x, y)
     draw_pixbuf(cr, top_right_point, x + w - top_left_point.get_width(), y)
     draw_pixbuf(cr, bottom_left_point, x, y + h - top_left_point.get_height())
     draw_pixbuf(cr, bottom_right_point, x + w - top_left_point.get_width(), y + h - top_left_point.get_height())
     
     # Draw font.
     draw_text(cr, self.label, x, y, w, h, self.font_size, text_color,
                 alignment=pango.ALIGN_CENTER)
     
     return True
Пример #25
0
 def __treeview_paint_nodes_event(self, node_event):
     color = self.listview_color.get_color()
     text_color = "#FFFFFF"
     # 单击和移动, 双击.
     if node_event.node in node_event.single_items:
         color_info = [(0, (color, 0.45)), (1, (color, 0.45))] 
         draw_vlinear(node_event.cr,
                      node_event.x, node_event.y, node_event.w, node_event.h,
                      color_info
                      )
         #text_color = "#000000"
     elif node_event.node in node_event.motion_items:
         color_info = [(0, (color, 0.75)), (1, (color, 0.75))] 
         draw_vlinear(node_event.cr,
                      node_event.x, node_event.y, node_event.w, node_event.h,
                      color_info
                      )
     #
     x_padding = 12 # 因为要和搜索框对齐.
     if 0 == node_event.node.leave: # 根节点. :比如->> >我看过的. >优酷视频. >pps.
         if node_event.node.is_expanded:
             pixbuf = self.one_open.get_pixbuf()
         else:
             pixbuf = self.one_close.get_pixbuf()
     elif 1 == node_event.node.leave: # 
         if node_event.node.is_expanded:
             pixbuf = self.two_open.get_pixbuf()
         else:
             pixbuf = self.two_close.get_pixbuf()
     else:
         if node_event.node.is_expanded:
             pixbuf = self.three_open.get_pixbuf()
         else:
             pixbuf = self.three_close.get_pixbuf()
     #
     icon_x = node_event.x + x_padding
     icon_y = node_event.y + node_event.h/2 - pixbuf.get_height()/2 + 1
     if node_event.node.leave > 1:
         icon_x += (node_event.node.leave - 1) * pixbuf.get_width()
     if node_event.node.leave > 0:
         text_color = "#a8a8a8"
     ##########
     # 画图标.
     if node_event.node.nodes != []:
         draw_pixbuf(node_event.cr,
                     pixbuf,
                     icon_x,
                     icon_y) 
     # 画文本.
     text_x_padding = 15
     text_size = 9
     draw_text(node_event.cr, 
               node_event.node.text, 
               icon_x + text_x_padding,
               node_event.y + node_event.h/2 - get_text_size(node_event.node.text, text_size=9)[1]/2,
               text_color=text_color,
               text_size=text_size
               )
Пример #26
0
 def expose_menu_item(self, widget, event):
     '''Expose menu item.'''
     # Init.
     cr = widget.window.cairo_create()
     rect = widget.allocation
     font_color = ui_theme.get_color("menu_font").get_color()
     (item_icons, item_content, item_node) = self.item[0:3]
     
     # Draw select effect.
     if self.submenu_active or widget.state in [gtk.STATE_PRELIGHT, gtk.STATE_ACTIVE]:
         # Draw background.
         draw_vlinear(cr, rect.x, rect.y, rect.width, rect.height, 
                      ui_theme.get_shadow_color("menu_item_select").get_color_info(),
                      MENU_ITEM_RADIUS)
         
         # Set font color.
         font_color = ui_theme.get_color("menu_select_font").get_color()
         
     # Draw item icon.
     pixbuf = None
     pixbuf_width = 0
     if item_icons:
         (item_normal_dpixbuf, item_hover_dpixbuf) = item_icons
         if self.submenu_active or widget.state in [gtk.STATE_PRELIGHT, gtk.STATE_ACTIVE]:
             if item_hover_dpixbuf == None:
                 pixbuf = item_normal_dpixbuf.get_pixbuf()
             else:
                 pixbuf = item_hover_dpixbuf.get_pixbuf()
         else:
             pixbuf = item_normal_dpixbuf.get_pixbuf()
         pixbuf_width += pixbuf.get_width()
         draw_pixbuf(cr, pixbuf, rect.x + self.item_padding_x, rect.y + (rect.height - pixbuf.get_height()) / 2)
         
     # Draw item content.
     draw_text(cr, item_content, 
                 rect.x + self.item_padding_x * 2 + self.icon_width,
                 rect.y,
                 rect.width,
                 rect.height,
                 self.font_size, font_color,
                 )
     
     # Draw submenu arrow.
     if isinstance(item_node, Menu):
         if self.submenu_active or widget.state in [gtk.STATE_PRELIGHT, gtk.STATE_ACTIVE]:
             submenu_pixbuf = ui_theme.get_pixbuf("menu/arrow_hover.png").get_pixbuf()
         else:
             submenu_pixbuf = ui_theme.get_pixbuf("menu/arrow_normal.png").get_pixbuf()
         draw_pixbuf(cr, submenu_pixbuf,
                     rect.x + rect.width - self.item_padding_x - submenu_pixbuf.get_width() - self.arrow_padding_x,
                     rect.y + (rect.height - submenu_pixbuf.get_height()) / 2)
     
     # Propagate expose to children.
     propagate_expose(widget, event)
 
     return True
Пример #27
0
    def render(self, cr, rect):
        # Draw select background.
        if self.is_select:
            draw_vlinear(
                cr, rect.x, rect.y, rect.width, rect.height,
                ui_theme.get_shadow_color("listview_select").get_color_info())

        # Draw loading text.
        draw_text(cr, "(空)", rect.x + COLUMN_OFFSET * self.column_index,
                  rect.y, rect.width, rect.height)
Пример #28
0
 def render_title(self, cr, rect):
     if self.is_select:
         text_color = "#FFFFFF"
         bg_color = "#3399FF"
         cr.set_source_rgb(*color_hex_to_cairo(bg_color))
         cr.rectangle(rect.x, rect.y, rect.width, rect.height)
         cr.paint()
     else:
         text_color = "#000000"
     draw_text(cr, self.title, rect.x, rect.y, rect.width, rect.height, text_color=text_color)
Пример #29
0
 def expose_category_item(self, widget, event):
     '''Expose navigate item.'''
     # Init.
     cr = widget.window.cairo_create()
     rect = widget.allocation
     select_index = self.get_index()
     font_color = ui_theme.get_color("category_item").get_color()
     
     # Draw background.
     if widget.state == gtk.STATE_NORMAL:
         if select_index == self.index:
             select_status = BUTTON_PRESS
         else:
             select_status = BUTTON_NORMAL
     elif widget.state == gtk.STATE_PRELIGHT:
         if select_index == self.index:
             select_status = BUTTON_PRESS
         else:
             select_status = BUTTON_HOVER
     elif widget.state == gtk.STATE_ACTIVE:
         select_status = BUTTON_PRESS
         
     if select_status == BUTTON_PRESS:
         draw_vlinear(cr, rect.x, rect.y, rect.width, rect.height, 
                     ui_theme.get_shadow_color("category_item_press").get_color_info())
 
         font_color = ui_theme.get_color("category_select_item").get_color()
     elif select_status == BUTTON_HOVER:
         draw_vlinear(cr, rect.x, rect.y, rect.width, rect.height, 
                     ui_theme.get_shadow_color("category_item_hover").get_color_info())
         
         font_color = ui_theme.get_color("category_select_item").get_color()
         
     # Draw navigate item.
     category_item_pixbuf = self.icon_dpixbuf.get_pixbuf()
     draw_pixbuf(
         cr, category_item_pixbuf, 
         rect.x + self.padding_left,
         rect.y + (rect.height - category_item_pixbuf.get_height()) / 2
         )
     
     # Draw font.
     draw_text(cr, self.content, 
                 rect.x + self.padding_left + self.font_offset,
                 rect.y,
                 rect.width - self.padding_left - self.font_offset - self.padding_right,
                 rect.height,
                 self.font_size, 
                 font_color,
                 )
     
     # Propagate expose to children.
     propagate_expose(widget, event)
 
     return True
Пример #30
0
    def render(self, cr, rect):
        # Draw select background.
        if self.is_select:
            draw_vlinear(cr, rect.x ,rect.y, rect.width, rect.height,
                         ui_theme.get_shadow_color("listview_select").get_color_info())

        # Draw loading text.
        draw_text(cr, "(空)",
                  rect.x + COLUMN_OFFSET * self.column_index,
                  rect.y,
                  rect.width, rect.height)
    def __treeview_paint_nodes_event(self, node_event):
        leave_width = 20
        color = self.listview_color.get_color()
        text_color = "#FFFFFF"
        #
        if node_event.node in node_event.single_items:
            color_info = [(0, (color, 0.45)), (1, (color, 0.45))] 
            draw_vlinear(node_event.cr,
                         node_event.x, node_event.y, node_event.w, node_event.h,
                         color_info
                         )
            text_color = "#000000"
        elif node_event.node in node_event.motion_items:
            color_info = [(0, (color, 0.75)), (1, (color, 0.75))] 
            draw_vlinear(node_event.cr,
                         node_event.x, node_event.y, node_event.w, node_event.h,
                         color_info
                         )
        #
        if node_event.node.leave == 1: # 根节点.
            x = node_event.x + 20
            # 画root的图标.
            if node_event.node.is_expanded:
                pixbuf = self.tree_view_close.get_pixbuf()
            else:
                pixbuf = self.tree_view_open.get_pixbuf()
            # node_event.x + 5 是图标与文字之间的宽度.
            draw_pixbuf(node_event.cr,
                        pixbuf,
                        node_event.x + 5,
                        node_event.y + node_event.h/2 - pixbuf.get_height()/2 )
        else:
            #x_padding = node_event.node.leave * leave_width
            #x = node_event.x + 18 + x_padding
            x = node_event.x + 20
            #
            if node_event.node.is_expanded:
                pixbuf = self.tree_view_bottom.get_pixbuf()
            else:
                pixbuf = self.tree_view_right.get_pixbuf()
            icon_x = node_event.x + pixbuf.get_width()/2
            icon_y = node_event.y + node_event.h/2 - pixbuf.get_height()/2

            if node_event.node.nodes or node_event.node.leave == 2:
                draw_pixbuf(node_event.cr, pixbuf, icon_x, icon_y)
        #
        draw_text(node_event.cr, 
                  node_event.node.text, 
                  x + 5,
                  node_event.y + node_event.h/2 - get_text_size(node_event.node.text, text_size=9)[1]/2,
                  text_color=text_color,
                  text_size=9
                  )
Пример #32
0
    def render_title(self, cr, rect):
        font_color = ui_theme.get_color("menu_font").get_color()

        if self.is_hover:
            draw_vlinear(cr, rect.x, rect.y, rect.width, rect.height, ui_theme.get_shadow_color("menu_item_select").get_color_info())
            font_color = ui_theme.get_color("menu_select_font").get_color()

        draw_text(cr, self.title, rect.x + self.padding_x,
                  rect.y, rect.width - self.padding_x * 2,
                  rect.height, text_size=self.font_size,
                  text_color = font_color,
                  alignment=pango.ALIGN_LEFT)
Пример #33
0
def main():
    myplayer = Player()
    game_over = False

    draw.draw_background()
    draw.draw_text_box()
    draw.update()
    sound.play_soundtrack("soundtrack/")

    sound.play_sound("dialogue/welcome.wav")
    draw.draw_text(
        "Welcome player!"
        "\nYou find yourself stranded at an unknown location, feel free to explore!"
        "\nPlease enter your name.")
    input_text = return_on_event("sound")
    myplayer.name = return_on_event("string", input_text)

    while not game_over:
        sound.play_sound("dialogue/action.wav")
        draw.draw_text(
            "Choose an action: \n [1] Move north \n [2] Move west \n [3] Move south \n [4] Move east "
            "\n [5] Look around")
        return_on_event("sound")
        try:
            action = int(float(return_on_event("string")))
        except:
            action = -1

        if not 0 < action < 6:
            draw.draw_text("Invalid input, please input a number from 1 to 5")
            sound.play_sound("dialogue/invalid.wav")
            return_on_event("sound")
        else:
            if action == 5:
                look(regions, myplayer)
                if myplayer.region == myplayer.region_shop_keeper and myplayer.gold:
                    draw.draw_text(
                        "You hand over the bag of gold and the magic shopkeeper throws powder in the air with "
                        "colorful sparks. "
                        "\nAnd you escape the island."
                        "\nCongratulations " + myplayer.name + "!")
                    sound.play_sound("dialogue/escape.wav")
                    return_on_event("sound")
                    draw.draw_text(
                        " \n \nLead Programmer & Designer: Axel Söderberg\n"
                        "Audio & Programming: Tintin Axelsson\n"
                        "Voice Acting: Eric Ryberg")
                    game_over = True
            else:
                player_move(action, myplayer)
                return_on_event("sound")
    return_on_event("text")
Пример #34
0
    def loading_flag(self, widget, event):
        cr = widget.window.cairo_create()
        rect = widget.allocation
        cr.set_source_rgb(*color_hex_to_cairo(THEME['bg']))
        cr.rectangle(0, 0, rect.width, rect.height)
        cr.fill()

        draw_text(cr,
                  rect.x,
                  rect.y,
                  text_size=20,
                  text_color=THEME['font_color'])
        propagate_expose(widget, event)
 def __treeview_paint_nodes_event(self, node_event):
     color = self.listview_color.get_color()
     text_color = "#FFFFFF"
     # 单击和移动, 双击.
     if node_event.node in node_event.single_items:
         color_info = [(0, (color, 0.45)), (1, (color, 0.45))]
         draw_vlinear(node_event.cr, node_event.x, node_event.y,
                      node_event.w, node_event.h, color_info)
         #text_color = "#000000"
     elif node_event.node in node_event.motion_items:
         color_info = [(0, (color, 0.75)), (1, (color, 0.75))]
         draw_vlinear(node_event.cr, node_event.x, node_event.y,
                      node_event.w, node_event.h, color_info)
     #
     x_padding = 12  # 因为要和搜索框对齐.
     if 0 == node_event.node.leave:  # 根节点. :比如->> >我看过的. >优酷视频. >pps.
         if node_event.node.is_expanded:
             pixbuf = self.one_open.get_pixbuf()
         else:
             pixbuf = self.one_close.get_pixbuf()
     elif 1 == node_event.node.leave:  #
         if node_event.node.is_expanded:
             pixbuf = self.two_open.get_pixbuf()
         else:
             pixbuf = self.two_close.get_pixbuf()
     else:
         if node_event.node.is_expanded:
             pixbuf = self.three_open.get_pixbuf()
         else:
             pixbuf = self.three_close.get_pixbuf()
     #
     icon_x = node_event.x + x_padding
     icon_y = node_event.y + node_event.h / 2 - pixbuf.get_height() / 2 + 1
     if node_event.node.leave > 1:
         icon_x += (node_event.node.leave - 1) * pixbuf.get_width()
     if node_event.node.leave > 0:
         text_color = "#a8a8a8"
     ##########
     # 画图标.
     if node_event.node.nodes != []:
         draw_pixbuf(node_event.cr, pixbuf, icon_x, icon_y)
     # 画文本.
     text_x_padding = 15
     text_size = 9
     draw_text(node_event.cr,
               node_event.node.text,
               icon_x + text_x_padding,
               node_event.y + node_event.h / 2 -
               get_text_size(node_event.node.text, text_size=9)[1] / 2,
               text_color=text_color,
               text_size=text_size)
Пример #36
0
 def expose_nav_item(self, widget, event):
     '''Expose navigate item.'''
     # Init.
     cr = widget.window.cairo_create()
     rect = widget.allocation
     select_index = self.get_index()
     hover_pixbuf = ui_theme.get_pixbuf("navigatebar/nav_item_hover.png").get_pixbuf()
     press_pixbuf = ui_theme.get_pixbuf("navigatebar/nav_item_press.png").get_pixbuf()
     
     # Draw background.
     if widget.state == gtk.STATE_NORMAL:
         if select_index == self.index:
             select_pixbuf = press_pixbuf
         else:
             select_pixbuf = None
     elif widget.state == gtk.STATE_PRELIGHT:
         if select_index == self.index:
             select_pixbuf = press_pixbuf
         else:
             select_pixbuf = hover_pixbuf
     elif widget.state == gtk.STATE_ACTIVE:
         select_pixbuf = press_pixbuf
         
     if select_pixbuf:
         draw_pixbuf(cr, select_pixbuf, rect.x, rect.y)
     
     # Draw navigate item.
     nav_item_pixbuf = self.icon_dpixbuf.get_pixbuf()
     draw_pixbuf(
         cr, nav_item_pixbuf, 
         rect.x + (rect.width - nav_item_pixbuf.get_width()) / 2,
         rect.y)
     
     # Draw font.
     draw_text(cr, 
               self.content, 
               rect.x, 
               rect.y + nav_item_pixbuf.get_height() - 3, 
               rect.width, 
               rect.height - nav_item_pixbuf.get_height(),
               text_color="#FFFFFF",
               alignment=pango.ALIGN_CENTER,
               gaussian_radious=2, gaussian_color="#000000",
               border_radious=1, border_color="#000000", 
               )
     
     # Propagate expose to children.
     propagate_expose(widget, event)
 
     return True
 def __paint_nodes_event(self, node_event):
     if node_event.node.leave == 0: # 根节点.
         x = node_event.x + 15
         if node_event.node.is_expanded:
             root_text = "-"
         else:
             root_text = "+"
         draw_text(node_event.cr, 
                   root_text, 
                   node_event.x + 5, 
                   node_event.y + get_text_size("+")[1]/2)
     else:
         x_padding = node_event.node.leave * self.leave_width
         x = node_event.x + 10 + x_padding
         if node_event.node.is_expanded:
             draw_text(node_event.cr, 
                       "*", 
                       node_event.x + x_padding, 
                       node_event.y + get_text_size("*")[1]/2)
         else:
             if node_event.node.leave < 2:
                 draw_text(node_event.cr, 
                           ">", 
                           node_event.x + x_padding, 
                           node_event.y + get_text_size(">")[1]/2)
     draw_text(node_event.cr, 
               node_event.node.text, 
               x,
               node_event.y + get_text_size(node_event.node.text)[1]/2)
Пример #38
0
    def expose_tab_switcher(self, widget, event):
        # Init.
        cr = widget.window.cairo_create()
        rect = widget.allocation
        
        with cairo_state(cr):
            cr.rectangle(rect.x, rect.y, rect.width, rect.height)
            cr.clip()

            # Draw tab line.
            cr.set_source_rgb(*color_hex_to_cairo(self.line_dcolor.get_color()))
            cr.rectangle(rect.x + self.padding_x, 
                         rect.y + self.tab_height,
                         rect.width - self.padding_x * 2, 
                         self.tab_line_height)
            cr.fill()
            
            # Draw tab.
            draw_start_x = rect.x + (rect.width - self.tab_width * self.tab_number) / 2
            if self.in_animiation:
                cr.rectangle(self.tab_animation_x,
                             rect.y,
                             self.tab_width,
                             self.tab_height)
            else:
                cr.rectangle(draw_start_x + self.tab_index * self.tab_width,
                             rect.y,
                             self.tab_width,
                             self.tab_height)
            cr.fill()
            
            # Draw tab name.
            for (tab_index, tab_name) in enumerate(self.tab_names):
                if self.in_animiation:
                    tab_name_color = "#000000"
                elif tab_index == self.tab_index:
                    tab_name_color = "#FFFFFF"
                else:
                    tab_name_color = "#000000"
                draw_text(cr,
                          tab_name,
                          draw_start_x + tab_index * self.tab_width,
                          rect.y,
                          self.tab_width,
                          self.tab_height,
                          text_size=self.tab_name_size,
                          text_color=tab_name_color,
                          alignment=pango.ALIGN_CENTER,
                          )
Пример #39
0
def expose_button(widget, event, 
                  cache_pixbuf,
                  scale_x, scaleY,
                  normal_dpixbuf, hover_dpixbuf, press_dpixbuf,
                  button_label, font_size, label_dcolor):
    '''Expose function to replace event box's image.'''
    # Init.
    rect = widget.allocation
    
    # Get pixbuf along with button's sate.
    if widget.state == gtk.STATE_NORMAL:
        image = normal_dpixbuf.get_pixbuf()
    elif widget.state == gtk.STATE_PRELIGHT:
        image = hover_dpixbuf.get_pixbuf()
    elif widget.state == gtk.STATE_ACTIVE:
        image = press_dpixbuf.get_pixbuf()
    
    # Init size.
    if scale_x:
        image_width = widget.allocation.width
    else:
        image_width = image.get_width()
        
    if scaleY:
        image_height = widget.allocation.height
    else:
        image_height = image.get_height()
    
    # Draw button.
    pixbuf = image
    if pixbuf.get_width() != image_width or pixbuf.get_height() != image_height:
        cache_pixbuf.scale(image, image_width, image_height)
        pixbuf = cache_pixbuf.get_cache()
    cr = widget.window.cairo_create()
    draw_pixbuf(cr, pixbuf, widget.allocation.x, widget.allocation.y)
    
    # Draw font.
    if button_label:
        draw_text(cr, button_label, 
                    rect.x, rect.y, rect.width, rect.height,
                    font_size, 
                    label_dcolor.get_color(),
                    alignment=pango.ALIGN_CENTER
                    )

    # Propagate expose to children.
    propagate_expose(widget, event)
    
    return True
Пример #40
0
def main():
    screen = d.blank_screen()
    screen = d.draw_percentage_bar(screen, 50, 72, 127, 4)
    screen = d.draw_percentage_bar(screen, 33, 72, 127, 5)
    screen = d.draw_percentage_bar(screen, 75, 72, 127, 6)
    screen = d.draw_percentage_bar(screen, 100, 72, 127, 7)
    screen = d.draw_icon(screen, 'rest-level', 64, 4)
    screen = d.draw_icon(screen, 'hygiene-level', 64, 5)
    screen = d.draw_icon(screen, 'entertain-level', 64, 6)
    screen = d.draw_icon(screen, 'food-level', 64, 7)
    screen = d.draw_icon(screen, 'thought-bubble', 64, 0)
    screen = d.draw_text(screen, 'Grumpy', 64 + 32 - 6 * 4, 1)
    screen = d.draw_text(screen, 'Hungry', 64 + 32 - 6 * 4, 2)
    screen = d.draw_icon(screen, 'crying', 8, 2)
    d.save_screen(screen, 'status.png')
Пример #41
0
    def expose_event(self, widget, event):
        cr = widget.window.cairo_create()
        rect = widget.allocation

        font_width, font_height = get_text_size(
            self.lang == "zh" and "震" or "w",
            text_size=self.font_size
        )
        y_padding = (rect.height - font_height) / 2
        draw_text(cr, self.current_text,
                  rect.x,
                  rect.y + y_padding,
                  text_size=self.font_size,
                  text_color=self.font_color)
        return True
Пример #42
0
def main():
    screen = d.blank_screen()
    screen = d.draw_percentage_bar(screen, 50, 72, 127, 4)
    screen = d.draw_percentage_bar(screen, 33, 72, 127, 5)
    screen = d.draw_percentage_bar(screen, 75, 72, 127, 6)
    screen = d.draw_percentage_bar(screen, 100, 72, 127, 7)
    screen = d.draw_icon(screen, 'rest-level', 64, 4)
    screen = d.draw_icon(screen, 'hygiene-level', 64, 5)
    screen = d.draw_icon(screen, 'entertain-level', 64, 6)
    screen = d.draw_icon(screen, 'food-level', 64, 7)
    screen = d.draw_icon(screen, 'thought-bubble', 64, 0)
    screen = d.draw_text(screen, 'Grumpy', 64 + 32 - 6*4, 1)
    screen = d.draw_text(screen, 'Hungry', 64 + 32 - 6*4, 2)
    screen = d.draw_icon(screen, 'crying', 8, 2)
    d.save_screen(screen, 'status.png')
Пример #43
0
 def render_title(self, cr, rect):
     if self.is_select:
         text_color = "#FFFFFF"
         bg_color = "#3399FF"
         cr.set_source_rgb(*color_hex_to_cairo(bg_color))
         cr.rectangle(rect.x, rect.y, rect.width, rect.height)
         cr.paint()
     else:
         text_color = "#000000"
     draw_text(cr,
               self.title,
               rect.x,
               rect.y,
               rect.width,
               rect.height,
               text_color=text_color)
 def test_paint_nodes_event(e):
     if e.node.leave == 0: # 根节点.
         draw_text(e.cr, 
                   e.node.text, 
                   e.x + e.w/2 - get_text_size(e.node.text)[0]/2, 
                   e.y + e.h/2 - get_text_size(e.node.text)[1]/2)
         e.cr.set_source_rgba(1, 1, 1, 1.0)
         e.cr.rectangle(e.x, e.y, e.w, e.h)
         e.cr.stroke()
     else:
         pixbuf = gtk.gdk.pixbuf_new_from_file("logo.png")
         pixbuf = pixbuf.scale_simple(e.h, e.h, gtk.gdk.INTERP_BILINEAR)
         draw_pixbuf(e.cr, pixbuf, e.x + e.w/2 - pixbuf.get_width()/2 + (e.node.leave - 1)* e.h, e.y)
         draw_text(e.cr, 
                   e.node.text, 
                   e.x + e.w/2 - get_text_size(e.node.text)[1]/2 + pixbuf.get_width() + e.node.leave * e.h,
                   e.y + e.h/2 - get_text_size(e.node.text)[1]/2)
Пример #45
0
 def __select_btn_expose_event(self, widget, event):
     cr = widget.window.cairo_create()
     rect = widget.allocation
     if widget.state == gtk.STATE_NORMAL:
         pixbuf = self.left_normal_pixbuf.get_pixbuf()
     elif widget.state == gtk.STATE_PRELIGHT:
         pixbuf = self.left_hover_pixbuf.get_pixbuf()
     elif widget.state == gtk.STATE_ACTIVE:
         pixbuf = self.left_press_pixbuf.get_pixbuf()
     draw_pixbuf(cr, pixbuf, rect.x, rect.y)
     text_size = get_text_size(widget.get_label(), text_size=9)
     draw_text(cr, widget.get_label(), 
               rect.x + rect.width/2 - text_size[0]/2 + 5, 
               rect.y + rect.height/2 - text_size[1]/2, 
               text_size=10)
     #
     return True
Пример #46
0
def player_move(direction, player):  # Returns new region value for player
    if illegal_move(direction, player.region):  # Check for illegal move
        draw.draw_text(
            "There's nothing but open water that way, try somewhere else!")
        sound.play_sound("dialogue/nothing.wav")
        return_on_event("sound")
    else:
        if direction == 1:
            player.region -= 3  # North
        elif direction == 2:
            player.region -= 1  # West
        elif direction == 3:
            player.region += 3  # South
        elif direction == 4:
            player.region += 1  # East
        draw.draw_text("You start walking.")
        sound.play_sound("dialogue/walking.wav")
Пример #47
0
 def __select_btn_expose_event(self, widget, event):
     cr = widget.window.cairo_create()
     rect = widget.allocation
     if widget.state == gtk.STATE_NORMAL:
         pixbuf = self.left_normal_pixbuf.get_pixbuf()
     elif widget.state == gtk.STATE_PRELIGHT:
         pixbuf = self.left_hover_pixbuf.get_pixbuf()
     elif widget.state == gtk.STATE_ACTIVE:
         pixbuf = self.left_press_pixbuf.get_pixbuf()
     draw_pixbuf(cr, pixbuf, rect.x, rect.y)
     text_size = get_text_size(widget.get_label(), text_size=9)
     draw_text(cr,
               widget.get_label(),
               rect.x + rect.width / 2 - text_size[0] / 2 + 5,
               rect.y + rect.height / 2 - text_size[1] / 2,
               text_size=10)
     #
     return True
Пример #48
0
    def render_title(self, cr, rect):
        font_color = ui_theme.get_color("menu_font").get_color()

        if self.is_hover:
            draw_vlinear(
                cr, rect.x, rect.y, rect.width, rect.height,
                ui_theme.get_shadow_color("menu_item_select").get_color_info())
            font_color = ui_theme.get_color("menu_select_font").get_color()

        draw_text(cr,
                  self.title,
                  rect.x + self.padding_x,
                  rect.y,
                  rect.width - self.padding_x * 2,
                  rect.height,
                  text_size=self.font_size,
                  text_color=font_color,
                  alignment=pango.ALIGN_LEFT)
Пример #49
0
 def __on_draw_column_heade_hd(self, e):
     if e.single_columns == e.column:
         e.cr.set_source_rgba(*alpha_color_hex_to_cairo(("#ebebeb", 0.1)))
         e.text_color = "#000000"
     elif e.motion_columns == e.column:
         e.cr.set_source_rgba(*alpha_color_hex_to_cairo(("#0000FF", 0.1)))
         e.text_color = "#0000FF"
     else:
         e.cr.set_source_rgba(*alpha_color_hex_to_cairo(("#FF00FF", 0.1)))
         e.text_color = "#FF00FF"
     e.cr.rectangle(e.x, e.y, e.w, e.h)
     e.cr.stroke()
     if self.columns[len(self.columns) - 1] == e.column:
         e.cr.set_source_rgba(*alpha_color_hex_to_cairo(("#FF00FF", 0.1)))
         e.cr.rectangle(e.x + e.w, e.y, self.allocation.width - e.x, e.h)
         e.cr.stroke()
     # 画标题栏文本.
     draw_text(e.cr, e.text, e.x, e.y, e.w, e.h, text_color=e.text_color, alignment=Text.CENTER)
Пример #50
0
    def render_name(self, cr, rect):
        '''
        Render icon and name of DirItem.
        '''
        if self.pixbuf == None:
            self.pixbuf = get_file_icon_pixbuf(self.directory_path, ICON_SIZE)

        # Draw select background.
        if self.is_select or self.is_highlight:
            draw_vlinear(cr, rect.x ,rect.y, rect.width, rect.height,
                         ui_theme.get_shadow_color("listview_select").get_color_info())

        # Draw directory arrow icon.
        if self.is_expand:
            expand_indicator_pixbuf = ui_theme.get_pixbuf("treeview/arrow_down.png").get_pixbuf()
        else:
            expand_indicator_pixbuf = ui_theme.get_pixbuf("treeview/arrow_right.png").get_pixbuf()
        draw_pixbuf(cr, expand_indicator_pixbuf,
                    rect.x + COLUMN_OFFSET * self.column_index + INDICATOR_PADDING_LEFT,
                    rect.y + (rect.height - expand_indicator_pixbuf.get_height()) / 2,
                    )

        # Draw directory icon.
        draw_pixbuf(cr, self.pixbuf,
                    rect.x + COLUMN_OFFSET * self.column_index + INDICATOR_PADDING_LEFT + expand_indicator_pixbuf.get_width() + INDICATOR_PADDING_RIGHT + ICON_PADDING_LEFT,
                    rect.y + (rect.height - ICON_SIZE) / 2,
                    )

        # Draw directory name.
        draw_text(cr, self.name,
                  rect.x + COLUMN_OFFSET * self.column_index + INDICATOR_PADDING_LEFT + expand_indicator_pixbuf.get_width() + INDICATOR_PADDING_RIGHT + ICON_PADDING_LEFT + ICON_SIZE + ICON_PADDING_RIGHT,
                  rect.y,
                  rect.width, rect.height)

        # Draw drag line.
        if self.drag_line:
            with cairo_disable_antialias(cr):
                cr.set_line_width(1)
                if self.drag_line_at_bottom:
                    cr.rectangle(rect.x, rect.y + rect.height - 1, rect.width, 1)
                else:
                    cr.rectangle(rect.x, rect.y, rect.width, 1)
                cr.fill()
Пример #51
0
 def test_paint_nodes_event(e):
     if e.node.leave == 0:  # 根节点.
         draw_text(e.cr, e.node.text,
                   e.x + e.w / 2 - get_text_size(e.node.text)[0] / 2,
                   e.y + e.h / 2 - get_text_size(e.node.text)[1] / 2)
         e.cr.set_source_rgba(1, 1, 1, 1.0)
         e.cr.rectangle(e.x, e.y, e.w, e.h)
         e.cr.stroke()
     else:
         pixbuf = gtk.gdk.pixbuf_new_from_file("logo.png")
         pixbuf = pixbuf.scale_simple(e.h, e.h, gtk.gdk.INTERP_BILINEAR)
         draw_pixbuf(
             e.cr, pixbuf, e.x + e.w / 2 - pixbuf.get_width() / 2 +
             (e.node.leave - 1) * e.h, e.y)
         draw_text(
             e.cr, e.node.text,
             e.x + e.w / 2 - get_text_size(e.node.text)[1] / 2 +
             pixbuf.get_width() + e.node.leave * e.h,
             e.y + e.h / 2 - get_text_size(e.node.text)[1] / 2)
Пример #52
0
    def expose_droplist_item(self, widget, event, item_content):
        '''
        Internal function to handle `expose-event` signal of item.

        @param widget: DropItem widget.
        @param event: Expose event.
        @param item_content: Item content.
        '''
        # Init.
        cr = widget.window.cairo_create()
        rect = widget.allocation
        font_color = ui_theme.get_color("menu_font").get_color()

        # Draw select effect.
        if self.subdroplist_active or widget.state in [
                gtk.STATE_PRELIGHT, gtk.STATE_ACTIVE
        ]:
            # Draw background.
            draw_vlinear(
                cr, rect.x, rect.y, rect.width, rect.height,
                ui_theme.get_shadow_color("menu_item_select").get_color_info())

            # Set font color.
            font_color = ui_theme.get_color("menu_select_font").get_color()

        # Draw item content.
        draw_text(
            cr,
            item_content,
            rect.x + self.item_padding_left,
            rect.y,
            rect.width,
            rect.height,
            self.font_size,
            font_color,
        )

        # Propagate expose to children.
        propagate_expose(widget, event)

        return True
Пример #53
0
    def update(self):
        if self.node == None:
            #self.node = 1
            #self.x,self.y = self.route[0]
            object_kill(self.id, 'creep')
        else:
            #print self.node
            #dx,dy = self.node
            diff_x = self.dx-self.x
            diff_y = self.dy-self.y
            dist = pow(pow(diff_x,2) + pow(diff_y,2),0.5)
            dir = math.atan2(diff_y, diff_x)

            if dist < scale/5:
                self.node = world_map[self.node]['next']
                if self.node:
                    self.dx = self.node[0]*scale + scale/2 #+ randint(-scale/3,scale/3)
                    self.dy = self.node[1]*scale + scale/2 #+ randint(-scale/3,scale/3)
            else:
                #mx = self.speed * diff_x/(abs(diff_x)+abs(diff_y))
                #my = self.speed * diff_y/(abs(diff_x)+abs(diff_y))
                mx = min(self.speed, dist) * math.cos(dir)
                my = min(self.speed, dist) * math.sin(dir)
                #print x,',', y
                self.x,self.y = self.x+mx, self.y+my

        if self.debug:
            draw.draw_text('node: '+str(self.node), (0,15), 255, 255, 255)
            draw.draw_text('pos: '+str((self.x,self.y)), (0,45), 255, 255, 255)
            draw.draw_text('dest: '+str((self.dx,self.dy)), (0,60), 255, 255, 255)
Пример #54
0
    def update(self):
        if self.cooldown > 0:
            self.cooldown = max(self.cooldown - self.speed, 0)
            
        else:
            target_id = -1
            close = 0
            for c in object_dict['creep'].values():
               dist = pow(pow(c.x-self.x,2) + pow(c.y-self.y,2),0.5)
               if dist <= self.range and (dist < close or target_id == -1):
                   close = dist
                   target_id = c.id

            self.target_id = target_id
            if target_id >= 0:
                #print 'fire at target: ', target_id
                Missile(self.x, self.y, target_id)
                self.cooldown = 1000
                
        if self.debug:
            draw.draw_text('cooldown: '+str(self.cooldown), (0,15), 255, 255, 255)
            draw.draw_text('target: '+str(self.target_id), (0,30), 255, 255, 255)
Пример #55
0
    def render(self, cr, rect):
        # Draw label content.
        with cairo_state(cr):
            if self.is_expandable:
                content_height = int(rect.height - self.label_expand_height) / self.label_line_height * self.label_line_height
                cr.rectangle(rect.x, rect.y, rect.width, content_height)
            else:
                content_height = rect.height
                cr.rectangle(rect.x, rect.y, rect.width, content_height)
            cr.clip()

            draw_text(
                cr,
                self.label_content,
                rect.x + (rect.width - self.label_wrap_width) / 2,
                rect.y,
                rect.width,
                content_height,
                text_size=self.label_font_size,
                text_color=self.label_font_color,
                wrap_width=self.label_wrap_width
                )

        # Draw expand button.
        if self.is_expandable:
            if self.has_expand:
                text = self.shrink_button_content
                text_width, text_height = self.shrink_button_width, self.shrink_button_height
            else:
                text = self.expand_button_content
                text_width, text_height = self.expand_button_width, self.expand_button_height
            draw_text(
                cr,
                text,
                rect.x + rect.width - (rect.width - self.label_wrap_width) / 2 - text_width,
                rect.y + rect.height - text_height,
                text_width,
                text_height,
                )
Пример #56
0
    def draw_value(self, cr, rect, text, value, type_=None, mark_check=False):
        text_width, text_height = get_content_size(text)
        text_y = rect.y
        if gtk.POS_TOP == type_:
            text_y = text_y
        if gtk.POS_BOTTOM == type_:
            text_y = rect.y + (rect.height-self.bottom_space)/2 + self.point_height + self.bottom_space - text_height/2

        x = rect.x + int(float(value) / self.value_max * (rect.width - self.point_width))
        max_value = max(x - (text_width/2 - self.point_width/2), rect.x)
        min_value = min(max_value, rect.x + rect.width - text_width)

        if self.enable_check:
            draw_text(cr, text, min_value, text_y, rect.width, 0)
        else:
            draw_text(cr, text, min_value, text_y, rect.width, 0, DEFAULT_FONT_SIZE, self.bg_side_color)

        mark_y = text_y-self.bottom_space/2-(self.point_height-self.line_height)/2
        if mark_check:
            cr.set_source_rgb(*color_hex_to_cairo(self.bg_side_color))
            cr.rectangle(x + self.point_width/2, mark_y, self.mark_width, self.mark_height)
            cr.fill()
Пример #57
0
    def update(self):
        if self.cooldown > 0:
            self.cooldown = max(self.cooldown - self.speed, 0)
            
        else:
            target_id = -1
            close = 0
            for c in object_dict['creep'].values():
               dist = pow(pow(c.x-self.x,2) + pow(c.y-self.y,2),0.5)
               if dist <= self.range and (dist < close or target_id == -1):
                   close = dist
                   target_id = c.id

            if target_id >= 0:
                #print 'fire at target: ', target_id
                Beam(self.x, self.y, object_dict['creep'][target_id].x, object_dict['creep'][target_id].y)
                self.cooldown = 1000
                #object_kill(target_id)
                object_dict['creep'][target_id].damage(2)
                
        if self.debug:
            draw.draw_text('cooldown: '+str(self.cooldown), (0,15), 255, 255, 255)
Пример #58
0
    def draw_ip(self, cr, rect):
        x, y, w, h = rect.x, rect.y, rect.width, rect.height
        ip_segment_distance = self.width / self.segment_number
        for (ip_segment_index,
             ip_segment) in enumerate(self.ip.split(self.segment_split_char)):
            text_color = "#000000"
            if ip_segment_index == self.highlight_segment_index:
                (ip_segment_width,
                 ip_segment_height) = get_content_size(ip_segment)

                if self.grab_focus_flag:
                    background_color = self.select_active_color.get_color_info(
                    )
                else:
                    background_color = self.select_inactive_color.get_color_info(
                    )
                draw_hlinear(
                    cr,
                    x + ip_segment_index * ip_segment_distance +
                    (ip_segment_distance - ip_segment_width) / 2,
                    y + self.cursor_padding_y,
                    ip_segment_width + 1,
                    h - self.cursor_padding_y * 2,
                    background_color,
                )

                text_color = "#FFFFFF"

            draw_text(
                cr,
                ip_segment,
                x + ip_segment_index * ip_segment_distance,
                y,
                ip_segment_distance,
                h,
                alignment=pango.ALIGN_CENTER,
                text_color=text_color,
            )
Пример #59
0
def drawing():
    gl.glClear(gl.GL_COLOR_BUFFER_BIT)  # smaz obsah okna (vybarvi na cerno)
    gl.glColor3f(0, 1, 0)  # nastav barvu kresleni na zelenu

    ### Plots the snake body
    for i in range(0, len(snake_position) - 1):
        draw_rectangle(PIECE * snake_position[i][0],
                       PIECE * snake_position[i][1],
                       PIECE * (snake_position[i][0] + 1),
                       PIECE * (snake_position[i][1] + 1))

    ### Snake head in blue
    gl.glColor3f(0, 0, 1)
    draw_rectangle(PIECE * snake_position[-1][0],
                   PIECE * snake_position[-1][1],
                   PIECE * (snake_position[-1][0] + 1),
                   PIECE * (snake_position[-1][1] + 1))

    ### Food
    draw_rectangle(PIECE * food_position[0], PIECE * food_position[1],
                   PIECE * (food_position[0] + 1),
                   PIECE * (food_position[1] + 1))
    ### Score
    draw_text(str(N - 20), PIECE * SCORE_POSITION[0],
              PIECE * SCORE_POSITION[1], 'left', PIECE * FONT_SIZE)
    ### Walls
    gl.glColor3f(0, 1, 0)  # nastav barvu kresleni na zelenu
    draw_rectangle(0, 0, PIECE * WALL_THICKNESS, PIECE * HEIGHT)
    draw_rectangle(0, 0, PIECE * WIDTH, PIECE * WALL_THICKNESS)
    draw_rectangle(PIECE * WIDTH - PIECE * WALL_THICKNESS, 0, PIECE * WIDTH,
                   PIECE * HEIGHT)
    draw_rectangle(0, PIECE * HEIGHT - PIECE * WALL_THICKNESS, PIECE * WIDTH,
                   PIECE * HEIGHT)

    if QUIT_SIGNAL == 1:
        draw_text('GAME OVER', PIECE * WIDTH // 2 - PIECE * FONT_SIZE * 4,
                  PIECE * HEIGHT // 2 - PIECE * FONT_SIZE // 2, 'left',
                  PIECE * FONT_SIZE)
Пример #60
0
def render_pixbuf(widget, event, input_args):
    '''
    Render and save pixbuf.

    @param widget: Gtk.Widget instance.
    @param event: Expose event.
    @param input_args: Input arguments as format: (select_num, vlinear_color, text_color, filepath).
    '''
    # Init.
    (select_num, vlinear_color, text_color, filepath) = input_args

    cr = widget.window.cairo_create()
    rect = widget.allocation
    num_pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, True, 8, rect.width,
                                rect.height)

    # Draw background.
    cr.set_operator(cairo.OPERATOR_OVER)
    draw_vlinear(cr, rect.x, rect.y, rect.width, rect.height,
                 eval(vlinear_color))

    # Draw text.
    draw_text(cr,
              select_num,
              rect.x,
              rect.y,
              rect.width,
              rect.height,
              text_color=text_color,
              alignment=pango.ALIGN_CENTER)

    # Render pixbuf from drawing area.
    num_pixbuf.get_from_drawable(widget.window, widget.get_colormap(), 0, 0, 0,
                                 0, rect.width,
                                 rect.height).save(filepath, "png")

    # Exit after generate png file.
    gtk.main_quit()