iforce2d Chris / Mbed 2 deprecated ubxDistanceMeter

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers u8g_rect.c Source File

u8g_rect.c

00001 /*
00002 
00003   u8g_rect.c
00004   
00005   U8G high level interface for horizontal and vertical things
00006 
00007   Universal 8bit Graphics Library
00008   
00009   Copyright (c) 2011, olikraus@gmail.com
00010   All rights reserved.
00011 
00012   Redistribution and use in source and binary forms, with or without modification, 
00013   are permitted provided that the following conditions are met:
00014 
00015   * Redistributions of source code must retain the above copyright notice, this list 
00016     of conditions and the following disclaimer.
00017     
00018   * Redistributions in binary form must reproduce the above copyright notice, this 
00019     list of conditions and the following disclaimer in the documentation and/or other 
00020     materials provided with the distribution.
00021 
00022   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
00023   CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 
00024   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
00025   MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
00026   DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 
00027   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
00028   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
00029   NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
00030   LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
00031   CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
00032   STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
00033   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 
00034   ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  
00035   
00036   
00037 */
00038 
00039 #include "u8g.h"
00040 
00041 void u8g_draw_hline(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w)
00042 {
00043   uint8_t pixel = 0x0ff;
00044   while( w >= 8 )
00045   {
00046     u8g_Draw8Pixel(u8g, x, y, 0, pixel);
00047     w-=8;
00048     x+=8;
00049   }
00050   if ( w != 0 )
00051   {
00052     w ^=7;
00053     w++;
00054     pixel <<= w&7;
00055     u8g_Draw8Pixel(u8g, x, y, 0, pixel);
00056   }
00057 }
00058 
00059 void u8g_draw_vline(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t h)
00060 {
00061   uint8_t pixel = 0x0ff;
00062   while( h >= 8 )
00063   {
00064     u8g_Draw8Pixel(u8g, x, y, 1, pixel);
00065     h-=8;
00066     y+=8;
00067   }
00068   if ( h != 0 )
00069   {
00070     h ^=7;
00071     h++;
00072     pixel <<= h&7;
00073     u8g_Draw8Pixel(u8g, x, y, 1, pixel);
00074   }
00075 }
00076 
00077 void u8g_DrawHLine(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w)
00078 {
00079   if ( u8g_IsBBXIntersection(u8g, x, y, w, 1) == 0 )
00080     return;
00081   u8g_draw_hline(u8g, x, y, w);
00082 }
00083 
00084 void u8g_DrawVLine(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w)
00085 {
00086   if ( u8g_IsBBXIntersection(u8g, x, y, 1, w) == 0 )
00087     return;
00088   u8g_draw_vline(u8g, x, y, w);
00089 }
00090 
00091 /* restrictions: w > 0 && h > 0 */
00092 void u8g_DrawFrame(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w, u8g_uint_t h)
00093 {
00094   u8g_uint_t xtmp = x;
00095   
00096   if ( u8g_IsBBXIntersection(u8g, x, y, w, h) == 0 )
00097     return;
00098 
00099   
00100   u8g_draw_hline(u8g, x, y, w);
00101   u8g_draw_vline(u8g, x, y, h);
00102   x+=w;
00103   x--;
00104   u8g_draw_vline(u8g, x, y, h);
00105   y+=h;
00106   y--;
00107   u8g_draw_hline(u8g, xtmp, y, w);
00108 }
00109 
00110 void u8g_draw_box(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w, u8g_uint_t h)
00111 {
00112   do
00113   { 
00114     u8g_draw_hline(u8g, x, y, w);
00115     y++;    
00116     h--;
00117   } while( h != 0 );
00118 }
00119 
00120 /* restrictions: h > 0 */
00121 void u8g_DrawBox(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w, u8g_uint_t h)
00122 {
00123   if ( u8g_IsBBXIntersection(u8g, x, y, w, h) == 0 )
00124     return;
00125   u8g_draw_box(u8g, x, y, w, h);
00126 }
00127 
00128 
00129 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)
00130 {
00131   u8g_uint_t xl, yu;
00132 
00133   if ( u8g_IsBBXIntersection(u8g, x, y, w, h) == 0 )
00134     return;
00135 
00136   xl = x;
00137   xl += r;
00138   yu = y;
00139   yu += r;
00140  
00141   {
00142     u8g_uint_t yl, xr;
00143       
00144     xr = x;
00145     xr += w;
00146     xr -= r;
00147     xr -= 1;
00148     
00149     yl = y;
00150     yl += h;
00151     yl -= r; 
00152     yl -= 1;
00153 
00154     u8g_draw_circle(u8g, xl, yu, r, U8G_DRAW_UPPER_LEFT);
00155     u8g_draw_circle(u8g, xr, yu, r, U8G_DRAW_UPPER_RIGHT);
00156     u8g_draw_circle(u8g, xl, yl, r, U8G_DRAW_LOWER_LEFT);
00157     u8g_draw_circle(u8g, xr, yl, r, U8G_DRAW_LOWER_RIGHT);
00158   }
00159 
00160   {
00161     u8g_uint_t ww, hh;
00162 
00163     ww = w;
00164     ww -= r;
00165     ww -= r;
00166     ww -= 2;
00167     hh = h;
00168     hh -= r;
00169     hh -= r;
00170     hh -= 2;
00171     
00172     xl++;
00173     yu++;
00174     h--;
00175     w--;
00176     u8g_draw_hline(u8g, xl, y, ww);
00177     u8g_draw_hline(u8g, xl, y+h, ww);
00178     u8g_draw_vline(u8g, x,         yu, hh);
00179     u8g_draw_vline(u8g, x+w, yu, hh);
00180   }
00181 }
00182 
00183 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)
00184 {
00185   u8g_uint_t xl, yu;
00186     u8g_uint_t yl, xr;
00187 
00188   if ( u8g_IsBBXIntersection(u8g, x, y, w, h) == 0 )
00189     return;
00190 
00191   xl = x;
00192   xl += r;
00193   yu = y;
00194   yu += r;
00195  
00196   xr = x;
00197   xr += w;
00198   xr -= r;
00199   xr -= 1;
00200   
00201   yl = y;
00202   yl += h;
00203   yl -= r; 
00204   yl -= 1;
00205 
00206   u8g_draw_disc(u8g, xl, yu, r, U8G_DRAW_UPPER_LEFT);
00207   u8g_draw_disc(u8g, xr, yu, r, U8G_DRAW_UPPER_RIGHT);
00208   u8g_draw_disc(u8g, xl, yl, r, U8G_DRAW_LOWER_LEFT);
00209   u8g_draw_disc(u8g, xr, yl, r, U8G_DRAW_LOWER_RIGHT);
00210 
00211   {
00212     u8g_uint_t ww, hh;
00213 
00214     ww = w;
00215     ww -= r;
00216     ww -= r;
00217     ww -= 2;
00218     hh = h;
00219     hh -= r;
00220     hh -= r;
00221     hh -= 2;
00222     
00223     xl++;
00224     yu++;
00225     h--;
00226     u8g_draw_box(u8g, xl, y, ww, r+1);
00227     u8g_draw_box(u8g, xl, yl, ww, r+1);
00228     //u8g_draw_hline(u8g, xl, y+h, ww);
00229     u8g_draw_box(u8g, x, yu, w, hh);
00230     //u8g_draw_vline(u8g, x+w, yu, hh);
00231   }
00232 }
00233