home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 5 Edit
/
05-Edit.zip
/
p2demo21.exe
/
PEL
/
LINEDRAW.PEL
< prev
next >
Wrap
Text File
|
1995-03-13
|
17KB
|
568 lines
# $Header: P:\source\wmacros\linedraw.pev 1.7 13 Mar 1995 13:17:54 PFHDWM0 $
##############################################################################
#
# Compuware Corporation
# 31440 Northwestern Highway
# Farmington Hills, Michigan 48334-2564
#
# This source code listing contains information that is
# proprietary to Compuware Corporation and may not be copied
# duplicated, translated, transmitted, stored, retrieved
# or in any manner or by any method conveyed or disclosed
# to a third party or parties without express written
# permission from Compuware Corporation.
#
#
##############################################################################
#### $Workfile: linedraw.pel $: Line drawing binding code
#
#
#
# The function linedraw() is used to enable 'line drawing' mode by executing
# the function toggle_drawing() with a line style. Once activated the Numpad
# arrow keys will be changed to draw lines. An optional parameter to
# toggle_drawing() sets the style of line drawing characters to one of 4
# styles (default is style 1). This version differs from the original Sage
# editor in that the changes to the Numpad arrow keys are global instead of
# being restricted to the current buffer. Invoking toggle_drawing() a second
# time with no parameters, or linedraw() with a 0 (zero) parameter turns off
# line drawing and restores the original Numpad keys.
#
# The function linedraw() prompts for a style if one is not provided and can
# be assigned to a key.
#
# The keys defined are:
# Num Left, Right, Up and Down: insert linedraw character and move in
# specified direction.
# Num 5: insert arrow pointing in the last used direction.
# Ctrl-Num-Left, Right, Up and Down: insert arrow character pointing in the
# specified direction, then move.
#
local ld_Keymap = 0;
local up_array
local down_array
local left_array
local right_array
local arrow_array
local last_dir = 4
local t_char_array
local b_char_array
local r_char_array
local l_char_array
local VERT_C = 1
local HORZ_C = 2
local NO_C = 0
local TOP_C = 1
local LEFT_C = 2
local BOT_C = 4
local RIGHT_C = 8
global function linedraw( style )
{
if (argcount() < 1)
style = prompt("Select style: 1 = ─┼─, 2 = ▀█▀, 3 = -+-, 4 = ═╬═: ", "1",
"linedraw_dialog");
if (style != "") # style will be NULL string for escape.
{
if (style+0 >= 0 && style+0 < 5)
toggle_drawing( style );
else
notify("Invalid linedrawing style selected")
}
}
#
# init_lines() sets the characters for the type of lines to be drawn.
#
# The line styles are determined by borderStyle in the following manner:
#
# 1 2 3 4
# ┌───┬───┐ █▀▀▀█▀▀▀█ +---+---+ ╔═══╦═══╗
# │ │ │ █ █ █ | | | ║ ║ ║
# ├───┼───┤ █▀▀▀█▀▀▀█ +---+---+ ╠═══╬═══╣
# │ │ │ █ █ █ | | | ║ ║ ║
# └───┴───┘ ▀▀▀▀▀▀▀▀▀ +---+---+ ╚═══╩═══╝
#
local function init_lines( borderStyle )
{
local v_bar = 179 # │
local h_bar = 196 # ─
local tl_corner = 218 # ┌
local tr_corner = 191 # ┐
local ll_corner = 192 # └
local lr_corner = 217 # ┘
local x_inter = 197 # ┼
local t_inter = 193 # ┴
local b_inter = 194 # ┬
local l_inter = 180 # ┤
local r_inter = 195 # ├
if (borderStyle == 2)
{
# v_bar = 179 # │
# h_bar = 205 # ═
# tl_corner = 213 # ╒
# tr_corner = 184 # ╕
# ll_corner = 212 # ╘
# lr_corner = 190 # ╛
# x_inter = 216 # ╪
# t_inter = 207 # ╧
# b_inter = 209 # ╤
# l_inter = 181 # ╡
# r_inter = 198 # ╞
v_bar = 219 # █
h_bar = 223 # ▀
tl_corner = 219
tr_corner = 219
ll_corner = 223
lr_corner = 223
x_inter = 219
t_inter = 223
b_inter = 219
l_inter = 219
r_inter = 219
}
else if (borderStyle == 3)
{
# v_bar = 186 # ║
# h_bar = 196 # ─
# tl_corner = 214 # ╓
# tr_corner = 183 # ╖
# ll_corner = 211 # ╙
# lr_corner = 189 # ╜
# x_inter = 215 # ╫
# t_inter = 208 # ╨
# b_inter = 210 # ╥
# l_inter = 182 # ╢
# r_inter = 199 # ╟
v_bar = 124 # ║
h_bar = 45 # ─
tl_corner = 43 # ╓
tr_corner = 43 # ╖
ll_corner = 43 # ╙
lr_corner = 43 # ╜
x_inter = 43 # ╫
t_inter = 43 # ╨
b_inter = 43 # ╥
l_inter = 43 # ╢
r_inter = 43 # ╟
}
else if (borderStyle == 4)
{
v_bar = 186 # ║
h_bar = 205 # ═
tl_corner = 201 # ╔
tr_corner = 187 # ╗
ll_corner = 200 # ╚
lr_corner = 188 # ╝
x_inter = 206 # ╬
t_inter = 202 # ╩
b_inter = 203 # ╦
l_inter = 185 # ╣
r_inter = 204 # ╠
}
else
{
v_bar = 179 # │
h_bar = 196 # ─
tl_corner = 218 # ┌
tr_corner = 191 # ┐
ll_corner = 192 # └
lr_corner = 217 # ┘
x_inter = 197 # ┼
t_inter = 193 # ┴
b_inter = 194 # ┬
l_inter = 180 # ┤
r_inter = 195 # ├
}
arrow_array[1] = 30 # up
arrow_array[2] = 31 # down
arrow_array[3] = 17 # left
arrow_array[4] = 16 # right
up_array[ chr(h_bar) ] = HORZ_C;
up_array[ chr(v_bar) ] = VERT_C;
up_array[ chr(tl_corner) ] = VERT_C;
up_array[ chr(tr_corner) ] = VERT_C;
up_array[ chr(ll_corner) ] = HORZ_C;
up_array[ chr(lr_corner) ] = HORZ_C;
up_array[ chr(x_inter) ] = VERT_C;
up_array[ chr(t_inter) ] = HORZ_C;
up_array[ chr(b_inter) ] = VERT_C;
up_array[ chr(l_inter) ] = VERT_C;
up_array[ chr(r_inter) ] = VERT_C;
down_array[ chr(h_bar) ] = HORZ_C;
down_array[ chr(v_bar) ] = VERT_C;
down_array[ chr(tl_corner) ] = HORZ_C;
down_array[ chr(tr_corner) ] = HORZ_C;
down_array[ chr(ll_corner) ] = VERT_C;
down_array[ chr(lr_corner) ] = VERT_C;
down_array[ chr(x_inter) ] = VERT_C;
down_array[ chr(t_inter) ] = VERT_C;
down_array[ chr(b_inter) ] = HORZ_C;
down_array[ chr(l_inter) ] = VERT_C;
down_array[ chr(r_inter) ] = VERT_C;
left_array[ chr(h_bar) ] = HORZ_C;
left_array[ chr(v_bar) ] = VERT_C;
left_array[ chr(tl_corner) ] = HORZ_C;
left_array[ chr(tr_corner) ] = VERT_C;
left_array[ chr(ll_corner) ] = HORZ_C;
left_array[ chr(lr_corner) ] = VERT_C;
left_array[ chr(x_inter) ] = HORZ_C;
left_array[ chr(t_inter) ] = HORZ_C;
left_array[ chr(b_inter) ] = HORZ_C;
left_array[ chr(l_inter) ] = VERT_C;
left_array[ chr(r_inter) ] = HORZ_C;
right_array[ chr(h_bar) ] = HORZ_C;
right_array[ chr(v_bar) ] = VERT_C;
right_array[ chr(tl_corner) ] = VERT_C;
right_array[ chr(tr_corner) ] = HORZ_C;
right_array[ chr(ll_corner) ] = VERT_C;
right_array[ chr(lr_corner) ] = HORZ_C;
right_array[ chr(x_inter) ] = HORZ_C;
right_array[ chr(t_inter) ] = HORZ_C;
right_array[ chr(b_inter) ] = HORZ_C;
right_array[ chr(l_inter) ] = HORZ_C;
right_array[ chr(r_inter) ] = VERT_C;
t_char_array[ 0 ] = v_bar # "│"
t_char_array[ 1 ] = v_bar # "│"
t_char_array[ 2 ] = lr_corner # "┘"
t_char_array[ 3 ] = lr_corner # "┘"
t_char_array[ 4 ] = v_bar # "│"
t_char_array[ 5 ] = v_bar # "│"
t_char_array[ 6 ] = l_inter # "┤"
t_char_array[ 7 ] = l_inter # "┤"
t_char_array[ 8 ] = ll_corner # "└"
t_char_array[ 9 ] = ll_corner # "└"
t_char_array[ 10 ] = t_inter # "┴"
t_char_array[ 11 ] = t_inter # "┴"
t_char_array[ 12 ] = r_inter # "├"
t_char_array[ 13 ] = r_inter # "├"
t_char_array[ 14 ] = x_inter # "┼"
t_char_array[ 15 ] = x_inter # "┼"
l_char_array[ 0 ] = h_bar # "─"
l_char_array[ 1 ] = lr_corner # "┘"
l_char_array[ 2 ] = h_bar # "─"
l_char_array[ 3 ] = lr_corner # "┘"
l_char_array[ 4 ] = tr_corner # "┐"
l_char_array[ 5 ] = l_inter # "┤"
l_char_array[ 6 ] = tr_corner # "┐"
l_char_array[ 7 ] = l_inter # "┤"
l_char_array[ 8 ] = h_bar # "─"
l_char_array[ 9 ] = t_inter # "┴"
l_char_array[ 10 ] = h_bar # "─"
l_char_array[ 11 ] = t_inter # "┴"
l_char_array[ 12 ] = b_inter # "┬"
l_char_array[ 13 ] = x_inter # "┼"
l_char_array[ 14 ] = b_inter # "┬"
l_char_array[ 15 ] = x_inter # "┼"
b_char_array[ 0 ] = v_bar # "│"
b_char_array[ 1 ] = v_bar # "│"
b_char_array[ 2 ] = tr_corner # "┐"
b_char_array[ 3 ] = l_inter # "┤"
b_char_array[ 4 ] = v_bar # "│"
b_char_array[ 5 ] = v_bar # "│"
b_char_array[ 6 ] = tr_corner # "┐"
b_char_array[ 7 ] = l_inter # "┤"
b_char_array[ 8 ] = tl_corner # "┌"
b_char_array[ 9 ] = r_inter # "├"
b_char_array[ 10 ] = b_inter # "┬"
b_char_array[ 11 ] = x_inter # "┼"
b_char_array[ 12 ] = tl_corner # "┌"
b_char_array[ 13 ] = r_inter # "├"
b_char_array[ 14 ] = b_inter # "┬"
b_char_array[ 15 ] = x_inter # "┼"
r_char_array[ 0 ] = h_bar # "─"
r_char_array[ 1 ] = ll_corner # "└"
r_char_array[ 2 ] = h_bar # "─"
r_char_array[ 3 ] = t_inter # "┴"
r_char_array[ 4 ] = tl_corner # "┌"
r_char_array[ 5 ] = r_inter # "├"
r_char_array[ 6 ] = b_inter # "┬"
r_char_array[ 7 ] = x_inter # "┼"
r_char_array[ 8 ] = h_bar # "─"
r_char_array[ 9 ] = ll_corner # "└"
r_char_array[ 10 ] = h_bar # "─"
r_char_array[ 11 ] = t_inter # "┴"
r_char_array[ 12 ] = tl_corner # "┌"
r_char_array[ 13 ] = r_inter # "├"
r_char_array[ 14 ] = b_inter # "┬"
r_char_array[ 15 ] = x_inter # "┼"
}
#
# getlevel()
# This function checks the characters in the buffer surrounding the
# one to be drawn to see if any of them are also linedrawing characters.
# This info is used to determine if a junction or corner character
# should be drawn.
#
local function getlevel()
{
local ch1 = "" # char above
local ch2 = "" # char to the left
local ch3 = "" # char below
local ch4 = "" # char to the right
local cc;
local level = NO_C; # 0 = no surrounding character
# 1 = top char needs to connect
# 2 = left char needs to connect
# 4 = bottom char needs to connect
# 8 = right char needs to connect
if ( up() )
{
ch1 = read_buffer( 1 );
down();
}
if ( left() )
{
ch2 = read_buffer( 1 );
right()
}
cc = current_column;
if ( down() )
{
if (current_column == cc )
ch3 = read_buffer( 1 );
up();
}
current_column = cc;
if ( right() )
{
ch4 = read_buffer( 1 );
left();
}
if (ch1 in up_array)
if (up_array[ ch1 ] == VERT_C)
level += TOP_C
if (ch2 in left_array)
if (left_array[ ch2 ] == HORZ_C)
level += LEFT_C
if (ch3 in down_array)
if (down_array[ ch3 ] == VERT_C)
level += BOT_C
if (ch4 in right_array)
if (right_array[ ch4 ] == HORZ_C)
level += RIGHT_C
return level;
}
#
# ld_move(dir, arrow_flag)
#
# dir: 1 = up, 2 = down, 3 = left, 4 = right, 0 = last
# arrow_flag: 1 = draw arrow, 0 = draw line
#
global function ld_move(dir, arrow_flag)
{
local flags = reset_buffer_flags();
if (!dir)
dir = last_dir # default move right
else
last_dir = dir
if (dir == 1)
{
insert_key( arrow_flag ? arrow_array[dir] : t_char_array[ getlevel() ] );
left(1);
up(1);
}
else if (dir == 2)
{
insert_key( arrow_flag ? arrow_array[dir] : b_char_array[ getlevel() ] );
ld_down()
}
else if (dir == 3)
{
insert_key( arrow_flag ? arrow_array[dir] : l_char_array[ getlevel() ] );
left( 2 );
}
else if (dir == 4)
{
insert_key( arrow_flag ? arrow_array[dir] : r_char_array[ getlevel() ] );
}
else
beep()
reset_buffer_flags( flags );
}
local function ld_down()
{
local cc;
left(1);
cc = current_column;
if (!down(1) || cc != current_column)
{ # allow drawing past eof
save_position();
goto_eol();
insert_newline();
restore_position( 1 );
down(1);
}
current_column = cc;
}
#
# reset_buffer_flags()
#
# Sets the required buffer flags for line drawing mode and
# returns the current flags so they can be reset later.
# This function is called by all the motion keys so that the flags
# are always set properly.
#
local function reset_buffer_flags( bf )
{
local flags;
if (argcount())
{
buffer_flags = or(and( buffer_flags,
not(BUFFER_TABS_TO_SPACES + BUFFER_OVERTYPE_MODE)),
bf );
}
else
{
flags = and( buffer_flags,
BUFFER_TABS_TO_SPACES +
BUFFER_OVERTYPE_MODE +
BUFFER_WP_ENABLED +
BUFFER_REAL_SPACE_ONLY +
BUFFER_SNAP_TO_EOL );
buffer_flags = and(buffer_flags, not( flags ));
buffer_flags = or(buffer_flags,
BUFFER_TABS_TO_SPACES + BUFFER_OVERTYPE_MODE);
return flags;
}
}
#
# toggle_drawing()
#
# toggles the line drawing capability assigned to
# the shift-arrow keys. The lineStyle parameter is passed on to init_lines
# if it is different from the last call.
#
global function toggle_drawing( style )
{
local ld_lineStyle = 0 # set to 1 - 4 to choose style
local inLineDrawMode = 0 # set to 1 if we are activating line
# drawing mode.
# If no line drawing keymap created then make one based on the
# current keymap with the numpad arrow keys reassigned.
# When line drawing mode is active, this keymap will be used
# for all buffers.
if (!ld_Keymap)
{
# Create a new keymap intilized from the current_keymap
# Set current keymap to the newly created map and assign
# new key values. Then reset the current_keymap.
ld_Keymap = create_keymap( current_keymap );
if( ld_Keymap )
{
push_keymap( ld_Keymap );
# Assign Keys
assign_key( "<Num-Up>", "ld_move 1" );
assign_key( "<Num-Down>", "ld_move 2" );
assign_key( "<Num-Left>", "ld_move 3" );
assign_key( "<Num-Right>", "ld_move 4" );
assign_key( "<Num-5>", "ld_move 0 1" );
assign_key( "<Ctrl-Num-Up>", "ld_move 1 1" );
assign_key( "<Ctrl-Num-Down>", "ld_move 2 1" );
assign_key( "<Ctrl-Num-Left>", "ld_move 3 1" );
assign_key( "<Ctrl-Num-Right>", "ld_move 4 1" );
pop_keymap()
}
}
#
# get the current line drawing mode.
# inLineDrawMode is assigned 0 or 1
#
inLineDrawMode = (ld_Keymap == current_keymap);
#
# toggle or set the mode
#
if( argcount() < 1 )
{
inLineDrawMode = !inLineDrawMode; # toggle the mode value
}
else if (style == 0)
{
inLineDrawMode = 0;
}
else
{
inLineDrawMode = 1;
ld_lineStyle = 0+style;
}
if ( !inLineDrawMode )
{
# If we are deactivating line drawing, and the current keymap
# is the line drawing keymap, then restore the original keymap
if (current_keymap == ld_Keymap)
pop_keymap();
notify( "Line drawing keys inactive. ");
beep();
}
else
{
# If we are activating line drawing, and it is not already
# active, save the current keymap and make the line drawing
# keymap current.
if (!ld_Keymap)
{
warning("Invalid line drawing keymap")
}
else
{
if (current_keymap != ld_Keymap)
push_keymap( ld_Keymap );
# Set the line style
init_lines( ld_lineStyle );
notify( "Line drawing keys active. ");
beep();
}
}
}