home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 January
/
usenetsourcesnewsgroupsinfomagicjanuary1994.iso
/
sources
/
x
/
volume8
/
xfig2.8
/
part12
/
ruler.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-07-03
|
13KB
|
446 lines
/*
* FIG : Facility for Interactive Generation of figures
*
* Copyright (c) 1985 by Supoj Sutanthavibul (supoj@sally.UTEXAS.EDU)
* January 1985.
* 1st revision : Aug 1985.
*
* %W% %G%
*/
#include "fig.h"
#include "resources.h"
#include "const.h"
#include "font.h"
#include "paintop.h"
#define INCH_MARK 8
#define HALF_MARK 8
#define QUARTER_MARK 6
#define SIXTEENTH_MARK 4
#define TRM_WID 16
#define TRM_HT 8
#define SRM_WID 8
#define SRM_HT 16
extern int CANVAS_HEIGHT, CANVAS_WIDTH;
extern int SIDERULER_WIDTH, SIDERULER_HEIGHT;
extern int TOPRULER_WIDTH, TOPRULER_HEIGHT;
extern int SIDERULER_HEIGHT, SIDERULER_START;
extern int TOPRULER_LEFT, TOPRULER_TOP;
extern null_proc();
extern appresStruct appres;
static lasty = -100;
static lastx = -100;
static int troffx = -7, troffy = -10;
static char tr_marker_image[16] = {
0xFE, 0xFF, /* *************** */
0xFC, 0x7F, /* ************* */
0xF8, 0x3F, /* *********** */
0xF0, 0x1F, /* ********* */
0xE0, 0x0F, /* ******* */
0xC0, 0x07, /* ***** */
0x80, 0x03, /* *** */
0x00, 0x01, /* * */
};
static mpr_static(trm_pr, TRM_WID, TRM_HT, 1, tr_marker_image);
static int srroffx = 2, srroffy = -7;
static char srr_marker_image[16] = {
0x80, /* * */
0xC0, /* ** */
0xE0, /* *** */
0xF0, /* **** */
0xF8, /* ***** */
0xFC, /* ****** */
0xFE, /* ******* */
0xFF, /* ******** */
0xFE, /* ******* */
0xFC, /* ****** */
0xF8, /* ***** */
0xF0, /* **** */
0xE0, /* *** */
0xC0, /* ** */
0x80, /* * */
0x00
};
static mpr_static(srrm_pr, SRM_WID, SRM_HT, 1, srr_marker_image);
static int srloffx = -10, srloffy = -7;
static char srl_marker_image[16] = {
0x01, /* * */
0x03, /* ** */
0x07, /* *** */
0x0F, /* **** */
0x1F, /* ***** */
0x3F, /* ****** */
0x7F, /* ******* */
0xFF, /* ******** */
0x7F, /* ******* */
0x3F, /* ****** */
0x1F, /* ***** */
0x0F, /* **** */
0x07, /* *** */
0x03, /* ** */
0x01, /* * */
0x00
};
static mpr_static(srlm_pr, SRM_WID, SRM_HT, 1, srl_marker_image);
static Pixmap toparrow_pm, sidearrow_pm;
set_toprulermark(x)
int x;
{
XClearArea(tool_d, topruler_win,lastx + troffx,
TOPRULER_HEIGHT + troffy,trm_pr.width,
trm_pr.height, False);
XCopyArea(tool_d, toparrow_pm, topruler_win, topgc,
0, 0, trm_pr.width, trm_pr.height,
x + troffx, TOPRULER_HEIGHT + troffy);
lastx = x;
}
static Arg ruler_args[] =
{
/* 0 */ { XtNwidth, (XtArgVal) 0 },
/* 1 */ { XtNheight, (XtArgVal) 0 },
/* 2 */ { XtNlabel, (XtArgVal) "" },
/* 3 */ { XtNfromHoriz, (XtArgVal) NULL },
/* 4 */ { XtNhorizDistance, (XtArgVal) 0 },
/* 5 */ { XtNfromVert, (XtArgVal) NULL },
/* 6 */ { XtNvertDistance, (XtArgVal) 0 },
/* 7 */ { XtNresizable, (XtArgVal) False },
/* 8 */ { XtNtop, (XtArgVal) XtRubber }, /* these will be changed */
/* 9 */ { XtNbottom, (XtArgVal) XtRubber },
/* 10 */ { XtNleft, (XtArgVal) XtRubber },
/* 11 */ { XtNright, (XtArgVal) XtRubber },
};
extern int SIDERULER_WIDTH, SIDERULER_HEIGHT;
extern int TOPRULER_WIDTH, TOPRULER_HEIGHT;
int
init_sideruler(tool)
TOOL tool;
{
ruler_args[0].value = SIDERULER_WIDTH = RULER_WIDTH;
ruler_args[1].value = SIDERULER_HEIGHT = CANVAS_HEIGHT;
ruler_args[3].value = (XtArgVal) canvas_sw; /* from right edge of canvas */
ruler_args[5].value = (XtArgVal) topruler_sw; /* down from top ruler */
/* Place the sideruler below the topruler, next to the canvas,
but fixed offset from the top of the form */
ruler_args[8].value = (XtArgVal) XtChainTop;
ruler_args[9].value = (XtArgVal) XtRubber;
ruler_args[10].value = (XtArgVal) XtChainRight;
ruler_args[11].value = (XtArgVal) XtChainRight;
sideruler_sw = XtCreateWidget("sruler", labelWidgetClass, tool,
ruler_args, XtNumber(ruler_args));
return(1);
}
redisplay_sideruler()
{
XClearWindow(tool_d, sideruler_win);
}
int
init_topruler(tool)
TOOL tool;
{
ruler_args[0].value = TOPRULER_WIDTH = CANVAS_WIDTH;; /* width */
ruler_args[1].value = TOPRULER_HEIGHT = RULER_WIDTH; /* height */
ruler_args[3].value = (XtArgVal) panel_sw;
ruler_args[5].value = (XtArgVal) NULL;
/* fix the top & bottom to the top of the form,
the left to the panel, and the right is rubber */
ruler_args[8].value = (XtArgVal) XtChainTop;
ruler_args[9].value = (XtArgVal) XtChainTop;
ruler_args[10].value = (XtArgVal) XtChainLeft;
ruler_args[11].value = (XtArgVal) XtRubber;
topruler_sw = XtCreateWidget("truler", labelWidgetClass, tool,
ruler_args, XtNumber(ruler_args));
return(1);
}
redisplay_topruler()
{
XClearWindow(tool_d, topruler_win);
}
setup_rulers()
{
register int i, j;
register Pixmap p;
#define HINCH (PIX_PER_INCH / 2)
#define QINCH (PIX_PER_INCH / 4)
#define SINCH (PIX_PER_INCH / 16)
#define TWOMM (PIX_PER_CM / 5)
char number[3];
Arg tmp_arg[3];
unsigned long bg, fg;
static Arg ruler_args[] =
{
{ XtNbackgroundPixmap, (XtArgVal)NULL },
};
topruler_win = XtWindow(topruler_sw);
sideruler_win = XtWindow(sideruler_sw);
XDefineCursor(tool_d, topruler_win, (Cursor)bull_cursor.bitmap);
XDefineCursor(tool_d, sideruler_win, (Cursor)bull_cursor.bitmap);
/* top ruler, adjustments for digits are kludges based on 6x13 char */
p = XCreatePixmap(tool_d, topruler_win,
TOPRULER_WIDTH, TOPRULER_HEIGHT,
DefaultDepthOfScreen(tool_s));
XtSetArg(tmp_arg[0], XtNbackground, &bg);
XtSetArg(tmp_arg[1], XtNforeground, &fg);
XtGetValues(topruler_sw, tmp_arg, 2);
XSetBackground(tool_d, gc, bg);
XSetForeground(tool_d, gc, bg);
XFillRectangle(tool_d, p, gc, 0, 0, TOPRULER_WIDTH,
TOPRULER_HEIGHT);
XSetForeground(tool_d, gc, fg);
XDrawString(tool_d, p, gc, 2, TOPRULER_HEIGHT - INCH_MARK - 3,
appres.INCHES ? "in" : "cm", 2);
if(appres.INCHES)
for (i = SINCH - 1; i <= TOPRULER_WIDTH; i += SINCH)
{
j = i + 1;
if (j % PIX_PER_INCH == 0)
{
XDrawLine(tool_d, p, gc, i, TOPRULER_HEIGHT - 1, i,
TOPRULER_HEIGHT - INCH_MARK - 1);
sprintf(number, "%d", j / PIX_PER_INCH);
XDrawString(tool_d, p, gc, i - 3,
TOPRULER_HEIGHT - INCH_MARK - 3, number,
j < PIX_PER_INCH * 10 ? 1 : 2);
}
else if (j % HINCH == 0)
XDrawLine(tool_d, p, gc, i, TOPRULER_HEIGHT - 1, i,
TOPRULER_HEIGHT - HALF_MARK - 1);
else if (j % QINCH == 0)
XDrawLine(tool_d, p, gc, i, TOPRULER_HEIGHT - 1, i,
TOPRULER_HEIGHT - QUARTER_MARK - 1);
else if (j % SINCH == 0)
XDrawLine(tool_d, p, gc, i, TOPRULER_HEIGHT - 1, i,
TOPRULER_HEIGHT - SIXTEENTH_MARK - 1);
}
else
for (i = TWOMM - 1; i <= TOPRULER_WIDTH; i++)
{
j = i + 1;
if (j % PIX_PER_CM == 0)
{
XDrawLine(tool_d, p, gc, i, TOPRULER_HEIGHT - 1, i,
TOPRULER_HEIGHT - INCH_MARK - 1);
sprintf(number, "%d", j / PIX_PER_CM);
XDrawString(tool_d, p, gc, i - 3,
TOPRULER_HEIGHT - INCH_MARK - 3, number,
j < PIX_PER_CM * 10 ? 1 : 2);
}
else if (j % TWOMM == 0)
XDrawLine(tool_d, p, gc, i, TOPRULER_HEIGHT - 1, i,
TOPRULER_HEIGHT - QUARTER_MARK - 1);
}
ruler_args[0].value = (XtArgVal) p;
XtSetValues(topruler_sw, ruler_args, 1);
/* The arrows will be XORed into the rulers.
We want the foreground color in the arrow to result in
the foreground or background color in the display.
so if the source pixel is fg^bg, it produces fg when XOR'ed
with bg, and bg when XOR'ed with bg.
If the source pixel is zero, it produces fg when XOR'ed with
fg, and bg when XOR'ed with bg.
*/
XSetForeground(tool_d, gc, fg ^ bg);
XSetBackground(tool_d, gc, 0);
/* make pixmaps for top ruler arrow */
toparrow_pm = XCreatePixmap(tool_d, topruler_win, trm_pr.width,
trm_pr.height,
DefaultDepthOfScreen(tool_s));
XPutImage(tool_d, toparrow_pm, gc, &trm_pr, 0, 0, 0, 0,
trm_pr.width, trm_pr.height);
/* side ruler, adjustments for digits are kludges based on 6x13 char */
p = XCreatePixmap(tool_d, sideruler_win,
SIDERULER_WIDTH, SIDERULER_HEIGHT,
DefaultDepthOfScreen(tool_s));
XtSetArg(tmp_arg[0], XtNbackground, &bg);
XtSetArg(tmp_arg[1], XtNforeground, &fg);
XtGetValues(sideruler_sw, tmp_arg, 2);
XSetBackground(tool_d, gc, bg);
XSetForeground(tool_d, gc, bg);
XFillRectangle(tool_d, p, gc, 0, 0, SIDERULER_WIDTH,
SIDERULER_HEIGHT);
XSetForeground(tool_d, gc, fg);
if( appres.INCHES )
{
if( appres.RHS_PANEL )
{
for (i = SINCH - 1; i <= SIDERULER_HEIGHT; i += SINCH)
{
j = i + 1;
if (j % PIX_PER_INCH == 0)
{
XDrawLine(tool_d, p, gc, RULER_WIDTH-INCH_MARK,
i, RULER_WIDTH, i);
sprintf(number, "%d", j / PIX_PER_INCH);
XDrawString(tool_d, p, gc,
RULER_WIDTH-INCH_MARK - 8, i + 3,
number, j < PIX_PER_INCH * 10 ? 1 : 2);
}
else if (j % QINCH == 0)
XDrawLine(tool_d, p, gc,
RULER_WIDTH-QUARTER_MARK, i,
RULER_WIDTH, i);
else if (j % SINCH == 0)
XDrawLine(tool_d, p, gc,
RULER_WIDTH-SIXTEENTH_MARK, i,
RULER_WIDTH, i);
}
}
else
{
for (i = SINCH - 1; i <= SIDERULER_HEIGHT; i += SINCH)
{
j = i + 1;
if (j % PIX_PER_INCH == 0)
{
XDrawLine(tool_d, p, gc, 0, i,
INCH_MARK - 1, i);
sprintf(number, "%d", j / PIX_PER_INCH);
XDrawString(tool_d, p, gc, INCH_MARK + 3,
i + 3, number,
j < PIX_PER_INCH * 10 ? 1 : 2);
}
else if (j % QINCH == 0)
XDrawLine(tool_d, p, gc, 0, i,
QUARTER_MARK - 1, i);
else if (j % SINCH == 0)
XDrawLine(tool_d, p, gc, 0, i,
SIXTEENTH_MARK - 1, i);
}
}
}
else
{
if( appres.RHS_PANEL )
{
for (i = TWOMM - 1; i <= SIDERULER_HEIGHT; i++)
{
j = i + 1;
if (j % PIX_PER_CM == 0)
{
XDrawLine(tool_d, p, gc, RULER_WIDTH-INCH_MARK,
i, RULER_WIDTH, i);
sprintf(number, "%d", j / PIX_PER_CM);
XDrawString(tool_d, p, gc,
RULER_WIDTH-INCH_MARK - 8, i + 3,
number, j < PIX_PER_CM * 10 ? 1 : 2);
}
else if (j % TWOMM == 0)
XDrawLine(tool_d, p, gc,
RULER_WIDTH-QUARTER_MARK, i,
RULER_WIDTH, i);
}
}
else
{
for (i = TWOMM - 1; i <= SIDERULER_HEIGHT; i++)
{
j = i + 1;
if (j % PIX_PER_CM == 0)
{
XDrawLine(tool_d, p, gc, 0, i,
INCH_MARK - 1, i);
sprintf(number, "%d", j / PIX_PER_CM);
XDrawString(tool_d, p, gc, INCH_MARK + 3,
i + 3, number,
j < PIX_PER_CM * 10 ? 1 : 2);
}
else if (j % TWOMM == 0)
XDrawLine(tool_d, p, gc, 0, i,
QUARTER_MARK - 1, i);
}
}
}
ruler_args[0].value = (XtArgVal) p;
XtSetValues(sideruler_sw, ruler_args, 1);
/* Colors set as above */
XSetForeground(tool_d, gc, fg ^ bg);
XSetBackground(tool_d, gc, 0);
/* make pixmaps for side ruler arrow */
if( appres.RHS_PANEL )
{
sidearrow_pm = XCreatePixmap(tool_d, sideruler_win,
srlm_pr.width, srlm_pr.height,
DefaultDepthOfScreen(tool_s));
XPutImage(tool_d, sidearrow_pm, gc, &srlm_pr, 0, 0, 0, 0,
srlm_pr.width, srlm_pr.height);
}
else
{
sidearrow_pm = XCreatePixmap(tool_d, sideruler_win,
srrm_pr.width, srrm_pr.height,
DefaultDepthOfScreen(tool_s));
XPutImage(tool_d, sidearrow_pm, gc, &srrm_pr, 0, 0, 0, 0,
srrm_pr.width, srrm_pr.height);
}
}
set_rulermark(x, y)
int x, y;
{
if( appres.TRACKING )
{
set_siderulermark(y);
set_toprulermark(x);
}
}
redisplay_rulers()
{
redisplay_topruler();
redisplay_sideruler();
}
set_siderulermark(y)
int y;
{
if( appres.RHS_PANEL ) {
/* Because the ruler uses a background pixmap, we can win
here by using XClearArea to erase the old thing. */
XClearArea(tool_d, sideruler_win,
RULER_WIDTH+srloffx, lasty + srloffy,
srlm_pr.width, srlm_pr.height, False);
XCopyArea(tool_d, sidearrow_pm, sideruler_win,
sidegc, 0, 0, srlm_pr.width,
srlm_pr.height, RULER_WIDTH+srloffx, y + srloffy);
}
else
{
/* Because the ruler uses a background pixmap, we can win
here by using XClearArea to erase the old thing. */
XClearArea(tool_d, sideruler_win,
srroffx, lasty + srroffy,
srlm_pr.width, srlm_pr.height, False);
XCopyArea(tool_d, sidearrow_pm, sideruler_win,
sidegc, 0, 0, srrm_pr.width,
srrm_pr.height, srroffx, y + srroffy);
}
lasty = y;
}