From 5fb4e26f2329c8522047fb13a9f4975b309ce7d8 Mon Sep 17 00:00:00 2001 From: Walter Bender Date: Thu, 21 Jan 2010 15:05:11 +0000 Subject: fixed findsprite bug --- diff --git a/TurtleArtActivity.py b/TurtleArtActivity.py index 15bd409..d5b5ed2 100644 --- a/TurtleArtActivity.py +++ b/TurtleArtActivity.py @@ -63,6 +63,8 @@ from taexporthtml import * from taexportlogo import * import re +from constants import * + SERVICE = 'org.laptop.TurtleArtActivity' IFACE = SERVICE PATH = '/org/laptop/TurtleArtActivity' @@ -419,7 +421,7 @@ class TurtleArtActivity(activity.Activity): self.tw.cartesian_coordinates_spr.hide() self.tw.cartesian = False else: - self.tw.cartesian_coordinates_spr.set_layer(610) + self.tw.cartesian_coordinates_spr.set_layer(OVERLAY_LAYER) self.tw.cartesian = True def _do_polar_cb(self, button): @@ -427,7 +429,7 @@ class TurtleArtActivity(activity.Activity): self.tw.polar_coordinates_spr.hide() self.tw.polar = False else: - self.tw.polar_coordinates_spr.set_layer(610) + self.tw.polar_coordinates_spr.set_layer(OVERLAY_LAYER) self.tw.polar = True """ diff --git a/block.py b/block.py index f88dd27..02fcaf4 100644 --- a/block.py +++ b/block.py @@ -93,7 +93,7 @@ class Block: else: print "%s %s (%d %d)" % (name, labels[0], x, y) - svg = block_factory.SVG() + svg = sprite_factory.SVG() if name in TURTLE_PALETTE: svg.set_colors(TURTLE_COLORS) elif name in PEN_PALETTE: @@ -167,6 +167,24 @@ class Block: for label in labels: self.spr.set_label(label, labels.index(label)) + self.type = 'block' + +class Turtle: + def __init__(self, blocks, orientation=0, scale=1.0): + self.blocks = blocks + self.spr = None + self._new_turtle_from_prototype(orientation, scale) + self.blocks.append_to_list(self) + self.orientation = orientation + + def _new_turtle_from_prototype(self, orientation, scale): + svg = sprite_factory.SVG() + svg.set_scale(scale) + svg.set_orientation(orientation) + self.spr = sprites.Sprite(self.blocks.sprites, 0, 0, + svg_str_to_pixbuf(svg.turtle())) + self.type = 'turtle' + # # Load pixbuf from SVG string # diff --git a/constants.py b/constants.py index 47d6b86..41e11dd 100644 --- a/constants.py +++ b/constants.py @@ -13,6 +13,17 @@ from gettext import gettext as _ +# sprite layers +CANVAS_LAYER = 600 +TURTLE_LAYER = 630 +HIDE_LAYER = 100 +OVERLAY_LAYER = 615 +STATUS_LAYER = 710 +TOP_LAYER = 2000 +BLOCK_LAYER = 650 +CATEGORY_LAYER = 660 +TAB_LAYER = 670 + # block to proto tables BASIC_STYLE_HEAD = ['start', 'action 1', 'action 2'] BASIC_STYLE_TAIL = ['stop action'] diff --git a/sprite_factory.py b/sprite_factory.py index 061d624..e56ff09 100755 --- a/sprite_factory.py +++ b/sprite_factory.py @@ -34,6 +34,7 @@ class SVG: self._width = 0 self._height = 0 self._scale = 1 + self._orientation = 0 self._radius = 8 self._stroke_width = 1 self._innie = [False] @@ -197,6 +198,43 @@ class SVG: svg += self._end_boolean() return self._header() + svg + def turtle(self): + self._fill, self._stroke = "#D0D000", "none" + svg = self._rect(21, 21, 19.5, 18) + self._fill = "#808000" + svg += self._rect(3, 3, 30, 24) + svg += self._rect(3, 3, 24, 24) + svg += self._rect(3, 3, 30, 30) + svg += self._rect(3, 3, 24, 30) + svg += self._rect(3, 3, 27, 27) + svg += self._rect(3, 3, 21, 27) + svg += self._rect(3, 3, 33, 27) + svg += self._rect(3, 3, 27, 21) + svg += self._rect(3, 3, 21, 21) + svg += self._rect(3, 3, 33, 21) + svg += self._rect(3, 3, 27, 33) + svg += self._rect(3, 3, 21, 33) + svg += self._rect(3, 3, 33, 33) + svg += self._rect(3, 3, 30, 36) + svg += self._rect(3, 3, 24, 36) + svg += self._rect(3, 3, 30, 18) + svg += self._rect(3, 3, 24, 18) + svg += self._rect(3, 3, 36, 24) + svg += self._rect(3, 3, 36, 30) + svg += self._rect(3, 3, 36, 18) + svg += self._rect(3, 3, 36, 36) + self._fill, self._stroke = "#008000", "#008000" + svg += self._turtle_body() + self._fill, self._stroke = "#00a000", "#00a000" + svg += self._turtle_shell() + self._fill, self._stroke = "#000000", "#000000" + svg += self._circle(1.25,32.5,8) + svg += self._circle(1.25,27.5,8) + svg += self._footer() + self._width, self._height = 60, 60 + # TODO: Add orientation + return self._header() + svg + # # Utility methods # @@ -204,6 +242,9 @@ class SVG: def set_scale(self, scale=1): self._scale = scale + def set_orientation(self, orientation=0): + self._orientation = orientation + def expand(self, w=0, h=0): self._expand_x = w self._expand_y = h @@ -319,6 +360,24 @@ class SVG: "stroke-linecap:square;", "stroke-opacity:1;\" />\n") + def _circle(self, r, cx, cy): + return "%s%s%s%s%s%f%s%f%s%f%s" % ("") + + def _rect(self, w, h, x, y): + return "%s%s%s%s%s%f%s%f%s%f%s%f%s" % ("") + + def _turtle_body(self): + return "%s%s%s%s%s" % ("") + + def _turtle_shell(self): + return "%s%s%s%s%s" % ("") + def _check_min_max(self): if self._x < self._min_x: self._min_x = self._x diff --git a/sprites.py b/sprites.py index 2b5e9ad..23626c5 100644 --- a/sprites.py +++ b/sprites.py @@ -67,7 +67,7 @@ class Sprites: self.list.remove(spr) def find_sprite(self, pos): - list = self.list + list = self.list[:] list.reverse() for spr in list: if spr.hit(pos): return spr @@ -171,10 +171,12 @@ class Sprite: self.sprites.remove_from_list(self) def inval(self): + # print "inval (%f,%f) (%f,%f)" % (self.x,self.y,self.width,self.height) self.sprites.area.invalidate_rect( gtk.gdk.Rectangle(self.x,self.y,self.width,self.height), False) def draw(self): + # print "draw (%f,%f)" % (self.x,self.y) if isinstance(self.image, gtk.gdk.Pixbuf): self.sprites.area.draw_pixbuf( self.sprites.gc, self.image, 0, 0, self.x, self.y) @@ -183,7 +185,6 @@ class Sprite: self.sprites.gc, self.image, 0, 0, self.x, self.y, -1, -1) if len(self.labels) > 0: self.draw_label() - # self.inval() def hit(self, pos): x, y = pos diff --git a/talogo.py b/talogo.py index 1a54be5..bbb91d9 100644 --- a/talogo.py +++ b/talogo.py @@ -44,6 +44,9 @@ from tajail import * from gettext import gettext as _ +from constants import * + + procstop = False class symbol: @@ -158,7 +161,7 @@ def readline(lc, line): return res def setup_cmd(lc, str): - lc.tw.turtle.spr.set_layer(100) + lc.tw.turtle.spr.set_layer(HIDE_LAYER) lc.procstop=False list = readline(lc, str) lc.step = start_eval(lc, list) @@ -176,11 +179,11 @@ def evline(lc, list): lc.arglist = None while lc.iline: if lc.tw.step_time > 0: - lc.tw.turtle.spr.set_layer(630) + lc.tw.turtle.spr.set_layer(TURTLE_LAYER) endtime = millis()+an_int(lc,lc.tw.step_time)*100 while millis()