Revision 40 layer.py
| layer.py (revision 40) | ||
|---|---|---|
| 21 | 21 |
#self.bring_to_front() |
| 22 | 22 |
self.touches[touchID] = Vector(x,y) |
| 23 | 23 |
return True |
| 24 |
|
|
| 25 |
|
|
| 26 |
class Layer(specialScatterW): |
|
| 24 |
|
|
| 25 |
class AbstractLayer(specialScatterW): |
|
| 27 | 26 |
def __init__(self, **kwargs): |
| 28 | 27 |
kwargs.setdefault('layer_manager', None)
|
| 29 |
self.moveable = kwargs.get('moveable')
|
|
| 30 |
self.layer_manager = kwargs.get('layer_manager')
|
|
| 31 |
if self.moveable == False : |
|
| 32 |
kwargs.setdefault('do_scale', False)
|
|
| 33 |
kwargs.setdefault('do_rotation', False)
|
|
| 34 |
kwargs.setdefault('do_translation', False)
|
|
| 35 |
super(Layer, self).__init__(**kwargs) |
|
| 36 |
self.fbo = Fbo(size=(self.width, self.height), with_depthbuffer=False) |
|
| 28 |
self.layer_manager = kwargs.get('layer_manager')
|
|
| 29 |
super(AbstractLayer, self).__init__(**kwargs) |
|
| 30 |
self.fbo = Fbo(size=(self.width, self.height), with_depthbuffer=False) |
|
| 37 | 31 |
self.color = kwargs.get('color')
|
| 38 |
set_brush('brushes/brush_particle.png')
|
|
| 39 |
self.layer_clear() |
|
| 40 |
set_brush_size(25) |
|
| 32 |
set_brush('brushes/brush_particle.png',25)
|
|
| 33 |
#self.layer_clear() |
|
| 41 | 34 |
self.brush_color=(0,0,0,1) |
| 35 |
self.id = kwargs.get('id')
|
|
| 42 | 36 |
|
| 43 | 37 |
def layer_clear(self): |
| 44 | 38 |
self.fbo.bind() |
| 45 |
glClearColor(1,1,1,1) |
|
| 46 |
glClear(GL_COLOR_BUFFER_BIT) |
|
| 39 |
#glClearColor(1,1,1,1) |
|
| 40 |
#glClear(GL_COLOR_BUFFER_BIT) |
|
| 47 | 41 |
set_color(self.color) |
| 48 | 42 |
drawRectangle((0,0),(self.width,self.height)) |
| 49 | 43 |
self.fbo.release() |
| ... | ... | |
| 51 | 45 |
def on_touch_down(self, touches, touchID, x, y): |
| 52 | 46 |
if self.collide_point(x,y): |
| 53 | 47 |
self.touches[touchID] = self.to_local(x,y) |
| 48 |
if len(touches)==2 : |
|
| 49 |
if touches[touchID].is_double_tap: |
|
| 50 |
self.layer_manager.move_layer_down(self.id) |
|
| 51 |
elif touches[touchID].is_double_tap: |
|
| 52 |
self.layer_manager.move_layer_up(self.id) |
|
| 54 | 53 |
if self.layer_manager.mode == "draw": |
| 55 |
self.fbo.bind() |
|
| 56 |
set_color(*self.brush_color) |
|
| 57 |
set_brush('brushes/brush_particle.png')
|
|
| 58 |
set_brush_size(25) |
|
| 59 |
drawCircle(pos=self.to_local(x,y), radius=1) |
|
| 60 |
self.fbo.release() |
|
| 54 |
with self.fbo: |
|
| 55 |
set_color(*self.brush_color) |
|
| 56 |
set_brush('brushes/brush_particle.png',25)
|
|
| 57 |
drawCircle(pos=self.to_local(x,y), radius=1) |
|
| 61 | 58 |
elif self.layer_manager.mode == "zoom": |
| 62 |
super(Layer, self).on_touch_down(touches, touchID, x, y) |
|
| 63 |
|
|
| 59 |
super(AbstractLayer, self).on_touch_down(touches, touchID, x, y) |
|
| 64 | 60 |
return True |
| 65 | 61 |
|
| 66 | 62 |
def on_touch_move(self, touches, touchID, x, y): |
| 67 | 63 |
if touchID in self.touches: |
| 68 | 64 |
if self.layer_manager.mode == "zoom": |
| 69 |
super(Layer, self).on_touch_move(touches, touchID, x, y) |
|
| 65 |
super(AbstractLayer, self).on_touch_move(touches, touchID, x, y) |
|
| 70 | 66 |
elif self.layer_manager.mode == "draw": |
| 71 | 67 |
cur_pos = self.to_local(x,y) |
| 72 | 68 |
ox,oy = self.touches[touchID] |
| 73 |
self.fbo.bind() |
|
| 74 |
set_color(*self.brush_color) |
|
| 75 |
set_brush('brushes/brush_particle.png')
|
|
| 76 |
set_brush_size(25) |
|
| 77 |
paintLine((ox,oy,cur_pos[0],cur_pos[1])) |
|
| 78 |
self.fbo.release() |
|
| 69 |
with self.fbo: |
|
| 70 |
set_color(*self.brush_color) |
|
| 71 |
set_brush('brushes/brush_particle.png',25)
|
|
| 72 |
paintLine((ox,oy,cur_pos[0],cur_pos[1])) |
|
| 73 |
self.fbo.release() |
|
| 79 | 74 |
self.touches[touchID] = self.to_local(x,y) |
| 80 | 75 |
return True |
| 81 | 76 |
|
| ... | ... | |
| 83 | 78 |
if touchID in self.touches: |
| 84 | 79 |
del self.touches[touchID] |
| 85 | 80 |
return True |
| 81 |
|
|
| 82 |
def set_brush_color(self,color): |
|
| 83 |
self.brush_color = color |
|
| 86 | 84 |
|
| 85 |
|
|
| 87 | 86 |
|
| 87 |
class NormalLayer(AbstractLayer): |
|
| 88 |
def __init__(self, **kwargs): |
|
| 89 |
kwargs.setdefault('layer_manager', None)
|
|
| 90 |
self.moveable = kwargs.get('moveable')
|
|
| 91 |
if self.moveable == False : |
|
| 92 |
kwargs.setdefault('do_scale', False)
|
|
| 93 |
kwargs.setdefault('do_rotation', False)
|
|
| 94 |
kwargs.setdefault('do_translation', False)
|
|
| 95 |
super(NormalLayer, self).__init__(**kwargs) |
|
| 96 |
|
|
| 88 | 97 |
def draw(self): |
| 89 | 98 |
with gx_matrix: |
| 90 | 99 |
#glColor4f(*self.color) |
| 91 | 100 |
if self.moveable == False : |
| 92 | 101 |
glColor4f(*self.color) |
| 93 | 102 |
drawRectangle((0,0),(self.width,self.height)) |
| 94 |
with gx_blending: |
|
| 95 |
glColor4f(self.color[0],self.color[1],self.color[2],0.5) |
|
| 103 |
else: |
|
| 104 |
glColor4f(self.color[0],self.color[1],self.color[2],self.color[3]) |
|
| 96 | 105 |
drawRectangle((0,0),(self.width,self.height)) |
| 97 |
drawTexturedRectangle(self.fbo.texture, (-6,-6),(self.width+12,self.height+12)) |
|
| 98 |
|
|
| 99 |
def set_mode(self,mode): |
|
| 100 |
self.mode = mode |
|
| 101 |
|
|
| 102 |
def set_brush_color(self,color): |
|
| 103 |
self.brush_color = color |
|
| 106 |
drawTexturedRectangle(self.fbo.texture, (0,0),(self.width,self.height)) |
|
Also available in: Unified diff
