home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Professional
/
OS2PRO194.ISO
/
os2
/
editor
/
me
/
linedraw.m
< prev
next >
Wrap
Text File
|
1994-01-31
|
5KB
|
249 lines
#include "mekeys.h"
#define ERR (-1)
#define DIR_UP 0
#define DIR_DOWN 1
#define DIR_LEFT 2
#define DIR_RIGHT 3
#define MODE_SINGLE 1
#define MODE_DOUBLE 2
string DefaultGraphics[4];
string OverwriteGraphic[11];
int LineMode;
init()
{
assign_key("drawline", "<ALT-D>");
DefaultGraphics[DIR_UP+1] = "││┐┌";
DefaultGraphics[DIR_DOWN+1] = "││┘└";
DefaultGraphics[DIR_LEFT+1] = "└┌──";
DefaultGraphics[DIR_RIGHT+1] = "┘┐──";
OverwriteGraphic[1] = "┼┬┬┬┴┼┴┴┴┬──┴┬──";
OverwriteGraphic[2] = "││┤├││┤├├├┼├┤┤┤┼";
OverwriteGraphic[3] = "├┌┬┌├├┬├├┌├┌┼┬┬┬";
OverwriteGraphic[4] = "┼┬┬┬┼┼┼┼┼┬┬┬┼┬┬┬";
OverwriteGraphic[5] = "┤┐┐┬┤┤┤┬┼┬┬┬┤┐┐┬";
OverwriteGraphic[6] = "├├┼├├├┼├├├┼├┼┼┼┼";
OverwriteGraphic[7] = "┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼";
OverwriteGraphic[8] = "┤┤┤┼┤┤┤┼┼┼┼┼┤┤┤┼";
OverwriteGraphic[9] = "├├┼├└├┴└└├┴└┴┼┴┴";
OverwriteGraphic[10] = "┼┼┼┼┴┼┴┴┴┼┴┴┴┼┴┴";
OverwriteGraphic[11] = "┤┤┤┼┘┤┘┴┴┼┴┴┘┤┘┴";
LineMode = MODE_SINGLE;
}
drawline()
{
int iOldDirection, iNewDirection;
iOldDirection = ERR;
setprompt(2);
debug = 1;
while (1)
{
start:
if (LineMode == MODE_SINGLE)
szMode = "Single";
else if (LineMode == MODE_DOUBLE)
szMode = "Double";
message("%s-line drawing mode...", szMode);
s = "";
key = get_tty_char();
switch (key)
{
case _UP :
iNewDirection = DIR_UP;
break;
case _DOWN :
iNewDirection = DIR_DOWN;
break;
case _LEFT :
iNewDirection = DIR_LEFT;
break;
case _RIGHT:
iNewDirection = DIR_RIGHT;
break;
case '1' :
LineMode = MODE_SINGLE;
/* continue; */
goto start;
case '2' :
LineMode = MODE_DOUBLE;
/* continue; */
goto start;
case ESC :
get_tty_str("Thanks for coming!");
return;
default :
bell();
/* continue; */
goto start;
}
/*
See if the character overwritten is another line graphic character
*/
if ((chCurrGraphic = index("─│┌┬┐├┼┤└┴┘═║╔╦╗╠╬╣╚╩╝", chr(currchar()))) >= 1)
{
chCurrGraphic = (chCurrGraphic / 12) + (chCurrGraphic % 12);
if (debug)
get_tty_str("chCurrGraphic is [%d]", chCurrGraphic);
if ((s = MaybeCorner(iOldDirection, iNewDirection)) == "")
{
s = OverwriteGraphic[chCurrGraphic];
s = substr(s, iOldDirection*4 + iNewDirection + 1, 1);
}
}
else
{
/*
We are not overwriting an existing graphic.
*/
if (iOldDirection == ERR)
iOldDirection = iNewDirection;
szGraphics = DefaultGraphics[iOldDirection+1];
s = substr(szGraphics, iNewDirection+1, 1);
if (debug)
get_tty_str("szGraphics is %s and s is %s", szGraphics, s);
}
if (s != "")
{
if (currchar())
delchar();
insert(GraphicTranslate(tonum(s)));
refresh();
}
switch (key)
{
case _UP :
col = currcol()-1;
up();
setcol(col);
break;
case _DOWN :
col = currcol()-1;
if (currlinenum() == lastlinenum())
append_line();
else
down();
setcol(col);
break;
case _LEFT :
left();
if (currcol() > 1)
left();
break;
case _RIGHT :
break;
default :
/* continue; */
goto start;
}
iOldDirection = iNewDirection;
} /* end while */
}
MaybeCorner(iOld, iNew)
{
chAbove = chBelow = chRight = chLeft = 0;
if (up())
{
chAbove = currchar();
down();
}
if (down())
{
chBelow = currchar();
up();
}
if (currcol() > 1)
{
left();
chLeft = currchar();
right();
}
right();
chRight = currchar();
left();
dir = iOld * 4 + iNew;
if (dir == 2 || dir == 13)
{
/* UP and LEFT or RIGHT and DOWN */
if (chAbove == 0 && chRight == 0)
return "┐";
}
else if (dir == 3 || dir == 9)
{
/* UP and RIGHT or LEFT and DOWN */
if (chAbove == 0 && chLeft == 0)
return "┌";
}
else if (dir == 6 || dir == 12)
{
/* DOWN and LEFT or RIGHT and UP */
if (chBelow == 0 && chRight == 0)
return "┘";
}
else if (dir == 7 || dir == 8)
{
/* DOWN and RIGHT or LEFT and UP */
if (chBelow == 0 && chLeft == 0)
return "└";
}
return "";
}
GraphicTranslate(chGraphic)
{
switch (chGraphic)
{
case '─':
return substr("─═", LineMode, 1);
case '│':
return substr("│║", LineMode, 1);
case '┌':
return substr("┌╔", LineMode, 1);
case '┬':
return substr("┬╦", LineMode, 1);
case '┐':
return substr("┐╗", LineMode, 1);
case '├':
return substr("├╠", LineMode, 1);
case '┼':
return substr("┼╬", LineMode, 1);
case '┤':
return substr("┤╣", LineMode, 1);
case '└':
return substr("└╚", LineMode, 1);
case '┴':
return substr("┴╩", LineMode, 1);
case '┘':
return substr("┘╝", LineMode, 1);
}
}