author | Radek Brich <radek.brich@devl.cz> |
Fri, 28 Mar 2014 14:58:12 +0100 | |
changeset 95 | 05392e369ede |
parent 94 | e50dae408fe9 |
child 107 | 1822c37b2688 |
permissions | -rw-r--r-- |
86
0978fb755d31
Add core Application (adjusted), Window (new version), Signal (replaces Emitter), Size (adjusted). Add application demo.
Radek Brich <radek.brich@devl.cz>
parents:
81
diff
changeset
|
1 |
from tuikit.core.signal import Signal |
94
e50dae408fe9
Add origin to Buffer. Use it to simplify hierarchical drawing.
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
2 |
from tuikit.core.coords import Point, Size, Rect |
89 | 3 |
from tuikit.core.theme import default_theme |
4 |
||
5 |
from contextlib import contextmanager |
|
78
6031e99c8ad3
Add Buffer class with basic drawing methods.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
6 |
|
6031e99c8ad3
Add Buffer class with basic drawing methods.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
7 |
|
79
dbdc38f9981a
Add attribute storage to Buffer.
Radek Brich <radek.brich@devl.cz>
parents:
78
diff
changeset
|
8 |
class Cell: |
dbdc38f9981a
Add attribute storage to Buffer.
Radek Brich <radek.brich@devl.cz>
parents:
78
diff
changeset
|
9 |
|
dbdc38f9981a
Add attribute storage to Buffer.
Radek Brich <radek.brich@devl.cz>
parents:
78
diff
changeset
|
10 |
"""Character buffer cell. |
dbdc38f9981a
Add attribute storage to Buffer.
Radek Brich <radek.brich@devl.cz>
parents:
78
diff
changeset
|
11 |
|
dbdc38f9981a
Add attribute storage to Buffer.
Radek Brich <radek.brich@devl.cz>
parents:
78
diff
changeset
|
12 |
Cell contains one character and its attribute. |
dbdc38f9981a
Add attribute storage to Buffer.
Radek Brich <radek.brich@devl.cz>
parents:
78
diff
changeset
|
13 |
|
dbdc38f9981a
Add attribute storage to Buffer.
Radek Brich <radek.brich@devl.cz>
parents:
78
diff
changeset
|
14 |
""" |
dbdc38f9981a
Add attribute storage to Buffer.
Radek Brich <radek.brich@devl.cz>
parents:
78
diff
changeset
|
15 |
|
dbdc38f9981a
Add attribute storage to Buffer.
Radek Brich <radek.brich@devl.cz>
parents:
78
diff
changeset
|
16 |
__slots__ = ('char', 'attr') |
dbdc38f9981a
Add attribute storage to Buffer.
Radek Brich <radek.brich@devl.cz>
parents:
78
diff
changeset
|
17 |
|
dbdc38f9981a
Add attribute storage to Buffer.
Radek Brich <radek.brich@devl.cz>
parents:
78
diff
changeset
|
18 |
def __init__(self, char=' ', attr=0): |
dbdc38f9981a
Add attribute storage to Buffer.
Radek Brich <radek.brich@devl.cz>
parents:
78
diff
changeset
|
19 |
self.char = char |
dbdc38f9981a
Add attribute storage to Buffer.
Radek Brich <radek.brich@devl.cz>
parents:
78
diff
changeset
|
20 |
self.attr = attr |
dbdc38f9981a
Add attribute storage to Buffer.
Radek Brich <radek.brich@devl.cz>
parents:
78
diff
changeset
|
21 |
|
dbdc38f9981a
Add attribute storage to Buffer.
Radek Brich <radek.brich@devl.cz>
parents:
78
diff
changeset
|
22 |
def set(self, char, attr): |
dbdc38f9981a
Add attribute storage to Buffer.
Radek Brich <radek.brich@devl.cz>
parents:
78
diff
changeset
|
23 |
self.char = char |
dbdc38f9981a
Add attribute storage to Buffer.
Radek Brich <radek.brich@devl.cz>
parents:
78
diff
changeset
|
24 |
self.attr = attr |
dbdc38f9981a
Add attribute storage to Buffer.
Radek Brich <radek.brich@devl.cz>
parents:
78
diff
changeset
|
25 |
|
dbdc38f9981a
Add attribute storage to Buffer.
Radek Brich <radek.brich@devl.cz>
parents:
78
diff
changeset
|
26 |
|
86
0978fb755d31
Add core Application (adjusted), Window (new version), Signal (replaces Emitter), Size (adjusted). Add application demo.
Radek Brich <radek.brich@devl.cz>
parents:
81
diff
changeset
|
27 |
class BufferOperationsMixin: |
0978fb755d31
Add core Application (adjusted), Window (new version), Signal (replaces Emitter), Size (adjusted). Add application demo.
Radek Brich <radek.brich@devl.cz>
parents:
81
diff
changeset
|
28 |
|
0978fb755d31
Add core Application (adjusted), Window (new version), Signal (replaces Emitter), Size (adjusted). Add application demo.
Radek Brich <radek.brich@devl.cz>
parents:
81
diff
changeset
|
29 |
def draw(self, buffer, x=0, y=0): |
0978fb755d31
Add core Application (adjusted), Window (new version), Signal (replaces Emitter), Size (adjusted). Add application demo.
Radek Brich <radek.brich@devl.cz>
parents:
81
diff
changeset
|
30 |
"""Draw another buffer onto this buffer at x/y coords.""" |
0978fb755d31
Add core Application (adjusted), Window (new version), Signal (replaces Emitter), Size (adjusted). Add application demo.
Radek Brich <radek.brich@devl.cz>
parents:
81
diff
changeset
|
31 |
for bufy in range(buffer.size.h): |
0978fb755d31
Add core Application (adjusted), Window (new version), Signal (replaces Emitter), Size (adjusted). Add application demo.
Radek Brich <radek.brich@devl.cz>
parents:
81
diff
changeset
|
32 |
for bufx in range(buffer.size.w): |
0978fb755d31
Add core Application (adjusted), Window (new version), Signal (replaces Emitter), Size (adjusted). Add application demo.
Radek Brich <radek.brich@devl.cz>
parents:
81
diff
changeset
|
33 |
char, attr_desc = buffer.get(bufx, bufy) |
0978fb755d31
Add core Application (adjusted), Window (new version), Signal (replaces Emitter), Size (adjusted). Add application demo.
Radek Brich <radek.brich@devl.cz>
parents:
81
diff
changeset
|
34 |
self.setattr(attr_desc) |
95
05392e369ede
Refactoring: Swap drawing operations parameters. Coords are now last and have default values.
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
35 |
self.putch(char, x + bufx, y + bufy) |
86
0978fb755d31
Add core Application (adjusted), Window (new version), Signal (replaces Emitter), Size (adjusted). Add application demo.
Radek Brich <radek.brich@devl.cz>
parents:
81
diff
changeset
|
36 |
|
95
05392e369ede
Refactoring: Swap drawing operations parameters. Coords are now last and have default values.
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
37 |
def puts(self, s, x=0, y=0): |
86
0978fb755d31
Add core Application (adjusted), Window (new version), Signal (replaces Emitter), Size (adjusted). Add application demo.
Radek Brich <radek.brich@devl.cz>
parents:
81
diff
changeset
|
38 |
"""Output string of characters.""" |
95
05392e369ede
Refactoring: Swap drawing operations parameters. Coords are now last and have default values.
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
39 |
for ch in s: |
05392e369ede
Refactoring: Swap drawing operations parameters. Coords are now last and have default values.
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
40 |
self.putch(ch, x, y) |
86
0978fb755d31
Add core Application (adjusted), Window (new version), Signal (replaces Emitter), Size (adjusted). Add application demo.
Radek Brich <radek.brich@devl.cz>
parents:
81
diff
changeset
|
41 |
x += 1 |
0978fb755d31
Add core Application (adjusted), Window (new version), Signal (replaces Emitter), Size (adjusted). Add application demo.
Radek Brich <radek.brich@devl.cz>
parents:
81
diff
changeset
|
42 |
|
95
05392e369ede
Refactoring: Swap drawing operations parameters. Coords are now last and have default values.
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
43 |
def hline(self, ch='-', x=0, y=0, w=0): |
86
0978fb755d31
Add core Application (adjusted), Window (new version), Signal (replaces Emitter), Size (adjusted). Add application demo.
Radek Brich <radek.brich@devl.cz>
parents:
81
diff
changeset
|
44 |
"""Draw horizontal line.""" |
95
05392e369ede
Refactoring: Swap drawing operations parameters. Coords are now last and have default values.
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
45 |
w = self.size.w if not w else w |
05392e369ede
Refactoring: Swap drawing operations parameters. Coords are now last and have default values.
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
46 |
self.puts([ch] * w, x, y) |
86
0978fb755d31
Add core Application (adjusted), Window (new version), Signal (replaces Emitter), Size (adjusted). Add application demo.
Radek Brich <radek.brich@devl.cz>
parents:
81
diff
changeset
|
47 |
|
95
05392e369ede
Refactoring: Swap drawing operations parameters. Coords are now last and have default values.
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
48 |
def vline(self, ch='|', x=0, y=0, h=0): |
86
0978fb755d31
Add core Application (adjusted), Window (new version), Signal (replaces Emitter), Size (adjusted). Add application demo.
Radek Brich <radek.brich@devl.cz>
parents:
81
diff
changeset
|
49 |
"""Draw vertical line.""" |
95
05392e369ede
Refactoring: Swap drawing operations parameters. Coords are now last and have default values.
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
50 |
h = self.size.h if not h else h |
86
0978fb755d31
Add core Application (adjusted), Window (new version), Signal (replaces Emitter), Size (adjusted). Add application demo.
Radek Brich <radek.brich@devl.cz>
parents:
81
diff
changeset
|
51 |
for i in range(h): |
95
05392e369ede
Refactoring: Swap drawing operations parameters. Coords are now last and have default values.
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
52 |
self.putch(ch, x, y + i) |
86
0978fb755d31
Add core Application (adjusted), Window (new version), Signal (replaces Emitter), Size (adjusted). Add application demo.
Radek Brich <radek.brich@devl.cz>
parents:
81
diff
changeset
|
53 |
|
95
05392e369ede
Refactoring: Swap drawing operations parameters. Coords are now last and have default values.
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
54 |
def fill(self, ch=' ', x=0, y=0, w=0, h=0): |
86
0978fb755d31
Add core Application (adjusted), Window (new version), Signal (replaces Emitter), Size (adjusted). Add application demo.
Radek Brich <radek.brich@devl.cz>
parents:
81
diff
changeset
|
55 |
"""Fill rectangular area. |
0978fb755d31
Add core Application (adjusted), Window (new version), Signal (replaces Emitter), Size (adjusted). Add application demo.
Radek Brich <radek.brich@devl.cz>
parents:
81
diff
changeset
|
56 |
|
0978fb755d31
Add core Application (adjusted), Window (new version), Signal (replaces Emitter), Size (adjusted). Add application demo.
Radek Brich <radek.brich@devl.cz>
parents:
81
diff
changeset
|
57 |
Fill whole buffer if width or height is not specified (zero). |
0978fb755d31
Add core Application (adjusted), Window (new version), Signal (replaces Emitter), Size (adjusted). Add application demo.
Radek Brich <radek.brich@devl.cz>
parents:
81
diff
changeset
|
58 |
|
0978fb755d31
Add core Application (adjusted), Window (new version), Signal (replaces Emitter), Size (adjusted). Add application demo.
Radek Brich <radek.brich@devl.cz>
parents:
81
diff
changeset
|
59 |
""" |
0978fb755d31
Add core Application (adjusted), Window (new version), Signal (replaces Emitter), Size (adjusted). Add application demo.
Radek Brich <radek.brich@devl.cz>
parents:
81
diff
changeset
|
60 |
w = self.size.w if not w else w |
0978fb755d31
Add core Application (adjusted), Window (new version), Signal (replaces Emitter), Size (adjusted). Add application demo.
Radek Brich <radek.brich@devl.cz>
parents:
81
diff
changeset
|
61 |
h = self.size.h if not h else h |
0978fb755d31
Add core Application (adjusted), Window (new version), Signal (replaces Emitter), Size (adjusted). Add application demo.
Radek Brich <radek.brich@devl.cz>
parents:
81
diff
changeset
|
62 |
for i in range(h): |
95
05392e369ede
Refactoring: Swap drawing operations parameters. Coords are now last and have default values.
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
63 |
self.hline(ch, x, y + i, w) |
86
0978fb755d31
Add core Application (adjusted), Window (new version), Signal (replaces Emitter), Size (adjusted). Add application demo.
Radek Brich <radek.brich@devl.cz>
parents:
81
diff
changeset
|
64 |
|
89 | 65 |
def frame(self, x=0, y=0, w=0, h=0, theme=default_theme): |
86
0978fb755d31
Add core Application (adjusted), Window (new version), Signal (replaces Emitter), Size (adjusted). Add application demo.
Radek Brich <radek.brich@devl.cz>
parents:
81
diff
changeset
|
66 |
"""Draw rectangular frame. |
0978fb755d31
Add core Application (adjusted), Window (new version), Signal (replaces Emitter), Size (adjusted). Add application demo.
Radek Brich <radek.brich@devl.cz>
parents:
81
diff
changeset
|
67 |
|
0978fb755d31
Add core Application (adjusted), Window (new version), Signal (replaces Emitter), Size (adjusted). Add application demo.
Radek Brich <radek.brich@devl.cz>
parents:
81
diff
changeset
|
68 |
Frame whole buffer if width or height is not specified (zero). |
0978fb755d31
Add core Application (adjusted), Window (new version), Signal (replaces Emitter), Size (adjusted). Add application demo.
Radek Brich <radek.brich@devl.cz>
parents:
81
diff
changeset
|
69 |
Use line-drawing characters from `style` bank. |
0978fb755d31
Add core Application (adjusted), Window (new version), Signal (replaces Emitter), Size (adjusted). Add application demo.
Radek Brich <radek.brich@devl.cz>
parents:
81
diff
changeset
|
70 |
|
0978fb755d31
Add core Application (adjusted), Window (new version), Signal (replaces Emitter), Size (adjusted). Add application demo.
Radek Brich <radek.brich@devl.cz>
parents:
81
diff
changeset
|
71 |
""" |
0978fb755d31
Add core Application (adjusted), Window (new version), Signal (replaces Emitter), Size (adjusted). Add application demo.
Radek Brich <radek.brich@devl.cz>
parents:
81
diff
changeset
|
72 |
w = self.size.w if not w else w |
0978fb755d31
Add core Application (adjusted), Window (new version), Signal (replaces Emitter), Size (adjusted). Add application demo.
Radek Brich <radek.brich@devl.cz>
parents:
81
diff
changeset
|
73 |
h = self.size.h if not h else h |
95
05392e369ede
Refactoring: Swap drawing operations parameters. Coords are now last and have default values.
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
74 |
self.putch(theme.frame_ulcorner, x, y) |
05392e369ede
Refactoring: Swap drawing operations parameters. Coords are now last and have default values.
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
75 |
self.putch(theme.frame_urcorner, x+w-1, y) |
05392e369ede
Refactoring: Swap drawing operations parameters. Coords are now last and have default values.
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
76 |
self.putch(theme.frame_llcorner, x, y+h-1) |
05392e369ede
Refactoring: Swap drawing operations parameters. Coords are now last and have default values.
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
77 |
self.putch(theme.frame_lrcorner, x+w-1, y+h-1) |
05392e369ede
Refactoring: Swap drawing operations parameters. Coords are now last and have default values.
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
78 |
self.hline(theme.frame_hline, x+1, y, w-2) |
05392e369ede
Refactoring: Swap drawing operations parameters. Coords are now last and have default values.
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
79 |
self.hline(theme.frame_hline, x+1, y+h-1, w-2) |
05392e369ede
Refactoring: Swap drawing operations parameters. Coords are now last and have default values.
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
80 |
self.vline(theme.frame_vline, x, y+1, h-2) |
05392e369ede
Refactoring: Swap drawing operations parameters. Coords are now last and have default values.
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
81 |
self.vline(theme.frame_vline, x+w-1, y+1, h-2) |
89 | 82 |
|
83 |
@contextmanager |
|
84 |
def attr(self, attr_desc): |
|
85 |
"""Set attribute for block of commands, then restore previous attribute.""" |
|
86 |
original_attr = self.getattr() |
|
91
de80e140b0ec
Add clipping for Buffer draw operations.
Radek Brich <radek.brich@devl.cz>
parents:
90
diff
changeset
|
87 |
try: |
de80e140b0ec
Add clipping for Buffer draw operations.
Radek Brich <radek.brich@devl.cz>
parents:
90
diff
changeset
|
88 |
self.setattr(attr_desc) |
de80e140b0ec
Add clipping for Buffer draw operations.
Radek Brich <radek.brich@devl.cz>
parents:
90
diff
changeset
|
89 |
yield |
de80e140b0ec
Add clipping for Buffer draw operations.
Radek Brich <radek.brich@devl.cz>
parents:
90
diff
changeset
|
90 |
finally: |
de80e140b0ec
Add clipping for Buffer draw operations.
Radek Brich <radek.brich@devl.cz>
parents:
90
diff
changeset
|
91 |
self.setattr(original_attr) |
86
0978fb755d31
Add core Application (adjusted), Window (new version), Signal (replaces Emitter), Size (adjusted). Add application demo.
Radek Brich <radek.brich@devl.cz>
parents:
81
diff
changeset
|
92 |
|
0978fb755d31
Add core Application (adjusted), Window (new version), Signal (replaces Emitter), Size (adjusted). Add application demo.
Radek Brich <radek.brich@devl.cz>
parents:
81
diff
changeset
|
93 |
|
91
de80e140b0ec
Add clipping for Buffer draw operations.
Radek Brich <radek.brich@devl.cz>
parents:
90
diff
changeset
|
94 |
class BufferClippingMixin: |
de80e140b0ec
Add clipping for Buffer draw operations.
Radek Brich <radek.brich@devl.cz>
parents:
90
diff
changeset
|
95 |
|
de80e140b0ec
Add clipping for Buffer draw operations.
Radek Brich <radek.brich@devl.cz>
parents:
90
diff
changeset
|
96 |
@property |
de80e140b0ec
Add clipping for Buffer draw operations.
Radek Brich <radek.brich@devl.cz>
parents:
90
diff
changeset
|
97 |
def clip_rect(self): |
94
e50dae408fe9
Add origin to Buffer. Use it to simplify hierarchical drawing.
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
98 |
"""Return clipping rectangle in buffer coordinates.""" |
91
de80e140b0ec
Add clipping for Buffer draw operations.
Radek Brich <radek.brich@devl.cz>
parents:
90
diff
changeset
|
99 |
try: |
de80e140b0ec
Add clipping for Buffer draw operations.
Radek Brich <radek.brich@devl.cz>
parents:
90
diff
changeset
|
100 |
return self._clip_rect |
de80e140b0ec
Add clipping for Buffer draw operations.
Radek Brich <radek.brich@devl.cz>
parents:
90
diff
changeset
|
101 |
except AttributeError: |
de80e140b0ec
Add clipping for Buffer draw operations.
Radek Brich <radek.brich@devl.cz>
parents:
90
diff
changeset
|
102 |
self.clip_rect = None |
de80e140b0ec
Add clipping for Buffer draw operations.
Radek Brich <radek.brich@devl.cz>
parents:
90
diff
changeset
|
103 |
return self._clip_rect |
de80e140b0ec
Add clipping for Buffer draw operations.
Radek Brich <radek.brich@devl.cz>
parents:
90
diff
changeset
|
104 |
|
de80e140b0ec
Add clipping for Buffer draw operations.
Radek Brich <radek.brich@devl.cz>
parents:
90
diff
changeset
|
105 |
@clip_rect.setter |
de80e140b0ec
Add clipping for Buffer draw operations.
Radek Brich <radek.brich@devl.cz>
parents:
90
diff
changeset
|
106 |
def clip_rect(self, value): |
de80e140b0ec
Add clipping for Buffer draw operations.
Radek Brich <radek.brich@devl.cz>
parents:
90
diff
changeset
|
107 |
if value: |
de80e140b0ec
Add clipping for Buffer draw operations.
Radek Brich <radek.brich@devl.cz>
parents:
90
diff
changeset
|
108 |
self._clip_rect = value |
de80e140b0ec
Add clipping for Buffer draw operations.
Radek Brich <radek.brich@devl.cz>
parents:
90
diff
changeset
|
109 |
else: |
de80e140b0ec
Add clipping for Buffer draw operations.
Radek Brich <radek.brich@devl.cz>
parents:
90
diff
changeset
|
110 |
self._clip_rect = Rect(0, 0, self.size.w, self.size.h) |
de80e140b0ec
Add clipping for Buffer draw operations.
Radek Brich <radek.brich@devl.cz>
parents:
90
diff
changeset
|
111 |
|
de80e140b0ec
Add clipping for Buffer draw operations.
Radek Brich <radek.brich@devl.cz>
parents:
90
diff
changeset
|
112 |
def testxy(self, x, y): |
de80e140b0ec
Add clipping for Buffer draw operations.
Radek Brich <radek.brich@devl.cz>
parents:
90
diff
changeset
|
113 |
"""Test if x/y coords are inside current clipping region.""" |
de80e140b0ec
Add clipping for Buffer draw operations.
Radek Brich <radek.brich@devl.cz>
parents:
90
diff
changeset
|
114 |
return (x, y) in self.clip_rect |
de80e140b0ec
Add clipping for Buffer draw operations.
Radek Brich <radek.brich@devl.cz>
parents:
90
diff
changeset
|
115 |
|
de80e140b0ec
Add clipping for Buffer draw operations.
Radek Brich <radek.brich@devl.cz>
parents:
90
diff
changeset
|
116 |
@contextmanager |
de80e140b0ec
Add clipping for Buffer draw operations.
Radek Brich <radek.brich@devl.cz>
parents:
90
diff
changeset
|
117 |
def clip(self, x, y, w, h): |
de80e140b0ec
Add clipping for Buffer draw operations.
Radek Brich <radek.brich@devl.cz>
parents:
90
diff
changeset
|
118 |
"""Update clipping region as intersection of original and new region. |
de80e140b0ec
Add clipping for Buffer draw operations.
Radek Brich <radek.brich@devl.cz>
parents:
90
diff
changeset
|
119 |
|
de80e140b0ec
Add clipping for Buffer draw operations.
Radek Brich <radek.brich@devl.cz>
parents:
90
diff
changeset
|
120 |
Restore original region before returning. |
de80e140b0ec
Add clipping for Buffer draw operations.
Radek Brich <radek.brich@devl.cz>
parents:
90
diff
changeset
|
121 |
|
de80e140b0ec
Add clipping for Buffer draw operations.
Radek Brich <radek.brich@devl.cz>
parents:
90
diff
changeset
|
122 |
""" |
de80e140b0ec
Add clipping for Buffer draw operations.
Radek Brich <radek.brich@devl.cz>
parents:
90
diff
changeset
|
123 |
original_rect = self.clip_rect |
de80e140b0ec
Add clipping for Buffer draw operations.
Radek Brich <radek.brich@devl.cz>
parents:
90
diff
changeset
|
124 |
try: |
de80e140b0ec
Add clipping for Buffer draw operations.
Radek Brich <radek.brich@devl.cz>
parents:
90
diff
changeset
|
125 |
self.clip_rect = original_rect.intersect(Rect(x, y, w, h)) |
de80e140b0ec
Add clipping for Buffer draw operations.
Radek Brich <radek.brich@devl.cz>
parents:
90
diff
changeset
|
126 |
yield |
de80e140b0ec
Add clipping for Buffer draw operations.
Radek Brich <radek.brich@devl.cz>
parents:
90
diff
changeset
|
127 |
finally: |
de80e140b0ec
Add clipping for Buffer draw operations.
Radek Brich <radek.brich@devl.cz>
parents:
90
diff
changeset
|
128 |
self.clip_rect = original_rect |
de80e140b0ec
Add clipping for Buffer draw operations.
Radek Brich <radek.brich@devl.cz>
parents:
90
diff
changeset
|
129 |
|
de80e140b0ec
Add clipping for Buffer draw operations.
Radek Brich <radek.brich@devl.cz>
parents:
90
diff
changeset
|
130 |
|
94
e50dae408fe9
Add origin to Buffer. Use it to simplify hierarchical drawing.
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
131 |
class BufferOriginMixin: |
e50dae408fe9
Add origin to Buffer. Use it to simplify hierarchical drawing.
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
132 |
|
e50dae408fe9
Add origin to Buffer. Use it to simplify hierarchical drawing.
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
133 |
@property |
e50dae408fe9
Add origin to Buffer. Use it to simplify hierarchical drawing.
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
134 |
def origin(self): |
e50dae408fe9
Add origin to Buffer. Use it to simplify hierarchical drawing.
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
135 |
"""Origin coordinates for `putch`. |
e50dae408fe9
Add origin to Buffer. Use it to simplify hierarchical drawing.
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
136 |
|
e50dae408fe9
Add origin to Buffer. Use it to simplify hierarchical drawing.
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
137 |
Drawing is relative to origin. |
e50dae408fe9
Add origin to Buffer. Use it to simplify hierarchical drawing.
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
138 |
|
e50dae408fe9
Add origin to Buffer. Use it to simplify hierarchical drawing.
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
139 |
""" |
e50dae408fe9
Add origin to Buffer. Use it to simplify hierarchical drawing.
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
140 |
try: |
e50dae408fe9
Add origin to Buffer. Use it to simplify hierarchical drawing.
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
141 |
return self._origin |
e50dae408fe9
Add origin to Buffer. Use it to simplify hierarchical drawing.
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
142 |
except AttributeError: |
e50dae408fe9
Add origin to Buffer. Use it to simplify hierarchical drawing.
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
143 |
self._origin = Point(0, 0) |
e50dae408fe9
Add origin to Buffer. Use it to simplify hierarchical drawing.
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
144 |
return self._origin |
e50dae408fe9
Add origin to Buffer. Use it to simplify hierarchical drawing.
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
145 |
|
e50dae408fe9
Add origin to Buffer. Use it to simplify hierarchical drawing.
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
146 |
@origin.setter |
e50dae408fe9
Add origin to Buffer. Use it to simplify hierarchical drawing.
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
147 |
def origin(self, value): |
e50dae408fe9
Add origin to Buffer. Use it to simplify hierarchical drawing.
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
148 |
self.origin.update(value) |
e50dae408fe9
Add origin to Buffer. Use it to simplify hierarchical drawing.
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
149 |
|
e50dae408fe9
Add origin to Buffer. Use it to simplify hierarchical drawing.
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
150 |
def reset_origin(self): |
e50dae408fe9
Add origin to Buffer. Use it to simplify hierarchical drawing.
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
151 |
self.origin.update(0, 0) |
e50dae408fe9
Add origin to Buffer. Use it to simplify hierarchical drawing.
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
152 |
|
e50dae408fe9
Add origin to Buffer. Use it to simplify hierarchical drawing.
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
153 |
def move_origin(self, relx, rely): |
e50dae408fe9
Add origin to Buffer. Use it to simplify hierarchical drawing.
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
154 |
self.origin.move(relx, rely) |
e50dae408fe9
Add origin to Buffer. Use it to simplify hierarchical drawing.
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
155 |
|
e50dae408fe9
Add origin to Buffer. Use it to simplify hierarchical drawing.
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
156 |
@contextmanager |
e50dae408fe9
Add origin to Buffer. Use it to simplify hierarchical drawing.
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
157 |
def moved_origin(self, relx, rely): |
e50dae408fe9
Add origin to Buffer. Use it to simplify hierarchical drawing.
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
158 |
ox, oy = self.origin |
e50dae408fe9
Add origin to Buffer. Use it to simplify hierarchical drawing.
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
159 |
try: |
e50dae408fe9
Add origin to Buffer. Use it to simplify hierarchical drawing.
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
160 |
self.origin.move(relx, rely) |
e50dae408fe9
Add origin to Buffer. Use it to simplify hierarchical drawing.
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
161 |
yield |
e50dae408fe9
Add origin to Buffer. Use it to simplify hierarchical drawing.
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
162 |
finally: |
e50dae408fe9
Add origin to Buffer. Use it to simplify hierarchical drawing.
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
163 |
self.origin.update(ox, oy) |
e50dae408fe9
Add origin to Buffer. Use it to simplify hierarchical drawing.
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
164 |
|
e50dae408fe9
Add origin to Buffer. Use it to simplify hierarchical drawing.
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
165 |
|
e50dae408fe9
Add origin to Buffer. Use it to simplify hierarchical drawing.
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
166 |
class Buffer(BufferOperationsMixin, BufferClippingMixin, BufferOriginMixin): |
78
6031e99c8ad3
Add Buffer class with basic drawing methods.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
167 |
|
6031e99c8ad3
Add Buffer class with basic drawing methods.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
168 |
"""Rectangular character buffer. |
6031e99c8ad3
Add Buffer class with basic drawing methods.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
169 |
|
6031e99c8ad3
Add Buffer class with basic drawing methods.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
170 |
Retains characters and colors drawn into it |
6031e99c8ad3
Add Buffer class with basic drawing methods.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
171 |
until resized. Contents are reset when resized. |
6031e99c8ad3
Add Buffer class with basic drawing methods.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
172 |
|
6031e99c8ad3
Add Buffer class with basic drawing methods.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
173 |
""" |
6031e99c8ad3
Add Buffer class with basic drawing methods.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
174 |
|
6031e99c8ad3
Add Buffer class with basic drawing methods.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
175 |
def __init__(self, w=0, h=0): |
6031e99c8ad3
Add Buffer class with basic drawing methods.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
176 |
self._size = Size(w, h) |
6031e99c8ad3
Add Buffer class with basic drawing methods.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
177 |
self._data = None |
79
dbdc38f9981a
Add attribute storage to Buffer.
Radek Brich <radek.brich@devl.cz>
parents:
78
diff
changeset
|
178 |
self._attr_descs = ['default'] |
dbdc38f9981a
Add attribute storage to Buffer.
Radek Brich <radek.brich@devl.cz>
parents:
78
diff
changeset
|
179 |
self._attr_map = {'default': 0} |
dbdc38f9981a
Add attribute storage to Buffer.
Radek Brich <radek.brich@devl.cz>
parents:
78
diff
changeset
|
180 |
self._current_attr = 0 |
78
6031e99c8ad3
Add Buffer class with basic drawing methods.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
181 |
self.clear() |
86
0978fb755d31
Add core Application (adjusted), Window (new version), Signal (replaces Emitter), Size (adjusted). Add application demo.
Radek Brich <radek.brich@devl.cz>
parents:
81
diff
changeset
|
182 |
self.sig_resized = Signal() |
78
6031e99c8ad3
Add Buffer class with basic drawing methods.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
183 |
|
6031e99c8ad3
Add Buffer class with basic drawing methods.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
184 |
@property |
6031e99c8ad3
Add Buffer class with basic drawing methods.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
185 |
def size(self): |
94
e50dae408fe9
Add origin to Buffer. Use it to simplify hierarchical drawing.
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
186 |
"""Width and height of buffer, in characters.""" |
90
781774a8d568
Add timer, adjust inheritance of Widget, Container, Window.
Radek Brich <radek.brich@devl.cz>
parents:
89
diff
changeset
|
187 |
return self._size.readonly() |
78
6031e99c8ad3
Add Buffer class with basic drawing methods.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
188 |
|
6031e99c8ad3
Add Buffer class with basic drawing methods.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
189 |
def resize(self, w, h): |
6031e99c8ad3
Add Buffer class with basic drawing methods.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
190 |
"""Resize buffer.""" |
6031e99c8ad3
Add Buffer class with basic drawing methods.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
191 |
self._size.update(w, h) |
6031e99c8ad3
Add Buffer class with basic drawing methods.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
192 |
self.clear() |
86
0978fb755d31
Add core Application (adjusted), Window (new version), Signal (replaces Emitter), Size (adjusted). Add application demo.
Radek Brich <radek.brich@devl.cz>
parents:
81
diff
changeset
|
193 |
self.sig_resized(w, h) |
78
6031e99c8ad3
Add Buffer class with basic drawing methods.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
194 |
|
6031e99c8ad3
Add Buffer class with basic drawing methods.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
195 |
def clear(self): |
6031e99c8ad3
Add Buffer class with basic drawing methods.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
196 |
"""Reset buffer data.""" |
79
dbdc38f9981a
Add attribute storage to Buffer.
Radek Brich <radek.brich@devl.cz>
parents:
78
diff
changeset
|
197 |
self._data = [Cell() for _i in range(self._size.w * self._size.h)] |
91
de80e140b0ec
Add clipping for Buffer draw operations.
Radek Brich <radek.brich@devl.cz>
parents:
90
diff
changeset
|
198 |
self.clip_rect = None |
79
dbdc38f9981a
Add attribute storage to Buffer.
Radek Brich <radek.brich@devl.cz>
parents:
78
diff
changeset
|
199 |
|
dbdc38f9981a
Add attribute storage to Buffer.
Radek Brich <radek.brich@devl.cz>
parents:
78
diff
changeset
|
200 |
def get(self, x, y): |
dbdc38f9981a
Add attribute storage to Buffer.
Radek Brich <radek.brich@devl.cz>
parents:
78
diff
changeset
|
201 |
"""Get cell data at `x`, `y` coords. |
dbdc38f9981a
Add attribute storage to Buffer.
Radek Brich <radek.brich@devl.cz>
parents:
78
diff
changeset
|
202 |
|
dbdc38f9981a
Add attribute storage to Buffer.
Radek Brich <radek.brich@devl.cz>
parents:
78
diff
changeset
|
203 |
Returns tuple (char, attr_desc). |
78
6031e99c8ad3
Add Buffer class with basic drawing methods.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
204 |
|
79
dbdc38f9981a
Add attribute storage to Buffer.
Radek Brich <radek.brich@devl.cz>
parents:
78
diff
changeset
|
205 |
""" |
dbdc38f9981a
Add attribute storage to Buffer.
Radek Brich <radek.brich@devl.cz>
parents:
78
diff
changeset
|
206 |
cell = self._data[y * self._size.w + x] |
dbdc38f9981a
Add attribute storage to Buffer.
Radek Brich <radek.brich@devl.cz>
parents:
78
diff
changeset
|
207 |
return cell.char, self._attr_descs[cell.attr] |
78
6031e99c8ad3
Add Buffer class with basic drawing methods.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
208 |
|
89 | 209 |
def getattr(self): |
210 |
"""Get current attribute.""" |
|
211 |
return self._attr_descs[self._current_attr] |
|
212 |
||
81
5cd40c30c4f2
Add frame method to Buffer.
Radek Brich <radek.brich@devl.cz>
parents:
79
diff
changeset
|
213 |
def setattr(self, attr_desc): |
5cd40c30c4f2
Add frame method to Buffer.
Radek Brich <radek.brich@devl.cz>
parents:
79
diff
changeset
|
214 |
"""Set attribute to be used for subsequent draw operations.""" |
5cd40c30c4f2
Add frame method to Buffer.
Radek Brich <radek.brich@devl.cz>
parents:
79
diff
changeset
|
215 |
if attr_desc in self._attr_map: |
5cd40c30c4f2
Add frame method to Buffer.
Radek Brich <radek.brich@devl.cz>
parents:
79
diff
changeset
|
216 |
attr = self._attr_map[attr_desc] |
5cd40c30c4f2
Add frame method to Buffer.
Radek Brich <radek.brich@devl.cz>
parents:
79
diff
changeset
|
217 |
else: |
5cd40c30c4f2
Add frame method to Buffer.
Radek Brich <radek.brich@devl.cz>
parents:
79
diff
changeset
|
218 |
attr = len(self._attr_descs) |
5cd40c30c4f2
Add frame method to Buffer.
Radek Brich <radek.brich@devl.cz>
parents:
79
diff
changeset
|
219 |
self._attr_descs.append(attr_desc) |
5cd40c30c4f2
Add frame method to Buffer.
Radek Brich <radek.brich@devl.cz>
parents:
79
diff
changeset
|
220 |
self._attr_map[attr_desc] = attr |
5cd40c30c4f2
Add frame method to Buffer.
Radek Brich <radek.brich@devl.cz>
parents:
79
diff
changeset
|
221 |
self._current_attr = attr |
5cd40c30c4f2
Add frame method to Buffer.
Radek Brich <radek.brich@devl.cz>
parents:
79
diff
changeset
|
222 |
|
95
05392e369ede
Refactoring: Swap drawing operations parameters. Coords are now last and have default values.
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
223 |
def putch(self, ch, x=0, y=0): |
94
e50dae408fe9
Add origin to Buffer. Use it to simplify hierarchical drawing.
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
224 |
"""Set character on `x`, `y` coords to `ch`. |
e50dae408fe9
Add origin to Buffer. Use it to simplify hierarchical drawing.
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
225 |
|
e50dae408fe9
Add origin to Buffer. Use it to simplify hierarchical drawing.
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
226 |
Coords are adjusted by origin. |
e50dae408fe9
Add origin to Buffer. Use it to simplify hierarchical drawing.
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
227 |
|
e50dae408fe9
Add origin to Buffer. Use it to simplify hierarchical drawing.
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
228 |
""" |
e50dae408fe9
Add origin to Buffer. Use it to simplify hierarchical drawing.
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
229 |
x += self.origin.x |
e50dae408fe9
Add origin to Buffer. Use it to simplify hierarchical drawing.
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
230 |
y += self.origin.y |
91
de80e140b0ec
Add clipping for Buffer draw operations.
Radek Brich <radek.brich@devl.cz>
parents:
90
diff
changeset
|
231 |
if self.testxy(x, y): |
de80e140b0ec
Add clipping for Buffer draw operations.
Radek Brich <radek.brich@devl.cz>
parents:
90
diff
changeset
|
232 |
self._data[y * self._size.w + x].set(ch, self._current_attr) |
78
6031e99c8ad3
Add Buffer class with basic drawing methods.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
233 |
|
86
0978fb755d31
Add core Application (adjusted), Window (new version), Signal (replaces Emitter), Size (adjusted). Add application demo.
Radek Brich <radek.brich@devl.cz>
parents:
81
diff
changeset
|
234 |
|
94
e50dae408fe9
Add origin to Buffer. Use it to simplify hierarchical drawing.
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
235 |
class ProxyBuffer(BufferOperationsMixin, BufferClippingMixin, BufferOriginMixin): |
78
6031e99c8ad3
Add Buffer class with basic drawing methods.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
236 |
|
86
0978fb755d31
Add core Application (adjusted), Window (new version), Signal (replaces Emitter), Size (adjusted). Add application demo.
Radek Brich <radek.brich@devl.cz>
parents:
81
diff
changeset
|
237 |
"""Special buffer which proxies the operations |
0978fb755d31
Add core Application (adjusted), Window (new version), Signal (replaces Emitter), Size (adjusted). Add application demo.
Radek Brich <radek.brich@devl.cz>
parents:
81
diff
changeset
|
238 |
to another buffer or buffer-like class.""" |
78
6031e99c8ad3
Add Buffer class with basic drawing methods.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
239 |
|
86
0978fb755d31
Add core Application (adjusted), Window (new version), Signal (replaces Emitter), Size (adjusted). Add application demo.
Radek Brich <radek.brich@devl.cz>
parents:
81
diff
changeset
|
240 |
def __init__(self, target): |
0978fb755d31
Add core Application (adjusted), Window (new version), Signal (replaces Emitter), Size (adjusted). Add application demo.
Radek Brich <radek.brich@devl.cz>
parents:
81
diff
changeset
|
241 |
self.target = target |
0978fb755d31
Add core Application (adjusted), Window (new version), Signal (replaces Emitter), Size (adjusted). Add application demo.
Radek Brich <radek.brich@devl.cz>
parents:
81
diff
changeset
|
242 |
self.sig_resized = Signal() |
78
6031e99c8ad3
Add Buffer class with basic drawing methods.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
243 |
|
86
0978fb755d31
Add core Application (adjusted), Window (new version), Signal (replaces Emitter), Size (adjusted). Add application demo.
Radek Brich <radek.brich@devl.cz>
parents:
81
diff
changeset
|
244 |
@property |
0978fb755d31
Add core Application (adjusted), Window (new version), Signal (replaces Emitter), Size (adjusted). Add application demo.
Radek Brich <radek.brich@devl.cz>
parents:
81
diff
changeset
|
245 |
def size(self): |
0978fb755d31
Add core Application (adjusted), Window (new version), Signal (replaces Emitter), Size (adjusted). Add application demo.
Radek Brich <radek.brich@devl.cz>
parents:
81
diff
changeset
|
246 |
return self.target.size |
81
5cd40c30c4f2
Add frame method to Buffer.
Radek Brich <radek.brich@devl.cz>
parents:
79
diff
changeset
|
247 |
|
86
0978fb755d31
Add core Application (adjusted), Window (new version), Signal (replaces Emitter), Size (adjusted). Add application demo.
Radek Brich <radek.brich@devl.cz>
parents:
81
diff
changeset
|
248 |
def resize(self, w, h): |
0978fb755d31
Add core Application (adjusted), Window (new version), Signal (replaces Emitter), Size (adjusted). Add application demo.
Radek Brich <radek.brich@devl.cz>
parents:
81
diff
changeset
|
249 |
"""Resize buffer.""" |
0978fb755d31
Add core Application (adjusted), Window (new version), Signal (replaces Emitter), Size (adjusted). Add application demo.
Radek Brich <radek.brich@devl.cz>
parents:
81
diff
changeset
|
250 |
self.target.resize(w, h) |
0978fb755d31
Add core Application (adjusted), Window (new version), Signal (replaces Emitter), Size (adjusted). Add application demo.
Radek Brich <radek.brich@devl.cz>
parents:
81
diff
changeset
|
251 |
self.sig_resized(w, h) |
79
dbdc38f9981a
Add attribute storage to Buffer.
Radek Brich <radek.brich@devl.cz>
parents:
78
diff
changeset
|
252 |
|
86
0978fb755d31
Add core Application (adjusted), Window (new version), Signal (replaces Emitter), Size (adjusted). Add application demo.
Radek Brich <radek.brich@devl.cz>
parents:
81
diff
changeset
|
253 |
def clear(self): |
0978fb755d31
Add core Application (adjusted), Window (new version), Signal (replaces Emitter), Size (adjusted). Add application demo.
Radek Brich <radek.brich@devl.cz>
parents:
81
diff
changeset
|
254 |
"""Reset buffer data.""" |
0978fb755d31
Add core Application (adjusted), Window (new version), Signal (replaces Emitter), Size (adjusted). Add application demo.
Radek Brich <radek.brich@devl.cz>
parents:
81
diff
changeset
|
255 |
self.target.clear() |
91
de80e140b0ec
Add clipping for Buffer draw operations.
Radek Brich <radek.brich@devl.cz>
parents:
90
diff
changeset
|
256 |
self.clip_rect = None |
79
dbdc38f9981a
Add attribute storage to Buffer.
Radek Brich <radek.brich@devl.cz>
parents:
78
diff
changeset
|
257 |
|
86
0978fb755d31
Add core Application (adjusted), Window (new version), Signal (replaces Emitter), Size (adjusted). Add application demo.
Radek Brich <radek.brich@devl.cz>
parents:
81
diff
changeset
|
258 |
def get(self, x, y): |
0978fb755d31
Add core Application (adjusted), Window (new version), Signal (replaces Emitter), Size (adjusted). Add application demo.
Radek Brich <radek.brich@devl.cz>
parents:
81
diff
changeset
|
259 |
"""Get cell data at `x`, `y` coords.""" |
0978fb755d31
Add core Application (adjusted), Window (new version), Signal (replaces Emitter), Size (adjusted). Add application demo.
Radek Brich <radek.brich@devl.cz>
parents:
81
diff
changeset
|
260 |
return self.target.get(x, y) |
81
5cd40c30c4f2
Add frame method to Buffer.
Radek Brich <radek.brich@devl.cz>
parents:
79
diff
changeset
|
261 |
|
89 | 262 |
def getattr(self): |
263 |
"""Get current attribute.""" |
|
264 |
return self.target.getattr() |
|
265 |
||
86
0978fb755d31
Add core Application (adjusted), Window (new version), Signal (replaces Emitter), Size (adjusted). Add application demo.
Radek Brich <radek.brich@devl.cz>
parents:
81
diff
changeset
|
266 |
def setattr(self, attr_desc): |
0978fb755d31
Add core Application (adjusted), Window (new version), Signal (replaces Emitter), Size (adjusted). Add application demo.
Radek Brich <radek.brich@devl.cz>
parents:
81
diff
changeset
|
267 |
"""Set attribute to be used for subsequent draw operations.""" |
0978fb755d31
Add core Application (adjusted), Window (new version), Signal (replaces Emitter), Size (adjusted). Add application demo.
Radek Brich <radek.brich@devl.cz>
parents:
81
diff
changeset
|
268 |
self.target.setattr(attr_desc) |
0978fb755d31
Add core Application (adjusted), Window (new version), Signal (replaces Emitter), Size (adjusted). Add application demo.
Radek Brich <radek.brich@devl.cz>
parents:
81
diff
changeset
|
269 |
|
95
05392e369ede
Refactoring: Swap drawing operations parameters. Coords are now last and have default values.
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
270 |
def putch(self, ch, x=0, y=0): |
94
e50dae408fe9
Add origin to Buffer. Use it to simplify hierarchical drawing.
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
271 |
"""Set character on `x`, `y` coords to `ch`. |
e50dae408fe9
Add origin to Buffer. Use it to simplify hierarchical drawing.
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
272 |
|
e50dae408fe9
Add origin to Buffer. Use it to simplify hierarchical drawing.
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
273 |
Coords are adjusted by origin. |
e50dae408fe9
Add origin to Buffer. Use it to simplify hierarchical drawing.
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
274 |
|
e50dae408fe9
Add origin to Buffer. Use it to simplify hierarchical drawing.
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
275 |
""" |
e50dae408fe9
Add origin to Buffer. Use it to simplify hierarchical drawing.
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
276 |
x += self.origin.x |
e50dae408fe9
Add origin to Buffer. Use it to simplify hierarchical drawing.
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
277 |
y += self.origin.y |
91
de80e140b0ec
Add clipping for Buffer draw operations.
Radek Brich <radek.brich@devl.cz>
parents:
90
diff
changeset
|
278 |
if self.testxy(x, y): |
95
05392e369ede
Refactoring: Swap drawing operations parameters. Coords are now last and have default values.
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
279 |
self.target.putch(ch, x, y) |
86
0978fb755d31
Add core Application (adjusted), Window (new version), Signal (replaces Emitter), Size (adjusted). Add application demo.
Radek Brich <radek.brich@devl.cz>
parents:
81
diff
changeset
|
280 |