From 11e88c07cfa97933ac17dddbabb7e8bce1fbb07a Mon Sep 17 00:00:00 2001 From: Walter Bender Date: Tue, 02 Mar 2010 08:23:29 +0000 Subject: moving color to canvas --- diff --git a/NEWS b/NEWS index 8b5683f..f3adb9d 100644 --- a/NEWS +++ b/NEWS @@ -18,6 +18,7 @@ o labels on coordinate-grid overlays o more complete support in non-Sugar environments o new (and improved) sample code + o Logo code for project added to View Source * completed a major refactoring of the code o 90% smaller download bundle-size diff --git a/icons/debugoff.svg b/icons/debugoff.svg index c5a3bc4..cf70e7e 100644 --- a/icons/debugoff.svg +++ b/icons/debugoff.svg @@ -113,27 +113,27 @@ id="path3258" style="fill:none;stroke:#ffffff;stroke-width:0.75545591;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" /> diff --git a/icons/debugon.svg b/icons/debugon.svg index 5cc7762..6232a99 100644 --- a/icons/debugon.svg +++ b/icons/debugon.svg @@ -118,27 +118,27 @@ id="path3258" style="fill:none;stroke:#000000;stroke-width:0.75545591;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" /> diff --git a/icons/eraseroff.svg b/icons/eraseroff.svg index 9f466ce..5ced823 100644 --- a/icons/eraseroff.svg +++ b/icons/eraseroff.svg @@ -11,23 +11,23 @@ diff --git a/icons/eraseron.svg b/icons/eraseron.svg index ca884df..27a5ffd 100644 --- a/icons/eraseron.svg +++ b/icons/eraseron.svg @@ -15,23 +15,23 @@ id="g3589" style="fill:#404040;fill-opacity:1;stroke:#ffffff;stroke-width:2;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"> diff --git a/icons/stopitoff.svg b/icons/stopitoff.svg index 7379bee..de041ea 100644 --- a/icons/stopitoff.svg +++ b/icons/stopitoff.svg @@ -11,7 +11,7 @@ diff --git a/sprites.py b/sprites.py index a361ba0..0bdab1f 100644 --- a/sprites.py +++ b/sprites.py @@ -34,7 +34,7 @@ class Sprite manages individual sprites within the collection. Example usage: # Import the classes into your program. - from sprites import Sprites Sprite + from sprites import Sprites, Sprite # Create a new sprite collection for a gtk Drawing Area. my_drawing_area = gtk.DrawingArea() @@ -364,3 +364,4 @@ class Sprite: except IndexError: print "Index Error: %d %d" % (len(array), offset) return (-1,-1,-1,-1) + diff --git a/tacanvas.py b/tacanvas.py index 77e42ad..2ce5106 100644 --- a/tacanvas.py +++ b/tacanvas.py @@ -76,9 +76,15 @@ class TurtleGraphics: self.canvas.type = 'canvas' self.canvas.set_layer(CANVAS_LAYER) self.gc = self.canvas.images[0].new_gc() + self.cm = self.gc.get_colormap() + self.fgrgb = [255,0,0] + self.fgcolor = self.cm.alloc_color('red') + self.bgrgb = [255,248,222] + self.bgcolor = self.cm.alloc_color('#fff8de') + self.textsize = 48 + self.textcolor = self.cm.alloc_color('blue') self.tw.active_turtle.show() self.shade = 0 - self.bgcolor = self.tw.bgcolor self.svg = SVG() self.svg.set_fill_color('none') self.tw.svg_string = '' @@ -86,7 +92,7 @@ class TurtleGraphics: def clearscreen(self): rect = gtk.gdk.Rectangle(0, 0, self.width, self.height) - self.gc.set_foreground(self.tw.bgcolor) + self.gc.set_foreground(self.bgcolor) self.canvas.images[0].draw_rectangle(self.gc, True, *rect) self.invalt(0, 0, self.width, self.height) self.setpensize(5) @@ -110,7 +116,7 @@ class TurtleGraphics: def forward(self, n): n *= self.tw.coord_scale - self.gc.set_foreground(self.tw.fgcolor) + self.gc.set_foreground(self.fgcolor) oldx, oldy = self.xcor, self.ycor try: self.xcor += n*sin(self.heading*DEGTOR) @@ -144,7 +150,7 @@ class TurtleGraphics: self.turn_turtle() def arc(self, a, r): - self.gc.set_foreground(self.tw.fgcolor) + self.gc.set_foreground(self.fgcolor) r *= self.tw.coord_scale try: if a<0: @@ -265,10 +271,8 @@ class TurtleGraphics: oldc, olds = self.color,self.shade self.setcolor(c); self.setshade(s) rect = gtk.gdk.Rectangle(0,0,self.width,self.height) - self.gc.set_foreground(self.tw.fgcolor) - self.bgcolor = "#%02x%02x%02x" % (self.tw.rgb[0], - self.tw.rgb[1], - self.tw.rgb[2]) + self.gc.set_foreground(self.fgcolor) + self.bgrgb = self.fgrgb[:] self.canvas.images[0].draw_rectangle(self.gc, True, *rect) self.invalt(0,0,self.width,self.height) self.setcolor(oldc); self.setshade(olds) @@ -280,18 +284,18 @@ class TurtleGraphics: rgb = color_table[wrap100(self.color)] r,g,b = (rgb>>8)&0xff00,rgb&0xff00,(rgb<<8)&0xff00 r,g,b = calc_shade(r,sh),calc_shade(g,sh),calc_shade(b,sh) - self.tw.rgb = [r>>8,g>>8,b>>8] - self.tw.fgcolor = self.tw.cm.alloc_color(r,g,b) - self.svg.set_stroke_color("#%02x%02x%02x" % (self.tw.rgb[0], - self.tw.rgb[1], - self.tw.rgb[2])) + self.fgrgb = [r>>8,g>>8,b>>8] + self.fgcolor = self.cm.alloc_color(r,g,b) + self.svg.set_stroke_color("#%02x%02x%02x" % (self.fgrgb[0], + self.fgrgb[1], + self.fgrgb[2])) def set_textcolor(self): sh = (wrap100(self.shade)-50)/50.0 rgb = color_table[wrap100(self.tcolor)] r,g,b = (rgb>>8)&0xff00,rgb&0xff00,(rgb<<8)&0xff00 r,g,b = calc_shade(r,sh),calc_shade(g,sh),calc_shade(b,sh) - self.tw.textcolor = self.tw.cm.alloc_color(r,g,b) + self.tw.textcolor = self.cm.alloc_color(r,g,b) def setpen(self,bool): self.pendown = bool @@ -379,6 +383,6 @@ class TurtleGraphics: return self.svg.calc_w_h(False) self.tw.svg_string = "%s%s%s%s" % (self.svg.header(True), - self.svg.background(self.bgcolor), - self.tw.svg_string, - self.svg.footer()) + self.svg.background("#%02x%02x%02x" %\ + (self.bgrgb[0], self.bgrgb[1], self.bgrgb[2])), + self.tw.svg_string, self.svg.footer()) diff --git a/talogo.py b/talogo.py index 4e0bfa5..f1691f3 100644 --- a/talogo.py +++ b/talogo.py @@ -1016,7 +1016,7 @@ class LogoCode: for s in sarray: self.tw.canvas.setxy(x, y) self.show(s) - y -= int(self.tw.textsize*self.tw.lead) + y -= int(self.tw.canvas.textsize*self.tw.lead) def set_scale(self, x): self.scale = x @@ -1041,16 +1041,18 @@ class LogoCode: self.play_sound(string) else: if center: - y -= self.tw.textsize + y -= self.tw.canvas.textsize self.tw.canvas.draw_text(string, x, y, - int(self.tw.textsize*self.scale/100), + int(self.tw.canvas.textsize*\ + self.scale/100), self.tw.canvas.width-x) elif type(string) == float or type(string) == int: string = round_int(string) if center: - y -= self.tw.textsize + y -= self.tw.canvas.textsize self.tw.canvas.draw_text(string, x, y, - int(self.tw.textsize*self.scale/100), + int(self.tw.canvas.textsize*\ + self.scale/100), self.tw.canvas.width-x) # Image only (at current x,y) @@ -1172,7 +1174,7 @@ class LogoCode: y = self.tw.canvas.height/2 self.tw.canvas.setxy(x, y) # save the text size so we can restore it later - save_text_size = self.tw.textsize + save_text_size = self.tw.canvas.textsize # set title text self.tw.canvas.settextsize(self.title_height) self.show(title) @@ -1201,7 +1203,7 @@ class LogoCode: y = self.tw.canvas.height/2 self.tw.canvas.setxy(x, y) # save the text size so we can restore it later - save_text_size = self.tw.textsize + save_text_size = self.tw.canvas.textsize # set title text self.tw.canvas.settextsize(self.title_height) self.show(title) @@ -1236,7 +1238,7 @@ class LogoCode: y = self.tw.canvas.height/2 self.tw.canvas.setxy(x, y) # save the text size so we can restore it later - save_text_size = self.tw.textsize + save_text_size = self.tw.canvas.textsize # set title text self.tw.canvas.settextsize(self.title_height) self.show(sarray[0]) @@ -1258,7 +1260,7 @@ class LogoCode: y = self.tw.canvas.height/2 self.tw.canvas.setxy(x, y) # save the text size so we can restore it later - save_text_size = self.tw.textsize + save_text_size = self.tw.canvas.textsize # set title text self.tw.canvas.settextsize(self.title_height) self.show(title) @@ -1293,7 +1295,7 @@ class LogoCode: y = self.tw.canvas.height/2 self.tw.canvas.setxy(x, y) # save the text size so we can restore it later - save_text_size = self.tw.textsize + save_text_size = self.tw.canvas.textsize # set title text self.tw.canvas.settextsize(self.title_height) self.show(title) @@ -1327,7 +1329,7 @@ class LogoCode: y = self.tw.canvas.height/2 self.tw.canvas.setxy(x, y) # save the text size so we can restore it later - save_text_size = self.tw.textsize + save_text_size = self.tw.canvas.textsize # set title text self.tw.canvas.settextsize(self.title_height) self.show(title) diff --git a/tamyblock.py b/tamyblock.py index 6627066..a90995a 100644 --- a/tamyblock.py +++ b/tamyblock.py @@ -51,7 +51,7 @@ def myblock(lc, x): # while b > 255: # b -= 256 # rgb = "#%02x%02x%02x" % (r,g,b) - # lc.tw.fgcolor = lc.tw.cm.alloc_color(rgb) + # lc.tw.canvas.fgcolor = lc.tw.canvas.cm.alloc_color(rgb) # return ########################################################################### @@ -120,7 +120,7 @@ def myblock(lc, x): # b = int((val*(100-x) + lc.tw.rgb[2]*x)/100) # reallocate current color # rgb = "#%02x%02x%02x" % (r,g,b) - # lc.tw.fgcolor = lc.tw.cm.alloc_color(rgb) + # lc.tw.canvas.fgcolor = lc.tw.canvas.cm.alloc_color(rgb) # return ########################################################################### diff --git a/tawindow.py b/tawindow.py index b249f18..456f91d 100644 --- a/tawindow.py +++ b/tawindow.py @@ -124,13 +124,6 @@ class TurtleArtWindow(): self.scale = 1.0 self.block_scale = BLOCK_SCALE self.trash_scale = 0.5 - self.cm = self.gc.get_colormap() - self.rgb = [255,0,0] - self.bgcolor = self.cm.alloc_color('#fff8de') - self.msgcolor = self.cm.alloc_color('black') - self.fgcolor = self.cm.alloc_color('red') - self.textcolor = self.cm.alloc_color('blue') - self.textsize = 48 self.myblock = None self.nop = 'nop' self.loaded = 0 @@ -2637,7 +2630,7 @@ class TurtleArtWindow(): dsobject.metadata['title'] = name dsobject.metadata['icon-color'] = profile.get_color().to_string() if svg: - dsobject.metadata['mime_type'] = 'image/svg' + dsobject.metadata['mime_type'] = 'image/svg+xml' else: dsobject.metadata['mime_type'] = 'image/png' dsobject.set_file_path(file_path) -- cgit v0.9.1