📄 _xview.c
字号:
/* initalize the colormap segment data and set the required RGB values */
(red)[0] = 255; (green)[0] = 255; (blue)[0] = 255 ; /* white */
(red)[1] = 0; (green)[1] = 0; (blue)[1] = 0 ; /* black */
(red)[2] = 255; (green)[2] = 0; (blue)[2] = 0 ; /* red */
(red)[3] = 0; (green)[3] = 255; (blue)[3] = 0 ; /* green */
(red)[4] = 0; (green)[4] = 100; (blue)[4] = 255 ; /* blue */
(red)[5] = 255; (green)[5] = 255; (blue)[5] = 0 ; /* yellow */
(red)[6] = 128; (green)[6] = 0; (blue)[6] = 178 ; /* violet */
(red)[7] = 255; (green)[7] = 150; (blue)[7] = 0 ; /* orange */
cms_data.type = XV_STATIC_CMS;
cms_data.size = 8;
cms_data.rgb_count = 8;
cms_data.index = 0;
cms_data.red = red;
cms_data.green = green;
cms_data.blue = blue;
icon = icon_create(ICON_IMAGE, &leda_icon_pixrect, 0);
repaint_count = 0;
frame = window_create(0, FRAME,
WIN_X, w_xpos,
WIN_Y, w_ypos,
WIN_WIDTH, w_width-10,
WIN_HEIGHT, w_height-30,
WIN_IGNORE_EVENT, WIN_REPAINT,
FRAME_NO_CONFIRM, TRUE,
FRAME_LABEL, default_frame_label,
0);
/*
icon = (Icon)xv_create(frame,ICON,
ICON_IMAGE,icon_image,
XV_X, 100,
XV_Y, 100,
0);
*/
window_set(frame, FRAME_ICON, icon,0);
window_set(frame, WIN_SHOW, TRUE, 0);
canvas = window_create(frame, CANVAS,
WIN_EVENT_PROC, x_draw_event_proc,
CANVAS_REPAINT_PROC, x_draw_canvas_repaint_proc,
CANVAS_RESIZE_PROC, x_draw_canvas_resize_proc,
CANVAS_X_PAINT_WINDOW, TRUE,
WIN_CMS_NAME, "palette",
WIN_CMS_DATA, &cms_data,
WIN_IGNORE_EVENT, WIN_REPAINT,
0);
/*
xv_create(canvas,SCROLLBAR,
SCROLLBAR_DIRECTION, SCROLLBAR_HORIZONTAL, 0);
xv_create(canvas,SCROLLBAR,
SCROLLBAR_DIRECTION, SCROLLBAR_VERTICAL, 0);
*/
/* Get the actual indices into the colormap and store them in pixel_table */
xpixels = (int *)xv_get(canvas, WIN_X_COLOR_INDICES);
for (i = 0; i < 8; i++) pixel_table[i] = xpixels[i];
pw = canvas_pixwin(canvas);
xv_set(canvas_paint_window(canvas),
WIN_EVENT_PROC, x_draw_event_proc,
WIN_CONSUME_EVENTS, WIN_RIGHT_KEYS, LOC_MOVE,
LOC_WINENTER, LOC_WINEXIT,
WIN_MOUSE_BUTTONS,
0,
WIN_IGNORE_EVENT, WIN_UP_EVENTS,
WIN_IGNORE_EVENT, WIN_REPAINT,
0);
notify_interpose_destroy_func(frame,x_draw_notice_destroy);
display = (Display *)xv_get(frame,XV_DISPLAY);
drawable = (Drawable)xv_get(pw,XV_XID);
xv_screen = (Xv_Screen)xv_get(frame,XV_SCREEN);
screen = (int)xv_get(xv_screen,SCREEN_NUMBER);
gc = DefaultGC(display,screen);
x_draw_depth = DefaultDepth(display,screen);
screen_width = DisplayWidth(display,screen);
screen_height = DisplayHeight(display,screen);
XSetLineAttributes(display,gc,1,LineSolid,CapButt,JoinMiter);
x_draw_init_fonts();
x_draw_set_show_coord(1);
x_draw_set_line_style(0);
x_draw_set_line_width(1);
x_draw_set_mode(0);
x_draw_set_node_width(12);
x_draw_set_text_mode(0);
x_draw_color = 1;
gc_val.foreground = BlackPixel(display,screen);
XChangeGC(display,gc,GCForeground,&gc_val);
for(i=0;i<8;i++)
{ buffer_width[i] = 0;
buffer_height[i] = 0;
}
x_draw_xmin = 0;
x_draw_ymin = 0;
x_draw_xmax = 0;
x_draw_ymax = 0;
x_draw_scale = 1;
mouse_xpix = 0;
mouse_ypix = 0;
mesg_count = 0;
x_draw_window_xpos = w_xpos;
x_draw_window_ypos = w_ypos;
x_draw_window_width = w_width;
x_draw_window_height = w_height;
/* wait for REPAINT events */
while (repaint_count == 0 ) notify_dispatch();
for(i=0; repaint_count < 2 && i < 1000; i++) notify_dispatch();
x_draw_reset_frame_label();
XFlush(display);
}
x_draw_init(x0,x1,y0,g_mode)
double x0,x1,y0;
int g_mode;
{
double x,y;
DPRINT(("x_draw_init\n"));
draw_init_done = TRUE;
if (x0>=x1)
{fprintf(stderr,"Illegal arguments in draw_init: x0 (%f) >= x1 (%f)\n",x0,x1);
abort();
}
x_draw_grid_mode = g_mode;
xdots = (int)window_get(canvas, CANVAS_WIDTH);
ydots = (int)window_get(canvas, CANVAS_HEIGHT);
x_draw_scale = ((double)xdots)/(x1-x0);
/* at least grid distance of 2 pixels */
if ((x_draw_grid_mode) && (x_draw_grid_mode*x_draw_scale < 2))
{ x_draw_grid_mode=0;
fprintf(stderr,"warning: grid distance to small.\n");
}
if (x_draw_grid_mode)
{ if (x_draw_scale < 1) x_draw_scale = 1;
else x_draw_scale = (int)x_draw_scale;
DPRINT(("grid mode %d ; draw scale %d\n",x_draw_grid_mode,x_draw_scale));
}
x_draw_xmin = x0;
x_draw_ymin = y0;
x_draw_xmax = x0+xdots/x_draw_scale;
x_draw_ymax = y0+ydots/x_draw_scale;
xorigin = -x0*x_draw_scale;
yorigin = ydots+y0*x_draw_scale;
mouse_xreal = 0;
mouse_yreal = 0;
x_draw_clear(0);
if (x_draw_grid_mode) x_draw_cursor();
notify_dispatch();
if (x_draw_grid_mode) x_draw_cursor();
if (x_draw_redraw) (*x_draw_redraw)();
XFlush(display);
}
x_show_window() { while (!x_draw_done) notify_dispatch(); }
x_draw_end()
{ if (pw)
{ pw_close(pw);
/* window_destroy(frame); */
pw = 0;
}
}
x_draw_xpix(x)
double x;
{ return XPIX(x); }
x_draw_ypix(x)
double x;
{ return YPIX(x); }
x_draw_pix(x,y,col)
double x,y;
int col;
{ if (col != x_draw_color) x_draw_set_color(col);
XDrawPoint(display,drawable,gc,XPIX(x),YPIX(y));
if (x_draw_screen_flush)
XFlush(display);
}
x_draw_line(x1, y1, x2, y2, col)
double x1,y1,x2,y2;
int col;
{
int C[4];
int i;
int M = 32768; /* 2^15 */
double slope;
DPRINT(("x_draw_line %d\n",xpix_mode_op));
C[0] = XPIX(x1);
C[1] = YPIX(y1);
C[2] = XPIX(x2);
C[3] = YPIX(y2);
DPRINT(("x_draw_line %d %d %d %d\n\n",C[0],C[1],C[2],C[3]));
/*
Fehler beim Clipping fuer Koordinaten mit Absolutwert in
[i*2^15..(i+1)*2^15-1],i ungerade.
*/
for(i=0; i<4; i++)
if ((C[i]/M) % 2) C[i] = -C[i];
if (col != x_draw_color) x_draw_set_color(col);
XDrawLine(display,drawable,gc,C[0],C[1],C[2],C[3]);
if (x_draw_screen_flush)
XFlush(display);
}
x_draw_point(x,y,col)
double x,y;
int col;
{
int X = XPIX(x);
int Y = YPIX(y);
xv_vector(pw,X-2,Y-2,X+2,Y+2,PIX_SRC^PIX_DST,1);
xv_vector(pw,X+1,Y-1,X+2,Y-2,PIX_SRC^PIX_DST,1);
xv_vector(pw,X-1,Y+1,X-2,Y+2,PIX_SRC^PIX_DST,1);
if (x_draw_screen_flush) XFlush(display);
}
x_draw_arc(x0,y0,r1,r2,start,angle,col)
double x0,y0,r1,r2,start,angle;
int col;
{ int s,e,R1,R2;
s = (int)(360*32*start/M_PI);
e = (int)(360*32*angle/M_PI);
R1 = r1*x_draw_scale;
R2 = r2*x_draw_scale;
if (col != x_draw_color) x_draw_set_color(col);
XDrawArc(display,drawable,gc,XPIX(x0)-R1,YPIX(y0)-R2,2*R1,2*R2,s,e);
if (x_draw_screen_flush)
XFlush(display);
}
x_draw_filled_arc(x0,y0,r1,r2,start,angle,col)
double x0,y0,r1,r2,start,angle;
int col;
{ int s,e,R1,R2;
s = (int)(360*32*start/M_PI);
e = (int)(360*32*angle/M_PI);
R1 = r1*x_draw_scale;
R2 = r2*x_draw_scale;
if (col != x_draw_color) x_draw_set_color(col);
XFillArc(display,drawable,gc,XPIX(x0)-R1,YPIX(y0)-R2,2*R1,2*R2,s,e);
if (x_draw_screen_flush)
XFlush(display);
}
x_draw_node(x0,y0,col)
double x0,y0;
int col;
{ int save = x_draw_set_line_width(1);
double R = x_draw_node_width/x_draw_scale;
x_draw_arc(x0,y0,R,R,0.0,2*M_PI,col);
x_draw_set_line_width(save);
}
x_draw_filled_node(x0,y0,col)
double x0,y0;
int col;
{ double R = x_draw_node_width/x_draw_scale;
x_draw_filled_arc(x0,y0,R,R,0.0,2*M_PI,col); }
x_draw_text_node(x0,y0,s,col)
double x0,y0;
int col;
char* s;
{ XGCValues gc_val;
int save;
gc_val.font = (Font)xv_get(bold_font,XV_XID);
XChangeGC(display,gc,GCFont,&gc_val);
save = x_draw_text_mode;
x_draw_text_mode = 0; /* transparent */
if (x_draw_depth==1 || col == 1)
{ x_draw_filled_node(x0,y0,0);
x_draw_node(x0,y0,1);
}
else
x_draw_filled_node(x0,y0,col);
x_draw_ctext(x0,y0,s,1);
x_draw_text_mode = save;
gc_val.font = (Font)xv_get(text_font,XV_XID);
XChangeGC(display,gc,GCFont,&gc_val);
}
x_draw_int_node(x0,y0,i,col)
double x0,y0;
int i,col;
{ char buf[16];
sprintf(buf,"%d",i);
x_draw_text_node(x0,y0,buf,col);
}
x_draw_ellipse(x0,y0,a,b,alpha,col)
double x0,y0,a,b,alpha;
int col;
{ x_draw_arc(x0,y0,a,b,alpha,2*M_PI,col); }
x_draw_filled_ellipse(x0,y0,a,b,alpha,col)
double x0,y0,a,b,alpha;
int col;
{ x_draw_filled_arc(x0,y0,a,b,alpha,2*M_PI,col); }
x_draw_circle(x0,y0,r,col)
double x0,y0,r;
int col;
{ x_draw_arc(x0,y0,r,r,0.0,2*M_PI,col); }
x_draw_filled_circle(x0,y0,r,col)
double x0,y0,r;
int col;
{ if (r > 0)
x_draw_filled_arc(x0,y0,r,r,0.0,2*M_PI,col);
else
x_draw_pix(x0,y0,col);
}
typedef struct{ int x,y,d; } queue_el;
static queue_el P_QUEUE[2048];
#define FILLPUT(x1,y1,d1)\
{if (pw_get(pw,x1,y1) != col)\
{ pw_put(pw,x1,y1,col);\
top->x = x1;\
top->y = y1;\
top->d = d1;\
top++;\
if (top==stop) top=P_QUEUE; }\
}
static void bfs_fill(x,y,col)
int x,y,col;
{ register queue_el* bot = P_QUEUE;
register queue_el* top = P_QUEUE;
register queue_el* stop = P_QUEUE+2048;
FILLPUT(x,y,0)
while (top != bot)
{ if (bot->d != 1) FILLPUT(bot->x-1,bot->y,3)
if (bot->d != 3) FILLPUT(bot->x+1,bot->y,1)
if (bot->d != 2) FILLPUT(bot->x,bot->y-1,4)
if (bot->d != 4) FILLPUT(bot->x,bot->y+1,2)
bot++;
if (bot==stop) bot=P_QUEUE;
}
}
x_draw_fill(x,y,col)
double x,y;
int col;
{ Rect *r = (Rect *) window_get(canvas, WIN_SCREEN_RECT);
pw_lock(pw,r);
bfs_fill(XPIX(x),YPIX(y),col);
pw_unlock(pw);
}
x_draw_plot_xy(x0,x1,f,col)
double x0,x1;
double (*f)();
int col;
{
XPoint *points;
int x = XPIX(x0);
int y_old = YPIX((*f)(x0));
int i,y_new;
int size = 0;
int n = 0;
if (col != x_draw_color) x_draw_set_color(col);
for(x = XPIX(x0)+1; x <= XPIX(x1); x++)
{ y_new = YPIX((*f)(XREAL(x)));
if (y_new > y_old)
size += (y_new-y_old+1);
else
size += (y_old-y_new+1);
y_old = y_new;
}
points = (XPoint *) malloc(2*size*sizeof(short));
y_old = YPIX((*f)(x0));
for(x = XPIX(x0)+1; x <= XPIX(x1); x++)
{ y_new = YPIX((*f)(XREAL(x)));
if (y_new > y_old)
for(i=y_old; i<=y_new; i++)
{ points[n].x = (short) x;
points[n].y = (short) i;
n++;
}
else
for(i=y_old; i>=y_new; i--)
{ points[n].x = (short) x;
points[n].y = (short) i;
n++;
}
y_old = y_new;
}
XDrawPoints(display,drawable,gc,points,size,CoordModeOrigin);
free((char*)points);
if (x_draw_screen_flush)
XFlush(display);
}
x_draw_plot_yx(y0,y1,f,col)
double y0,y1;
double (*f)();
int col;
{
XPoint *points;
int y;
int i,x_new;
int x_old = XPIX((*f)(y0));
int size = 0;
int n = 0;
if (col != x_draw_color) x_draw_set_color(col);
for(y = YPIX(y0)-1; y >= YPIX(y1); y++)
{ x_new = XPIX((*f)(YREAL(y)));
if (x_new > x_old)
size += (x_new-x_old+1);
else
size += (x_old-x_new+1);
x_old = x_new;
}
points = (XPoint *) malloc(2*size*sizeof(short));
x_old = XPIX((*f)(y0));
for(y = YPIX(y0)-1; y >= YPIX(y1); y--)
{
x_new = XPIX((*f)(YREAL(y)));
if (x_new > x_old)
for(i=x_old; i<=x_new; i++)
{ points[n].x = (short) i;
points[n].y = (short) y;
n++;
}
else
for(i=x_old; i>=x_new; i--)
{ points[n].x = (short) i;
points[n].y = (short) y;
n++;
}
x_old = x_new;
}
XDrawPoints(display,drawable,gc,points,size,CoordModeOrigin);
free((char*)points);
if (x_draw_screen_flush)
XFlush(display);
}
x_draw_filled_polygon(n,xcoord,ycoord,col)
int col, n;
double *xcoord, *ycoord;
{
XPoint *edges;
int i;
edges = (XPoint *) malloc(2*n*sizeof(short));
for(i=0;i<n;i++)
{ edges[i].x = (short) XPIX(xcoord[i]);
edges[i].y = (short) YPIX(ycoord[i]);
}
if (col != x_draw_color) x_draw_set_color(col);
XFillPolygon(display,drawable,gc,edges,n,Convex,CoordModeOrigin);
free((char*)edges);
if (x_draw_screen_flush)
XFlush(display);
}
x_draw_polygon(n,xcoord,ycoord,col)
int col, n;
double *xcoord, *ycoord;
{ int i;
for(i=0;i<n-1;i++)
x_draw_line(xcoord[i],ycoord[i], xcoord[i+1],ycoord[i+1],col);
x_draw_line(xcoord[n-1],ycoord[n-1],xcoord[0],ycoord[0],col);
}
x_draw_rectangle(x1,y1,x2,y2,col)
double x1,y1,x2,y2;
int col;
{
x_draw_line(x1,y1,x1,y2,col);
x_draw_line(x1,y2,x2,y2,col);
x_draw_line(x2,y2,x2,y1,col);
x_draw_line(x2,y1,x1,y1,col);
}
x_draw_filled_rectangle(x1,y1,x2,y2,col)
double x1,y1,x2,y2;
int col;
{ double xcoord[4], ycoord[4];
xcoord[0] = x1;
ycoord[0] = y1;
xcoord[1] = x1;
ycoord[1] = y2;
xcoord[2] = x2;
ycoord[2] = y2;
xcoord[3] = x2;
ycoord[3] = y1;
x_draw_filled_polygon(4,xcoord,ycoord,col);
}
x_draw_copy(x1,y1,x2,y2,buf)
double x1,y1,x2,y2;
int buf;
{
int w = (int)((x2-x1)*x_draw_scale);
int h = (int)((y2-y1)*x_draw_scale);
if (w<=0 || h <=0) return;
buffer_pixmap[buf] = XCreatePixmap(display,drawable,w,h,x_draw_depth);
buffer_width[buf] = w;
buffer_height[buf] = h;
XCopyArea(display,drawable,buffer_pixmap[buf],gc, XPIX(x1),YPIX(y2),w,h,0,0);
}
x_draw_cut(x1,y1,x2,y2,buf)
double x1,y1,x2,y2;
int buf;
{ x_draw_copy(x1,y1,x2,y2,buf);
x_draw_filled_rectangle(x1,y1,x2,y2,0);
}
x_draw_paste(buf,x,y)
double x,y;
int buf;
{ int w = buffer_width[buf];
int h = buffer_height[buf];
if(w>0 && h>0)
XCopyArea(display,buffer_pixmap[buf],drawable,gc,0,0,w,h,XPIX(x),YPIX(y)-h);
}
x_draw_clear_buf(i)
int i;
{ buffer_height[i] = buffer_width[i] = 0; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -