hadif azli / Mbed 2 deprecated TEST123

Dependencies:   mbed Blynk

Committer:
lixianyu
Date:
Mon Jun 13 02:21:11 2016 +0000
Revision:
1:0e75de2a5d21
Parent:
0:d8f4c441e032
u8glib???????????????????????????Adafruit_GFX????OLED????????bitmap??????

Who changed what in which revision?

UserRevisionLine numberNew contents of line
lixianyu 0:d8f4c441e032 1 /*
lixianyu 0:d8f4c441e032 2
lixianyu 0:d8f4c441e032 3 u8g_rect.c
lixianyu 0:d8f4c441e032 4
lixianyu 0:d8f4c441e032 5 U8G high level interface for horizontal and vertical things
lixianyu 0:d8f4c441e032 6
lixianyu 0:d8f4c441e032 7 Universal 8bit Graphics Library
lixianyu 0:d8f4c441e032 8
lixianyu 0:d8f4c441e032 9 Copyright (c) 2011, olikraus@gmail.com
lixianyu 0:d8f4c441e032 10 All rights reserved.
lixianyu 0:d8f4c441e032 11
lixianyu 0:d8f4c441e032 12 Redistribution and use in source and binary forms, with or without modification,
lixianyu 0:d8f4c441e032 13 are permitted provided that the following conditions are met:
lixianyu 0:d8f4c441e032 14
lixianyu 0:d8f4c441e032 15 * Redistributions of source code must retain the above copyright notice, this list
lixianyu 0:d8f4c441e032 16 of conditions and the following disclaimer.
lixianyu 0:d8f4c441e032 17
lixianyu 0:d8f4c441e032 18 * Redistributions in binary form must reproduce the above copyright notice, this
lixianyu 0:d8f4c441e032 19 list of conditions and the following disclaimer in the documentation and/or other
lixianyu 0:d8f4c441e032 20 materials provided with the distribution.
lixianyu 0:d8f4c441e032 21
lixianyu 0:d8f4c441e032 22 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
lixianyu 0:d8f4c441e032 23 CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
lixianyu 0:d8f4c441e032 24 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
lixianyu 0:d8f4c441e032 25 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
lixianyu 0:d8f4c441e032 26 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
lixianyu 0:d8f4c441e032 27 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
lixianyu 0:d8f4c441e032 28 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
lixianyu 0:d8f4c441e032 29 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
lixianyu 0:d8f4c441e032 30 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
lixianyu 0:d8f4c441e032 31 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
lixianyu 0:d8f4c441e032 32 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
lixianyu 0:d8f4c441e032 33 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
lixianyu 0:d8f4c441e032 34 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
lixianyu 0:d8f4c441e032 35
lixianyu 0:d8f4c441e032 36
lixianyu 0:d8f4c441e032 37 */
lixianyu 0:d8f4c441e032 38
lixianyu 0:d8f4c441e032 39 #include "u8g.h"
lixianyu 0:d8f4c441e032 40
lixianyu 0:d8f4c441e032 41 void u8g_draw_hline(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w)
lixianyu 0:d8f4c441e032 42 {
lixianyu 0:d8f4c441e032 43 uint8_t pixel = 0x0ff;
lixianyu 0:d8f4c441e032 44 while( w >= 8 )
lixianyu 0:d8f4c441e032 45 {
lixianyu 0:d8f4c441e032 46 u8g_Draw8Pixel(u8g, x, y, 0, pixel);
lixianyu 0:d8f4c441e032 47 w-=8;
lixianyu 0:d8f4c441e032 48 x+=8;
lixianyu 0:d8f4c441e032 49 }
lixianyu 0:d8f4c441e032 50 if ( w != 0 )
lixianyu 0:d8f4c441e032 51 {
lixianyu 0:d8f4c441e032 52 w ^=7;
lixianyu 0:d8f4c441e032 53 w++;
lixianyu 0:d8f4c441e032 54 pixel <<= w&7;
lixianyu 0:d8f4c441e032 55 u8g_Draw8Pixel(u8g, x, y, 0, pixel);
lixianyu 0:d8f4c441e032 56 }
lixianyu 0:d8f4c441e032 57 }
lixianyu 0:d8f4c441e032 58
lixianyu 0:d8f4c441e032 59 void u8g_draw_vline(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t h)
lixianyu 0:d8f4c441e032 60 {
lixianyu 0:d8f4c441e032 61 uint8_t pixel = 0x0ff;
lixianyu 0:d8f4c441e032 62 while( h >= 8 )
lixianyu 0:d8f4c441e032 63 {
lixianyu 0:d8f4c441e032 64 u8g_Draw8Pixel(u8g, x, y, 1, pixel);
lixianyu 0:d8f4c441e032 65 h-=8;
lixianyu 0:d8f4c441e032 66 y+=8;
lixianyu 0:d8f4c441e032 67 }
lixianyu 0:d8f4c441e032 68 if ( h != 0 )
lixianyu 0:d8f4c441e032 69 {
lixianyu 0:d8f4c441e032 70 h ^=7;
lixianyu 0:d8f4c441e032 71 h++;
lixianyu 0:d8f4c441e032 72 pixel <<= h&7;
lixianyu 0:d8f4c441e032 73 u8g_Draw8Pixel(u8g, x, y, 1, pixel);
lixianyu 0:d8f4c441e032 74 }
lixianyu 0:d8f4c441e032 75 }
lixianyu 0:d8f4c441e032 76
lixianyu 0:d8f4c441e032 77 void u8g_DrawHLine(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w)
lixianyu 0:d8f4c441e032 78 {
lixianyu 0:d8f4c441e032 79 if ( u8g_IsBBXIntersection(u8g, x, y, w, 1) == 0 )
lixianyu 0:d8f4c441e032 80 return;
lixianyu 0:d8f4c441e032 81 u8g_draw_hline(u8g, x, y, w);
lixianyu 0:d8f4c441e032 82 }
lixianyu 0:d8f4c441e032 83
lixianyu 0:d8f4c441e032 84 void u8g_DrawVLine(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w)
lixianyu 0:d8f4c441e032 85 {
lixianyu 0:d8f4c441e032 86 if ( u8g_IsBBXIntersection(u8g, x, y, 1, w) == 0 )
lixianyu 0:d8f4c441e032 87 return;
lixianyu 0:d8f4c441e032 88 u8g_draw_vline(u8g, x, y, w);
lixianyu 0:d8f4c441e032 89 }
lixianyu 0:d8f4c441e032 90
lixianyu 0:d8f4c441e032 91 /* restrictions: w > 0 && h > 0 */
lixianyu 0:d8f4c441e032 92 void u8g_DrawFrame(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w, u8g_uint_t h)
lixianyu 0:d8f4c441e032 93 {
lixianyu 0:d8f4c441e032 94 u8g_uint_t xtmp = x;
lixianyu 0:d8f4c441e032 95
lixianyu 0:d8f4c441e032 96 if ( u8g_IsBBXIntersection(u8g, x, y, w, h) == 0 )
lixianyu 0:d8f4c441e032 97 return;
lixianyu 0:d8f4c441e032 98
lixianyu 0:d8f4c441e032 99
lixianyu 0:d8f4c441e032 100 u8g_draw_hline(u8g, x, y, w);
lixianyu 0:d8f4c441e032 101 u8g_draw_vline(u8g, x, y, h);
lixianyu 0:d8f4c441e032 102 x+=w;
lixianyu 0:d8f4c441e032 103 x--;
lixianyu 0:d8f4c441e032 104 u8g_draw_vline(u8g, x, y, h);
lixianyu 0:d8f4c441e032 105 y+=h;
lixianyu 0:d8f4c441e032 106 y--;
lixianyu 0:d8f4c441e032 107 u8g_draw_hline(u8g, xtmp, y, w);
lixianyu 0:d8f4c441e032 108 }
lixianyu 0:d8f4c441e032 109
lixianyu 0:d8f4c441e032 110 void u8g_draw_box(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w, u8g_uint_t h)
lixianyu 0:d8f4c441e032 111 {
lixianyu 0:d8f4c441e032 112 do
lixianyu 0:d8f4c441e032 113 {
lixianyu 0:d8f4c441e032 114 u8g_draw_hline(u8g, x, y, w);
lixianyu 0:d8f4c441e032 115 y++;
lixianyu 0:d8f4c441e032 116 h--;
lixianyu 0:d8f4c441e032 117 } while( h != 0 );
lixianyu 0:d8f4c441e032 118 }
lixianyu 0:d8f4c441e032 119
lixianyu 0:d8f4c441e032 120 /* restrictions: h > 0 */
lixianyu 0:d8f4c441e032 121 void u8g_DrawBox(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w, u8g_uint_t h)
lixianyu 0:d8f4c441e032 122 {
lixianyu 0:d8f4c441e032 123 if ( u8g_IsBBXIntersection(u8g, x, y, w, h) == 0 )
lixianyu 0:d8f4c441e032 124 return;
lixianyu 0:d8f4c441e032 125 u8g_draw_box(u8g, x, y, w, h);
lixianyu 0:d8f4c441e032 126 }
lixianyu 0:d8f4c441e032 127
lixianyu 0:d8f4c441e032 128
lixianyu 0:d8f4c441e032 129 void u8g_DrawRFrame(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w, u8g_uint_t h, u8g_uint_t r)
lixianyu 0:d8f4c441e032 130 {
lixianyu 0:d8f4c441e032 131 u8g_uint_t xl, yu;
lixianyu 0:d8f4c441e032 132
lixianyu 0:d8f4c441e032 133 if ( u8g_IsBBXIntersection(u8g, x, y, w, h) == 0 )
lixianyu 0:d8f4c441e032 134 return;
lixianyu 0:d8f4c441e032 135
lixianyu 0:d8f4c441e032 136 xl = x;
lixianyu 0:d8f4c441e032 137 xl += r;
lixianyu 0:d8f4c441e032 138 yu = y;
lixianyu 0:d8f4c441e032 139 yu += r;
lixianyu 0:d8f4c441e032 140
lixianyu 0:d8f4c441e032 141 {
lixianyu 0:d8f4c441e032 142 u8g_uint_t yl, xr;
lixianyu 0:d8f4c441e032 143
lixianyu 0:d8f4c441e032 144 xr = x;
lixianyu 0:d8f4c441e032 145 xr += w;
lixianyu 0:d8f4c441e032 146 xr -= r;
lixianyu 0:d8f4c441e032 147 xr -= 1;
lixianyu 0:d8f4c441e032 148
lixianyu 0:d8f4c441e032 149 yl = y;
lixianyu 0:d8f4c441e032 150 yl += h;
lixianyu 0:d8f4c441e032 151 yl -= r;
lixianyu 0:d8f4c441e032 152 yl -= 1;
lixianyu 0:d8f4c441e032 153
lixianyu 0:d8f4c441e032 154 u8g_draw_circle(u8g, xl, yu, r, U8G_DRAW_UPPER_LEFT);
lixianyu 0:d8f4c441e032 155 u8g_draw_circle(u8g, xr, yu, r, U8G_DRAW_UPPER_RIGHT);
lixianyu 0:d8f4c441e032 156 u8g_draw_circle(u8g, xl, yl, r, U8G_DRAW_LOWER_LEFT);
lixianyu 0:d8f4c441e032 157 u8g_draw_circle(u8g, xr, yl, r, U8G_DRAW_LOWER_RIGHT);
lixianyu 0:d8f4c441e032 158 }
lixianyu 0:d8f4c441e032 159
lixianyu 0:d8f4c441e032 160 {
lixianyu 0:d8f4c441e032 161 u8g_uint_t ww, hh;
lixianyu 0:d8f4c441e032 162
lixianyu 0:d8f4c441e032 163 ww = w;
lixianyu 0:d8f4c441e032 164 ww -= r;
lixianyu 0:d8f4c441e032 165 ww -= r;
lixianyu 0:d8f4c441e032 166 ww -= 2;
lixianyu 0:d8f4c441e032 167 hh = h;
lixianyu 0:d8f4c441e032 168 hh -= r;
lixianyu 0:d8f4c441e032 169 hh -= r;
lixianyu 0:d8f4c441e032 170 hh -= 2;
lixianyu 0:d8f4c441e032 171
lixianyu 0:d8f4c441e032 172 xl++;
lixianyu 0:d8f4c441e032 173 yu++;
lixianyu 0:d8f4c441e032 174 h--;
lixianyu 0:d8f4c441e032 175 w--;
lixianyu 0:d8f4c441e032 176 u8g_draw_hline(u8g, xl, y, ww);
lixianyu 0:d8f4c441e032 177 u8g_draw_hline(u8g, xl, y+h, ww);
lixianyu 0:d8f4c441e032 178 u8g_draw_vline(u8g, x, yu, hh);
lixianyu 0:d8f4c441e032 179 u8g_draw_vline(u8g, x+w, yu, hh);
lixianyu 0:d8f4c441e032 180 }
lixianyu 0:d8f4c441e032 181 }
lixianyu 0:d8f4c441e032 182
lixianyu 0:d8f4c441e032 183 void u8g_DrawRBox(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w, u8g_uint_t h, u8g_uint_t r)
lixianyu 0:d8f4c441e032 184 {
lixianyu 0:d8f4c441e032 185 u8g_uint_t xl, yu;
lixianyu 0:d8f4c441e032 186 u8g_uint_t yl, xr;
lixianyu 0:d8f4c441e032 187
lixianyu 0:d8f4c441e032 188 if ( u8g_IsBBXIntersection(u8g, x, y, w, h) == 0 )
lixianyu 0:d8f4c441e032 189 return;
lixianyu 0:d8f4c441e032 190
lixianyu 0:d8f4c441e032 191 xl = x;
lixianyu 0:d8f4c441e032 192 xl += r;
lixianyu 0:d8f4c441e032 193 yu = y;
lixianyu 0:d8f4c441e032 194 yu += r;
lixianyu 0:d8f4c441e032 195
lixianyu 0:d8f4c441e032 196 xr = x;
lixianyu 0:d8f4c441e032 197 xr += w;
lixianyu 0:d8f4c441e032 198 xr -= r;
lixianyu 0:d8f4c441e032 199 xr -= 1;
lixianyu 0:d8f4c441e032 200
lixianyu 0:d8f4c441e032 201 yl = y;
lixianyu 0:d8f4c441e032 202 yl += h;
lixianyu 0:d8f4c441e032 203 yl -= r;
lixianyu 0:d8f4c441e032 204 yl -= 1;
lixianyu 0:d8f4c441e032 205
lixianyu 0:d8f4c441e032 206 u8g_draw_disc(u8g, xl, yu, r, U8G_DRAW_UPPER_LEFT);
lixianyu 0:d8f4c441e032 207 u8g_draw_disc(u8g, xr, yu, r, U8G_DRAW_UPPER_RIGHT);
lixianyu 0:d8f4c441e032 208 u8g_draw_disc(u8g, xl, yl, r, U8G_DRAW_LOWER_LEFT);
lixianyu 0:d8f4c441e032 209 u8g_draw_disc(u8g, xr, yl, r, U8G_DRAW_LOWER_RIGHT);
lixianyu 0:d8f4c441e032 210
lixianyu 0:d8f4c441e032 211 {
lixianyu 0:d8f4c441e032 212 u8g_uint_t ww, hh;
lixianyu 0:d8f4c441e032 213
lixianyu 0:d8f4c441e032 214 ww = w;
lixianyu 0:d8f4c441e032 215 ww -= r;
lixianyu 0:d8f4c441e032 216 ww -= r;
lixianyu 0:d8f4c441e032 217 ww -= 2;
lixianyu 0:d8f4c441e032 218 hh = h;
lixianyu 0:d8f4c441e032 219 hh -= r;
lixianyu 0:d8f4c441e032 220 hh -= r;
lixianyu 0:d8f4c441e032 221 hh -= 2;
lixianyu 0:d8f4c441e032 222
lixianyu 0:d8f4c441e032 223 xl++;
lixianyu 0:d8f4c441e032 224 yu++;
lixianyu 0:d8f4c441e032 225 h--;
lixianyu 0:d8f4c441e032 226 u8g_draw_box(u8g, xl, y, ww, r+1);
lixianyu 0:d8f4c441e032 227 u8g_draw_box(u8g, xl, yl, ww, r+1);
lixianyu 0:d8f4c441e032 228 //u8g_draw_hline(u8g, xl, y+h, ww);
lixianyu 0:d8f4c441e032 229 u8g_draw_box(u8g, x, yu, w, hh);
lixianyu 0:d8f4c441e032 230 //u8g_draw_vline(u8g, x+w, yu, hh);
lixianyu 0:d8f4c441e032 231 }
lixianyu 0:d8f4c441e032 232 }
lixianyu 0:d8f4c441e032 233