Talk:Sugar Standard Icons: Difference between revisions

From OLPC
Jump to navigation Jump to search
(Script to generate cursor XBM's)
 
(→‎Help!: new section)
Line 68: Line 68:


-- [[User:Kevin.saff|Kevin.saff]] 23:16, 25 March 2008 (EDT)
-- [[User:Kevin.saff|Kevin.saff]] 23:16, 25 March 2008 (EDT)

== Help! ==

Hi!
I'm working in a project for my university about an application for sugar and I really really need the svg of "Standard Sugar Cursors"!!! I need it to use in Adobe Illustrator. Does anyone know where I can get it? I looked everywhere already! Thanks!
Lu

Revision as of 14:02, 15 October 2008

Script

I ain't no good at python yet, but here's a script that might let you automagically convert youse's pngs into xbms. I couldn't get this to work on the olpc, but it should work in most python environments with pygame installed.

It will produce files of the form cursorRC.xbm and maskRC.xbm where R is the (0 indexed) row number of your desired cursor, and C is the column number. You will probably want to convert those names to something legible before using the cursors. Anyone is free to improve this script (I am sure there are plenty of ways to do that) or otherwise do what you want with it, etc.

Conversion script

#!/usr/bin/env python
import pygame
import pygame.image
def xbmhex( n ):
   if n >= 16:
       return hex( n )
   else:
       return "0x0"+("0","1","2","3","4","5","6","7",
                       "8","9","a","b","c","d","e","f")[n]
def when_black_opaque( rgba ):
   return rgba == (0,0,0,255)
def when_opaque( rgba ):
   return rgba[3] == (255)
def write( name, image, row, col, when, hot ):
   print( "writing " + name )
   fc = open( name + ".xbm", 'w')
   name = "cursor"
   fc.write("#define "+name+"_width 48\n" )
   fc.write("#define "+name+"_height 48\n")
   fc.write("#define "+name+"_hot_x "+str(hot[0])+"\n")
   fc.write("#define "+name+"_hot_y "+str(hot[1])+"\n")
   fc.write("static unsigned char "+name+"_bits[] = { \n ")
   for y in range( 0, 47 ):
       n = 0
       b = 1
       for x in range( 0, 48 ):
           if when( image.get_at((col*48+x,row*48+y)) ):
               n += b
           b <<= 1
           if b == 256:
               fc.write(xbmhex(n)+", ")
               n = 0
               b = 1
       fc.write("\n ")
   fc.write("0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };")
   fc.close()
def main():
   print( "loading images\n")
   cursors  = pygame.image.load( "sugar-00.png" )
   hotspots = pygame.image.load( "sugar-hotspots.png" )
   if not cursors:
       print( "FILE NOT FOUND!\n" )
   if not hotspots:
       print( "FILE NOT FOUND!\n" )
   for row in range( 0, 7 ):
       for col in range( 0, 6 ):
           hot = (0, 0)
           for x in range( 0, 48 ):
               for y in range( 0, 48 ):
                   if hotspots.get_at(
                           (col*48+x,row*48+y))[3]:
                       hot = (x, y)
                       print( "hot: " + str(hot) )
           write( "cursor" + str(row) + str(col), 
                   cursors, row, col, 
                   when_black_opaque, hot)
           write( "mask" + str(row) + str(col), 
                   cursors, row, col, 
                   when_opaque, hot)
if __name__ == "__main__":
   main()

-- Kevin.saff 23:16, 25 March 2008 (EDT)

Help!

Hi! I'm working in a project for my university about an application for sugar and I really really need the svg of "Standard Sugar Cursors"!!! I need it to use in Adobe Illustrator. Does anyone know where I can get it? I looked everywhere already! Thanks! Lu