void pager_draw_button (int x, int num) { char label; #ifdef XFT XftColor col; #endif if (num == tb.my_desktop) { /* current desktop */ draw_box (x, PAGER_BUTTON_WIDTH); } else { set_foreground (5); fill_rect (x, 1, PAGER_BUTTON_WIDTH+1, WINHEIGHT - 2); } label = '1' + num; #ifdef XFT col.color.alpha = 0xffff; col.color.red = cols[5].red; col.color.green = cols[5].green; col.color.blue = cols[5].blue; XftDrawString8 (xftdraw, &col, xfs, x + ((PAGER_BUTTON_WIDTH - PAGER_DIGIT_WIDTH) / 2), text_y, &label, 1); #else if (num == tb.my_desktop) { set_foreground (6); } else { set_foreground (4); } XDrawString (dd, tb.win, fore_gc, x + ((PAGER_BUTTON_WIDTH - PAGER_DIGIT_WIDTH) / 2) - 1, text_y, &label, 1); #endif }
static void draw_string(struct test_display *t, Drawable d, uint8_t alu, int x, int y, uint32_t fg, uint32_t bg, int s, int fill) { const char *strings[] = { "Hello", "World", "Cairo's twin is Giza", }; XGCValues val; GC gc; val.function = alu; val.foreground = fg; val.background = bg; gc = XCreateGC(t->dpy, d, GCForeground | GCBackground | GCFunction, &val); if (fill) XDrawImageString(t->dpy, d, gc, x, y, strings[s%3], strlen(strings[s%3])); else XDrawString(t->dpy, d, gc, x, y, strings[s%3], strlen(strings[s%3])); XFreeGC(t->dpy, gc); }
void NSSelector::addItem(const char* str) { char* newStr = new char[strlen(str) + 1]; strcpy(newStr, str); items.push_back(newStr); if (_last - _first + 1 <= _displayableNum) { _last = items.size(); XDrawString(NSdpy, window(), _gc, _hGap, (_vGap + _font.height()) * (_last - _first), items[_last - 1], strlen(items[_last - 1])); } else { _vscroll.barPercent(_displayableNum * 100 / items.size()); _vscroll.movement(_vscroll.height() / items.size()); } unsigned int strWidth = _font.textWidth(str); unsigned int width = NSWindow::width(); if (strWidth > width) _hscroll.barPercent(width * 100 / strWidth); }
void DoWrite(unsigned char *s) { int x,y; unsigned char *p; int newline=0; x=(crtX-1)*8; y=(crtY-1)*14; if (memcmp(s,"\x03\x08 \x08",4)==0) { XFillRectangle(dpy, pm, gcclear, x-8,y,8,14); crtX--; return; } XFillRectangle(dpy, pm, gcclear, x,y,8*s[0],14); p=s+1; while (p<=s+s[0]) { switch (*p) { case 10: newline=1; if (p!=s+s[0]) fprintf(stderr,"NOT IMPLEMENTED: newline in middle of string"); s[0]--; break; case 248: *p=176; break; /* degree */ case 230: *p=181; break; /* mu */ default: if (*p<32 || *p>127) { write_other(x+8*(p-s-1), y, *p); *p=' '; } } p++; } XDrawString(dpy,pm,gctext,x,y+fontyoffs,s+1,s[0]); crtX+=s[0]; if (newline) { crtX=crtXmin; crtY++; } drawcounter++; }
struct wm_window* create_parent_window(struct wm_window *child) { GC gc; XGCValues values; struct wm_window *parent_win = (struct wm_window *)malloc(sizeof(struct wm_window)); XColor bg_color; bg_color.red = 0 * 256; bg_color.green = 100 * 256; bg_color.blue = 150 * 256; XAllocColor(wm.display, DefaultColormap(wm.display, wm.screen), &bg_color); parent_win->win = XCreateSimpleWindow(wm.display, DefaultRootWindow(wm.display), 0, 0, 600, 600, 0, bg_color.pixel, bg_color.pixel); wm_window_resize(&wm, child, 590, 570); int w, h; w = 100 + rand()%screen_width - (child->width + 20); h = 100 + rand()%screen_height - (child->height + 20); w = w >= 0 ? w : 0; h = h >= 0 ? h : 0; printf("::: %d %d\n", w, h); wm_window_move(&wm, parent_win, w, h); wm_window_show(&wm, parent_win); gc = XCreateGC(wm.display, parent_win->win, None, &values); XSetLineAttributes(wm.display, gc, 2, LineSolid, CapButt, JoinRound); XDrawString(wm.display, parent_win->win, gc, 20, 20, child->title, strlen(child->title)); Pixmap exit_icon, mask; XpmAttributes xpm_attr; XpmCreatePixmapFromData(wm.display, parent_win->win, exit_icon_xpm, &exit_icon, &mask, &xpm_attr); GC gc2; XGCValues values2; gc2 = XCreateGC(wm.display, parent_win->win, None, &values2); XSetClipMask(wm.display, gc2, mask); // XcopyArea() server-side should be faster than XPutImage() client-side XSetClipOrigin(wm.display, gc2, 600-xpm_attr.width, 0); XCopyArea(wm.display, exit_icon, parent_win->win, gc2, 0, 0, xpm_attr.width, xpm_attr.height, 600-xpm_attr.width, 0); return parent_win; }
void stk_progress_bar_expose(stk_widget *pb) { int width, wcenter, hcenter, len; stk_progress_bar *spb = (stk_progress_bar*)pb->ext_struct; XClearWindow(pb->dsp, pb->win); XFillRectangle(pb->dsp, pb->win, pb->gc, 0, 0, (pb->w * spb->pct)/100, pb->h); len = strlen(spb->label); if(len > 0) { width = XTextWidth(pb->font_info, spb->label, strlen(spb->label)); wcenter = (pb->w - width) / 2; hcenter = ((pb->font_info->descent + pb->font_info->ascent)/2) + (pb->h / 2); XDrawString(pb->dsp, pb->win, pb->gc2, wcenter, hcenter, spb->label, strlen(spb->label)); } XFlush(pb->dsp); }
void polytext8_test(void) { int num_strings = 200; int i; long totaltime; char buf[80]; num_strings *= X.percent; XSync(X.dpy,0); start_timer(); for (i=0;i<num_strings;++i) { XDrawString(X.dpy,X.win,X.gc,(i%2 ? i : num_strings - i),i, string8,sizeof(string8)-1); } XSync(X.dpy,0); totaltime = end_timer(); snprintf(buf,sizeof buf,"%d strings in %.2f seconds.",num_strings, (double) totaltime/1000000.); show_result(buf); }
void HandleModeButtons(XEvent* event, int mode) { int width, center; switch(event->type) { case Expose: case LeaveNotify: XClearWindow(dis, button_modes[mode]); width = XTextWidth(font_info, "Mode", strlen("Mode")); center = (BUTTON_WIDTH - width) / 2; XDrawString(dis, button_modes[mode], gc, center, font_info->ascent, "Mode", strlen("Mode")); XFlush(dis); break; case EnterNotify: case ButtonPress: XDrawRectangle(dis, button_modes[mode], gc, 1, 1, BUTTON_WIDTH - 3, BUTTON_HEIGHT - 3); break; case ButtonRelease: capture_mode = mode; break; default: break; } }
static PyObject * PaxGC_DrawString(PaxGCObject * self, PyObject *args) { int arg1; int arg2; PyObject *arg3; int nchars; if (!PyArg_ParseTuple(args, "iiS", &arg1, &arg2, &arg3)) return NULL; if (!(nchars = PyString_Size(arg3), 1)) { if (!PyErr_Occurred()) PyErr_SetString(PyExc_TypeError, "arg3 should be char[]"); return NULL; } XDrawString(self->display, self->drawable, self->gc, arg1, arg2, PyString_AsString(arg3), nchars); Py_INCREF(Py_None); return Py_None; }
int WinPrintf(int iWin, int x, int y, char *fmt, ...) { va_list args ; char str[MAX_STRING] ; int len ; DIAG_WINDOW *pwin ; va_start(args, fmt) ; pwin = HandleToPtr(iWin) ; /* AHH! what coordinate system to use? */ /* y = pwin->xwin->ysize - y ;*/ fmt = va_arg(args, char *) ; vsprintf(str, fmt, args) ; len = strlen(str) ; XDrawString(pwin->xvf->display, pwin->xwin->window, pwin->xwin->black, x, y, str, len); /* XFlush(pwin->xvf->display) ;*/ va_end(args) ; return(len) ; }
void HandleRegButton(XEvent * event, int id, struct fp_img_dev *dev) { int width, center; switch(event->type) { case Expose: case LeaveNotify: XClearWindow(dis, MenuButton[id].window); width = XTextWidth(font_info, MenuButton[id].label, strlen(MenuButton[id].label)); center = (SB_WIDTH - width) / 2; XDrawString(dis, MenuButton[id].window, gc, center, font_info->ascent, MenuButton[id].label, strlen(MenuButton[id].label)); XFlush(dis); break; case EnterNotify: case ButtonPress: XDrawRectangle(dis, MenuButton[id].window, gc, 1, 1, SB_WIDTH - 3, SB_HEIGHT - 3); break; case ButtonRelease: MenuButton[id].func(dev); break; default: break; } }
//--------------------------------------------------------------------------- void hxc_popup::draw(int i) { int y=border,bh=h-border*2; int first=0,last=menu.NumStrings-1; if (i>=0){ y+=itemheight*i; bh=itemheight; first=i; last=i; } XSetForeground(XD,hxc::gc,hxc::col_bk); XFillRectangle(XD,handle,hxc::gc,border,y,w-border*2,bh); XSetForeground(XD,hxc::gc,hxc::col_black); int text_off=(itemheight - hxc::font->descent + hxc::font->ascent)/2; for (int n=first;n<=last;n++){ bool line=IsSameStr(menu[n].String,"-"); if (sel==n && line==0){ XSetForeground(XD,hxc::gc,hxc::col_sel_back); XFillRectangle(XD,handle,hxc::gc,border,y,w-border*2,itemheight); XSetForeground(XD,hxc::gc,hxc::col_sel_fore); } if (line){ XDrawLine(XD,handle,hxc::gc,border+2,y+border+itemheight/2,w-1-2-border,y+border+itemheight/2); }else{ int x=border+4; if (lpig){ lpig->DrawIcon(menu[n].Data[0],handle,hxc::gc,x,y+(itemheight-lpig->IconHeight)/2); x+=lpig->IconWidth + 5; } XDrawString(XD,handle,hxc::gc,x,y+text_off,menu[n].String,strlen(menu[n].String)); } y+=itemheight; XSetForeground(XD,hxc::gc,hxc::col_black); } if (i==-1) hxc::draw_border(XD,handle,hxc::gc,0,0,w,h,border,hxc::col_black,hxc::col_black); }
void draw_inputsymbol(InputItem *sym) { int y_spot = start_y; LineStruct *cline; XCharStruct extents; int dir, asc, des; #if 0 int cursor_y; cursor_y = (sym->curr_line->line_number - 1) * line_height; #endif XClearWindow(gXDisplay, sym->win); XTextExtents(gInputFont, sym->curr_line->buffer, sym->curr_line->buff_pntr, &dir, &asc, &des, &extents); sym->cursor_x = start_x + extents.width; /* * While the list of input strings is not NULL, I should just keep * drawing them */ for (cline = sym->lines; cline != NULL; cline = cline->next, y_spot += line_height) { /* Now I should draw the initial string ** */ cline->changed = 0; XDrawString(gXDisplay, sym->win, gWindow->fInputGC, start_x, y_spot, cline->buffer, cline->len); } if (gWindow->page->current_item == sym) draw_cursor(sym); }
/* * UpdateLabTrack updates the label of a specific Track window. */ void UpdateLabTrack(Trace *trc, Track *trk) { char sncl[20]; char buf[100]; XClearWindow(theDisp, trk->txtwin); if (trc && trc->wave) { if(Mode_labDetails) { if(trc->wave) { sprintf(buf, "%d\n", trc->wave->info.n_values); XDrawString(theDisp, trk->txtwin, trk->txtgc, 10, (trk->height-10)/2, buf, strlen(buf)); sprintf(buf, "%g\n", trc->wave->info.sample_rate); XDrawString(theDisp, trk->txtwin, trk->txtgc, 10, (trk->height-10)/2+15, buf, strlen(buf)); sprintf(buf,"[%d]",trc->itrc); XDrawString(theDisp, trk->txtwin, trk->txtgc, 70, (trk->height-10)/2+15, buf, strlen(buf)); } return; } sprintf(sncl, "%s %s %s %s", trc->wave->info.station, trc->wave->info.network, trc->wave->info.channel, strlen(trc->wave->info.location) > 0 ? trc->wave->info.location : "--"); if(trk->height<30) { XDrawString(theDisp, trk->txtwin, trk->txtgc, 10, trk->height-2, sncl, strlen(sncl)); }else { XDrawString(theDisp, trk->txtwin, trk->txtgc, 10, (trk->height-10)/2, sncl, strlen(sncl)); /* sprintf(buf,"%3.5f\n",trc->axis.vs); * XDrawString(theDisp, trk->txtwin, trk->txtgc, 10, * (trk->height-10)/2+15, buf, strlen(buf)); */ } if (trc->selected) { sprintf(buf,"%d",trc->itrc); XDrawString(theDisp, trk->txtwin, trk->txtgc, 80, (trk->height-10)/2+15, buf, strlen(buf)); XFillRectangle(theDisp, trk->txtwin, trk->ovrGC, 0, 0, TXTCANV_WIDTH, trk->height); } } }
static void do_label(t_x11 *x11,t_manager *man,int x,int y,bool bSet) { atom_id ai; unsigned long col; if ((ai=which_atom(man,x,y)) != NO_ATID) { x=man->ix[ai][XX]; y=man->ix[ai][YY]; if (bSet && !man->bLabel[ai]) { col=WHITE; man->bLabel[ai]=TRUE; } else if (!bSet && man->bLabel[ai]) { col=BLUE; man->bLabel[ai]=FALSE; } else return; XSetForeground(x11->disp,x11->gc,col); XDrawString(x11->disp,man->molw->wd.self,x11->gc,x+2,y-2,man->szLab[ai], strlen(man->szLab[ai])); XSetForeground(x11->disp,x11->gc,x11->fg); } }
void subshow(DSPOBJ *dspobj) { PULLDOWN *pulldown = dspobj->extend; int y; XClearWindow(dsp, dspobj->win); for (y = 0; y != pulldown->nitems; y++) { XDrawString(dsp, dspobj->win, dspobj->gc, pulldown->x, y * pulldown->h + pulldown->y, pulldown->items[y], strlen(pulldown->items[y])); if (y == pulldown->which) { XDrawLine(dsp, dspobj->win, dspobj->gc, 1, y * pulldown->h, pulldown->w - 2, y * pulldown->h); XDrawLine(dsp, dspobj->win, dspobj->gc, pulldown->w - 2, y * pulldown->h, pulldown->w - 2, (y + 1) * pulldown->h); XDrawLine(dsp, dspobj->win, dspobj->gc, pulldown->w - 2, (y + 1) * pulldown->h, 1, (y + 1) * pulldown->h); XDrawLine(dsp, dspobj->win, dspobj->gc, 1, (y + 1) * pulldown->h, 1, y * pulldown->h); } } }
void drawentry(Entry *e) { int x, y, h, len; XRectangle r = { e->x, e->y, e->w, e->h }; const char *l; ulong *col; if(e->pressed) col = dc.press; else if(e->highlighted) col = dc.high; else col = dc.norm; XSetForeground(dpy, dc.gc, col[ColBG]); XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1); XSetForeground(dpy, dc.gc, dc.norm[ColFG]); r.height -= 1; r.width -= 1; XDrawRectangles(dpy, dc.drawable, dc.gc, &r, 1); XSetForeground(dpy, dc.gc, col[ColFG]); l = e->label; len = strlen(l); h = dc.font.height; y = e->y + (e->h / 2) - (h / 2) + dc.font.ascent; x = e->x + (e->w / 2) - (textnw(l, len) / 2); if(dc.font.set) { XmbDrawString(dpy, dc.drawable, dc.font.set, dc.gc, x, y, l, len); } else XDrawString(dpy, dc.drawable, dc.gc, x, y, l, len); XCopyArea(dpy, dc.drawable, win, dc.gc, e->x, e->y, e->w, e->h, e->x, e->y); }
int main(void) { Display *d; Window w; XEvent e; char *msg = "Hello, World!"; int s; d = XOpenDisplay(NULL); if (d == NULL) { fprintf(stderr, "Cannot open display\n"); exit(1); } s = DefaultScreen(d); w = XCreateSimpleWindow(d, RootWindow(d, s), 10, 10, 100, 100, 1, BlackPixel(d, s), WhitePixel(d, s)); XSelectInput(d, w, ExposureMask | KeyPressMask); Atom wmDeleteMessage = XInternAtom(d, "WM_DELETE_WINDOW", False); XSetWMProtocols(d, w, &wmDeleteMessage, 1); XMapWindow(d, w); while (1) { XNextEvent(d, &e); if (e.type == Expose) { XFillRectangle(d, w, DefaultGC(d, s), 20, 20, 10, 10); XDrawString(d, w, DefaultGC(d, s), 10, 50, msg, strlen(msg)); } if (e.type == KeyPress || e.type == ClientMessage || (e.type == DestroyNotify && e.xclient.data.l[0] == wmDeleteMessage)) break; } XCloseDisplay(d); return 0; }
void nsPluginInstance::draw() { unsigned int h = mHeight/2; unsigned int w = 3 * mWidth/4; int x = (mWidth - w)/2; // center int y = h/2; XClearArea(mDisplay, mWindow, 0, 0, 0, 0, False); if (x >= 0 && y >= 0) { GC gc = XCreateGC(mDisplay, mWindow, 0, NULL); if (!gc) return; XDrawRectangle(mDisplay, mWindow, gc, x, y, w, h); if (mString[0]) { int l = strlen(mString); int fmba = mFontInfo->max_bounds.ascent; int fmbd = mFontInfo->max_bounds.descent; int fh = fmba + fmbd; y += fh; x += 32; XDrawString(mDisplay, mWindow, gc, x, y, mString, l); } XFreeGC(mDisplay, gc); } }
void redraw_frame(client_t *c) { int x, y; if (c && c->decor) { XClearWindow(dpy, c->frame); if (!c->shaded) XDrawLine(dpy, c->frame, border_gc, 0, frame_height(c) - BW(c) + BW(c)/2, c->geom.w, frame_height(c) - BW(c) + BW(c)/2); XDrawLine(dpy, c->frame, border_gc, c->geom.w - frame_height(c) + BW(c)/2, 0, c->geom.w - frame_height(c) + BW(c)/2, frame_height(c)); if (!c->trans && c->name) { x = opt_pad + DESCENT/2; y = opt_pad + ASCENT; #ifdef XFT #ifdef X_HAVE_UTF8_STRING XftDrawStringUtf8(c->xftdraw, &xft_fg, xftfont, x, y, (unsigned char *)c->name, strlen(c->name)); #else XftDrawString8(c->xftdraw, &xft_fg, xftfont, x, y, (unsigned char *)c->name, strlen(c->name)); #endif #else #ifdef X_HAVE_UTF8_STRING Xutf8DrawString(dpy, c->frame, font_set, string_gc, x, y, c->name, strlen(c->name)); #else XDrawString(dpy, c->frame, string_gc, x, y, c->name, strlen(c->name)); #endif #endif } } }
int main(void) { Display *d; Window w; char *msg = "Hello, World! AlanTom"; int s; // open connection with the X server d = XOpenDisplay(NULL); //get screen_number s = DefaultScreen(d); // create a window w = XCreateSimpleWindow(d, RootWindow(d, s), 10, 10, 640, 480, 0, BlackPixel(d, s), WhitePixel(d, s)); // set title words XStoreName(d, w, "MY WINDOW!!"); // show the window XMapWindow(d, w); while (1) { // show string XDrawString(d, w, DefaultGC(d, s), 120, 50, msg, strlen(msg)); } // close connection to X server XCloseDisplay(d); return 0; }
void drawText() { XDrawString( myDisplay, myWindow, myGC, 2+1, 15+1, "abc", strlen("abc")); XDrawString( myDisplay, myWindow, myGC, window_width/2 - 13 + 1, 15 + 1, "ABC", strlen("ABC")); XDrawString( myDisplay, myWindow, myGC, window_width - 3*9 - 2 + 1, 15 + 1, "123", strlen("123")); XSetForeground (myDisplay, myGC, getColor( myDisplay, 60, 120, 200 ) ); XDrawString( myDisplay, myWindow, myGC, 2, 15, "abc", strlen("abc")); XDrawString( myDisplay, myWindow, myGC, window_width/2 - 13, 15, "ABC", strlen("ABC")); XDrawString( myDisplay, myWindow, myGC, window_width - 3*9 - 2, 15, "123", strlen("123")); XSetForeground (myDisplay, myGC, BlackPixel( myDisplay, myScreen ) ); }
/**************************************** draw_widget_text ***************************************** Purpose: To draw the text lines in a detail view widget. The first parameter specfies the index of the account in accts, and the second specifies whether or not to draw in reverse colors for selected accounts. ****************************************/ void draw_widget_text (int ndx, int reverse) { int length; /* string length */ int x; /* x coordinate */ int y; /* y coordinate */ char locbuf[20]; /* buffer for building strings */ #ifdef FT char acc_plus[69]; /* account and compt attente */ #endif /* initialize coordinates */ x = 10; y = 20; /* draw text for non-selected account */ if (!reverse) /* normal text */ { /* first line is account id */ #ifdef FT memset(acc_plus,'\0',sizeof(acc_plus)); sprintf(acc_plus,"%s - Compte Attente: %s", accts[ndx].external_id, accts[ndx].compte_attente); length = strlen (acc_plus); XDrawString (display, XtWindow (accts[ndx].bb), gc, x, y, acc_plus, length); #else length = strlen (accts[ndx].external_id); XDrawString (display, XtWindow (accts[ndx].bb), gc, x, y, accts[ndx].external_id, length); #endif /* second line is company or individual name */ y += font_height + TEXT_SEPARATION / 2; /* length = strlen (accts[ndx].text2); XDrawString (display, XtWindow (accts[ndx].bb), gc, x, y, accts[ndx].text2, length); y += font_height + TEXT_SEPARATION / 2; */ /* third line is status infomation */ strcpy (locbuf, get_status_abbrev(accts[ndx].net_status)); length = strlen (locbuf); XDrawString (display, XtWindow (accts[ndx].bb), gc, STAT_X, y, locbuf, length); if (accts[ndx].type) strcpy (locbuf, "B"); else strcpy (locbuf, "U"); length = strlen (locbuf); XDrawString (display, XtWindow (accts[ndx].bb), gc, TYPE_X, y, locbuf, length); sprintf (locbuf, "%d", accts[ndx].vip); length = strlen (locbuf); XDrawString (display, XtWindow (accts[ndx].bb), gc, VIP_X, y, locbuf, length); sprintf (locbuf, "%d", accts[ndx].cltn_status); length = strlen (locbuf); XDrawString (display, XtWindow (accts[ndx].bb), gc, COL_X, y, locbuf, length); /* DCP 140498 CAMqa15928 */ /* Num orders has no relevance in this interface any more */ /*if (accts[ndx].num_orders < 100) sprintf (locbuf, "%3d", accts[ndx].num_orders); else strcpy (locbuf, "99+"); length = strlen (locbuf); XDrawString (display, XtWindow (accts[ndx].bb), gc, PO_X, y, locbuf, length);*/ if (accts[ndx].num_equip < 1000) sprintf (locbuf, "%4d", accts[ndx].num_equip); else strcpy (locbuf, "999+"); length = strlen (locbuf); XDrawString (display, XtWindow (accts[ndx].bb), gc, SERV_X, y, locbuf, length); } else /* selected item */ { /* use highlight color */ XSetBackground (display, gc, highlight); /* first line is account id */ #ifdef FT memset(acc_plus,'\0',sizeof(acc_plus)); sprintf(acc_plus,"%s - Compte Attente: %s", accts[ndx].external_id, accts[ndx].compte_attente); length = strlen (acc_plus); XDrawImageString (display, XtWindow (accts[ndx].bb), gc, x, y, acc_plus, length); #else length = strlen (accts[ndx].external_id); XDrawImageString (display, XtWindow (accts[ndx].bb), gc, x, y, accts[ndx].external_id, length); #endif y += font_height + TEXT_SEPARATION / 2; /* second line is company or individual name */ /* length = strlen (accts[ndx].text2); XDrawImageString (display, XtWindow (accts[ndx].bb), gc, x, y, accts[ndx].text2, length); y += font_height + TEXT_SEPARATION / 2; */ /* third line is status infomation */ strcpy (locbuf, get_status_abbrev(accts[ndx].net_status)); length = strlen (locbuf); XDrawImageString (display, XtWindow (accts[ndx].bb), gc, STAT_X, y, locbuf, length); if (accts[ndx].type) strcpy (locbuf, "B"); else strcpy (locbuf, "U"); length = strlen (locbuf); XDrawImageString (display, XtWindow (accts[ndx].bb), gc, TYPE_X, y, locbuf, length); sprintf (locbuf, "%d", accts[ndx].vip); length = strlen (locbuf); XDrawImageString (display, XtWindow (accts[ndx].bb), gc, VIP_X, y, locbuf, length); sprintf (locbuf, "%d", accts[ndx].cltn_status); length = strlen (locbuf); XDrawImageString (display, XtWindow (accts[ndx].bb), gc, COL_X, y, locbuf, length); /* DCP 140498 CAMqa15928 */ /* Num orders has no relevance in this interface any more */ /*if (accts[ndx].num_orders < 100) sprintf (locbuf, "%3d", accts[ndx].num_orders); else strcpy (locbuf, "99+"); length = strlen (locbuf); XDrawImageString (display, XtWindow (accts[ndx].bb), gc, PO_X, y, locbuf, length);*/ if (accts[ndx].num_equip < 100) sprintf (locbuf, "%4d", accts[ndx].num_equip); else strcpy (locbuf, "999+"); length = strlen (locbuf); XDrawImageString (display, XtWindow (accts[ndx].bb), gc, SERV_X, y, locbuf, length); /* reset GC */ XSetBackground (display, gc, background); } }
static Bool xlib_cursor_load( Handle self, Handle icon) { XImage *im; Pixmap p1 = None, p2 = None; Bool free_pixmap = true; GC gc; XGCValues gcv; char c; int id, w = guts.cursor_width, h = guts.cursor_height; id = get_cursor( self, &p1, &p2, nil, nil); if ( id < crDefault || id > crUser) return false; if ( id == crUser) { if ( !p1 || !p2) { warn( "User pointer inconsistency"); return false; } free_pixmap = false; } else { XFontStruct *fs; XCharStruct *cs; int idx = cursor_map[id]; if ( !load_pointer_font()) return false; fs = guts.pointer_font; if ( !fs-> per_char) cs = &fs-> min_bounds; else if ( idx < fs-> min_char_or_byte2 || idx > fs-> max_char_or_byte2) { int default_char = fs-> default_char; if ( default_char < fs-> min_char_or_byte2 || default_char > fs-> max_char_or_byte2) default_char = fs-> min_char_or_byte2; cs = fs-> per_char + default_char - fs-> min_char_or_byte2; } else cs = fs-> per_char + idx - fs-> min_char_or_byte2; p1 = XCreatePixmap( DISP, guts. root, w, h, 1); p2 = XCreatePixmap( DISP, guts. root, w, h, 1); gcv. background = 1; gcv. foreground = 0; gcv. font = guts.pointer_font-> fid; gc = XCreateGC( DISP, p1, GCBackground | GCForeground | GCFont, &gcv); XFillRectangle( DISP, p1, gc, 0, 0, w, h); gcv. background = 0; gcv. foreground = 1; XChangeGC( DISP, gc, GCBackground | GCForeground, &gcv); XFillRectangle( DISP, p2, gc, 0, 0, w, h); XDrawString( DISP, p1, gc, -cs-> lbearing, cs-> ascent, (c = (char)(idx+1), &c), 1); gcv. background = 1; gcv. foreground = 0; XChangeGC( DISP, gc, GCBackground | GCForeground, &gcv); XDrawString( DISP, p2, gc, -cs-> lbearing, cs-> ascent, (c = (char)(idx+1), &c), 1); XDrawString( DISP, p1, gc, -cs-> lbearing, cs-> ascent, (c = (char)idx, &c), 1); XFreeGC( DISP, gc); } CIcon(icon)-> create_empty( icon, w, h, imBW); im = XGetImage( DISP, p1, 0, 0, w, h, 1, XYPixmap); prima_copy_xybitmap( PIcon(icon)-> data, (Byte*)im-> data, PIcon(icon)-> w, PIcon(icon)-> h, PIcon(icon)-> lineSize, im-> bytes_per_line); XDestroyImage( im); im = XGetImage( DISP, p2, 0, 0, w, h, 1, XYPixmap); prima_copy_xybitmap( PIcon(icon)-> mask, (Byte*)im-> data, PIcon(icon)-> w, PIcon(icon)-> h, PIcon(icon)-> maskLine, im-> bytes_per_line); if ( id == crUser) { int i; Byte * mask = PIcon(icon)-> mask; for ( i = 0; i < PIcon(icon)-> maskSize; i++) mask[i] = ~mask[i]; } XDestroyImage( im); if ( free_pixmap) { XFreePixmap( DISP, p1); XFreePixmap( DISP, p2); } return true; }
static void NewLevel(struct state *st, int xlim, int ylim) { char buf[32]; int width, i, sumlive = 0; int liv[kNumCities]; int freecity = 0; if (st->level == 0) { st->level++; goto END_LEVEL; } /* check for a free city */ if (st->score >= st->nextBonus) { st->numBonus++; st->nextBonus += kFirstBonus * st->numBonus; freecity = 1; } for (i=0;i<kNumCities;i++) { if (st->bround) st->city[i].alive = st->blive[i]; liv[i] = st->city[i].alive; sumlive += liv[i]; if (!st->bround) st->city[i].alive = 0; } /* print out screen */ XFillRectangle(st->dpy, st->window, st->erase_gc, 0, 0, xlim, ylim); if (st->bround) sprintf(buf, "Bonus Round Over"); else { if (sumlive || freecity) sprintf(buf, "Level %d Cleared", st->level); else sprintf(buf, "GAME OVER"); } if (st->level > 0) { width = XTextWidth(st->font, buf, strlen(buf)); XDrawString(st->dpy, st->window, st->level_gc, xlim / 2 - width / 2, ylim / 2 - font_height(st->font) / 2, buf, strlen(buf)); XSync(st->dpy, False); usleep(1000000); } if (!st->bround) { if (sumlive || freecity) { int sumwidth; /* draw live cities */ XFillRectangle(st->dpy, st->window, st->erase_gc, 0, ylim - 100, xlim, 100); sprintf(buf, "X %ld", st->level * 100L); /* how much they get */ sumwidth = XTextWidth(st->font, buf, strlen(buf)); /* add width of city */ sumwidth += 60; /* add spacer */ sumwidth += 40; DrawCity(st, xlim / 2 - sumwidth / 2 + 30, ylim * 0.70, st->city[0].color); XDrawString(st->dpy, st->window, st->level_gc, xlim / 2 - sumwidth / 2 + 40 + 60, ylim * 0.7, buf, strlen(buf)); for (i=0;i<kNumCities;i++) { if (liv[i]) { st->city[i].alive = 1; AddScore(st, xlim, ylim, 100 * st->level); DrawCities(st, xlim, ylim); XSync(st->dpy, False); usleep(kCityPause); } } } else { /* we're dead */ usleep(3000000); /* start new */ st->gamez++; Improve(st); for (i=0;i<kNumCities;i++) st->city[i].alive = 1; st->level = 0; st->loop = 1; st->score = 0; st->nextBonus = kFirstBonus; st->numBonus = 0; DrawCities(st, xlim, ylim); } } /* do free city part */ if (freecity && sumlive < 5) { int ncnt = random() % (5 - sumlive) + 1; for (i=0;i<kNumCities;i++) if (!st->city[i].alive) if (!--ncnt) st->city[i].alive = 1; strcpy(buf, "Bonus City"); width = XTextWidth(st->font, buf, strlen(buf)); XDrawString(st->dpy, st->window, st->level_gc, xlim / 2 - width / 2, ylim / 4, buf, strlen(buf)); DrawCities(st, xlim, ylim); XSync(st->dpy, False); usleep(1000000); } XFillRectangle(st->dpy, st->window, st->erase_gc, 0, 0, xlim, ylim - 100); if (!st->bround) st->level++; if (st->level == 1) { st->nextBonus = kFirstBonus; } if (st->level > 3 && (st->level % 5 == 1)) { if (st->bround) { st->bround = 0; DrawCities(st, xlim, ylim); } else { /* bonus round */ st->bround = 1; st->levMissiles = 20 + st->level * 10; st->levFreq = 10; for (i=0;i<kNumCities;i++) st->blive[i] = st->city[i].alive; sprintf(buf, "Bonus Round"); width = XTextWidth(st->font, buf, strlen(buf)); XDrawString(st->dpy, st->window, st->level_gc, xlim / 2 - width / 2, ylim / 2 - font_height(st->font) / 2, buf, strlen(buf)); XSync(st->dpy, False); usleep(1000000); XFillRectangle(st->dpy, st->window, st->erase_gc, 0, 0, xlim, ylim - 100); } } END_LEVEL: ; if (!st->bround) { st->levMissiles = 5 + st->level * 3; if (st->level > 5) st->levMissiles += st->level * 5; /* levMissiles = 2; */ st->levFreq = 120 - st->level * 5; if (st->levFreq < 30) st->levFreq = 30; } /* ready to fire */ st->lastLaser = 0; }
static Bool NumberScreen(ModeInfo * mi) { Display *display = MI_DISPLAY(mi); Window window = MI_WINDOW(mi); puzzlestruct *pp = &puzzles[MI_SCREEN(mi)]; if (mode_font == None) mode_font = getFont(display); if (!pp->done) { XGCValues gcv; pp->done = 1; gcv.font = mode_font->fid; gcv.graphics_exposures = False; gcv.foreground = MI_WHITE_PIXEL(mi); gcv.background = MI_BLACK_PIXEL(mi); if ((pp->gc = XCreateGC(display, window, GCForeground | GCBackground | GCGraphicsExposures | GCFont, &gcv)) == None) { free_puzzle(display, pp); return False; } pp->ascent = mode_font->ascent; pp->fontHeight = font_height(mode_font); pp->fontWidth = font_width(mode_font, '5'); } XSetForeground(display, pp->gc, MI_WHITE_PIXEL(mi)); { XPoint pos, letter; int count = 1, digitOffset = 1, temp, letterOffset; int i, j, mult = pp->count.x * pp->count.y; char buf[16]; letter.x = pp->boxsize.x / 2 - 3; letter.y = pp->boxsize.y / 2 + pp->ascent / 2 - 1; letterOffset = pp->fontWidth / 2; pos.y = 0; for (j = 0; j < pp->count.y; j++) { pos.x = 0; for (i = 0; i < pp->count.x; i++) { if (count < mult) { if (pp->boxsize.x > 2 * pp->fontWidth && pp->boxsize.y > pp->fontHeight) { (void) sprintf(buf, "%d", count); (void) XDrawString(display, window, pp->gc, pos.x + letter.x - letterOffset * digitOffset + pp->randompos.x, pos.y + letter.y + pp->randompos.y, buf, digitOffset); } XDrawRectangle(display, window, pp->gc, pos.x + 1 + pp->randompos.x, pos.y + 1 + pp->randompos.y, pp->boxsize.x - 3, pp->boxsize.y - 3); count++; digitOffset = 0; temp = count; while (temp >= 1) { temp /= 10; digitOffset++; } } pos.x += pp->boxsize.x; } pos.y += pp->boxsize.y; } } return True; }
int main(int argc, char* argv[]) { struct timeval begin, now; long counter; printf("\n -- EYEBOT Viewer -- \n\n"); // Allocate buffers img_buffer = malloc(SIZE * CHANNELS); read_buffer = malloc(SIZE + PADDING); scaled_up_img = malloc(UP_S * CHANNELS); scaled_up_img_dbl = malloc(UP_S * CHANNELS); unsigned char b[4096]; display = XOpenDisplay(NULL); visual = DefaultVisual(display, 0); window = XCreateSimpleWindow(display, RootWindow(display, 0), 0, 0, 320, 300, 1, 0, 0); XMapWindow(display, window); XFlush(display); if(visual->class!=TrueColor) { fprintf(stderr, "Cannot handle non true color visual ...\n"); exit(1); } //XMapWindow(display, window); //XFlush(display); image = NULL; struct addrinfo hints, *res; int socket_fd = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP); if(socket_fd == -1) { printf("Could not make a socket\n"); return 1; } memset(&hints, 0, sizeof hints); hints.ai_family = AF_INET; hints.ai_socktype = SOCK_STREAM; getaddrinfo(SERVER_HOSTNAME, SERVER_PORT, &hints, &res); sleep(1); memset(b, 0, sizeof(b)); sprintf(b, "Eyebot Line Follower - LiveEye"); XSetForeground(display, DefaultGC(display, 0), 0x00ff0000); // red XDrawString(display, window, DefaultGC(display, 0), 10, 20, b, strlen(b)); memset(b, 0, sizeof(b)); sprintf(b, "Copyright (C) 2013 Andre Christensen and Jacob Pedersen"); XSetForeground(display, DefaultGC(display, 0), 0x000000EF); // red XDrawString(display, window, DefaultGC(display, 0), 10, 35, b, strlen(b)); XFlush(display); while (1) { printf("Connecting to EYEBOT! (%s:%s)\n", SERVER_HOSTNAME, SERVER_PORT); // Connect loop while (1) { if (connect(socket_fd, res->ai_addr, res->ai_addrlen) == -1) { sleep(1); } else { printf("Connected!\n"); break; } } // Two seconds of timeout. Useful so that recv doesn't wait // forever to receive all its bytes. struct timeval tv; tv.tv_sec = 2; tv.tv_usec = 0; setsockopt(socket_fd, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(struct timeval)); // Measure time at beginning counter = 0; gettimeofday(&begin, NULL); // Frame update loop while (1) { int bytes_read; int total = 0; unsigned int x = 0, y = 0, error, error_upper, mass; int l_x, l_y, u_x, u_y; fd_set fds; FD_ZERO(&fds); FD_SET(socket_fd, &fds); struct timeval timeout; timeout.tv_sec = 6 * 60; timeout.tv_usec = 0; if (select(sizeof(fds) * 8, &fds, NULL, NULL, &timeout) < 0) { exitp("select()"); } if (read(socket_fd, &l_x, sizeof(l_x)) < 0) { exitp("read() (error x)"); } if (read(socket_fd, &l_y, sizeof(l_y)) < 0) { exitp("read() (error y)"); } if (read(socket_fd, &u_x, sizeof(u_x)) < 0) { exitp("read() (error x)"); } if (read(socket_fd, &u_y, sizeof(u_y)) < 0) { exitp("read() (error y)"); } if (read(socket_fd, &error, sizeof(error)) < 0) { exitp("read() (error)"); } if (read(socket_fd, &error_upper, sizeof(error_upper)) < 0) { exitp("read() (error)"); } if (read(socket_fd, &mass, sizeof(mass)) < 0) { exitp("read() (error mass)"); } // Clear the read buffer memset(read_buffer, 0, SIZE); // // Read the 76800 bytes a frame consist of // bytes_read = recv(socket_fd, read_buffer, SIZE, MSG_WAITALL); if (bytes_read < 0) { perror("recv"); break; } else if (bytes_read == SIZE) { copy_to_x_buffer(read_buffer, bytes_read); draw_center_point(l_x, l_y, 0, 0, 255); draw_center_point(u_x, u_y, 0, 255, 0); draw_center_lines(); //upscale_image(); if (image != NULL) { XDestroyImage(image); } //upscale_image(); //draw_center_point2(l_x, l_y, 0, 0, 255); //draw_center_point2(u_x, u_y, 0, 255, 0); //draw_center_lines2(); //scaled_up_img_dbl = malloc(UP_S * CHANNELS); //memcpy(scaled_up_img_dbl, scaled_up_img, UP_S * CHANNELS); // Allocate a new buffer for next frame. // The old one is freed by XDestroyImage img_disp_buffer = (unsigned char *) malloc(SIZE * CHANNELS); memcpy(img_disp_buffer, img_buffer, SIZE * CHANNELS); image = XCreateImage(display, visual, 24, ZPixmap, 0, img_disp_buffer, 320, 240, 32, 0); XPutImage(display, window, DefaultGC(display, 0), image, 0, 0, 0, 0, 320, 240); //image = XCreateImage(display, visual, 24, ZPixmap, 0, scaled_up_img_dbl, 640, 480, 32, 0); //XPutImage(display, window, DefaultGC(display, 0), image, 0, 0, 0, 0, 640, 480); // Clear text area XSetForeground(display, DefaultGC(display, 0), 0x00ffffff); XFillRectangle(display, window, DefaultGC(display, 0), 0, 240, 320, 60); // memset(b, 0, sizeof(b)); // sprintf(b, "Center: (%d, %d)", x,y); XSetForeground(display, DefaultGC(display, 0), 0x00ff0000); // red // XDrawString(display, window, DefaultGC(display, 0), 5, 260, b, strlen(b)); memset(b, 0, sizeof(b)); sprintf(b, "Error (upper): %d", error_upper); XDrawString(display, window, DefaultGC(display, 0), 5, 250, b, strlen(b)); memset(b, 0, sizeof(b)); sprintf(b, "Error (lower): %d", error); XDrawString(display, window, DefaultGC(display, 0), 5, 280, b, strlen(b)); memset(b, 0, sizeof(b)); sprintf(b, "Mass: %d", mass); XDrawString(display, window, DefaultGC(display, 0), 150, 250, b, strlen(b)); // Calculate and display fps gettimeofday(&now, NULL); double elapsed = (now.tv_sec - begin.tv_sec) * 1000.0; elapsed += (now.tv_usec - begin.tv_usec) / 1000.0; elapsed /= 1000.0; memset(b, 0, sizeof(b)); sprintf(b, "FPS: %.2f", ((counter / elapsed) * 3)); XDrawString(display, window, DefaultGC(display, 0), 150, 280, b, strlen(b)); counter++; } else { printf("Connection lost - retrying!\n"); close(socket_fd); break; } } } printf("Closing the socket\n"); if(close(socket_fd) == -1) { printf("Could not close socket\n"); return 0; } }
static void update_passwd_window (saver_info *si, const char *printed_passwd, float ratio) { passwd_dialog_data *pw = si->pw_data; XGCValues gcv; GC gc1, gc2; int x, y; pw->ratio = ratio; gcv.foreground = pw->passwd_foreground; gcv.font = pw->passwd_font->fid; gc1 = XCreateGC (si->dpy, si->passwd_dialog, GCForeground|GCFont, &gcv); gcv.foreground = pw->passwd_background; gc2 = XCreateGC (si->dpy, si->passwd_dialog, GCForeground, &gcv); if (printed_passwd) { char *s = strdup (printed_passwd); if (pw->passwd_string) free (pw->passwd_string); pw->passwd_string = s; } /* [email protected] - Added to redraw username here */ XDrawString (si->dpy, si->passwd_dialog, gc1, pw->uname_field_x, pw->uname_field_y, si->user, strlen(si->user)); if (pw->draw_password_prompt) { /* The user entry (password) field is double buffered. * This avoids flickering, particularly in synchronous mode. */ if (pw->passwd_changed_p) { pw->passwd_changed_p = False; if (pw->user_entry_pixmap) { XFreePixmap(si->dpy, pw->user_entry_pixmap); pw->user_entry_pixmap = 0; } pw->user_entry_pixmap = XCreatePixmap (si->dpy, si->passwd_dialog, pw->passwd_field_width, pw->passwd_field_height, DefaultDepthOfScreen (pw->prompt_screen->screen)); XFillRectangle (si->dpy, pw->user_entry_pixmap, gc2, 0, 0, pw->passwd_field_width, pw->passwd_field_height); XDrawString (si->dpy, pw->user_entry_pixmap, gc1, 0, pw->passwd_font->ascent, pw->passwd_string, strlen(pw->passwd_string)); /* Ensure the new pixmap gets copied to the window */ pw->i_beam = 0; } /* The I-beam */ if (pw->i_beam == 0) { /* Make the I-beam disappear */ XCopyArea(si->dpy, pw->user_entry_pixmap, si->passwd_dialog, gc2, 0, 0, pw->passwd_field_width, pw->passwd_field_height, pw->passwd_field_x, pw->passwd_field_y); } else if (pw->i_beam == 1) { x = (pw->passwd_field_x + 0 + string_width (pw->passwd_font, pw->passwd_string)); y = pw->passwd_field_y + 0; if (x > pw->passwd_field_x + pw->passwd_field_width - 1) x = pw->passwd_field_x + pw->passwd_field_width - 1; XDrawLine (si->dpy, si->passwd_dialog, gc1, x, y, x, y+pw->passwd_font->ascent + pw->passwd_font->descent-1); } pw->i_beam = (pw->i_beam + 1) % 4; } XFreeGC (si->dpy, gc1); XFreeGC (si->dpy, gc2); XSync (si->dpy, False); }
static void dialog_expose (Display *dpy, Window win) { struct XJDialog *dlg = NULL; XFindContext (dpy, win, _dlg_ctx, (XPointer*)&dlg); if (!dlg) return; const unsigned long whiteColor = WhitePixel (dpy, DefaultScreen (dpy)); const unsigned long blackColor = BlackPixel (dpy, DefaultScreen (dpy)); XSetForeground (dpy, dlg->gc, _c_gray1.pixel); XFillRectangle (dpy, win, dlg->gc, 0, 0, dlg->width, dlg->height); int i; for (i=0; i < dlg->menu_count; ++i) { int t_x = 15; int t_y = (i+1) * (_dlg_font_height + 2); if (strlen (dlg->menu_items[i].text) == 0) { t_y -= _dlg_font_ascent * .5; XSetForeground (dpy, dlg->gc, _c_gray2.pixel); XDrawLine (dpy, win, dlg->gc, 5, t_y, dlg->width - 6, t_y); continue; // separator } if (!dlg->menu_items[i].callback && !dlg->menu_items[i].submenu) { // center align headings int t_w = 0; query_font_geometry (dpy, dlg->gc, dlg->menu_items[i].text, &t_w, NULL, NULL, NULL); t_x = (dlg->width - t_w) * .5; } if (dlg->menu_hover == i && dlg->menu_items[i].sensitive && (dlg->menu_items[i].callback || dlg->menu_items[i].submenu)) { XSetForeground (dpy, dlg->gc, blackColor); XFillRectangle (dpy, win, dlg->gc, 2, t_y - _dlg_font_ascent, dlg->width - 4, _dlg_font_height); XSetForeground (dpy, dlg->gc, whiteColor); } else if (!dlg->menu_items[i].sensitive) { XSetForeground (dpy, dlg->gc, _c_gray2.pixel); } else { XSetForeground (dpy, dlg->gc, blackColor); } XDrawString (dpy, win, dlg->gc, t_x, t_y, dlg->menu_items[i].text, strlen (dlg->menu_items[i].text)); if (dlg->menu_items[i].key && strlen(dlg->menu_items[i].key) > 0) { int ks = 10; if (strlen(dlg->menu_items[i].key) > 0) { query_font_geometry(dpy, dlg->gc, dlg->menu_items[i].key, &ks, NULL, NULL, NULL); ks += 5; } XDrawString (dpy, win, dlg->gc, dlg->width - ks, t_y, dlg->menu_items[i].key, strlen (dlg->menu_items[i].key)); } if (dlg->menu_items[i].enabled) { XFillArc (dpy, win, dlg->gc, 5, t_y - _dlg_font_ascent * .5 - 3, 7, 7, 0, 360*64); } if (dlg->menu_items[i].submenu) { XPoint pts[3] = { {dlg->width - 5, t_y - _dlg_font_ascent * .5 + 1}, {-4, -4}, {0, 8}}; XFillPolygon (dpy, win, dlg->gc, pts, 3, Convex, CoordModePrevious); } } XFlush (dpy); }
int main(int argc, char **argv) { fd_set rfds; struct timeval tv; int retval; int fd; unsigned long mode; lirc_t data; lirc_t x1,y1,x2,y2; int result; char textbuffer[80]; int div=5; int dmode=0; struct stat s; char *device=LIRC_DRIVER_DEVICE; char *progname; progname="xmode2"; while(1) { int c; static struct option long_options[] = { {"help",no_argument,NULL,'h'}, {"version",no_argument,NULL,'v'}, {"device",required_argument,NULL,'d'}, {"timediv",required_argument,NULL,'t'}, {"mode",required_argument,NULL,'m'}, {0, 0, 0, 0} }; c = getopt_long(argc,argv,"hvd:t:m",long_options,NULL); if(c==-1) break; switch (c) { case 'h': printf("Usage: %s [options]\n",progname); printf("\t -h --help\t\tdisplay usage summary\n"); printf("\t -v --version\t\tdisplay version\n"); printf("\t -d --device=device\tread from given device\n"); printf("\t -t --timediv=value\tms per unit\n"); printf("\t -m --mode\t\tenable alternative display mode\n"); return(EXIT_SUCCESS); case 'v': printf("%s %s\n",progname, VERSION); return(EXIT_SUCCESS); case 'd': device=optarg; break; case 't': /* timediv */ div = strtol(optarg,NULL,10); break; case 'm': dmode=1; break; default: printf("Usage: %s [options]\n",progname); return(EXIT_FAILURE); } } if (optind < argc-1) { fprintf(stderr,"%s: too many arguments\n",progname); return(EXIT_FAILURE); } fd=open(device,O_RDONLY); if(fd==-1) { perror(progname); fprintf(stderr,"%s: error opening %s\n",progname,device); exit(EXIT_FAILURE); }; if ( (fstat(fd,&s)!=-1) && (S_ISFIFO(s.st_mode)) ) { /* can't do ioctls on a pipe */ } else if(ioctl(fd,LIRC_GET_REC_MODE,&mode)==-1 || mode!=LIRC_MODE_MODE2) { printf("This program is only intended for receivers " "supporting the pulse/space layer.\n"); printf("Note that this is no error, but this program simply " "makes no sense for your\nreceiver.\n"); close(fd); exit(EXIT_FAILURE); } initscreen(); y1=20; x1=x2=0; sprintf(textbuffer,"%d ms/unit",div); for (y2=0;y2<w1_w;y2+=10) XDrawLine(d1,w1,gc1,y2,0,y2,w1_h); XDrawString(d1,w1,gc2,w1_w-100,10,textbuffer,strlen(textbuffer)); XFlush(d1); while(1) { if (XCheckWindowEvent(d1, w1, KeyPressMask|StructureNotifyMask, &event_return1)) { switch(event_return1.type) { case KeyPress: if (event_return1.xkey.keycode==XKeysymToKeycode(d1,XStringToKeysym("q"))) { closescreen(); exit(1); } break; case ConfigureNotify: w1_w=event_return1.xconfigure.width; w1_h=event_return1.xconfigure.height; for (y2=0;y2<w1_w;y2+=10) XDrawLine(d1,w1,gc1,y2,0,y2,w1_h); XDrawString(d1,w1,gc2,w1_w-100,10,textbuffer,strlen(textbuffer)); // printf("resize \n"); break; default: ; } } /* Watch stdin (fd 0) to see when it has input. */ FD_ZERO(&rfds); FD_SET(fd, &rfds); /* Wait up to one second. */ tv.tv_sec = 1; tv.tv_usec = 0; retval = select(fd+1, &rfds, NULL, NULL, &tv); if (FD_ISSET(fd,&rfds)) { result=read(fd,&data,sizeof(data)); if (result!=0) { // printf("%.8x\t",data); x2=(data&PULSE_MASK)/(div*50); if(x2>400) { if(!dmode) { y1+=15; } else { y1++; } x1=0; } else { if (x1==0) { if(!dmode) XDrawLine(d1,w1,gc2,x1, y1+10, x1+10, y1+10); x1+=10; if(!dmode) XDrawLine(d1,w1,gc2,x1, y1+10, x1, y1); } if (x1<w1_w) { if(dmode) { if(data&PULSE_BIT) XDrawLine(d1,w1,gc2,x1,y1,x1+x2,y1); x1+=x2; } else { XDrawLine(d1,w1,gc2,x1, ((data&PULSE_BIT) ? y1:y1+10),x1+x2, ((data&PULSE_BIT) ? y1:y1+10)); x1+=x2; XDrawLine(d1,w1,gc2,x1, ((data&PULSE_BIT) ? y1:y1+10),x1, ((data&PULSE_BIT) ? y1+10:y1)); } } } if (y1>w1_h) { y1=20; XClearWindow(d1,w1); for (y2=0;y2<w1_w;y2+=10) XDrawLine(d1,w1,gc1,y2,0,y2,w1_h); XDrawString(d1,w1,gc2,w1_w-100,10,textbuffer,strlen(textbuffer)); } } } // gl_copyscreen(physicalscreen); // XFlush(d1); }; exit(EXIT_SUCCESS); }