root / core / app / canvas / layer.py @ 41
View | Annotate | Download (4.3 KB)
| 1 | 38 | sharath.patali | from __future__ import with_statement |
|---|---|---|---|
| 2 | 38 | sharath.patali | from pymt import * |
| 3 | 38 | sharath.patali | from pyglet.gl import * |
| 4 | 38 | sharath.patali | |
| 5 | 38 | sharath.patali | class specialScatterW(MTScatterWidget): |
| 6 | 38 | sharath.patali | def __init__(self, **kwargs): |
| 7 | 38 | sharath.patali | super(specialScatterW, self).__init__(**kwargs) |
| 8 | 38 | sharath.patali | |
| 9 | 38 | sharath.patali | def on_touch_down(self, touches, touchID, x, y): |
| 10 | 38 | sharath.patali | # if the touch isnt on the widget we do nothing |
| 11 | 38 | sharath.patali | if not self.collide_point(x,y): |
| 12 | 38 | sharath.patali | return False |
| 13 | 38 | sharath.patali | |
| 14 | 38 | sharath.patali | # let the child widgets handle the event if they want |
| 15 | 38 | sharath.patali | lx, ly = self.to_local(x,y) |
| 16 | 38 | sharath.patali | if super(MTScatterWidget, self).on_touch_down(touches, touchID, lx, ly): |
| 17 | 38 | sharath.patali | return True |
| 18 | 38 | sharath.patali | |
| 19 | 38 | sharath.patali | # if the children didnt handle it, we bring to front & keep track |
| 20 | 38 | sharath.patali | # of touches for rotate/scale/zoom action |
| 21 | 38 | sharath.patali | #self.bring_to_front() |
| 22 | 38 | sharath.patali | self.touches[touchID] = Vector(x,y) |
| 23 | 38 | sharath.patali | return True |
| 24 | 40 | sharath.patali | |
| 25 | 40 | sharath.patali | class AbstractLayer(specialScatterW): |
| 26 | 38 | sharath.patali | def __init__(self, **kwargs): |
| 27 | 39 | sharath.patali | kwargs.setdefault('layer_manager', None)
|
| 28 | 40 | sharath.patali | self.layer_manager = kwargs.get('layer_manager')
|
| 29 | 40 | sharath.patali | super(AbstractLayer, self).__init__(**kwargs) |
| 30 | 40 | sharath.patali | self.fbo = Fbo(size=(self.width, self.height), with_depthbuffer=False) |
| 31 | 38 | sharath.patali | self.color = kwargs.get('color')
|
| 32 | 40 | sharath.patali | set_brush('brushes/brush_particle.png',25)
|
| 33 | 41 | sharath.patali | self.layer_clear() |
| 34 | 38 | sharath.patali | self.brush_color=(0,0,0,1) |
| 35 | 40 | sharath.patali | self.id = kwargs.get('id')
|
| 36 | 38 | sharath.patali | |
| 37 | 38 | sharath.patali | def layer_clear(self): |
| 38 | 41 | sharath.patali | with self.fbo: |
| 39 | 41 | sharath.patali | glClearColor(1,1,1,1) |
| 40 | 41 | sharath.patali | glClear(GL_COLOR_BUFFER_BIT) |
| 41 | 41 | sharath.patali | set_color(self.color) |
| 42 | 41 | sharath.patali | drawRectangle((0,0),(self.width,self.height)) |
| 43 | 38 | sharath.patali | |
| 44 | 38 | sharath.patali | def on_touch_down(self, touches, touchID, x, y): |
| 45 | 38 | sharath.patali | if self.collide_point(x,y): |
| 46 | 39 | sharath.patali | self.touches[touchID] = self.to_local(x,y) |
| 47 | 40 | sharath.patali | if len(touches)==2 : |
| 48 | 40 | sharath.patali | if touches[touchID].is_double_tap: |
| 49 | 40 | sharath.patali | self.layer_manager.move_layer_down(self.id) |
| 50 | 40 | sharath.patali | elif touches[touchID].is_double_tap: |
| 51 | 41 | sharath.patali | self.layer_manager.move_layer_up(self.id) |
| 52 | 39 | sharath.patali | if self.layer_manager.mode == "draw": |
| 53 | 40 | sharath.patali | with self.fbo: |
| 54 | 40 | sharath.patali | set_color(*self.brush_color) |
| 55 | 40 | sharath.patali | set_brush('brushes/brush_particle.png',25)
|
| 56 | 40 | sharath.patali | drawCircle(pos=self.to_local(x,y), radius=1) |
| 57 | 39 | sharath.patali | elif self.layer_manager.mode == "zoom": |
| 58 | 40 | sharath.patali | super(AbstractLayer, self).on_touch_down(touches, touchID, x, y) |
| 59 | 38 | sharath.patali | return True |
| 60 | 38 | sharath.patali | |
| 61 | 38 | sharath.patali | def on_touch_move(self, touches, touchID, x, y): |
| 62 | 39 | sharath.patali | if touchID in self.touches: |
| 63 | 39 | sharath.patali | if self.layer_manager.mode == "zoom": |
| 64 | 40 | sharath.patali | super(AbstractLayer, self).on_touch_move(touches, touchID, x, y) |
| 65 | 39 | sharath.patali | elif self.layer_manager.mode == "draw": |
| 66 | 38 | sharath.patali | cur_pos = self.to_local(x,y) |
| 67 | 39 | sharath.patali | ox,oy = self.touches[touchID] |
| 68 | 40 | sharath.patali | with self.fbo: |
| 69 | 40 | sharath.patali | set_color(*self.brush_color) |
| 70 | 40 | sharath.patali | set_brush('brushes/brush_particle.png',25)
|
| 71 | 41 | sharath.patali | paintLine((ox,oy,cur_pos[0],cur_pos[1])) |
| 72 | 39 | sharath.patali | self.touches[touchID] = self.to_local(x,y) |
| 73 | 38 | sharath.patali | return True |
| 74 | 39 | sharath.patali | |
| 75 | 39 | sharath.patali | def on_touch_up(self, touches, touchID, x,y): |
| 76 | 39 | sharath.patali | if touchID in self.touches: |
| 77 | 39 | sharath.patali | del self.touches[touchID] |
| 78 | 39 | sharath.patali | return True |
| 79 | 40 | sharath.patali | |
| 80 | 40 | sharath.patali | def set_brush_color(self,color): |
| 81 | 40 | sharath.patali | self.brush_color = color |
| 82 | 39 | sharath.patali | |
| 83 | 40 | sharath.patali | |
| 84 | 38 | sharath.patali | |
| 85 | 40 | sharath.patali | class NormalLayer(AbstractLayer): |
| 86 | 40 | sharath.patali | def __init__(self, **kwargs): |
| 87 | 40 | sharath.patali | kwargs.setdefault('layer_manager', None)
|
| 88 | 40 | sharath.patali | self.moveable = kwargs.get('moveable')
|
| 89 | 40 | sharath.patali | if self.moveable == False : |
| 90 | 40 | sharath.patali | kwargs.setdefault('do_scale', False)
|
| 91 | 40 | sharath.patali | kwargs.setdefault('do_rotation', False)
|
| 92 | 40 | sharath.patali | kwargs.setdefault('do_translation', False)
|
| 93 | 40 | sharath.patali | super(NormalLayer, self).__init__(**kwargs) |
| 94 | 40 | sharath.patali | |
| 95 | 38 | sharath.patali | def draw(self): |
| 96 | 38 | sharath.patali | with gx_matrix: |
| 97 | 39 | sharath.patali | #glColor4f(*self.color) |
| 98 | 39 | sharath.patali | if self.moveable == False : |
| 99 | 39 | sharath.patali | glColor4f(*self.color) |
| 100 | 39 | sharath.patali | drawRectangle((0,0),(self.width,self.height)) |
| 101 | 40 | sharath.patali | else: |
| 102 | 40 | sharath.patali | glColor4f(self.color[0],self.color[1],self.color[2],self.color[3]) |
| 103 | 39 | sharath.patali | drawRectangle((0,0),(self.width,self.height)) |
| 104 | 40 | sharath.patali | drawTexturedRectangle(self.fbo.texture, (0,0),(self.width,self.height)) |
