Exemple #1
0
void box(int ox, int oy, int ww, int wh)
{
    float x[2],vertexcolor[3];
    
    
    vertexcolor[0] = 1.0;
    vertexcolor[1] = 1.0;
    vertexcolor[2] = 1.0;
	mycolor(vertexcolor);	
	glBegin(GL_POLYGON);
	x[0] = ox;
	x[1] = oy;
	myvx(x);
	x[0] = ox+ww-1;
    vertexcolor[0] = 0;
    vertexcolor[1] = 1;
    vertexcolor[2] = 0;
	mycolor(vertexcolor);	
	myvx(x);
	x[1] = oy+wh -1;
	myvx(x);
	x[0] = ox;
	myvx(x);
	glEnd();
    
}
Exemple #2
0
void paint_bar(Stimulus *st, Substim *sst, int mode)
{
   Locator *pos = &sst->pos;
  int i,ci,w,h;
  float x[2],z[2],vcolor[3],*xc,*yc,*cc,*rc,cval;
  float angle,val;

    val = (st->background) * (1+ pos->contrast);
  if(pos->contrast > 2)
    val = 1.0;
  else if (st->background == 0)
    val = pos->contrast;
  cval = dogamma(val);
  vcolor[0] = vcolor[1] = vcolor[2] = cval;

  glPushMatrix();
  glTranslatef((pos->xy[0]),pos->xy[1],0);
  angle = (float) (pos->angle * 180.0/M_PI);
  glRotatef(angle,0,0,1);

  if(mode == LEFTMODE)
  {
    rc = cc = &vcolor[0];
  }
  else if(mode == RIGHTMODE)
  {
    cc = &vcolor[1];
    rc = &vcolor[2];
  }
   val = pos->phase;
   while(val > (2 * M_PI))
     val -= (M_PI * 2);

/*
* for bars, pos->f determines the width of the bar, while
* pos->radius[1] determines the field over which the bar moves
*/
   h = pos->radius[0];
   w = deg2pix(1/(2*st->f));
  z[0] = (-pos->radius[0]);
/*
 * if SQUARE, have constant velocity sweeps in one direction. Sign reversal 
 * is so that direction matches sines/rds
 */

  if(st->flag & STIMULUS_IS_SQUARE)
    z[1] = -w/2 - ((pos->radius[1]) * (val/M_PI -1));
  else
    z[1] = ((pos->radius[1]) * cos(val)) - w/2;
  glBegin(GL_POLYGON);
  mycolor(vcolor);	
  x[0] = z[0];
  x[1] = z[1];
  myvx(x);
  x[1] = z[1] + w;
  myvx(x);
  x[0] = z[0] +2 *  pos->radius[0];
  myvx(x);
  x[1] = z[1];
  myvx(x);
  glEnd();

  if(optionflag & ANTIALIAS_BIT)
    {
  glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
  glLineWidth(1.0);
  glEnable(GL_BLEND);
  glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  glEnable(GL_LINE_SMOOTH);
  glBegin(GL_POLYGON);
  mycolor(vcolor);	
  x[0] = z[0];
  x[1] = z[1];
  myvx(x);
  x[1] = z[1] + w;
  myvx(x);
  x[0] = z[0] +2 *  pos->radius[0];
  myvx(x);
  x[1] = z[1];
  myvx(x);
  glEnd();
  glDisable(GL_BLEND);
  glDisable(GL_LINE_SMOOTH);
  glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
    }
  glPopMatrix();
  for(i = 0; i < sst->nbars; i++){
    glPushMatrix();
    glTranslatef(sst->xpos[i],sst->ypos[i],0);
    angle = (float) (sst->imb[i] * 180.0/M_PI);
    glRotatef(angle,0,0,1);
  glBegin(GL_POLYGON);
  mycolor(vcolor);	
  x[0] = z[0];
  x[1] = z[1];
  myvx(x);
  x[1] = z[1] + w;
  myvx(x);
  x[0] = z[0] +2 *  pos->radius[0];
  myvx(x);
  x[1] = z[1];
  myvx(x);
  glEnd();
    glPopMatrix();
      if(debug){
      glFlushRenderAPPLE();
          glSwapAPPLE();
      }
  }

}
Exemple #3
0
int main( int argc , char *argv[] ){
    Display *display;
    Window window;
    Window pen_window[5];
    Window color_window[5];

    GC     gc;
    char title[]      = "Paint";
    char icon_title[] = "Paint";
    unsigned long background;
    unsigned long foreground;
    int button_size=40;

    char *colors[]={
	"rgb:00/00/00",
	"rgb:ff/00/00",
	"rgb:00/ff/00",
	"rgb:00/00/ff",
	"rgb:ff/ff/00",
    };

    int current_pen=2;
    unsigned long current_color=0;
    int x0,y0,x1,y1;
    int i;
		     
    display = XOpenDisplay(NULL);

    background = WhitePixel(display,0);
    foreground = BlackPixel(display,0);

    window = XCreateSimpleWindow(display,
                                 DefaultRootWindow(display),
                                 0,0,500,400,
                                 0,0,background);

    XSetStandardProperties(display,window,title,icon_title,
			   None,argv,argc,NULL);

    /* GC を生成し、各種設定を行う */
    gc = XCreateGC(display,window,0,0);
    XSetBackground(display,gc,background);
    XSetForeground(display,gc,current_color);
    XSetLineAttributes(display,gc,current_pen,
		       LineSolid,CapRound,JoinMiter);

    /* メインウィンドウのイベントマスクを設定 */
    XSelectInput(display,window,
		 ExposureMask |
		 ButtonPressMask |
		 ButtonMotionMask);

    /* ペンサイズ・色選択ウィンドウを作成 */
    for ( i=0 ; i<sizeof(pen_window)/sizeof(pen_window[0]) ; i++ ){
	pen_window[i] =
	  XCreateSimpleWindow(display,window,
			      10,(button_size+10)*i+30,
			      button_size,button_size,
			      1,mycolor(display,"rgb:aa/aa/aa"),
			      mycolor(display,"rgb:ee/ee/ee"));
	color_window[i] =
	  XCreateSimpleWindow(display,window,
			      500-10-button_size,(button_size+10)*i+30,
			      button_size,button_size,
			      1,mycolor(display,"rgb:aa/aa/aa"),
			      mycolor(display,colors[i]));
	XSelectInput(display,pen_window[i],
		     ButtonPressMask |
		     EnterWindowMask |
		     LeaveWindowMask );
	XSelectInput(display,color_window[i],
		     ButtonPressMask |
		     EnterWindowMask |
		     LeaveWindowMask );
    }

    /* 全てのウィンドウをマップ */
    XMapWindow(display,window);
    XMapSubwindows(display,window);

    while (1){
	XEvent event;
        XNextEvent(display,&event);
        switch ( event.type ){

          case Expose:		/* 再描画 */
	    for ( i=0 ; i<sizeof(pen_window)/sizeof(pen_window[0]) ; i++ ){
		int pen_size = i*3+2;
				/* ペンサイズウィンドウを再描画 */
		XSetForeground(display,gc,foreground);
		XFillArc(display,pen_window[i],gc,
			 button_size/2-pen_size/2,button_size/2-pen_size/2,
			 pen_size,pen_size,0,360*64);

	    }
            break;

	  case EnterNotify:	/* ウィンドウにポインタが入った */
	    XSetWindowBorder(display,event.xany.window,
			     mycolor(display,"black"));
	    break;

	  case LeaveNotify:	/* ウィンドウからポインタが出た */
	    XSetWindowBorder(display,event.xany.window,
			     mycolor(display,"rgb:aa/aa/aa"));
	    break;

	  case MotionNotify:	/* ボタンを押しながらマウスが動いた */
	    x1 = event.xbutton.x;
	    y1 = event.xbutton.y;
	    XDrawLine(display,window,gc,x0,y0,x1,y1);
	    x0 = x1; y0 = y1;
	    break;

	  case ButtonPress:	/* ボタンが押された */

				/* キャンバス上で押された? */
	    if ( event.xany.window == window ){
		x0 = event.xbutton.x;
		y0 = event.xbutton.y;
		XDrawLine(display,window,gc,x0,y0,x0,y0);
		break;
	    }

				/* ペンサイズ/色選択ウィンドウ上で押された? */
	    for ( i=0 ; i<sizeof(pen_window)/sizeof(pen_window[0]) ; i++ ){
				/* ペンサイズを変更 */
		if ( event.xany.window == pen_window[i] ){
		    current_pen = i*3+2;
		    XSetLineAttributes(display,gc,current_pen,
				       LineSolid,CapRound,JoinMiter);
		    break;
		}
				/* 色を変更 */
		if ( event.xany.window == color_window[i] ){
		    current_color = mycolor(display,colors[i]);
		    XSetForeground(display,gc,current_color);
		    break;
		}
	    }
	    break;
        }
    }
}
Exemple #4
0
void paint_square(Stimulus *st, Substim *sst, int mode)
{
    Locator *pos = &sst->pos;
    int i,ci,w,h,ncycles;
    short *p,*q,*end,vx,vy,*vpx,*vpy,*vpoy,*vpox;
    short x[2],z[2],*xc,*yc,c;
    float offcolor[3],vcolor[3],*rc,*cc;
    float angle, oldplaid;
    double val,cval;
    
    if(sst->ptr->plaid_angle < -0.1)
        val = (double)(st->background) * (1+ pos->contrast_amp);
    else
        val = (double)(st->background) * (1+ pos->contrast);
    if(st->background < 0.01 && pos->contrast > 0)
        val = pos->contrast;
    
    vcolor[0] = vcolor[1] = vcolor[2] = dogamma(val);
    
    if(sst->ptr->plaid_angle < -0.1)
        val = (double)(st->background) * (1- pos->contrast_amp);
    else
        val = (double)(st->background) * (1- pos->contrast);
    if(st->background < 0.01 && pos->contrast < 0)
        val = -pos->contrast;
    
    offcolor[0] = offcolor[1] = offcolor[2] = dogamma(val);
    
    glPushMatrix();
    glTranslatef((pos->xy[0]),pos->xy[1],0);
    angle  = (pos->angle+sst->ptr->plaid_angle/2) * 180/M_PI;
    glRotatef(angle,0.0,0.0,1.0);
    
    if(mode == LEFTMODE)
    {
        rc = cc = &vcolor[0];
    }
    else if(mode == RIGHTMODE)
    {
        cc = &vcolor[1];
        rc = &vcolor[2];
    }
    val = pos->phase;
    while(val > (2 * M_PI))
        val -= (M_PI * 2);
    
    /*
     * for ss, pos->f determines the width of the square, while
     * pos->radius[1] determines the field over which the squaren moves
     */
    h = pos->radius[0];
    w = deg2pix(1/(2*st->f));
    ncycles = pos->radius[1]/w;
    z[1] = -w * val/M_PI - (pos->radius[1]);
    z[0] = (-pos->radius[0]);
    while(z[1] < pos->radius[1])
    {
        mycolor(vcolor);	
        glBegin(GL_POLYGON);
        x[0] = z[0];
        x[1] = z[1];
        if(x[1] < -pos->radius[1])
            x[1] = -pos->radius[1];
        else if(x[1] > pos->radius[1])
            x[1] = pos->radius[1];
        myvx(x);
        x[1] = z[1] + w;
        if(x[1] < -pos->radius[1])
            x[1] = -pos->radius[1];
        else if(x[1] > pos->radius[1])
            x[1] = pos->radius[1];
        myvx(x);
        x[0] = z[0] +2 *  pos->radius[0];
        myvx(x);
        x[1] = z[1];
        if(x[1] < -pos->radius[1])
            x[1] = -pos->radius[1];
        else if(x[1] > pos->radius[1])
            x[1] = pos->radius[1];
        myvx(x);
        glEnd();
        z[1] += w;
        
        mycolor(offcolor);	
        glBegin(GL_POLYGON);
        x[0] = z[0];
        x[1] = z[1];
        if(x[1] < -pos->radius[1])
            x[1] = -pos->radius[1];
        else if(x[1] > pos->radius[1])
            x[1] = pos->radius[1];
        myvx(x);
        x[1] = z[1] + w;
        if(x[1] < -pos->radius[1])
            x[1] = -pos->radius[1];
        else if(x[1] > pos->radius[1])
            x[1] = pos->radius[1];
        myvx(x);
        x[0] = z[0] +2 *  pos->radius[0];
        myvx(x);
        x[1] = z[1];
        if(x[1] < -pos->radius[1])
            x[1] = -pos->radius[1];
        else if(x[1] > pos->radius[1])
            x[1] = pos->radius[1];
        myvx(x);
        glEnd();
        
        z[1] += w;
    }
    
    glPopMatrix();
    if(sst->ptr->plaid_angle > 0.01)
    {
        glDisable(GL_DEPTH_TEST);
        glDisable(GL_LIGHTING);
        glEnable(GL_BLEND);
        glBlendColor(0.5, 0.5, 0.5,  0.5);
        glBlendFunc (GL_ONE_MINUS_CONSTANT_COLOR, GL_CONSTANT_COLOR);
        oldplaid = sst->ptr->plaid_angle;
        sst->ptr->plaid_angle = -sst->ptr->plaid_angle;
        paint_square(st, sst, mode);
        glDisable(GL_BLEND);
        sst->ptr->plaid_angle = oldplaid;
    }
    
}