home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 January
/
usenetsourcesnewsgroupsinfomagicjanuary1994.iso
/
sources
/
x
/
volume8
/
xfig2.8
/
part03
/
char.c
next >
Wrap
C/C++ Source or Header
|
1990-07-02
|
4KB
|
161 lines
/*
* FIG : Facility for Interactive Generation of figures
*
* Copyright (c) 1988 by Supoj Sutanthavibul (supoj@sally.UTEXAS.EDU)
* Febuary 1988.
*
* %W% %G%
*/
#include "fig.h"
#include "resources.h"
#include "font.h"
#include "paintop.h"
#include "object.h"
extern int cur_x, cur_y;
extern int cur_font, cur_fontsize;
extern int cur_textjust;
#define BLINK_INTERVAL 700 /* milliseconds blink rate */
#define BUF_SIZE 400
char prefix[BUF_SIZE], /* part of string left of mouse click */
suffix[BUF_SIZE]; /* part to right of click */
int leng_prefix, leng_suffix;
static PIXWIN pw;
static int char_ht;
static int char_received;
static int cbase_x, cbase_y;
static float rbase_x, rcur_x;
static int obase_x;
static (*cr_proc)();
static
draw_cursor(x, y)
int x, y;
{
pw_vector(pw, x, y, x, y-char_ht, INV_PAINT, 1, SOLID_LINE, 0.0);
}
initialize_char_handler(p, cr, bx, by)
PIXWIN p;
int (*cr)();
int bx, by;
{
pw = p;
cr_proc = cr;
rbase_x = obase_x = cbase_x = bx; /* keep real base so dont have roundoff */
rcur_x = cur_x;
cbase_y = by;
char_ht = char_height(canvas_font);
char_received = 0;
turn_on_blinking_cursor(draw_cursor, draw_cursor,
cur_x, cur_y, (long)BLINK_INTERVAL);
}
terminate_char_handler()
{
turn_off_blinking_cursor();
cr_proc = NULL;
return(char_received);
}
erase_char_string()
{
pw_text(pw, cbase_x, cbase_y, INV_PAINT,
cur_font, cur_fontsize, prefix);
if (leng_suffix)
pw_text(pw, cur_x, cbase_y, INV_PAINT,
cur_font, cur_fontsize, suffix);
}
draw_char_string()
{
pw_text(pw, cbase_x, cbase_y, INV_PAINT,
cur_font, cur_fontsize, prefix);
if (leng_suffix)
pw_text(pw, cur_x, cbase_y, INV_PAINT,
cur_font, cur_fontsize, suffix);
move_blinking_cursor(cur_x, cur_y);
}
char_handler(c)
unsigned char c;
{
int cwidth;
if (cr_proc == NULL)
return;
if (c == CR) {
erase_char_string();
cr_proc();
}
else if (c == DEL || c == CTRL_H) {
if (leng_prefix > 0) {
erase_char_string();
char_received = 1;
cwidth = char_advance(canvas_font,prefix[leng_prefix-1]);
if (cur_textjust == T_LEFT_JUSTIFIED)
rcur_x -= cwidth; /* move the suffix to the left */
else if (cur_textjust == T_CENTER_JUSTIFIED)
{
rbase_x += cwidth/2.0; /* advance right by half cwidth */
rcur_x -= cwidth/2.0; /* move suffix left half cwidth */
}
if (cur_textjust == T_RIGHT_JUSTIFIED)
rbase_x += (float) cwidth; /* move the prefix to the right */
prefix[--leng_prefix] = '\0';
cbase_x = rbase_x; /* fix */
cur_x = rcur_x;
draw_char_string();
}
}
else if (c == CTRL_U || c == CTRL_X) {
if (leng_prefix > 0) {
erase_char_string();
char_received = 1;
if (cur_textjust == T_CENTER_JUSTIFIED)
{
while (leng_prefix--) /* subtract half of the character widths */
rcur_x -= char_advance(canvas_font,prefix[leng_prefix])/2.0;
cur_x = cbase_x = rbase_x = rcur_x ;
}
else if (cur_textjust == T_RIGHT_JUSTIFIED)
cbase_x = rbase_x = cur_x = rcur_x;
else
cur_x = rcur_x = cbase_x = rbase_x;
leng_prefix = 0;
*prefix = '\0';
draw_char_string();
}
}
else if (c < SP) {
}
else if (leng_prefix+leng_suffix == BUF_SIZE) {
put_msg("Text buffer is full, character is ignored");
}
else {
erase_char_string();
cwidth = char_advance(canvas_font,c);
if (cur_textjust == T_LEFT_JUSTIFIED)
rcur_x += cwidth; /* move the suffix to the right */
else if (cur_textjust == T_CENTER_JUSTIFIED)
{
rbase_x -= cwidth/2.0; /* advance left by half cwidth */
rcur_x += cwidth/2.0; /* move suffix right half cwidth */
}
if (cur_textjust == T_RIGHT_JUSTIFIED)
rbase_x -= cwidth; /* move the prefix to the left */
char_received = 1;
prefix[leng_prefix++] = c;
prefix[leng_prefix] = '\0';
cbase_x = rbase_x; /* fix */
cur_x = rcur_x;
draw_char_string();
}
}