-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpreview_context.py
More file actions
executable file
·85 lines (58 loc) · 2.02 KB
/
preview_context.py
File metadata and controls
executable file
·85 lines (58 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env python2.7
from context import *
import pygame
BLACK = ( 0 , 0 , 0 )
RED = ( 255 , 0 , 0 )
GREEN = ( 0 , 255 , 0 )
BLUE = ( 0 , 0 , 255 )
CYAN = ( 0, 255, 255 )
MAGENTA = ( 255 , 0, 255 )
YELLOW = ( 255, 255, 0 )
WHITE = ( 255, 255, 255 )
DARK_GREY = ( 50, 50, 50 )
VERY_DARK_GREY = ( 25, 25, 25 )
class PreviewContext(Context):
def __init__(self,w,h,ppi):
Context.__init__(self)
pygame.init()
size=[int(w*ppi),int(h*ppi)]
# This will send us to on screen coordinates
self.mstack.append(
matrix([
[float(ppi),0,float(ppi)*float(w)/2.0],
[0,float(ppi),float(ppi)*float(h)/2.0],
[0,0,1]
]))
self.screen=pygame.display.set_mode(size)
self.screen.fill(BLACK)
pygame.display.set_caption("Preview")
pygame.draw.line(self.screen,DARK_GREY,(w*ppi/2,0),(w*ppi/2,h*ppi))
pygame.draw.line(self.screen,DARK_GREY,(0,h*ppi/2),(w*ppi,h*ppi/2))
def show(self):
clock = pygame.time.Clock()
done=False
while done==False:
for event in pygame.event.get():
if event.type == pygame.QUIT:
done=True
pygame.display.flip()
clock.tick(20)
print "Goodbye!"
pygame.quit()
def get_color(self):
try:
return self.get_layer_prop("color")
except KeyError:
return WHITE
def write_line(self,obj):
p1 = (obj.p1.item(0),obj.p1.item(1))
p2 = (obj.p2.item(0),obj.p2.item(1))
pygame.draw.line(self.screen,self.get_color(),p1,p2)
def write_arc(self,obj):
print "writing an arc!!111"
def write_point(self,obj):
POINTCROSSPX=3
x = obj.p.item(0)
y = obj.p.item(1)
pygame.draw.line(self.screen,self.get_color(),(x-POINTCROSSPX,y),(x+POINTCROSSPX,y))
pygame.draw.line(self.screen,self.get_color(),(x,y-POINTCROSSPX),(x,y+POINTCROSSPX))