diff options
author | Alan Aguiar <alanjas@hotmail.com> | 2013-05-14 22:29:18 (GMT) |
---|---|---|
committer | Alan Aguiar <alanjas@hotmail.com> | 2013-05-14 22:29:18 (GMT) |
commit | a81a16eb9fb8a2d49c918d2d1922ee2d2ac3ed5c (patch) | |
tree | fed181bc901416ce2e89bd1f23217495cd2dce28 | |
parent | 68761b4d6f5e35e5690c842b1f7fc9dc77a581ce (diff) |
can select color of points
-rwxr-xr-x | activity.py | 23 | ||||
-rwxr-xr-x | main.py | 15 |
2 files changed, 31 insertions, 7 deletions
diff --git a/activity.py b/activity.py index 4a9e96e..e161e36 100755 --- a/activity.py +++ b/activity.py @@ -20,9 +20,8 @@ # Contact information: # Alan Aguiar <alanjas@gmail.com> -import sys + import gtk -import pygame import sugargame.canvas from sugar.activity import activity @@ -30,6 +29,7 @@ from sugar.graphics.toolbarbox import ToolbarBox from sugar.activity.widgets import ActivityToolbarButton from sugar.graphics.toolbutton import ToolButton from sugar.activity.widgets import StopButton +from sugar.graphics.colorbutton import ColorToolButton from gettext import gettext as _ @@ -92,6 +92,14 @@ class Activity(activity.Activity): item4.add(self.v_spin) toolbar_box.toolbar.insert(item4, -1) + # Point color + item5 = gtk.ToolItem() + self._fill_color = ColorToolButton() + self._fill_color.connect('notify::color', self.color_button_change) + item5.add(self._fill_color) + toolbar_box.toolbar.insert(item5, -1) + + # end separator separator = gtk.SeparatorToolItem() separator.props.draw = False separator.set_expand(True) @@ -118,6 +126,17 @@ class Activity(activity.Activity): def v_spin_set_max(self, value): self.v_spin.set_range(2, value) + def color_button_change(self, widget, pspec): + color = widget.get_color() + new_color = self.color_to_rgb(color) + self.game.set_point_color(new_color) + + def color_to_rgb(self, color): + r = color.red *255 / 65536 + g = color.green *255 / 65536 + b = color.blue *255 / 65536 + return (r, g, b) + def read_file(self, file_path): pass @@ -7,7 +7,6 @@ import gtk LINE_SIZE = 10 T = 15 -COLOR1 = (0, 0, 0) COLOR_OWNER = (255, 0, 0) class box: @@ -50,14 +49,20 @@ class Game: self.box_size = (50, 50) self.x_offset = 100 self.y_offset = 100 + self.line_color = (0, 0, 0) + self.point_color = (0, 0, 0) def draw_line(self, r1, r2): - pygame.draw.line(self.screen, COLOR1, r1, r2, LINE_SIZE) + pygame.draw.line(self.screen, self.line_color, r1, r2, LINE_SIZE) def set_board_size(self, size): self.grid_size = size self.draw_grid() + def set_point_color(self, color): + self.point_color = color + self.draw_grid() + def draw_grid(self): w = self.grid_size[0] h = self.grid_size[1] @@ -99,7 +104,7 @@ class Game: self.vertical.append(y) if j > 0: v_boxes.append(box(self, i - 1, j - 1)) - pygame.draw.circle(self.screen, (0, 0, 0), (x, y), LINE_SIZE, LINE_SIZE) + pygame.draw.circle(self.screen, self.point_color, (x, y), LINE_SIZE, LINE_SIZE) if i > 0: self.boxes.append(v_boxes) self.x_end = (len(self.horizontal) - 1) * self.box_size[0] + self.x_offset @@ -252,7 +257,7 @@ class Game: if b.check(): b.showText(self.current) con = True - pygame.draw.line(self.screen, COLOR1, (r1[0],self.y_offset), (r1[1],self.y_offset), LINE_SIZE) + self.draw_line((r1[0],self.y_offset), (r1[1],self.y_offset)) return con elif (y < (self.y_end + T)) and (y > self.y_end): if not(r1[0] == False): @@ -265,7 +270,7 @@ class Game: b.down = 1 if b.check(): b.showText(self.current) - pygame.draw.line(self.screen, COLOR1, (r1[0],self.y_end), (r1[1],self.y_end), LINE_SIZE) + self.draw_line((r1[0],self.y_end), (r1[1],self.y_end)) return False |