korg_draw-0.0.1 What? ----- This is a graphics wrapper for python. It provides a generic interface to simple drawing stuff in hopefully a clear and useful way. It does text alignment in what I think is a more useful way. It can use PIL or pygame as a backend. test.py renders the same image in both :) and they look the same. whoohoo. It provides nice and easy text alignment functions. Requirements: ------------- * PIL * pygame/SDL Currently _both_ PIL and SDL for testing, but soon to be one _or_ the other. Useage: ------- You create a graphics base object. You create canvas (images) from the graphics base. Perform graphics ops on the canvas (see test.py). The Canvas should have all the drawing methods you need. See the test.py for an example. Canvas methods: --------------- c.offset(xy) change drawing origin to xy=tuple(x,y) topleft c.line(color,xy) xy=list(x,y,x,y,x,y,...) c.rect(color,xyxy) xyxy=list(x,y,x,y) c.rect_xywh(color,xywh) xywh=list(x,y,width,height) c.poly(color_outline,color_fill,xy) xy=list(x,y,x,y,x,y,...) c.clear(color) erase canvas to this color c.text_getsize_of_line(font,txt) returns wouldbe size c.text_getsize_of_block(fnt,block) handles multi line stuff c.text(fg,bg,xy,align,font,msg) fg=text color bg=background box color (or None for no box) xy=position align=text alignment font=fontname msg=msgblock eg 'foo' 'foo\n2ndfoo' ['foo','2ndfoo'] c.tile(xy,tile) paste the tile object at xy (data/tile/NAME.png) (or "foo/name" loads 'data/tile/foo/name.png') c.paste(xy,sub_canvas) paste another canvas object at xy c.show() display the canvas c.write(file) write canvas image to file 'data' directory: ----------------- (change it in base_draw.py if you need to) data/fonts holds ttfs data/tiles holds tile images note you can refer to stuff in subdirectories by using something like "night/snow/hill" to load a tile "data/tiles/night/snow/hill.png" colors: ------- colors are either * lists of [ r,g,b,a ] * strings of the form '#rgba' '#rrggbbaa' (converted to list) * strings of the form '#rgb' '#rrggbb' (converted to list, a=0) text alignment -------------- if 1 letter code: look up the ALIGN_SHORTCUT ALIGN_SHORTCUT={ 'c':'ct', 'l':'lt', 'r':'rt', None:'lt' } if 2 letters: x_align, y_align from the code: # [left|center|right] [up|top|center|bottom|down] # default is left,top ALIGN_VERTICAL='tTbBcC' ALIGN_HORIZONTAL='lLcCrR' Capital letters mean align whole BLOCK. Lower case letters mean start align of FIRST LINE. (test.py has examples of all the alignments) todo: ----- * handle missing PIL or SDL better * better default font locating * SDL: more event / better event handling interface * [later] change fix go allow different origions (center, bottom/left, etc) * [later] better/verify alpha support * [much later] pyopengl version bugs: ----- SDL's show doesnt close properly and you need to kill it.