1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 import os
22 import Image
23 from copy import deepcopy
24
25 from opengltk.extent import _gllib
26 from opengltk.OpenGL import GL
27 from DejaVu.Insert2d import Insert2d
28
30
31 keywords = Insert2d.keywords + [
32 'image',
33 ]
34
35 - def __init__(self, name='StickImage', check=1, **kw):
36
37
38 self.image = None
39
40 apply(Insert2d.__init__, (self, name, check), kw)
41
42 self.needsRedoDpyListOnResize = True
43
44
45 - def Set(self, check=1, redo=1, updateOwnGui=True, **kw):
46 """set data for this object:
47 check=1 : verify that all the keywords present can be handle by this func
48 redo=1 : append self to viewer.objectsNeedingRedo
49 updateOwnGui=True : allow to update owngui at the end this func
50 """
51
52 redrawFlag, \
53 updateOwnGuiFlag, \
54 redoViewerDisplayListFlag, \
55 redoDisplayListFlag, \
56 redoTemplateFlag, \
57 redoDisplayChildrenListFlag = apply( Insert2d.Set, (self, check, 0), kw)
58
59 image = kw.get('image')
60 if image is not None:
61 kw.pop('image')
62 self.image = image
63 self.size[0] = self.image.size[0]
64 self.size[1] = self.image.size[1]
65 redoDisplayListFlag = True
66
67 if redo and self.viewer:
68 if redoTemplateFlag is True:
69 self.redoTemplate()
70 redrawFlag = True
71 if redoDisplayListFlag is True:
72 if self not in self.viewer.objectsNeedingRedo.keys():
73 self.viewer.objectsNeedingRedo[self] = None
74 redrawFlag = True
75 if redoDisplayChildrenListFlag is True:
76 lObjectsNeedingRedo = self.viewer.objectsNeedingRedo.keys()
77 for child in self.AllObjects():
78 if child not in lObjectsNeedingRedo:
79 self.viewer.objectsNeedingRedo[child] = None
80 redrawFlag = True
81 if redoViewerDisplayListFlag is True:
82 self.viewer.deleteOpenglList()
83 redrawFlag = True
84 if updateOwnGui is True and updateOwnGuiFlag is True and self.ownGui is not None:
85 self.updateOwnGui()
86 if redrawFlag is True:
87 self.viewer.Redraw()
88 return redrawFlag, updateOwnGuiFlag, redoViewerDisplayListFlag, redoDisplayListFlag, redoTemplateFlag, redoDisplayChildrenListFlag
89
90
91
93
94
95 if self.image is None:
96 return
97
98 GL.glMatrixMode(GL.GL_PROJECTION)
99 GL.glPushMatrix()
100 GL.glLoadIdentity()
101 Insert2d.Draw(self)
102 GL.glMatrixMode(GL.GL_MODELVIEW)
103 GL.glPushMatrix()
104 GL.glLoadIdentity()
105
106 GL.glDisable(GL.GL_DEPTH_TEST)
107 GL.glDisable(GL.GL_LIGHTING);
108
109 width = self.size[0]
110 height = self.size[1]
111
112 fullWidth = self.viewer.currentCamera.width
113 fullHeight = self.viewer.currentCamera.height
114
115
116 posxFromLeft = self.position[0] * fullWidth - self.anchor[0] * width
117 posyFrombottom = (1.-self.position[1]) * fullHeight - (1.-self.anchor[1]) * height
118
119
120
121 self.polygonContour = [ (posxFromLeft, posyFrombottom),
122 (posxFromLeft+width, posyFrombottom),
123 (posxFromLeft+width, posyFrombottom+height),
124 (posxFromLeft, posyFrombottom+height)
125 ]
126
127
128 GL.glRasterPos2f(0, 0)
129 _gllib.glBitmap(0, 0, 0, 0, posxFromLeft, posyFrombottom, 0)
130
131 GL.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1)
132 if self.image.mode == 'RGBA':
133 _gllib.glDrawPixels(self.image.size[0], self.image.size[1],
134 GL.GL_RGBA, GL.GL_UNSIGNED_BYTE,
135 self.image.tostring() )
136 elif self.image.mode == 'RGB':
137 _gllib.glDrawPixels(self.image.size[0], self.image.size[1],
138 GL.GL_RGB, GL.GL_UNSIGNED_BYTE,
139 self.image.tostring() )
140 elif self.image.mode == 'L':
141 _gllib.glDrawPixels(self.image.size[0], self.image.size[1],
142 GL.GL_LUMINANCE, GL.GL_UNSIGNED_BYTE,
143 self.image.tostring() )
144
145 GL.glMatrixMode(GL.GL_PROJECTION)
146 GL.glPopMatrix()
147 GL.glMatrixMode(GL.GL_MODELVIEW)
148 GL.glPopMatrix()
149
150 return 1
151
152
154 """the trackball transmit the translation info
155 """
156 pass
157