debian: Add graphviz dependency
[gfxprim/pasky.git] / demos / py_simple / font_style.py
blob47d8e2cbff8eea7e07a2fdb4ce6c34b11d380a84
1 #!/usr/bin/env python
3 import sys
5 import gfxprim.core as core
6 import gfxprim.gfx as gfx
7 import gfxprim.backends as backends
8 import gfxprim.input as input
9 import gfxprim.text as text
11 def redraw(win):
12 c = win.context
14 black = c.RGBToPixel(0, 0, 0)
15 white = c.RGBToPixel(0xff, 0xff, 0xff)
17 c.gfx.Fill(black)
19 align = text.C.ALIGN_CENTER | text.C.VALIGN_CENTER
20 style = text.TextStyle(text.DefaultProportionalFont, 0, 0, 1, 1, 1)
22 spacing = 20
23 y = 20
25 while y < c.h:
26 y += text.TextHeight(style) + spacing
27 c.text.Text(style, c.w//2, y, align, white, black, "Lorem Ipsum Dolor Sit Amet.")
29 style.pixel_xspace += 1
30 style.pixel_yspace += 1
31 style.pixel_xmul += 1
32 style.pixel_ymul += 1
34 win.Flip()
37 def main():
38 # Create X11 window
39 win = backends.BackendX11Init(None, 0, 0, 800, 600, "Fonts", 0)
40 assert(win)
42 redraw(win)
44 # Event loop
45 while True:
46 ev = win.WaitEvent()
48 if (ev.type == input.EV_KEY and ev.val.val == input.KEY_ESC):
49 sys.exit(0)
50 elif (ev.type == input.EV_SYS):
51 if (ev.code == input.EV_SYS_QUIT):
52 sys.exit(0)
53 if (ev.code == input.EV_SYS_RESIZE):
54 win.ResizeAck()
55 redraw(win)
57 if __name__ == '__main__':
58 main()