📄 xrgraph.cpp
字号:
while (XPending(display)) XNextEvent(display, &event);} void initgraphique(){ int ddd; atexit(myend); win=0; XSetWindowAttributes attributes; NbErrX11=0; XGCValues gcvalues; XEvent report; display = XOpenDisplay(NULL); if (!display) { cerr << " Erreur openning display " << endl; exit(2); } colortable=0; ncolortable=0; LastColor=2;// En couleur pas defaul // modif FH Display *dpy=display; // Colormap color_map,color_map_sys; visual = DefaultVisual(display, DefaultScreen(display)); fcolor=0; /* pas couleur */ int fstereo=0; /* non */ int nbplans=visual->bits_per_rgb; color_map_sys = DefaultColormap (display, DefaultScreen (display)); color_map = color_map_sys; foreground= BlackPixel(display, screen); background= WhitePixel(display, screen); switch (visual->c_class) { case GrayScale: {break;} case PseudoColor: { cout << " PseudoColor nbcolor =" << visual->map_entries << endl; color_map= XCreateColormap (display, RootWindow (display, DefaultScreen (display)), visual,AllocAll); // copy the def color map for (int i=0;i<visual->map_entries;i++) { XColor colorcell_defs; colorcell_defs.pixel = (unsigned long) i; XQueryColor (display, color_map_sys, &colorcell_defs); XStoreColor (display, color_map, &colorcell_defs); } fcolor=1; SetColorTable(8); // set break; } case DirectColor: { cout << " DirectColor " << endl; fcolor=1; SetColorTable(8); // set break; } case TrueColor : { cout << " TrueColor " << endl; fcolor=1; SetColorTable(8); // set break; } } font_info = XLoadQueryFont(display, "6x9"); if (!font_info) font_info = XLoadQueryFont(display, "6x10"); if( !font_info) {cout << " erreur font 6x10 and 6x9 not found !\n";exit(2);}; XSetErrorHandler((XErrorHandler)xerror); XSetIOErrorHandler((XIOErrorHandler)xerrorio); screen = DefaultScreen(display); width = DisplayWidth(display, screen); height = DisplayHeight(display, screen); ddd = width < height ? width : height; width = ddd*8/10; height = ddd*8/10; attributes.background_pixel = background; attributes.border_pixel = foreground; attributes.backing_store = Always; attributes.colormap = color_map; win = XCreateWindow(display, RootWindow(display, DefaultScreen(display)), 50, 80, width, height,4, CopyFromParent, InputOutput, visual, CWBackPixel | CWBorderPixel | CWBackingStore | CWColormap, &attributes); char title[256]; sprintf(title,"%s%s","FreeFrem++ ",StrVersionNumber().c_str()); XChangeProperty(display, win, XA_WM_NAME, XA_STRING, 8 , PropModeReplace,(const unsigned char *) title , strlen(title)); gcvalues.foreground = foreground; gcvalues.background = background; gcvalues.function = GXcopy ; gc = XCreateGC(display, win, GCForeground | GCBackground | GCFunction, &gcvalues); XSetFillRule(display,gc,WindingRule); // win = XCreateSimpleWindow(display, RootWindow(display, screen), 50, 80, width, height, 4, // foreground,background); cursor_arrow = XCreateFontCursor(display,XC_arrow); cursor_watch = XCreateFontCursor(display,XC_watch); size_hints.flags = PPosition | PSize; size_hints.x = 0; size_hints.y = 0; size_hints.width = width; size_hints.height = height; XSetFont(display, gc, font_info->fid); XSetForeground(display, gc, foreground); XMapWindow(display, win); MyXSelectInput (display, win, (int) (ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask /* | ResizeRedirectMask */ | StructureNotifyMask) ); // do XNextEvent(display, &report); while (report.type != Expose); XDefineCursor(display,win,cursor_watch); XFlush(display); INITGRAPH = 1;}void closegraphique(){ if (INITGRAPH) { INITGRAPH = 0; XUnloadFont(display, font_info->fid); XFreeGC(display, gc); XCloseDisplay(display); closePS(); }}void cadre(reel xmin,reel xmax,reel ymin,reel ymax){ rxmin = xmin; rxmax = xmax; rymin = ymin; rymax = ymax; echx = width / (xmax - xmin); echy = height / (ymax - ymin);}void getcadre(reel &xmin,reel &xmax,reel &ymin,reel &ymax){ xmin = rxmin; xmax = rxmax; ymin = rymin; ymax = rymax;}int InRecScreen(reel x1, reel y1,reel x2, reel y2){ return (Max(x1,x2)>= rxmin) && (Min(x1,x2) <= rxmax) && (Max(y1,y2) >= rymin) && (Min(y1,y2) <= rymax);}int InPtScreen( reel x, reel y){ return (x >= rxmin) && (x <= rxmax) && (y >= rymin) && (y <= rymax);}float scali(int i){ return i/echx + rxmin;}float scalj(int j){ return -j/echy + rymax;}int scalx(reel x){ return (int) Min(fMaxPixel,Max(fMinPixel,((x - rxmin) * echx)));} int scaly(reel y){ return (int)Min(fMaxPixel,Max(fMinPixel,((rymax - y) * echy)));}void pointe(reel x, reel y){ XDrawPoint(display, win, gc, scalx(x), scaly(y));}void rmoveto(reel x, reel y){ currx = scalx(x); curry = scaly(y);}void rlineto(reel x, reel y){ int newx = scalx(x), newy = scaly(y); XDrawLine(display, win, gc, currx, curry, newx, newy); if (psfile) fprintf(psfile,"%d %d %d %d L\n",currx, height-curry, newx, height-newy); currx = newx; curry = newy;/* XFlush(display); */}void cadreortho(reel centrex, reel centrey, reel rayon){ // int xasp,yasp; if (height < width) { rymin = centrey - rayon; rymax = centrey + rayon; echx = echy= height / (2 * rayon); rxmin= centrex - width / (2 * echx); rxmax= centrex + width / (2 * echx); } else { rxmin = centrex - rayon; rxmax = centrex + rayon; echx = echy = width / (2 * rayon); rymin = centrey - height / (2 * echy); rymax = centrey + height / (2 * echy); }}void plotstring (const char * string){ int lx,l = strlen(string); XDrawString(display, win, gc, currx, curry , string, l); lx = XTextWidth( font_info,string,l); if(psfile) fprintf(psfile,"(%s) %d %d S\n",string,currx,height-curry); currx += lx;}void showgraphic(){}void x11draw3(int * ptype){ XGCValues gcvalues; int type; type= *ptype; switch (type) { case 0 : {gcvalues.line_style = LineSolid; break;} case 1 : {gcvalues.line_style = LineOnOffDash; break;} default : {gcvalues.line_style = LineDoubleDash;break;} } XChangeGC(display, gc, GCLineStyle, &gcvalues); if (psfile) switch (type) { case 0 : {fprintf(psfile,"[] setdash\n");break;} case 1 : {fprintf(psfile,"[3] setdash\n");break;} default : {fprintf(psfile,"[4 1] setdash\n");break;} }} void penthickness(int pepais){ XGCValues gcvalues; gcvalues.line_width = pepais; XChangeGC(display, gc, GCLineWidth, &gcvalues); if (psfile) fprintf(psfile,"%d setlinewidth\n",pepais);}void x11linsrn(int * x1,int * x2,int * y1,int * y2) //int *x1,*x2,*y1,*y2;{ XDrawLine(display, win, gc, *x1, *x2, *y1, *y2); /* call(viderbuff)(); */} void viderbuff(){ XRaiseWindow (display,win); XFlush(display); }void cercle(reel centrex, reel centrey, reel rayon){ int r = (int) (rayon * echx); XDrawArc(display, win, gc, scalx(centrex) - r, scaly(centrey) - r, width, height, 0, 360 * 64); XFlush(display);}void reffecran(){ XClearWindow(display,win);}void fillpoly(int n, float *poly){ int i; XPoint *poly0,polyloc[10]; if(n<10) poly0=polyloc; else if(poly0= (XPoint *) malloc(n*sizeof(XPoint)), !poly) { fprintf(stderr, "Erreur d'allocation dans raffpoly\n"); return; } for(i=0; i<n; i++) { poly0[i].x =scalx(poly[2*i]); poly0[i].y =scaly(poly[2*i+1]); } XFillPolygon(display, win, gc, poly0,n, Complex, CoordModeOrigin); if( poly0!=polyloc) free((char*)poly0); if (psfile) { fprintf(psfile,"bF "); for (i=0;i<n;i++) fprintf(psfile,"%d %d ", scalx(poly[2*i]),height-scaly( poly[2*i+1])); fprintf(psfile,"eF\n"); }}#include "getprog-unix.hpp"int execute (const char * str){ return system(str);}char Getijc(int *x1,int *y1){ char char1; XEvent event; int flag,nb; XComposeStatus status; char buffer[20]; KeySym keysym; /* incidence */ XDefineCursor(display,win,cursor_arrow); flag=0; while (!flag) { XNextEvent(display, &event); if(event.type == ButtonRelease) { *x1 = event.xbutton.x; *y1 = event.xbutton.y; if (event.xbutton.button == Button1) char1=shift?248:251; else if (event.xbutton.button == Button2) char1=shift?249:252; else char1=shift?250:253; // printf(" mouse release %d\n",(int) char1); flag=1; } else if(event.type == KeyPress) { *x1 = event.xkey.x; *y1 = event.xkey.y; char1= event.xkey.keycode ; keysym=0; nb=XLookupString(&event.xkey,buffer,20,&keysym,&status);/* printf("nb= %d keysym= %d buffer=",nb,keysym);/* for(i=0;i<20;i++)/* printf(" %d ",(int)buffer[i]);/* printf("\n");*//* voir /usr/include/X11/keysymdef.h + ap_keysym */ if (nb != 0) {char1 = buffer[0]; flag= 1; } else {/* if (IsFunctionKey(keysym)) printf("function down\n"); else if(IsModifierKey(keysym)) printf("modifier down\n"); else if(IsKeypadKey(keysym)) printf(" keypad down\n"); else if(IsMiscFunctionKey(keysym)) printf(" misc function down\n"); else if(IsPFKey(keysym)) printf(" PF key down\n");*/ switch(keysym)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -