📄 dna.cc
字号:
tempstring[0]=s; tempstring[1]=0; offset=0; text_size(tempstring, w, h, ascent, descent); // Draw the string on the Pixmap XSetForeground(g.display, g.gc, (ulong)fcol); if(wantbkg) XSetBackground(g.display,g.gc,(ulong)bcol); else XSetBackground(g.display,g.gc,(ulong)fcol-1); // Initialize spixmap, otherwise if offset!=0, some // pixels are not set. Mainly needed for 'j'. XDrawImageString(g.display, g.spixmap, g.gc, 0, ascent, " ", 3); XDrawImageString(g.display, g.spixmap, g.gc, offset, ascent, tempstring, 1); copyimage(0,0,w,h,0,0,GET,g.stringbufr_ximage,g.spixmap); // Draw fg pixels one at a time on screen // and also put in appropriate buffer. for(j=0;j<h;j++) for(i=0;i<w;i++) { c = pixelat(g.stringbufr[j] + i*g.off[g.bitsperpixel], g.bitsperpixel); if(wantbkg) // Want background and want vertical { if((uint)c==(uint)bcol) XSetForeground(g.display,g.gc,(ulong)bcol); else XSetForeground(g.display,g.gc,(ulong)fcol); }else if(c!=(int)fcol) continue; if(vertical) { xx = x+j; yy = y-i; } else { xx = x+i; yy = y+j; } XDrawPoint(g.display, win, g.gc, xx, yy); } if(vertical) y -= w; else x += w; }}//--------------------------------------------------------------------------//// text_size // //--------------------------------------------------------------------------//void text_size(char *s, int &xsize, int &ysize, int &ascent, int &descent){ int direction; XFontStruct *fstruct; XCharStruct overall; fstruct = g.fontstruct; XTextExtents(fstruct,s,1,&direction,&ascent,&descent,&overall); xsize = XTextWidth(fstruct,s,strlen(s)); ysize = fstruct->ascent + fstruct->descent; ascent =fstruct->ascent; descent = fstruct->descent;}//-------------------------------------------------------------------// // copyimage ////-------------------------------------------------------------------//void copyimage(int x1, int y1, int x2, int y2, int xoff, int yoff, int mode, XImage *ximage, Window win){ uint uw, uh; x1 = max(0,x1); y1 = max(0,y1); x2 = min(g.main_xsize+xoff,x2); y2 = min(g.main_ysize+yoff,y2); uw = 1+x2-x1; uh = 1+y2-y1; if(mode==GET) XGetSubImage(g.display, win, x1, y1, uw, uh, XAllPlanes(), ZPixmap, ximage, xoff, yoff); if(mode==PUT) XPutImage(g.display, win, g.gc, ximage, x1, y1, xoff, yoff, uw, uh);}//--------------------------------------------------------------------------//// pixelat - returns the pixel value that starts at the specified memory //// location, accounting for specified bits/pixel. //// (for accessing pixels in arrays). //// 48 bpp is down-converted to 24. //// Doesn't check the address. It will crash if address is wrong. //// Put bytes in correct order for the x server. Different servers expect //// pixel bytes to be arranged in different orders. ////--------------------------------------------------------------------------//uint pixelat(uchar* p, int bpp){ if(g.ximage_byte_order == LSBFirst) { switch(bpp) { case 7: return ( *p ); case 8: return ( *p ); case 15: return ( 0x7fff & (*(p+1)<<8) + *p ); case 16: return ( (*(p+1)<<8) + *p ); case 24: case 32: return ( (*(p+2)<<16) + (*(p+1)<<8) + *p ); case 48: return ( (*(p+4)<<16) + (*(p+2)<<8) + *p ); } }else { switch(bpp) { case 7: return ( *p ); case 8: return ( *p ); case 15: return ( 0x7fff & (*(p+1)<<8) + *p ); case 16: return ( (*(p)<<8) + *(p+1) ); case 24: return ( (*(p+0)<<16) + (*(p+1)<<8) + *(p+2) ); //ok case 32: return ( (*(p+1)<<16) + (*(p+2)<<8) + *(p+3) ); case 48: return ( (*(p+1)<<16) + (*(p+3)<<8) + *(p+5) ); } } return 0;}//--------------------------------------------------------------------------//// putpixelbytes ////--------------------------------------------------------------------------//void putpixelbytes(uchar *address, int color, int depth){ switch(depth) { case 8: *address = color; break; case 15: case 16: *(short int*)address = (short int)color; break; case 24: *(address+2) = color & 0x0000ff; *(address+1) = color & 0x00ff00; *(address+0) = color & 0xff0000; break; case 32: *(int*)address = (int)color; break; }}//--------------------------------------------------------------------//// cant_overwrite_file - returns 1 if file exists & dont want to //// erase it ////--------------------------------------------------------------------//int cant_overwrite_file(char* filename){ char temp[2048]; if(!access(filename,F_OK)) { sprintf(temp,"Overwrite existing file\n%s (y/n)?",filename); if(message(temp,QUESTION)!=YES) { message("File transfer aborted",WARNING); return(ABORT); } } return(OK);}//--------------------------------------------------------------------//// Callbacks ////--------------------------------------------------------------------//void focuscb(Widget w, XtP client_data, XEvent *event){ client_data=client_data; w=w; // Keep compiler quiet if(event->type==FocusIn) XtSetKeyboardFocus(g.main_widget, g.draw_widget);}//--------------------------------------------------------------------//// clickboxcb - callback for getting a value in dialog box. Called //// by a text widget. Reads the Widget's string, converts it to an //// integer, checks it against the values in the clickboxinfo struct, //// and sets the slider value in the 'c->widget' (which must be a //// XmScale). // //--------------------------------------------------------------------//void clickboxcb(Widget w, XtPointer client_data, XmACB *call_data){ call_data=call_data; // Keep compiler quiet int answer=0; double fanswer=0; char *string = new char[256]; clickboxinfo *c = (clickboxinfo*)client_data; string = XmTextGetString(w); if(string) { if(c->type==INTEGER) { answer = atoi(string); answer=max(min(answer,c->maxval),c->minval); XmScaleSetValue(c->widget[0], answer); } if(c->type==DOUBLE) { fanswer = atof(string) * 1.000001 * pow(10, g.signif); c->fanswer = fanswer; fanswer=max(min(fanswer,c->maxval),c->minval); XmScaleSetValue(c->widget[0], (int)(fanswer)); } } delete[] string;}//--------------------------------------------------------------------//// slidercb - Called by a slider widget, reads the slider's value, //// Widget's string, converts it to a string, and sets the text in the //// 'c->widget' (which must be a XmText). ////--------------------------------------------------------------------//void slidercb(Widget w, XtPointer client_data, XmACB *call_data){ call_data=call_data; // Keep compiler quiet int answer=0; double fanswer=0.0; char *string = new char[256]; strcpy(string," "); clickboxinfo *c = (clickboxinfo*)client_data; XmScaleGetValue(w, &answer); switch(c->type) { case INTEGER: c->f1(answer); itoa(answer, string, 10); break; case DOUBLE: fanswer = ((double)answer)/pow(10, g.signif); c->fanswer = fanswer; c->f2(fanswer); gcvt(fanswer, g.signif, string); break; case INTARRAY: c->answers[c->k] = answer; c->answer = answer; c->f3(c->answers); itoa(c->answers[c->k], string, 10); break; } XmTextSetString(c->widget[0], string); delete[] string;}//--------------------------------------------------------------------//// timer_callback //// Callback function for asynchronous or automatic events ////--------------------------------------------------------------------//void timer_callback(XtPointer client_data, XtIntervalId *timer_id){ client_data=client_data; timer_id=timer_id; // Keep compiler quiet // Restart timer once every 'DELAY' milliseconds int DELAY = 250; XtAppAddTimeOut(XtWidgetToApplicationContext(g.main_widget), DELAY, timer_callback, NULL);} //--------------------------------------------------------------------//// getfilename //// Returns filename ////--------------------------------------------------------------------//char *getfilename(char *oldtitle){ int k; clickboxinfo c; c.title = oldtitle; c.widget[1] = NULL; c.helptopic = 0; c.done = 0; c.wc = 0; c.w = new Widget[20]; c.answers = new int[10]; c.f1 = null; c.f2 = null; c.f3 = null; c.wc = 0; c.form = NULL; c.type = SINGLE; c.list = NULL; c.filename = new char[FILENAMELENGTH]; c.dirmask = new char[FILENAMELENGTH]; c.path = new char[FILENAMELENGTH]; filenamecb(g.main_widget, &c, NULL); // This changes c.wc while(!c.done) XtAppProcessEvent (XtWidgetToApplicationContext(g.main_widget), XtIMAll); for(k=0;k<c.wc;k++) XtDestroyWidget(c.w[k]); delete[] c.w; delete[] c.answers; delete[] c.filename; delete[] c.dirmask; delete[] c.path; if(strlen(c.title)>0) return c.title; else return oldtitle;}//--------------------------------------------------------------------//// getfilenames - allocates array `names', gets one or more filenames,//// allocates space for each filename, and returns the no. of names //// selected by user. Caller must free the strings and the array. //// Returns list of filenames and puts their count in `count'. ////--------------------------------------------------------------------//char **getfilenames(int *count){ int k; clickboxinfo c; c.widget[1] = NULL; c.helptopic = 0; c.done = 0; c.wc = 0; c.w = new Widget[20]; c.f1 = null; c.f2 = null; c.f3 = null; c.wc = 0; c.form = NULL; c.type = MULTIPLE; c.count = 0; c.list = NULL; c.filename = new char[FILENAMELENGTH]; c.dirmask = new char[FILENAMELENGTH]; c.path = new char[FILENAMELENGTH]; strcpy(c.title, "Multiple Filenames"); filenamecb(g.main_widget, &c, NULL); // This changes c.wc while(!c.done) XtAppProcessEvent (XtWidgetToApplicationContext(g.main_widget), XtIMAll); for(k=0;k<c.wc;k++) XtDestroyWidget(c.w[k]); delete[] c.filename; delete[] c.dirmask; delete[] c.path; delete[] c.w; *count = c.count; return c.list;}//--------------------------------------------------------------------//// warningmessagecb - handle warning messages from Xt (mainly "unable //// to allocate colormap entry for default background").
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -