iforce2d Chris / Mbed 2 deprecated ubxDistanceMeter

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers u8g_rot.c Source File

u8g_rot.c

00001 /*
00002 
00003   u8g_rot.c
00004 
00005   Universal 8bit Graphics Library
00006   
00007   Copyright (c) 2011, 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   
00035 */
00036 
00037 #include "u8g.h"
00038 
00039 uint8_t u8g_dev_rot90_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg);
00040 uint8_t u8g_dev_rot180_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg);
00041 uint8_t u8g_dev_rot270_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg);
00042 
00043 u8g_dev_t u8g_dev_rot = { u8g_dev_rot90_fn, NULL, NULL };
00044 
00045 
00046 void u8g_UndoRotation(u8g_t *u8g)
00047 {
00048   if ( u8g->dev != &u8g_dev_rot )
00049     return;
00050   u8g->dev = u8g_dev_rot.dev_mem;
00051   u8g_UpdateDimension(u8g);
00052 }
00053 
00054 void u8g_SetRot90(u8g_t *u8g)
00055 {
00056   if ( u8g->dev != &u8g_dev_rot )
00057   {
00058     u8g_dev_rot.dev_mem = u8g->dev;
00059     u8g->dev = &u8g_dev_rot;
00060   }
00061   u8g_dev_rot.dev_fn = u8g_dev_rot90_fn;
00062   u8g_UpdateDimension(u8g);
00063 }
00064 
00065 void u8g_SetRot180(u8g_t *u8g)
00066 {
00067   if ( u8g->dev != &u8g_dev_rot )
00068   {
00069     u8g_dev_rot.dev_mem = u8g->dev;
00070     u8g->dev = &u8g_dev_rot;
00071   }
00072   u8g_dev_rot.dev_fn = u8g_dev_rot180_fn;
00073   u8g_UpdateDimension(u8g);
00074 }
00075 
00076 void u8g_SetRot270(u8g_t *u8g)
00077 {
00078   if ( u8g->dev != &u8g_dev_rot )
00079   {
00080     u8g_dev_rot.dev_mem = u8g->dev;
00081     u8g->dev = &u8g_dev_rot;
00082   }
00083   u8g_dev_rot.dev_fn = u8g_dev_rot270_fn;
00084   u8g_UpdateDimension(u8g);
00085 }
00086 
00087 uint8_t u8g_dev_rot90_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
00088 {
00089   u8g_dev_t *rotation_chain = (u8g_dev_t *)(dev->dev_mem);
00090   switch(msg)
00091   {
00092     default:
00093     /*
00094     case U8G_DEV_MSG_INIT:
00095     case U8G_DEV_MSG_STOP:
00096     case U8G_DEV_MSG_PAGE_FIRST:
00097     case U8G_DEV_MSG_PAGE_NEXT:
00098     case U8G_DEV_MSG_SET_COLOR_ENTRY:
00099     case U8G_DEV_MSG_SET_XY_CB:
00100     */
00101       return u8g_call_dev_fn(u8g, rotation_chain, msg, arg);
00102 #ifdef U8G_DEV_MSG_IS_BBX_INTERSECTION
00103     case U8G_DEV_MSG_IS_BBX_INTERSECTION:
00104       {
00105         u8g_dev_arg_bbx_t *bbx = (u8g_dev_arg_bbx_t *)arg;
00106         u8g_uint_t x, y, tmp;
00107         
00108         /* transform the reference point */
00109         y = bbx->x;
00110         x = u8g->height;
00111         /* x = u8g_GetWidthLL(u8g, rotation_chain); */
00112         x -= bbx->y; 
00113         x--;
00114         
00115         /* adjust point to be the uppler left corner again */
00116         x -= bbx->h;
00117         x++;
00118         
00119         /* swap box dimensions */        
00120         tmp = bbx->w;
00121         bbx->w = bbx->h;
00122         bbx->h = tmp;
00123         
00124         /* store x,y */
00125         bbx->x = x;
00126         bbx->y = y;
00127       }
00128       return u8g_call_dev_fn(u8g, rotation_chain, msg, arg);
00129 #endif /* U8G_DEV_MSG_IS_BBX_INTERSECTION */
00130     case U8G_DEV_MSG_GET_PAGE_BOX:
00131       /* get page size from next device in the chain */
00132       u8g_call_dev_fn(u8g, rotation_chain, msg, arg);
00133       //printf("pre x: %3d..%3d y: %3d..%3d   ", ((u8g_box_t *)arg)->x0, ((u8g_box_t *)arg)->x1, ((u8g_box_t *)arg)->y0, ((u8g_box_t *)arg)->y1);
00134       {
00135     u8g_box_t new_box;
00136     //new_box.x0 = u8g_GetHeightLL(u8g,rotation_chain) - ((u8g_box_t *)arg)->y1 - 1;
00137     //new_box.x1 = u8g_GetHeightLL(u8g,rotation_chain) - ((u8g_box_t *)arg)->y0 - 1;
00138     
00139     new_box.x0 = ((u8g_box_t *)arg)->y0;
00140     new_box.x1 = ((u8g_box_t *)arg)->y1;
00141     new_box.y0 = ((u8g_box_t *)arg)->x0;
00142     new_box.y1 = ((u8g_box_t *)arg)->x1;
00143     *((u8g_box_t *)arg) = new_box;
00144     //printf("post x: %3d..%3d y: %3d..%3d\n", ((u8g_box_t *)arg)->x0, ((u8g_box_t *)arg)->x1, ((u8g_box_t *)arg)->y0, ((u8g_box_t *)arg)->y1);
00145       }
00146       break;
00147     case U8G_DEV_MSG_GET_WIDTH:
00148       *((u8g_uint_t *)arg) = u8g_GetHeightLL(u8g,rotation_chain);
00149       break;
00150     case U8G_DEV_MSG_GET_HEIGHT:
00151       *((u8g_uint_t *)arg) = u8g_GetWidthLL(u8g, rotation_chain);
00152       break;
00153     case U8G_DEV_MSG_SET_PIXEL:
00154     case U8G_DEV_MSG_SET_TPIXEL:
00155       {
00156         u8g_uint_t x, y;
00157         y = ((u8g_dev_arg_pixel_t *)arg)->x;
00158         x = u8g_GetWidthLL(u8g, rotation_chain);
00159         x -= ((u8g_dev_arg_pixel_t *)arg)->y; 
00160         x--;
00161         ((u8g_dev_arg_pixel_t *)arg)->x = x;
00162         ((u8g_dev_arg_pixel_t *)arg)->y = y;
00163       }
00164       u8g_call_dev_fn(u8g, rotation_chain, msg, arg);
00165       break;
00166     case U8G_DEV_MSG_SET_8PIXEL:
00167     case U8G_DEV_MSG_SET_4TPIXEL:
00168       {
00169         u8g_uint_t x, y;
00170     //uint16_t x,y;
00171         y = ((u8g_dev_arg_pixel_t *)arg)->x;
00172         x = u8g_GetWidthLL(u8g, rotation_chain);
00173         x -= ((u8g_dev_arg_pixel_t *)arg)->y; 
00174         x--;
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+=1;
00178         ((u8g_dev_arg_pixel_t *)arg)->dir &= 3;
00179       }
00180       u8g_call_dev_fn(u8g, rotation_chain, msg, arg);
00181       break;
00182   }
00183   return 1;
00184 }
00185 
00186 uint8_t u8g_dev_rot180_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
00187 {
00188   u8g_dev_t *rotation_chain = (u8g_dev_t *)(dev->dev_mem);
00189   switch(msg)
00190   {
00191     default:
00192     /*
00193     case U8G_DEV_MSG_INIT:
00194     case U8G_DEV_MSG_STOP:
00195     case U8G_DEV_MSG_PAGE_FIRST:
00196     case U8G_DEV_MSG_PAGE_NEXT:
00197     case U8G_DEV_MSG_SET_COLOR_ENTRY:
00198     case U8G_DEV_MSG_SET_XY_CB:
00199     */
00200       return u8g_call_dev_fn(u8g, rotation_chain, msg, arg);
00201 #ifdef U8G_DEV_MSG_IS_BBX_INTERSECTION
00202     case U8G_DEV_MSG_IS_BBX_INTERSECTION:
00203       {
00204         u8g_dev_arg_bbx_t *bbx = (u8g_dev_arg_bbx_t *)arg;
00205         u8g_uint_t x, y;
00206         
00207         /* transform the reference point */
00208         //y = u8g_GetHeightLL(u8g, rotation_chain);
00209         y = u8g->height;
00210         y -= bbx->y; 
00211         y--;
00212         
00213         //x = u8g_GetWidthLL(u8g, rotation_chain);
00214         x = u8g->width;
00215         x -= bbx->x; 
00216         x--;
00217         
00218         /* adjust point to be the uppler left corner again */
00219         y -= bbx->h;
00220         y++;
00221         
00222         x -= bbx->w;
00223         x++;
00224                 
00225         /* store x,y */
00226         bbx->x = x;
00227         bbx->y = y;
00228       }
00229       return u8g_call_dev_fn(u8g, rotation_chain, msg, arg);
00230 #endif /* U8G_DEV_MSG_IS_BBX_INTERSECTION */
00231     case U8G_DEV_MSG_GET_PAGE_BOX:
00232       /* get page size from next device in the chain */
00233       u8g_call_dev_fn(u8g, rotation_chain, msg, arg);
00234       //printf("pre x: %3d..%3d y: %3d..%3d   ", ((u8g_box_t *)arg)->x0, ((u8g_box_t *)arg)->x1, ((u8g_box_t *)arg)->y0, ((u8g_box_t *)arg)->y1);
00235       {
00236     u8g_box_t new_box;
00237     
00238     new_box.x0 = u8g_GetWidthLL(u8g,rotation_chain) - ((u8g_box_t *)arg)->x1 - 1;
00239     new_box.x1 = u8g_GetWidthLL(u8g,rotation_chain) - ((u8g_box_t *)arg)->x0 - 1;
00240     new_box.y0 = u8g_GetHeightLL(u8g,rotation_chain) - ((u8g_box_t *)arg)->y1 - 1;
00241     new_box.y1 = u8g_GetHeightLL(u8g,rotation_chain) - ((u8g_box_t *)arg)->y0 - 1;
00242     *((u8g_box_t *)arg) = new_box;
00243     //printf("post x: %3d..%3d y: %3d..%3d\n", ((u8g_box_t *)arg)->x0, ((u8g_box_t *)arg)->x1, ((u8g_box_t *)arg)->y0, ((u8g_box_t *)arg)->y1);
00244       }
00245       break;
00246     case U8G_DEV_MSG_GET_WIDTH:
00247       *((u8g_uint_t *)arg) = u8g_GetWidthLL(u8g,rotation_chain);
00248       break;
00249     case U8G_DEV_MSG_GET_HEIGHT:
00250       *((u8g_uint_t *)arg) = u8g_GetHeightLL(u8g, rotation_chain);
00251       break;
00252     case U8G_DEV_MSG_SET_PIXEL:
00253     case U8G_DEV_MSG_SET_TPIXEL:
00254       {
00255         u8g_uint_t x, y;
00256 
00257         y = u8g_GetHeightLL(u8g, rotation_chain);
00258         y -= ((u8g_dev_arg_pixel_t *)arg)->y; 
00259         y--;
00260         
00261         x = u8g_GetWidthLL(u8g, rotation_chain);
00262         x -= ((u8g_dev_arg_pixel_t *)arg)->x; 
00263         x--;
00264         
00265         ((u8g_dev_arg_pixel_t *)arg)->x = x;
00266         ((u8g_dev_arg_pixel_t *)arg)->y = y;
00267       }
00268       u8g_call_dev_fn(u8g, rotation_chain, msg, arg);
00269       break;
00270     case U8G_DEV_MSG_SET_8PIXEL:
00271     case U8G_DEV_MSG_SET_4TPIXEL:
00272       {
00273         u8g_uint_t x, y;
00274         
00275         y = u8g_GetHeightLL(u8g, rotation_chain);
00276         y -= ((u8g_dev_arg_pixel_t *)arg)->y; 
00277         y--;
00278         
00279         x = u8g_GetWidthLL(u8g, rotation_chain);
00280         x -= ((u8g_dev_arg_pixel_t *)arg)->x; 
00281         x--;
00282         
00283         ((u8g_dev_arg_pixel_t *)arg)->x = x;
00284         ((u8g_dev_arg_pixel_t *)arg)->y = y;
00285         ((u8g_dev_arg_pixel_t *)arg)->dir+=2;
00286         ((u8g_dev_arg_pixel_t *)arg)->dir &= 3;
00287       }
00288       u8g_call_dev_fn(u8g, rotation_chain, msg, arg);
00289       break;
00290   }
00291   return 1;
00292 }
00293 
00294 uint8_t u8g_dev_rot270_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
00295 {
00296   u8g_dev_t *rotation_chain = (u8g_dev_t *)(dev->dev_mem);
00297   switch(msg)
00298   {
00299     default:
00300     /*
00301     case U8G_DEV_MSG_INIT:
00302     case U8G_DEV_MSG_STOP:
00303     case U8G_DEV_MSG_PAGE_FIRST:
00304     case U8G_DEV_MSG_PAGE_NEXT:
00305     case U8G_DEV_MSG_SET_COLOR_ENTRY:
00306     case U8G_DEV_MSG_SET_XY_CB:
00307     */
00308       return u8g_call_dev_fn(u8g, rotation_chain, msg, arg);
00309 #ifdef U8G_DEV_MSG_IS_BBX_INTERSECTION
00310     case U8G_DEV_MSG_IS_BBX_INTERSECTION:
00311       {
00312         u8g_dev_arg_bbx_t *bbx = (u8g_dev_arg_bbx_t *)arg;
00313         u8g_uint_t x, y, tmp;
00314         
00315         /* transform the reference point */
00316         x = bbx->y;
00317         
00318         y = u8g->width;
00319         /* y = u8g_GetHeightLL(u8g, rotation_chain); */
00320         y -= bbx->x; 
00321         y--;
00322                 
00323         /* adjust point to be the uppler left corner again */
00324         y -= bbx->w;
00325         y++;
00326         
00327         /* swap box dimensions */        
00328         tmp = bbx->w;
00329         bbx->w = bbx->h;
00330         bbx->h = tmp;
00331         
00332         /* store x,y */
00333         bbx->x = x;
00334         bbx->y = y;
00335       }
00336       return u8g_call_dev_fn(u8g, rotation_chain, msg, arg);
00337 #endif /* U8G_DEV_MSG_IS_BBX_INTERSECTION */
00338     case U8G_DEV_MSG_GET_PAGE_BOX:
00339       /* get page size from next device in the chain */
00340       u8g_call_dev_fn(u8g, rotation_chain, msg, arg);
00341       //printf("pre x: %3d..%3d y: %3d..%3d   ", ((u8g_box_t *)arg)->x0, ((u8g_box_t *)arg)->x1, ((u8g_box_t *)arg)->y0, ((u8g_box_t *)arg)->y1);
00342       {
00343     u8g_box_t new_box;
00344     
00345     new_box.x0 = u8g_GetHeightLL(u8g,rotation_chain) - ((u8g_box_t *)arg)->y1 - 1;
00346     new_box.x1 = u8g_GetHeightLL(u8g,rotation_chain) - ((u8g_box_t *)arg)->y0 - 1;
00347     new_box.y0 = u8g_GetWidthLL(u8g,rotation_chain) - ((u8g_box_t *)arg)->x1 - 1;
00348     new_box.y1 = u8g_GetWidthLL(u8g,rotation_chain) - ((u8g_box_t *)arg)->x0 - 1;
00349     *((u8g_box_t *)arg) = new_box;
00350     //printf("post x: %3d..%3d y: %3d..%3d\n", ((u8g_box_t *)arg)->x0, ((u8g_box_t *)arg)->x1, ((u8g_box_t *)arg)->y0, ((u8g_box_t *)arg)->y1);
00351       }
00352       break;
00353     case U8G_DEV_MSG_GET_WIDTH:
00354       *((u8g_uint_t *)arg) = u8g_GetHeightLL(u8g,rotation_chain);
00355       break;
00356     case U8G_DEV_MSG_GET_HEIGHT:
00357       *((u8g_uint_t *)arg) = u8g_GetWidthLL(u8g, rotation_chain);
00358       break;
00359     case U8G_DEV_MSG_SET_PIXEL:
00360     case U8G_DEV_MSG_SET_TPIXEL:
00361       {
00362         u8g_uint_t x, y;
00363         x = ((u8g_dev_arg_pixel_t *)arg)->y;
00364         
00365         y = u8g_GetHeightLL(u8g, rotation_chain);
00366         y -= ((u8g_dev_arg_pixel_t *)arg)->x; 
00367         y--;
00368           
00369         /*
00370         x = u8g_GetWidthLL(u8g, rotation_chain);
00371         x -= ((u8g_dev_arg_pixel_t *)arg)->y; 
00372         x--;
00373         */
00374         ((u8g_dev_arg_pixel_t *)arg)->x = x;
00375         ((u8g_dev_arg_pixel_t *)arg)->y = y;
00376       }
00377       u8g_call_dev_fn(u8g, rotation_chain, msg, arg);
00378       break;
00379     case U8G_DEV_MSG_SET_8PIXEL:
00380     case U8G_DEV_MSG_SET_4TPIXEL:
00381       {
00382         u8g_uint_t x, y;
00383         x = ((u8g_dev_arg_pixel_t *)arg)->y;
00384         
00385         y = u8g_GetHeightLL(u8g, rotation_chain);
00386         y -= ((u8g_dev_arg_pixel_t *)arg)->x; 
00387         y--;
00388           
00389         /*
00390         x = u8g_GetWidthLL(u8g, rotation_chain);
00391         x -= ((u8g_dev_arg_pixel_t *)arg)->y; 
00392         x--;
00393         */
00394         ((u8g_dev_arg_pixel_t *)arg)->x = x;
00395         ((u8g_dev_arg_pixel_t *)arg)->y = y;
00396         ((u8g_dev_arg_pixel_t *)arg)->dir+=3;
00397         ((u8g_dev_arg_pixel_t *)arg)->dir &= 3;
00398       }
00399       u8g_call_dev_fn(u8g, rotation_chain, msg, arg);
00400       break;
00401   }
00402   return 1;
00403 }
00404 
00405