Commits

Brendan Howell committed b92f8ba

text rotation. fixed fill-color bug.

  • Participants
  • Parent commits 97ba3ee

Comments (0)

Files changed (4)

File pycessing/data/examples/screen-text.cess

 def setup():
     pycessing.noLoop = True
     pycessing.size(600, 400)
-	
+     
 def draw():
     # you can print a semi-alphabetical list of all fonts available
     myText.listFonts()
     
     myText.setText("hello pycessors")
-    myText.draw(20, 20)
+    myText.draw(20, 320)
     
     #draw it twice a little offset for a cheesy 
     # drop-shadow effect
     myText.setColor(128, 0, 255)
-    myText.draw(18, 18)
+    myText.draw(18, 318)
+    
+    #put a nice sqare in there
+    setFillColor(127, 0, 127, 90)
+    rect(20, 20, 200, 200)
     
     # now change the font face and the size
-    myText.setFont("Georgia", 60)
+    myText.setFont("Georgia", 40)
+    
+    #make it red!
     myText.setColor(200, 10, 10)
+        
+    #now rotate it a little bit
+    myText.rotate(30)
     myText.setText("Enjoy Typography!")
-    myText.draw(40, 80, 200)
+    myText.draw(20, 90, 200)
+    
+    #the object keeps its settings so you can reuse it
+    myText.setText("Practice is Perfect")
+    myText.draw(230, 180, 200)
 
 

File pycessing/drawing_cairo.py

 import pygame
 import cairo
 import pangocairo
-import pango
-import numpy
 import math
-import array
 import sys
 
 
         #subsurf.set_shifts((a, r, g, b))
         #subsurf.set_masks((am, rm, gm, bm))
 
-
         self.surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height)
         self.ctx = cairo.Context(self.surface)
         self.pangoctx = pangocairo.CairoContext(self.ctx)
 
     def setBackground(self, red, green=None, blue=None):
         if not(green):
-            self.ctx.set_source_rgba(red/255.0, red/255.0, red/255.0, 1)
+            self.ctx.set_source_rgba(red / 255.0, red / 255.0, red / 255.0, 1)
         else:
-            self.ctx.set_source_rgba(red/255.0, blue/255.0, green/255.0, 1)
+            self.ctx.set_source_rgba(red / 255.0, blue / 255.0, green / 255.0, 1)
         self.ctx.paint()
 
     def setStroke(self, red, green=None, blue=None, alpha=255, width=1):
 
     def setStrokeColor(self, red, green=None, blue=None, alpha=255):
         #assume greyscale if only 1 parameter is specified
-        if not(green):
-            self.stroke_color = (red/255.0, red/255.0, red/255.0, alpha/255.0)
+        if green is None:
+            self.stroke_color = (red / 255.0, red / 255.0, red / 255.0, alpha / 255.0)
         else:
-            self.stroke_color = (red/255.0, green/255.0, blue/255.0, alpha/255.0)
+            self.stroke_color = (red / 255.0, green / 255.0, blue / 255.0, alpha / 255.0)
 
     def setStrokeWidth(self, width):
         self.stroke_width = width
 
     def setFillColor(self, red, green=None, blue=None, alpha=255):
         #assume greyscale if only 1 parameter is specified, assume you want fill
-        if not(green):
-            self.fill_color = (red/255.0, red/255.0, red/255.0, alpha/255.0)
+        if green is None:
+            self.fill_color = (red / 255.0, red / 255.0, red / 255.0, alpha / 255.0)
         else:
-            self.fill_color = (red/255.0, green/255.0, blue/255.0, alpha/255.0)
+            self.fill_color = (red / 255.0, green / 255.0, blue / 255.0, alpha / 255.0)
         self.fill = True
 
     def setFillState(self, fill):
     def screenGrab(self, fileName):
         pygame.image.save(self.sdl_surface, fileName)
 
-    def drawText(self, x, y, txt):
-        self.ctx.save()
-        self.ctx.translate(x,y)
-        self.ctx.set_source_rgb(0, 0, 0)
-        layout = self.pangoctx.create_layout()
-        #print dir(self.families[0])
-        print self.families[0].get_name()
-        layout.set_font_description(pango.FontDescription(self.families[0].get_name() + " 25"))
-        layout.set_width(300)
-        layout.set_text(txt)
-        self.pangoctx.update_layout(layout)
-        #print('ctx.POS: %s %s'%self.ctx.get_current_point())
-        self.pangoctx.show_layout(layout)
-        #print('F => %s %s'%layout.get_pixel_size())
-        self.ctx.restore()
-
     def _fillAndStroke(self):
         if(self.fill):
             self.ctx.set_source_rgba(self.fill_color[0], self.fill_color[1], self.fill_color[2], self.fill_color[3])
 
     #TODO: finish and test PDF output
     def renderToPDF(self, fileName):
-    	self.surface = cairo.PDFSurface(fileName, self.sdl_surface.get_width(), self.sdl_surface.get_height())
-
+        self.surface = cairo.PDFSurface(fileName, self.sdl_surface.get_width(), self.sdl_surface.get_height())
 
     def _blitToScreen(self):
         dest = pygame.surfarray.pixels2d(self.sdl_surface)
             dest.data[:] = self.surface.get_data()[::-1]
         else:
             dest.data[:] = self.surface.get_data()
-
-

File pycessing/images.py

         CTX.restore()
 
     def rotate(self, angle):
-        self.rotation = math.pi * angle / 180.0
+        self.rotation = -math.pi * angle / 180.0
 
     def scale(self, pixelsx, pixelsy):
         if (pixelsx < 1) or (pixelsy < 1):

File pycessing/typo.py

     along with PyCessing.  If not, see <http://www.gnu.org/licenses/>.
 """
 
-import pygame
-import os
 import pango
+import math
 
 PROJECT_DIR = None
 DRAWING = None
         self.surface = None
         self.setFont(fontName, size)
         self.setColor(color)
+        self.rotation = 0.0
 
     def setText(self, text):
         self.text = text
         self.fontName = fontName
         self.size = size
 
+    #TODO: reimpliment this so it actually works with pango
     def setFontFromFile(self, filename, size=30):
         #fp = open(filename)
-        if not(os.path.exists(filename)):
-            filename = os.path.join(PROJECT_DIR, filename)
-            if not(os.path.exists(filename)):
-                print "Error: font file " + filename + " not found."
-                return
-        self.font = pygame.font.Font(filename, size)
-        self.size = size
+        print "NOT IMPLEMENTED: sorry this does not work yet"
+        return
 
     def setSize(self, size):
         self.size = size
         else:
             print "ScreenText: error invalid color specified."
 
+    def rotate(self, angle):
+        self.rotation = -math.pi * angle / 180.0
+
     def draw(self, x, y, width=-1):
         DRAWING.ctx.save()
         DRAWING.ctx.translate(x, y)
+        DRAWING.ctx.rotate(self.rotation)
         r, g, b, a = self.color
         DRAWING.ctx.set_source_rgba(r, g, b, a)
         layout = DRAWING.pangoctx.create_layout()