iforce2d Chris / Mbed 2 deprecated ubxDistanceMeter

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers u8g_scale.c Source File

u8g_scale.c

00001 /*
00002 
00003   u8g_scale.c
00004 
00005   Universal 8bit Graphics Library
00006   
00007   Copyright (c) 2012, olikraus@gmail.com
00008   All rights reserved.
00009 
00010   Redistribution and use in source and binary forms, with or without modification, 
00011   are permitted provided that the following conditions are met:
00012 
00013   * Redistributions of source code must retain the above copyright notice, this list 
00014     of conditions and the following disclaimer.
00015     
00016   * Redistributions in binary form must reproduce the above copyright notice, this 
00017     list of conditions and the following disclaimer in the documentation and/or other 
00018     materials provided with the distribution.
00019 
00020   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
00021   CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 
00022   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
00023   MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
00024   DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 
00025   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
00026   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
00027   NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
00028   LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
00029   CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
00030   STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
00031   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 
00032   ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  
00033 
00034   Scale screen by some constant factors. Usefull for making bigger fonts wiht less
00035   memory consumption
00036     
00037 */
00038 
00039 #include "u8g.h"
00040 
00041 uint8_t u8g_dev_scale_2x2_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg);
00042 
00043 
00044 u8g_dev_t u8g_dev_scale = { u8g_dev_scale_2x2_fn, NULL, NULL };
00045 
00046 void u8g_UndoScale(u8g_t *u8g)
00047 {
00048   if ( u8g->dev != &u8g_dev_scale )
00049     return;
00050   u8g->dev = u8g_dev_scale.dev_mem;
00051   u8g_UpdateDimension(u8g);
00052 }
00053 
00054 void u8g_SetScale2x2(u8g_t *u8g)
00055 {
00056   if ( u8g->dev != &u8g_dev_scale )
00057   {
00058     u8g_dev_scale.dev_mem = u8g->dev;
00059     u8g->dev = &u8g_dev_scale;
00060   }
00061   u8g_dev_scale.dev_fn = u8g_dev_scale_2x2_fn;
00062   u8g_UpdateDimension(u8g);
00063 }
00064 
00065 
00066 uint8_t u8g_dev_scale_2x2_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
00067 {
00068   u8g_dev_t *chain = (u8g_dev_t *)(dev->dev_mem);
00069   uint8_t pixel;
00070   uint16_t scaled_pixel;
00071   uint8_t i;
00072   uint8_t dir;
00073   u8g_uint_t x, y, xx,yy;
00074   
00075   switch(msg)
00076   {
00077     default:
00078       return u8g_call_dev_fn(u8g, chain, msg, arg);
00079     case U8G_DEV_MSG_GET_WIDTH:
00080       *((u8g_uint_t *)arg) = u8g_GetWidthLL(u8g, chain) / 2;
00081       break;
00082     case U8G_DEV_MSG_GET_HEIGHT:
00083       *((u8g_uint_t *)arg) = u8g_GetHeightLL(u8g, chain) / 2;
00084       break;
00085     case U8G_DEV_MSG_GET_PAGE_BOX:
00086       /* get page size from next device in the chain */
00087       u8g_call_dev_fn(u8g, chain, msg, arg);
00088       ((u8g_box_t *)arg)->x0 /= 2;
00089       ((u8g_box_t *)arg)->x1 /= 2;
00090       ((u8g_box_t *)arg)->y0 /= 2;
00091       ((u8g_box_t *)arg)->y1 /= 2;
00092       return 1;
00093     case U8G_DEV_MSG_SET_PIXEL:
00094       x = ((u8g_dev_arg_pixel_t *)arg)->x;
00095       x *= 2;
00096       y = ((u8g_dev_arg_pixel_t *)arg)->y;
00097       y *= 2;
00098       ((u8g_dev_arg_pixel_t *)arg)->x = x;
00099       ((u8g_dev_arg_pixel_t *)arg)->y = y;
00100       u8g_call_dev_fn(u8g, chain, msg, arg);
00101       x++;
00102       ((u8g_dev_arg_pixel_t *)arg)->x = x;
00103       ((u8g_dev_arg_pixel_t *)arg)->y = y;
00104       u8g_call_dev_fn(u8g, chain, msg, arg);
00105       y++;
00106       ((u8g_dev_arg_pixel_t *)arg)->x = x;
00107       ((u8g_dev_arg_pixel_t *)arg)->y = y;
00108       u8g_call_dev_fn(u8g, chain, msg, arg);
00109       x--;
00110       ((u8g_dev_arg_pixel_t *)arg)->x = x;
00111       ((u8g_dev_arg_pixel_t *)arg)->y = y;
00112       u8g_call_dev_fn(u8g, chain, msg, arg);    
00113       break;
00114     case U8G_DEV_MSG_SET_8PIXEL:
00115       pixel = ((u8g_dev_arg_pixel_t *)arg)->pixel;
00116       dir = ((u8g_dev_arg_pixel_t *)arg)->dir;
00117       scaled_pixel = 0;
00118       for( i = 0; i < 8; i++ )
00119       {
00120     scaled_pixel<<=2;
00121     if ( pixel & 128 )
00122     {
00123       scaled_pixel |= 3;
00124     }
00125     pixel<<=1;
00126       }
00127       x = ((u8g_dev_arg_pixel_t *)arg)->x;
00128       x *= 2;
00129       xx = x;
00130       y = ((u8g_dev_arg_pixel_t *)arg)->y;
00131       y *= 2;
00132       yy = y;
00133       if ( ((u8g_dev_arg_pixel_t *)arg)->dir & 1 )
00134       {
00135     xx++;
00136       }
00137       else
00138       {
00139     yy++;
00140       }
00141       
00142       ((u8g_dev_arg_pixel_t *)arg)->pixel = scaled_pixel>>8;      
00143       ((u8g_dev_arg_pixel_t *)arg)->x = x;
00144       ((u8g_dev_arg_pixel_t *)arg)->y = y;
00145       ((u8g_dev_arg_pixel_t *)arg)->dir = dir;
00146       u8g_call_dev_fn(u8g, chain, msg, arg);    
00147 
00148       
00149       ((u8g_dev_arg_pixel_t *)arg)->x = xx;
00150       ((u8g_dev_arg_pixel_t *)arg)->y = yy;
00151       ((u8g_dev_arg_pixel_t *)arg)->dir = dir;
00152       u8g_call_dev_fn(u8g, chain, msg, arg);    
00153       
00154       ((u8g_dev_arg_pixel_t *)arg)->pixel = scaled_pixel&255;
00155       //((u8g_dev_arg_pixel_t *)arg)->pixel = 0x00;
00156       switch(dir)
00157       {
00158     case 0:
00159       x+=8;
00160       xx+=8;
00161       break;
00162     case 1:
00163       y+=8;
00164       yy+=8;
00165       break;
00166     case 2:
00167       x-=8;
00168       xx-=8;
00169       break;
00170     case 3:
00171       y-=8;
00172       yy-=8;
00173       break;
00174       }
00175       ((u8g_dev_arg_pixel_t *)arg)->x = x;
00176       ((u8g_dev_arg_pixel_t *)arg)->y = y;
00177       ((u8g_dev_arg_pixel_t *)arg)->dir = dir;
00178       u8g_call_dev_fn(u8g, chain, msg, arg);    
00179       
00180       ((u8g_dev_arg_pixel_t *)arg)->x = xx;
00181       ((u8g_dev_arg_pixel_t *)arg)->y = yy;
00182       ((u8g_dev_arg_pixel_t *)arg)->dir = dir;
00183       u8g_call_dev_fn(u8g, chain, msg, arg);    
00184       break;
00185   }
00186   return 1;
00187 }
00188 
00189