aboutsummaryrefslogtreecommitdiffstats
path: root/drv_generic_text.c
diff options
context:
space:
mode:
authorreinelt <reinelt@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>2005-05-08 04:32:45 +0000
committerreinelt <reinelt@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>2005-05-08 04:32:45 +0000
commitdbf5d92605a9db10e3e3cb154d03a515c5d5c5af (patch)
tree501d5dda3ce90fe924b893e487d9ef9f0683382b /drv_generic_text.c
parenta1c471e9fb7cadb68bb182ab2e9715a0aa092386 (diff)
downloadlcd4linux-dbf5d92605a9db10e3e3cb154d03a515c5d5c5af.tar.gz
[lcd4linux @ 2005-05-08 04:32:43 by reinelt]
CodingStyle added and applied git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@547 3ae390bd-cb1e-0410-b409-cd5a39f66f1f
Diffstat (limited to 'drv_generic_text.c')
-rw-r--r--drv_generic_text.c1277
1 files changed, 662 insertions, 615 deletions
diff --git a/drv_generic_text.c b/drv_generic_text.c
index 36309f4..f250ca2 100644
--- a/drv_generic_text.c
+++ b/drv_generic_text.c
@@ -1,4 +1,4 @@
-/* $Id: drv_generic_text.c,v 1.26 2005/05/06 06:37:34 reinelt Exp $
+/* $Id: drv_generic_text.c,v 1.27 2005/05/08 04:32:44 reinelt Exp $
*
* generic driver helper for text-based displays
*
@@ -23,6 +23,9 @@
*
*
* $Log: drv_generic_text.c,v $
+ * Revision 1.27 2005/05/08 04:32:44 reinelt
+ * CodingStyle added and applied
+ *
* Revision 1.26 2005/05/06 06:37:34 reinelt
* hollow bar patch from geronet
*
@@ -213,43 +216,43 @@
typedef struct {
- int val1;
- int val2;
- DIRECTION dir;
- STYLE style;
- int segment;
- int invalid;
+ int val1;
+ int val2;
+ DIRECTION dir;
+ STYLE style;
+ int segment;
+ int invalid;
} BAR;
typedef struct {
- int val1;
- int val2;
- DIRECTION dir;
- STYLE style;
- int used;
- int ascii;
+ int val1;
+ int val2;
+ DIRECTION dir;
+ STYLE style;
+ int used;
+ int ascii;
} SEGMENT;
-static char *Section=NULL;
-static char *Driver=NULL;
+static char *Section = NULL;
+static char *Driver = NULL;
-int DROWS = 20; /* display size: rows */
-int DCOLS = 4; /* display size: columns */
-int LROWS = 20; /* layout size: rows */
-int LCOLS = 4; /* layout size: columns */
-int XRES = 6; /* pixels of one char cell */
-int YRES = 8; /* pixels of one char cell */
-int CHARS = 0; /* number of user-defineable characters */
-int CHAR0 = 0; /* ASCII of first user-defineable char */
-int ICONS = 0; /* number of user-defineable characters reserved for icons */
+int DROWS = 20; /* display size: rows */
+int DCOLS = 4; /* display size: columns */
+int LROWS = 20; /* layout size: rows */
+int LCOLS = 4; /* layout size: columns */
+int XRES = 6; /* pixels of one char cell */
+int YRES = 8; /* pixels of one char cell */
+int CHARS = 0; /* number of user-defineable characters */
+int CHAR0 = 0; /* ASCII of first user-defineable char */
+int ICONS = 0; /* number of user-defineable characters reserved for icons */
-int GOTO_COST = 0; /* number of bytes a goto command requires */
-int INVALIDATE = 0; /* re-send a modified userdefined char? */
+int GOTO_COST = 0; /* number of bytes a goto command requires */
+int INVALIDATE = 0; /* re-send a modified userdefined char? */
-static char *LayoutFB = NULL;
-static char *DisplayFB = NULL;
+static char *LayoutFB = NULL;
+static char *DisplayFB = NULL;
static int Single_Segments = 0;
@@ -264,62 +267,64 @@ static BAR *BarFB = NULL;
/*** generic Framebuffer stuff ***/
/****************************************/
-static void drv_generic_text_resizeFB (int rows, int cols)
+static void drv_generic_text_resizeFB(int rows, int cols)
{
- char *newFB;
- BAR *newBar;
- int i, row, col;
-
- /* Layout FB is large enough */
- if (rows <= LROWS && cols <= LCOLS)
- return;
-
- /* get maximum values */
- if (rows < LROWS) rows = LROWS;
- if (cols < LCOLS) cols = LCOLS;
-
- /* allocate new Layout FB */
- newFB = malloc(cols * rows * sizeof(char));
- memset (newFB, ' ', rows * cols * sizeof(char));
-
- /* transfer contents */
- if (LayoutFB != NULL) {
- for (row = 0; row < LROWS; row++) {
- for (col = 0; col < LCOLS; col++) {
- newFB[row * cols + col] = LayoutFB[row * LCOLS + col];
- }
- }
- free (LayoutFB);
- }
- LayoutFB = newFB;
-
-
- /* resize Bar buffer */
- if (BarFB) {
-
- newBar = malloc (rows * cols * sizeof(BAR));
-
- for (i = 0; i < rows * cols; i++) {
- newBar[i].val1 = -1;
- newBar[i].val2 = -1;
- newBar[i].dir = 0;
- newBar[i].segment = -1;
- newBar[i].invalid = 0;
- }
-
+ char *newFB;
+ BAR *newBar;
+ int i, row, col;
+
+ /* Layout FB is large enough */
+ if (rows <= LROWS && cols <= LCOLS)
+ return;
+
+ /* get maximum values */
+ if (rows < LROWS)
+ rows = LROWS;
+ if (cols < LCOLS)
+ cols = LCOLS;
+
+ /* allocate new Layout FB */
+ newFB = malloc(cols * rows * sizeof(char));
+ memset(newFB, ' ', rows * cols * sizeof(char));
+
/* transfer contents */
- for (row = 0; row < LROWS; row++) {
- for (col = 0; col < LCOLS; col++) {
- newBar[row * cols + col] = BarFB[row * LCOLS + col];
- }
+ if (LayoutFB != NULL) {
+ for (row = 0; row < LROWS; row++) {
+ for (col = 0; col < LCOLS; col++) {
+ newFB[row * cols + col] = LayoutFB[row * LCOLS + col];
+ }
+ }
+ free(LayoutFB);
}
+ LayoutFB = newFB;
+
+
+ /* resize Bar buffer */
+ if (BarFB) {
+
+ newBar = malloc(rows * cols * sizeof(BAR));
+
+ for (i = 0; i < rows * cols; i++) {
+ newBar[i].val1 = -1;
+ newBar[i].val2 = -1;
+ newBar[i].dir = 0;
+ newBar[i].segment = -1;
+ newBar[i].invalid = 0;
+ }
+
+ /* transfer contents */
+ for (row = 0; row < LROWS; row++) {
+ for (col = 0; col < LCOLS; col++) {
+ newBar[row * cols + col] = BarFB[row * LCOLS + col];
+ }
+ }
- free (BarFB);
- BarFB = newBar;
- }
-
- LCOLS = cols;
- LROWS = rows;
+ free(BarFB);
+ BarFB = newBar;
+ }
+
+ LCOLS = cols;
+ LROWS = rows;
}
@@ -327,152 +332,157 @@ static void drv_generic_text_resizeFB (int rows, int cols)
/*** generic text handling ***/
/****************************************/
-int drv_generic_text_init (const char *section, const char *driver)
+int drv_generic_text_init(const char *section, const char *driver)
{
- Section = (char*)section;
- Driver = (char*)driver;
-
- /* init display framebuffer */
- DisplayFB = (char*)malloc(DCOLS * DROWS * sizeof(char));
- memset (DisplayFB, ' ', DROWS * DCOLS * sizeof(char));
-
- /* init layout framebuffer */
- LROWS = 0;
- LCOLS = 0;
- LayoutFB = NULL;
- drv_generic_text_resizeFB (DROWS, DCOLS);
-
- /* sanity check */
- if (LayoutFB == NULL || DisplayFB == NULL) {
- error ("%s: framebuffer could not be allocated: malloc() failed", Driver);
- return -1;
- }
-
- return 0;
+ Section = (char *) section;
+ Driver = (char *) driver;
+
+ /* init display framebuffer */
+ DisplayFB = (char *) malloc(DCOLS * DROWS * sizeof(char));
+ memset(DisplayFB, ' ', DROWS * DCOLS * sizeof(char));
+
+ /* init layout framebuffer */
+ LROWS = 0;
+ LCOLS = 0;
+ LayoutFB = NULL;
+ drv_generic_text_resizeFB(DROWS, DCOLS);
+
+ /* sanity check */
+ if (LayoutFB == NULL || DisplayFB == NULL) {
+ error("%s: framebuffer could not be allocated: malloc() failed", Driver);
+ return -1;
+ }
+
+ return 0;
}
/* say hello to the user */
-int drv_generic_text_greet (const char *msg1, const char *msg2)
+int drv_generic_text_greet(const char *msg1, const char *msg2)
{
- int i;
- int flag = 0;
-
- char *line1[] = { "* LCD4Linux " VERSION " *",
- "LCD4Linux " VERSION,
- "* LCD4Linux *",
- "LCD4Linux",
- "L4Linux",
- NULL };
-
- char *line2[] = { "http://lcd4linux.bulix.org",
- "lcd4linux.bulix.org",
- NULL };
-
-
- for (i = 0; line1[i]; i++) {
- if (strlen(line1[i]) <= (unsigned)DCOLS) {
- drv_generic_text_real_write (0, (DCOLS - strlen(line1[i])) / 2, line1[i], strlen(line1[i]));
- flag = 1;
- break;
+ int i;
+ int flag = 0;
+
+ char *line1[] = { "* LCD4Linux " VERSION " *",
+ "LCD4Linux " VERSION,
+ "* LCD4Linux *",
+ "LCD4Linux",
+ "L4Linux",
+ NULL
+ };
+
+ char *line2[] = { "http://lcd4linux.bulix.org",
+ "lcd4linux.bulix.org",
+ NULL
+ };
+
+
+ for (i = 0; line1[i]; i++) {
+ if (strlen(line1[i]) <= (unsigned) DCOLS) {
+ drv_generic_text_real_write(0, (DCOLS - strlen(line1[i])) / 2, line1[i], strlen(line1[i]));
+ flag = 1;
+ break;
+ }
}
- }
- if (DROWS >= 2) {
- for (i = 0; line2[i]; i++) {
- if (strlen(line2[i]) <= (unsigned)DCOLS) {
- drv_generic_text_real_write (1, (DCOLS - strlen(line2[i])) / 2, line2[i], strlen(line2[i]));
- flag = 1;
- break;
- }
+ if (DROWS >= 2) {
+ for (i = 0; line2[i]; i++) {
+ if (strlen(line2[i]) <= (unsigned) DCOLS) {
+ drv_generic_text_real_write(1, (DCOLS - strlen(line2[i])) / 2, line2[i], strlen(line2[i]));
+ flag = 1;
+ break;
+ }
+ }
}
- }
-
- if (msg1 && DROWS >= 3) {
- int len = strlen(msg1);
- if ( len <= DCOLS) {
- drv_generic_text_real_write (2, (DCOLS-len) / 2, msg1, len);
- flag = 1;
+
+ if (msg1 && DROWS >= 3) {
+ int len = strlen(msg1);
+ if (len <= DCOLS) {
+ drv_generic_text_real_write(2, (DCOLS - len) / 2, msg1, len);
+ flag = 1;
+ }
}
- }
-
- if (msg2 && DROWS >= 4) {
- int len = strlen(msg2);
- if ( len <= DCOLS) {
- drv_generic_text_real_write (3, (DCOLS-len) / 2, msg2, len);
- flag = 1;
+
+ if (msg2 && DROWS >= 4) {
+ int len = strlen(msg2);
+ if (len <= DCOLS) {
+ drv_generic_text_real_write(3, (DCOLS - len) / 2, msg2, len);
+ flag = 1;
+ }
}
- }
- return flag;
+ return flag;
}
-int drv_generic_text_draw (WIDGET *W)
+int drv_generic_text_draw(WIDGET * W)
{
- WIDGET_TEXT *Text = W->data;
- char *txt, *fb1, *fb2;
- int row, col, col0, len, end;
-
- row = W->row;
- col = W->col;
- txt = Text->buffer;
- len = strlen(txt);
- end = col + len;
-
- /* maybe grow layout framebuffer */
- drv_generic_text_resizeFB (row+1, col+len);
-
- fb1 = LayoutFB + row*LCOLS;
- fb2 = DisplayFB + row*DCOLS;
-
- /* transfer new text into layout buffer */
- memcpy (fb1 + col, txt, len);
-
- if (row<DROWS) {
- for (; col <= end && col < DCOLS; col++) {
- int pos1, pos2, equal;
- if (fb1[col] == fb2[col]) continue;
- col0 = col;
- for (pos1 = col, pos2 = pos1, col++, equal = 0; col <= end && col < DCOLS; col++) {
- if (fb1[col] == fb2[col]) {
- /* If we find just one equal byte, we don't break, because this */
- /* would require a goto, which takes several bytes, too. */
- if (GOTO_COST >= 0 && ++equal > GOTO_COST) break;
- } else {
- pos2 = col;
- equal = 0;
+ WIDGET_TEXT *Text = W->data;
+ char *txt, *fb1, *fb2;
+ int row, col, col0, len, end;
+
+ row = W->row;
+ col = W->col;
+ txt = Text->buffer;
+ len = strlen(txt);
+ end = col + len;
+
+ /* maybe grow layout framebuffer */
+ drv_generic_text_resizeFB(row + 1, col + len);
+
+ fb1 = LayoutFB + row * LCOLS;
+ fb2 = DisplayFB + row * DCOLS;
+
+ /* transfer new text into layout buffer */
+ memcpy(fb1 + col, txt, len);
+
+ if (row < DROWS) {
+ for (; col <= end && col < DCOLS; col++) {
+ int pos1, pos2, equal;
+ if (fb1[col] == fb2[col])
+ continue;
+ col0 = col;
+ for (pos1 = col, pos2 = pos1, col++, equal = 0; col <= end && col < DCOLS; col++) {
+ if (fb1[col] == fb2[col]) {
+ /* If we find just one equal byte, we don't break, because this */
+ /* would require a goto, which takes several bytes, too. */
+ if (GOTO_COST >= 0 && ++equal > GOTO_COST)
+ break;
+ } else {
+ pos2 = col;
+ equal = 0;
+ }
+ }
+ memcpy(fb2 + pos1, fb1 + pos1, pos2 - pos1 + 1);
+ drv_generic_text_real_write(row, col0, fb2 + pos1, pos2 - pos1 + 1);
}
- }
- memcpy ( fb2+pos1, fb1+pos1, pos2-pos1+1);
- drv_generic_text_real_write (row, col0, fb2+pos1, pos2-pos1+1);
}
- }
- return 0;
+ return 0;
}
-int drv_generic_text_quit (void) {
-
- if (LayoutFB) {
- free(LayoutFB);
- LayoutFB = NULL;
- }
-
- if (DisplayFB) {
- free(DisplayFB);
- DisplayFB = NULL;
- }
-
- if (BarFB) {
- free (BarFB);
- BarFB = NULL;
- }
- widget_unregister();
-
- return (0);
+int drv_generic_text_quit(void)
+{
+
+ if (LayoutFB) {
+ free(LayoutFB);
+ LayoutFB = NULL;
+ }
+
+ if (DisplayFB) {
+ free(DisplayFB);
+ DisplayFB = NULL;
+ }
+
+ if (BarFB) {
+ free(BarFB);
+ BarFB = NULL;
+ }
+ widget_unregister();
+
+ return (0);
}
@@ -480,70 +490,72 @@ int drv_generic_text_quit (void) {
/*** generic icon handling ***/
/****************************************/
-int drv_generic_text_icon_init (void)
+int drv_generic_text_icon_init(void)
{
- if (cfg_number(Section, "Icons", 0, 0, CHARS, &ICONS) < 0) return -1;
- if (ICONS>0) {
- info ("%s: reserving %d of %d user-defined characters for icons", Driver, ICONS, CHARS);
- }
- return 0;
+ if (cfg_number(Section, "Icons", 0, 0, CHARS, &ICONS) < 0)
+ return -1;
+ if (ICONS > 0) {
+ info("%s: reserving %d of %d user-defined characters for icons", Driver, ICONS, CHARS);
+ }
+ return 0;
}
-int drv_generic_text_icon_draw (WIDGET *W)
+int drv_generic_text_icon_draw(WIDGET * W)
{
- static int icon_counter = 0;
- WIDGET_ICON *Icon = W->data;
- int row, col;
- int l_idx, d_idx;
- int invalidate = 0;
- unsigned char ascii;
-
- row = W->row;
- col = W->col;
-
- /* maybe grow layout framebuffer */
- drv_generic_text_resizeFB (row+1, col+1);
-
- /* icon deactivated? */
- if (Icon->ascii == -2) return 0;
-
- /* ASCII already assigned? */
- if (Icon->ascii == -1) {
- if (icon_counter >= ICONS) {
- error ("cannot process icon '%s': out of icons", W->name);
- Icon->ascii = -2;
- return -1;
+ static int icon_counter = 0;
+ WIDGET_ICON *Icon = W->data;
+ int row, col;
+ int l_idx, d_idx;
+ int invalidate = 0;
+ unsigned char ascii;
+
+ row = W->row;
+ col = W->col;
+
+ /* maybe grow layout framebuffer */
+ drv_generic_text_resizeFB(row + 1, col + 1);
+
+ /* icon deactivated? */
+ if (Icon->ascii == -2)
+ return 0;
+
+ /* ASCII already assigned? */
+ if (Icon->ascii == -1) {
+ if (icon_counter >= ICONS) {
+ error("cannot process icon '%s': out of icons", W->name);
+ Icon->ascii = -2;
+ return -1;
+ }
+ icon_counter++;
+ Icon->ascii = CHAR0 + CHARS - icon_counter;
+ }
+
+ /* maybe redefine icon */
+ if (Icon->curmap != Icon->prvmap && Icon->visible) {
+ Icon->prvmap = Icon->curmap;
+ drv_generic_text_real_defchar(Icon->ascii, Icon->bitmap + YRES * Icon->curmap);
+ invalidate = INVALIDATE;
}
- icon_counter++;
- Icon->ascii = CHAR0 + CHARS - icon_counter;
- }
-
- /* maybe redefine icon */
- if (Icon->curmap != Icon->prvmap && Icon->visible) {
- Icon->prvmap = Icon->curmap;
- drv_generic_text_real_defchar(Icon->ascii, Icon->bitmap + YRES * Icon->curmap);
- invalidate = INVALIDATE;
- }
-
- /* use blank if invisible */
- ascii = Icon->visible ? Icon->ascii : ' ';
-
- /* index into the two framebuffers */
- l_idx = row * LCOLS + col;
- d_idx = row * DCOLS + col;
-
- /* transfer icon into layout buffer */
- LayoutFB[l_idx] = ascii;
-
- /* maybe send icon to the display */
- if (row < DROWS && col < DCOLS && (DisplayFB[d_idx] != ascii || invalidate)) {
- DisplayFB[d_idx] = ascii;
- drv_generic_text_real_write (row, col, DisplayFB + d_idx, 1);
- }
-
- return 0;
-
+
+ /* use blank if invisible */
+ ascii = Icon->visible ? Icon->ascii : ' ';
+
+ /* index into the two framebuffers */
+ l_idx = row * LCOLS + col;
+ d_idx = row * DCOLS + col;
+
+ /* transfer icon into layout buffer */
+ LayoutFB[l_idx] = ascii;
+
+ /* maybe send icon to the display */
+ if (row < DROWS && col < DCOLS && (DisplayFB[d_idx] != ascii || invalidate)) {
+ DisplayFB[d_idx] = ascii;
+ drv_generic_text_real_write(row, col, DisplayFB + d_idx, 1);
+ }
+
+ return 0;
+
}
@@ -553,152 +565,154 @@ int drv_generic_text_icon_draw (WIDGET *W)
static void drv_generic_text_bar_clear(void)
{
- int i;
-
- for (i = 0; i < LROWS*LCOLS; i++) {
- BarFB[i].val1 = -1;
- BarFB[i].val2 = -1;
- BarFB[i].dir = 0;
- BarFB[i].style = 0;
- BarFB[i].segment = -1;
- BarFB[i].invalid = 0;
- }
-
- for (i = 0; i < nSegment; i++) {
- Segment[i].used = 0;
- }
+ int i;
+
+ for (i = 0; i < LROWS * LCOLS; i++) {
+ BarFB[i].val1 = -1;
+ BarFB[i].val2 = -1;
+ BarFB[i].dir = 0;
+ BarFB[i].style = 0;
+ BarFB[i].segment = -1;
+ BarFB[i].invalid = 0;
+ }
+
+ for (i = 0; i < nSegment; i++) {
+ Segment[i].used = 0;
+ }
}
-int drv_generic_text_bar_init (const int single_segments)
+int drv_generic_text_bar_init(const int single_segments)
{
- if (BarFB) free (BarFB);
-
- if ((BarFB = malloc (LROWS * LCOLS * sizeof(BAR))) == NULL) {
- error ("bar buffer allocation failed: out of memory");
- return -1;
- }
-
- Single_Segments = single_segments;
-
- nSegment = 0;
- fSegment = 0;
-
- drv_generic_text_bar_clear();
-
- return 0;
+ if (BarFB)
+ free(BarFB);
+
+ if ((BarFB = malloc(LROWS * LCOLS * sizeof(BAR))) == NULL) {
+ error("bar buffer allocation failed: out of memory");
+ return -1;
+ }
+
+ Single_Segments = single_segments;
+
+ nSegment = 0;
+ fSegment = 0;
+
+ drv_generic_text_bar_clear();
+
+ return 0;
}
void drv_generic_text_bar_add_segment(const int val1, const int val2, const DIRECTION dir, const int ascii)
{
- Segment[fSegment].val1 = val1;
- Segment[fSegment].val2 = val2;
- Segment[fSegment].dir = dir;
- if (val1 == 0 && val2 == 0)
- Segment[fSegment].style = 0;
- else
- Segment[fSegment].style = 255;
- Segment[fSegment].used = 0;
- Segment[fSegment].ascii = ascii;
-
- fSegment++;
- nSegment = fSegment;
+ Segment[fSegment].val1 = val1;
+ Segment[fSegment].val2 = val2;
+ Segment[fSegment].dir = dir;
+ if (val1 == 0 && val2 == 0)
+ Segment[fSegment].style = 0;
+ else
+ Segment[fSegment].style = 255;
+ Segment[fSegment].used = 0;
+ Segment[fSegment].ascii = ascii;
+
+ fSegment++;
+ nSegment = fSegment;
}
-static void drv_generic_text_bar_create_bar (int row, int col, const DIRECTION dir, STYLE style, int len, int val1, int val2)
+static void drv_generic_text_bar_create_bar(int row, int col, const DIRECTION dir, STYLE style, int len, int val1, int val2)
{
- int rev = 0, max;
- if (style)
- BarFB[row * LCOLS + col].style = STYLE_FIRST;
-
- switch (dir) {
- case DIR_WEST:
- max = len * XRES;
- val1 = max - val1;
- val2 = max - val2;
- rev = 1;
-
- case DIR_EAST:
- while (len > 0 && col < LCOLS) {
- BarFB[row*LCOLS+col].dir = dir;
- BarFB[row*LCOLS+col].segment = -1;
- if (style && BarFB[row * LCOLS + col].style == 0)
- BarFB[row * LCOLS + col].style = STYLE_HOLLOW;
- if (val1 >= XRES) {
- BarFB[row*LCOLS+col].val1 = rev ? 0 : XRES;
- val1 -= XRES;
- } else {
- BarFB[row*LCOLS+col].val1 = rev ? XRES-val1 : val1;
- val1 = 0;
- }
- if (val2 >= XRES) {
- BarFB[row*LCOLS+col].val2 = rev ? 0 : XRES;
- val2 -= XRES;
- } else {
- BarFB[row*LCOLS+col].val2 = rev ? XRES-val2 : val2;
- val2 = 0;
- }
- len--;
- col++;
- }
+ int rev = 0, max;
if (style)
- BarFB[row * LCOLS + col - 1].style = STYLE_LAST;
- break;
-
- case DIR_SOUTH:
- max = len * YRES;
- val1 = max - val1;
- val2 = max - val2;
- rev = 1;
-
- case DIR_NORTH:
- while (len > 0 && row < LROWS) {
- BarFB[row*LCOLS+col].dir = dir;
- BarFB[row*LCOLS+col].segment = -1;
- if (val1 >= YRES) {
- BarFB[row*LCOLS+col].val1 = rev ? 0 : YRES;
- val1 -= YRES;
- } else {
- BarFB[row*LCOLS+col].val1 = rev ? YRES-val1 : val1;
- val1 = 0;
- }
- if (val2 >= YRES) {
- BarFB[row*LCOLS+col].val2 = rev ? 0 : YRES;
- val2 -= YRES;
- } else {
- BarFB[row*LCOLS+col].val2 = rev ? YRES - val2 : val2;
- val2 = 0;
- }
- len--;
- row++;
+ BarFB[row * LCOLS + col].style = STYLE_FIRST;
+
+ switch (dir) {
+ case DIR_WEST:
+ max = len * XRES;
+ val1 = max - val1;
+ val2 = max - val2;
+ rev = 1;
+
+ case DIR_EAST:
+ while (len > 0 && col < LCOLS) {
+ BarFB[row * LCOLS + col].dir = dir;
+ BarFB[row * LCOLS + col].segment = -1;
+ if (style && BarFB[row * LCOLS + col].style == 0)
+ BarFB[row * LCOLS + col].style = STYLE_HOLLOW;
+ if (val1 >= XRES) {
+ BarFB[row * LCOLS + col].val1 = rev ? 0 : XRES;
+ val1 -= XRES;
+ } else {
+ BarFB[row * LCOLS + col].val1 = rev ? XRES - val1 : val1;
+ val1 = 0;
+ }
+ if (val2 >= XRES) {
+ BarFB[row * LCOLS + col].val2 = rev ? 0 : XRES;
+ val2 -= XRES;
+ } else {
+ BarFB[row * LCOLS + col].val2 = rev ? XRES - val2 : val2;
+ val2 = 0;
+ }
+ len--;
+ col++;
+ }
+ if (style)
+ BarFB[row * LCOLS + col - 1].style = STYLE_LAST;
+ break;
+
+ case DIR_SOUTH:
+ max = len * YRES;
+ val1 = max - val1;
+ val2 = max - val2;
+ rev = 1;
+
+ case DIR_NORTH:
+ while (len > 0 && row < LROWS) {
+ BarFB[row * LCOLS + col].dir = dir;
+ BarFB[row * LCOLS + col].segment = -1;
+ if (val1 >= YRES) {
+ BarFB[row * LCOLS + col].val1 = rev ? 0 : YRES;
+ val1 -= YRES;
+ } else {
+ BarFB[row * LCOLS + col].val1 = rev ? YRES - val1 : val1;
+ val1 = 0;
+ }
+ if (val2 >= YRES) {
+ BarFB[row * LCOLS + col].val2 = rev ? 0 : YRES;
+ val2 -= YRES;
+ } else {
+ BarFB[row * LCOLS + col].val2 = rev ? YRES - val2 : val2;
+ val2 = 0;
+ }
+ len--;
+ row++;
+ }
+ break;
}
- break;
- }
}
-static void drv_generic_text_bar_create_segments (void)
+static void drv_generic_text_bar_create_segments(void)
{
- int i, j, n;
- int res, l1, l2;
-
- /* find first unused segment */
- for (i = fSegment; i < nSegment && Segment[i].used; i++);
-
- /* pack unused segments */
- for (j = i+1; j < nSegment; j++) {
- if (Segment[j].used)
- Segment[i++] = Segment[j];
- }
- nSegment = i;
-
- /* create needed segments */
- for (n = 0; n < LROWS*LCOLS; n++) {
- if (BarFB[n].dir == 0) continue;
- res = BarFB[n].dir & (DIR_EAST|DIR_WEST) ? XRES:YRES;
- for (i = 0; i < nSegment; i++) {
+ int i, j, n;
+ int res, l1, l2;
+
+ /* find first unused segment */
+ for (i = fSegment; i < nSegment && Segment[i].used; i++);
+
+ /* pack unused segments */
+ for (j = i + 1; j < nSegment; j++) {
+ if (Segment[j].used)
+ Segment[i++] = Segment[j];
+ }
+ nSegment = i;
+
+ /* create needed segments */
+ for (n = 0; n < LROWS * LCOLS; n++) {
+ if (BarFB[n].dir == 0)
+ continue;
+ res = BarFB[n].dir & (DIR_EAST | DIR_WEST) ? XRES : YRES;
+ for (i = 0; i < nSegment; i++) {
l1 = Segment[i].val1;
if (l1 > res)
l1 = res;
@@ -725,141 +739,163 @@ static void drv_generic_text_bar_create_segments (void)
break;
/* hollow style, val(1,2) == 1, like '[' */
/* if (l1 == 1 && l2 == 1 && Segment[i].style == STYLE_FIRST && BarFB[n].style == STYLE_HOLLOW)
- break;
+ break;
*//* hollow style, val(1,2) == 1, like ']' */
/* if (l1 == 1 && l2 == 1 && Segment[i].style == STYLE_LAST && BarFB[n].style == STYLE_HOLLOW)
break;
*/ }
}
- if (i == nSegment) {
- nSegment++;
- Segment[i].val1 = BarFB[n].val1;
- Segment[i].val2 = BarFB[n].val2;
- Segment[i].dir = BarFB[n].dir;
- Segment[i].style = BarFB[n].style;
- Segment[i].used = 0;
- Segment[i].ascii = -1;
+ if (i == nSegment) {
+ nSegment++;
+ Segment[i].val1 = BarFB[n].val1;
+ Segment[i].val2 = BarFB[n].val2;
+ Segment[i].dir = BarFB[n].dir;
+ Segment[i].style = BarFB[n].style;
+ Segment[i].used = 0;
+ Segment[i].ascii = -1;
+ }
+ BarFB[n].segment = i;
}
- BarFB[n].segment = i;
- }
}
-static int drv_generic_text_bar_segment_error (const int i, const int j)
+static int drv_generic_text_bar_segment_error(const int i, const int j)
{
- int res;
- int i1, i2, j1, j2;
-
- if (i == j) return 65535;
- if (!(Segment[i].dir & Segment[j].dir)) return 65535;
- if (Segment[i].style != Segment[j].style) return 65535;
-
- res = Segment[i].dir&(DIR_EAST|DIR_WEST) ? XRES:YRES;
-
- i1 = Segment[i].val1; if (i1 > res) i1 = res;
- i2 = Segment[i].val2; if (i2 > res) i2 = res;
- j1 = Segment[j].val1; if (j1 > res) j1 = res;
- j2 = Segment[j].val2; if (j2 > res) j2 = res;
-
- if (i1 == 0 && j1 != 0) return 65535;
- if (i2 == 0 && j2 != 0) return 65535;
- if (i1 == res && j1 < res) return 65535;
- if (i2 == res && j2 < res) return 65535;
- if (i1 == 1 && j1 != 1 && i2 > 0) return 65535;
- if (i2 == 1 && j2 != 1 && j1 > 0) return 65535;
- if (i1 == i2 && j1 != j2) return 65535;
-
- return (i1-j1)*(i1-j1) + (i2-j2)*(i2-j2);
+ int res;
+ int i1, i2, j1, j2;
+
+ if (i == j)
+ return 65535;
+ if (!(Segment[i].dir & Segment[j].dir))
+ return 65535;
+ if (Segment[i].style != Segment[j].style)
+ return 65535;
+
+ res = Segment[i].dir & (DIR_EAST | DIR_WEST) ? XRES : YRES;
+
+ i1 = Segment[i].val1;
+ if (i1 > res)
+ i1 = res;
+ i2 = Segment[i].val2;
+ if (i2 > res)
+ i2 = res;
+ j1 = Segment[j].val1;
+ if (j1 > res)
+ j1 = res;
+ j2 = Segment[j].val2;
+ if (j2 > res)
+ j2 = res;
+
+ if (i1 == 0 && j1 != 0)
+ return 65535;
+ if (i2 == 0 && j2 != 0)
+ return 65535;
+ if (i1 == res && j1 < res)
+ return 65535;
+ if (i2 == res && j2 < res)
+ return 65535;
+ if (i1 == 1 && j1 != 1 && i2 > 0)
+ return 65535;
+ if (i2 == 1 && j2 != 1 && j1 > 0)
+ return 65535;
+ if (i1 == i2 && j1 != j2)
+ return 65535;
+
+ return (i1 - j1) * (i1 - j1) + (i2 - j2) * (i2 - j2);
}
-static void drv_generic_text_bar_pack_segments (void)
+static void drv_generic_text_bar_pack_segments(void)
{
- int i, j, n, min;
- int pack_i, pack_j;
- int pass1 = 1;
- int error[nSegment][nSegment];
-
- if (nSegment <= fSegment + CHARS - ICONS) {
- return;
- }
-
- for (i = 0; i < nSegment; i++) {
- for (j = 0; j < nSegment; j++) {
- error[i][j] = drv_generic_text_bar_segment_error(i, j);
+ int i, j, n, min;
+ int pack_i, pack_j;
+ int pass1 = 1;
+ int error[nSegment][nSegment];
+
+ if (nSegment <= fSegment + CHARS - ICONS) {
+ return;
}
- }
-
- while (nSegment > fSegment + CHARS - ICONS) {
-
- min = 65535;
- pack_i = -1;
- pack_j = -1;
- for (i = fSegment; i < nSegment; i++) {
- if (pass1 && Segment[i].used) continue;
- for (j = 0; j < nSegment; j++) {
- if (error[i][j] < min) {
- min = error[i][j];
- pack_i = i;
- pack_j = j;
+
+ for (i = 0; i < nSegment; i++) {
+ for (j = 0; j < nSegment; j++) {
+ error[i][j] = drv_generic_text_bar_segment_error(i, j);
}
- }
}
- if (pack_i == -1) {
- if (pass1) {
- pass1 = 0;
- continue;
- } else {
- error ("unable to compact bar characters");
- error ("nSegment=%d fSegment=%d CHARS=%d ICONS=%d", nSegment, fSegment, CHARS, ICONS);
- error ("Segment[0].val1=%d val2=%d", Segment[0].val1, Segment[0].val2);
- error ("Segment[1].val1=%d val2=%d", Segment[1].val1, Segment[1].val2);
- error ("Segment[2].val1=%d val2=%d", Segment[2].val1, Segment[2].val2);
- nSegment = CHARS - ICONS;
- break;
- }
- }
+ while (nSegment > fSegment + CHARS - ICONS) {
+
+ min = 65535;
+ pack_i = -1;
+ pack_j = -1;
+ for (i = fSegment; i < nSegment; i++) {
+ if (pass1 && Segment[i].used)
+ continue;
+ for (j = 0; j < nSegment; j++) {
+ if (error[i][j] < min) {
+ min = error[i][j];
+ pack_i = i;
+ pack_j = j;
+ }
+ }
+ }
+ if (pack_i == -1) {
+ if (pass1) {
+ pass1 = 0;
+ continue;
+ } else {
+ error("unable to compact bar characters");
+ error("nSegment=%d fSegment=%d CHARS=%d ICONS=%d", nSegment, fSegment, CHARS, ICONS);
+ error("Segment[0].val1=%d val2=%d", Segment[0].val1, Segment[0].val2);
+ error("Segment[1].val1=%d val2=%d", Segment[1].val1, Segment[1].val2);
+ error("Segment[2].val1=%d val2=%d", Segment[2].val1, Segment[2].val2);
+ nSegment = CHARS - ICONS;
+ break;
+ }
+ }
#if 0
- debug ("pack_segment: n=%d i=%d j=%d min=%d", nSegment, pack_i, pack_j, min);
- debug ("Pack_segment: i1=%d i2=%d j1=%d j2=%d\n",
- Segment[pack_i].val1, Segment[pack_i].val2,
- Segment[pack_j].val1, Segment[pack_j].val2);
+ debug("pack_segment: n=%d i=%d j=%d min=%d", nSegment, pack_i, pack_j, min);
+ debug("Pack_segment: i1=%d i2=%d j1=%d j2=%d\n", Segment[pack_i].val1, Segment[pack_i].val2, Segment[pack_j].val1, Segment[pack_j].val2);
#endif
-
- nSegment--;
- Segment[pack_i] = Segment[nSegment];
-
- for (i = 0; i < nSegment; i++) {
- error[pack_i][i] = error[nSegment][i];
- error[i][pack_i] = error[i][nSegment];
- }
-
- for (n = 0; n < LROWS * LCOLS; n++) {
- if (BarFB[n].segment == pack_i) BarFB[n].segment = pack_j;
- if (BarFB[n].segment == nSegment) BarFB[n].segment = pack_i;
+
+ nSegment--;
+ Segment[pack_i] = Segment[nSegment];
+
+ for (i = 0; i < nSegment; i++) {
+ error[pack_i][i] = error[nSegment][i];
+ error[i][pack_i] = error[i][nSegment];
+ }
+
+ for (n = 0; n < LROWS * LCOLS; n++) {
+ if (BarFB[n].segment == pack_i)
+ BarFB[n].segment = pack_j;
+ if (BarFB[n].segment == nSegment)
+ BarFB[n].segment = pack_i;
+ }
}
- }
}
static void drv_generic_text_bar_define_chars(void)
{
- int c, i, j;
- unsigned char buffer[8];
-
- for (i = fSegment; i < nSegment; i++) {
- if (Segment[i].used) continue;
- if (Segment[i].ascii != -1) continue;
- for (c = 0; c < CHARS - ICONS; c++) {
- for (j = fSegment; j < nSegment; j++) {
- if (Segment[j].ascii == c) break;
- }
- if (j == nSegment) break;
- }
- Segment[i].ascii = c;
- switch (Segment[i].dir) {
- case DIR_WEST:
+ int c, i, j;
+ unsigned char buffer[8];
+
+ for (i = fSegment; i < nSegment; i++) {
+ if (Segment[i].used)
+ continue;
+ if (Segment[i].ascii != -1)
+ continue;
+ for (c = 0; c < CHARS - ICONS; c++) {
+ for (j = fSegment; j < nSegment; j++) {
+ if (Segment[j].ascii == c)
+ break;
+ }
+ if (j == nSegment)
+ break;
+ }
+ Segment[i].ascii = c;
+ switch (Segment[i].dir) {
+ case DIR_WEST:
if (Segment[i].style) {
buffer[0] = 255;
buffer[7] = 255;
@@ -868,8 +904,8 @@ static void drv_generic_text_bar_define_chars(void)
buffer[j] |= Segment[i].style & STYLE_FIRST ? 16 : 1;
}
}
- break;
- case DIR_EAST:
+ break;
+ case DIR_EAST:
for (j = 0; j < 4; j++) {
buffer[j] = 255 << (XRES - Segment[i].val1);
buffer[j + 4] = 255 << (XRES - Segment[i].val2);
@@ -882,130 +918,141 @@ static void drv_generic_text_bar_define_chars(void)
buffer[j] |= Segment[i].style & STYLE_FIRST ? 16 : 1;
}
}
- break;
- case DIR_NORTH:
- for (j = 0; j < Segment[i].val1; j++) {
- buffer[7-j] = (1<<XRES)-1;
- }
- for (; j < YRES; j++) {
- buffer[7-j] = 0;
- }
- break;
- case DIR_SOUTH:
- for (j = 0; j < Segment[i].val1; j++) {
- buffer[j] = (1<<XRES)-1;
- }
- for (; j < YRES; j++) {
- buffer[j] = 0;
- }
- break;
- }
- drv_generic_text_real_defchar(CHAR0+c, buffer);
-
- /* maybe invalidate framebuffer */
- if (INVALIDATE) {
- for (j = 0; j < LROWS*LCOLS; j++) {
- if (BarFB[j].segment == i) {
- BarFB[j].invalid = 1;
+ break;
+ case DIR_NORTH:
+ for (j = 0; j < Segment[i].val1; j++) {
+ buffer[7 - j] = (1 << XRES) - 1;
+ }
+ for (; j < YRES; j++) {
+ buffer[7 - j] = 0;
+ }
+ break;
+ case DIR_SOUTH:
+ for (j = 0; j < Segment[i].val1; j++) {
+ buffer[j] = (1 << XRES) - 1;
+ }
+ for (; j < YRES; j++) {
+ buffer[j] = 0;
+ }
+ break;
+ }
+ drv_generic_text_real_defchar(CHAR0 + c, buffer);
+
+ /* maybe invalidate framebuffer */
+ if (INVALIDATE) {
+ for (j = 0; j < LROWS * LCOLS; j++) {
+ if (BarFB[j].segment == i) {
+ BarFB[j].invalid = 1;
+ }
+ }
}
- }
}
- }
}
-int drv_generic_text_bar_draw (WIDGET *W)
+int drv_generic_text_bar_draw(WIDGET * W)
{
- WIDGET_BAR *Bar = W->data;
- int row, col, col0, len, res, max, val1, val2;
- int c, n, s;
- DIRECTION dir;
- STYLE style;
-
- row = W->row;
- col = W->col;
- dir = Bar->direction;
- style = Bar->style;
- len = Bar->length;
-
- /* maybe grow layout framebuffer */
- /* bars *always* grow heading North or East! */
- if (dir & (DIR_EAST|DIR_WEST)) {
- drv_generic_text_resizeFB (row+1, col+len);
- } else {
- drv_generic_text_resizeFB (row+1, col+1);
- }
-
- res = dir & (DIR_EAST|DIR_WEST) ? XRES : YRES;
- max = len * res;
- val1 = Bar->val1 * (double)(max);
- val2 = Bar->val2 * (double)(max);
-
- if (val1 < 1) val1 = 1;
- else if (val1 > max) val1 = max;
-
- if (val2 < 1) val2 = 1;
- else if (val2 > max) val2 = max;
-
- if (Single_Segments) val2 = val1;
-
- /* create this bar */
- drv_generic_text_bar_create_bar (row, col, dir, style, len, val1, val2);
-
- /* process all bars */
- drv_generic_text_bar_create_segments ();
- drv_generic_text_bar_pack_segments ();
- drv_generic_text_bar_define_chars();
-
- /* reset usage flags */
- for (s = 0; s < nSegment; s++) {
- Segment[s].used = 0;
- }
-
- /* set usage flags */
- for (n = 0; n < LROWS*LCOLS; n++) {
- if ((s = BarFB[n].segment) != -1) Segment[s].used = 1;
- }
-
- /* transfer bars into layout buffer */
- for (row = 0; row < LROWS; row++) {
- for (col = 0; col < LCOLS; col++) {
- n = row*LCOLS+col;
- s = BarFB[n].segment;
- if (s == -1) continue;
- c = Segment[s].ascii;
- if (c == -1) continue;
- if (s >= fSegment) c += CHAR0; /* ascii offset for user-defineable chars */
- LayoutFB[n] = c;
- /* maybe invalidate display framebuffer */
- if (BarFB[n].invalid) {
- BarFB[n].invalid = 0;
- DisplayFB[row*DCOLS+col] = ~LayoutFB[n];
- }
+ WIDGET_BAR *Bar = W->data;
+ int row, col, col0, len, res, max, val1, val2;
+ int c, n, s;
+ DIRECTION dir;
+ STYLE style;
+
+ row = W->row;
+ col = W->col;
+ dir = Bar->direction;
+ style = Bar->style;
+ len = Bar->length;
+
+ /* maybe grow layout framebuffer */
+ /* bars *always* grow heading North or East! */
+ if (dir & (DIR_EAST | DIR_WEST)) {
+ drv_generic_text_resizeFB(row + 1, col + len);
+ } else {
+ drv_generic_text_resizeFB(row + 1, col + 1);
+ }
+
+ res = dir & (DIR_EAST | DIR_WEST) ? XRES : YRES;
+ max = len * res;
+ val1 = Bar->val1 * (double) (max);
+ val2 = Bar->val2 * (double) (max);
+
+ if (val1 < 1)
+ val1 = 1;
+ else if (val1 > max)
+ val1 = max;
+
+ if (val2 < 1)
+ val2 = 1;
+ else if (val2 > max)
+ val2 = max;
+
+ if (Single_Segments)
+ val2 = val1;
+
+ /* create this bar */
+ drv_generic_text_bar_create_bar(row, col, dir, style, len, val1, val2);
+
+ /* process all bars */
+ drv_generic_text_bar_create_segments();
+ drv_generic_text_bar_pack_segments();
+ drv_generic_text_bar_define_chars();
+
+ /* reset usage flags */
+ for (s = 0; s < nSegment; s++) {
+ Segment[s].used = 0;
+ }
+
+ /* set usage flags */
+ for (n = 0; n < LROWS * LCOLS; n++) {
+ if ((s = BarFB[n].segment) != -1)
+ Segment[s].used = 1;
}
- }
-
- /* transfer differences to the display */
- for (row = 0; row < DROWS; row++) {
- for (col = 0; col < DCOLS; col++) {
- int pos1, pos2, equal;
- if (LayoutFB[row*LCOLS+col] == DisplayFB[row*DCOLS+col]) continue;
- col0 = col;
- for (pos1 = col, pos2 = pos1, col++, equal = 0; col < DCOLS; col++) {
- if (LayoutFB[row*LCOLS+col] == DisplayFB[row*DCOLS+col]) {
- /* If we find just one equal byte, we don't break, because this */
- /* would require a goto, which takes several bytes, too. */
- if (++equal > GOTO_COST) break;
- } else {
- pos2 = col;
- equal = 0;
+
+ /* transfer bars into layout buffer */
+ for (row = 0; row < LROWS; row++) {
+ for (col = 0; col < LCOLS; col++) {
+ n = row * LCOLS + col;
+ s = BarFB[n].segment;
+ if (s == -1)
+ continue;
+ c = Segment[s].ascii;
+ if (c == -1)
+ continue;
+ if (s >= fSegment)
+ c += CHAR0; /* ascii offset for user-defineable chars */
+ LayoutFB[n] = c;
+ /* maybe invalidate display framebuffer */
+ if (BarFB[n].invalid) {
+ BarFB[n].invalid = 0;
+ DisplayFB[row * DCOLS + col] = ~LayoutFB[n];
+ }
}
- }
- memcpy ( DisplayFB+row*DCOLS+pos1, LayoutFB+row*LCOLS+pos1, pos2-pos1+1);
- drv_generic_text_real_write (row, col0, DisplayFB+row*DCOLS+pos1, pos2-pos1+1);
}
- }
-
- return 0;
+
+ /* transfer differences to the display */
+ for (row = 0; row < DROWS; row++) {
+ for (col = 0; col < DCOLS; col++) {
+ int pos1, pos2, equal;
+ if (LayoutFB[row * LCOLS + col] == DisplayFB[row * DCOLS + col])
+ continue;
+ col0 = col;
+ for (pos1 = col, pos2 = pos1, col++, equal = 0; col < DCOLS; col++) {
+ if (LayoutFB[row * LCOLS + col] == DisplayFB[row * DCOLS + col]) {
+ /* If we find just one equal byte, we don't break, because this */
+ /* would require a goto, which takes several bytes, too. */
+ if (++equal > GOTO_COST)
+ break;
+ } else {
+ pos2 = col;
+ equal = 0;
+ }
+ }
+ memcpy(DisplayFB + row * DCOLS + pos1, LayoutFB + row * LCOLS + pos1, pos2 - pos1 + 1);
+ drv_generic_text_real_write(row, col0, DisplayFB + row * DCOLS + pos1, pos2 - pos1 + 1);
+ }
+ }
+
+ return 0;
}