📄 xwindow.c
字号:
unsigned char blowup )
{
XDrawLine(gDisplay, gWindow, pointGC,
blowup*x1, blowup*y1, blowup*x2, blowup*y2 );
XFlush(gDisplay);
}
void xwin_DrawRect(int x1,int y1,int x2,int y2,int mag)
{
x1 = x1 * mag;
y1 = y1 * mag;
x2 = x2 * mag;
y2 = y2 * mag;
XDrawLine(gDisplay,gWindow,rectGC,x1,y1,x2,y1);
XDrawLine(gDisplay,gWindow,rectGC,x1,y1,x1,y2);
XDrawLine(gDisplay,gWindow,rectGC,x2,y1,x2,y2);
XDrawLine(gDisplay,gWindow,rectGC,x1,y2,x2,y2);
XFlush(gDisplay);
}
void xwin_SelRegion( int *sx, int *sy, int *length, int *height)
{
int done =_FALSE;
XEvent event;
int x=0,y=0 ;
*sx = *sy = *length = *height = 0;
fprintf(stdout,"\n\n Left Button:click and Drag \n");
while (!done){
XNextEvent(gDisplay, &event);
switch (event.type){
case ButtonPress:
*sx = x = event.xbutton.x;
*sy = y = event.xbutton.y;
XSetFunction(gDisplay,rectGC,GXxor);
break;
case ButtonRelease:
done = _TRUE;
xwin_DrawRect(*sx,*sy,x,y,1);
break;
case MotionNotify:
if (*sx)
{
xwin_DrawRect(*sx,*sy,x,y,1);
x = event.xbutton.x;
y = event.xbutton.y;
*length = abs(x-*sx);
*height = abs(y-*sy);
xwin_DrawRect(*sx,*sy,x,y,1);
}
break;
}
}
if (x<*sx) *sx = x;
if (y<*sy) *sy = y;
}
/* initialize the object by specifying significant points (drag) */
void xwin_InitSnakeDrag( short *row, short *col,
short *numpts, int spacing)
{
int done = _FALSE ;
XEvent event ;
int x, y;
fprintf(stdout, "\n\n Left Button : Drag, Right Button : Done\n\n");
while( !done ) {
XNextEvent(gDisplay, &event) ;
switch (event.type) {
case ButtonPress : /* initialize first point */
*numpts = 0 ;
*(col + *numpts) = event.xbutton.x ;
*(row + *numpts) = event.xbutton.y ;
XFillRectangle(gDisplay, gWindow, pointGC,
*(col + *numpts)+POINT_OFF,
*(row + *numpts)+POINT_OFF,
POINT_DIM, POINT_DIM) ;
break ;
case ButtonRelease : /* done */
done = _TRUE ;
break ;
case MotionNotify : /* fill points at appropriate distance */ x = event.xbutton.x ;
y = event.xbutton.y ;
if( MAX( abs(x-*(col+*numpts)), abs(y-*(row+*numpts)) )
>= spacing ) {
XFillRectangle(gDisplay, gWindow, pointGC,
x+POINT_OFF, y+POINT_OFF,
POINT_DIM, POINT_DIM) ;
*numpts += 1 ;
*(col + *numpts) = x ;
*(row + *numpts) = y ;
if( *numpts >= MAX_SNAKEPTS - 1 )
done = _TRUE ;
}
break ;
}
}
}
/* ShapeContour allows manual adjustment of snaxel locations. Requires
start of row and column data */
short XgetVicinity(int x,int y, double *row, double *col,short numpts)
{
short count=0;
while (count< numpts)
{
if ((y < *(row+count)+3) && (y > *(row+count)-3))
if ((x < *(col+count)+3) && (x > *(col+count)-3))
return count;
count++;
}
return -1; /* Chosen point is not near any snaxel */
}
void xwin_ShapeContour(XImage *ximg,double *row, double *col,short numpts )
{
int done = _FALSE, end = _FALSE ;
XEvent event ;
int x, y,i;
int target= -1;
fprintf(stdout, "\n\n Left Button : Drag, Right Button : Done\n\n");
while( !end ) {
XNextEvent(gDisplay, &event) ;
switch (event.type) {
case ButtonPress : /* initialize first point */
if (event.xbutton.button !=Button1)
{
end = _TRUE;
XSetFunction(gDisplay,pointGC,GXcopy);
}
else
{
done = _FALSE;
x= event.xbutton.x;
y= event.xbutton.y;
target = XgetVicinity(x,y,row,col,numpts);
}
break ;
case ButtonRelease : /* done */
done = _TRUE ;
if (target != -1)
for (i=0;i<numpts;i++)
XFillRectangle(gDisplay, gWindow, pointGC,
ROUNDOFF(*(col + i)),ROUNDOFF(*(row + i)),
POINT_DIM, POINT_DIM);
target = -1;
break ;
case MotionNotify : /* fill points at appropriate distance*/
if (target!=-1)
{
XPutImage(gDisplay, gWindow, imageGC, ximg,
x-3,y-3,x-3,y-3,POINT_DIM+5,POINT_DIM+5);
XFlush(gDisplay) ;
x = event.xbutton.x;
y = event.xbutton.y;
XFillRectangle(gDisplay, gWindow, pointGC,
x, y, POINT_DIM, POINT_DIM) ;
*(col + target) = x ;
*(row + target) = y ;
}
break;
}
}
}
/* initialize the object by specifying significant points (click) */
void xwin_InitSnakeClick( short *row, short *col,
short *numpts)
{
BOOLEAN done = _FALSE;
XEvent event;
fprintf(stdout, "\n\n Left Button : Click, Right Button : Done\n\n");
*numpts = 0;
while( !done ) {
XNextEvent(gDisplay, &event) ;
if(event.type != ButtonPress) /* only wait for button event */
continue ;
if(event.xbutton.button != Button1) /* exit button pressed */
done = _TRUE ;
else {
*(col + *numpts) = event.xbutton.x ;
*(row + *numpts) = event.xbutton.y ;
XFillRectangle(gDisplay, gWindow, pointGC,
*(col + *numpts)+POINT_OFF,
*(row + *numpts)+POINT_OFF,
POINT_DIM, POINT_DIM);
*numpts += 1;
}
}
}
int xwin_MovePoint(XImage *ximg, short Xsrc, short Ysrc,
short Xdest, short Ydest,
int pt_offx, int pt_offy)
{
XPutImage(gDisplay, gWindow, imageGC, ximg,
ci_expand*Xsrc, ci_expand*Ysrc,
ci_expand*(Xsrc+pt_offx)+POINT_OFF,
ci_expand*(Ysrc+pt_offy)+POINT_OFF,
POINT_DIM, POINT_DIM) ;
XFillRectangle(gDisplay, gWindow, pointGC,
ci_expand*(Xdest+pt_offx)+POINT_OFF,
ci_expand*(Ydest+pt_offy)+POINT_OFF,
POINT_DIM, POINT_DIM) ;
XFlush(gDisplay) ;
return ( (XCheckTypedWindowEvent(gDisplay, gWindow, ButtonPress,
&any_event) == True) ? _FALSE : _TRUE ) ;
}
/* set expand ration */
void xwin_setexpandratio(short expand,
unsigned char blowup )
{
ci_expand = (int)expand *(int)blowup;
POINT_OFF = -(POINT_DIM/2 - (blowup+1)/2) ;
}
void xwin_DrawPoint( short row, short col )
{
XFillRectangle(gDisplay, gWindow, pointGC,
ci_expand*col+POINT_OFF,
ci_expand*row+POINT_OFF,
POINT_DIM, POINT_DIM) ;
XFlush(gDisplay) ;
}
void xwin_clrpoint( XImage *ximg, short col, short row )
{
XPutImage(gDisplay, gWindow, imageGC, ximg,
ci_expand*col, ci_expand*row,
ci_expand*col, ci_expand*row,
POINT_DIM, POINT_DIM) ;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -