Revision 39 layer.py

layer.py (revision 39)
25 25

  
26 26
class Layer(specialScatterW):
27 27
    def __init__(self, **kwargs):
28
        kwargs.setdefault('layer_manager', None)
28 29
        self.moveable = kwargs.get('moveable')
30
        self.layer_manager = kwargs.get('layer_manager')
29 31
        if self.moveable == False :
30 32
            kwargs.setdefault('do_scale', False)
31 33
            kwargs.setdefault('do_rotation', False)
......
35 37
        self.color = kwargs.get('color')
36 38
        set_brush('brushes/brush_particle.png')
37 39
        self.layer_clear()
38
        self.touch_positions = {}
39
        self.mode = "zoom"
40 40
        set_brush_size(25)
41 41
        self.brush_color=(0,0,0,1)
42 42

  
......
50 50

  
51 51
    def on_touch_down(self, touches, touchID, x, y):
52 52
        if self.collide_point(x,y): 
53
            self.touch_positions[touchID] = self.to_local(x,y)            
54
            if self.mode == "draw":
53
            self.touches[touchID] = self.to_local(x,y)
54
            if self.layer_manager.mode == "draw":
55 55
                self.fbo.bind()
56 56
                set_color(*self.brush_color)
57 57
                set_brush('brushes/brush_particle.png')
58 58
                set_brush_size(25)
59 59
                drawCircle(pos=self.to_local(x,y), radius=1)            
60 60
                self.fbo.release()
61
            elif self.mode == "zoom":
61
            elif self.layer_manager.mode == "zoom":
62 62
                super(Layer, self).on_touch_down(touches, touchID, x, y)
63 63

  
64 64
            return True
65 65
            
66 66
    def on_touch_move(self, touches, touchID, x, y):
67
        if self.touch_positions.has_key(touchID):
68
            if self.mode == "zoom":
67
        if touchID in self.touches:
68
            if self.layer_manager.mode == "zoom":
69 69
                super(Layer, self).on_touch_move(touches, touchID, x, y)
70
            elif self.mode == "draw":
70
            elif self.layer_manager.mode == "draw":
71 71
                cur_pos = self.to_local(x,y)
72
                ox,oy = self.touch_positions[touchID]
72
                ox,oy = self.touches[touchID]
73 73
                self.fbo.bind()
74 74
                set_color(*self.brush_color)
75 75
                set_brush('brushes/brush_particle.png')
76 76
                set_brush_size(25)
77 77
                paintLine((ox,oy,cur_pos[0],cur_pos[1]))
78 78
                self.fbo.release()
79
                self.touch_positions[touchID] = self.to_local(x,y)
79
                self.touches[touchID] = self.to_local(x,y)
80 80
            return True
81
            
82
    def on_touch_up(self, touches, touchID, x,y):
83
        if touchID in self.touches:
84
            del self.touches[touchID]
85
            return True
86
            
81 87

  
82 88
    def draw(self):
83 89
        with gx_matrix:
84
           glColor4f(*self.color)
85
           drawRectangle((0,0),(self.width,self.height))
86
           #with gx_blending:
87
           #     drawTexturedRectangle(self.fbo.texture, (-6,-6),(self.width+12,self.height+12))
90
            #glColor4f(*self.color)
91
            if self.moveable == False :
92
                glColor4f(*self.color)
93
                drawRectangle((0,0),(self.width,self.height))
94
            with gx_blending:
95
                glColor4f(self.color[0],self.color[1],self.color[2],0.5)
96
                drawRectangle((0,0),(self.width,self.height))
97
                drawTexturedRectangle(self.fbo.texture, (-6,-6),(self.width+12,self.height+12))
88 98
    
89 99
    def set_mode(self,mode):
90 100
        self.mode = mode

Also available in: Unified diff