Revision 38
| core/app/canvas/layer.py (revision 38) | ||
|---|---|---|
| 1 |
from __future__ import with_statement |
|
| 2 |
from pymt import * |
|
| 3 |
from pyglet.gl import * |
|
| 4 |
|
|
| 5 |
class specialScatterW(MTScatterWidget): |
|
| 6 |
def __init__(self, **kwargs): |
|
| 7 |
super(specialScatterW, self).__init__(**kwargs) |
|
| 8 |
|
|
| 9 |
def on_touch_down(self, touches, touchID, x, y): |
|
| 10 |
# if the touch isnt on the widget we do nothing |
|
| 11 |
if not self.collide_point(x,y): |
|
| 12 |
return False |
|
| 13 |
|
|
| 14 |
# let the child widgets handle the event if they want |
|
| 15 |
lx, ly = self.to_local(x,y) |
|
| 16 |
if super(MTScatterWidget, self).on_touch_down(touches, touchID, lx, ly): |
|
| 17 |
return True |
|
| 18 |
|
|
| 19 |
# if the children didnt handle it, we bring to front & keep track |
|
| 20 |
# of touches for rotate/scale/zoom action |
|
| 21 |
#self.bring_to_front() |
|
| 22 |
self.touches[touchID] = Vector(x,y) |
|
| 23 |
return True |
|
| 24 |
|
|
| 25 |
|
|
| 26 |
class Layer(specialScatterW): |
|
| 27 |
def __init__(self, **kwargs): |
|
| 28 |
self.moveable = kwargs.get('moveable')
|
|
| 29 |
if self.moveable == False : |
|
| 30 |
kwargs.setdefault('do_scale', False)
|
|
| 31 |
kwargs.setdefault('do_rotation', False)
|
|
| 32 |
kwargs.setdefault('do_translation', False)
|
|
| 33 |
super(Layer, self).__init__(**kwargs) |
|
| 34 |
self.fbo = Fbo(size=(self.width, self.height), with_depthbuffer=False) |
|
| 35 |
self.color = kwargs.get('color')
|
|
| 36 |
set_brush('brushes/brush_particle.png')
|
|
| 37 |
self.layer_clear() |
|
| 38 |
self.touch_positions = {}
|
|
| 39 |
self.mode = "zoom" |
|
| 40 |
set_brush_size(25) |
|
| 41 |
self.brush_color=(0,0,0,1) |
|
| 42 |
|
|
| 43 |
def layer_clear(self): |
|
| 44 |
self.fbo.bind() |
|
| 45 |
glClearColor(1,1,1,1) |
|
| 46 |
glClear(GL_COLOR_BUFFER_BIT) |
|
| 47 |
set_color(self.color) |
|
| 48 |
drawRectangle((0,0),(self.width,self.height)) |
|
| 49 |
self.fbo.release() |
|
| 50 |
|
|
| 51 |
def on_touch_down(self, touches, touchID, x, y): |
|
| 52 |
if self.collide_point(x,y): |
|
| 53 |
self.touch_positions[touchID] = self.to_local(x,y) |
|
| 54 |
if self.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() |
|
| 61 |
elif self.mode == "zoom": |
|
| 62 |
super(Layer, self).on_touch_down(touches, touchID, x, y) |
|
| 63 |
|
|
| 64 |
return True |
|
| 65 |
|
|
| 66 |
def on_touch_move(self, touches, touchID, x, y): |
|
| 67 |
if self.touch_positions.has_key(touchID): |
|
| 68 |
if self.mode == "zoom": |
|
| 69 |
super(Layer, self).on_touch_move(touches, touchID, x, y) |
|
| 70 |
elif self.mode == "draw": |
|
| 71 |
cur_pos = self.to_local(x,y) |
|
| 72 |
ox,oy = self.touch_positions[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() |
|
| 79 |
self.touch_positions[touchID] = self.to_local(x,y) |
|
| 80 |
return True |
|
| 81 |
|
|
| 82 |
def draw(self): |
|
| 83 |
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)) |
|
| 88 |
|
|
| 89 |
def set_mode(self,mode): |
|
| 90 |
self.mode = mode |
|
| 91 |
|
|
| 92 |
def set_brush_color(self,color): |
|
| 93 |
self.brush_color = color |
|
| core/app/canvas/canvas_new.py (revision 38) | ||
|---|---|---|
| 1 |
from __future__ import with_statement |
|
| 2 |
from pymt import * |
|
| 3 |
from pyglet.gl import * |
|
| 4 |
from layermanager import * |
|
| 5 |
|
|
| 6 |
class Canvas(MTScatterWidget): |
|
| 7 |
def __init__(self, **kwargs): |
|
| 8 |
super(Canvas, self).__init__(**kwargs) |
|
| 9 |
self.canvas_area = CanvasArea(pos=(10,10),size=(500,400)) |
|
| 10 |
self.add_widget(self.canvas_area) |
|
| 11 |
|
|
| 12 |
def draw(self): |
|
| 13 |
with gx_matrix: |
|
| 14 |
glColor4f(0,0,0,1) |
|
| 15 |
drawRectangle((0,0),(self.width,self.height)) |
|
| 16 |
|
|
| 17 |
class CanvasArea(MTStencilContainer): |
|
| 18 |
def __init__(self, **kwargs): |
|
| 19 |
super(CanvasArea, self).__init__(**kwargs) |
|
| 20 |
self.layer_manager = LayerManager(pos=(10,10),canvas=self) |
|
| 21 |
self.add_widget(self.layer_manager) |
|
| 22 |
|
|
| 23 |
#def draw(self): |
|
| 24 |
# pass |
|
| 25 |
#self.draw() |
|
| 26 |
|
|
| 27 |
|
|
| 28 |
|
|
| 29 |
if __name__ == '__main__': |
|
| 30 |
w = MTWindow() |
|
| 31 |
canvas = Canvas(size=(520,420)) |
|
| 32 |
w.add_widget(canvas) |
|
| 33 |
runTouchApp() |
|
| 34 |
|
|
| 35 |
|
|
| 36 |
|
|
| core/app/canvas/layermanager.py (revision 38) | ||
|---|---|---|
| 1 |
from __future__ import with_statement |
|
| 2 |
from pymt import * |
|
| 3 |
from pyglet.gl import * |
|
| 4 |
from layer import * |
|
| 5 |
|
|
| 6 |
class LayerManager(MTScatterWidget): |
|
| 7 |
def __init__(self, **kwargs): |
|
| 8 |
kwargs.setdefault('do_scale', False)
|
|
| 9 |
kwargs.setdefault('do_rotation', False)
|
|
| 10 |
kwargs.setdefault('do_translation', False)
|
|
| 11 |
super(LayerManager, self).__init__(**kwargs) |
|
| 12 |
self.canvas = kwargs.get('canvas')
|
|
| 13 |
self.size = self.canvas.size |
|
| 14 |
self.layer_list = [] |
|
| 15 |
self.background = Layer(size=self.canvas.size,color=(1,1,1,1),moveable=False) |
|
| 16 |
self.add_widget(self.background) |
|
| 17 |
self.layer1 = Layer(size=(200,200),color=(1,0,0,0.5)) |
|
| 18 |
self.add_widget(self.layer1) |
|
| 19 |
self.layer2 = Layer(size=(300,200),color=(0,1,0,0.5)) |
|
| 20 |
self.add_widget(self.layer2) |
|
| 21 |
self.layer3 = Layer(size=(250,150),color=(0,0,1,0.5)) |
|
| 22 |
self.add_widget(self.layer3) |
|
| 23 |
self.layer_list.append(self.background) |
|
| 24 |
|
|
| 25 |
|
|
Also available in: Unified diff
