cmenu: fix menu separators
authorPierre-Alexandre Meyer <pierre@mouraf.org>
Sun, 30 Aug 2009 03:53:38 +0000 (20:53 -0700)
committerPierre-Alexandre Meyer <pierre@mouraf.org>
Tue, 1 Sep 2009 18:43:38 +0000 (11:43 -0700)
Use the alternate character set to draw horizontal lines (menu
separator). Refactor the c*print functions in the same time as they
were severely broken.

Signed-off-by: Pierre-Alexandre Meyer <pierre@mouraf.org>
com32/cmenu/libmenu/com32io.c
com32/cmenu/libmenu/com32io.h
com32/cmenu/libmenu/menu.c
com32/cmenu/libmenu/tui.c
com32/cmenu/libmenu/tui.h

index f59baeb..60789f8 100644 (file)
@@ -13,6 +13,7 @@
 #include <string.h>
 #include <com32.h>
 #include "com32io.h"
+#include "tui.h"
 #include "syslnx.h"
 
 com32sys_t inreg, outreg;      // Global register sets for use
@@ -71,6 +72,14 @@ void cprint(char chr, char attr, unsigned int times, char disppage)
                cprint_vga2ansi(chr, attr);
 }
 
+void csprint(const char *str, char attr)
+{
+       while (*str) {
+               cprint(*str, attr, 1, 0);
+               str++;
+       }
+}
+
 void setdisppage(char num)     // Set the display page to specified number
 {
     REG_AH(inreg) = 0x05;
index a73b9f3..938ecee 100644 (file)
@@ -30,16 +30,18 @@ static inline beep()
 
 /* BIOS Assisted output routines */
 
-void cswprint(const char *str, char attr, char left);
 // Print a C str (NUL-terminated) respecting the left edge of window
 // i.e. \n in str will move cursor to column left
 // Print a C str (NUL-terminated)
 
-static inline void csprint(const char *str, char attr)
+void csprint(const char *str, char attr);
+
+static inline void cswprint(const char *str, char attr, char left)
 {
-    cswprint(str, attr, 0);
+       csprint(str, attr);
 }
 
+
 void cprint(char chr, char attr, unsigned int times, char disppage);   // Print a char
 
 void setdisppage(char num);    // Set the display page to specified number
index a00c0ce..03e8367 100644 (file)
@@ -148,10 +148,10 @@ void printmenu(pt_menu menu, int curr, uchar top, uchar left, uchar first)
 {
     int x, row;                        // x = index, row = position from top
     int numitems, menuwidth;
-    char fchar[5], lchar[5];   // The first and last char in for each entry
+    char fchar[6], lchar[6];   // The first and last char in for each entry
     const char *str;           // and inbetween the item or a seperator is printed
+       char sep[MENULEN];      // Separator (OPT_SEP)
     uchar *attr;               // attribute attr
-    char sep[MENULEN];         // and inbetween the item or a seperator is printed
     pt_menuitem ci;
 
     numitems = calc_visible(menu, first);
@@ -163,8 +163,6 @@ void printmenu(pt_menu menu, int curr, uchar top, uchar left, uchar first)
                ms->menupage, ms->fillchar, ms->shadowattr);
     drawbox(top - 1, left - 3, top + numitems, left + menuwidth,
            ms->menupage, ms->normalattr[NOHLITE], ms->menubt);
-    memset(sep, ms->box_horiz, menuwidth);     // String containing the seperator string
-    sep[menuwidth - 1] = 0;
     // Menu title
     x = (menuwidth - strlen(menu->title) - 1) >> 1;
     gotoxy(top - 1, left + x, ms->menupage);
@@ -200,18 +198,22 @@ void printmenu(pt_menu menu, int curr, uchar top, uchar left, uchar first)
            lchar[1] = 0;
            break;
        case OPT_SEP:
-           fchar[0] = '\b';
-           fchar[1] = ms->box_ltrt;
-           fchar[2] = ms->box_horiz;
-           fchar[3] = ms->box_horiz;
-           fchar[4] = 0;
-           lchar[0] = ms->box_horiz;
-           lchar[1] = ms->box_rtlt;
-           lchar[2] = 0;
-           str = sep;
-           break;
+               fchar[0] = '\b';
+               fchar[1] = SO;
+               fchar[2] = LEFT_MIDDLE_BORDER;
+               fchar[3] = MIDDLE_BORDER;
+               fchar[4] = MIDDLE_BORDER;
+               fchar[5] = 0;
+               memset(sep, MIDDLE_BORDER, menuwidth);
+               sep[menuwidth - 1] = 0;
+               str = sep;
+               lchar[0] = MIDDLE_BORDER;
+               lchar[1] = RIGHT_MIDDLE_BORDER;
+               lchar[2] = SI;
+               lchar[3] = 0;
+               break;
        case OPT_EXITMENU:
-           fchar[0] = EXITMENUCHAR;
+           fchar[0] = '<';
            fchar[1] = 0;
            break;
        default:                // Just to keep the compiler happy
@@ -224,7 +226,7 @@ void printmenu(pt_menu menu, int curr, uchar top, uchar left, uchar first)
        gotoxy(top + row, left, ms->menupage);
        printmenuitem(str, attr);       // Print main part
        gotoxy(top + row, left + menuwidth - 1, ms->menupage);  // Last char if any
-       fputs(lchar, stdout);   // Print last part
+       csprint(lchar, attr[NOHLITE]);  // Print first part
     }
     // Check if we need to MOREABOVE and MOREBELOW to be added
     // reuse x
index d4e0828..a8ca1cd 100644 (file)
@@ -212,43 +212,6 @@ void getuserinput(char *stra, unsigned int size, unsigned int password,
     free(str);
 }
 
-/* Print a C string (NUL-terminated) */
-void cswprint(const char *str, char attr, char left)
-{
-    char page = getdisppage();
-    char newattr = 0, cha, chb;
-
-    while (*str) {
-       switch (*str) {
-       case BELL:              // Bell Char
-           beep();
-           break;
-       case CHRELATTR: // change attribute (relatively)
-       case CHABSATTR: // change attribute (absolute)
-           cha = *(str + 1);
-           chb = *(str + 2);
-           if ((((cha >= '0') && (cha <= '9')) || ((cha >= 'A') && (cha <= 'F'))) && (((chb >= '0') && (chb <= '9')) || ((chb >= 'A') && (chb <= 'F'))))       // Next two chars are legal
-           {
-               if ((cha >= 'A') && (cha <= 'F'))
-                   cha = cha - 'A' + 10;
-               else
-                   cha = cha - '0';
-               if ((chb >= 'A') && (chb <= 'F'))
-                   chb = chb - 'A' + 10;
-               else
-                   chb = chb - '0';
-               newattr = (cha << 4) + chb;
-               attr = (*str == CHABSATTR ? newattr : attr ^ newattr);
-               str += 2;       // Will be incremented again later
-           }
-           break;
-       default:
-               cprint(*str, attr, 1, page);
-       }
-       str++;
-    }
-}
-
 void clearwindow(char top, char left, char bot, char right, char page,
                 char fillchar, char fillattr)
 {
@@ -345,11 +308,13 @@ void drawhorizline(char top, char left, char right, char page, char attr,
        end = right;
     }
     gotoxy(top, start, page);
-    cprint(box_chars[BOX_HORIZ], attr, end - start + 1, page);
+       putchar(SO);
+    cprint(MIDDLE_BORDER, attr, end - start + 1, page);
     if (dumb == 0) {
        gotoxy(top, left, page);
-       cprint(box_chars[BOX_LTRT], attr, 1, page);
+       cprint(MIDDLE_BORDER, attr, 1, page);
        gotoxy(top, right, page);
-       cprint(box_chars[BOX_RTLT], attr, 1, page);
+       cprint(MIDDLE_BORDER, attr, 1, page);
     }
+       putchar(SI);
 }
index 5cf5dd7..54bce86 100644 (file)
@@ -33,6 +33,9 @@
 #define BOTTOM_RIGHT_CORNER_BORDER '\152'
 #define LEFT_BORDER '\170'
 #define RIGHT_BORDER '\170'
+#define LEFT_MIDDLE_BORDER '\164'
+#define MIDDLE_BORDER '\161'
+#define RIGHT_MIDDLE_BORDER '\165'
 
 #define BELL 0x07
 // CHRELATTR = ^N, CHABSATTR = ^O