| 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 | */ |
| 61 | void u8g2_DrawFrame(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t w, u8g2_uint_t h) |
| 62 | { |
| 63 | u8g2_uint_t xtmp = x; |
| 64 | |
| 65 | #ifdef U8G2_WITH_INTERSECTION |
| 66 | if ( u8g2_IsIntersection(u8g2, x, y, x+w, y+h) == 0 ) |
| 67 | return; |
| 68 | #endif /* U8G2_WITH_INTERSECTION */ |
| 69 | |
| 70 | u8g2_DrawHVLine(u8g2, x, y, w, 0); |
| 71 | if (h >= 2) { |
| 72 | h-=2; |
| 73 | y++; |
| 74 | if (h > 0) { |
| 75 | u8g2_DrawHVLine(u8g2, x, y, h, 1); |
| 76 | x+=w; |
| 77 | x--; |
| 78 | u8g2_DrawHVLine(u8g2, x, y, h, 1); |
| 79 | y+=h; |
| 80 | } |
| 81 | u8g2_DrawHVLine(u8g2, xtmp, y, w, 0); |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | |
| 86 | |
| 87 | |
| 88 | 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) |
| 89 | { |
| 90 | u8g2_uint_t xl, yu; |
| 91 | u8g2_uint_t yl, xr; |
| 92 | |
| 93 | #ifdef U8G2_WITH_INTERSECTION |
| 94 | if ( u8g2_IsIntersection(u8g2, x, y, x+w, y+h) == 0 ) |
| 95 | return; |
| 96 | #endif /* U8G2_WITH_INTERSECTION */ |
| 97 | |
| 98 | xl = x; |
| 99 | xl += r; |
| 100 | yu = y; |
| 101 | yu += r; |
| 102 | |
| 103 | xr = x; |
| 104 | xr += w; |
| 105 | xr -= r; |
| 106 | xr -= 1; |
| 107 | |
| 108 | yl = y; |
| 109 | yl += h; |
| 110 | yl -= r; |
| 111 | yl -= 1; |
| 112 | |
| 113 | u8g2_DrawDisc(u8g2, xl, yu, r, U8G2_DRAW_UPPER_LEFT); |
| 114 | u8g2_DrawDisc(u8g2, xr, yu, r, U8G2_DRAW_UPPER_RIGHT); |
| 115 | u8g2_DrawDisc(u8g2, xl, yl, r, U8G2_DRAW_LOWER_LEFT); |
| 116 | u8g2_DrawDisc(u8g2, xr, yl, r, U8G2_DRAW_LOWER_RIGHT); |
| 117 | |
| 118 | { |
| 119 | u8g2_uint_t ww, hh; |
| 120 | |
| 121 | ww = w; |
| 122 | ww -= r; |
| 123 | ww -= r; |
| 124 | xl++; |
| 125 | yu++; |
| 126 | |
| 127 | if ( ww >= 3 ) |
| 128 | { |
| 129 | ww -= 2; |
| 130 | u8g2_DrawBox(u8g2, xl, y, ww, r+1); |
| 131 | u8g2_DrawBox(u8g2, xl, yl, ww, r+1); |
| 132 | } |
| 133 | |
| 134 | hh = h; |
| 135 | hh -= r; |
| 136 | hh -= r; |
| 137 | //h--; |
| 138 | if ( hh >= 3 ) |
| 139 | { |
| 140 | hh -= 2; |
| 141 | u8g2_DrawBox(u8g2, x, yu, w, hh); |
| 142 | } |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | |
| 147 | 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) |
| 148 | { |
| 149 | u8g2_uint_t xl, yu; |
| 150 | |
| 151 | #ifdef U8G2_WITH_INTERSECTION |
| 152 | if ( u8g2_IsIntersection(u8g2, x, y, x+w, y+h) == 0 ) |
| 153 | return; |
| 154 | #endif /* U8G2_WITH_INTERSECTION */ |
| 155 | |
| 156 | xl = x; |
| 157 | xl += r; |
| 158 | yu = y; |
| 159 | yu += r; |
| 160 | |
| 161 | { |
| 162 | u8g2_uint_t yl, xr; |
| 163 | |
| 164 | xr = x; |
| 165 | xr += w; |
| 166 | xr -= r; |
| 167 | xr -= 1; |
| 168 | |
| 169 | yl = y; |
| 170 | yl += h; |
| 171 | yl -= r; |
| 172 | yl -= 1; |
| 173 | |
| 174 | u8g2_DrawCircle(u8g2, xl, yu, r, U8G2_DRAW_UPPER_LEFT); |
| 175 | u8g2_DrawCircle(u8g2, xr, yu, r, U8G2_DRAW_UPPER_RIGHT); |
| 176 | u8g2_DrawCircle(u8g2, xl, yl, r, U8G2_DRAW_LOWER_LEFT); |
| 177 | u8g2_DrawCircle(u8g2, xr, yl, r, U8G2_DRAW_LOWER_RIGHT); |
| 178 | } |
| 179 | |
| 180 | { |
| 181 | u8g2_uint_t ww, hh; |
| 182 | |
| 183 | ww = w; |
| 184 | ww -= r; |
| 185 | ww -= r; |
| 186 | hh = h; |
| 187 | hh -= r; |
| 188 | hh -= r; |
| 189 | |
| 190 | xl++; |
| 191 | yu++; |
| 192 | |
| 193 | if ( ww >= 3 ) |
| 194 | { |
| 195 | ww -= 2; |
| 196 | h--; |
| 197 | u8g2_DrawHLine(u8g2, xl, y, ww); |
| 198 | u8g2_DrawHLine(u8g2, xl, y+h, ww); |
| 199 | } |
| 200 | |
| 201 | if ( hh >= 3 ) |
| 202 | { |
| 203 | hh -= 2; |
| 204 | w--; |
| 205 | u8g2_DrawVLine(u8g2, x, yu, hh); |
| 206 | u8g2_DrawVLine(u8g2, x+w, yu, hh); |
| 207 | } |
| 208 | } |
| 209 | } |
| 210 | |