lib/unigraphic/GraphicsDisplay.cpp

Mon, 11 Mar 2024 15:35:36 +0100

author
David Douard <david.douard@sdf3.org>
date
Mon, 11 Mar 2024 15:35:36 +0100
changeset 71
d193c24a078a
parent 66
48f29a1d43d6
permissions
-rw-r--r--

Add links to sr.ht repos and add an image in the README file

5
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
1 /* mbed UniGraphic library - Graphics class
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
2 * Copyright (c) 2015 Giuliano Dianda
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
3 * Released under the MIT License: http://mbed.org/license/mit
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
4 *
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
5 * Derived work of:
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
6 *
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
7 * mbed GraphicsDisplay Display Library Base Class
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
8 * Copyright (c) 2007-2009 sford
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
9 * Released under the MIT License: http://mbed.org/license/mit
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
10 *
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
11 * mbed library for 240*320 pixel display TFT based on ILI9341 LCD Controller
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
12 * Copyright (c) 2013 Peter Drescher - DC2PD
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
13 *
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
20 * THE SOFTWARE.
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
21 */
26
86f099bda525 Several stuff
David Douard <david.douard@sdfa3.org>
parents: 5
diff changeset
22
5
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
23
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
24 #include "GraphicsDisplay.h"
26
86f099bda525 Several stuff
David Douard <david.douard@sdfa3.org>
parents: 5
diff changeset
25
5
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
26 #define SWAP(a, b) { a ^= b; b ^= a; a ^= b; }
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
27 GraphicsDisplay::GraphicsDisplay(const char *name):TextDisplay(name) {
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
28 set_font((unsigned char*)Terminal6x8,32,127,true);
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
29 // foreground(0xFFFF);
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
30 // background(0x0000);
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
31 char_x = 0;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
32 char_y = 0;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
33 oriented_width=0;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
34 oriented_height=0;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
35 fontzoomver=1;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
36 fontzoomhor=1;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
37 auto_up = true;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
38 }
26
86f099bda525 Several stuff
David Douard <david.douard@sdfa3.org>
parents: 5
diff changeset
39
5
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
40 void GraphicsDisplay::WindowMax (void)
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
41 {
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
42 window (0, 0, oriented_width, oriented_height);
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
43 }
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
44 void GraphicsDisplay::set_width(int width)
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
45 {
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
46 oriented_width = width;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
47 }
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
48 void GraphicsDisplay::set_height(int height)
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
49 {
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
50 oriented_height = height;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
51 }
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
52 int GraphicsDisplay::width()
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
53 {
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
54 return oriented_width;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
55 }
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
56 int GraphicsDisplay::height()
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
57 {
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
58 return oriented_height;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
59 }
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
60 void GraphicsDisplay::circle(int x0, int y0, int r, unsigned short color)
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
61 {
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
62 int x = -r, y = 0, err = 2-2*r, e2;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
63 do {
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
64 pixel(x0-x, y0+y,color);
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
65 pixel(x0+x, y0+y,color);
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
66 pixel(x0+x, y0-y,color);
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
67 pixel(x0-x, y0-y,color);
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
68 e2 = err;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
69 if (e2 <= y) {
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
70 err += ++y*2+1;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
71 if (-x == y && e2 <= x) e2 = 0;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
72 }
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
73 if (e2 > x) err += ++x*2+1;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
74 } while (x <= 0);
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
75 if(auto_up) copy_to_lcd();
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
76 }
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
77 void GraphicsDisplay::fillcircle(int x0, int y0, int r, unsigned short color)
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
78 {
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
79 bool old_auto_up=auto_up;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
80 if(auto_up) auto_up=false;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
81 int x = -r, y = 0, err = 2-2*r, e2;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
82 do {
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
83 vline(x0-x, y0-y, y0+y, color);
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
84 vline(x0+x, y0-y, y0+y, color);
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
85 e2 = err;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
86 if (e2 <= y) {
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
87 err += ++y*2+1;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
88 if (-x == y && e2 <= x) e2 = 0;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
89 }
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
90 if (e2 > x) err += ++x*2+1;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
91 } while (x <= 0);
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
92 if(old_auto_up)
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
93 {
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
94 auto_up=true;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
95 copy_to_lcd();
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
96 }
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
97 }
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
98 void GraphicsDisplay::hline(int x0, int x1, int y, unsigned short color)
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
99 {
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
100 int len = x1 - x0 + 1;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
101 window(x0,y,len,1);
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
102 // for (int j=0; j<len; j++) window_pushpixel(color);
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
103 window_pushpixel(color, len);
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
104 if(auto_up) copy_to_lcd();
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
105 return;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
106 }
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
107 void GraphicsDisplay::vline(int x, int y0, int y1, unsigned short color)
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
108 {
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
109 int len = y1 - y0 + 1;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
110 window(x,y0,1,len);
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
111 // for (int y=0; y<len; y++) window_pushpixel(color);
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
112 window_pushpixel(color, len);
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
113 if(auto_up) copy_to_lcd();
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
114 return;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
115 }
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
116 void GraphicsDisplay::line(int x0, int y0, int x1, int y1, unsigned short color)
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
117 {
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
118 //WindowMax();
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
119 int dx = 0, dy = 0;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
120 int dx_sym = 0, dy_sym = 0;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
121 int dx_x2 = 0, dy_x2 = 0;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
122 int di = 0;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
123
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
124 dx = x1-x0;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
125 dy = y1-y0;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
126
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
127 if (dx == 0) { /* vertical line */
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
128 if (y1 < y0) SWAP(y0,y1);
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
129 vline(x0,y0,y1,color);
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
130 return;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
131 }
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
132
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
133 if (dx > 0) {
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
134 dx_sym = 1;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
135 } else {
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
136 dx_sym = -1;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
137 }
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
138 if (dy == 0) { /* horizontal line */
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
139 if (x1 < x0) SWAP(x1,x0);
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
140 hline(x0,x1,y0,color);
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
141 return;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
142 }
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
143
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
144 if (dy > 0) {
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
145 dy_sym = 1;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
146 } else {
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
147 dy_sym = -1;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
148 }
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
149
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
150 dx = dx_sym*dx;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
151 dy = dy_sym*dy;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
152
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
153 dx_x2 = dx*2;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
154 dy_x2 = dy*2;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
155
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
156 if (dx >= dy) {
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
157 di = dy_x2 - dx;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
158 while (x0 != x1) {
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
159
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
160 pixel(x0, y0, color);
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
161 x0 += dx_sym;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
162 if (di<0) {
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
163 di += dy_x2;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
164 } else {
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
165 di += dy_x2 - dx_x2;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
166 y0 += dy_sym;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
167 }
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
168 }
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
169 pixel(x0, y0, color);
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
170 } else {
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
171 di = dx_x2 - dy;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
172 while (y0 != y1) {
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
173 pixel(x0, y0, color);
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
174 y0 += dy_sym;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
175 if (di < 0) {
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
176 di += dx_x2;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
177 } else {
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
178 di += dx_x2 - dy_x2;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
179 x0 += dx_sym;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
180 }
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
181 }
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
182 pixel(x0, y0, color);
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
183 }
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
184 if(auto_up) copy_to_lcd();
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
185 return;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
186 }
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
187 void GraphicsDisplay::rect(int x0, int y0, int x1, int y1, unsigned short color)
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
188 {
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
189 bool old_auto_up=auto_up;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
190 if(auto_up) auto_up=0;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
191 if (x1 > x0) hline(x0,x1,y0,color);
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
192 else hline(x1,x0,y0,color);
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
193
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
194 if (y1 > y0) vline(x0,y0,y1,color);
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
195 else vline(x0,y1,y0,color);
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
196
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
197 if (x1 > x0) hline(x0,x1,y1,color);
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
198 else hline(x1,x0,y1,color);
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
199
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
200 if (y1 > y0) vline(x1,y0,y1,color);
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
201 else vline(x1,y1,y0,color);
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
202 if(old_auto_up)
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
203 {
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
204 auto_up=true;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
205 copy_to_lcd();
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
206 }
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
207 return;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
208 }
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
209 void GraphicsDisplay::fillrect(int x0, int y0, int x1, int y1, unsigned short color)
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
210 {
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
211 if(x0 > x1) SWAP(x0,x1);
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
212 if(y0 > y1) SWAP(y0,y1);
26
86f099bda525 Several stuff
David Douard <david.douard@sdfa3.org>
parents: 5
diff changeset
213
5
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
214 int h = y1 - y0 + 1;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
215 int w = x1 - x0 + 1;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
216 unsigned int pixels = h * w;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
217 window(x0,y0,w,h);
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
218 // for (unsigned int p=0; p<pixels; p++) window_pushpixel(color);
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
219 window_pushpixel(color, pixels);
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
220 if(auto_up) copy_to_lcd();
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
221 return;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
222 }
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
223 void GraphicsDisplay::locate(int x, int y)
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
224 {
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
225 char_x = x;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
226 char_y = y;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
227 }
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
228 int GraphicsDisplay::columns()
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
229 {
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
230 return oriented_width / fonthor;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
231 }
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
232 int GraphicsDisplay::rows()
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
233 {
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
234 return oriented_height / fontvert;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
235 }
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
236 void GraphicsDisplay::set_font(unsigned char* f, unsigned char firstascii, unsigned char lastascii, bool proportional)
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
237 {
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
238 font = f;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
239 // read font parameter from start of array
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
240 //fontoffset = font[0]; // bytes / char
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
241 fonthor = font[1]; // get hor size of font
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
242 fontvert = font[2]; // get vert size of font
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
243 //fontbpl = font[3]; // bytes per line
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
244 fontbpl = (fontvert+7)>>3; //bytes per line, rounded up to multiple of 8
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
245 fontoffset = (fonthor*fontbpl)+1;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
246 firstch = firstascii; // first ascii code present in font array (usually 32)
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
247 lastch = lastascii; // last ascii code present in font array (usually 127)
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
248 fontprop = proportional;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
249 set_font_zoom(1,1);
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
250 }
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
251 void GraphicsDisplay::set_font_zoom(unsigned char x_mul, unsigned char y_mul)
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
252 {
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
253 fontzoomhor=((x_mul==0) ? 1:x_mul);
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
254 fontzoomver=((y_mul==0) ? 1:y_mul);
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
255 }
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
256 int GraphicsDisplay::_putc(int value)
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
257 {
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
258 if (value == '\n') { // new line
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
259 char_x = 0;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
260 char_y = char_y + fontvert*fontzoomver;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
261 if (char_y >= oriented_height - fontvert*fontzoomver) {
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
262 char_y = 0;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
263 }
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
264 } else {
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
265 character(char_x, char_y, value);
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
266 if(auto_up) copy_to_lcd();
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
267 }
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
268 return value;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
269 }
45
2da50a3d4e9f Adjust font rendering
David Douard <david.douard@sdf3.org>
parents: 26
diff changeset
270
2da50a3d4e9f Adjust font rendering
David Douard <david.douard@sdf3.org>
parents: 26
diff changeset
271 void GraphicsDisplay::character(int c)
2da50a3d4e9f Adjust font rendering
David Douard <david.douard@sdf3.org>
parents: 26
diff changeset
272 {
2da50a3d4e9f Adjust font rendering
David Douard <david.douard@sdf3.org>
parents: 26
diff changeset
273 character(char_x, char_y, c);
2da50a3d4e9f Adjust font rendering
David Douard <david.douard@sdf3.org>
parents: 26
diff changeset
274 }
2da50a3d4e9f Adjust font rendering
David Douard <david.douard@sdf3.org>
parents: 26
diff changeset
275
5
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
276 void GraphicsDisplay::character(int x, int y, int c)
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
277 {
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
278 char_x=x;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
279 char_y=y;
66
48f29a1d43d6 Clean several compilation warnings
David Douard <david.douard@sdfa3.org>
parents: 58
diff changeset
280 unsigned int j, i, b;
5
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
281 unsigned char* zeichen;
66
48f29a1d43d6 Clean several compilation warnings
David Douard <david.douard@sdfa3.org>
parents: 58
diff changeset
282 unsigned char z, w, v, wtot;
5
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
283
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
284 /* // read font parameter from start of array
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
285 offset = font[0]; // bytes / char
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
286 hor = font[1]; // get hor size of font
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
287 vert = font[2]; // get vert size of font
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
288 bpl = font[3]; // bytes per line
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
289 */
58
c1dfd75f2842 Do not go to the next line if the char to display does not fit
David Douard <david.douard@sdf3.org>
parents: 45
diff changeset
290 /*
5
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
291 if (char_x + fonthor*fontzoomhor > oriented_width) {
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
292 char_x = 0;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
293 char_y = char_y + fontvert*fontzoomver;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
294 if (char_y > oriented_height - fontvert*fontzoomver) {
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
295 char_y = 0;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
296 }
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
297 }
58
c1dfd75f2842 Do not go to the next line if the char to display does not fit
David Douard <david.douard@sdf3.org>
parents: 45
diff changeset
298 */
c1dfd75f2842 Do not go to the next line if the char to display does not fit
David Douard <david.douard@sdf3.org>
parents: 45
diff changeset
299 if (char_x + fonthor*fontzoomhor > oriented_width) {
c1dfd75f2842 Do not go to the next line if the char to display does not fit
David Douard <david.douard@sdf3.org>
parents: 45
diff changeset
300 // a bit brutal, but meh
c1dfd75f2842 Do not go to the next line if the char to display does not fit
David Douard <david.douard@sdf3.org>
parents: 45
diff changeset
301 // so if the char to write crosses the width, do not display it
c1dfd75f2842 Do not go to the next line if the char to display does not fit
David Douard <david.douard@sdf3.org>
parents: 45
diff changeset
302 return;
c1dfd75f2842 Do not go to the next line if the char to display does not fit
David Douard <david.douard@sdf3.org>
parents: 45
diff changeset
303 }
66
48f29a1d43d6 Clean several compilation warnings
David Douard <david.douard@sdfa3.org>
parents: 58
diff changeset
304 wtot = 0;
48f29a1d43d6 Clean several compilation warnings
David Douard <david.douard@sdfa3.org>
parents: 58
diff changeset
305
5
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
306 if ((c < firstch) || (c > lastch)) { // test char range - if not exist fill with blank
45
2da50a3d4e9f Adjust font rendering
David Douard <david.douard@sdf3.org>
parents: 26
diff changeset
307 window(char_x, char_y, fonthor*fontzoomhor, fontvert*fontzoomver); // char box
5
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
308 window_pushpixel(_background, fontzoomhor*fonthor*fontvert*fontzoomver); //(color, howmany)
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
309 w = fonthor;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
310 } else {
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
311 zeichen = &font[((c-firstch) * fontoffset) + 4]; // start of char bitmap
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
312 w = zeichen[0]; // width of actual char
45
2da50a3d4e9f Adjust font rendering
David Douard <david.douard@sdf3.org>
parents: 26
diff changeset
313 if((fontprop) && (w<fonthor))
2da50a3d4e9f Adjust font rendering
David Douard <david.douard@sdf3.org>
parents: 26
diff changeset
314 // put at least 1 blank after variable-width characters, except
2da50a3d4e9f Adjust font rendering
David Douard <david.douard@sdf3.org>
parents: 26
diff changeset
315 // characters that occupy whole fonthor space like "_"
2da50a3d4e9f Adjust font rendering
David Douard <david.douard@sdf3.org>
parents: 26
diff changeset
316 wtot = (w*fontzoomhor) + 1;
2da50a3d4e9f Adjust font rendering
David Douard <david.douard@sdf3.org>
parents: 26
diff changeset
317 else
2da50a3d4e9f Adjust font rendering
David Douard <david.douard@sdf3.org>
parents: 26
diff changeset
318 wtot = fonthor*fontzoomhor;
2da50a3d4e9f Adjust font rendering
David Douard <david.douard@sdf3.org>
parents: 26
diff changeset
319 window(char_x, char_y, wtot, fontvert*fontzoomver); // char box
2da50a3d4e9f Adjust font rendering
David Douard <david.douard@sdf3.org>
parents: 26
diff changeset
320
5
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
321 // construct the char into the buffer
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
322 for (j=0; j<(fontbpl); j++) { // vert bytes
45
2da50a3d4e9f Adjust font rendering
David Douard <david.douard@sdf3.org>
parents: 26
diff changeset
323 for (v=0; v<fontzoomver; v++) { // repeat horiz line for vertical zooming
2da50a3d4e9f Adjust font rendering
David Douard <david.douard@sdf3.org>
parents: 26
diff changeset
324 for (int p=0; p<8; p++) { // pixel in the current vert byte
2da50a3d4e9f Adjust font rendering
David Douard <david.douard@sdf3.org>
parents: 26
diff changeset
325 if ((j*8+p) > fontvert)
2da50a3d4e9f Adjust font rendering
David Douard <david.douard@sdf3.org>
parents: 26
diff changeset
326 break;
2da50a3d4e9f Adjust font rendering
David Douard <david.douard@sdf3.org>
parents: 26
diff changeset
327 b = 1 << p;
2da50a3d4e9f Adjust font rendering
David Douard <david.douard@sdf3.org>
parents: 26
diff changeset
328 for (i=0; i<wtot; i++) { // horz line
2da50a3d4e9f Adjust font rendering
David Douard <david.douard@sdf3.org>
parents: 26
diff changeset
329 z = zeichen[(fontbpl * i) + j + 1];
2da50a3d4e9f Adjust font rendering
David Douard <david.douard@sdf3.org>
parents: 26
diff changeset
330 window_pushpixel(( z & b ) ? _foreground : _background, fontzoomhor); //(color, howmany)
2da50a3d4e9f Adjust font rendering
David Douard <david.douard@sdf3.org>
parents: 26
diff changeset
331 }
2da50a3d4e9f Adjust font rendering
David Douard <david.douard@sdf3.org>
parents: 26
diff changeset
332 }
2da50a3d4e9f Adjust font rendering
David Douard <david.douard@sdf3.org>
parents: 26
diff changeset
333 } //for each zoomed vert
5
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
334 }
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
335 }
45
2da50a3d4e9f Adjust font rendering
David Douard <david.douard@sdf3.org>
parents: 26
diff changeset
336 char_x += wtot;
2da50a3d4e9f Adjust font rendering
David Douard <david.douard@sdf3.org>
parents: 26
diff changeset
337 }
2da50a3d4e9f Adjust font rendering
David Douard <david.douard@sdf3.org>
parents: 26
diff changeset
338
2da50a3d4e9f Adjust font rendering
David Douard <david.douard@sdf3.org>
parents: 26
diff changeset
339 uint8_t GraphicsDisplay::char_width(char c, bool move_location)
2da50a3d4e9f Adjust font rendering
David Douard <david.douard@sdf3.org>
parents: 26
diff changeset
340 {
2da50a3d4e9f Adjust font rendering
David Douard <david.douard@sdf3.org>
parents: 26
diff changeset
341 unsigned char* zeichen;
2da50a3d4e9f Adjust font rendering
David Douard <david.douard@sdf3.org>
parents: 26
diff changeset
342 uint8_t w;
2da50a3d4e9f Adjust font rendering
David Douard <david.douard@sdf3.org>
parents: 26
diff changeset
343
2da50a3d4e9f Adjust font rendering
David Douard <david.douard@sdf3.org>
parents: 26
diff changeset
344 zeichen = &font[((c-firstch) * fontoffset) + 4]; // start of char bitmap
2da50a3d4e9f Adjust font rendering
David Douard <david.douard@sdf3.org>
parents: 26
diff changeset
345 w = zeichen[0]; // width of actual char
2da50a3d4e9f Adjust font rendering
David Douard <david.douard@sdf3.org>
parents: 26
diff changeset
346
5
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
347 if((fontprop) && (w<fonthor))
45
2da50a3d4e9f Adjust font rendering
David Douard <david.douard@sdf3.org>
parents: 26
diff changeset
348 w = (w*fontzoomhor) + 1;
5
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
349 else
45
2da50a3d4e9f Adjust font rendering
David Douard <david.douard@sdf3.org>
parents: 26
diff changeset
350 w = fonthor*fontzoomhor;
2da50a3d4e9f Adjust font rendering
David Douard <david.douard@sdf3.org>
parents: 26
diff changeset
351 if (move_location)
2da50a3d4e9f Adjust font rendering
David Douard <david.douard@sdf3.org>
parents: 26
diff changeset
352 char_x += w;
2da50a3d4e9f Adjust font rendering
David Douard <david.douard@sdf3.org>
parents: 26
diff changeset
353 return w;
5
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
354 }
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
355
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
356 void GraphicsDisplay::Bitmap_BW(Bitmap_s bm, int x, int y)
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
357 {
66
48f29a1d43d6 Clean several compilation warnings
David Douard <david.douard@sdfa3.org>
parents: 58
diff changeset
358 unsigned int h,v,b;
5
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
359 // int cropX;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
360 char d;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
361 if(x<0) x=0;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
362 if(y<0) y=0;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
363 int cropX = (x+bm.xSize)-oriented_width;
26
86f099bda525 Several stuff
David Douard <david.douard@sdfa3.org>
parents: 5
diff changeset
364 if(cropX<0) cropX=0;
5
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
365 window(x, y, bm.xSize-cropX, bm.ySize);
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
366 for(v=0; v < bm.ySize; v++) { // lines
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
367 if((v + y) >= oriented_height) break; // no need to crop Y
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
368 for(h=0; h < bm.xSize; h++) { // pixel
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
369 if((h + x) >= oriented_width) break;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
370 d = bm.data[bm.Byte_in_Line * v + ((h & 0xF8) >> 3)];
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
371 b = 0x80 >> (h & 0x07);
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
372 if((d & b) == 0) {
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
373 window_pushpixel(_background);
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
374 } else {
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
375 window_pushpixel(_foreground);
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
376 }
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
377 }
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
378 }
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
379 if(auto_up) copy_to_lcd();
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
380 }
66
48f29a1d43d6 Clean several compilation warnings
David Douard <david.douard@sdfa3.org>
parents: 58
diff changeset
381 void GraphicsDisplay::Bitmap(unsigned int x, unsigned int y, unsigned int w, unsigned int h,unsigned char *bitmap)
5
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
382 {
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
383 int j;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
384 unsigned char padd;
26
86f099bda525 Several stuff
David Douard <david.douard@sdfa3.org>
parents: 5
diff changeset
385 unsigned short *bitmap_ptr = (unsigned short *)bitmap;
5
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
386
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
387 padd = w%2; // the lines are padded to multiple of 4 bytes in a bitmap
66
48f29a1d43d6 Clean several compilation warnings
David Douard <david.douard@sdfa3.org>
parents: 58
diff changeset
388 if(x >= oriented_width) return;
48f29a1d43d6 Clean several compilation warnings
David Douard <david.douard@sdfa3.org>
parents: 58
diff changeset
389 if(y >= oriented_height) return;
5
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
390 int cropX = (x+w)-oriented_width;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
391 if(cropX<0) cropX=0;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
392 int cropY = (y+h)-oriented_height;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
393 if(cropY<0) cropY=0;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
394 window(x, y, w-cropX, h-cropY);
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
395 bitmap_ptr += ((h - 1)* (w + padd)); // begin of last line in array (first line of image)(standard bmp scan direction is left->right bottom->top)
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
396 for (j = 0; j < h-cropY; j++) { //Lines
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
397 window_pushpixelbuf(bitmap_ptr, w-cropX);
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
398 bitmap_ptr -= w+padd;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
399 }
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
400 if(auto_up) copy_to_lcd();
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
401 }
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
402
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
403 // local filesystem is not implemented in kinetis board , but you can add a SD card
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
404 // fixme this whole functions needs testing and speedup
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
405 int GraphicsDisplay::BMP_16(int x, int y, const char *Name_BMP)
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
406 {
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
407
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
408 #define OffsetPixelWidth 18
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
409 #define OffsetPixelHeigh 22
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
410 #define OffsetFileSize 34
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
411 #define OffsetPixData 10
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
412 #define OffsetBPP 28
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
413
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
414 char filename[50];
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
415 unsigned char BMP_Header[54];
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
416 unsigned short BPP_t;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
417 unsigned int PixelWidth,PixelHeigh,start_data;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
418 unsigned int i,off;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
419 int padd,j;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
420 unsigned short *line;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
421
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
422 // get the filename
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
423 i=0;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
424 while (*Name_BMP!='\0') {
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
425 filename[i++]=*Name_BMP++;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
426 }
26
86f099bda525 Several stuff
David Douard <david.douard@sdfa3.org>
parents: 5
diff changeset
427 filename[i] = 0;
86f099bda525 Several stuff
David Douard <david.douard@sdfa3.org>
parents: 5
diff changeset
428
5
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
429 FILE *Image = fopen((const char *)&filename[0], "rb"); // open the bmp file
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
430 if (!Image) {
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
431 return(0); // error file not found !
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
432 }
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
433
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
434 fread(&BMP_Header[0],1,54,Image); // get the BMP Header
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
435
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
436 if (BMP_Header[0] != 0x42 || BMP_Header[1] != 0x4D) { // check magic byte
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
437 fclose(Image);
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
438 return(-1); // error no BMP file
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
439 }
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
440
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
441 BPP_t = BMP_Header[OffsetBPP] + (BMP_Header[OffsetBPP + 1] << 8);
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
442 if (BPP_t != 0x0010) {
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
443 fclose(Image);
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
444 return(-2); // error no 16 bit BMP
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
445 }
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
446
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
447 PixelHeigh = BMP_Header[OffsetPixelHeigh] + (BMP_Header[OffsetPixelHeigh + 1] << 8) + (BMP_Header[OffsetPixelHeigh + 2] << 16) + (BMP_Header[OffsetPixelHeigh + 3] << 24);
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
448 PixelWidth = BMP_Header[OffsetPixelWidth] + (BMP_Header[OffsetPixelWidth + 1] << 8) + (BMP_Header[OffsetPixelWidth + 2] << 16) + (BMP_Header[OffsetPixelWidth + 3] << 24);
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
449 if (PixelHeigh > oriented_height + y || PixelWidth > oriented_width + x) {
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
450 fclose(Image);
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
451 return(-3); // to big
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
452 }
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
453
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
454 start_data = BMP_Header[OffsetPixData] + (BMP_Header[OffsetPixData + 1] << 8) + (BMP_Header[OffsetPixData + 2] << 16) + (BMP_Header[OffsetPixData + 3] << 24);
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
455
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
456 line = (unsigned short *) malloc (2 * PixelWidth); // we need a buffer for a line
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
457 if (line == NULL) {
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
458 return(-4); // error no memory
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
459 }
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
460
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
461 // the bmp lines are padded to multiple of 4 bytes
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
462 padd = -1;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
463 do {
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
464 padd ++;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
465 } while ((PixelWidth * 2 + padd)%4 != 0);
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
466
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
467 window(x, y,PixelWidth ,PixelHeigh);
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
468 // wr_cmd(0x2C); // send pixel
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
469 for (j = PixelHeigh - 1; j >= 0; j--) { //Lines bottom up
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
470 off = j * (PixelWidth * 2 + padd) + start_data; // start of line
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
471 fseek(Image, off ,SEEK_SET);
26
86f099bda525 Several stuff
David Douard <david.douard@sdfa3.org>
parents: 5
diff changeset
472 fread(line,1,PixelWidth * 2,Image); // read a line - slow
5
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
473 /* for (i = 0; i < PixelWidth; i++)
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
474 { // copy pixel data to TFT
26
86f099bda525 Several stuff
David Douard <david.douard@sdfa3.org>
parents: 5
diff changeset
475 // wr_16(line[i]); // one 16 bit pixel
5
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
476 window_pushpixel(line[i]);
26
86f099bda525 Several stuff
David Douard <david.douard@sdfa3.org>
parents: 5
diff changeset
477
5
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
478 } */
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
479 window_pushpixelbuf(line, PixelWidth);
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
480 }
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
481 free (line);
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
482 fclose(Image);
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
483 if(auto_up) copy_to_lcd();
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
484 return(1);
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
485 }
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
486
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
487 void GraphicsDisplay::cls (void)
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
488 {
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
489 unsigned int pixels = ( oriented_width * oriented_height);
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
490 WindowMax();
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
491 for (unsigned int i = 0; i < pixels; i++)
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
492 {
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
493 window_pushpixel(_background);
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
494 }
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
495 }
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
496 void GraphicsDisplay::set_auto_up(bool up)
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
497 {
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
498 if(up) auto_up = true;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
499 else auto_up = false;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
500 }
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
501 bool GraphicsDisplay::get_auto_up(void)
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
502 {
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
503 return (auto_up);
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
504 }

mercurial