Commit fce9ab37 authored by Bruno Coudoin's avatar Bruno Coudoin

port to goocanvas goes on

svn path=/branches/gcomprixogoo/; revision=3177
parent a93b56f7
......@@ -3,6 +3,6 @@
path=$1
activity=clickanddraw
plugindir=$path/../boards/.libs
pythonplugindir=$path./drawnumber-activity
pythonplugindir=$path/../drawnumber-activity
resourcedir=$path/../drawnumber-activity/resources
section="/computer/mouse"
......@@ -32,6 +32,7 @@ import gcompris.bonus
import gcompris.anim
import gtk
import gtk.gdk
import cairo
from gettext import gettext as _
from connect4p import rules
......@@ -88,7 +89,8 @@ class Gcompris_connect4:
x=0.0,
y=0.0
)
selector.connect("event", self.columnItemEvent, 0)
selector.connect("motion_notify_event", self.columnItemEvent, 0)
selector.connect("button_press_event", self.columnItemEvent, 0)
if self.mode == 1:
self.prof = \
......@@ -98,8 +100,8 @@ class Gcompris_connect4:
x=10,
y=350.0
)
self.prof.connect("event", self.profItemEvent, 0)
self.prof.connect("event", gcompris.utils.item_event_focus)
self.prof.connect("button_press_event", self.profItemEvent, 0)
self.prof.connect("enter_notify_event", gcompris.utils.item_event_focus)
self.timericon = gcompris.anim.CanvasItem( gcompris.anim.Animation("connect4/sablier.txt"),
self.rootitem )
......@@ -116,11 +118,11 @@ class Gcompris_connect4:
self.score_item = \
goocanvas.Text(
parent = self.rootitem,
font=gcompris.skin.get_font("gcompris/board/huge bold"),
x=60,
y=250,
justification=gtk.JUSTIFY_CENTER,
fill_color_rgba=0xFF0000FFL)
font=gcompris.skin.get_font("gcompris/board/huge bold"),
x=60,
y=250,
anchor = gtk.ANCHOR_CENTER,
fill_color_rgba=0xFF0000FFL)
self.update_scores((0, 0))
......@@ -158,7 +160,7 @@ class Gcompris_connect4:
def update_scores(self, scores=None):
if scores: self.scores = list(scores)
txt = str(self.scores[0]) + "\n\n" + str(self.scores[1])
self.score_item.set(text=txt)
self.score_item.props.text = txt
def stone_init(self):
if self.player_stone:
......@@ -217,10 +219,10 @@ class Gcompris_connect4:
self.boardItem.remove()
self.boardItem = \
goocanvas.Group(
parent = self.gcomprisBoard.canvas.get_root_item(),
x=(gcompris.BOARD_WIDTH-self.boardSize)/2.0,
y=50.0
)
parent = self.gcomprisBoard.canvas.get_root_item()
)
self.boardItem.translate((gcompris.BOARD_WIDTH-self.boardSize)/2.0,
50.0)
self.player1 = human.Human(self.gcomprisBoard.level)
if self.mode == 1:
self.player2 = minmax.MinMax(self.gcomprisBoard.level, self.refreshScreen)
......@@ -240,25 +242,27 @@ class Gcompris_connect4:
if self.mode == 1:
self.prof.props.visibility = goocanvas.ITEM_VISIBLE
def columnItemEvent(self, widget, event, columns):
def columnItemEvent(self, widget, target, event, columns):
(x, y)= self.gcomprisBoard.canvas.\
convert_from_item_space(widget, event.x, event.y)
if self.mode == 1 and self.cur_player == 2: # AI playing
return False
if self.cur_player == 0 or self.timerAnim: # Game over or Timer animate
return False
if event.type == gtk.gdk.BUTTON_PRESS and event.button == 1:
column = int((event.x - (gcompris.BOARD_WIDTH-self.boardSize)/2.0) // self.stoneSize)
column = int((x - (gcompris.BOARD_WIDTH-self.boardSize)/2.0) // self.stoneSize)
if 0 <= column < self.nbColumns:
if self.play(self.player1, self.cur_player, column):
self.timericon.goocanvas.props.visibility = goocanvas.ITEM_VISIBLE
self.player_stone.props.visibility = goocanvas.ITEM_INVISIBLE
elif event.type == gtk.gdk.MOTION_NOTIFY:
column = int((event.x - (gcompris.BOARD_WIDTH-self.boardSize)/2.0) // self.stoneSize)
column = int((x - (gcompris.BOARD_WIDTH-self.boardSize)/2.0) // self.stoneSize)
if 0 <= column < self.nbColumns:
self.keyb_column = column
self.update_stone2()
return False
def profItemEvent(self, widget, event, column):
def profItemEvent(self, widget, target, event, column):
if event.type == gtk.gdk.BUTTON_PRESS:
self.cur_player=1
self.prof.props.visibility = goocanvas.ITEM_INVISIBLE
......@@ -308,7 +312,8 @@ class Gcompris_connect4:
x=x*(self.boardSize/self.nbColumns),
y=0
)
self.stone.connect("event", self.columnItemEvent, 0)
self.stone.connect("button_press_event", self.columnItemEvent, 0)
self.stone.connect("motion_notify_event", self.columnItemEvent, 0)
self.countAnim = self.nbLines-y
self.timerAnim = gobject.timeout_add(200, self.animTimer)
self.timericon.goocanvas.props.visibility = goocanvas.ITEM_VISIBLE
......@@ -343,20 +348,20 @@ class Gcompris_connect4:
self.scores[player-1] += 1
self.update_scores()
points = ( self.winLine[0][0]*(self.boardSize/self.nbColumns)+self.stoneSize/2,
(self.boardSize/self.nbColumns)*(self.nbLines-1-self.winLine[0][1])+self.stoneSize/2,
self.winLine[1][0]*(self.boardSize/self.nbColumns)+self.stoneSize/2,
(self.boardSize/self.nbColumns)*(self.nbLines-1-self.winLine[1][1])+self.stoneSize/2
)
points = goocanvas.Points([(self.winLine[0][0]*(self.boardSize/self.nbColumns)+self.stoneSize/2,
(self.boardSize/self.nbColumns)*(self.nbLines-1-self.winLine[0][1])+self.stoneSize/2),
(self.winLine[1][0]*(self.boardSize/self.nbColumns)+self.stoneSize/2,
(self.boardSize/self.nbColumns)*(self.nbLines-1-self.winLine[1][1])+self.stoneSize/2)
])
self.redLine = \
goocanvas.Polyline(
parent = self.boardItem,
fill_color_rgba=0xFF0000FFL,
points=points,
width_pixels = 8
parent = self.boardItem,
stroke_color_rgba=0xFF0000FFL,
points = points,
line_width = 8,
line_cap = cairo.LINE_CAP_ROUND
)
self.redLine.set_property("cap-style", gtk.gdk.CAP_ROUND)
if player == 1:
gcompris.bonus.display(gcompris.bonus.WIN, gcompris.bonus.FLOWER)
elif player == 2:
......
......@@ -27,11 +27,12 @@ import gcompris.score
import gtk
import gtk.gdk
import gobject
import cairo
from drawnumber import Gcompris_drawnumber
class Gcompris_clickanddraw(Gcompris_drawnumber) :
class Gcompris_clickanddraw(Gcompris_drawnumber):
def set_sublevel(self,sublevel=1):
def set_sublevel(self, sublevel=1):
"""Start of the game at sublevel number sublevel of level n"""
if self.MAX!=0 :
......@@ -44,7 +45,8 @@ class Gcompris_clickanddraw(Gcompris_drawnumber) :
)
#Setting of the first background image of the level
gcompris.set_background(self.ROOT,self.data[sublevel][0][1])
gcompris.set_background(self.gcomprisBoard.canvas.get_root_item(),
self.data[sublevel][0][1])
#Initialisation of sub-elements in list
self.POINT=[0]
......@@ -64,6 +66,7 @@ class Gcompris_clickanddraw(Gcompris_drawnumber) :
#Data loading from global data and display of points and numbers
i=self.MAX
prev_point = None
while(i>0):
if self.gcomprisBoard.level==1 :
self.POINT.append(self.point(idpt=(self.MAX-i+1),
......@@ -78,29 +81,33 @@ class Gcompris_clickanddraw(Gcompris_drawnumber) :
x=self.data[sublevel][i][0],
y=self.data[sublevel][i][1],d=20))
self.POINT[(self.MAX-i+1)].connect('event',self.action,(self.MAX-i+1))
self.POINT[(self.MAX-i+1)].connect('button_press_event',
self.action,(self.MAX-i+1))
#Setting of display level to prevent from covert a point with another
#Setting of display level to prevent covering a point with another
#point which cause an impossibility to select it.
self.POINT[(self.MAX-i+1)].lower(300-(self.MAX-i+1))
i=i-1
if prev_point:
self.POINT[(self.MAX-i+1)].lower(prev_point)
prev_point = self.POINT[(self.MAX-i+1)]
i = i-1
#Setting color of the first point to blue instead of green
self.POINT[1].set(fill_color='blue')
self.POINT[1].set_properties(fill_color_rgba = 0x003DF5D0)
def action(self,objet,truc,idpt):
def action(self, objet, target, truc, idpt):
"""Action to do at each step during normal execution of the game"""
if truc.type == gtk.gdk.BUTTON_PRESS :
if idpt == (self.actu+1): #Action to execute if the selected point is the following of previous one
xd,yd,xa,ya = self.POINT[(idpt-1)].x, self.POINT[(idpt-1)].y, self.POINT[idpt].x, self.POINT[idpt].y
goocanvas.Polyline(
parent = self.ROOT,
points=(xd,yd,xa,ya),
fill_color='black',
line_width=2)
points = goocanvas.Points([(xd,yd), (xa,ya)]),
fill_color = 'black',
line_cap = cairo.LINE_CAP_ROUND,
line_width = 2)
if idpt == 2: # Always raise the first point
self.POINT[self.MAX].raise_to_top()
self.POINT[self.MAX].raise_(None)
objet.props.visibility = goocanvas.ITEM_INVISIBLE
if idpt==self.MAX : #Action to exectute if all points have been selected in good way
......@@ -109,6 +116,7 @@ class Gcompris_clickanddraw(Gcompris_drawnumber) :
self.gamewon = 1
self.timeout = gobject.timeout_add(1500, self.lauch_bonus) # The level is complete -> Bonus display
else : #Action to execute if the selected point isn't the last one of this level
self.POINT[(idpt+1)].set(fill_color='blue') #Set color in blue to next point. Too easy ???
else : # Action to execute if the selected point isn't the last one of this level
# Set color in blue to next point. Too easy ???
self.POINT[(idpt+1)].set_properties(fill_color_rgba=0x003DF5D0)
self.actu = self.actu+1 #self.actu update to set it at actual value of selected point
......@@ -24,9 +24,11 @@ import gcompris
import gcompris.utils
import gcompris.bonus
import gcompris.score
import gcompris.skin
import gtk
import gtk.gdk
import gobject
import cairo
class Gcompris_drawnumber :
......@@ -126,23 +128,29 @@ class Gcompris_drawnumber :
#Data loading from global data and display of points and numbers
i=1
while(i<=(self.MAX)):
prev_text = None
prev_point = None
while(i <= self.MAX):
self.POINT.append(self.point(i,self.data[sublevel][i][0],
self.data[sublevel][i][1],30))
self.POINT[i].connect('button_press_event', self.action, i)
self.TEXT.append(self.text(i,
self.data[sublevel][i][0],
self.data[sublevel][i][1]))
self.TEXT[i].connect('event', self.action, i)
self.TEXT[i].lower(300-i)
self.POINT.append(self.point(i,self.data[sublevel][i][0],
self.data[sublevel][i][1],30))
self.POINT[i].connect('event', self.action, i)
self.TEXT[i].connect('button_press_event', self.action, i)
# Setting of display level to prevent covering a point with another point which
# cause an impossibility to select it.
self.TEXT[i].lower(prev_point)
prev_text = self.TEXT[i]
self.POINT[i].lower(prev_text)
prev_point = self.POINT[i]
#Setting of display level to prevent from covert a point with another point which
#cause an impossibility to select it.
self.POINT[i].lower(300-i)
i=i+1
#Setting color of the first point to blue instead of green
self.POINT[1].set(fill_color='blue')
self.POINT[1].set_properties(fill_color_rgba=0x003DF5D0)
def point(self, idpt, x, y, d=30):
"""Setting point from his x and y location"""
......@@ -152,7 +160,7 @@ class Gcompris_drawnumber :
center_y = y,
radius_x = d/2,
radius_y = d/2,
fill_color = "green", # default color is green and outline in black
fill_color_rgba = 0x3DF500D0, # default color is green and outline in black
stroke_color = "black",
line_width = 1.5
)
......@@ -163,31 +171,33 @@ class Gcompris_drawnumber :
"""Setting text beside the point number idpt locate as xt, yt"""
labell = goocanvas.Text(
parent = self.ROOT,
x=xt,
y=yt,
fill_color="black",
size_points=14,
text=str(idpt)) # ,font=gcompris.FONT_TITLE)
x = xt,
y = yt,
fill_color = "black",
font = gcompris.skin.get_font("gcompris/board/big bold"),
anchor = gtk.ANCHOR_CENTER,
text = str(idpt))
return labell
def lauch_bonus(self):
gcompris.bonus.display(gcompris.bonus.WIN, gcompris.bonus.RANDOM)
def action(self,objet,truc,idpt):
def action(self, objet, target, truc, idpt):
"""Action to do at each step during normal execution of the game"""
if truc.type == gtk.gdk.BUTTON_PRESS :
if idpt == (self.actu+1): #Action to execute if the selected point is the following of previous one
xd,yd,xa,ya=self.POINT[(idpt-1)].x,self.POINT[(idpt-1)].y,self.POINT[idpt].x,self.POINT[idpt].y
xd,yd,xa,ya = self.POINT[(idpt-1)].x,self.POINT[(idpt-1)].y,self.POINT[idpt].x,self.POINT[idpt].y
item = goocanvas.Polyline(
parent = self.ROOT,
points=(xd,yd,xa,ya),
fill_color='black',
line_width=1.5)
points = goocanvas.Points([(xd,yd),(xa,ya)]),
stroke_color = 'black',
line_cap = cairo.LINE_CAP_ROUND,
line_width = 1.5)
if idpt == 2: # Always raise the first point
self.POINT[self.MAX].raise_to_top()
self.TEXT[self.MAX].raise_to_top()
self.POINT[self.MAX].raise_(None)
self.TEXT[self.MAX].raise_(None)
self.POINT[idpt].props.visibility = goocanvas.ITEM_INVISIBLE
self.TEXT[idpt].props.visibility = goocanvas.ITEM_INVISIBLE
......@@ -197,7 +207,8 @@ class Gcompris_drawnumber :
self.timeout = gobject.timeout_add(1500, self.lauch_bonus) # The level is complete -> Bonus display
else : #Action to execute if the selected point isn't the last one of this level
#self.POINT[(idpt+1)].set(fill_color='blue') #Set color in blue to next point. Too easy ???
#Set color in blue to next point. Too easy ???
#self.POINT[(idpt+1)].set_properties(fill_color_rgba=0x003DF5F0)
self.actu=self.actu+1 #self.actu update to set it at actual value of selected point
def ok(self):
......
......@@ -19,6 +19,7 @@
# Follow Line Board module
import gobject
import goocanvas
import cairo
import gcompris
import gcompris.skin
import gcompris.bonus
......@@ -188,9 +189,10 @@ class Gcompris_followline:
item = goocanvas.Polyline(
parent = self.lines_group,
points = goocanvas.Points([(x, y), (x + step + 4, y2)]),
points = goocanvas.Points([(x, y), (x + step, y2)]),
stroke_color_rgba = self.color_empty,
line_width = line_width,
line_cap = cairo.LINE_CAP_ROUND
)
item.connect("enter_notify_event", self.line_item_event)
......@@ -202,18 +204,8 @@ class Gcompris_followline:
(x + step, y2)]),
fill_color_rgba = self.color_border,
line_width = line_width + 20,
line_cap = cairo.LINE_CAP_ROUND
)
# Make the outline smooth
goocanvas.Ellipse(
parent = self.rootitem,
center_x = x + step,
center_y = y2,
radius_x = (line_width + 20) / 2,
radius_y = (line_width + 20) / 2,
fill_color_rgba = self.color_border,
line_width = 0,
)
y = y2
self.highlight_next_line()
......
# gcompris - searace
#
# Time-stamp: <2001/08/20 00:54:45 bruno>
#
# Copyright (C) 2004 Bruno Coudoin
#
# This program is free software; you can redistribute it and/or modify
......@@ -130,6 +128,8 @@ class Gcompris_searace:
y=0,
)
item.connect("button_press_event", self.ruler_item_event)
item.connect("button_release_event", self.ruler_item_event)
item.connect("motion_notify_event", self.ruler_item_event)
self.display_sea_area()
......@@ -179,7 +179,7 @@ class Gcompris_searace:
self.race_one_command(self.left_boat)
self.race_one_command(self.right_boat)
else:
self.statusitem.set(text=_("The race is already being run"))
self.statusitem.props.text = _("The race is already being run")
# Called by gcompris when the user click on the level icon
def set_level(self, level):
......@@ -256,10 +256,11 @@ class Gcompris_searace:
pixbuf = pixmap,
x=self.left_boat.x,
y=self.left_boat.y,
anchor=gtk.ANCHOR_CENTER,
)
self.left_boat.item.raise_(None)
self.left_boat.item.connect("button_press_event", self.ruler_item_event)
self.left_boat.item.connect("button_release_event", self.ruler_item_event)
self.left_boat.item.connect("motion_notify_event", self.ruler_item_event)
if(self.right_boat.item):
self.right_boat.item.remove()
......@@ -270,10 +271,11 @@ class Gcompris_searace:
pixbuf = pixmap,
x=self.right_boat.x,
y=self.right_boat.y,
anchor=gtk.ANCHOR_CENTER,
)
self.right_boat.item.raise_(None)
self.right_boat.item.connect("button_press_event", self.ruler_item_event)
self.right_boat.item.connect("button_release_event", self.ruler_item_event)
self.right_boat.item.connect("motion_notify_event", self.ruler_item_event)
# Reset command line processing as well.
......@@ -283,7 +285,9 @@ class Gcompris_searace:
self.right_boat.arrived = False
self.left_boat.won = False
self.right_boat.won = False
self.statusitem.set(text="")
self.left_boat.speeditem.props.text = ""
self.right_boat.speeditem.props.text = ""
self.statusitem.props.text = ""
# Let the user enter comands
self.left_boat.tv.set_editable(True)
......@@ -319,17 +323,6 @@ class Gcompris_searace:
color = cb
ci += 1
# Shadow for text number
item = goocanvas.Text(
parent = self.rootitem,
text=int(ci),
font=gcompris.skin.get_font("gcompris/content"),
x=text_x+1,
y=y+1,
fill_color_rgba=0x000000FFL
)
item.connect("button_press_event", self.ruler_item_event)
# Text number
item = goocanvas.Text(
parent = self.rootitem,
......@@ -337,18 +330,23 @@ class Gcompris_searace:
font=gcompris.skin.get_font("gcompris/content"),
x=text_x,
y=y,
fill_color_rgba=cb
fill_color_rgba=cb,
anchor = gtk.ANCHOR_CENTER
)
item.connect("button_press_event", self.ruler_item_event)
item.connect("button_release_event", self.ruler_item_event)
item.connect("motion_notify_event", self.ruler_item_event)
item = goocanvas.Polyline(
parent = self.rootitem,
points = goocanvas.Points([(self.sea_area[0], y),
(self.sea_area[2], y)]),
fill_color_rgba = color,
stroke_color_rgba = color,
line_width = 1.0
)
item.connect("button_press_event", self.ruler_item_event)
item.connect("button_release_event", self.ruler_item_event)
item.connect("motion_notify_event", self.ruler_item_event)
ci = 0
......@@ -359,17 +357,6 @@ class Gcompris_searace:
color = cb
ci += 1
# Shadow for text number
item = goocanvas.Text(
parent = self.rootitem,
text=int(ci),
font=gcompris.skin.get_font("gcompris/content"),
x=x+1,
y=text_y+1,
fill_color_rgba=0x000000FFL
)
item.connect("button_press_event", self.ruler_item_event)
# Text number
item = goocanvas.Text(
parent = self.rootitem,
......@@ -377,7 +364,8 @@ class Gcompris_searace:
font=gcompris.skin.get_font("gcompris/content"),
x=x,
y=text_y,
fill_color_rgba=cb
fill_color_rgba=cb,
anchor = gtk.ANCHOR_CENTER
)
item.connect("button_press_event", self.ruler_item_event)
......@@ -385,7 +373,7 @@ class Gcompris_searace:
parent = self.rootitem,
points= goocanvas.Points([(x, self.sea_area[1]),
(x, self.sea_area[3])]),
fill_color_rgba = color,
stroke_color_rgba = color,
line_width=1.0
)
item.connect("button_press_event", self.ruler_item_event)
......@@ -396,7 +384,7 @@ class Gcompris_searace:
parent = self.rootitem,
points = goocanvas.Points([(self.sea_area[2], self.sea_area[1]-5),
(self.sea_area[2], self.sea_area[3]+5)]),
fill_color_rgba = 0xFF0000FFL,
stroke_color_rgba = 0xFF0000FFL,
line_width=5.0
)
item.connect("button_press_event", self.ruler_item_event)
......@@ -465,7 +453,8 @@ class Gcompris_searace:
font=gcompris.skin.get_font("gcompris/content"),
x=x_left,
y=y-20,
fill_color_rgba=0xFF0000FFL
fill_color_rgba=0xFF0000FFL,
anchor = gtk.ANCHOR_CENTER
)
self.right_boat.speeditem = goocanvas.Text(
......@@ -474,7 +463,8 @@ class Gcompris_searace:
font=gcompris.skin.get_font("gcompris/content"),
x=x_right,
y=y-20,
fill_color_rgba=0X027308FFL
fill_color_rgba=0X027308FFL,
anchor = gtk.ANCHOR_CENTER
)
# The status area
......@@ -484,7 +474,8 @@ class Gcompris_searace:
font=gcompris.skin.get_font("gcompris/content"),
x=gcompris.BOARD_WIDTH/2,
y=y-40,
fill_color_rgba=0X000a89FFL
fill_color_rgba=0X000a89FFL,
anchor = gtk.ANCHOR_CENTER
)
# The decoration boats
......@@ -492,21 +483,17 @@ class Gcompris_searace:
item = goocanvas.Image(
parent = self.rootitem,
pixbuf = pixmap,
x=25,
y=y+40,
anchor=gtk.ANCHOR_CENTER,
)
gcompris.utils.item_rotate_relative(item, -90);
gcompris.utils.item_rotate(item, -90);
item.translate(-y-40, -10)
pixmap = gcompris.utils.load_pixmap("searace/top_boat_green.png")
item = goocanvas.Image(
parent = self.rootitem,
pixbuf = pixmap,
x=gcompris.BOARD_WIDTH-25,
y=y+40,
anchor=gtk.ANCHOR_CENTER,
)
gcompris.utils.item_rotate_relative(item, -90);
gcompris.utils.item_rotate(item, -90);
item.translate(-y-40, gcompris.BOARD_WIDTH-60)
# The commands
hl = 18
......@@ -518,16 +505,18 @@ class Gcompris_searace:
font=gcompris.skin.get_font("gcompris/content"),
x=gcompris.BOARD_WIDTH/2,
y=y,
fill_color_rgba=text_color
fill_color_rgba=text_color,
anchor = gtk.ANCHOR_CENTER
)
self.rootitem.add (
goocanvas.Text,
goocanvas.Text(
parent = self.rootitem,
text=_("forward"),
font=gcompris.skin.get_font("gcompris/content"),
x=gcompris.BOARD_WIDTH/2,
y=y+hl,
fill_color_rgba= text_color
fill_color_rgba= text_color,
anchor = gtk.ANCHOR_CENTER
)
goocanvas.Text(
......@@ -536,7 +525,8 @@ class Gcompris_searace:
font=gcompris.skin.get_font("gcompris/content"),
x=gcompris.BOARD_WIDTH/2,
y=y+hl*2,
fill_color_rgba= text_color
fill_color_rgba= text_color,
anchor = gtk.ANCHOR_CENTER
)
goocanvas.Text(
......@@ -545,7 +535,8 @@ class Gcompris_searace:
font=gcompris.skin.get_font("gcompris/content"),
x=gcompris.BOARD_WIDTH/2,
y=y+hl*3,
fill_color_rgba=text_color
fill_color_rgba=text_color,
anchor = gtk.ANCHOR_CENTER
)
......@@ -613,21 +604,11 @@ class Gcompris_searace:
pixbuf = pixmap,
x=cx,
y=cy,
anchor=gtk.ANCHOR_CENTER
)
gcompris.utils.item_rotate_relative(item, condition[1][0]);
item.connect("button_press_event", self.ruler_item_event)
# Text number Shadow
item = goocanvas.Text(
parent = self.root_weather_item,
text=condition[1][1],
font=gcompris.skin.get_font("gcompris/content"),
x=cx+1+pixmap.get_width()/2,
y=cy+1+pixmap.get_height()/2,
fill_color_rgba=0x000000FFL
)
item.connect("button_press_event", self.ruler_item_event)
item.connect("button_release_event", self.ruler_item_event)
item.connect("motion_notify_event", self.ruler_item_event)
# Text number
item = goocanvas.Text (
......@@ -636,15 +617,19 @@ class Gcompris_searace:
font=gcompris.skin.get_font("gcompris/content"),
x=cx+pixmap.get_width()/2,
y=cy+pixmap.get_height()/2,
fill_color_rgba=0xFFFFFFFFL
fill_color_rgba=0xFFFFFFFFL,
anchor = gtk.ANCHOR_CENTER
)
item.connect("button_press_event", self.ruler_item_event)
item.connect("button_release_event", self.ruler_item_event)
item.connect("motion_notify_event", self.ruler_item_event)
return
# Given a boat item, return it's weather condition
def get_weather_condition(self, boat):
(x, y)= boat.item.i2w( boat.x, boat.y)
(x, y)= self.gcomprisBoard.canvas.\
convert_from_item_space(boat.item, boat.x, boat.y)
# Look in the cache to speed the process
if(boat.condition):
......@@ -722,15 +707,18 @@ class Gcompris_searace:
boat.y += 0
# We need to convert the coord to the rootitem coordinate to check limits
(x, y)= boat.item.i2w( boat.x, boat.y)
(x, y)= self.gcomprisBoard.canvas.\
convert_from_item_space(boat.item, boat.x, boat.y)
# Manage the wrapping
if(y<self.sea_area[1]):
y = self.sea_area[3]
(boat.x, boat.y)= boat.item.w2i( x, y)
(boat.x, boat.y)= self.gcomprisBoard.canvas.\
convert_to_item_space(boat.item, x, y)
elif(y>self.sea_area[3]):
y = self.sea_area[1]
(boat.x, boat.y)= boat.item.w2i( x, y)
(boat.x, boat.y)= self.gcomprisBoard.canvas.\
convert_to_item_space(boat.item, x, y)
elif(x>self.sea_area[2]):
boat.arrived = True
boat.finish_time = time.time()
......@@ -740,26 +728,26 @@ class Gcompris_searace:
boat.won = True
elif(abs(self.left_boat.finish_time - self.right_boat.finish_time) < 1):
# The two boat arrived in a close time frame (1s), it's a draw
self.statusitem.set(text=_("This is a draw"))