Example #1
0
/* display_mat: displays a Row x Col matrix Mat in the window Gid,
 * using a simple colour-coded representation (blue for Lowval, red for
 * Upval etc.) The window may be resized, moved or iconified.
 * The window is closed when <Esc> is pressed.
 */
void display_mat(long Gid, double **Mat, unsigned int Row, unsigned int Col, 
		    double Lowval, double Upval)
{
    Device Dev;
    short Val;
    
    plot_mat(Gid, Mat, Row, Col, Lowval, Upval);
    while(1)
    {
	do  /* read the event queue until empty */
	{
	    Dev=qread(&Val);
	    switch(Dev)
	    {
		case REDRAW:	/* redraw if necessary */
		case REDRAWICONIC:
		case WINFREEZE:
		case WINTHAW:
		    plot_mat(Gid, Mat, Row, Col, Lowval, Upval);
		break;
		
		case ESCKEY:	/* both close up shop */
		case WINQUIT:
		    winclose(Gid); return;
		break;
		
		default: break;
	    }
	} while (qtest());
    }	    /* while(1) */
}
Example #2
0
vrpn_SGIBox::vrpn_SGIBox(char * name, vrpn_Connection * c):
  vrpn_Analog(name, c), vrpn_Button_Filter(name, c) {
    int ret;
    char hn[128];
    sid  = -1;
    winid =  -1;

    if (winid != -1) {
      printf("Closing previous windows Winid=%d, sid = %d:\n",winid, sid);
      winclose(winid);
      //dglclose(sid);
      dglclose(-1); // close all dgl connection;
    }

    ret = gethostname(hn, 100);
    if (ret < 0) {
      fprintf(stderr, "vrpn_SGIBox: error in gethostname()\n");
      return;
    }
    sid = ret = dglopen(hn,DGLLOCAL);
    if (ret < 0) {
      fprintf(stderr, "vrpn_SGIBox: error in dglopen()\n");
      return;
    }
    noport();
    winid = winopen("");
    reset();
    num_channel = NUM_DIALS;
    num_buttons = NUM_BUTTONS;
    
    register_autodeleted_handler(c->register_message_type( vrpn_got_first_connection), sgibox_con_cb, this);
    register_autodeleted_handler(alert_message_id,sgibox_alert_handler, this);
    set_alerts(1);	//turn on alerts from toggle filter class to notify
			//local sgibox that lights should be turned on/off
}
Example #3
0
static int
rmb(void)
{
	static Menu menu = {nil, menugen};
	int n;
	Win *w;
	File *f;

	if(actw != nil && actw->tab->rmb != nil && actw->tab->rmb(actw, mc) >= 0)
		return 0;
	n = menuhit(3, mc, &menu, nil);
	if(n < 0)
		return 0;
	switch(n){
	case ZEROX:
		w = winsel(mc, 3);
		if(w != nil)
			winzerox(w, mc);
		return 0;
	case CLOSE:
		w = winsel(mc, 3);
		if(w != nil)
			winclose(w);
		return 0;
	case RESIZE:
		winresize(winsel(mc, 3), mc);
		return 0;
	case WRITE:
		w = winsel(mc, 3);
		if(w != nil)
			winwrite(w, nil);
		return 0;
	case QUIT:
		return quit();
	}
	if(n < WIN)
		sysfatal("rmb: no action for n=%d", n);
	if(n == 0){
		setfocus(cmdw);
		return 0;
	}
	n -= WIN;
	for(f = flist.next; f != &flist; f = f->next)
		if(--n == 0){
			if(f->wins.wnext == &f->wins){
				newwinsel(f->type, mc, f);
				return 0;
			}
			for(w = f->wins.wnext; w != &f->wins && w != actw; w = w->wnext)
				;
			if(w->wnext == &f->wins)
				w = w->wnext;
			setfocus(w->wnext);
			return 0;
		}
	return 0;
}
Example #4
0
void
colclose(Column *c, Window *w, int dofree)
{
	Rectangle r;
	int i, didmouse, up;

	/* w is locked */
	if(!c->safe)
		colgrow(c, w, 1);
	for(i=0; i<c->nw; i++)
		if(c->w[i] == w)
			goto Found;
	error("can't find window");
  Found:
	r = w->r;
	w->tag.col = nil;
	w->body.col = nil;
	w->col = nil;
	didmouse = restoremouse(w);
	if(dofree){
		windelete(w);
		winclose(w);
	}
	c->nw--;
	memmove(c->w+i, c->w+i+1, (c->nw-i)*sizeof(Window*));
	c->w = realloc(c->w, c->nw*sizeof(Window*));
	if(c->nw == 0){
		draw(screen, r, display->white, nil, ZP);
		return;
	}
	up = 0;
	if(i == c->nw){		/* extend last window down */
		w = c->w[i-1];
		r.min.y = w->r.min.y;
		r.max.y = c->r.max.y;
	}else{			/* extend next window up */
		up = 1;
		w = c->w[i];
		r.max.y = w->r.max.y;
	}
	draw(screen, r, textcols[BACK], nil, ZP);
	if(c->safe) {
		if(!didmouse && up)
			w->showdel = TRUE;
		winresize(w, r, FALSE, TRUE);
		if(!didmouse && up)
			movetodel(w);
	}
}
Example #5
0
void
colcloseall(Column *c)
{
	int i;
	Window *w;

	if(c == activecol)
		activecol = nil;
	textclose(&c->tag);
	for(i=0; i<c->nw; i++){
		w = c->w[i];
		winclose(w);
	}
	c->nw = 0;
	free(c->w);
	free(c);
	clearmouse();
}
Example #6
0
File: fsys.c Project: npe9/harvey
static
Xfid*
fsyswalk(Xfid *x, Fid *f)
{
    Fcall t;
    int c, i, j, id;
    Qid q;
    uint8_t type;
    uint32_t path;
    Fid *nf;
    Dirtab *d, *dir;
    Window *w;
    char *err;

    nf = nil;
    w = nil;
    if(f->open)
        return respond(x, &t, "walk of open file");
    if(x->fid != x->newfid) {
        nf = newfid(x->newfid);
        if(nf->busy)
            return respond(x, &t, "newfid already in use");
        nf->busy = TRUE;
        nf->open = FALSE;
        nf->mntdir = f->mntdir;
        if(f->mntdir)
            f->mntdir->ref++;
        nf->dir = f->dir;
        nf->qid = f->qid;
        nf->w = f->w;
        nf->nrpart = 0;	/* not open, so must be zero */
        if(nf->w)
            incref(nf->w);
        f = nf;	/* walk f */
    }

    t.nwqid = 0;
    err = nil;
    dir = nil;
    id = WIN(f->qid);
    q = f->qid;

    if(x->nwname > 0) {
        for(i=0; i<x->nwname; i++) {
            if((q.type & QTDIR) == 0) {
                err = Enotdir;
                break;
            }

            if(strcmp(x->wname[i], "..") == 0) {
                type = QTDIR;
                path = Qdir;
                id = 0;
                if(w) {
                    winclose(w);
                    w = nil;
                }
Accept:
                if(i == MAXWELEM) {
                    err = "name too long";
                    break;
                }
                q.type = type;
                q.vers = 0;
                q.path = QID(id, path);
                t.wqid[t.nwqid++] = q;
                continue;
            }

            /* is it a numeric name? */
            for(j=0; (c=x->wname[i][j]); j++)
                if(c<'0' || '9'<c)
                    goto Regular;
            /* yes: it's a directory */
            if(w)	/* name has form 27/23; get out before losing w */
                break;
            id = atoi(x->wname[i]);
            qlock(&row);
            w = lookid(id, FALSE);
            if(w == nil) {
                qunlock(&row);
                break;
            }
            incref(w);	/* we'll drop reference at end if there's an error */
            path = Qdir;
            type = QTDIR;
            qunlock(&row);
            dir = dirtabw;
            goto Accept;

Regular:
//			if(FILE(f->qid) == Qacme)	/* empty directory */
//				break;
            if(strcmp(x->wname[i], "new") == 0) {
                if(w)
                    error("w set in walk to new");
                sendp(cnewwindow, nil);	/* signal newwindowthread */
                w = recvp(cnewwindow);	/* receive new window */
                incref(w);
                type = QTDIR;
                path = QID(w->id, Qdir);
                id = w->id;
                dir = dirtabw;
                goto Accept;
            }

            if(id == 0)
                d = dirtab;
            else
                d = dirtabw;
            d++;	/* skip '.' */
            for(; d->name; d++)
                if(strcmp(x->wname[i], d->name) == 0) {
                    path = d->qid;
                    type = d->type;
                    dir = d;
                    goto Accept;
                }

            break;	/* file not found */
        }

        if(i==0 && err == nil)
            err = Eexist;
    }

    if(err!=nil || t.nwqid<x->nwname) {
        if(nf) {
            nf->busy = FALSE;
            fsysdelid(nf->mntdir);
        }
    } else if(t.nwqid  == x->nwname) {
        if(w) {
            f->w = w;
            w = nil;	/* don't drop the reference */
        }
        if(dir)
            f->dir = dir;
        f->qid = q;
    }

    if(w != nil)
        winclose(w);

    return respond(x, &t, err);
}
Example #7
0
void pdfapp_onkey(pdfapp_t *app, int c)
{
	int oldpage = app->pageno;
	enum panning panto = PAN_TO_TOP;
	int loadpage = 1;

	if (app->isediting)
	{
		int n = strlen(app->search);
		if (c < ' ')
		{
			if (c == '\b' && n > 0)
			{
				app->search[n - 1] = 0;
				winrepaintsearch(app);
			}
			if (c == '\n' || c == '\r')
			{
				app->isediting = 0;
				if (n > 0)
				{
					winrepaintsearch(app);
					pdfapp_onkey(app, 'n');
				}
				else
					winrepaint(app);
			}
			if (c == '\033')
			{
				app->isediting = 0;
				winrepaint(app);
			}
		}
		else
		{
			if (n + 2 < sizeof app->search)
			{
				app->search[n] = c;
				app->search[n + 1] = 0;
				winrepaintsearch(app);
			}
		}
		return;
	}

	/*
	 * Save numbers typed for later
	 */

	if (c >= '0' && c <= '9')
	{
		app->number[app->numberlen++] = c;
		app->number[app->numberlen] = '\0';
	}

	switch (c)
	{

	case '?':
		winhelp(app);
		break;

	case 'q':
		winclose(app);
		break;

	/*
	 * Zoom and rotate
	 */

	case '+':
	case '=':
		app->resolution *= ZOOMSTEP;
		if (app->resolution > MAXRES)
			app->resolution = MAXRES;
		pdfapp_showpage(app, 0, 1, 1);
		break;
	case '-':
		app->resolution /= ZOOMSTEP;
		if (app->resolution < MINRES)
			app->resolution = MINRES;
		pdfapp_showpage(app, 0, 1, 1);
		break;

	case 'L':
		app->rotate -= 90;
		pdfapp_showpage(app, 0, 1, 1);
		break;
	case 'R':
		app->rotate += 90;
		pdfapp_showpage(app, 0, 1, 1);
		break;

	case 'c':
		app->grayscale ^= 1;
		pdfapp_showpage(app, 0, 1, 1);
		break;

#ifndef NDEBUG
	case 'a':
		app->rotate -= 15;
		pdfapp_showpage(app, 0, 1, 1);
		break;
	case 's':
		app->rotate += 15;
		pdfapp_showpage(app, 0, 1, 1);
		break;
#endif

	/*
	 * Pan view, but dont need to repaint image
	 */

	case 'w':
		app->shrinkwrap = 1;
		app->panx = app->pany = 0;
		pdfapp_showpage(app, 0, 0, 1);
		break;

	case 'h':
		app->panx += app->image->w / 10;
		pdfapp_showpage(app, 0, 0, 1);
		break;

	case 'j':
		app->pany -= app->image->h / 10;
		pdfapp_showpage(app, 0, 0, 1);
		break;

	case 'k':
		app->pany += app->image->h / 10;
		pdfapp_showpage(app, 0, 0, 1);
		break;

	case 'l':
		app->panx -= app->image->w / 10;
		pdfapp_showpage(app, 0, 0, 1);
		break;

	/*
	 * Page navigation
	 */

	case 'g':
	case '\n':
	case '\r':
		if (app->numberlen > 0)
			app->pageno = atoi(app->number);
		else
			app->pageno = 1;
		break;

	case 'G':
		app->pageno = app->pagecount;
		break;

	case 'm':
		if (app->numberlen > 0)
		{
			int idx = atoi(app->number);

			if (idx >= 0 && idx < nelem(app->marks))
				app->marks[idx] = app->pageno;
		}
		else
		{
			if (app->histlen + 1 == 256)
			{
				memmove(app->hist, app->hist + 1, sizeof(int) * 255);
				app->histlen --;
			}
			app->hist[app->histlen++] = app->pageno;
		}
		break;

	case 't':
		if (app->numberlen > 0)
		{
			int idx = atoi(app->number);

			if (idx >= 0 && idx < nelem(app->marks))
				if (app->marks[idx] > 0)
					app->pageno = app->marks[idx];
		}
		else if (app->histlen > 0)
			app->pageno = app->hist[--app->histlen];
		break;

	/*
	 * Back and forth ...
	 */

	case ',':
		panto = PAN_TO_BOTTOM;
		if (app->numberlen > 0)
			app->pageno -= atoi(app->number);
		else
			app->pageno--;
		break;

	case '.':
		panto = PAN_TO_TOP;
		if (app->numberlen > 0)
			app->pageno += atoi(app->number);
		else
			app->pageno++;
		break;

	case 'b':
		panto = DONT_PAN;
		if (app->numberlen > 0)
			app->pageno -= atoi(app->number);
		else
			app->pageno--;
		break;

	case ' ':
		panto = DONT_PAN;
		if (app->numberlen > 0)
			app->pageno += atoi(app->number);
		else
			app->pageno++;
		break;

	case '<':
		panto = PAN_TO_TOP;
		app->pageno -= 10;
		break;
	case '>':
		panto = PAN_TO_TOP;
		app->pageno += 10;
		break;

	/*
	 * Reloading the file...
	 */

	case 'r':
		panto = DONT_PAN;
		oldpage = -1;
		winreloadfile(app);
		break;

	/*
	 * Searching
	 */

	case '/':
		app->isediting = 1;
		app->search[0] = 0;
		app->hit = -1;
		app->hitlen = 0;
		winrepaintsearch(app);
		break;

	case 'n':
		pdfapp_searchforward(app, &panto);
		loadpage = 0;
		break;

	case 'N':
		pdfapp_searchbackward(app, &panto);
		loadpage = 0;
		break;

	}

	if (c < '0' || c > '9')
		app->numberlen = 0;

	if (app->pageno < 1)
		app->pageno = 1;
	if (app->pageno > app->pagecount)
		app->pageno = app->pagecount;

	if (app->pageno != oldpage)
	{
		switch (panto)
		{
		case PAN_TO_TOP:
			app->pany = 0;
			break;
		case PAN_TO_BOTTOM:
			app->pany = -2000;
			break;
		case DONT_PAN:
			break;
		}
		pdfapp_showpage(app, loadpage, 1, 1);
	}
}
Example #8
0
/*
OK w95
 */
void mainEventLoop() {

   short     sVal, sXCurrent, sYCurrent;
   long      lDevice;
	int		i=0;
	int 	state = FALSE;
    short attached = 1;
    short value;
    int dev;
    int pupval;

  // make_all();
	//init_menu();

   nCurrentDir = DIR_NONE;

   czclear(0x404040, getgdesc(GD_ZMAX));

   while (TRUE) {

      if (qtest()) {
         lDevice = qread(&sVal);

         switch (lDevice) {

			case INPUTCHANGE:
				#ifdef DOFF
					printf(" %d, %d, %d\n", Win_ids[0], Win_ids[1], sVal);
				#endif
				if ( sVal != 0 )
					Input_win = sVal;
				else
					Input_win = -1;
				break;

            case REDRAW:
				if ( sVal == Win_ids[1] && Win_ids[1] != -1 )
					vDrawHelpScene();
				else if ( sVal == Win_ids[0] )
				{
               		reshapeviewport();
               		getsize(&nWinWidth, &nWinHeight);
               		getorigin(&nXWinOrigin, &nYWinOrigin);
				}
               break;

            case RIGHTMOUSE:
               pupval = dopup(mainmenu);
               break;
  
			case SPACEKEY:
				state = TRUE;
				i++;
				if ( i == 4 )
					subEventLoop();
				break;

			case RKEY:
				if ( Last_Actions[FIRE] == TRUE )
					vEventLoop(&vDrawTitle);
				break;

         case QKEY:
				if ( Input_win == Win_ids[1] ) 
				{
					winclose(Input_win);
					Win_ids[1] != -1;
				}
				else if ( Input_win == Win_ids[0] )
				{
					winclose(Win_ids[0]);
					if ( Win_ids[1] != -1 )
						winclose(Win_ids[1]);
	               exit(0);
				}
               break;

            default:
               break;
         }
      }
		getdev(DR_NUM_BUT, Devs, Last_Actions);

	  	vDrawTitle(state);
   }
}
Example #9
0
/*
 half OK w95
 */
void subEventLoop() 
{
   short     sVal, sXCurrent, sYCurrent;
   long      lDevice;
	float tmp;

   nCurrentDir = DIR_NONE;
   czclear(0x404040, getgdesc(GD_ZMAX));

   strcpy(Message, ReadyMesg);
   vDrawScene();
   qreset();
   while (TRUE) {

      if (qtest()) {
         lDevice = qread(&sVal);

         switch (lDevice)
			{

			case INPUTCHANGE:
				#ifdef DOFF
					printf(" %d, %d, %d\n", Win_ids[0], Win_ids[1], sVal);
				#endif
				if ( sVal != 0 )
					Input_win = sVal;
				else
					Input_win = -1;
				break;

            case REDRAW:
				if ( sVal == Win_ids[1] && Win_ids[1] != -1 )
					vDrawHelpScene();
				else if ( sVal == Win_ids[0] )
				{
					winset(Win_ids[0]);
               		reshapeviewport();
               		getsize(&nWinWidth, &nWinHeight);
               		getorigin(&nXWinOrigin, &nYWinOrigin);
					tmp = Speed;
					Speed = 0.0;
               		vDrawScene();
					Speed = tmp;
				}
            break;

         case RIGHTMOUSE:
               dopup(mainmenu);
               break;
  
			case SPACEKEY:
				if ( EMode == FALSE )
				{
					p1EventLoop();
					strcpy(Message, "");
				}
				if ( EMode == TRUE )    /* game over */
				{
					vDrawOverScene();
				}
				break;

			case RKEY:
				if ( Last_Actions[FIRE] == TRUE )
					vEventLoop((&vDrawScene));
				break;

         case QKEY:
				if ( Input_win == Win_ids[1] ) 
				{
					winclose(Input_win);
					Win_ids[1] != -1;
				}
				else if ( Input_win == Win_ids[0] )
				{
					winclose(Win_ids[0]);
					if ( Win_ids[1] != -1 )
						winclose(Win_ids[1]);
	               exit(0);
				}
				break;

             default:
               break;
         }
      }
	  else
		getdev(DR_NUM_BUT, Devs, Last_Actions);

   }
}
Example #10
0
/*---------------------------------------------------------------------------
main play loop
---------------------------------------------------------------------------*/
void p1EventLoop() {

   short     sVal;
   long      lDevice;
   Matrix    mNewMat;
   int		 reset = TRUE, i;
	static OKMode = FALSE;

	PMode = TRUE;

    strcpy(Message, "");
    while (TRUE) 
	{

		if (qtest()) 
		{
    		lDevice = qread(&sVal);

        	switch (lDevice) 
			{

			case INPUTCHANGE:
				#ifdef DOFF
					printf(" %d, %d, %d\n", Win_ids[0], Win_ids[1], sVal);
				#endif
				if ( sVal != 0 )
					Input_win = sVal;
				else
					Input_win = -1;
				break;

            case REDRAW:
				if ( sVal == Win_ids[1] && Win_ids[1] != -1 )
					vDrawHelpScene();
				else if ( sVal == Win_ids[0] )
				{
					winset(Win_ids[0]);
               		reshapeviewport();
               		getsize(&nWinWidth, &nWinHeight);
               		getorigin(&nXWinOrigin, &nYWinOrigin);
/*
               		vDrawScene();
*/
				}
               break;

				case ESCKEY:
					if ( OKMode != TRUE)
						return;
					break;

            case QKEY:
				if ( Input_win == Win_ids[1] ) 
				{
					winclose(Input_win);
					Win_ids[1] != -1;
				}
				else if ( Input_win == Win_ids[0] )
				{
					winclose(Win_ids[0]);
					if ( Win_ids[1] != -1 )
						winclose(Win_ids[1]);
	               exit(0);
				}
                	break;
        	}
		}

		getdev(DR_NUM_BUT, Devs, Last_Actions);

		if ( Time == Time/REDRAW_RATE*REDRAW_RATE )
		{
			if ( Energy <= 0 )
			{
				EMode = TRUE;
				return;
			}
			else if ( Time >= END_TIME )
			{
				OKMode = TRUE;
				last_mesg();
			}
			else
				vDrawScene();
		}

		for ( i=0; i<DR_NUM_BUT; i++)
		{
			Last_Actions[i] = FALSE;
		}
		Time++;

	}
}
Example #11
0
File: xfid.c Project: fr1tz/nadir
void
xfidclose(Xfid *x)
{
	Fcall fc;
	Window *w;
	int q;
	Text *t;

	w = x->f->w;
	x->f->busy = FALSE;
	x->f->w = nil;
	if(x->f->open == FALSE){
		if(w != nil)
			winclose(w);
		respond(x, &fc, nil);
		return;
	}

	q = FILE(x->f->qid);
	x->f->open = FALSE;
	if(w){
		winlock(w, 'E');
		switch(q){
		case QWctl:
			if(w->ctlfid!=~0 && w->ctlfid==x->f->fid){
				w->ctlfid = ~0;
				qunlock(&w->ctllock);
			}
			break;
		case QWdata:
		case QWxdata:
			w->nomark = FALSE;
			/* fall through */
		case QWaddr:
		case QWevent:	/* BUG: do we need to shut down Xfid? */
			if(--w->nopen[q] == 0){
				if(q == QWdata || q == QWxdata)
					w->nomark = FALSE;
				if(q==QWevent && !w->isdir && w->col!=nil){
					w->filemenu = TRUE;
					winsettag(w);
				}
				if(q == QWevent){
					free(w->dumpstr);
					free(w->dumpdir);
					w->dumpstr = nil;
					w->dumpdir = nil;
				}
			}
			break;
		case QWrdsel:
			close(w->rdselfd);
			w->rdselfd = 0;
			break;
		case QWwrsel:
			w->nomark = FALSE;
			t = &w->body;
			/* before: only did this if !w->noscroll, but that didn't seem right in practice */
			textshow(t, min(w->wrselrange.q0, t->file->b.nc),
				min(w->wrselrange.q1, t->file->b.nc), 1);
			textscrdraw(t);
			break;
		case QWeditout:
			qunlock(&w->editoutlk);
			break;
		}
		winunlock(w);
		winclose(w);
	}
	else{
		switch(q){
		case Qeditout:
			qunlock(&editoutlk);
			break;
		}
	}
	respond(x, &fc, nil);
}