def __init__(self, app, rows, cols, spacing=15): Clutter.Actor.__init__(self) self.settings = Gio.Settings.new(base.SCHEMA_ID) self.settings.connect("changed::cards", self.update_cards) self.settings.connect("changed::show-value-on-cards", self.update_cards) self.app = app self.canvas = Clutter.Canvas() self.canvas.connect("draw", self.draw_rect) self.set_content(self.canvas) self.set_x_expand(False) self.set_y_expand(False) self.column_width, self.row_height = base.get_card_size() self.canvas.set_size(cols*self.column_width+(cols+1)*spacing,rows*self.row_height+(rows+1)*spacing) self.max_height = 0 self.max_width = 0 self.rows = rows self.cols = cols self.face_up = True self.spacing = spacing self.children = [] n=0 while n<rows: self.children.append([]) i=0 while i<cols: self.children[n].append(0) i=i+1 n=n+1
def relayout(self): card_w, card_h = base.get_card_size() if self.max_height > 0 and self.rows > 1: self.row_height = int( (self.max_height - (self.rows + 1) * self.spacing - card_h) / (self.rows - 1)) if self.max_width > 0 and self.cols > 1: self.column_width = int( (self.max_width - (self.cols + 1) * self.spacing - card_w) / (self.cols - 1)) h = (self.rows + 1) * self.spacing + card_h + (self.rows - 1) * self.row_height w = (self.cols + 1) * self.spacing + card_w + (self.cols - 1) * self.column_width self.canvas.set_size(w, h) r = 0 while r < self.rows: c = 0 while c < self.cols: if self.children[r][c] != 0: self.children[r][c].set_x( self.get_x() + c * (self.column_width + self.spacing) + self.spacing) self.children[r][c].set_y( self.get_y() + r * (self.row_height + self.spacing) + self.spacing) c += 1 r += 1
def __init__(self, app, with_scopa=False, padding=15): Clutter.Actor.__init__(self) self.settings = Gio.Settings.new(base.SCHEMA_ID) self.settings.connect("changed::cards", self.update_cards) self.app = app self.canvas = Clutter.Canvas() self.canvas.connect("draw", self._draw) self.set_content(self.canvas) self.child_w, self.child_h = base.get_card_size() self.set_x_expand(False) self.set_y_expand(False) self.padding = padding self.surface = cairo.ImageSurface.create_from_png( base.percorso_carte + self.settings.get_string('cards') + '/' + base.immagini[1][0]) self.cards = [] self.with_scopa = with_scopa self.scopa_card = None self.scope = 0 if with_scopa: self.canvas.set_size(2 * (padding + self.child_w), 2 * padding + self.child_h + 20) else: self.canvas.set_size(2 * padding + self.child_w + 20, 2 * padding + self.child_h + 20)
def __init__(self, app, rows, cols, spacing=15): Clutter.Actor.__init__(self) self.settings = Gio.Settings.new(base.SCHEMA_ID) self.settings.connect("changed::cards", self.update_cards) self.settings.connect("changed::show-value-on-cards", self.update_cards) self.app = app self.canvas = Clutter.Canvas() self.canvas.connect("draw", self.draw_rect) self.set_content(self.canvas) self.set_x_expand(False) self.set_y_expand(False) self.column_width, self.row_height = base.get_card_size() self.canvas.set_size(cols * self.column_width + (cols + 1) * spacing, rows * self.row_height + (rows + 1) * spacing) self.max_height = 0 self.max_width = 0 self.rows = rows self.cols = cols self.face_up = True self.spacing = spacing self.children = [] n = 0 while n < rows: self.children.append([]) i = 0 while i < cols: self.children[n].append(0) i = i + 1 n = n + 1
def update_cards(self, settings=None, key=None): self.surface = cairo.ImageSurface.create_from_png(base.percorso_carte+self.settings.get_string('cards')+'/'+base.immagini[1][0]) self.child_w,self.child_h = base.get_card_size() if self.with_scopa: self.canvas.set_size(2*(self.padding+self.child_w),2*self.padding+self.child_h+20) else: self.canvas.set_size(2*self.padding+self.child_w+20,2*self.padding+self.child_h+20) self.draw()
def draw_card(self, face_up=True): self.face_up = face_up self.w, self.h=base.get_card_size() if self.get_reactive(): flag = self.canvas.set_size(self.w+s,self.h+s) self.set_size(self.w+s,self.h+s) else: flag = self.canvas.set_size(self.w,self.h) self.set_size(self.w,self.h) if (not flag): self.canvas.invalidate()
def draw_card(self, face_up=True): self.face_up = face_up self.w, self.h = base.get_card_size() if self.get_reactive(): flag = self.canvas.set_size(self.w + s, self.h + s) self.set_size(self.w + s, self.h + s) else: flag = self.canvas.set_size(self.w, self.h) self.set_size(self.w, self.h) if (not flag): self.canvas.invalidate()
def update_cards(self, settings=None, key=None): self.surface = cairo.ImageSurface.create_from_png( base.percorso_carte + self.settings.get_string('cards') + '/' + base.immagini[1][0]) self.child_w, self.child_h = base.get_card_size() if self.with_scopa: self.canvas.set_size(2 * (self.padding + self.child_w), 2 * self.padding + self.child_h + 20) else: self.canvas.set_size(2 * self.padding + self.child_w + 20, 2 * self.padding + self.child_h + 20) self.draw()
def relayout(self): card_w,card_h = base.get_card_size() if self.max_height>0 and self.rows>1: self.row_height = int((self.max_height-(self.rows+1)*self.spacing-card_h)/(self.rows-1)) if self.max_width>0 and self.cols>1: self.column_width = int((self.max_width-(self.cols+1)*self.spacing-card_w)/(self.cols-1)) h=(self.rows+1)*self.spacing+card_h+(self.rows-1)*self.row_height w=(self.cols+1)*self.spacing+card_w+(self.cols-1)*self.column_width self.canvas.set_size(w,h) r=0 while r<self.rows: c=0 while c<self.cols: if self.children[r][c] != 0: self.children[r][c].set_x(self.get_x()+c*(self.column_width+self.spacing)+self.spacing) self.children[r][c].set_y(self.get_y()+r*(self.row_height+self.spacing)+self.spacing) c+=1 r+=1
def __init__(self, app, with_scopa=False, padding=15): Clutter.Actor.__init__(self) self.settings = Gio.Settings.new(base.SCHEMA_ID) self.settings.connect("changed::cards", self.update_cards) self.app = app self.canvas = Clutter.Canvas() self.canvas.connect("draw", self._draw) self.set_content(self.canvas) self.child_w,self.child_h = base.get_card_size() self.set_x_expand(False) self.set_y_expand(False) self.padding = padding self.surface = cairo.ImageSurface.create_from_png(base.percorso_carte+self.settings.get_string('cards')+'/'+base.immagini[1][0]) self.cards = [] self.with_scopa = with_scopa self.scopa_card = None self.scope = 0 if with_scopa: self.canvas.set_size(2*(padding+self.child_w),2*padding+self.child_h+20) else: self.canvas.set_size(2*padding+self.child_w+20,2*padding+self.child_h+20)
def get_natural_height(self): return (self.rows+1)*self.spacing+self.rows*base.get_card_size()[1]
def get_natural_width(self): return (self.cols+1)*self.spacing+self.cols*base.get_card_size()[0]
def get_min_height(self): if self.rows>1: return (self.rows+1)*self.spacing+(self.rows-1)*min_height+base.get_card_size()[1] return (self.rows+1)*self.spacing+self.rows*base.get_card_size()[1]
def get_min_width(self): if self.cols>1: return (self.cols+1)*self.spacing+(self.cols-1)*min_width+base.get_card_size()[0] return (self.cols+1)*self.spacing+self.cols*base.get_card_size()[0]
def get_min_width(self): if self.cols > 1: return (self.cols + 1) * self.spacing + ( self.cols - 1) * min_width + base.get_card_size()[0] return (self.cols + 1) * self.spacing + self.cols * base.get_card_size()[0]
def _draw(self, canvas, cr, width, height): cr.set_operator(cairo.OPERATOR_CLEAR) cr.paint() cr.set_operator(cairo.OPERATOR_OVER) w,h=base.get_card_size() if self.face_up: ### Shadow effect using cairo, clutter one doesn't work ### if self.mouse_over: #down-left corner rg = cairo.RadialGradient(s+r, self.h-r, 0, s+r, self.h-r, s+r) rg.add_color_stop_rgba(0.0, 0.4, 0.4, 0.4, 1.0) rg.add_color_stop_rgba(1.0, 0, 0, 0, 0) cr.set_source(rg) cr.rectangle(0, self.h-r, s+r, s+r) cr.fill() #down lg = cairo.LinearGradient(0, self.h-r, 0, self.h+s) lg.add_color_stop_rgba(0.0, 0.4, 0.4, 0.4, 1.0) lg.add_color_stop_rgba(1.0, 0, 0, 0, 0) cr.rectangle(s+r, self.h-r, self.w-s-2*r, s+r) cr.set_source(lg) cr.fill() #top-right corner rg = cairo.RadialGradient(self.w-r, s+r, 0, self.w-r, s+r, s+r) rg.add_color_stop_rgba(0.0, 0.4, 0.4, 0.4, 1.0) rg.add_color_stop_rgba(1.0, 0, 0, 0, 0) cr.set_source(rg) cr.rectangle(self.w-r, 0, s+r, s+r) cr.fill() #up lg = cairo.LinearGradient(self.w-r, 0, self.w+s, 0) lg.add_color_stop_rgba(0.0, 0.4, 0.4, 0.4, 1.0) lg.add_color_stop_rgba(1.0, 0, 0, 0, 0) cr.rectangle(self.w-r, s+r, self.w+r, self.h-s-2*r) cr.set_source(lg) cr.fill() #down-right corner rg = cairo.RadialGradient(self.w-r, self.h-r, 0, self.w-r, self.h-r, s+r) rg.add_color_stop_rgba(0.0, 0.4, 0.4, 0.4, 1.0) rg.add_color_stop_rgba(1.0, 0, 0, 0, 0) cr.set_source(rg) cr.rectangle(self.w-r, self.h-r, s+r, s+r) cr.fill() ### Now drawing the card ### surface = cairo.ImageSurface.create_from_png(base.percorso_carte+self.settings.get_string('cards')+'/'+base.immagini[self.suit][self.value]) cr.set_source_surface(surface,0,0) cr.paint() if self.settings.get_boolean('show-value-on-cards'): cr.set_font_size(15) xb, yb, w, h, xadvance, yadvance = (cr.text_extents(str(self.value))) w,h=int(w),int(h) sur = cairo.ImageSurface(cairo.FORMAT_ARGB32,w+10,h+10) tmp = cairo.Context(sur) tmp.set_source_rgb(0,0,0) tmp.paint() tmp.set_source_rgb(1,1,1) tmp.set_font_size(15) tmp.move_to(5,h+5) tmp.show_text(str(self.value)) cr.set_source_surface(sur,0,0) cr.paint() else: surface = cairo.ImageSurface.create_from_png(base.percorso_carte+self.settings.get_string('cards')+'/'+base.immagini[1][0]) cr.set_source_surface(surface,0,0) cr.paint() return True
def _draw(self, canvas, cr, width, height): cr.set_operator(cairo.OPERATOR_CLEAR) cr.paint() cr.set_operator(cairo.OPERATOR_OVER) w, h = base.get_card_size() if self.face_up: ### Shadow effect using cairo, clutter one doesn't work ### if self.mouse_over: #down-left corner rg = cairo.RadialGradient(s + r, self.h - r, 0, s + r, self.h - r, s + r) rg.add_color_stop_rgba(0.0, 0.4, 0.4, 0.4, 1.0) rg.add_color_stop_rgba(1.0, 0, 0, 0, 0) cr.set_source(rg) cr.rectangle(0, self.h - r, s + r, s + r) cr.fill() #down lg = cairo.LinearGradient(0, self.h - r, 0, self.h + s) lg.add_color_stop_rgba(0.0, 0.4, 0.4, 0.4, 1.0) lg.add_color_stop_rgba(1.0, 0, 0, 0, 0) cr.rectangle(s + r, self.h - r, self.w - s - 2 * r, s + r) cr.set_source(lg) cr.fill() #top-right corner rg = cairo.RadialGradient(self.w - r, s + r, 0, self.w - r, s + r, s + r) rg.add_color_stop_rgba(0.0, 0.4, 0.4, 0.4, 1.0) rg.add_color_stop_rgba(1.0, 0, 0, 0, 0) cr.set_source(rg) cr.rectangle(self.w - r, 0, s + r, s + r) cr.fill() #up lg = cairo.LinearGradient(self.w - r, 0, self.w + s, 0) lg.add_color_stop_rgba(0.0, 0.4, 0.4, 0.4, 1.0) lg.add_color_stop_rgba(1.0, 0, 0, 0, 0) cr.rectangle(self.w - r, s + r, self.w + r, self.h - s - 2 * r) cr.set_source(lg) cr.fill() #down-right corner rg = cairo.RadialGradient(self.w - r, self.h - r, 0, self.w - r, self.h - r, s + r) rg.add_color_stop_rgba(0.0, 0.4, 0.4, 0.4, 1.0) rg.add_color_stop_rgba(1.0, 0, 0, 0, 0) cr.set_source(rg) cr.rectangle(self.w - r, self.h - r, s + r, s + r) cr.fill() ### Now drawing the card ### surface = cairo.ImageSurface.create_from_png( base.percorso_carte + self.settings.get_string('cards') + '/' + base.immagini[self.suit][self.value]) cr.set_source_surface(surface, 0, 0) cr.paint() if self.settings.get_boolean('show-value-on-cards'): cr.set_font_size(15) xb, yb, w, h, xadvance, yadvance = (cr.text_extents( str(self.value))) w, h = int(w), int(h) sur = cairo.ImageSurface(cairo.FORMAT_ARGB32, w + 10, h + 10) tmp = cairo.Context(sur) tmp.set_source_rgb(0, 0, 0) tmp.paint() tmp.set_source_rgb(1, 1, 1) tmp.set_font_size(15) tmp.move_to(5, h + 5) tmp.show_text(str(self.value)) cr.set_source_surface(sur, 0, 0) cr.paint() else: surface = cairo.ImageSurface.create_from_png( base.percorso_carte + self.settings.get_string('cards') + '/' + base.immagini[1][0]) cr.set_source_surface(surface, 0, 0) cr.paint() return True
def get_min_height(self): if self.rows > 1: return (self.rows + 1) * self.spacing + ( self.rows - 1) * min_height + base.get_card_size()[1] return (self.rows + 1) * self.spacing + self.rows * base.get_card_size()[1]
def get_natural_height(self): return (self.rows + 1) * self.spacing + self.rows * base.get_card_size()[1]
def get_natural_width(self): return (self.cols + 1) * self.spacing + self.cols * base.get_card_size()[0]