components/u8g2/csrc/u8g2_box.c

changeset 0
88d965579617
equal deleted inserted replaced
-1:000000000000 0:88d965579617
1 /*
2
3 u8g2_box.c
4
5 Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
6
7 Copyright (c) 2016, olikraus@gmail.com
8 All rights reserved.
9
10 Redistribution and use in source and binary forms, with or without modification,
11 are permitted provided that the following conditions are met:
12
13 * Redistributions of source code must retain the above copyright notice, this list
14 of conditions and the following disclaimer.
15
16 * Redistributions in binary form must reproduce the above copyright notice, this
17 list of conditions and the following disclaimer in the documentation and/or other
18 materials provided with the distribution.
19
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
21 CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
22 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
25 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
30 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
32 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33
34 */
35
36 #include "u8g2.h"
37
38 /*
39 draw a filled box
40 restriction: does not work for w = 0 or h = 0
41 */
42 void u8g2_DrawBox(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t w, u8g2_uint_t h)
43 {
44 #ifdef U8G2_WITH_INTERSECTION
45 if ( u8g2_IsIntersection(u8g2, x, y, x+w, y+h) == 0 )
46 return;
47 #endif /* U8G2_WITH_INTERSECTION */
48 while( h != 0 )
49 {
50 u8g2_DrawHVLine(u8g2, x, y, w, 0);
51 y++;
52 h--;
53 }
54 }
55
56
57 /*
58 draw a frame (empty box)
59 restriction: does not work for w = 0 or h = 0
60 ToDo:
61 pixel in the corners are drawn twice. This could be optimized.
62 */
63 void u8g2_DrawFrame(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t w, u8g2_uint_t h)
64 {
65 u8g2_uint_t xtmp = x;
66
67 #ifdef U8G2_WITH_INTERSECTION
68 if ( u8g2_IsIntersection(u8g2, x, y, x+w, y+h) == 0 )
69 return;
70 #endif /* U8G2_WITH_INTERSECTION */
71
72 u8g2_DrawHVLine(u8g2, x, y, w, 0);
73 u8g2_DrawHVLine(u8g2, x, y, h, 1);
74 x+=w;
75 x--;
76 u8g2_DrawHVLine(u8g2, x, y, h, 1);
77 y+=h;
78 y--;
79 u8g2_DrawHVLine(u8g2, xtmp, y, w, 0);
80 }
81
82
83
84
85 void u8g2_DrawRBox(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t w, u8g2_uint_t h, u8g2_uint_t r)
86 {
87 u8g2_uint_t xl, yu;
88 u8g2_uint_t yl, xr;
89
90 #ifdef U8G2_WITH_INTERSECTION
91 if ( u8g2_IsIntersection(u8g2, x, y, x+w, y+h) == 0 )
92 return;
93 #endif /* U8G2_WITH_INTERSECTION */
94
95 xl = x;
96 xl += r;
97 yu = y;
98 yu += r;
99
100 xr = x;
101 xr += w;
102 xr -= r;
103 xr -= 1;
104
105 yl = y;
106 yl += h;
107 yl -= r;
108 yl -= 1;
109
110 u8g2_DrawDisc(u8g2, xl, yu, r, U8G2_DRAW_UPPER_LEFT);
111 u8g2_DrawDisc(u8g2, xr, yu, r, U8G2_DRAW_UPPER_RIGHT);
112 u8g2_DrawDisc(u8g2, xl, yl, r, U8G2_DRAW_LOWER_LEFT);
113 u8g2_DrawDisc(u8g2, xr, yl, r, U8G2_DRAW_LOWER_RIGHT);
114
115 {
116 u8g2_uint_t ww, hh;
117
118 ww = w;
119 ww -= r;
120 ww -= r;
121 xl++;
122 yu++;
123
124 if ( ww >= 3 )
125 {
126 ww -= 2;
127 u8g2_DrawBox(u8g2, xl, y, ww, r+1);
128 u8g2_DrawBox(u8g2, xl, yl, ww, r+1);
129 }
130
131 hh = h;
132 hh -= r;
133 hh -= r;
134 //h--;
135 if ( hh >= 3 )
136 {
137 hh -= 2;
138 u8g2_DrawBox(u8g2, x, yu, w, hh);
139 }
140 }
141 }
142
143
144 void u8g2_DrawRFrame(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t w, u8g2_uint_t h, u8g2_uint_t r)
145 {
146 u8g2_uint_t xl, yu;
147
148 #ifdef U8G2_WITH_INTERSECTION
149 if ( u8g2_IsIntersection(u8g2, x, y, x+w, y+h) == 0 )
150 return;
151 #endif /* U8G2_WITH_INTERSECTION */
152
153 xl = x;
154 xl += r;
155 yu = y;
156 yu += r;
157
158 {
159 u8g2_uint_t yl, xr;
160
161 xr = x;
162 xr += w;
163 xr -= r;
164 xr -= 1;
165
166 yl = y;
167 yl += h;
168 yl -= r;
169 yl -= 1;
170
171 u8g2_DrawCircle(u8g2, xl, yu, r, U8G2_DRAW_UPPER_LEFT);
172 u8g2_DrawCircle(u8g2, xr, yu, r, U8G2_DRAW_UPPER_RIGHT);
173 u8g2_DrawCircle(u8g2, xl, yl, r, U8G2_DRAW_LOWER_LEFT);
174 u8g2_DrawCircle(u8g2, xr, yl, r, U8G2_DRAW_LOWER_RIGHT);
175 }
176
177 {
178 u8g2_uint_t ww, hh;
179
180 ww = w;
181 ww -= r;
182 ww -= r;
183 hh = h;
184 hh -= r;
185 hh -= r;
186
187 xl++;
188 yu++;
189
190 if ( ww >= 3 )
191 {
192 ww -= 2;
193 h--;
194 u8g2_DrawHLine(u8g2, xl, y, ww);
195 u8g2_DrawHLine(u8g2, xl, y+h, ww);
196 }
197
198 if ( hh >= 3 )
199 {
200 hh -= 2;
201 w--;
202 u8g2_DrawVLine(u8g2, x, yu, hh);
203 u8g2_DrawVLine(u8g2, x+w, yu, hh);
204 }
205 }
206 }
207

mercurial