Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
u8g_virtual_screen.c
00001 /* 00002 00003 u8g_virtual_screen.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 00035 */ 00036 00037 #include "u8g.h" 00038 00039 struct _u8g_vs_t 00040 { 00041 u8g_uint_t x; 00042 u8g_uint_t y; 00043 u8g_t *u8g; 00044 }; 00045 typedef struct _u8g_vs_t u8g_vs_t; 00046 00047 #define U8g_VS_MAX 4 00048 uint8_t u8g_vs_cnt = 0; 00049 u8g_vs_t u8g_vs_list[U8g_VS_MAX]; 00050 uint8_t u8g_vs_current; 00051 u8g_uint_t u8g_vs_width; 00052 u8g_uint_t u8g_vs_height; 00053 00054 uint8_t u8g_dev_vs_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) 00055 { 00056 switch(msg) 00057 { 00058 default: 00059 { 00060 uint8_t i; 00061 for( i = 0; i < u8g_vs_cnt; i++ ) 00062 { 00063 u8g_call_dev_fn(u8g_vs_list[i].u8g, u8g_vs_list[i].u8g->dev, msg, arg); 00064 } 00065 } 00066 return 1; 00067 case U8G_DEV_MSG_PAGE_FIRST: 00068 u8g_vs_current = 0; 00069 if ( u8g_vs_cnt != 0 ) 00070 return u8g_call_dev_fn(u8g_vs_list[u8g_vs_current].u8g, u8g_vs_list[u8g_vs_current].u8g->dev, msg, arg); 00071 return 0; 00072 case U8G_DEV_MSG_PAGE_NEXT: 00073 { 00074 uint8_t ret = 0; 00075 if ( u8g_vs_cnt != 0 ) 00076 ret = u8g_call_dev_fn(u8g_vs_list[u8g_vs_current].u8g, u8g_vs_list[u8g_vs_current].u8g->dev, msg, arg); 00077 if ( ret != 0 ) 00078 return ret; 00079 u8g_vs_current++; /* next device */ 00080 if ( u8g_vs_current >= u8g_vs_cnt ) /* reached end? */ 00081 return 0; 00082 return u8g_call_dev_fn(u8g_vs_list[u8g_vs_current].u8g, u8g_vs_list[u8g_vs_current].u8g->dev, U8G_DEV_MSG_PAGE_FIRST, arg); 00083 } 00084 return 0; 00085 case U8G_DEV_MSG_GET_WIDTH: 00086 *((u8g_uint_t *)arg) = u8g_vs_width; 00087 break; 00088 case U8G_DEV_MSG_GET_HEIGHT: 00089 *((u8g_uint_t *)arg) = u8g_vs_height; 00090 break; 00091 case U8G_DEV_MSG_GET_PAGE_BOX: 00092 if ( u8g_vs_current < u8g_vs_cnt ) 00093 { 00094 u8g_call_dev_fn(u8g_vs_list[u8g_vs_current].u8g, u8g_vs_list[u8g_vs_current].u8g->dev, msg, arg); 00095 ((u8g_box_t *)arg)->x0 += u8g_vs_list[u8g_vs_current].x; 00096 ((u8g_box_t *)arg)->x1 += u8g_vs_list[u8g_vs_current].x; 00097 ((u8g_box_t *)arg)->y0 += u8g_vs_list[u8g_vs_current].y; 00098 ((u8g_box_t *)arg)->y1 += u8g_vs_list[u8g_vs_current].y; 00099 } 00100 else 00101 { 00102 ((u8g_box_t *)arg)->x0 = 0; 00103 ((u8g_box_t *)arg)->x1 = 0; 00104 ((u8g_box_t *)arg)->y0 = 0; 00105 ((u8g_box_t *)arg)->y1 = 0; 00106 } 00107 return 1; 00108 case U8G_DEV_MSG_SET_PIXEL: 00109 case U8G_DEV_MSG_SET_8PIXEL: 00110 if ( u8g_vs_current < u8g_vs_cnt ) 00111 { 00112 ((u8g_dev_arg_pixel_t *)arg)->x -= u8g_vs_list[u8g_vs_current].x; 00113 ((u8g_dev_arg_pixel_t *)arg)->y -= u8g_vs_list[u8g_vs_current].y; 00114 return u8g_call_dev_fn(u8g_vs_list[u8g_vs_current].u8g, u8g_vs_list[u8g_vs_current].u8g->dev, msg, arg); 00115 } 00116 break; 00117 } 00118 return 1; 00119 } 00120 00121 00122 00123 u8g_dev_t u8g_dev_vs = { u8g_dev_vs_fn, NULL, NULL }; 00124 00125 void u8g_SetVirtualScreenDimension(u8g_t *vs_u8g, u8g_uint_t width, u8g_uint_t height) 00126 { 00127 if ( vs_u8g->dev != &u8g_dev_vs ) 00128 return; /* abort if there is no a virtual screen device */ 00129 u8g_vs_width = width; 00130 u8g_vs_height = height; 00131 } 00132 00133 uint8_t u8g_AddToVirtualScreen(u8g_t *vs_u8g, u8g_uint_t x, u8g_uint_t y, u8g_t *child_u8g) 00134 { 00135 if ( vs_u8g->dev != &u8g_dev_vs ) 00136 return 0; /* abort if there is no a virtual screen device */ 00137 if ( u8g_vs_cnt >= U8g_VS_MAX ) 00138 return 0; /* maximum number of child u8g's reached */ 00139 u8g_vs_list[u8g_vs_cnt].u8g = child_u8g; 00140 u8g_vs_list[u8g_vs_cnt].x = x; 00141 u8g_vs_list[u8g_vs_cnt].y = y; 00142 u8g_vs_cnt++; 00143 return 1; 00144 } 00145 00146
Generated on Tue Jul 12 2022 17:30:58 by
1.7.2