//========================================= // validColorDepth ( >= 8 Bit ) //----------------------------------------- int validColorDepth (Display* dpy) { int planes = DisplayPlanes (dpy, DefaultScreen(dpy)); if (planes >= MIN_DEPTH) { return 1; } return 0; }
static int get_border_properties(void) { char *bwidth; /*char *bc = NULL;*/ int bw; /*XColor color_def, color_db;*/ Colormap cmap; /*int ret_val;*/ bwidth = "2"; /* XGetDefault(gXDisplay, "Axiom.hyperdoc", "BorderWidth") */ if (bwidth == NULL) bw = 1; else { bw = atoi(bwidth); if (bw < 1) { fprintf(stderr, "%s: The line width value must be greater than zero\n", "Axiom.hyperdoc"); bw = 1; } } /* Now try to find the user preferred border color */ if (DisplayPlanes(gXDisplay, gXScreenNumber) == 1) gBorderColor = BlackPixel(gXDisplay, gXScreenNumber); else { cmap = DefaultColormap(gXDisplay, gXScreenNumber); gBorderColor = get_color("BorderColor", "Foreground", BlackPixel(gXDisplay, gXScreenNumber), &cmap); } return bw; }
int XInitShades(Display *display, int screen) { char *bits; int count; int chars_bitmap = char_bitmap(); int bit; bits = (char *) malloc(chars_bitmap * sizeof(char)); for (count = 0; count < XShadeMax; count++) { /* Load in the next bitmap */ for (bit = 0; bit < chars_bitmap; bit++) bits[bit] = XShadeBits[count * chars_bitmap + bit]; /* Create it and put it into the Pixmap array */ XShade[count] = XCreatePixmapFromBitmapData(display, RootWindow(display, screen), bits, XShadeWidth, XShadeWidth, BlackPixel(display, screen), WhitePixel(display, screen), DisplayPlanes(display, screen)); } TileGC = XCreateGC(display, RootWindow(display, screen), 0, NULL); XSetFillStyle(display, TileGC, FillTiled); XSetTile(display, TileGC, XShade[XShadeMax / 2]); return XShadeMax; }
static void set_up_gradient(void) { int i; #ifdef X11 if (output_methods & TO_X) { colour_depth = DisplayPlanes(display, screen); } else #endif /* X11 */ { colour_depth = 16; } if (colour_depth != 24 && colour_depth != 16) { NORM_ERR("using non-standard colour depth, gradients may look like a " "lolly-pop"); } redmask = 0; greenmask = 0; bluemask = 0; for (i = (colour_depth / 3) - 1; i >= 0; i--) { redmask |= 1 << i; greenmask |= 1 << i; bluemask |= 1 << i; } if (colour_depth % 3 == 1) { greenmask |= 1 << (colour_depth / 3); } redmask = redmask << (2 * colour_depth / 3 + colour_depth % 3); greenmask = greenmask << (colour_depth / 3); }
void do_planes() { int over=0; int finished=0; int width, xloc, yloc, dist, size, i; short** heights; heights=(short **) malloc(DisplayPlanes(dpy, screen)); for (i=0; i < DisplayPlanes(dpy, screen); i++) { heights[i]=(short *) calloc(sizeof(short), DisplayWidth(dpy, screen)); } while (!over) { depth=rnd(DisplayPlanes(dpy, screen)); width=rnd(MIN_WIDTH)+WIDTH_ADD; xloc=calc_xloc(width); yloc=DisplayHeight(dpy, screen); for (i=xloc; i < (xloc+width); i++) { yloc=min(yloc, heights[depth][i]); } if (yloc == DisplayHeight(dpy, screen)) continue; dist=rnd(yloc/10+MIN_DIST); size=rnd(max(yloc+MIN_SIZE, MAX_SIZE)); XSetPlaneMask(dpy, copygc, 1<<depth); XSetPlaneMask(dpy, fillgc, 1<<depth); XCopyArea(dpy, win, win, copygc, xloc, yloc, width, size, xloc, yloc+dist); XFillRectangle(dpy, win, fillgc, xloc, yloc, width, dist); yloc+=dist; for (i=xloc; i < (xloc+width); i++) { if ((heights[depth][i] < (DisplayHeight(dpy, screen)-MIN_SIZE)) && (yloc >= (DisplayHeight(dpy, screen)-MIN_SIZE))) finished++; heights[depth][i]=max(heights[depth][i], yloc); } if (finished >= (DisplayWidth(dpy, screen)-FINISHED)) { XSync(dpy, 0); over=1; } } }
int main(void) { Display * display; XImage * ximage; Window window; XEvent an_event; GC gc; Visual * visual; XGCValues values; int m, n, screen, dplanes; int width, height, ret = 1; width = MAXIMOX; height = MAXIMOY; if ((display = XOpenDisplay(NULL)) == NULL) ret = 0; else { screen = DefaultScreen(display); dplanes = DisplayPlanes(display,screen); visual = XDefaultVisual(display,screen); if (!(window=XCreateSimpleWindow(display,RootWindow(display,screen),0,0,width,height,1,BlackPixel(display,screen),WhitePixel(display,screen)))) ret = 0; else { XSelectInput(display, window, EventMask); gc = XCreateGC(display, window, 0, &values); XMapWindow(display,window); XSync(display,False); ximage = XCreateImage(display,visual,dplanes,ZPixmap,0,malloc(width*height*sizeof(int)),width,height,8,0); /*Imagens*/ Image retinha = Line(260,0,0,240, getColor(255,0,0)); Image retinha2 = Line(10,0,11,240, getColor(0,255,0)); Image retinha3 = Line(0,0,260,240, getColor(0,0,255)); Image retangulozinho = Rectangle(200,200, getColor(255,255,0)); /*Desenhar*/ Draw(ximage,retangulozinho,150,100); Draw(ximage,retinha,100,100); Draw(ximage,retinha2,100,100); Draw(ximage,retinha3,100,100); /*Free memory*/ Dispose(retangulozinho); Dispose(retinha); Dispose(retinha2); Dispose(retinha3); XPutImage(display,window,gc,ximage,0,0,0,0,width,height); sleep(50); } } return 0; }
int x11_init(GraceApp *gapp) { X11Stuff *xstuff = gapp->gui->xstuff; XGCValues gc_val; long mrsize; int max_path_limit; xstuff->screennumber = DefaultScreen(xstuff->disp); xstuff->root = RootWindow(xstuff->disp, xstuff->screennumber); xstuff->gc = DefaultGC(xstuff->disp, xstuff->screennumber); xstuff->depth = DisplayPlanes(xstuff->disp, xstuff->screennumber); /* init colormap */ xstuff->cmap = DefaultColormap(xstuff->disp, xstuff->screennumber); /* redefine colormap, if needed */ if (gapp->gui->install_cmap == CMAP_INSTALL_ALWAYS) { xstuff->cmap = XCopyColormapAndFree(xstuff->disp, xstuff->cmap); gapp->gui->private_cmap = TRUE; } /* set GCs */ if (gapp->gui->invert) { gc_val.function = GXinvert; } else { gc_val.function = GXxor; } gcxor = XCreateGC(xstuff->disp, xstuff->root, GCFunction, &gc_val); /* XExtendedMaxRequestSize() appeared in X11R6 */ #if XlibSpecificationRelease > 5 mrsize = XExtendedMaxRequestSize(xstuff->disp); #else mrsize = 0; #endif if (mrsize <= 0) { mrsize = XMaxRequestSize(xstuff->disp); } max_path_limit = (mrsize - 3)/2; if (max_path_limit < get_max_path_limit(grace_get_canvas(gapp->grace))) { char buf[128]; sprintf(buf, "Setting max drawing path length to %d (limited by the X server)", max_path_limit); errmsg(buf); set_max_path_limit(grace_get_canvas(gapp->grace), max_path_limit); } xstuff->dpi = rint(MM_PER_INCH*DisplayWidth(xstuff->disp, xstuff->screennumber)/ DisplayWidthMM(xstuff->disp, xstuff->screennumber)); return RETURN_SUCCESS; }
int NvCtrlGetScreenPlanes(NvCtrlAttributeHandle *handle) { NvCtrlAttributePrivateHandle *h; if (!handle) return -1; h = (NvCtrlAttributePrivateHandle *) handle; if (h->target_type != NV_CTRL_TARGET_TYPE_X_SCREEN) return -1; return DisplayPlanes(h->dpy, h->target_id); } /* NvCtrlGetScreenPlanes() */
static void InitGlobals(void) { theScreen = DefaultScreen(theDisp); theCmap = DefaultColormap(theDisp, theScreen); rootW = RootWindow(theDisp, theScreen); theGC = DefaultGC(theDisp, theScreen); theVisual = DefaultVisual(theDisp, theScreen); ncells = DisplayCells(theDisp, theScreen); dispWIDE = DisplayWidth(theDisp, theScreen); dispHIGH = DisplayHeight(theDisp, theScreen); dispDEEP = DisplayPlanes(theDisp, theScreen); white = WhitePixel(theDisp,theScreen); black = BlackPixel(theDisp,theScreen); }
int DumpX(bufferdevice * dev, palette * pal) { Display * display; XImage * ximage; Window window; XEvent an_event; GC gc; Visual * visual; XGCValues values; int m, n, screen, dplanes; int width, height, ret = 1; ColorValues * cor; width = dev->MaxX; height = dev->MaxY; if ((display = XOpenDisplay(NULL)) == NULL) ret = 0; else { screen = DefaultScreen(display); dplanes = DisplayPlanes(display,screen); visual = XDefaultVisual(display,screen); if (!(window=XCreateSimpleWindow(display,RootWindow(display,screen),0,0,width,height,1,BlackPixel(display,screen),WhitePixel(display,screen)))) ret = 0; else { XSelectInput(display, window, EventMask); gc = XCreateGC(display, window, 0, &values); XMapWindow(display,window); XSync(display,False); ximage = XCreateImage(display,visual,dplanes,ZPixmap,0,malloc(width*height*sizeof(int)),width,height,8,0); for(m=0;m<height;m++) { for(n=0;n<width;n++) { cor = GetColor(dev->buffer[m*width+n],pal); ximage -> data[(m*4)*width+n*4] = (char) round((cor->blue)*255); ximage -> data[(m*4)*width+n*4+1] = (char) round((cor->green)*255); ximage -> data[(m*4)*width+n*4+2] = (char) round((cor->red)*255); ximage -> data[(m*4)*width+n*4+3] = (char) 0; } } XPutImage(display,window,gc,ximage,0,0,0,0,width,height); sleep(30); } } return ret; }
void initX() { theDisplay = XOpenDisplay(NULL); if( theDisplay == NULL) { fprintf( stderr, "Can't esatblish connection to server %s.\n" ,XDisplayName(NULL) ); //exit(1); } theScreen = DefaultScreen( theDisplay ); theDepth = DisplayPlanes(theDisplay,theScreen); x_inited = 1; }
int DisplayWindow(int width,int height, int positionX,int positionY){ int ret =1; WindowProperties.width=width; WindowProperties.height=height; if ((WindowProperties.display = XOpenDisplay(NULL)) == NULL) ret = 0; else { WindowProperties.screen = DefaultScreen(WindowProperties.display); WindowProperties.dplanes = DisplayPlanes(WindowProperties.display,WindowProperties.screen); WindowProperties.visual = XDefaultVisual(WindowProperties.display,WindowProperties.screen); if (!(WindowProperties.window=XCreateSimpleWindow(WindowProperties.display,RootWindow(WindowProperties.display,WindowProperties.screen),positionX,positionY,width,height,1,BlackPixel(WindowProperties.display,WindowProperties.screen),WhitePixel(WindowProperties.display,WindowProperties.screen)))) ret = 0; else{ XSelectInput(WindowProperties.display, WindowProperties.window, EventMask); WindowProperties.gc = XCreateGC(WindowProperties.display, WindowProperties.window, 0, &WindowProperties.values); XMapWindow(WindowProperties.display,WindowProperties.window); XSync(WindowProperties.display,False); WindowProperties.ximage = XCreateImage(WindowProperties.display,WindowProperties.visual,WindowProperties.dplanes,ZPixmap,0,malloc(width*height*sizeof(int)),width,height,8,0); } return ret; } }
main() { Display * display; int screen; char * display_name=NULL; Window root; Visual* visual; /* Connect to X display server. */ display=XOpenDisplay(display_name); /* Get screen ID */ screen=DefaultScreen(display); printf("\n\tInformation extracted from the X server\n"); printf("\t---------------------------------------\n\n"); printf(" X server by \'%s\'\n", ServerVendor(display)); printf(" X Server protocol %d\n", ProtocolVersion(display)); printf(" X server Release %d\n", VendorRelease(display)); printf(" Screen is %dmm high.\n", DisplayHeightMM(display, screen)); printf(" Screen is %dmm wide.\n", DisplayWidthMM(display, screen)); printf(" Screen is %d pixels high.\n", DisplayHeight(display, screen)); printf(" Screen is %d pixels wide.\n", DisplayWidth(display, screen)); visual = DefaultVisual(display,screen); printf(" %3d Colour map entries", visual->map_entries); printf(" (Number of colours on the screen at one time).\n"); printf(" %3d Display planes (bits per screen pixel).\n", DisplayPlanes(display, screen)); printf(" There is %d screen(s).\n", ScreenCount (display)); }
void parse_input_pix(void) { TextNode *pixnode; char *filename; pixnode = curr_node; pixnode->type = token.type; pixnode->space = token.id[-1]; pixnode->width = -1; get_expected_token(Lbrace); filename = get_input_string(); pixnode->data.text = alloc_string(filename); curr_node = pixnode; if (pixnode->type == Inputimage) { char f[256]; char *p; if ((gXDisplay && DisplayPlanes(gXDisplay, gXScreenNumber) == 1) || gSwitch_to_mono ==1) { pixnode->type = Inputbitmap; strcpy(f, pixnode->data.text); strcat(f, ".bm"); p=pixnode->data.text; pixnode->data.text = alloc_string(f); free(p); } else { pixnode->type = Inputpixmap; strcpy(f, pixnode->data.text); #ifdef OLD strcat(f, ".pm"); #endif strcat(f, ".xpm"); p=pixnode->data.text; pixnode->data.text = alloc_string(f); free(p); } } }
//========================================= // update root window contents //----------------------------------------- void RedrawWindow (void) { int i; int planes = 0; for (i=0;i<scr_count;i++) { Window root = RootWindow(dpy,i); GC mgc = DefaultGC(dpy,i); planes = DisplayPlanes (dpy,i); if (planes < 8) { continue; } XCopyArea ( dpy,save[i].bg,root,mgc,0,0, save[i].width,save[i].height,save[i].x1,save[i].y1 ); if (i > 0) { XPutImage ( dpy,root,mgc,img,0,0, imgx,imgy,img->width,img->height ); } } XFlush(dpy); }
void expose_handler (ClientData cd, XEvent *ev) { Display *display; Window window; Visual *visual; GC gc; int screen; int depth; Tk_Window tkwin; tkwin=(Tk_Window) cd; display=Tk_Display (tkwin); window=Tk_WindowId (tkwin); gc=Tk_GetGC (tkwin,0,NULL); visual=Tk_Visual (tkwin); if (ximage==NULL) { screen=DefaultScreen (display); depth=DisplayPlanes (display,screen); image_data=(char *) malloc (RESX*RESY); ximage=XCreateImage (display,visual,depth,ZPixmap,0,image_data,RESX,RESY,8,0); gen_image (); } }
XMenu * XMenuCreate(Display *display, Window parent, register char const *def_env) /* ID of previously opened display */ /* Window ID of the menu's parent window. */ /* X Defaults program environment name. */ { register char *def_val; /* X Default value temp variable. */ register XMenu *menu; /* Pointer to the new menu. */ XMStyle menu_style; /* Menu display style. */ XMMode menu_mode; /* Menu display mode. */ XMPane *pane; /* Pane list header. */ XAssocTable *assoc_tab; /* XAssocTable pointer. */ int freeze; /* Freeze server mode. */ int reverse; /* Reverse video mode. */ XMStyle p_style; /* Pane display style. */ char const *p_fnt_name; /* Flag font name. */ XFontStruct *p_fnt_info; /* Flag font structure */ int p_fnt_pad; /* Flag font padding in pixels. */ double p_spread; /* Pane spread in flag height fractions. */ int p_fnt_height; /* Pane character height. */ int p_bdr_width; /* Pane border width. */ int flag_height; /* Flag window height. */ int p_height; /* Pane window height. */ int p_x_off; /* Pane X offset. */ int p_y_off; /* Pane Y offset. */ GC pane_GC; /* Pane graphics context. */ XMStyle s_style; /* Selection display style. */ char const *s_fnt_name; /* Selection font name. */ XFontStruct *s_fnt_info; /* Selection font structure. */ int s_fnt_pad; /* Selection font padding in pixels. */ int s_fnt_height; /* Selection font character height */ double s_spread; /* Select spread in line height fractions. */ int s_bdr_width; /* Highlight border width. */ int s_height; /* Selection window height. */ int s_x_off; /* Selection window X offset. */ int s_y_off; /* Selection window Y offset. */ GC normal_select_GC; /* GC used for normal video selection. */ GC inverse_select_GC; /* GC used for inverse video selection. */ GC inact_GC; /* GC for inactive pane header and */ /* selections. */ XColor color_def; /* Temp color definition holder. */ XColor p_bdr_color; /* Color of border. */ XColor s_bdr_color; /* Color of highlight. */ XColor p_frg_color; /* Color of pane foreground color. */ XColor s_frg_color; /* Color of selection foreground. */ XColor bkgnd_color; /* Color of background.. */ XColor mouse_color; /* Color of mouse cursor. */ Cursor mouse_cursor; /* Mouse cursor. */ Pixmap inact_bitmap; /* Menu inactive pixmap. */ int inact_pnum; /* Inactive background pattern number. */ Pixmap cursor; /* Cursor pixmap holder. */ Pixmap cursor_mask; /* Cursor mask pixmap holder. */ Pixmap stipple_pixmap; /* Stipple mask for half-tone text. */ unsigned long valuemask; XGCValues *values; Window root = RootWindow (display, DefaultScreen (display)); /* * Calloc the XMenu structure and the initial pane. */ menu = (XMenu *)calloc(1, sizeof(XMenu)); if (menu == NULL) { _XMErrorCode = XME_CALLOC; return(NULL); } pane = (XMPane *)calloc(1, sizeof(XMPane)); if (pane == NULL) { _XMErrorCode = XME_CALLOC; return(NULL); } /* * Create the XAssocTable */ assoc_tab = (XAssocTable *)XCreateAssocTable(XASSOC_TABLE_SIZE); if(assoc_tab == NULL) { _XMErrorCode= XME_CREATE_ASSOC; return(NULL); } /* * Set up the default environment name. */ if (def_env == NULL || *def_env == '\0') def_env = "XMenu"; /* * Set up internal fail-safe defaults. */ freeze = DEF_FREEZE; reverse = DEF_REVERSE; menu_style = DEF_MENU_STYLE; menu_mode = DEF_MENU_MODE; inact_pnum = DEF_INACT_PNUM; p_style = DEF_P_STYLE; p_spread = DEF_P_SPREAD; p_fnt_name = DEF_P_FNT_NAME; p_bdr_width = DEF_P_BDR_WIDTH; s_style = DEF_S_STYLE; s_spread = DEF_S_SPREAD; s_fnt_name = DEF_S_FNT_NAME; s_bdr_width = DEF_S_BDR_WIDTH; /* * Get default values from X. */ def_val = x_get_resource_string ("menuFreeze", "MenuFreeze"); if (def_val != NULL) { if (strcmp(def_val, "on") == 0) freeze = 1; else if (strcmp(def_val, "off") == 0) freeze = 0; } def_val = x_get_resource_string ("menuReverseVideo", "MenuReverseVideo"); if (def_val != NULL) { if (strcmp(def_val, "on") == 0) reverse = 1; else if (strcmp(def_val, "off") == 0) reverse = 0; } def_val = x_get_resource_string ("menuStyle", "MenuStyle"); if (def_val != NULL) { if (strcmp(def_val, "right_hand") == 0) menu_style = RIGHT; else if (strcmp(def_val, "left_hand") == 0) menu_style = LEFT; else if (strcmp(def_val, "center") == 0) menu_style = CENTER; } def_val = x_get_resource_string ("menuMode", "MenuMode"); if (def_val != NULL) { if (strcmp(def_val, "box") == 0) menu_mode = BOX; else if (strcmp(def_val, "invert") == 0) menu_mode = INVERT; } def_val = x_get_resource_string ("menuMouse", "MenuMouse"); if ( def_val != NULL && DisplayCells(display, DefaultScreen(display)) > 2 && XAllocDisplayColor(display, DefaultColormap(display, DefaultScreen(display)), def_val, &mouse_color, &color_def) ); else if (reverse && XAllocDisplayColor(display, DefaultColormap(display, DefaultScreen(display)), "white", &mouse_color, &color_def) ); else if (XAllocDisplayColor(display, DefaultColormap(display, DefaultScreen(display)), "black", &mouse_color, &color_def) ); else {} def_val = x_get_resource_string ("menuBackground", "MenuBackground"); if ( def_val != NULL && DisplayCells(display, DefaultScreen(display)) > 2 && XAllocDisplayColor(display, DefaultColormap(display, DefaultScreen(display)), def_val, &bkgnd_color, &color_def) ); else if (reverse && XAllocDisplayColor(display, DefaultColormap(display, DefaultScreen(display)), "black", &bkgnd_color, &color_def) ); else if (XAllocDisplayColor(display, DefaultColormap(display, DefaultScreen(display)), "white", &bkgnd_color, &color_def) ); else {} def_val = x_get_resource_string ("menuInactivePattern", "MenuInactivePattern"); if (def_val != NULL) { if (strcmp(def_val, "dimple1") == 0) inact_pnum = 0; else if (strcmp(def_val, "dimple3") == 0) inact_pnum = 1; else if (strcmp(def_val, "gray1") == 0) inact_pnum = 2; else if (strcmp(def_val, "gray3") == 0) inact_pnum = 3; else if (strcmp(def_val, "cross_weave") == 0) inact_pnum = 4; } def_val = x_get_resource_string ("paneStyle", "PaneStyle"); if (def_val != NULL) { if (strcmp(def_val, "flush_left") == 0) p_style = LEFT; else if (strcmp(def_val, "flush_right") == 0) p_style = RIGHT; else if (strcmp(def_val, "center") == 0) p_style = CENTER; } def_val = x_get_resource_string ("paneFont", "PaneFont"); if (def_val != NULL) p_fnt_name = def_val; def_val = x_get_resource_string ("paneForeground", "PaneForeground"); if ( def_val != NULL && DisplayCells(display, DefaultScreen(display)) > 2 ) XAllocDisplayColor(display, DefaultColormap(display, DefaultScreen(display)), def_val, &p_frg_color, &color_def); else if (reverse) XAllocDisplayColor(display, DefaultColormap(display, DefaultScreen(display)), "white", &p_frg_color, &color_def); else XAllocDisplayColor(display, DefaultColormap(display, DefaultScreen(display)), "black", &p_frg_color, &color_def); def_val = x_get_resource_string ("paneBorder", "PaneBorder"); if ( def_val != NULL && DisplayCells(display, DefaultScreen(display)) > 2 && XAllocDisplayColor(display, DefaultColormap(display, DefaultScreen(display)), def_val, &p_bdr_color, &color_def) ); else if (reverse && XAllocDisplayColor(display, DefaultColormap(display, DefaultScreen(display)), "white", &p_bdr_color, &color_def) ); else XAllocDisplayColor(display, DefaultColormap(display, DefaultScreen(display)), "black", &p_bdr_color, &color_def); def_val = x_get_resource_string ("paneBorderWidth", "PaneBorderWidth"); if (def_val != NULL) p_bdr_width = atoi(def_val); def_val = x_get_resource_string ("paneSpread", "PaneSpread"); if (def_val != NULL) p_spread = atof(def_val); def_val = x_get_resource_string ("selectionStyle", "SelectionStyle"); if (def_val != NULL) { if (strcmp(def_val, "flush_left") == 0) s_style = LEFT; else if (strcmp(def_val, "flush_right") == 0) s_style = RIGHT; else if (strcmp(def_val, "center") == 0) s_style = CENTER; } def_val = x_get_resource_string ("selectionFont", "SelectionFont"); if (def_val != NULL) s_fnt_name = def_val; def_val = x_get_resource_string ("selectionForeground", "SelectionForeground"); if ( def_val != NULL && DisplayCells(display, DefaultScreen(display)) > 2 && XAllocDisplayColor(display, DefaultColormap(display, DefaultScreen(display)), def_val, &s_frg_color, &color_def) ); else if (reverse && XAllocDisplayColor(display, DefaultColormap(display, DefaultScreen(display)), "white", &s_frg_color, &color_def) ) ; else if (XAllocDisplayColor(display, DefaultColormap(display, DefaultScreen(display)), "black", &s_frg_color, &color_def) ) ; else {} def_val = x_get_resource_string ("selectionBorder", "SelectionBorder"); if ( def_val != NULL && DisplayCells(display, DefaultScreen(display)) > 2 && XAllocDisplayColor(display, DefaultColormap(display, DefaultScreen(display)), def_val, &s_bdr_color, &color_def) ) ; else if (reverse && XAllocDisplayColor(display, DefaultColormap(display, DefaultScreen(display)), "white", &s_bdr_color, &color_def) ) ; else if (XAllocDisplayColor(display, DefaultColormap(display, DefaultScreen(display)), "black", &s_bdr_color, &color_def) ) ; else {} def_val = x_get_resource_string ("selectionBorderWidth", "SelectionBorderWidth"); if (def_val != NULL) s_bdr_width = atoi(def_val); def_val = x_get_resource_string ("selectionSpread", "SelectionSpread"); if (def_val != NULL) s_spread = atof(def_val); /* * Create and store the inactive pattern pixmap. */ { char *data = NULL; int width, height; switch (inact_pnum) { case 0: data = (char *)dimple1_bits; width = dimple1_width; height = dimple1_height; break; case 1: data = (char *)dimple3_bits; width = dimple3_width; height = dimple3_height; break; case 2: data = (char *)gray1_bits; width = gray1_width; height = gray1_height; break; case 3: data = (char *)gray3_bits; width = gray3_width; height = gray3_height; break; case 4: data = (char *)cross_weave_bits; width = cross_weave_width; height = cross_weave_height; break; } if (! data) { _XMErrorCode = XME_STORE_BITMAP; return(NULL); } inact_bitmap = XCreatePixmapFromBitmapData (display, root, data, width, height, p_frg_color.pixel, bkgnd_color.pixel, DisplayPlanes (display, DefaultScreen (display))); } /* * Load the mouse cursor. */ switch (menu_style) { case LEFT: cursor = XCreateBitmapFromData(display, root, left_ptr_bits, left_ptr_width, left_ptr_height); cursor_mask = XCreateBitmapFromData(display, root, left_ptrmsk_bits, left_ptrmsk_width, left_ptrmsk_height); mouse_cursor = XCreatePixmapCursor( display, cursor, cursor_mask, &mouse_color, &bkgnd_color, left_ptr_x_hot, left_ptr_y_hot ); XFreePixmap(display, cursor); XFreePixmap(display, cursor_mask); break; case RIGHT: cursor = XCreateBitmapFromData(display, root, right_ptr_bits, right_ptr_width, right_ptr_height); cursor_mask = XCreateBitmapFromData(display, root, right_ptrmsk_bits, right_ptrmsk_width, right_ptrmsk_height); mouse_cursor = XCreatePixmapCursor( display, cursor, cursor_mask, &mouse_color, &bkgnd_color, right_ptr_x_hot, right_ptr_y_hot ); XFreePixmap(display, cursor); XFreePixmap(display, cursor_mask); break; case CENTER: cursor = XCreateBitmapFromData(display, root, cntr_ptr_bits, cntr_ptr_width, cntr_ptr_height); cursor_mask = XCreateBitmapFromData(display, root, cntr_ptrmsk_bits, cntr_ptrmsk_width, cntr_ptrmsk_height); mouse_cursor = XCreatePixmapCursor( display, cursor, cursor_mask, &mouse_color, &bkgnd_color, cntr_ptr_x_hot, cntr_ptr_y_hot ); XFreePixmap(display, cursor); XFreePixmap(display, cursor_mask); break; default: /* Error! Invalid style parameter. */ _XMErrorCode = XME_STYLE_PARAM; return(NULL); } if (mouse_cursor == _X_FAILURE) { _XMErrorCode = XME_CREATE_CURSOR; return(NULL); } /* * Open the pane and selection fonts. */ p_fnt_info = XLoadQueryFont(display, p_fnt_name); if (p_fnt_info == NULL) { _XMErrorCode = XME_OPEN_FONT; return(NULL); } s_fnt_info = XLoadQueryFont(display, s_fnt_name); if (s_fnt_info == NULL) { _XMErrorCode = XME_OPEN_FONT; return(NULL); } /* * Calculate the fixed padding value in pixels for each font. */ p_fnt_height = p_fnt_info->max_bounds.ascent + p_fnt_info->max_bounds.descent; s_fnt_height = s_fnt_info->max_bounds.ascent + s_fnt_info->max_bounds.descent; p_fnt_pad = s_spread * p_fnt_height; s_fnt_pad = s_spread * s_fnt_height; /* * Calculate fixed height and offset requirements. */ flag_height = p_fnt_height + (p_fnt_pad << 1); p_height = 0; p_y_off = flag_height + p_bdr_width; p_x_off = p_y_off * p_spread; s_height = s_fnt_height + (s_fnt_pad << 1) + (s_bdr_width << 1); s_y_off = s_height; s_x_off = p_x_off; /* * Set up the pane list header. */ pane->next = pane; pane->prev = pane; pane->type = PL_HEADER; pane->serial = -1; /* * Initialize the internal pane and selection creation queues. */ _XMWinQueInit(); /* * Create pane, active, and inactive GC's. */ values = (XGCValues *)malloc(sizeof(XGCValues)); valuemask = (GCForeground | GCBackground | GCFont | GCLineWidth); /* * First, pane. */ values->foreground = p_frg_color.pixel; values->background = bkgnd_color.pixel; values->font = p_fnt_info->fid; values->line_width = p_bdr_width; pane_GC = XCreateGC( display, root, valuemask, values); /* * Then normal video selection. */ values->foreground = s_frg_color.pixel; values->background = bkgnd_color.pixel; values->font = s_fnt_info->fid; values->line_width = s_bdr_width; normal_select_GC = XCreateGC(display, root, valuemask, values); /* * Inverse video selection. */ values->foreground = bkgnd_color.pixel; values->background = s_frg_color.pixel; values->font = s_fnt_info->fid; values->line_width = s_bdr_width; inverse_select_GC = XCreateGC(display, root, valuemask, values); stipple_pixmap = XCreateBitmapFromData(display, root, stipple_bits, stipple_width, stipple_height); /* * Finally, inactive pane header and selections */ valuemask |= (GCFillStyle | GCStipple); values->foreground = s_frg_color.pixel; values->background = bkgnd_color.pixel; values->font = s_fnt_info->fid; values->line_width = s_bdr_width; values->fill_style = FillStippled; values->stipple = stipple_pixmap; inact_GC = XCreateGC(display, root, valuemask, values); valuemask |= (GCGraphicsExposures); values->graphics_exposures = False; /* * Construct the XMenu object. */ /* -------------------- Menu data -------------------- */ menu->menu_style = menu_style; menu->menu_mode = menu_mode; menu->freeze = freeze; menu->aeq = 0; menu->recompute = 1; menu->parent = parent; menu->height = 0; menu->width = 0; menu->mouse_cursor = mouse_cursor; menu->assoc_tab = assoc_tab; menu->p_list = pane; /* -------------------- Pane window data -------------------- */ menu->p_style = p_style; menu->p_events = DEF_P_EVENTS; menu->p_fnt_info = p_fnt_info; menu->p_fnt_pad = p_fnt_pad; menu->p_spread = p_spread; menu->p_bdr_width = p_bdr_width; menu->flag_height = flag_height; menu->p_width = 0; menu->p_height = p_height; menu->p_x_off = p_x_off; menu->p_y_off = p_y_off; menu->p_count = 0; menu->pane_GC = pane_GC; menu->x_pos = 0; menu->y_pos = 0; /* -------------------- Selection window data -------------------- */ menu->s_style = s_style; menu->s_events = DEF_S_EVENTS; menu->s_fnt_info = s_fnt_info; menu->s_fnt_pad = s_fnt_pad; menu->s_spread = s_spread; menu->s_bdr_width = s_bdr_width; /* unnecessary */ menu->s_width = 0; menu->s_height = s_height; menu->s_x_off = s_x_off; menu->s_y_off = s_y_off; menu->s_count = 0; menu->normal_select_GC = normal_select_GC; menu->inverse_select_GC = inverse_select_GC; menu->inact_GC = inact_GC; /* -------------------- Color data -------------------- */ menu->p_bdr_color = p_bdr_color.pixel; menu->s_bdr_color = s_bdr_color.pixel; menu->p_frg_color = p_frg_color.pixel; menu->s_frg_color = s_frg_color.pixel; menu->bkgnd_color = bkgnd_color.pixel; /* -------------------- Pixmap data -------------------- */ menu->p_bdr_pixmap = None; menu->s_bdr_pixmap = None; menu->p_frg_pixmap = None; menu->s_frg_pixmap = None; menu->bkgnd_pixmap = None; menu->inact_pixmap = inact_bitmap; /* * Return the completed XMenu. */ _XMErrorCode = XME_NO_ERROR; return(menu); }
enum _DtGrLoadStatus InitGifObject ( GifObj *go, Display *dpy, Drawable drawable, Screen *screen, int depth, Colormap colormap, Visual *visual, GC gc, enum _DtGrColorModel colorModel, Boolean allowReducedColors) { int r, g, b, i, visualsMatched; XVisualInfo vTemplate, *visualList; /* ** Initialize structure values */ go->bits_per_pixel = 2; go->colors_per_pixel = (int) pow (2, go->bits_per_pixel); go->total_colors = (int) pow (go->colors_per_pixel, 3); go->f_color_map_constructed = 0; go->f_total_greys = 2; go->f_ximage = NULL; go->f_dpy = dpy; go->f_drawable = drawable; go->f_screen = XScreenNumberOfScreen(screen); go->f_dft_depth = depth; go->f_cmap = colormap; go->f_gc = gc; go->f_visual = visual; go->f_ncells = DisplayCells(go->f_dpy, go->f_screen); go->f_nplanes = DisplayPlanes(go->f_dpy,go->f_screen); go->f_white = WhitePixel(go->f_dpy, go->f_screen); go->f_black = BlackPixel(go->f_dpy, go->f_screen); go->f_allow_reduced_colors = allowReducedColors; go->f_color_reduction_used = FALSE; /* ** Initialize color allocation fields according to the color model ** specified by the caller. */ switch (colorModel) { case _DtGrCOLOR: go->f_do_visual = DO_COLOR; go->f_init_total_greys = 32; break; case _DtGrGRAY_SCALE: go->f_do_visual = DO_GREY; go->f_init_total_greys = 32; break; case _DtGrBITONAL: go->f_do_visual = DO_GREY; go->f_init_total_greys = 2; break; default: /* Should never get here */ go->f_do_visual = DO_COLOR; go->f_init_total_greys = 32; } /* Return if the colormap is already allocated */ if ( go->f_color_map_constructed ) return (_DtGrSUCCESS); /* find the visual class code */ vTemplate.screen = go->f_screen; vTemplate.depth = go->f_dft_depth; visualList = XGetVisualInfo( go->f_dpy, VisualScreenMask | VisualDepthMask, &vTemplate, &visualsMatched ); /* Return failure if we can't find a matching visual */ if ( visualsMatched == 0 ) return (_DtGrCONVERT_FAILURE); go->f_visual_class = StaticGray; for ( i=0; i<visualsMatched; i++ ) { if ( visualList[i].visual == go->f_visual ) { go->f_visual_class = visualList[i].class; break; } }
static void ingItColors_and_fonts(void) { char property[256]; char *prop = &property[0]; char *str_type[50]; XrmValue value; Colormap cmap; int ts; /** get the color map for the display **/ /* fprintf(stderr,"initx:ingItColors_and_fonts:entered\n");*/ /* fprintf(stderr,"initx:ingItColors_and_fonts:DefaultColorMap\n");*/ cmap = DefaultColormap(gXDisplay, gXScreenNumber); /* fprintf(stderr,"initx:ingItColors_and_fonts:init_group_stack\n");*/ init_group_stack(); /** then start getting the fonts **/ /* fprintf(stderr,"initx:ingItColors_and_fonts:mergeDatabases\n");*/ mergeDatabases(); /* fprintf(stderr,"initx:ingItColors_and_fonts:XrmGetResource\n");*/ if (XrmGetResource(rDB, "FriCAS.hyperdoc.RmFont", "FriCAS.hyperdoc.Font", str_type, &value) == True) { (void) strncpy(prop, value.addr, (int) value.size); } else { (void) strcpy(prop, RmFontDefault); } /* fprintf(stderr,"initx:ingItColors_and_fonts:load_font 1\n");*/ load_font(&gRmFont, prop); /* fprintf(stderr,"initx:ingItColors_and_fonts:load_font 2\n");*/ load_font(&gInputFont, prop); /* fprintf(stderr,"initx:ingItColors_and_fonts:XrmGetResource 2\n");*/ if (XrmGetResource(rDB, "FriCAS.hyperdoc.TtFont", "FriCAS.hyperdoc.Font", str_type, &value) == True) { (void) strncpy(prop, value.addr, (int) value.size); } else { (void) strcpy(prop, TtFontDefault); } /* fprintf(stderr,"initx:ingItColors_and_fonts:load_font 3\n");*/ load_font(&gTtFont, prop); /* fprintf(stderr,"initx:ingItColors_and_fonts:is_it_850\n");*/ gTtFontIs850=is_it_850(gTtFont); /* fprintf(stderr,"initx:ingItColors_and_fonts:XrmGetResource 5\n");*/ if (XrmGetResource(rDB, "FriCAS.hyperdoc.ActiveFont", "FriCAS.hyperdoc.Font", str_type, &value) == True) { (void) strncpy(prop, value.addr, (int) value.size); } else { (void) strcpy(prop, ActiveFontDefault); } /* fprintf(stderr,"initx:ingItColors_and_fonts:load_font 4\n");*/ load_font(&gActiveFont, prop); /* maintain backwards compatibility */ /* fprintf(stderr,"initx:ingItColors_and_fonts:XrmGetResource 6\n");*/ if (XrmGetResource(rDB, "FriCAS.hyperdoc.FriCASFont", "FriCAS.hyperdoc.Font", str_type, &value) == True) { (void) strncpy(prop, value.addr, (int) value.size); } else { if (XrmGetResource(rDB, "FriCAS.hyperdoc.SpadFont", "FriCAS.hyperdoc.Font", str_type, &value) == True) { (void) strncpy(prop, value.addr, (int) value.size); } else { (void) strcpy(prop, fricas_font_default); } } /* fprintf(stderr,"initx:ingItColors_and_fonts:load_font 5\n");*/ load_font(&fricas_font, prop); /* fprintf(stderr,"initx:ingItColors_and_fonts:XrmGetResource 7\n");*/ if (XrmGetResource(rDB, "FriCAS.hyperdoc.EmphasizeFont", "FriCAS.hyperdoc.Font", str_type, &value) == True) { (void) strncpy(prop, value.addr, (int) value.size); } else { (void) strcpy(prop, EmphasizeFontDefault); } /* fprintf(stderr,"initx:ingItColors_and_fonts:load_font 6\n");*/ load_font(&gEmFont, prop); /* fprintf(stderr,"initx:ingItColors_and_fonts:XrmGetResource 8\n");*/ if (XrmGetResource(rDB, "FriCAS.hyperdoc.BoldFont", "FriCAS.hyperdoc.Font", str_type, &value) == True) { (void) strncpy(prop, value.addr, (int) value.size); } else { (void) strcpy(prop, BoldFontDefault); } /* fprintf(stderr,"initx:ingItColors_and_fonts:load_font 7\n");*/ load_font(&gBfFont, prop); /* * If we are on a monochrome screen, then we ignore user preferences, and * set the foreground and background as I wish */ /* fprintf(stderr,"initx:ingItColors_and_fonts:DisplayPlanes\n");*/ if (DisplayPlanes(gXDisplay, gXScreenNumber) == 1) { gActiveColor = fricas_color = gControlBackgroundColor = gInputBackgroundColor = gBfColor = gEmColor = gRmColor = gSlColor = gTtColor = BlackPixel(gXDisplay, gXScreenNumber); gBackgroundColor = gInputForegroundColor = gControlForegroundColor = WhitePixel(gXDisplay, gXScreenNumber); } else { /* * If I have gotten here, then we must be on a color screen, so see * what the user likes, and set it up */ /* fprintf(stderr,"initx:ingItColors_and_fonts:get_color 1\n");*/ gRmColor = get_color("RmColor", "Foreground", BlackPixel(gXDisplay, gXScreenNumber), &cmap); /* fprintf(stderr,"initx:ingItColors_and_fonts:get_color 2\n");*/ gBackgroundColor = get_color("Background", "Background", WhitePixel(gXDisplay, gXScreenNumber), &cmap); /* fprintf(stderr,"initx:ingItColors_and_fonts:get_color 3\n");*/ gActiveColor = get_color("ActiveColor", "Foreground", BlackPixel(gXDisplay, gXScreenNumber), &cmap); /* * for next two, I want name arg = class arg, ie do not want * Background and Foreground. */ /* fprintf(stderr,"initx:ingItColors_and_fonts:get_color 4\n");*/ gControlBackgroundColor = get_color("ControlBackground", "ControlBackground", WhitePixel(gXDisplay, gXScreenNumber), &cmap); /* fprintf(stderr,"initx:ingItColors_and_fonts:get_color 5\n");*/ gControlForegroundColor = get_color("ControlForeground", "ControlForeground", BlackPixel(gXDisplay, gXScreenNumber), &cmap); /* maintain backwards compatibility */ /* fprintf(stderr,"initx:ingItColors_and_fonts:get_color 6\n");*/ fricas_color = get_color("FriCASColor", "Foreground", 0, &cmap); /* fprintf(stderr,"initx:ingItColors_and_fonts:get_color 7\n");*/ if (fricas_color == 0) fricas_color = get_color("SpadColor", "Foreground", BlackPixel(gXDisplay, gXScreenNumber), &cmap); /* fprintf(stderr,"initx:ingItColors_and_fonts:get_color 8\n");*/ gInputBackgroundColor = get_color("InputBackground", "Foreground", gRmColor, &cmap); /* fprintf(stderr,"initx:ingItColors_and_fonts:get_color 9\n");*/ gInputForegroundColor = get_color("InputForeground", "Background", gBackgroundColor, &cmap); /* fprintf(stderr,"initx:ingItColors_and_fonts:get_color 10\n");*/ gEmColor = get_color("EmphasizeColor", "Foreground", gRmColor, &cmap); /* fprintf(stderr,"initx:ingItColors_and_fonts:get_color 11\n");*/ gTtColor = get_color("TtColor", "Foreground", gRmColor, &cmap); /* fprintf(stderr,"initx:ingItColors_and_fonts:get_color 12\n");*/ gSlColor = get_color("EmphasizeColor", "Foreground", gRmColor, &cmap); /* fprintf(stderr,"initx:ingItColors_and_fonts:get_color 13\n");*/ gBfColor = get_color("BoldColor", "Foreground", gRmColor, &cmap); } /* fprintf(stderr,"initx:ingItColors_and_fonts:makeColors\n");*/ makeColors(gXDisplay, gXScreenNumber, &cmap, &spadColors, &ts); /* * Now set the current color and font, so I never have to do it again */ gTopOfGroupStack->cur_color = gRmColor; gTopOfGroupStack->cur_font = gRmFont; /* fprintf(stderr,"initx:ingItColors_and_fonts:exited\n");*/ }
int kgInitglWindow(void* Gtmp) { #if 0 int snglBuf[] ={GLX_RGBA,GLX_RED_SIZE,1,GLX_GREEN_SIZE,1, GLX_BLUE_SIZE,1,GLX_DEPTH_SIZE,12,None}; int dblBuf[] ={GLX_RGBA,GLX_RED_SIZE,1,GLX_GREEN_SIZE,1, GLX_BLUE_SIZE,1,GLX_DEPTH_SIZE,12,GLX_DOUBLEBUFFER,None}; #endif DIG *G; int snglBuf[] = {GLX_RGBA, GLX_DEPTH_SIZE, 16, None}; int dblBuf[] = {GLX_RGBA, GLX_DEPTH_SIZE, 16, GLX_DOUBLEBUFFER, None}; XVisualInfo *vInfoMain; GLXContext *cMain; Window wMain,*sWin; int nvis,dummy; XVisualInfo sampleVis; Display *xDisplay; int xScreen; DIALOG *D; kgWC *wc; G = (DIG *)Gtmp; D = (DIALOG *)G->D; wc = WC(D); xDisplay = wc->Dsp; #if 1 if(!glXQueryExtension(xDisplay, &dummy, &dummy)) { printf("X server has no OpenGL GLX extension\n"); return 0; } #endif xScreen = DefaultScreen(xDisplay); kgSubWindow(Gtmp); sWin = (Window *)G->glWindow; wMain = *sWin; #if 0 sampleVis.screen = xScreen; sampleVis.depth = DisplayPlanes(xDisplay,DefaultScreen(xDisplay)); sampleVis.visual = XDefaultVisual(xDisplay,DefaultScreen(xDisplay)); sampleVis.visualid = XVisualIDFromVisual( XDefaultVisual(xDisplay,DefaultScreen(xDisplay))); vInfoMain = XGetVisualInfo(xDisplay, VisualIDMask|VisualScreenMask|VisualDepthMask,&sampleVis, &nvis); #else vInfoMain = glXChooseVisual(xDisplay,xScreen,dblBuf); if(vInfoMain == NULL) { vInfoMain = glXChooseVisual(xDisplay,xScreen,snglBuf); if(vInfoMain == NULL) { printf("No RGB Visual with Depth Buffer\n"); return GL_FALSE; } else { G->glDouble=0; printf("RGB Visual with Depth Buffer(single)\n"); } } else { G->glDouble=1; printf("RGB Visual with Depth Buffer(double)\n"); } if(vInfoMain->class != TrueColor) { printf("TrueColor visual required for this program\n"); exit(1); } #endif cMain = (GLXContext *)malloc(sizeof(GLXContext)); *cMain = glXCreateContext(xDisplay, vInfoMain, None, GL_TRUE); if (!(*cMain)) { fprintf(stderr, "Can't create a context!\n"); return GL_FALSE; } G->cMain = (void *) cMain; if (!glXMakeCurrent(xDisplay, wMain, *cMain)) { printf( "Can't make window current drawable!\n"); return GL_FALSE; } XMapWindow(xDisplay, wMain); glViewport(0,0,(G->x2-G->x1+1),(G->y2-G->y1+1)); return GL_TRUE; }
int main(int argc, char ** argv) { FILE * fp; struct Image * frame; Display * display; XImage * ximage; Window window; XEvent an_event; GC gc; Visual * visual; XGCValues values; int m, n, FOREGROUNDP = 0, BACKGROUNDP = 1, screen, dplanes; int IMAGE_HEIGHT, IMAGE_WIDTH; IMAGE_WIDTH = (int) atoi(argv[2]); IMAGE_HEIGHT = (int) atoi(argv[3]); if ((fp=fopen(argv[1],"rb"))==NULL) exit(1); frame = (struct Image *) malloc(IMAGE_WIDTH*IMAGE_HEIGHT*sizeof(struct Image)); if (!frame) exit(1); if ((display = XOpenDisplay(NULL)) == NULL) { printf("Incapaz de conectar ao display...\n"); exit(1); } screen = DefaultScreen(display); dplanes = DisplayPlanes(display,screen); visual = XDefaultVisual(display,screen); FOREGROUNDP=BlackPixel(display,screen); BACKGROUNDP=WhitePixel(display,screen); if (!(window=XCreateSimpleWindow(display,RootWindow(display,screen),0,0,IMAGE_WIDTH,IMAGE_HEIGHT,1,FOREGROUNDP,BACKGROUNDP))) { printf("Não foi possível criar a janela...\n"); exit(1); } XSelectInput(display, window, EventMask); gc = XCreateGC(display, window, 0, &values); XMapWindow(display,window); XSync(display,False); ximage = XCreateImage(display, visual, dplanes, ZPixmap, 0, malloc(IMAGE_WIDTH*IMAGE_HEIGHT*sizeof(int32_t)), IMAGE_WIDTH, IMAGE_HEIGHT, 8, 0); while (1) { if (fread(frame,IMAGE_WIDTH*IMAGE_HEIGHT*sizeof(struct Image),1,fp)<=0) break; for(m=0;m<IMAGE_HEIGHT;m++) { for(n=0;n<IMAGE_WIDTH;n++) { ximage -> data[(m*4)*IMAGE_WIDTH+n*4] = (uint8_t) frame[m*IMAGE_WIDTH+n].blue; ximage -> data[(m*4)*IMAGE_WIDTH+n*4+1] = (uint8_t) frame[m*IMAGE_WIDTH+n].green; ximage -> data[(m*4)*IMAGE_WIDTH+n*4+2] = (uint8_t) frame[m*IMAGE_WIDTH+n].red; ximage -> data[(m*4)*IMAGE_WIDTH+n*4+3] = (uint8_t) 0; } } XPutImage(display, window, gc, ximage, 0, 0, 0, 0, IMAGE_WIDTH, IMAGE_HEIGHT); XFlush(display); usleep(50000); // 50 ms por frame -> aproximadamente 20 quadros por segundo } sleep(5); fclose(fp); return 0; }
/****************************************************************************** * * Function jpeg_to_ximage * * This routine converts compressed jpeg data associated with a _DtGrStream * into an XImage. * * No X color allocation is done. The image is quantized down to MAX_COLORS * during decompression, and an array of XColor structures with the red, * green, and blue fields initialized to the colors used in the image is * returned to the caller. Each pixel value in the XImage data is an index * into this array. The caller must use this information to allocate X * color cells and substitute the appropriate pixel values into the XImage * data array before using the XImage. * * The routine makes use of a custom source data manager to allow the JPEG * data source to be a _DtGrStream, a custom data destination manager to * allow the decompressed and post-processed data to be written to an XImage, * and a custom error handler to allow standard _DtGr error codes to be * returned to the caller in the event of a JPEG library error. * *****************************************************************************/ enum _DtGrLoadStatus jpeg_to_ximage ( _DtGrStream *stream, Screen *screen, Visual *visual, Dimension *in_out_width, Dimension *in_out_height, XImage **ximage, XColor **xcolors, int *ncolors, int *xres) { struct jpeg_decompress_struct cinfo; struct my_error_mgr jerr; djpeg_dest_ptr dest_mgr = NULL; ximg_dest_ptr dest; int i, num_scanlines, nullCount, ximWidth; unsigned char *ximData = NULL; Display *display = DisplayOfScreen(screen); int nplanes = DisplayPlanes(display,XScreenNumberOfScreen(screen)); XColor *colors = NULL; /* ** Initialize the return values */ *ximage = NULL; *xres = *ncolors = *in_out_width = *in_out_height = 0; /* ** Initialize the jpeg library error handler with our custom routines */ cinfo.err = jpeg_std_error(&jerr.pub); jerr.pub.error_exit = my_error_exit; jerr.pub.output_message = my_output_message; /* ** Establish the setjmp return context for my_error_exit to use */ if (setjmp(jerr.setjmp_buffer)) { /* If we get here, the JPEG code has signaled an error. We need to ** free memory, clean up the JPEG object, and return a failure code. */ if (*ximage != NULL) XDestroyImage (*ximage); if (colors != NULL) free (colors); jpeg_destroy_decompress(&cinfo); return (_DtGrCONVERT_FAILURE); } /* ** Create a jpeg decompression object */ jpeg_create_decompress(&cinfo); /* ** Create a custom source data manager */ jpeg_stream_src(&cinfo, stream); /* ** Read the jpeg header */ jpeg_read_header(&cinfo, TRUE); if (cinfo.X_density > 0 && (cinfo.density_unit == 1 || cinfo.density_unit == 2)) { if (cinfo.density_unit == 1) *xres = cinfo.X_density; else *xres = cinfo.X_density * 2.54 + 0.5; } /* ** Initialize our desired post-processing attributes */ cinfo.quantize_colors = TRUE; cinfo.desired_number_of_colors = MAX_COLORS; /* ** Create a custom data destination manager to allow our processed data ** to be channeled into an XImage. */ dest_mgr = init_jpeg_dest_mgr(&cinfo); /* ** Initialize the decompression state */ jpeg_start_decompress(&cinfo); (*dest_mgr->start_output) (&cinfo, dest_mgr); /* ** Create an XImage to hold the processed data */ nullCount = (4 - (cinfo.output_width % 4)) & 0x03; ximWidth = cinfo.output_width + nullCount; if (nplanes > 8 ) ximData = (unsigned char *) malloc(ximWidth * cinfo.output_height * 4 ); else ximData = (unsigned char *) malloc(ximWidth * cinfo.output_height ); if (!ximData) { jpeg_destroy_decompress(&cinfo); return (_DtGrNO_MEMORY); } *ximage = XCreateImage(display, visual, nplanes, (nplanes == 1) ? XYPixmap : ZPixmap, 0, (char *)ximData, cinfo.output_width, cinfo.output_height, 32, 0); if (!*ximage) { free (ximData); jpeg_destroy_decompress(&cinfo); return (_DtGrCONVERT_FAILURE); } /* ** Store the XImage in the custom destination manager */ dest = (ximg_dest_ptr) dest_mgr; dest->ximage = *ximage; /* ** Process scanlines until there are none left */ while (cinfo.output_scanline < cinfo.output_height) { num_scanlines = jpeg_read_scanlines(&cinfo, (JSAMPARRAY)dest_mgr->buffer, dest_mgr->buffer_height); (*dest_mgr->put_pixel_rows) (&cinfo, dest_mgr, num_scanlines); } /* ** Return the colormap info as an array of XColors which can be ** used later for X color allocation purposes. */ if (cinfo.actual_number_of_colors) { colors = (XColor *) malloc((unsigned) sizeof(XColor) * cinfo.actual_number_of_colors); if (!colors) { XDestroyImage (*ximage); jpeg_destroy_decompress(&cinfo); return (_DtGrNO_MEMORY); } for (i=0; i<cinfo.actual_number_of_colors; i++) { if (cinfo.out_color_space == JCS_GRAYSCALE) { colors[i].red = colors[i].green = colors[i].blue = INTERP_TO_XCOLORSPACE(cinfo.colormap[0][i]); } else /* JCS_RGB */ { colors[i].red = INTERP_TO_XCOLORSPACE(cinfo.colormap[0][i]); colors[i].green = INTERP_TO_XCOLORSPACE(cinfo.colormap[1][i]); colors[i].blue = INTERP_TO_XCOLORSPACE(cinfo.colormap[2][i]); } } *xcolors = colors; *ncolors = cinfo.actual_number_of_colors; } /* ** Set the other return parameters */ *in_out_width = cinfo.output_width; *in_out_height = cinfo.output_height; /* ** Shut down the decompression engine and free the allocated memory */ (*dest_mgr->finish_output) (&cinfo, dest_mgr); jpeg_finish_decompress(&cinfo); jpeg_destroy_decompress(&cinfo); /* ** Return success */ return (_DtGrSUCCESS); }
int main(int argc, char ** argv) { FILE * fp; Display * display; XImage * ximage; Window window; GC gc; Visual * visual; XGCValues values; int m, n, FOREGROUNDP = 0, BACKGROUNDP = 1, screen, dplanes; int IMAGE_HEIGHT, IMAGE_WIDTH; float *tdc; fp = fopen(argv[1],"rb"); // recupera a tdc do arquivo fread(&IMAGE_WIDTH, sizeof(int), 1, fp); fread(&IMAGE_HEIGHT, sizeof(int), 1, fp); tdc = malloc(sizeof(float) * 3 * IMAGE_WIDTH * IMAGE_HEIGHT); fread(tdc, sizeof(float), 3 * IMAGE_WIDTH * IMAGE_HEIGHT, fp); fclose(fp); // aplica a itdc Image *itdc = malloc(sizeof(Image) * IMAGE_WIDTH * IMAGE_HEIGHT); frame_itdc(&itdc, IMAGE_WIDTH, IMAGE_HEIGHT, &tdc); if ((display = XOpenDisplay(NULL)) == NULL) { printf("Incapaz de conectar ao display...\n"); exit(1); } /* ---------------- funcoes do XDisplay ---------------- */ screen = DefaultScreen(display); dplanes = DisplayPlanes(display,screen); visual = XDefaultVisual(display,screen); FOREGROUNDP=BlackPixel(display,screen); BACKGROUNDP=WhitePixel(display,screen); if (!(window=XCreateSimpleWindow(display,RootWindow(display,screen),0,0,IMAGE_WIDTH,IMAGE_HEIGHT,1,FOREGROUNDP,BACKGROUNDP))) { printf("Não foi possível criar a janela...\n"); exit(1); } XSelectInput(display, window, EventMask); gc = XCreateGC(display, window, 0, &values); XMapWindow(display,window); XSync(display,False); ximage = XCreateImage(display, visual, dplanes, ZPixmap, 0, malloc(IMAGE_WIDTH*IMAGE_HEIGHT*sizeof(int)), IMAGE_WIDTH, IMAGE_HEIGHT, 8, 0); /* ------------------------------------------------ */ // Carrega os valores da itdc para exibir for(m=0;m<IMAGE_HEIGHT;m++) { for(n=0;n<IMAGE_WIDTH;n++) { ximage -> data[(m*4)*IMAGE_WIDTH+n*4] = itdc[m*IMAGE_WIDTH+n].blue; ximage -> data[(m*4)*IMAGE_WIDTH+n*4+1] = itdc[m*IMAGE_WIDTH+n].green; ximage -> data[(m*4)*IMAGE_WIDTH+n*4+2] = itdc[m*IMAGE_WIDTH+n].red; ximage -> data[(m*4)*IMAGE_WIDTH+n*4+3] = 0; } } XPutImage(display, window, gc, ximage, 0, 0, 0, 0, IMAGE_WIDTH, IMAGE_HEIGHT); sleep(10); free(tdc); free(itdc); return 0; }
//-------------------------------------------------------------------------------------------------// void GLXWindow::create(const String& name, uint width, uint height, bool fullScreen, const NameValuePairList *miscParams) { Display *xDisplay = mGLSupport->getXDisplay(); String title = name; uint samples = 0; short frequency = 0; bool vsync = false; bool hidden = false; unsigned int vsyncInterval = 1; int gamma = 0; ::GLXContext glxContext = 0; ::GLXDrawable glxDrawable = 0; Window externalWindow = 0; Window parentWindow = DefaultRootWindow(xDisplay); int left = DisplayWidth(xDisplay, DefaultScreen(xDisplay))/2 - width/2; int top = DisplayHeight(xDisplay, DefaultScreen(xDisplay))/2 - height/2; mIsFullScreen = fullScreen; if(miscParams) { NameValuePairList::const_iterator opt; NameValuePairList::const_iterator end = miscParams->end(); // NB: Do not try to implement the externalGLContext option. // // Accepting a non-current context would expose us to the // risk of segfaults when we made it current. Since the // application programmers would be responsible for these // segfaults, they are better discovering them in their code. if ((opt = miscParams->find("currentGLContext")) != end && StringConverter::parseBool(opt->second)) { if (! glXGetCurrentContext()) { OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR, "currentGLContext was specified with no current GL context", "GLXWindow::create"); } glxContext = glXGetCurrentContext(); glxDrawable = glXGetCurrentDrawable(); } // Note: Some platforms support AA inside ordinary windows if((opt = miscParams->find("FSAA")) != end) samples = StringConverter::parseUnsignedInt(opt->second); if((opt = miscParams->find("displayFrequency")) != end) frequency = (short)StringConverter::parseInt(opt->second); if((opt = miscParams->find("vsync")) != end) vsync = StringConverter::parseBool(opt->second); if((opt = miscParams->find("hidden")) != end) hidden = StringConverter::parseBool(opt->second); if((opt = miscParams->find("vsyncInterval")) != end) vsyncInterval = StringConverter::parseUnsignedInt(opt->second); if ((opt = miscParams->find("gamma")) != end) gamma = StringConverter::parseBool(opt->second); if((opt = miscParams->find("left")) != end) left = StringConverter::parseInt(opt->second); if((opt = miscParams->find("top")) != end) top = StringConverter::parseInt(opt->second); if((opt = miscParams->find("title")) != end) title = opt->second; if ((opt = miscParams->find("externalGLControl")) != end) mIsExternalGLControl = StringConverter::parseBool(opt->second); if((opt = miscParams->find("parentWindowHandle")) != end) { vector<String>::type tokens = StringUtil::split(opt->second, " :"); if (tokens.size() == 3) { // deprecated display:screen:xid format parentWindow = StringConverter::parseUnsignedLong(tokens[2]); } else { // xid format parentWindow = StringConverter::parseUnsignedLong(tokens[0]); } } else if((opt = miscParams->find("externalWindowHandle")) != end) { vector<String>::type tokens = StringUtil::split(opt->second, " :"); LogManager::getSingleton().logMessage( "GLXWindow::create: The externalWindowHandle parameter is deprecated.\n" "Use the parentWindowHandle or currentGLContext parameter instead."); if (tokens.size() == 3) { // Old display:screen:xid format // The old GLX code always created a "parent" window in this case: parentWindow = StringConverter::parseUnsignedLong(tokens[2]); } else if (tokens.size() == 4) { // Old display:screen:xid:visualinfo format externalWindow = StringConverter::parseUnsignedLong(tokens[2]); } else { // xid format externalWindow = StringConverter::parseUnsignedLong(tokens[0]); } } } // Ignore fatal XErrorEvents during parameter validation: oldXErrorHandler = XSetErrorHandler(safeXErrorHandler); // Validate parentWindowHandle if (parentWindow != DefaultRootWindow(xDisplay)) { XWindowAttributes windowAttrib; if (! XGetWindowAttributes(xDisplay, parentWindow, &windowAttrib) || windowAttrib.root != DefaultRootWindow(xDisplay)) { OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR, "Invalid parentWindowHandle (wrong server or screen)", "GLXWindow::create"); } } // Validate externalWindowHandle if (externalWindow != 0) { XWindowAttributes windowAttrib; if (! XGetWindowAttributes(xDisplay, externalWindow, &windowAttrib) || windowAttrib.root != DefaultRootWindow(xDisplay)) { OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR, "Invalid externalWindowHandle (wrong server or screen)", "GLXWindow::create"); } glxDrawable = externalWindow; } // Derive fbConfig ::GLXFBConfig fbConfig = 0; if (glxDrawable) { fbConfig = mGLSupport->getFBConfigFromDrawable (glxDrawable, &width, &height); } if (! fbConfig && glxContext) { fbConfig = mGLSupport->getFBConfigFromContext (glxContext); } mIsExternal = (glxDrawable != 0); XSetErrorHandler(oldXErrorHandler); if (! fbConfig) { int minAttribs[] = { GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT, GLX_RENDER_TYPE, GLX_RGBA_BIT, GLX_RED_SIZE, 1, GLX_BLUE_SIZE, 1, GLX_GREEN_SIZE, 1, None }; int maxAttribs[] = { GLX_SAMPLES, samples, GLX_DOUBLEBUFFER, 1, GLX_STENCIL_SIZE, INT_MAX, GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT, 1, None }; fbConfig = mGLSupport->selectFBConfig(minAttribs, maxAttribs); if (gamma != 0) { mGLSupport->getFBConfigAttrib(fbConfig, GL_FRAMEBUFFER_SRGB_CAPABLE_EXT, &gamma); } mHwGamma = (gamma != 0); } if (! fbConfig) { // This should never happen. OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR, "Unexpected failure to determine a GLXFBConfig","GLXWindow::create"); } mIsTopLevel = (! mIsExternal && parentWindow == DefaultRootWindow(xDisplay)); if (! mIsTopLevel) { mIsFullScreen = false; left = top = 0; } if (mIsFullScreen) { mGLSupport->switchMode (width, height, frequency); } if (! mIsExternal) { XSetWindowAttributes attr; ulong mask; XVisualInfo *visualInfo = mGLSupport->getVisualFromFBConfig (fbConfig); attr.background_pixel = 0; attr.border_pixel = 0; attr.colormap = XCreateColormap(xDisplay, DefaultRootWindow(xDisplay), visualInfo->visual, AllocNone); attr.event_mask = StructureNotifyMask | VisibilityChangeMask | FocusChangeMask; mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask; if(mIsFullScreen && mGLSupport->mAtomFullScreen == None) { LogManager::getSingleton().logMessage("GLXWindow::switchFullScreen: Your WM has no fullscreen support"); // A second best approach for outdated window managers attr.backing_store = NotUseful; attr.save_under = False; attr.override_redirect = True; mask |= CWSaveUnder | CWBackingStore | CWOverrideRedirect; left = top = 0; } // Create window on server mWindow = XCreateWindow(xDisplay, parentWindow, left, top, width, height, 0, visualInfo->depth, InputOutput, visualInfo->visual, mask, &attr); XFree(visualInfo); if(!mWindow) { OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR, "Unable to create an X Window", "GLXWindow::create"); } if (mIsTopLevel) { XWMHints *wmHints; XSizeHints *sizeHints; if ((wmHints = XAllocWMHints()) != NULL) { wmHints->initial_state = NormalState; wmHints->input = True; wmHints->flags = StateHint | InputHint; int depth = DisplayPlanes(xDisplay, DefaultScreen(xDisplay)); // Check if we can give it an icon if(depth == 24 || depth == 32) { if(mGLSupport->loadIcon("GLX_icon.png", &wmHints->icon_pixmap, &wmHints->icon_mask)) { wmHints->flags |= IconPixmapHint | IconMaskHint; } } } // Is this really necessary ? Which broken WM might need it? if ((sizeHints = XAllocSizeHints()) != NULL) { sizeHints->flags = USPosition; } XTextProperty titleprop; char *lst = (char*)title.c_str(); XStringListToTextProperty((char **)&lst, 1, &titleprop); XSetWMProperties(xDisplay, mWindow, &titleprop, NULL, NULL, 0, sizeHints, wmHints, NULL); XFree(titleprop.value); XFree(wmHints); XFree(sizeHints); XSetWMProtocols(xDisplay, mWindow, &mGLSupport->mAtomDeleteWindow, 1); XWindowAttributes windowAttrib; XGetWindowAttributes(xDisplay, mWindow, &windowAttrib); left = windowAttrib.x; top = windowAttrib.y; width = windowAttrib.width; height = windowAttrib.height; } glxDrawable = mWindow; // setHidden takes care of mapping or unmapping the window // and also calls setFullScreen if appropriate. setHidden(hidden); XFlush(xDisplay); WindowEventUtilities::_addRenderWindow(this); } mContext = new GLXContext(mGLSupport, fbConfig, glxDrawable, glxContext); // apply vsync settings. call setVSyncInterval first to avoid // setting vsync more than once. setVSyncInterval(vsyncInterval); setVSyncEnabled(vsync); int fbConfigID; mGLSupport->getFBConfigAttrib(fbConfig, GLX_FBCONFIG_ID, &fbConfigID); LogManager::getSingleton().logMessage("GLXWindow::create used FBConfigID = " + StringConverter::toString(fbConfigID)); mName = name; mWidth = width; mHeight = height; mLeft = left; mTop = top; mActive = true; mClosed = false; }
stk_widget *stk_progress_bar_new(stk_widget *parent_win, int x, int y, uint w, uint h, char *label) { stk_widget *new_pb = (stk_widget*) malloc(sizeof(stk_widget)); stk_progress_bar *pb = (stk_progress_bar*) malloc(sizeof(stk_progress_bar)); int screen; XGCValues gcval; long fg, bg; memset(new_pb, 0, sizeof(stk_widget)); new_pb->dsp = display; new_pb->fontname = "7x13"; screen = DefaultScreen(new_pb->dsp); fg = BlackPixel(new_pb->dsp, screen); bg = WhitePixel(new_pb->dsp, screen); gcval.foreground = fg; gcval.background = bg; new_pb->gc2 = XCreateGC(new_pb->dsp, parent_win->win, GCForeground | GCBackground, &gcval); if(new_pb->dsp) { new_pb->win = XCreateSimpleWindow(new_pb->dsp, parent_win->win, x, y, w, h, 1, fg, bg); new_pb->gc = XCreateGC(new_pb->dsp, new_pb->win, 0, 0); new_pb->font_info = XLoadQueryFont(new_pb->dsp, new_pb->fontname); if(new_pb->fontname != NULL) XSetFont(display, new_pb->gc2, new_pb->font_info->fid); else perror("XLoadQueryFont"); new_pb->mask = ExposureMask | EnterWindowMask | LeaveWindowMask | ButtonPressMask | ButtonReleaseMask; XSelectInput(new_pb->dsp, new_pb->win, new_pb->mask); if(DisplayPlanes(new_pb->dsp, screen) != 1) { pb->cmap = DefaultColormap(new_pb->dsp, screen); if(XAllocNamedColor(new_pb->dsp, pb->cmap, "red", &pb->color, &pb->colorrgb)) XSetForeground(new_pb->dsp, new_pb->gc, pb->color.pixel); } XMapWindow(new_pb->dsp, new_pb->win); memset(pb, 0, sizeof(stk_progress_bar)); new_pb->x = x; new_pb->y = y; new_pb->w = w; new_pb->h = h; new_pb->handler = &stk_progress_bar_handle; pb->pct = 0; new_pb->ext_struct = (void*)pb; if(label) strcpy(pb->label, label); else new_pb->label = NULL; stk_widget_insert((void*)new_pb); return new_pb; } else return NULL; }
/********************************************************************** * XG_INIT * - initializes plotting variables, the colortable, and the GC **********************************************************************/ void xg_init(Display *display, Window can_xid, int *can_bounds, char *fontname, void **xgid) { /* local variables */ struct xg_graphic *graphic; XGCValues gc_val; int i; /* allocate memory for xg_graphic structure */ if ((graphic = (struct xg_graphic *) calloc(1,sizeof(struct xg_graphic))) == NULL) exit(1); /* copy input variables to global variables */ graphic->dpy = display; graphic->xid = can_xid; for (i=0;i<4;i++) graphic->bounds[i] = can_bounds[i]; /* check for the type of display and set the display_type */ graphic->display_depth = DisplayPlanes(graphic->dpy, DefaultScreen(graphic->dpy)); /*fprintf(stderr,"graphic->display_depth:%d Default Visual:%d\n", graphic->display_depth, DefaultVisual(graphic->dpy, DefaultScreen(graphic->dpy)));*/ if (graphic->display_depth == 1 ) { if (XMatchVisualInfo(graphic->dpy,DefaultScreen(graphic->dpy), 1,StaticGray,&(graphic->visinfo)) == 0) { fprintf(stderr,"Error: Could not Match an 1 bit GrayScale plane\n"); exit(-1); } graphic->display_type = StaticGray; graphic->visual = graphic->visinfo.visual; } else if (graphic->display_depth == 8) { if (XMatchVisualInfo(graphic->dpy, DefaultScreen(graphic->dpy), 8,PseudoColor,&(graphic->visinfo)) == 0) { fprintf(stderr,"Error: Could not Match an 8 bit Pseudo-Color plane\n"); exit(-1); } graphic->display_type = PseudoColor; graphic->visual = graphic->visinfo.visual; } else if (graphic->display_depth == 16) { if (XMatchVisualInfo(graphic->dpy, DefaultScreen(graphic->dpy), 16,TrueColor,&(graphic->visinfo)) != 0) { graphic->display_type = TrueColor; graphic->visual = graphic->visinfo.visual; } else if (XMatchVisualInfo(graphic->dpy, DefaultScreen(graphic->dpy), 16,PseudoColor,&(graphic->visinfo)) != 0) { graphic->display_type = PseudoColor; graphic->visual = graphic->visinfo.visual; } else { fprintf(stderr,"Error: Could not Match a 16 bit TrueColor or Pseudocolor plane\n"); exit(-1); } } else if (graphic->display_depth == 24) { if (XMatchVisualInfo(graphic->dpy, DefaultScreen(graphic->dpy), 24,TrueColor,&(graphic->visinfo)) == 0) { fprintf(stderr,"Error: Could not Match a 24 bit TrueColor plane\n"); exit(-1); } graphic->display_type = TrueColor; graphic->visual = graphic->visinfo.visual; } else { graphic->visual = DefaultVisual(graphic->dpy, DefaultScreen(graphic->dpy)); graphic->display_type = 0; } /* set foreground and background colors */ if (graphic->display_type == StaticGray || graphic->display_type == PseudoColor || graphic->display_type == TrueColor) { graphic->bg_pixel = WhitePixel(graphic->dpy, DefaultScreen(graphic->dpy)); graphic->fg_pixel = BlackPixel(graphic->dpy, DefaultScreen(graphic->dpy)); } else { fprintf(stderr, "Error: Could not Match a one, eight, or twentyfour bit plane\n"); exit(-1); } /* load font */ if ((graphic->font_info = XLoadQueryFont(graphic->dpy, fontname)) == NULL) { printf("X Error: Cannot load font: %s\n",fontname); exit(-1); } /* set up graphics context */ gc_val.foreground = graphic->fg_pixel; gc_val.background = graphic->bg_pixel; gc_val.font = graphic->font_info->fid; /* set gc with solid lines */ gc_val.plane_mask = AllPlanes; gc_val.line_style = LineSolid; graphic->gc_solid = XCreateGC(graphic->dpy, graphic->xid, (GCForeground | GCBackground | GCFont | GCPlaneMask | GCLineStyle), &(gc_val)); /* set gc with dash lines */ gc_val.line_style = LineOnOffDash; graphic->gc_dash = XCreateGC(graphic->dpy, graphic->xid, (GCForeground | GCBackground | GCFont | GCPlaneMask | GCLineStyle), &(gc_val)); /* return pointer to xg_graphic structure */ *xgid = (void *) graphic; }
int XDisplayPlanes(Display *dpy, int scr) { return (DisplayPlanes(dpy, scr)); }
void init_window(int argc, char *argv[]) { unsigned long get_color_pix(char *color_name); screen = DefaultScreen(display); #if defined(HAVE_BZERO) && !defined(HAVE_MEMSET) bzero(&xsh, sizeof(xsh)); #else memset(&xsh, 0, sizeof(xsh)); #endif if (geometry) { int bitmask; bitmask = XGeometry(display, screen, geometry, NULL, bwidth, 1, 1, 1, 1, &(xsh.x), &(xsh.y), &(xsh.width), &(xsh.height)); if (bitmask & (XValue | YValue)) { xsh.flags |= USPosition; } if (bitmask & (WidthValue | HeightValue)) { xsh.flags |= USSize; } } else { xsh.flags = USPosition | PSize; if (!landscape) { xsh.width = XLENG / shrink; xsh.height = YLENG / shrink; xsh.x = X0; xsh.y = Y0; } else { xsh.width = YLENG / shrink; xsh.height = XLENG / shrink; xsh.x = X0_LAND; xsh.y = Y0; } } /** Color **/ #ifdef COLOR_BUG reverse = 1; #endif if (DisplayPlanes(display, screen) >= 3) { c_flg = 1; if (!reverse) { forepix = get_color_pix(fore_color); backpix = get_color_pix(back_color); highpix = get_color_pix(high_color); brdrpix = get_color_pix(brdr_color); mouspix = get_color_pix(mous_color); } else { forepix = get_color_pix(back_color); backpix = get_color_pix(fore_color); highpix = get_color_pix(high_color); brdrpix = get_color_pix(brdr_color); mouspix = get_color_pix(mous_color); } } else { if (!reverse) { forepix = BlackPixel(display, screen); highpix = BlackPixel(display, screen); backpix = WhitePixel(display, screen); brdrpix = BlackPixel(display, screen); mouspix = BlackPixel(display, screen); } else { forepix = WhitePixel(display, screen); highpix = WhitePixel(display, screen); backpix = BlackPixel(display, screen); brdrpix = WhitePixel(display, screen); mouspix = WhitePixel(display, screen); } } /** Generate Window **/ main_window = XCreateSimpleWindow(display, DefaultRootWindow(display), xsh.x, xsh.y, xsh.width, xsh.height, bwidth, brdrpix, backpix); XSetStandardProperties(display, main_window, windowtitle, windowtitle, None, argv, argc, &xsh); /* winatt.bit_gravity = SouthWestGravity; */ XChangeWindowAttributes(display, main_window, CWBitGravity, &winatt); /** Map Window **/ XSelectInput(display, main_window, StructureNotifyMask); XMapWindow(display, main_window); for (;;) { XNextEvent(display, &ev); if (ev.type == MapNotify) break; } XSelectInput(display, main_window, ButtonPressMask | PointerMotionMask | KeyPressMask | ExposureMask); /* KeyReleaseMask|ExposureMask|StructureNotifyMask); */ /** Cursor **/ watch_cur = XCreateFontCursor(display, XC_watch); XDefineCursor(display, main_window, watch_cur); /** GC **/ gcval.line_width = 1; gc = XCreateGC(display, main_window, GCLineWidth, &gcval); XSetFunction(display, gc, GXcopy); XSetGraphicsExposures(display, gc, False); XSetForeground(display, gc, forepix); XSetBackground(display, gc, backpix); font = XLoadFont(display, f_name[fno]); XSetFont(display, gc, font); }
int X11_Init(void) { char buf[512]; char *displayname; XGCValues gcvalues; /* grrr, Xtk forced contortions */ char *argv[2]; int argc = 2; if (cp_getvar("display", CP_STRING, buf)) { displayname = buf; } else if (!(displayname = getenv("DISPLAY"))) { internalerror("Can't open X display."); return (1); } # ifdef DEBUG _Xdebug = 1; # endif argv[0] = "ngspice"; argv[1] = displayname; /* argv[2] = "-geometry"; argv[3] = "=1x1+2+2"; */ /* initialize X toolkit */ toplevel = XtInitialize("ngspice", "Nutmeg", NULL, 0, &argc, argv); display = XtDisplay(toplevel); X11_Open = 1; /* "invert" works better than "xor" for B&W */ /* xor gc should be a function of the pixels that are written on */ /* gcvalues.function = GXxor; */ /* this patch makes lines visible on true color displays Guenther Roehrich 22-Jan-99 */ gcvalues.function = GXinvert; gcvalues.line_width = 1; gcvalues.foreground = 1; gcvalues.background = 0; xorgc = XCreateGC(display, DefaultRootWindow(display), GCLineWidth | GCFunction | GCForeground | GCBackground, &gcvalues); /* set correct information */ dispdev->numlinestyles = NUMLINESTYLES; dispdev->numcolors = NUMCOLORS; dispdev->width = DisplayWidth(display, DefaultScreen(display)); dispdev->height = DisplayHeight(display, DefaultScreen(display)); /* we don't want non-fatal X errors to call exit */ XSetErrorHandler(errorhandler); numdispplanes = DisplayPlanes(display, DefaultScreen(display)); return (0); }
//========================================= // prepare when ready //----------------------------------------- void prepare (void) { int count; char disp[80] = ""; if (displayname != NULL) { sprintf(disp,"DISPLAY=%s",displayname); putenv (disp); } //========================================= // start windowmanager... //----------------------------------------- wmpid = fork(); switch(wmpid) { case -1: perror("fork"); exit(1); break; case 0: execl(FVWM,"fvwm2","-f",FVWMRC,NULL); break; default: waitpid ( wmpid, NULL, WNOHANG | WUNTRACED ); } //========================================= // enable accessX... //----------------------------------------- XAccess(dpy,displayname); //========================================= // set the fashion style for all displays // including Xinerama handling here... //------------------------------------------ CountScreens (dpy); for (count = 0;count < scr_count; count++) { int bannerpid; int current_screen = scr[count]; Window root = RootWindow(dpy, current_screen); int depth = DefaultDepth(dpy,current_screen); char* display = (char*)malloc(sizeof(char)*128); char* dspstr = (char*)malloc(sizeof(char)*128); char* color = (char*)malloc(sizeof(char)*128); char screenStr [255] = ""; char x [128] = ""; char y [128] = ""; int x1,y1,width,height; GC mgc = DefaultGC(dpy,current_screen); Cursor cursor; //========================================= // set the background to darkSlateBlue //----------------------------------------- sprintf(color,"MidnightBlue"); if (blank) { sprintf(color,"black"); } XSetWindowBackground( dpy, root, NameToPixel( color,BlackPixel(dpy,current_screen),dpy,current_screen ) ); XClearWindow(dpy,root); XSetCloseDownMode(dpy, RetainPermanent); usleep (1000); if (blank) { XFlush(dpy); } //========================================= // set the corner marks //----------------------------------------- if (! blank) { setCorner ("10x15-0-0",dpy,current_screen); setCorner ("10x15-0+0",dpy,current_screen); setCorner ("10x15+0-0",dpy,current_screen); setCorner ("10x15+0+0",dpy,current_screen); //========================================= // set the bounding rectangle //----------------------------------------- setBounding (dpy,current_screen); //========================================= // set the SuSE Linux banner //----------------------------------------- if (DisplayPlanes (dpy, current_screen) >= 8) { sprintf(dspstr,"%s",displayname); dspstr = strtok (dspstr,"."); sprintf(display,"%s.%d",dspstr,current_screen); sprintf(x,"%d",DisplayWidth (dpy,current_screen) - 150); sprintf(y,"%d",DisplayHeight (dpy,current_screen) - 80); bannerpid = fork(); switch(bannerpid) { case -1: perror("fork"); exit(1); break; case 0: execl ( XBanner,"xbanner", "-file",XBannerFile,"-display",display, "-px",x,"-py",y,NULL ); break; default: waitpid ( bannerpid, NULL, 0 ); } //=================================================== // create a xlook banner on all non primary screen // pointing out, that this screen is not the one // the configuration program is running on //--------------------------------------------------- if (current_screen > 0) { int HasRender; sprintf(screenStr,"%s %d. %s 1.", gettext("Display"),count+1, gettext("Configuration on display") ); HasRender = XTestRender (dpy); if (! HasRender) { break; } img = setText ( dpy,current_screen,screenStr,&imgx,&imgy ); } //========================================= // set save area of the root window to be // restored on demand //----------------------------------------- x1 = DisplayWidth (dpy,current_screen) - 380; y1 = DisplayHeight (dpy,current_screen) - 120; width = 380; height = 120; save[current_screen].width = width; save[current_screen].height = height; save[current_screen].x1 = x1; save[current_screen].y1 = y1; save[current_screen].bg = XCreatePixmap ( dpy,root,width,height,depth ); XCopyArea ( dpy,root,save[current_screen].bg,mgc,x1,y1,width,height,0,0 ); } //========================================= // set the cursor look and feel //----------------------------------------- cursor = CreateCursorFromName(dpy,current_screen,"top_left_arrow"); if (cursor) { XDefineCursor (dpy,root,cursor); XFreeCursor (dpy,cursor); } } } //========================================= // Enter main loop, restore and redraw //----------------------------------------- if (! blank) { looppid = fork(); switch (looppid) { case -1: perror("fork"); exit(1); break; case 0: while(1) { usleep (50000); RedrawWindow(); } break; } } }