More useless, hackish, and/or poorly-written code meets an untimely end. SVN revision: 799eterm-0.10
parent
332269133d
commit
8e252e121d
23 changed files with 21 additions and 5271 deletions
@ -1,3 +0,0 @@ |
||||
Well, now that we have a new CVS server, I've kinda done a little |
||||
restructuring. There may still be things that are screwy, so please |
||||
let me know (mej@eterm.org) if you have problems. |
@ -1,553 +0,0 @@ |
||||
/*--------------------------------*-C-*---------------------------------*
|
||||
* File: graphics.c |
||||
* |
||||
* This module is all new by Rob Nation |
||||
* <nation@rocket.sanders.lockheed.com> |
||||
* |
||||
* Modifications by mj olesen <olesen@me.QueensU.CA> |
||||
* and Raul Garcia Garcia <rgg@tid.es> |
||||
*----------------------------------------------------------------------*/ |
||||
|
||||
static const char cvs_ident[] = "$Id$"; |
||||
|
||||
#include "config.h" |
||||
#include "feature.h" |
||||
|
||||
#ifdef HAVE_UNISTD_H |
||||
# include <unistd.h> |
||||
#endif |
||||
#include <X11/cursorfont.h> |
||||
|
||||
#include "command.h" /* for tt_printf() */ |
||||
#include "debug.h" |
||||
#include "graphics.h" |
||||
#include "startup.h" |
||||
#include "screen.h" |
||||
|
||||
/* commands:
|
||||
* 'C' = Clear |
||||
* 'F' = Fill |
||||
* 'G' = Geometry |
||||
* 'L' = Line |
||||
* 'P' = Points |
||||
* 'T' = Text |
||||
* 'W' = Window |
||||
*/ |
||||
|
||||
#ifndef GRX_SCALE |
||||
# define GRX_SCALE 10000 |
||||
#endif |
||||
|
||||
/* extern functions referenced */ |
||||
/* extern variables referenced */ |
||||
/* extern variables declared here */ |
||||
|
||||
#ifdef RXVT_GRAPHICS |
||||
/* local variables */ |
||||
static int graphics_up = 0; |
||||
|
||||
typedef struct grcmd_t { |
||||
char cmd; |
||||
short color; |
||||
short ncoords; |
||||
int *coords; |
||||
unsigned char *text; |
||||
struct grcmd_t *next; |
||||
} grcmd_t; |
||||
|
||||
typedef struct grwin_t { |
||||
Window win; |
||||
int x, y; |
||||
unsigned int w, h; |
||||
short screen; |
||||
grcmd_t *graphics; |
||||
struct grwin_t *prev, *next; |
||||
} grwin_t; |
||||
|
||||
static grwin_t *gr_root = NULL; |
||||
|
||||
/*----------------------------------------------------------------------*
|
||||
* local functions |
||||
*/ |
||||
/* Gr_NewWindow() */ |
||||
static void |
||||
Gr_NewWindow(int nargs, int args[]) |
||||
{ |
||||
int x, y; |
||||
unsigned int w, h; |
||||
Window win; |
||||
grwin_t *grwin; |
||||
Cursor cursor; |
||||
|
||||
if (nargs != 4) { |
||||
print_error("NewWindow: 4 args needed, got %d\n", nargs); |
||||
return; |
||||
} |
||||
x = args[0] * TermWin.width / GRX_SCALE + TermWin.internalBorder; |
||||
y = args[1] * TermWin.height / GRX_SCALE + TermWin.internalBorder; |
||||
w = args[2] * TermWin.width / GRX_SCALE; |
||||
h = args[3] * TermWin.height / GRX_SCALE; |
||||
|
||||
win = XCreateSimpleWindow(Xdisplay, TermWin.vt, |
||||
x, y, w, h, |
||||
0, |
||||
PixColors[fgColor], |
||||
PixColors[bgColor]); |
||||
|
||||
cursor = XCreateFontCursor(Xdisplay, XC_crosshair); |
||||
XDefineCursor(Xdisplay, win, cursor); |
||||
XMapWindow(Xdisplay, win); |
||||
XSelectInput(Xdisplay, win, ExposureMask); |
||||
|
||||
grwin = (grwin_t *) MALLOC(sizeof(grwin_t)); |
||||
grwin->win = win; |
||||
grwin->x = x; |
||||
grwin->y = y; |
||||
grwin->w = w; |
||||
grwin->h = h; |
||||
grwin->screen = 0; |
||||
grwin->prev = NULL; |
||||
grwin->next = gr_root; |
||||
if (grwin->next) |
||||
grwin->next->prev = grwin; |
||||
gr_root = grwin; |
||||
grwin->graphics = NULL; |
||||
graphics_up++; |
||||
|
||||
tt_printf("\033W%ld\n", (long) grwin->win); |
||||
} |
||||
|
||||
/* Gr_ClearWindow() */ |
||||
static void |
||||
Gr_ClearWindow(grwin_t * grwin) |
||||
{ |
||||
grcmd_t *cmd, *next; |
||||
|
||||
for (cmd = grwin->graphics; cmd != NULL; cmd = next) { |
||||
next = cmd->next; |
||||
free(cmd->coords); |
||||
if (cmd->text != NULL) |
||||
free(cmd->text); |
||||
free(cmd); |
||||
} |
||||
grwin->graphics = NULL; |
||||
XClearWindow(Xdisplay, grwin->win); |
||||
} |
||||
|
||||
/* Gr_Text() */ |
||||
/*
|
||||
* arg [0] = x |
||||
* arg [1] = y |
||||
* arg [2] = alignment |
||||
* arg [3] = strlen (text) |
||||
*/ |
||||
static void |
||||
Gr_Text(grwin_t * grwin, grcmd_t * data) |
||||
{ |
||||
int x, y, align; |
||||
|
||||
if (data->ncoords < 4 || data->text == NULL || *(data->text) == '\0') |
||||
return; |
||||
|
||||
x = data->coords[0] * grwin->w / GRX_SCALE; |
||||
y = data->coords[1] * grwin->h / GRX_SCALE; |
||||
align = data->coords[2]; |
||||
|
||||
if (align & RIGHT_TEXT) |
||||
x -= XTextWidth(TermWin.font, data->text, data->coords[3]); |
||||
else if (align & HCENTER_TEXT) |
||||
x -= (XTextWidth(TermWin.font, data->text, data->coords[3]) >> 1); |
||||
|
||||
if (align & TOP_TEXT) |
||||
y += TermWin.font->ascent; |
||||
else if (align & BOTTOM_TEXT) |
||||
y -= TermWin.font->descent; |
||||
|
||||
if (align & VCENTER_TEXT) |
||||
y -= TermWin.font->descent + ((TermWin.font->ascent + TermWin.font->descent) >> 1); |
||||
if (align & VCAPS_CENTER_TEXT) |
||||
y += (TermWin.font->ascent >> 1); |
||||
|
||||
# ifdef PIXMAP_SUPPORT |
||||
XClearArea(Xdisplay, grwin->win, |
||||
x, y, |
||||
Width2Pixel(data->coords[3]), |
||||
Height2Pixel(1), |
||||
0); |
||||
# endif |
||||
XDrawString(Xdisplay, grwin->win, TermWin.gc, |
||||
x, y, |
||||
data->text, data->coords[3]); |
||||
} |
||||
|
||||
/* Gr_Geometry() */ |
||||
static void |
||||
Gr_Geometry(grwin_t * grwin, grcmd_t * data) |
||||
{ |
||||
if (grwin) |
||||
tt_printf("\033G%ld %d %d %u %u %d %d %ld %ld %d\n", |
||||
(long) grwin->win, |
||||
grwin->x, grwin->y, grwin->w, grwin->h, |
||||
TermWin.fwidth, |
||||
TermWin.fheight, |
||||
(long) GRX_SCALE * TermWin.fwidth / grwin->w, |
||||
(long) GRX_SCALE * TermWin.fheight / grwin->h, |
||||
Xdepth); |
||||
else /* rxvt terminal window size */ |
||||
tt_printf("\033G0 0 0 %d %d %d %d %ld %ld %d\n", |
||||
TermWin.width - 2 * TermWin.internalBorder, |
||||
TermWin.height - 2 * TermWin.internalBorder, |
||||
TermWin.fwidth, |
||||
TermWin.fheight, |
||||
(long) GRX_SCALE * TermWin.fwidth / (TermWin.width - 2 * TermWin.internalBorder), |
||||
(long) GRX_SCALE * TermWin.fheight / (TermWin.height - 2 * TermWin.internalBorder), |
||||
Xdepth); |
||||
} |
||||
|
||||
/* Gr_DestroyWindow() */ |
||||
static void |
||||
Gr_DestroyWindow(grwin_t * grwin) |
||||
{ |
||||
grcmd_t *cmd, *next; |
||||
|
||||
if (grwin == NULL) |
||||
return; |
||||
|
||||
for (cmd = grwin->graphics; cmd; cmd = next) { |
||||
next = cmd->next; |
||||
free(cmd->coords); |
||||
if (cmd->text != NULL) |
||||
free(cmd->text); |
||||
free(cmd); |
||||
} |
||||
|
||||
XDestroyWindow(Xdisplay, grwin->win); |
||||
if (grwin->next != NULL) |
||||
grwin->next->prev = grwin->prev; |
||||
if (grwin->prev != NULL) |
||||
grwin->prev->next = grwin->next; |
||||
else |
||||
gr_root = grwin->next; |
||||
free(grwin); |
||||
|
||||
graphics_up--; |
||||
} |
||||
|
||||
/* Gr_Dispatch() */ |
||||
static void |
||||
Gr_Dispatch(grwin_t * grwin, grcmd_t * data) |
||||
{ |
||||
int i, n; |
||||
union { |
||||
XPoint pt[NGRX_PTS / 2]; |
||||
XRectangle rect[NGRX_PTS / 4]; |
||||
} xdata; |
||||
|
||||
if (data->color != fgColor) { |
||||
XGCValues gcv; |
||||
|
||||
gcv.foreground = PixColors[data->color]; |
||||
XChangeGC(Xdisplay, TermWin.gc, GCForeground, &gcv); |
||||
} |
||||
if (grwin) |
||||
switch (data->cmd) { |
||||
case 'L': |
||||
if (data->ncoords > 3) { |
||||
for (n = i = 0; i < data->ncoords; i += 2, n++) { |
||||
xdata.pt[n].x = data->coords[i] * grwin->w / GRX_SCALE; |
||||
xdata.pt[n].y = data->coords[i + 1] * grwin->h / GRX_SCALE; |
||||
} |
||||
XDrawLines(Xdisplay, |
||||
grwin->win, TermWin.gc, xdata.pt, n, CoordModeOrigin); |
||||
} |
||||
break; |
||||
|
||||
case 'P': |
||||
if (data->ncoords > 3) { |
||||
for (n = i = 0; i < data->ncoords; i += 2, n++) { |
||||
xdata.pt[n].x = data->coords[i] * grwin->w / GRX_SCALE; |
||||
xdata.pt[n].y = data->coords[i + 1] * grwin->h / GRX_SCALE; |
||||
} |
||||
XDrawPoints(Xdisplay, |
||||
grwin->win, TermWin.gc, xdata.pt, n, CoordModeOrigin); |
||||
} |
||||
break; |
||||
|
||||
case 'F': |
||||
if (data->ncoords > 0) { |
||||
for (n = i = 0; i < data->ncoords; i += 4, n++) { |
||||
xdata.rect[n].x = data->coords[i] * grwin->w / GRX_SCALE; |
||||
xdata.rect[n].y = data->coords[i + 1] * grwin->h / GRX_SCALE; |
||||
xdata.rect[n].width = ((data->coords[i + 2] |
||||
- data->coords[i] + 1) * |
||||
grwin->w / GRX_SCALE); |
||||
xdata.rect[n].height = ((data->coords[i + 3] |
||||
- data->coords[i + 1] + 1) * |
||||
grwin->h / GRX_SCALE); |
||||
|
||||
# ifdef PIXMAP_SUPPORT |
||||
XClearArea(Xdisplay, grwin->win, |
||||
xdata.rect[n].x, |
||||
xdata.rect[n].y, |
||||
xdata.rect[n].width, |
||||
xdata.rect[n].height, |
||||
0); |
||||
# endif |
||||
} |
||||
XFillRectangles(Xdisplay, grwin->win, TermWin.gc, xdata.rect, n); |
||||
} |
||||
break; |
||||
case 'T': |
||||
Gr_Text(grwin, data); |
||||
break; |
||||
case 'C': |
||||
Gr_ClearWindow(grwin); |
||||
break; |
||||
} |
||||
if (data->color != fgColor) { |
||||
XGCValues gcv; |
||||
|
||||
gcv.foreground = PixColors[fgColor]; |
||||
XChangeGC(Xdisplay, TermWin.gc, GCForeground, &gcv); |
||||
} |
||||
} |
||||
|
||||
/* Gr_Redraw() */ |
||||
static void |
||||
Gr_Redraw(grwin_t * grwin) |
||||
{ |
||||
grcmd_t *cmd; |
||||
|
||||
for (cmd = grwin->graphics; cmd != NULL; cmd = cmd->next) |
||||
Gr_Dispatch(grwin, cmd); |
||||
} |
||||
|
||||
#endif |
||||
/*----------------------------------------------------------------------*
|
||||
* end of static functions |
||||
*/ |
||||
|
||||
#ifdef RXVT_GRAPHICS |
||||
void |
||||
Gr_ButtonReport(int but, int x, int y) |
||||
{ |
||||
grwin_t *grwin; |
||||
|
||||
for (grwin = gr_root; grwin != NULL; grwin = grwin->next) |
||||
if ((x > grwin->x) && |
||||
(y > grwin->y) && |
||||
(x < grwin->x + grwin->w) && |
||||
(y < grwin->y + grwin->h)) |
||||
break; |
||||
|
||||
if (grwin == NULL) |
||||
return; |
||||
|
||||
x = GRX_SCALE * (x - grwin->x) / grwin->w; |
||||
y = GRX_SCALE * (y - grwin->y) / grwin->h; |
||||
tt_printf("\033%c%ld;%d;%d;\n", but, (long) grwin->win, x, y); |
||||
} |
||||
|
||||
/* Gr_do_graphics() */ |
||||
void |
||||
Gr_do_graphics(int cmd, int nargs, int args[], unsigned char *text) |
||||
{ |
||||
static Window last_id = None; |
||||
long win_id; |
||||
grwin_t *grwin; |
||||
grcmd_t *newcmd, *oldcmd; |
||||
int i; |
||||
|
||||
if (cmd == 'W') { |
||||
Gr_NewWindow(nargs, args); |
||||
return; |
||||
} |
||||
win_id = (nargs > 0) ? (Window) args[0] : None; |
||||
|
||||
if ((cmd == 'G') && (win_id == None)) { |
||||
Gr_Geometry(NULL, NULL); |
||||
return; |
||||
} |
||||
if ((win_id == None) && (last_id != None)) |
||||
win_id = last_id; |
||||
|
||||
if (win_id == None) |
||||
return; |
||||
|
||||
grwin = gr_root; |
||||
while ((grwin != NULL) && (grwin->win != win_id)) |
||||
grwin = grwin->next; |
||||
|
||||
if (grwin == NULL) |
||||
return; |
||||
|
||||
if (cmd == 'G') { |
||||
Gr_Geometry(grwin, NULL); |
||||
return; |
||||
} |
||||
nargs--; |
||||
args++; /* skip over window id */ |
||||
|
||||
/* record this new command */ |
||||
newcmd = (grcmd_t *) MALLOC(sizeof(grcmd_t)); |
||||
newcmd->ncoords = nargs; |
||||
newcmd->coords = (int *) MALLOC((newcmd->ncoords * sizeof(int))); |
||||
|
||||
newcmd->next = NULL; |
||||
newcmd->cmd = cmd; |
||||
newcmd->color = scr_get_fgcolor(); |
||||
newcmd->text = text; |
||||
|
||||
for (i = 0; i < newcmd->ncoords; i++) |
||||
newcmd->coords[i] = args[i]; |
||||
|
||||
/*
|
||||
* If newcmd == fill, and rectangle is full window, drop all prior |
||||
* commands. |
||||
*/ |
||||
if ((newcmd->cmd == 'F') && (grwin) && (grwin->graphics)) { |
||||
for (i = 0; i < newcmd->ncoords; i += 4) { |
||||
if ((newcmd->coords[i] == 0) && |
||||
(newcmd->coords[i + 1] == 0) && |
||||
(newcmd->coords[i + 2] == GRX_SCALE) && |
||||
(newcmd->coords[i + 3] == GRX_SCALE)) { |
||||
/* drop previous commands */ |
||||
oldcmd = grwin->graphics; |
||||
while (oldcmd->next != NULL) { |
||||
grcmd_t *tmp = oldcmd; |
||||
|
||||
oldcmd = oldcmd->next; |
||||
free(tmp); |
||||
} |
||||
grwin->graphics = NULL; |
||||
} |
||||
} |
||||
} |
||||
/* insert new command into command list */ |
||||
oldcmd = grwin->graphics; |
||||
if (oldcmd == NULL) |
||||
grwin->graphics = newcmd; |
||||
else { |
||||
while (oldcmd->next != NULL) |
||||
oldcmd = oldcmd->next; |
||||
oldcmd->next = newcmd; |
||||
} |
||||
Gr_Dispatch(grwin, newcmd); |
||||
} |
||||
|
||||
/* Gr_scroll() */ |
||||
void |
||||
Gr_scroll(int count) |
||||
{ |
||||
static short prev_start = 0; |
||||
grwin_t *grwin, *next; |
||||
|
||||
if ((count == 0) && (prev_start == TermWin.view_start)) |
||||
return; |
||||
|
||||
prev_start = TermWin.view_start; |
||||
|
||||
for (grwin = gr_root; grwin != NULL; grwin = next) { |
||||
next = grwin->next; |
||||
grwin->y -= (count * TermWin.fheight); |
||||
if ((grwin->y + grwin->h) < -(TermWin.saveLines * TermWin.fheight)) |
||||
Gr_DestroyWindow(grwin); |
||||
else |
||||
XMoveWindow(Xdisplay, grwin->win, |
||||
grwin->x, |
||||
grwin->y + (TermWin.view_start * TermWin.fheight)); |
||||
} |
||||
} |
||||
|
||||
/* Gr_ClearScreen() */ |
||||
void |
||||
Gr_ClearScreen(void) |
||||
{ |
||||
grwin_t *grwin, *next; |
||||
|
||||
for (grwin = gr_root; grwin != NULL; grwin = next) { |
||||
next = grwin->next; |
||||
if ((grwin->screen == 0) && (grwin->y + grwin->h > 0)) { |
||||
if (grwin->y >= 0) |
||||
Gr_DestroyWindow(grwin); |
||||
else |
||||
XResizeWindow(Xdisplay, grwin->win, |
||||
grwin->w, -grwin->y); |
||||
} |
||||
} |
||||
} |
||||
|
||||
/* Gr_ChangeScreen() */ |
||||
void |
||||
Gr_ChangeScreen(void) |
||||
{ |
||||
grwin_t *grwin, *next; |
||||
|
||||
for (grwin = gr_root; grwin != NULL; grwin = next) { |
||||
next = grwin->next; |
||||
if (grwin->y + grwin->h > 0) { |
||||
if (grwin->screen == 1) { |
||||
XMapWindow(Xdisplay, grwin->win); |
||||
grwin->screen = 0; |
||||
} else { |
||||
XUnmapWindow(Xdisplay, grwin->win); |
||||
grwin->screen = 1; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
/* Gr_expose() */ |
||||
void |
||||
Gr_expose(Window win) |
||||
{ |
||||
grwin_t *grwin; |
||||
|
||||
for (grwin = gr_root; grwin != NULL; grwin = grwin->next) { |
||||
if (grwin->win == win) { |
||||
Gr_Redraw(grwin); |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
|
||||
/* Gr_Resize() */ |
||||
void |
||||
Gr_Resize(int w, int h) |
||||
{ |
||||
grwin_t *grwin; |
||||
|
||||
for (grwin = gr_root; grwin != NULL; grwin = grwin->next) { |
||||
if (TermWin.height != h) { |
||||
grwin->y += (TermWin.height - h); |
||||
XMoveWindow(Xdisplay, grwin->win, |
||||
grwin->x, |
||||
grwin->y + (TermWin.view_start * TermWin.fheight)); |
||||
} |
||||
Gr_Redraw(grwin); |
||||
} |
||||
} |
||||
|
||||
/* Gr_reset() */ |
||||
void |
||||
Gr_reset(void) |
||||
{ |
||||
grwin_t *grwin, *next; |
||||
|
||||
for (grwin = gr_root; grwin != NULL; grwin = next) { |
||||
next = grwin->next; |
||||
Gr_DestroyWindow(grwin); |
||||
} |
||||
|
||||
graphics_up = 0; |
||||
} |
||||
|
||||
/* Gr_Displayed() */ |
||||
int |
||||
Gr_Displayed(void) |
||||
{ |
||||
return graphics_up; |
||||
} |
||||
|
||||
#endif /* RXVT_GRAPHICS */ |
||||
/*----------------------- end-of-file (C source) -----------------------*/ |
@ -1,63 +0,0 @@ |
||||
/*--------------------------------*-C-*---------------------------------*
|
||||
* File: graphics.h |
||||
* |
||||
*----------------------------------------------------------------------*/ |
||||
|
||||
#ifndef _GRAPHICS_H_ |
||||
# define _GRAPHICS_H_ |
||||
# include <X11/Xfuncproto.h> |
||||
|
||||
# include "grx.h" /* text alignment */ |
||||
|
||||
/*
|
||||
* number of graphics points |
||||
* divisible by 2 (num lines) |
||||
* divisible by 4 (num rect) |
||||
*/ |
||||
# define NGRX_PTS 1000 |
||||
|
||||
_XFUNCPROTOBEGIN |
||||
|
||||
extern void Gr_ButtonReport(int, int, int); |
||||
|
||||
extern void Gr_do_graphics (int /* cmd */, |
||||
int /* nargs */, |
||||
int /* args */[], |
||||
unsigned char * /* text */); |
||||
|
||||
extern void Gr_scroll (int /* count */); |
||||
|
||||
extern void Gr_ClearScreen (void); |
||||
|
||||
extern void Gr_ChangeScreen (void); |
||||
|
||||
extern void Gr_expose (Window /* win */); |
||||
|
||||
extern void Gr_Resize (int /* w */, |
||||
int /* h */); |
||||
|
||||
extern void Gr_reset (void); |
||||
|
||||
extern int Gr_Displayed (void); |
||||
|
||||
_XFUNCPROTOEND |
||||
|
||||
# ifdef RXVT_GRAPHICS |
||||
# define Gr_ButtonPress(x,y) Gr_ButtonReport ('P',(x),(y)) |
||||
# define Gr_ButtonRelease(x,y) Gr_ButtonReport ('R',(x),(y)) |
||||
# define GR_DISPLAY(x) if (Gr_Displayed()) (x) |
||||
# define GR_NO_DISPLAY(x) if (!Gr_Displayed()) (x) |
||||
# else |
||||
# define Gr_ButtonPress(x,y) ((void)0) |
||||
# define Gr_ButtonRelease(x,y) ((void)0) |
||||
# define Gr_scroll(count) ((void)0) |
||||
# define Gr_ClearScreen() ((void)0) |
||||
# define Gr_ChangeScreen() ((void)0) |
||||
# define Gr_expose(win) ((void)0) |
||||
# define Gr_Resize(w,h) ((void)0) |
||||
# define Gr_reset() ((void)0) |
||||
# define GR_DISPLAY(x) |
||||
# define GR_NO_DISPLAY(x) (x) |
||||
# endif |
||||
#endif /* whole file */ |
||||
/*----------------------- end-of-file (C header) -----------------------*/ |
@ -1,2 +0,0 @@ |
||||
Makefile |
||||
Makefile.in |
@ -1,11 +0,0 @@ |
||||
# $Id$
|
||||
|
||||
bin_PROGRAMS = qplot
|
||||
|
||||
qplot_SOURCES = grxlib.c qplot.c
|
||||
|
||||
INCLUDES = -I. -I.. -I$(includedir) -I$(prefix)/include
|
||||
|
||||
LDADD = -L. -L.. -L$(libdir) -L$(prefix)/lib
|
||||
|
||||
install-exec-hook: |
@ -1 +0,0 @@ |
||||
This is an example of rxvt graphics. |
File diff suppressed because it is too large
Load Diff
@ -1,169 +0,0 @@ |
||||
#include <stdio.h> |
||||
#include <stdlib.h> |
||||
#include <string.h> |
||||
#include <unistd.h> |
||||
#include <math.h> |
||||
|
||||
static const char cvs_ident[] = "$Id$"; |
||||
|
||||
#ifdef _AIX |
||||
# include <termio.h> |
||||
#else |
||||
# include <termios.h> |
||||
#endif |
||||
|
||||
#include "grxlib.h" |
||||
|
||||
/*----------------------------------------------------------------------*/ |
||||
|
||||
void Done (void) { putchar (':'); } |
||||
void StartLine (long id) { printf ("\033GL%ld", id); } |
||||
void StartPoint (long id) { printf ("\033GP%ld", id); } |
||||
void StartFill (long id) { printf ("\033GF%ld", id); } |
||||
void Extend (int x, int y) { printf (";%d;%d", x, y); } |
||||
void FillArea (int x1, int y1, int x2, int y2) |
||||
{ |
||||
printf (";%d;%d;%d;%d", x1, y1, x2, y2); |
||||
} |
||||
|
||||
void PlaceText (long id, int x, int y, int mode, char *text) |
||||
{ |
||||
printf ("\033GT%ld;%d;%d;%d;%d:%s", id, x, y, mode, strlen(text), text); |
||||
fflush (stdout); |
||||
} |
||||
|
||||
void ClearWindow (long id) { printf ("\033GC%ld:", id); } |
||||
void ForeColor (int col) { printf ("\033[3%dm", (col<0||col>7)?0:col); } |
||||
void DefaultRendition (void) { printf ("\033[m"); } |
||||
|
||||
#define LINESZ 100 |
||||
static char line [LINESZ]; |
||||
static FILE *infd = NULL; |
||||
|
||||
long |
||||
CreateWin (int x, int y, int w, int h) |
||||
{ |
||||
long id = 0; |
||||
|
||||
fflush (stdout); |
||||
printf ("\033GW%d;%d;%d;%d:", x, y, w, h); |
||||
fflush (stdout); |
||||
while (1) |
||||
{ |
||||
if ((fgets (line, LINESZ, infd) != NULL) && |
||||
(sscanf (line,"\033W%ld", &id) == 1)) |
||||
break; |
||||
} |
||||
return id; |
||||
} |
||||
|
||||
void |
||||
QueryWin (long id, int *nfwidth, int *nfheight) |
||||
{ |
||||
int id1, x, y, width, height, fwidth, fheight; |
||||
printf ("\033GG%ld:",id); |
||||
fflush (stdout); |
||||
while (1) |
||||
{ |
||||
if ((fgets (line, sizeof(line), infd) != NULL) && |
||||
(sscanf (line,"\033G%ld %ld %ld %ld %ld %ld %ld %ld %ld", |
||||
&id1, &x, &y, &width, &height, |
||||
&fwidth, &fheight, nfwidth, nfheight) != 0)) |
||||
break; |
||||
} |
||||
} |
||||
|
||||
int |
||||
WaitForCarriageReturn (long *win, int *x, int *y) |
||||
{ |
||||
int i, len; |
||||
|
||||
fgets (line, LINESZ, infd); |
||||
line [LINESZ-1] = 0; |
||||
len = strlen (line); |
||||
for (i = 0; i < len; i++) |
||||
{ |
||||
if (line [i] == '\033') |
||||
{ |
||||
int ret = 1; |
||||
i++; |
||||
switch (line[i]) { |
||||
case 'R': ret++; |
||||
/* drop */ |
||||
case 'P': |
||||
sscanf (&line[i+1],"%ld;%d;%d", win, x, y); |
||||
return ret; |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
return 0; |
||||
} |
||||
|
||||
static int fno2; |
||||
static struct termios ttmode; |
||||
|
||||
int |
||||
InitializeGraphics (int scroll_text_up) |
||||
{ |
||||
int fno, i; |
||||
char *screen_tty; |
||||
struct winsize winsize; |
||||
|
||||
fno = fileno (stdout); |
||||
if (!isatty (fno)) |
||||
{ |
||||
fprintf (stderr, "stdout must be a tty\n"); |
||||
return 0; |
||||
} |
||||
screen_tty = ttyname (fno); |
||||
ioctl (fno, TCGETS, (char *)&ttmode); |
||||
ttmode.c_lflag &= ~ECHO; |
||||
ioctl (fno, TCSETS, (char *)&ttmode); |
||||
|
||||
infd = fopen (screen_tty, "rw"); |
||||
|
||||
fno2 = fileno (infd); |
||||
ioctl (fno2, TCGETS, (char *)&ttmode); |
||||
ttmode.c_lflag &= ~ECHO; |
||||
ioctl (fno2, TCSETS, (char *)&ttmode); |
||||
|
||||
/* query rxvt to find if graphics are available */ |
||||
fflush (stdout); |
||||
printf ("\033GQ"); |
||||
fflush (stdout); |
||||
while (1) |
||||
{ |
||||
if ((fgets (line, LINESZ, infd) != NULL) && |
||||
(sscanf (line,"\033G%d", &i) == 1)) |
||||
{ |
||||
if (!i) |
||||
{ |
||||
fprintf (stderr, "rxvt graphics not available\n"); |
||||
CloseGraphics (); |
||||
return 0; |
||||
} |
||||
break; |
||||
} |
||||
} |
||||
if (scroll_text_up) |
||||
{ |
||||
ioctl (fno, TIOCGWINSZ, &winsize); |
||||
fflush (stdout); |
||||
for (i = 0; i < winsize.ws_row; i++) |
||||
putchar ('\n'); |
||||
fflush (stdout); |
||||
} |
||||
return i; |
||||
} |
||||
|
||||
void |
||||
CloseGraphics (void) |
||||
{ |
||||
DefaultRendition (); |
||||
fflush (stdout); |
||||
ttmode.c_lflag |= ECHO; |
||||
ioctl (fno2, TCSETS, (char *)&ttmode); |
||||
fclose (infd); |
||||
} |
||||
/*----------------------- end-of-file (C source) -----------------------*/ |
@ -1,28 +0,0 @@ |
||||
#include "../grx.h" /* text alignment */ |
||||
|
||||
/*function pointer to either StartLine or StartPoint */ |
||||
typedef void (*LineFunction) (long id); |
||||
|
||||
#ifdef __cplusplus |
||||
extern "C" { |
||||
#endif |
||||
extern void StartLine (long id); |
||||
extern void StartPoint (long id); |
||||
extern void Extend (int x, int y); |
||||
extern void StartFill (long id); |
||||
extern void FillArea (int x1, int y1, int x2, int y2); |
||||
extern void Done (void); |
||||
extern void PlaceText (long id, int x, int y, int mode, char *text); |
||||
|
||||
extern void ClearWindow (long id); |
||||
extern long CreateWin (int x, int y, int w, int h); |
||||
extern void QueryWin (long id, int *nfwidth, int *nfheight); |
||||
extern void ForeColor (int color); |
||||
extern void DefaultRendition (void); |
||||
extern int WaitForCarriageReturn (long *win, int *x, int *y); |
||||
extern int InitializeGraphics (int scroll_text_up); |
||||
extern void CloseGraphics (void); |
||||
#ifdef __cplusplus |
||||
} |
||||
#endif |
||||
/*----------------------- end-of-file (C header) -----------------------*/ |
@ -1,257 +0,0 @@ |
||||
#include <stdio.h> |
||||
#include <stdlib.h> |
||||
#include <math.h> |
||||
#include <signal.h> |
||||
#include "grxlib.h" |
||||
|
||||
static const char cvs_ident[] = "$Id$"; |
||||
|
||||
#define Real float |
||||
|
||||
#ifndef GRX_SCALE |
||||
# define GRX_SCALE 10000 |
||||
#endif |
||||
|
||||
#define DEFAULT_DATA_FILE "data" |
||||
|
||||
static void |
||||
axis_round (Real *min, Real *max, Real *grid_spacing) |
||||
{ |
||||
int logspace; |
||||
|
||||
logspace = (int)(log10 ((*max - *min)/10.0) + 0.5); |
||||
*grid_spacing = pow (10, (double)logspace); |
||||
*min = (Real)((int)(*min / (*grid_spacing))) * (*grid_spacing); |
||||
*max = (Real)((int)(*max / (*grid_spacing))+1) * (*grid_spacing); |
||||
} |
||||
|
||||
static int |
||||
nice_end (int junk) |
||||
{ |
||||
CloseGraphics (); |
||||
putchar ('\n'); |
||||
exit (EXIT_SUCCESS); |
||||
return 0; |
||||
} |
||||
|
||||
int |
||||
main (int argc, char **argv) |
||||
{ |
||||
char line[256], *file = NULL; |
||||
long id,winclick; |
||||
int Do_Start = 1,tmp; |
||||
Real x[1000000], y[1000000]; |
||||
Real nls[1000]; |
||||
int m, p, i, j, n, nchars, theight, twidth, xclick, yclick; |
||||
int downx = 1000,downy = 1000,upx,upy; |
||||
Real xmax, xmin, ymax, ymin, xdiff, ydiff, xgrid_spacing, ygrid_spacing; |
||||
FILE *fd; |
||||
char axis[100]; |
||||
|
||||
LineFunction linetype = StartLine; |
||||
|
||||
ymax = xmax = -HUGE_VAL; |
||||
ymin = xmin = HUGE_VAL; |
||||
|
||||
for (i = 1; i < argc; i++) |
||||
{ |
||||
if (*argv[i] == '-') |
||||
{ |
||||
if (!strcmp (argv[i], "-nl")) |
||||
linetype = StartPoint; |
||||
else if (argv[i][1] == '\0') /* use stdin */ |
||||
file = argv [i]; |
||||
else |
||||
{ |
||||
|
||||
fprintf(stderr, |
||||
"Usage:\n\t %s [options] [file]\n\n", argv[0]); |
||||
fprintf(stderr, |
||||
"where options include:\n" |
||||
" -pt plot with points instead of lines\n\n"); |
||||
|
||||
fprintf(stderr, |
||||
"file name `-' specifies stdin\n" |
||||
"if no file name is specified, " |
||||
"the default is \"%s\"\n\n", |
||||
DEFAULT_DATA_FILE); |
||||
|
||||
return EXIT_FAILURE; |
||||
} |
||||
} |
||||
else |
||||
{ |
||||
file = argv [i]; |
||||
} |
||||
} |
||||
|
||||
if (!strcmp (file, "-")) |
||||
{ |
||||
fd = stdin; |
||||
file = "stdin"; |
||||
} |
||||
else |
||||
{ |
||||
if (file == NULL) file = DEFAULT_DATA_FILE; |
||||
|
||||
if ((fd = fopen (file, "r")) == NULL) |
||||
{ |
||||
fprintf (stderr, "%s: can't open file \"%s\"\n", argv[0], file); |
||||
return EXIT_FAILURE; |
||||
} |
||||
} |
||||
m = 0; |
||||
p = 0; |
||||
while (fgets(line, sizeof(line),fd) != NULL) |
||||
{ |
||||
if (sscanf(line,"%f %f",&x[m], &y[m]) == 2) |
||||
{ |
||||
if (x[m] > xmax) xmax = x[m]; else if (x[m] < xmin) xmin = x[m]; |
||||
if (y[m] > ymax) ymax = y[m]; else if (y[m] < ymin) ymin = y[m]; |
||||
m++; |
||||
} |
||||
else |
||||
{ |
||||
nls [p] = m; |
||||
p++; |
||||
} |
||||
} |
||||
nls [p++] = m; |
||||
|
||||
if (m == 0) |
||||
return; |
||||
|
||||
signal (SIGTERM, nice_end); |
||||
signal (SIGSTOP, nice_end); |
||||
signal (SIGTSTP, nice_end); |
||||
signal (SIGINT, nice_end); |
||||
signal (SIGQUIT, nice_end); |
||||
if (!InitializeGraphics (1)) |
||||
return EXIT_FAILURE; |
||||
|
||||
n = 1; |
||||
do |
||||
{ |
||||
axis_round (&xmin, &xmax, &xgrid_spacing); |
||||
axis_round (&ymin, &ymax, &ygrid_spacing); |
||||
|
||||
id = CreateWin (0, 0, GRX_SCALE, GRX_SCALE); |
||||
if (id == 0) |
||||
{ |
||||
fprintf (stderr,"Help id = 0\n"); |
||||
return EXIT_FAILURE; |
||||
} |
||||
/* Fill the window in black for real eye-catching graphics! */ |
||||
ForeColor (0); |
||||
StartFill (id); |
||||
FillArea (0, 0, GRX_SCALE, GRX_SCALE); |
||||
Done (); |
||||
|
||||
/* draw outline box in white */ |
||||
ForeColor (7); |
||||
|
||||
/* Draw outline box */ |
||||
StartLine(id); |
||||
Extend (1000, 1000); |
||||
Extend (1000, 9000); |
||||
Extend (9000, 9000); |
||||
Extend (9000, 1000); |
||||
Extend (1000, 1000); |
||||
Done(); |
||||
|
||||
/* Draw the data - either lines or dots */ |
||||
xdiff = 8000 / (xmax-xmin); |
||||
ydiff = 8000 / (ymax-ymin); |
||||
|
||||
for (i = j = 0; j < p; j++) |
||||
{ |
||||
int n = 0; |
||||
|
||||
ForeColor (j%6+1); |
||||
while (((x[i] < xmin) || (x[i] > xmax) || |
||||
(y[i] < ymin) || (y[i] > ymax)) && (i < nls [j])) |
||||
i++; |
||||
|
||||
while (i < nls [j]) |
||||
{ |
||||
if (n == 0) |
||||
linetype (id); |
||||
Extend (1000+(x[i]-xmin)*xdiff,9000-(y[i]-ymin)*ydiff); |
||||
n++; |
||||
if (n > 450) |
||||
{ |
||||
Done (); |
||||
n = 0; |
||||
continue; |
||||
} |
||||
i++; |
||||
while ((i < nls [j]) && |
||||
((x [i] < xmin) || (x [i] > xmax) || |
||||
(y [i] < ymin) || (y [i] > ymax))) |
||||
i++; |
||||
} |
||||
if (n > 0) |
||||
Done (); |
||||
} |
||||
|
||||
/* Do axis labels in black */ |
||||
ForeColor (7); |
||||
QueryWin (id, &twidth,&theight); |
||||
PlaceText (id, GRX_SCALE/2, 0, HCENTER_TEXT|TOP_TEXT, file); |
||||
PlaceText (id, GRX_SCALE/2, GRX_SCALE, HCENTER_TEXT|BOTTOM_TEXT, "X"); |
||||
PlaceText (id, 0, GRX_SCALE/2, LEFT_TEXT|VCENTER_TEXT, "Y"); |
||||
sprintf (axis, "%f", ymax); |
||||
nchars = 1000 / twidth; |
||||
|
||||
axis [nchars] = 0; |
||||
PlaceText (id, GRX_SCALE/10, GRX_SCALE/10, |
||||
RIGHT_TEXT|TOP_TEXT, axis); |
||||
sprintf (axis, "%f", ymin); |
||||
axis [nchars] = 0; |
||||
PlaceText (id, GRX_SCALE/10, 9*GRX_SCALE/10, |
||||
RIGHT_TEXT|BOTTOM_TEXT,axis); |
||||
sprintf (axis, "%f",xmax); |
||||
PlaceText (id, 9*GRX_SCALE/10, 9*GRX_SCALE/10, |
||||
HCENTER_TEXT|TOP_TEXT,axis); |
||||
sprintf (axis,"%f",xmin); |
||||
PlaceText (id, GRX_SCALE/10, 9*GRX_SCALE/10, |
||||
HCENTER_TEXT|TOP_TEXT,axis); |
||||
fflush (stdout); |
||||
|
||||
do |
||||
{ |
||||
n = WaitForCarriageReturn (&winclick, &xclick, &yclick); |
||||
switch (n) { |
||||
case 1: |
||||
downx = xclick; |
||||
downy = yclick; |
||||
break; |
||||
case 2: |
||||
upx = xclick; |
||||
upy = yclick; |
||||
if (upx < downx) |
||||
{ |
||||
tmp = downx; |
||||
downx = upx; |
||||
upx = tmp; |
||||
} |
||||
if (upy < downy) |
||||
{ |
||||
tmp = downy; |
||||
downy = upy; |
||||
upy = tmp; |
||||
} |
||||
xmin = (xmax - xmin) * (downx - 1000) / (8000) + xmin; |
||||
xmax = (xmax - xmin) * (upx - 1000) / (8000) + xmin; |
||||
ymax = ymax - (ymax - ymin) * (downy - 1000) / (8000); |
||||
ymin = ymax - (ymax - ymin) * (upy - 1000) / (8000); |
||||
break; |
||||
} |
||||
} |
||||
while (n && (n != 2)); |
||||
} |
||||
while (n); |
||||
nice_end (EXIT_SUCCESS); |
||||
return EXIT_SUCCESS; |
||||
} |
||||
/*----------------------- end-of-file (C source) -----------------------*/ |
@ -1,53 +0,0 @@ |
||||
/*--------------------------------*-C-*---------------------------------*
|
||||
* File: grx.h |
||||
* |
||||
* Stuff for text alignment for special graphics mode |
||||
* |
||||
* alignment |
||||
* Top: |
||||
* text is placed so that the specified point is at the top of the |
||||
* capital letters |
||||
* Center: |
||||
* text is placed so that the specified point is equidistant from the |
||||
* bottom of descenders and the top of the capital letters |
||||
* Botton: |
||||
* text is placed so that the bottom of descenders is on the specified |
||||
* point |
||||
* Base: |
||||
* text is placed so that the bottom of the characters with no descenders |
||||
* is on the specified point |
||||
* Caps_Center: |
||||
* text is placed so that the specified point is equidistant from the |
||||
* bottom and tops of capital letters |
||||
*----------------------------------------------------------------------*/ |
||||
#ifndef _RXVTGRX_H |
||||
# define _RXVTGRX_H |
||||
|
||||
# define GRX_SCALE 10000 |
||||
|
||||
# define RIGHT_TEXT 0x10 |
||||
# define HCENTER_TEXT 0x20 |
||||
# define LEFT_TEXT 0x30 |
||||
# define HORIZONTAL_ALIGNMENT 0x70 |
||||
|
||||
# define TOP_TEXT 0x01 |
||||
# define VCENTER_TEXT 0x02 |
||||
# define BOTTOM_TEXT 0x03 |
||||
# define BASE_TEXT 0x04 |
||||
# define VCAPS_CENTER_TEXT 0x05 |
||||
# define VERTICAL_ALIGNMENT 0x0F |
||||
|
||||
# if 0 /* this would be nicer */ |
||||
# define TXT_RIGHT 'r' |
||||
# define TXT_CENTER 'c' |
||||
# define TXT_LEFT 'l' |
||||
|
||||
# define TXT_TOP 't' |
||||
# define TXT_VCENTER 'v' |
||||
# define TXT_BOTTOM 'b' |
||||
# define TXT_BASE '_' |
||||
# define TXT_VCAPS_CENTER 'C' |
||||
# endif |
||||
|
||||
#endif /* whole file */ |
||||
/*----------------------- end-of-file (C header) -----------------------*/ |