server/screen.c

00001 /*
00002  * Copyright Ian Burnett 2005, 2006.
00003  *
00004  * This file is part of Ian's Interactive LCD controller (IILC).
00005  * 
00006  * IILC is free software; you can redistribute it and/or modify it under
00007  * the terms of the GNU General Public License as published by the Free
00008  * Software Foundation; either version 2 of the License, or (at your
00009  * option) any later version.
00010  *
00011  * IILC is distributed in the hope that it will be useful, but WITHOUT
00012  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00013  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00014  * for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License along
00017  * with IILC; if not, write to the Free Software Foundation, Inc.,
00018  * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA.
00019  */
00020 
00021 #include "lcd.h"
00022 #include "screen.h"
00023 #include "module.h"
00024 #include "string.h"
00025 #include "vector.h"
00026 
00031 typedef struct _tag_window
00032 {
00033     int x;
00034 
00035     int y;
00036 
00037     int width;
00038 
00039     int height;
00040 
00041     LPMODULE pModule;
00042 
00043 } WINDOW, * LPWINDOW;
00044 
00045 /*
00046 
00047 typedef struct _tag_window
00048 {
00049     unsigned int x;
00050 
00051     unsigned int y;
00052 
00053     unsigned int width;
00054 
00055     unsigned int height;
00056 
00057     WINDOW_TYPE type;
00058 
00059     union _tag_window_pfn {
00060         pfnGetTextData    GetText;
00061         pfnGetNumericData GetNumeric;
00062     } pfn;
00063 
00064     void * context;
00065 
00066 } WINDOW;
00067 
00068 */
00069 
00070 typedef enum
00071 {
00072     SCREEN_TYPE_TEXT,
00073     SCREEN_TYPE_BAR
00074 
00075 } SCREEN_TYPE;
00076 
00077 typedef struct _tag_screen
00078 {
00079     int type;
00080 
00081     int width;
00082 
00083     int height;
00084 
00085     LPVECTOR pWindowList;
00086 
00087 } SCREEN;
00088 
00089 int screenGetSize(LPSCREEN pScreen, int * width, int * height)
00090 {
00091     *width = pScreen->width;
00092     *height = pScreen->height;
00093 
00094     return 0;
00095 }
00096 
00097 
00098 int screenCreate(LPSCREEN * ppScreen, unsigned int uWidth, unsigned int uHeight)
00099 {
00100     int rc = 0;
00101     LPSCREEN pScreen = NULL;
00102 
00103     pScreen = calloc(1, sizeof(SCREEN));
00104     pScreen->height = uHeight;
00105     pScreen->width  = uWidth;
00106 
00107     vectorCreate(&(pScreen->pWindowList));
00108 
00109     /* Assign to user */
00110     *ppScreen = pScreen;
00111 
00112     return rc;
00113 }
00114 
00115 
00116 int screenAddWindow(LPSCREEN pScreen, int x, int y, int width, int height, LPMODULE pModule)
00117 {
00118     int rc = 0;
00119     LPWINDOW pWindow = NULL;
00120 
00121     pWindow = (LPWINDOW) calloc(1, sizeof(WINDOW));
00122     pWindow->x       = x;
00123     pWindow->y       = y;
00124     pWindow->width   = width;
00125     pWindow->height  = height;
00126     pWindow->pModule = pModule;
00127 
00128     vectorAdd(pScreen->pWindowList, pWindow);
00129 
00130     return rc;
00131 }
00132 
00133 
00134 
00135 int screenDoRender(LPSCREEN pScreen, char * pszScreen)
00136 {
00137     int rc = 0;
00138     int i = 0, w = 0;
00139     int nWindowCount = 0;
00140     int nScreenSize = 0;
00141 
00142     /* Calculate our screen size and clear data to spaces */
00143     nScreenSize = pScreen->width * pScreen->height;
00144     memset(pszScreen, ' ', nScreenSize);
00145 
00146     /* Find number of windows in this screen */
00147     vectorGetSize(pScreen->pWindowList, &nWindowCount);
00148     for (w = 0; w < nWindowCount; w++) {
00149 
00150         LPWINDOW pWindow = NULL;
00151         int windowY = 0;
00152 
00153         /* Offset into the main buffer */
00154         int offset = 0;
00155 
00156         vectorGetElementAt(pScreen->pWindowList, w, (void **) &pWindow);
00157 
00158         /* Initialise offset */
00159         offset = pWindow->x + (pWindow->y * pScreen->width);
00160 
00161         /* Render the window line by line */
00162         for (windowY = 0; windowY < pWindow->height; windowY++) {
00163 
00164             /* Local temp buffer (TODO: Stack overwrite potential!) */
00165             char buf[1024];
00166             memset(buf, 0, sizeof(buf));
00167 
00168             /* Get data from the module */
00169             moduleRender(pWindow->pModule, windowY, pWindow->width, buf);
00170 
00171             /* Copy up to the last null-terminator */
00172             for (i = 0; (i < pWindow->width) && (buf[i] != 0); i++) {
00173                 pszScreen[offset + i] = buf[i];
00174             }
00175 
00176             /* Increate offset into the main buffer */
00177             offset += pScreen->width;
00178         }
00179 
00180         // printf("Screen rendered as [%s]\n", pszScreen);
00181     }
00182 
00183     return rc;
00184 }
00185 
00186 
00187 void * RenderThread(void * arg)
00188 {
00189     int running = 0;
00190 
00191     printf("RenderThread\n");
00192 
00193     while (running)
00194     {
00195 
00196 
00197     }
00198 
00199     return NULL;
00200 }

Generated on Mon Jul 17 01:36:12 2006 for IILC by  doxygen 1.4.6