Пример #1
0
/* HR 050203: drag & drop */
static
boolean itm_drop(WINDOW *w, int n, int *list, int kstate, ICND *icnlist, int x, int y)
{
	int i, item, apid = -1, hdl = wind_find(x, y);
	long fd;
/*	ITMTYPE type;
*/	const char *path;

	if (hdl > 0)
		wind_get(hdl, WF_OWNER, &apid);

	if (apid > 0)
	{
		char ddsexts[32];

		fd = ddcreate(apid, ap_id, hdl, x, y, kstate, ddsexts);
		if (fd > 0)
		{
			if (ddstry(fd, "ARGS", "", sizeof(LNAME)) != DD_NAK)
			{
				for (i = 0; i < n; i++)
				{
					if ((item = list[i]) == -1)
						continue;
			
					path = itm_fullname(w, item);

					if (path)
					{
					/*	type = itm_type(w, item);
						alert_msg("type %d | %s | '%s'", type, name, path);
					*/
						Fwrite(fd, 1, "'");
						Fwrite(fd, strlen(path), path);
						Fwrite(fd, 1, "'");	
					}
					if (i < n - 1)
						Fwrite(fd, 1, " ");
				}
				ddclose(fd);

				itm_select(w, -1, 0, TRUE);
				return TRUE;
			}
			else
				alert_printf(1, APPNOEXT);

			ddclose(fd);
		}
		else
		{
			alert_printf(1, APPNODD);
			return FALSE;
		}
	}

	alert_printf(1, MILLDEST);
	return FALSE;
}
Пример #2
0
/* check for duplicate or invalid keys */
static
boolean check_key(int button, int *tmp)
{
	int i, j;

	if ( button != OPTCANC && button != OPTKCLR )
	{
		for ( i = 0; i < NITEM; i++ )
			for ( j = i + 1; j <= NITEM; j++ )
				/* XD_ALT below in order to skip items related to boxes */
				if (       (tmp[i] & XD_SCANCODE) != 0
			    	|| (   (tmp[i] & ~XD_ALT) != 0
			    	    &&  tmp[i] == tmp[j]
			    	   )
					|| ( tmp[i] == (XD_CTRL | BACKSPC) ) /* DjV 019 280103 */
					|| ( tmp[i] == (XD_CTRL | TAB) 		 /* DjV 019 280103 */
					|| ( tmp[i] == XD_CTRL ) )			 /* DjV 019 280103 */
			       )
				{
					alert_printf ( 1, DUPKEY, setprefs[OPTKKEY].ob_spec.tedinfo->te_ptext );
					return TRUE;
				}
	}
	return FALSE;
}
Пример #3
0
int load_colors(XFILE *file)
{
	int nc, *colors;
	long n, h;

	if ((n = x_fread(file, &nc, sizeof(int))) < 0)
		 return (int) n;

	h = (long) nc *3L * sizeof(int);

	if ((colors = malloc(h)) == NULL)
		return ENSMEM;

	if ((n = x_fread(file, colors, h)) != h)
		return (n < 0) ? (int) n : EEOF;

	if (nc == ncolors)
		set_colors(colors);
	else
		alert_printf(1, MECOLORS);

	free(colors);

	return 0;
}
Пример #4
0
static boolean prtchar(char ch)
{
	long time;
	boolean ready = FALSE, result;
	int button;

	do
	{
		time = clock() + 1000;
		while ((clock() < time) && (Cprnos() == 0));
		if (Cprnos() != 0)
		{
			Cprnout(ch);
			result = FALSE;
			ready = TRUE;
		}
		else
		{
			button = alert_printf(2, MPRNRESP);
			result = TRUE;
			ready = (button == 2) ? TRUE : FALSE;
		}
	}
	while (ready == FALSE);

	return result;
}
Пример #5
0
boolean check_drive(int drv)
{
	if ((drv >= 0) && (drv < 26) && (btst(drvmap(), drv)))
		return TRUE;

	alert_printf(1, MDRVEXIS);

	return FALSE;
}
	/* from the tracker ABORT menu. */
int run_trials(void)
{
  int i;
  int trial;
                 // INITIAL CALIBRATION: matches following trials
  target_foreground_color = RGB(0,0,0);         // color of calibration target
  target_background_color = RGB(200,200,200);   // background for drift correction
  set_calibration_colors(target_foreground_color, target_background_color); // tell EXPTSPPT the colors
   
  // TRIAL_VAR_LABELS message is recorded for EyeLink Data Viewer analysis
  // It specifies the list of trial variables for the trial 
  // This should be written once only and put before the recording of individual trials
  eyemsg_printf("TRIAL_VAR_LABELS TYPE CENTRAL PERIPHERAL");

  if(SCRWIDTH!=800 || SCRHEIGHT!=600)
    alert_printf("Display mode is not 800x600, resizing will slow loading.");

  		/* PERFORM CAMERA SETUP, CALIBRATION */
  do_tracker_setup();
				/* loop through trials */
  for(trial=1;trial<=NTRIALS;trial++)
    {
      if(eyelink_is_connected()==0 || break_pressed())    /* drop out if link closed */
	{
	  return ABORT_EXPT;
	}
				/* RUN THE TRIAL */
      i = do_gcwindow_trial(trial);
      end_realtime_mode();

      switch(i)         	/* REPORT ANY ERRORS */
	{
	  case ABORT_EXPT:        /* handle experiment abort or disconnect */
	    eyemsg_printf("EXPERIMENT ABORTED");
	    return ABORT_EXPT;
	  case REPEAT_TRIAL:	  /* trial restart requested */
	    eyemsg_printf("TRIAL REPEATED");
	    trial--;
	    break;
	  case SKIP_TRIAL:	  /* skip trial */
	    eyemsg_printf("TRIAL ABORTED");
	    break;
	  case TRIAL_OK:          // successful trial
	    eyemsg_printf("TRIAL OK");
	    break;
	  default:                // other error code
	    eyemsg_printf("TRIAL ERROR");
	    break;
	}
    }  // END OF TRIAL LOOP
  return 0;
}
Пример #7
0
static void itm_copy(WINDOW *sw, int n, int *list, WINDOW *dw,
					 int dobject, int kstate, ICND *icnlist, int x, int y)
{
	if (dw != NULL)
	{
		if ((dobject != -1) && (itm_type(dw, dobject) == ITM_FILE))
			dobject = -1;
		if (((ITM_WINDOW *)dw)->itm_func->itm_copy(dw, dobject, sw, n, list, icnlist, x, y, kstate) == TRUE)
			itm_select(sw, -1, 0, TRUE);
	}
	else
		alert_printf(1, MILLDEST);
}
         // Create foreground and background bitmaps of picture
         // EyeLink graphics: blank display with box at center
         // type: 0 = blank background, 1= blank fovea (mask), 2 = blurred background
static int create_image_bitmaps(int type)
{ 
  target_foreground_color = RGB(0,0,0);         // color of calibration target
  target_background_color = RGB(128,128,128);   // background for drift correction
  set_calibration_colors(target_foreground_color, target_background_color); // tell EXPTSPPT the colors

  clear_full_screen_window(target_background_color);
// NOTE:  *** THE FOLLOWING TEXT SHOULD NOT APPEAR IN A REAL EXPERIMENT!!!! ****
  get_new_font("Arial", 24, 1);
  graphic_printf(target_foreground_color, -1, 1, SCRWIDTH/2, SCRHEIGHT/2, "Loading image...");

  switch(type)
    {  
      case 0:     // blank background
        fgbm = image_file_bitmap("images/sacrmeto.jpg", 0, SCRWIDTH,SCRHEIGHT,target_background_color);
        bgbm = blank_bitmap(target_background_color);
        break;
      case 1:     // blank fovea
        fgbm = blank_bitmap(target_background_color);
        bgbm = image_file_bitmap("images/sacrmeto.jpg", 0, SCRWIDTH,SCRHEIGHT,target_background_color);
        break;
      case 2:     // normal and blurred bitmaps, stretched to fit display
        fgbm = image_file_bitmap("images/sacrmeto.jpg", 0, SCRWIDTH,SCRHEIGHT,target_background_color);
        bgbm = image_file_bitmap("images/sac_blur.jpg", 0, SCRWIDTH,SCRHEIGHT,target_background_color);
        break;
    }

  eyecmd_printf("clear_screen 0");                   // clear EyeLink display
  eyecmd_printf("draw_box %d %d %d %d 15",          // Box around fixation point
           SCRWIDTH/2-16, SCRHEIGHT/2-16, SCRWIDTH/2+16, SCRHEIGHT/2+16);

  if(!fgbm || !bgbm)  // Check that both bitmaps exist.
    {
      eyemsg_printf("ERROR: could not load image");
      alert_printf("ERROR: could not load an image file");
      if(fgbm) DeleteObject(fgbm);
      if(bgbm) DeleteObject(bgbm);
      return SKIP_TRIAL;
    }
  return 0;
}
         // Create foreground and background bitmaps of text
static int create_text_bitmaps(void)
{
  RECT margins;                // margins for text
          
  margins.top = SCRHEIGHT/20;  // set margin in about 1°
  margins.left = SCRWIDTH/20;
  margins.right = SCRWIDTH - SCRWIDTH/20;
  margins.bottom = SCRHEIGHT - SCRHEIGHT/20;
    
  target_foreground_color = RGB(0,0,0);         // color of calibration target
  target_background_color = RGB(255,255,255);   // background for drift correction
  set_calibration_colors(target_foreground_color, target_background_color); // tell EXPTSPPT the colors

  get_new_font("Courier New", SCRHEIGHT/32, 1);   // create a monospaced font
                                 

  // Draw text and EyeLink graphics
  fgbm = text_bitmap_segment(fg_text, RGB(0,0,0), RGB(255,255,255), margins, SCRHEIGHT/15, 0, 
		"text.ias", "segments", SV_NOREPLACE); // Create bitmap and its segmentation (if it does not exist)
 

  // IAREA command is recorded for EyeLink Data Viewer analysis
  // It creates a set of interest areas by reading the segment files
  // Writes segmentation filename + path info 	
  eyemsg_printf("!V IAREA FILE segments/text.ias"); 

  // Draw text and EyeLink graphics for the background bitmap
  bgbm = text_bitmap(bg_text, RGB(0,0,0), RGB(255,255,255), margins, SCRHEIGHT/15, 0);

  
  if(!fgbm || !bgbm)  // Check that both bitmaps exist.
    {
      eyemsg_printf("ERROR: could not load image");
      alert_printf("ERROR: could not load an image file");
      if(fgbm) DeleteObject(fgbm);
      if(bgbm) DeleteObject(bgbm);
      return SKIP_TRIAL;
    }
  return 0;
}
Пример #10
0
static boolean check_print(WINDOW *w, int n, int *list)
{
	int i;
	boolean noerror;
	char *mes = "";

	for (i = 0; i < n; i++)
	{
		noerror = FALSE;

		switch (itm_type(w, list[i]))
		{
		case ITM_PRINTER:
			rsrc_gaddr(R_STRING, MPRINTER, &mes);
			break;
		case ITM_TRASH:
			rsrc_gaddr(R_STRING, MTRASHCN, &mes);
			break;
		case ITM_DRIVE:
			rsrc_gaddr(R_STRING, MDRIVE, &mes);
			break;
		case ITM_FOLDER:
			rsrc_gaddr(R_STRING, MFOLDER, &mes);
			break;
		case ITM_PROGRAM:
			rsrc_gaddr(R_STRING, MPROGRAM, &mes);
			break;
		case ITM_FILE:
			noerror = TRUE;
			break;
		}
		if (noerror == FALSE)
			break;
	}
	if (noerror == FALSE)
		alert_printf(1, MNOPRINT, mes);

	return noerror;
}
Пример #11
0
char *locate(const char *name, int type)
{
	char fname[256], *newpath, *newname, *fspec, *title;
	boolean result = FALSE;
	int ex_flags;

	if (type == L_FOLDER)
	{
		if ((fspec = fn_make_path(name, "*")) == NULL)		/* HR 271102 */
			return NULL;
		fname[0] = 0;
		ex_flags = EX_DIR;
	}
	else
	{
		if (   (fspec = fn_make_newname(
		                        name, 
		                        (  (type == L_LOADCFG) || (type == L_SAVECFG) )
		                          ? CFG_EXT
		                          : "*"					/* HR 271102 */
		                               )
		       ) == NULL
		   )
			return NULL;
		strcpy(fname, fn_get_name(name));
		ex_flags = EX_FILE;
	}

	rsrc_gaddr(R_STRING, FSTLFILE + type, &title);

	do
	{
		newpath = xfileselector(fspec, fname, title);

		free(fspec);

		if (newpath == NULL)
			return NULL;

		if (type == L_FOLDER)
		{
			if (((newname = fn_get_path(newpath)) != NULL) && (isroot(newname) == TRUE))
			{
				alert_printf(1, MNOROOT);
				free(newname);
			}
			else
				result = TRUE;
		}
		else
		{
			if ((type == L_PROGRAM) && (prg_isprogram(fname) == FALSE))
				alert_printf(1, MFNPRG, fname);
			else
			{
				if (((newname = fn_make_newname(newpath, fname)) != NULL) && (type != L_SAVECFG))
				{
					result = x_exist(newname, ex_flags);
					if (result == FALSE)
					{
						alert_printf(1, MFNEXIST, fname);
						free(newname);
					}
				}
				else
					result = TRUE;
			}
		}
		fspec = newpath;
	}
	while (result == FALSE);

	free(newpath);

	return newname;
}
Пример #12
0
static void load_options(void)
{
	XFILE *file;
	Options tmp;
	int error = 0;
	long n, opt_n;

	get_set_video(0); /* DjV 007 030103 get current video mode */
	
	if ((file = x_fopen(optname, O_DENYW | O_RDONLY, &error)) != NULL)
	{
		opt_n = sizeof(Options);
		tmp.version = 0;
		x_fread(file, &tmp, sizeof(int));

/* HR 240103: load older cfg versions */
		if (   tmp.version >= MIN_VERSION
		    && tmp.version <  CFG_VERSION
		   )
		{
			memset(&tmp.V2_2, 0, sizeof(tmp.V2_2));
			opt_n -= sizeof(tmp.V2_2);
		}

		x_fclose(file);
	}

	if ((file = x_fopen(optname, O_DENYW | O_RDONLY, &error)) != NULL)
	{
		if ((n = x_fread(file, &tmp, opt_n)) == opt_n)
		{
			if (   tmp.version >= MIN_VERSION		/* DjV 005 120103 (was 0x119) */
			    && tmp.version <= CFG_VERSION
			    && tmp.magic   == MAGIC
			   )
			{
				options = tmp;
				if (opt_n != sizeof(Options))		/* HR 240103 */
				{
					options.V2_2.fields = WD_SHSIZ | WD_SHDAT | WD_SHTIM | WD_SHATT; /* DjV 010 251202 HR 240103 */
					options.attribs = FA_SUBDIR | FA_SYSTEM; /* DjV 004 251202 HR 240103 */
				}
				ins_shorts();     /* DjV 019 080103 put kbd shortcuts into menu texts */
				wd_deselect_all();
				wd_default();

				if (tmp.cprefs & SAVE_COLORS)
					error = load_colors(file);

				if (error == 0)
					if ((error = dsk_load(file)) == 0)
						if ((error = ft_load(file)) == 0)
							if ((error = icnt_load(file)) == 0)
								if ((error = app_load(file)) == 0)
									if ((error = prg_load(file)) == 0)
										error = wd_load(file);
			}
			else
			{
				alert_printf(1, MVALIDCF);
				x_fclose(file);
				return;
			}
			/* DjV 007 030103 ---vvv--- */
			
			/* If read ok, set video state but do not change resolution */
			
			get_set_video(1);
			
			/* DjV 007 030103 ---^^^--- */
		}
		else
		{
			error = (n < 0) ? (int) n : EEOF;
			hndl_error(MLOADCFG, error);
			x_fclose(file);
			return;
		}
		x_fclose(file);
	}

	if (error != 0)
	{
		hndl_error(MLOADCFG, error);

		opt_default();
		dsk_default();
		ft_default();
		icnt_default();
		app_default();
		prg_default();
		wd_default();
	}

	if (options.version < 0x0130)
		options.dial_mode = (options.cprefs & 0x80) ? XD_BUFFERED : XD_NORMAL;

	xd_setposmode((options.cprefs & DIALPOS_MODE) ? XD_MOUSE : XD_CENTERED);
	set_dialmode();

	options.version = CFG_VERSION;
}
Пример #13
0
app_main()
{
  int i, j;
  char our_file_name[260] = "TEST";

  if(open_eyelink_connection(0)) return -1;    // abort if we can't open link
  set_offline_mode();                          
  flush_getkey_queue();                        // initialize getkey() system
  is_eyelink2 = (2 == eyelink_get_tracker_version(NULL) );

  get_display_information(&dispinfo);          // get window size, characteristics
      
     // NOTE: Camera display does not support 16-color modes
     // NOTE: Picture display examples don't work well with 256-color modes
     //       However, all other sample programs should work well.
  if(dispinfo.palsize==16)      // 16-color modes not functional
    {
      alert_printf("This program cannot use 16-color displays");
      goto shutdown;
    }
  if(dispinfo.refresh < 40)  // wait_for_refresh doesn't work!
    {
      alert_printf("No refresh synchroniztion available!");
    }
  if(dispinfo.palsize)     // 256-color modes: palettes not supported by this example
    {
      alert_printf("This program is not optimized for 256-color displays");
    }



  //SEAN  -display window
  if(make_full_screen_window(application_instance)) goto shutdown;  // create the window
  if(init_expt_graphics(full_screen_window, NULL)) goto shutdown;   // register window with EXPTSPPT

  i = SCRWIDTH/60;        // select best size for calibration target
  j = SCRWIDTH/300;       // and focal spot in target
  if(j < 2) j = 2;
  set_target_size(i, j);  // tell DLL the size of target features

  target_foreground_color = RGB(0,0,0);    // color of calibration target
  target_background_color = RGB(128,128,128);       // background for calibration and drift correction
  set_calibration_colors(target_foreground_color, target_background_color); // tell EXPTSPPT the colors

  set_cal_sounds("", "", "");
  set_dcorr_sounds("", "off", "off");
                                     // draw a title screen
  
  // SEAN
  clear_full_screen_window(target_background_color);    // clear screen

  get_new_font("Times Roman", SCRHEIGHT/32, 1);         // select a font
                                                        // Draw text
  graphic_printf(target_foreground_color, target_background_color, 1, SCRWIDTH/2, 1*SCRHEIGHT/30, 
                 "EyeLink Demonstration Experiment: Sample Code");
  graphic_printf(target_foreground_color, target_background_color, 1, SCRWIDTH/2, 2*SCRHEIGHT/30,
                 "Included with the Experiment Programming Kit for Windows");
  graphic_printf(target_foreground_color, target_background_color, 1, SCRWIDTH/2, 3*SCRHEIGHT/30, 
                 "All code is Copyright (c) 1997-2002 SR Research Ltd.");
  graphic_printf(target_foreground_color, target_background_color, 0, SCRWIDTH/5, 4*SCRHEIGHT/30, 
                 "Source code may be used as template for your experiments.");




//SEAN - file i/o
  i = edit_dialog(full_screen_window, "Create EDF File",            // Get the EDF file name
                 "Enter Tracker EDF file name:", our_file_name, 8);

  if(i==-1) goto shutdown;          // ALT-F4: terminate
  if(i==1)  our_file_name[0] = 0;   // Cancelled: No file name
  
  if(our_file_name[0])    // If file name set, open it
    {           
      if(!strstr(our_file_name, ".")) strcat(our_file_name, ".EDF");  // add extension
      i = open_data_file(our_file_name);                              // open file
      if(i!=0)                                                        // check for error
        {
          alert_printf("Cannot create EDF file '%s'", our_file_name);
          goto shutdown;
        }                                                              // add title to preamble
      eyecmd_printf("add_file_preamble_text 'RECORDED BY %s' ", program_name);
    }
                                      // Now configure tracker for display resolution
  eyecmd_printf("screen_pixel_coords = %ld %ld %ld %ld",    // Set display resolution   
                 dispinfo.left, dispinfo.top, dispinfo.right, dispinfo.bottom);
  eyecmd_printf("calibration_type = HV9");                  // Setup calibration type
  eyemsg_printf("DISPLAY_COORDS %ld %ld %ld %ld",           // Add resolution to EDF file
                 dispinfo.left, dispinfo.top, dispinfo.right, dispinfo.bottom);
  if(dispinfo.refresh>40)
    eyemsg_printf("FRAMERATE %1.2f Hz.", dispinfo.refresh);




		// SET UP TRACKER CONFIGURATION 
		      // set parser saccade thresholds (conservative settings)
  if(is_eyelink2)
    {
      eyecmd_printf("select_parser_configuration 0");  // 0 = standard sensitivity
    }
  else
    {
      eyecmd_printf("saccade_velocity_threshold = 35");
      eyecmd_printf("saccade_acceleration_threshold = 9500");
    }
		      // set EDF file contents 
  eyecmd_printf("file_event_filter = LEFT,RIGHT,FIXATION,SACCADE,BLINK,MESSAGE,BUTTON");
  eyecmd_printf("file_sample_data  = LEFT,RIGHT,GAZE,AREA,GAZERES,STATUS");
		      // set link data (used for gaze cursor) 
  eyecmd_printf("link_event_filter = LEFT,RIGHT,FIXATION,SACCADE,BLINK,BUTTON");
  eyecmd_printf("link_sample_data  = LEFT,RIGHT,GAZE,GAZERES,AREA,STATUS");
                      // Program button #5 for use in drift correction
  eyecmd_printf("button_function 5 'accept_target_fixation'");

  if(!eyelink_is_connected() || break_pressed()) goto end_expt;  // make sure we're still alive


	
       // RUN THE EXPERIMENTAL TRIALS (code depends on type of experiment)
                // Calling run_trials() performs a calibration followed by trials
                // This is equivalent to one block of an experiment 
                // It will return ABORT_EXPT if the program should exit

  i = run_trials();
  

end_expt:                // END: close, transfer EDF file
  set_offline_mode();               // set offline mode so we can transfer file
  pump_delay(500);                  // delay so tracker is ready
  eyecmd_printf("close_data_file"); // close data file

  if(break_pressed()) goto shutdown;          // don't get file if we aborted experiment
  if(our_file_name[0])                        // make sure we created a file
    receive_data_file(our_file_name, "", 0);  // transfer the file, ask for a local name

shutdown:                // CLEANUP
  close_expt_graphics();           // tell EXPTSPPT to release window
  close_eyelink_connection();      // disconnect from tracker
  close_full_screen_window();
  return 0;
}
      // Run gaze-contingent window trial
      // <fgbm> is bitmap to display within window
      // <bgbm> is bitmap to display outside window
      // <wwidth, wheight> is size of window in pixels
      // <mask> flags whether to treat window as a mask
      // <time_limit> is the maximum time the stimuli are displayed 
int gc_window_trial(HBITMAP fgbm, HBITMAP bgbm, 
                    int wwidth, int wheight, int mask, UINT32 time_limit)
{
  UINT32 trial_start=0;	// trial start time (for timeout) 
  UINT32 drawing_time;  // retrace-to-draw delay
  int button;		// the button pressed (0 if timeout) 
  int error;            // trial result code

  ALLF_DATA evt;         // buffer to hold sample and event data
  int first_display = 1; // used to determine first drawing of display  
  int eye_used = 0;      // indicates which eye's data to display
  float x, y;		 // gaze position 

    // NOTE: TRIALID AND TITLE MUST HAVE BEEN SET BEFORE DRIFT CORRECTION!
    // FAILURE TO INCLUDE THESE MAY CAUSE INCOMPATIBILITIES WITH ANALYSIS SOFTWARE!


       // Set size and type of gaze-contingent window 
  RECT display_rect;

  display_rect.top    = dispinfo.top;
  display_rect.bottom = dispinfo.bottom;
  display_rect.left   = dispinfo.left;
  display_rect.right  = dispinfo.right;
  initialize_gc_window(wwidth, wheight, fgbm, bgbm, 
                       full_screen_window, display_rect, 
                       mask, SCRWIDTH/300);  // sets 0.1 degree deadband

	   // DO PRE-TRIAL DRIFT CORRECTION 
	   // We repeat if ESC key pressed to do setup. 
  while(1)
    {              // Check link often so we can exit if tracker stopped
      if(!eyelink_is_connected()) return ABORT_EXPT;
	   // We let do_drift_correct() draw target in this example
	   // 3rd argument would be 0 if we already drew the display
      error = do_drift_correct((INT16)(SCRWIDTH/2), (INT16)(SCRHEIGHT/2), 1, 1);
           // repeat if ESC was pressed to access Setup menu 
      if(error!=27) break;
    }

  clear_full_screen_window(target_background_color);  // make sure display is blank
  
	// Start data recording to EDF file, BEFORE DISPLAYING STIMULUS 
	// You should always start recording 50-100 msec before required
	// otherwise you may lose a few msec of data 
  
	//  tell start_recording() to send link data
  error = start_recording(1,1,1,1);	// record with link data enabled
  if(error != 0) return error;          // ERROR: couldn't start recording
                              // record for 100 msec before displaying stimulus 
  begin_realtime_mode(100);   // Windows 2000/XP: no interruptions from now on

    // DONT DISPLAY OUR IMAGES TO SUBJECT until we have first gaze postion!
  
  if(!eyelink_wait_for_block_start(100, 1, 0))  // wait for link sample data
    {
      end_trial();
      alert_printf("ERROR: No link samples received!");
      return TRIAL_ERROR;
    }
  eye_used = eyelink_eye_available(); // determine which eye(s) are available 
  switch(eye_used)		      // select eye, add annotation to EDF file	
    {			
      case RIGHT_EYE:
        eyemsg_printf("EYE_USED 1 RIGHT");
        break;
      case BINOCULAR:           // both eye's data present: use left eye only
        eye_used = LEFT_EYE;
      case LEFT_EYE:
        eyemsg_printf("EYE_USED 0 LEFT");
        break;
    }
                                 // Now get ready for trial loop
  eyelink_flush_keybuttons(0);   // reset keys and buttons from tracker 
                       // we don't use getkey() especially in a time-critical trial
                       // as Windows may interrupt us and cause an unpredicatable delay
                       // so we would use buttons or tracker keys only  

     // Trial loop: till timeout or response -- added code for reading samples and moving cursor
  while(1) 
    {                            // First, check if recording aborted 
      if((error=check_recording())!=0) return error;  
                                 // Check if trial time limit expired
      if(current_time() > trial_start+time_limit && trial_start!=0)
        {
          eyemsg_printf("TIMEOUT");    // message to log the timeout 
	  end_trial();                 // local function to stop recording
	  button = 0;                  // trial result message is 0 if timeout 
	  break;                       // exit trial loop
	}

      if(break_pressed())     // check for program termination or ALT-F4 or CTRL-C keys
	{
	   end_trial();         // local function to stop recording
	   return ABORT_EXPT;   // return this code to terminate experiment
	 }

      if(escape_pressed())    // check for local ESC key to abort trial (useful in debugging)   
         {
	   end_trial();         // local function to stop recording
	   return SKIP_TRIAL;   // return this code if trial terminated
         }

		/* BUTTON RESPONSE TEST */
		// Check for eye-tracker buttons pressed
		// This is the preferred way to get response data or end trials	
      button = eyelink_last_button_press(NULL);
      if(button!=0)       // button number, or 0 if none pressed
	{
	   eyemsg_printf("ENDBUTTON %d", button);  // message to log the button press
	   end_trial();                            // local function to stop recording
	   break;                                  // exit trial loop
	 }
  
                // NEW CODE FOR GAZE CONTINGENT WINDOW 
  
      if(eyelink_newest_float_sample(NULL)>0)  // check for new sample update
	{
	  eyelink_newest_float_sample(&evt);   // get the sample 
          x = evt.fs.gx[eye_used];    // yes: get gaze position from sample 
	  y = evt.fs.gy[eye_used];
	  if(x!=MISSING_DATA && 
             y!=MISSING_DATA &&
	     evt.fs.pa[eye_used]>0)     // make sure pupil is present
            {
              if(first_display)  // mark display start AFTER first drawing of window
                {       
                  wait_for_video_refresh();	  // synchronize before drawing so all seen at once
                  drawing_time = current_msec();  // time of retrace
                  trial_start = drawing_time;   // record the display onset time 
                }
	      redraw_gc_window((int)x, (int)y);  // move window if visible
              if(first_display)  // mark display start AFTER first drawing of window
                {       
                  first_display = 0;      
                  drawing_time = current_msec() - drawing_time; // delay from retrace
                  eyemsg_printf("%d DISPLAY ON", drawing_time);	// message for RT recording in analysis 
                  eyemsg_printf("SYNCTIME %d", drawing_time);	// message marks zero-plot time for EDFVIEW 
                }
            }
	  else
            {
	        // Don't move window during blink
                // To hide window, use:   redraw_gc_window(MISSING, MISSING);
            }
        } 
    }                       // END OF RECORDING LOOP

  end_realtime_mode();      // safety cleanup code
  while(getkey());          // dump any accumulated key presses

			   // report response result: 0=timeout, else button number
  eyemsg_printf("TRIAL_RESULT %d", button);
			   // Call this at the end of the trial, to handle special conditions
  return check_record_exit();
}
Пример #15
0
static void itm_move(WINDOW *src_wd, int src_object, int old_x, int old_y)
{
	int x = old_x, y = old_y;
	WINDOW *cur_wd = src_wd, *new_wd;
	int cur_object = src_object, new_object;
	int clip[4];
	int ox, oy, kstate, *list, n, nv, i;
	boolean cur_state = TRUE, new_state, mreleased;
	ICND *icnlist;

	if (itm_type(src_wd, src_object) == ITM_PREVDIR)
	{
		wait_button();
		return;
	}

	if ((itm_list(src_wd, &n, &list) == FALSE) || (n == 0))
		return;

	for (i = 0; i < n; i++)
	{
		if (itm_type(src_wd, list[i]) == ITM_PREVDIR)
			itm_select(src_wd, list[i], 2, TRUE);
	}

	free(list);

	if (itm_xlist(src_wd, &n, &nv, &list, &icnlist, old_x, old_y) == FALSE)
		return;

	get_minmax(icnlist, nv, clip);

	wind_update(BEG_MCTRL);
	graf_mouse(FLAT_HAND, NULL);
	draw_icns(icnlist, nv, x, y, clip);

	do
	{
		ox = x;
		oy = y;
		mreleased = xe_mouse_event(0, &x, &y, &kstate);

		if ((x != ox) || (y != oy))
		{
			draw_icns(icnlist, nv, ox, oy, clip);
			find_newobj(x, y, &new_wd, &new_object, &new_state);

			if ((cur_wd != new_wd) || (cur_object != new_object))
			{
				if ((cur_state == FALSE) && (cur_object >= 0))
					select_object(cur_wd, cur_object, 2);

				cur_wd = new_wd;
				cur_object = new_object;
				cur_state = new_state;

				if ((cur_object >= 0) && (cur_state == FALSE))
					select_object(cur_wd, cur_object, 3);
			}
			if (mreleased == FALSE)
				draw_icns(icnlist, nv, x, y, clip);
		}
		else if (mreleased == TRUE)
			draw_icns(icnlist, nv, x, y, clip);
	}
	while (mreleased == FALSE);

	graf_mouse(ARROW, NULL);
	wind_update(END_MCTRL);


	if ((cur_state == FALSE) && (cur_object >= 0))
		select_object(cur_wd, cur_object, 2);

	if ((cur_wd != src_wd) || (cur_object != src_object))
	{
		if (cur_wd != NULL)
		{
			int cur_type = xw_type(cur_wd);

			if ((cur_type == DIR_WIND) || (cur_type == DESK_WIND))
			{
				/* Test if destination window is the desktop and if the
				   destination object is -1 (no object). If this is true,
				   clip the mouse coordinates. */

				if ((xw_type(cur_wd) == DESK_WIND) && (cur_object == -1) && (xw_type(src_wd) == DESK_WIND))
					clip_coords(clip, x, y, &x, &y);

				itm_copy(src_wd, n, list, cur_wd, cur_object, kstate, icnlist, x, y);
			}
			else
				alert_printf(1, MILLCOPY);
		}
		else
#if _MINT_
		if (mint)
			itm_drop(src_wd, n, list, kstate, icnlist, x, y);		/* HR 050203 drag & drop */
		else
#endif
			alert_printf(1, MILLCOPY);
	}

	free(list);
	free(icnlist);
}
Пример #16
0
int gaze_control_trial(UINT32 time_limit)
{
	UINT32 trial_start;		/* trial start time (for timeout) */
	UINT32 drawing_time;	/* retrace-to-draw delay*/
	int button;				/* the button pressed (0 if timeout) */
	int error;				/* trial result code*/

	ALLF_DATA evt;			/* buffer to hold sample and event data*/
	int eye_used = -1;		/* indicates which eye's data to display*/
	int i;

	SDL_Surface *gbm;			/* The bitmap containing the stimulus display*/

	   /* This supplies the title at the bottom of the eyetracker display */
	eyecmd_printf("record_status_message 'GAZE CONTROL TRIAL' ");

	/*	
	Always send a TRIALID message before starting to record. 
	It should contain trial condition data required for analysis.
	*/
	eyemsg_printf("TRIALID CONTROL");

  /* TRIAL_VAR_DATA message is recorded for EyeLink Data Viewer analysis
	It specifies the list of trial variables value for the trial 
	This must be specified within the scope of an individual trial (i.e., after 
	"TRIALID" and before "TRIAL_RESULT") 
	*/
	eyemsg_printf("!V TRIAL_VAR_DATA GAZECTRL");
	/* 
	IMGLOAD command is recorded for EyeLink Data Viewer analysis
	It displays a default image on the overlay mode of the trial viewer screen. 
	Writes the image filename + path info
     */
	eyemsg_printf("!V IMGLOAD FILL images/grid.png");	

	/* 
	IAREA command is recorded for EyeLink Data Viewer analysis
	It creates a set of interest areas by reading the segment files
	Writes segmentation filename + path info
	*/
	eyemsg_printf("!V IAREA FILE segments/grid.ias"); 

	/* Before recording, we place reference graphics on the EyeLink display*/
	set_offline_mode();			/* Must be offline to draw to EyeLink screen*/
	gbm = draw_grid_to_bitmap_segment("grid.ias", "segments", 1);;/* Draw bitmap and EyeLink reference graphics*/
	segment_source = gbm;

	/* 
		Save bitmap and transfer to the tracker pc.
		Since it takes a long to save the bitmap to the file, the 
		value of sv_options should be set as SV_NOREPLACE to save time
	*/

	bitmap_save_and_backdrop(gbm, 0, 0, 0, 0, "grid.png", "images", SV_NOREPLACE,
				  0, 0, (UINT16)(BX_MAXCONTRAST|((eyelink_get_tracker_version(NULL)>=2)?0:BX_GRAYSCALE)));

	   /* DO PRE-TRIAL DRIFT CORRECTION */
	   /* We repeat if ESC key pressed to do setup. */
	while(1)
	{              /* Check link often so we can exit if tracker stopped*/
	  if(!eyelink_is_connected()) return ABORT_EXPT;
	   /* We let do_drift_correct() draw target in this example*/
	   /* 3rd argument would be 0 if we already drew the display*/
	  error = do_drift_correct((INT16)(SCRWIDTH/2), (INT16)(SCRHEIGHT/2), 1, 1);
		   /* repeat if ESC was pressed to access Setup menu */
	  if(error!=27) break;
	}

	clear_full_screen_window(target_background_color);  /* make sure display is blank*/

		/* Configure EyeLink to send fixation updates every 50 msec*/
	eyecmd_printf("link_event_filter = LEFT,RIGHT,FIXUPDATE");
	eyecmd_printf("fixation_update_interval = 50");
	eyecmd_printf("fixation_update_accumulate = 50");

	init_regions();	/* Initialize regions for this display*/

	/* 
		Start data recording to EDF file, BEFORE DISPLAYING STIMULUS 
		You should always start recording 50-100 msec before required
		otherwise you may lose a few msec of data 
	*/
	error = start_recording(1,1,0,1);   /* send events only through link*/
	if(error != 0)           /* ERROR: couldn't start recording*/
	{
	  SDL_FreeSurface(gbm);   /* Be sure to delete bitmap before exiting!*/
	  return error;        /* Return the error code*/
	}
							  /* record for 100 msec before displaying stimulus */
	begin_realtime_mode(100);   /* Windows 2000/XP: no interruptions from now on*/

	/* 
		DISPLAY OUR IMAGE TO SUBJECT  by copying bitmap to display
		Because of faster drawing speeds and good refresh locking,
		we now place the stimulus onset message just after display refresh 
		and before drawing the stimulus.  This is accurate and will allow 
		drawing a new stimulus each display refresh.
	 
		However, we do NOT send the message after the retrace--this may take too long
		instead, we add a number to the message that represents the delay 
		from the event to the message in msec
	*/


	/* COPY BITMAP to display*/
	SDL_BlitSurface(gbm, NULL, window,NULL);
	Flip(window);
	drawing_time = current_msec();                   /* time of retrace*/
	trial_start = drawing_time;
	SDL_BlitSurface(gbm, NULL, window,NULL);
	



	/* delay from retrace (time to draw)*/
	drawing_time = current_msec()-drawing_time;    
	/* message for RT recording in analysis */
	eyemsg_printf("%d DISPLAY ON", drawing_time);
	/* message marks zero-plot time for EDFVIEW */
	eyemsg_printf("SYNCTIME %d", drawing_time);	 

	

	/* Print a title for the trial (for demo only)*/
	get_new_font("Times Roman", 24, 1);     
	graphic_printf(window,target_foreground_color, NONE, SCRWIDTH/2, 24, "Gaze Control Trial");
	

	if(!eyelink_wait_for_block_start(100, 0, 1))  /* wait for link event data*/
	{
	  end_trial();
	  alert_printf("ERROR: No link events received!");
	  return TRIAL_ERROR;
	}
	eye_used = eyelink_eye_available(); /* determine which eye(s) are available*/ 
	switch(eye_used)		      /* select eye, add annotation to EDF file	*/
	{			
	  case RIGHT_EYE:
		eyemsg_printf("EYE_USED 1 RIGHT");
		break;
	  case BINOCULAR:           /* both eye's data present: use left eye only*/
		eye_used = LEFT_EYE;
	  case LEFT_EYE:
		eyemsg_printf("EYE_USED 0 LEFT");
		break;
	}
								 
	/* Now get ready for trial loop*/
	eyelink_flush_keybuttons(0);   /* reset keys and buttons from tracker */

	/* 
		we don't use getkey() especially in a time-critical trial
		as Windows may interrupt us and cause an unpredicatable delay
		so we would use buttons or tracker keys only  
		Trial loop: till timeout or response -- added code for processing
		FIXUPDATE events
	*/
	while(1) 
	{ 
		/* First, check if recording aborted */
	  if((error=check_recording())!=0) return error;  
								 
	  /* Check if trial time limit expired*/
	  if(current_time() > trial_start+time_limit)
		{
			eyemsg_printf("TIMEOUT");    /* message to log the timeout */
			end_trial();                 /* local function to stop recording*/
			button = 0;                  /* trial result message is 0 if timeout */
			break;                       /* exit trial loop*/
		}

	  if(break_pressed())     /* check for program termination or ALT-F4 or CTRL-C keys*/
		{
			end_trial();         /* local function to stop recording*/
			return ABORT_EXPT;   /* return this code to terminate experiment*/
		}

	  /* check for local ESC key to abort trial (useful in debugging)   */
	  if(escape_pressed())    
		 {
			end_trial();         /* local function to stop recording*/
			return SKIP_TRIAL;   /* return this code if trial terminated*/
		 }

		/* BUTTON RESPONSE TEST */
		/* Check for eye-tracker buttons pressed
		/* This is the preferred way to get response data or end trials	*/
	  button = eyelink_last_button_press(NULL);
	  if(button!=0)       /* button number, or 0 if none pressed*/
		{
		  /* message to log the button press*/
			eyemsg_printf("ENDBUTTON %d", button);  
			/* local function to stop recording*/
			end_trial();                            
			break; /* exit trial loop*/
		}

		/* GET FIXUPDATE EVENTS, PROCESS*/

		i = eyelink_get_next_data(NULL);    /* Check for data from link*/
		if(i == FIXUPDATE)	  /* only process FIXUPDATE events*/
		{
			/* get a copy of the FIXUPDATE event */
			eyelink_get_float_data(&evt);  
			/* only process if it's from the desired eye?*/
			if(evt.fe.eye == eye_used)	   
			{   
				/* get average position and duration of the update */
				process_fixupdate((int)(evt.fe.gavx), (int)(evt.fe.gavy),/* Process event */
	       			 evt.fe.entime-evt.fe.sttime);
			}
		}
	}/* end of loop*/
	/* report response result: 0=timeout, else button number*/
	eyemsg_printf("TRIAL_RESULT %d", button);
		/* Call this at the end of the trial, to handle special conditions*/
	SDL_FreeSurface(gbm);
	segment_source = NULL;
	return check_record_exit();
}
Пример #17
0
static void hndlmenu(int title, int item, int kstate)
{
	int qbutton; /* DjV 013 291202 */

	if ((menu[item].ob_state & DISABLED) == 0)
	{
		switch (item)
		{
		case MINFO:
			info();
			break;
		case MQUIT:
			/* DjV 013 291202 ---vvv--- */
			qbutton = alert_printf(3,QUITALRT); /* DjV 013 090203  shutdown revived */
			switch (qbutton)
			{
				case 3:
					break;
				case 2:
					shutdown=TRUE; /* no effect yet */
					/* break;DjV 013 090203 only without shutdown */
				case 1:      
			/* DjV 013 291202 ---^^^--- */
					menu_tnormal(menu, title, 1);
					quit = TRUE;
					break;
			}        /* DjV 013 291202 */
			break;
		case MOPTIONS:
			setpreferences();
			break;
		case MPRGOPT:
			prg_setprefs();
			break;
		case MSAVESET:
			save_options();
			break;
		case MLOADOPT:
			load_settings();
			break;
		case MSAVEAS:
			save_options_as();
			break;
		case MAPPLIK:
			app_install();
			break;
		case MIDSKICN:
			dsk_insticon();
			break;
		case MIWDICN:
			icnt_settypes();
			break;
		case MCHNGICN:
			dsk_chngicon();
			break;
		case MREMICON:
			dsk_remicon();
			break;
		case MEDITOR:
			set_editor();
			break;
		/* DjV 016 050103 ---vvv--- */	
		case MCOPTS:
			copyprefs();
			break;
		/* DjV 016 050103 ---^^^--- */
		case MWDOPT:
			dsk_options();
			break;
		/* DjV 007 250102 ---vvv--- */	
		case MVOPTS:
			chrez=voptions();
			if ( chrez ) quit=TRUE;
			break;
		/* DjV 007 250102 ---^^^--- */
		default:
			wd_hndlmenu(item, kstate);	/* handle all the rest in window.c */
			break;
		}
	}
	menu_tnormal(menu, title, 1);
}
Пример #18
0
int app_main(char * trackerip, DISPLAYINFO * disp)
{
  UINT16 i, j;
  char our_file_name[260] = "TEST";
  char verstr[50];
  int eyelink_ver = 0;
  int tracker_software_ver = 0;
  
  if(trackerip)
		set_eyelink_address(trackerip);
  if(open_eyelink_connection(0)) return -1;    /* abort if we can't open link */
  set_offline_mode();
  flush_getkey_queue();                        /* initialize getkey() system */

  eyelink_ver = eyelink_get_tracker_version(verstr);
  if (eyelink_ver == 3)
	  tracker_software_ver = get_tracker_sw_version(verstr);



  if(init_expt_graphics(NULL, disp))
	  goto shutdown;   /* register window with EXPTSPPT */


  window = SDL_GetVideoSurface();
  get_display_information(&dispinfo);          /* get window size, characteristics */

    /*
		NOTE: Camera display does not support 16-color modes
		NOTE: Picture display examples don't work well with 256-color modes
		However, all other sample programs should work well.
	*/

  if(dispinfo.palsize)     /* 256-color modes: palettes not supported by this example */
      alert_printf("This program is not optimized for 256-color displays");


 

  
  i = SCRWIDTH/60;		  /* select best size for calibration target */
  j = SCRWIDTH/300;       /* and focal spot in target */
  if(j < 2) j = 2;
  set_target_size(i, j);  /* tell DLL the size of target features */


  /* color of calibration target */
  SETCOLOR(target_foreground_color, 0,0,0);
  /* background for calibration and drift correction */
  SETCOLOR(target_background_color, 128,128,128);
  /* tell EXPTSPPT the colors */
  set_calibration_colors(&target_foreground_color, &target_background_color);

  set_cal_sounds("", "", "");
  set_dcorr_sounds("", "off", "off");

  /* draw a title screen */
  clear_full_screen_window(target_background_color);    /* clear screen */
  get_new_font("Times Roman", SCRHEIGHT/32, 1);         /* select a font */
                                                        /* Draw text */
  graphic_printf(window, target_foreground_color,  CENTER, SCRWIDTH/2, 1*SCRHEIGHT/30,
                 "EyeLink Demonstration Experiment: Communicate with Listener");
  graphic_printf(window, target_foreground_color,  CENTER, SCRWIDTH/2, 2*SCRHEIGHT/30,
                 "Included with the Experiment Programming Kit for Windows");
  graphic_printf(window, target_foreground_color,  CENTER, SCRWIDTH/2, 3*SCRHEIGHT/30,
                 "All code is Copyright (c) 1997-2002 SR Research Ltd.");
  graphic_printf(window, target_foreground_color,  CENTER, SCRWIDTH/5, 4*SCRHEIGHT/30,
                 "Source code may be used as template for your experiments.");
  SDL_Flip(window);

  eyelink_set_name("comm_simple");  /* NEW: set our network name */

  if(check_for_listener())   /* check for COMM_LISTENER application */
    {
      alert_printf("Could not communicate with COMM_LISTENER application.");
      goto shutdown;
    }

  if(i==1)  our_file_name[0] = 0;   /* Cancelled: No file name */
  if(our_file_name[0])    /* If file name set, open it */
    {
      if(!strstr(our_file_name, ".")) strcat(our_file_name, ".EDF");  /* add extension   */
      i = open_data_file(our_file_name);                              /* open file       */
      if(i!=0)                                                        /* check for error */
        {
          alert_printf("Cannot create EDF file '%s'", our_file_name);
          goto shutdown;
        }
	  /* add title to preamble */
      eyecmd_printf("add_file_preamble_text 'RECORDED BY %s' ", program_name);
    }
  /*
		SET UP TRACKER CONFIGURATION
		NOTE: set contents before sending messages!
		set EDF file contents
  */
   if(eyelink_ver>=2)
    {
      eyecmd_printf("select_parser_configuration 0");  // 0 = standard sensitivity
	  if(eyelink_ver == 2) //turn off scenelink camera stuff
	  {
		eyecmd_printf("scene_camera_gazemap = NO");
	  }
    }
  else
    {
      eyecmd_printf("saccade_velocity_threshold = 35");
      eyecmd_printf("saccade_acceleration_threshold = 9500");
    }
  // NOTE: set contents before sending messages!
		     // set EDF file contents 
  eyecmd_printf("file_event_filter = LEFT,RIGHT,FIXATION,SACCADE,BLINK,MESSAGE,BUTTON");
  eyecmd_printf("file_sample_data  = LEFT,RIGHT,GAZE,AREA,GAZERES,STATUS%s",(tracker_software_ver>=4)?",HTARGET":"");
		      // set link data (used for gaze cursor) 
  eyecmd_printf("link_event_filter = LEFT,RIGHT,FIXATION,SACCADE,BLINK,BUTTON");
  eyecmd_printf("link_sample_data  = LEFT,RIGHT,GAZE,GAZERES,AREA,STATUS%s",(tracker_software_ver>=4)?",HTARGET":"");

  /* NEW: Allow EyeLink I (v2.1+) to echo messages back to listener */
  eyecmd_printf("link_nonrecord_events = BUTTONS, MESSAGES");

  /* Program button #5 for use in drift correction */
  eyecmd_printf("button_function 5 'accept_target_fixation'");

  /* Now configure tracker for display resolution */
  eyecmd_printf("screen_pixel_coords = %ld %ld %ld %ld",    /* Set display resolution */
                 dispinfo.left, dispinfo.top, dispinfo.right, dispinfo.bottom);
  eyecmd_printf("calibration_type = HV9");       /* Setup calibration type */
  eyemsg_printf("DISPLAY_COORDS %ld %ld %ld %ld",/* Add resolution to EDF file */
                 dispinfo.left, dispinfo.top, dispinfo.right, dispinfo.bottom);
  if(dispinfo.refresh>40)
    eyemsg_printf("FRAMERATE %1.2f Hz.", dispinfo.refresh);

  

  /* make sure we're still alive */
  if(!eyelink_is_connected() || break_pressed()) goto end_expt;

  /*
	 RUN THE EXPERIMENTAL TRIALS (code depends on type of experiment)
     Calling run_trials() performs a calibration followed by trials
     This is equivalent to one block of an experiment
     It will return ABORT_EXPT if the program should exit
   */
  i = run_trials();

end_expt:                /* END: close, transfer EDF file */
  set_offline_mode();    /* set offline mode so we can transfer file */
  pump_delay(500);       /* delay so tracker is ready */
  eyecmd_printf("close_data_file"); /* close data file */

  if(break_pressed()) goto shutdown;/* don't get file if we aborted experiment */
  if(our_file_name[0])              /* make sure we created a file */
    receive_data_file(our_file_name, "", 0);  /* transfer the file, ask for a local name */

shutdown:                /* CLEANUP */
  close_expt_graphics();           /* tell EXPTSPPT to release window */
  close_eyelink_connection();      /* disconnect from tracker */
  return 0;
}
Пример #19
0
int main(void)
{
	int error;

#if _MINT_				/* HR 151102 */
	have_ssystem = Ssystem(-1, 0, 0) == 0;		/* HR 151102: use Ssystem where possible */

	mint   = (find_cookie('MiNT') == -1) ? FALSE : TRUE;
	magx   = (find_cookie('MagX') == -1) ? FALSE : TRUE;	/* HR 151102 */
	geneva = (find_cookie('Gnva') == -1) ? FALSE : TRUE;    /* DjV 035 080203 */
	mint  |= magx;			/* Quick & dirty */

	if (mint)
	{
		Psigsetmask(0x7FFFE14EL);
		Pdomain(1);
	}
#endif

	x_init();

	if ((ap_id = appl_init()) < 0)
		return -1;

	if  (_GemParBlk.glob.version >= 0x400)
	{
		shel_write(9, 1, 0, NULL, NULL);
		menu_register(ap_id, "  Tera Desktop");
	}

	if (rsrc_load(RSRCNAME) == 0)
		form_alert(1, msg_resnfnd);
	else
	{
		if ((error = init_xdialog(&vdi_handle, malloc, free,
								  "Tera Desktop", 1, &nfonts)) < 0)
			xform_error(error);
		else
		{
			init_vdi();
			rsc_init();

			if (((max_w / screen_info.fnt_w) < 40) || ((max_h / screen_info.fnt_h) < 25))
				alert_printf(1, MRESTLOW);
			else
			{
				if ((error = alloc_global_memory()) == 0)
				{
					if (exec_deskbat() == FALSE)
					{
						if (load_icons() == FALSE)
						{
							if (init() == FALSE)
							{
								graf_mouse(ARROW, NULL);
								evntloop();

								wd_del_all();
								menu_bar(menu, 0);
								xw_close_desk();
							}

							free_icons();		/* HR 151102 */

							wind_set(0, WF_NEWDESK, NULL, 0);
							dsk_draw();
						}
					}

					Mfree(global_memory);
				}
				else
					xform_error(error);
			}

			if (vq_gdos() != 0)
				vst_unload_fonts(vdi_handle, 0);
			exit_xdialog();
		}

		rsrc_free();
	}

	/* DjV 013 030103 100203 ---vvv--- */
	/*
	 * The following section handles system shutdown and resolution change
	 * If a resolution change is required, shutdown is performed first
	 * If only shutdown s required, system will reset at the end.
	 */ 

	/* appl_exit(); */

	if ( chrez || shutdown ) /* If change resolution or shutdown ... */
	{

		/* Tell all applications which would understand it to end */

		quit = shel_write ( 4, 2, 0, NULL, NULL ); 	/* complete shutdown */
		evnt_timer( 3000, 0 );						/* Wait a bit? */

		/*

		/* 
		 * In Mint, must tell all proceseses to terminate nicely ?
		 * but this is only in this group ? What to do?
		 */

		Pkill(0, SIGTERM); 
		evnt_timer(3000, 0); /* Wait a bit? */
		*/

		/* 
		 * After all applications have hopefully been closed,
		 * change the screen resolution if needed;
		 * else- reset the computer
		 */
		if ( chrez )
			get_set_video(2);

#if 1
		else
	#if _MINT_
		if (!mint)			/* HR 230203: Dont reset under MiNT or MagiC !!!!! */
	#endif
		{
			/* Perform a reset here */

	#if 0		/* with warnings */
			long *m;					/* to memory locations */
			long rv;					/* reset vector */

			Super ( 0L );				/* Supervisor; old stack won't be needed again */
			*(m = 0x420L) = 0L;			/* memctrl  */
			*(m = 0x43aL) = 0L;			/* memval2  */
			*(m = 0x426L) = 0L;			/* resvalid */	
			m = *( m = 0x4f2 );			/* to start of OS */
			rv = *(m + 4);				/* to routine that  handles the reset */
			Supexec(rv);				/* execute it */
	#else			/* HR: without warnings */
			long (*rv)();					/* reset vector */

			Super ( 0L );				/* Supervisor; old stack won't be needed again */
			memctrl = 0L;
			memval2 = 0L;
			resvalid = 0L;
			(long)rv = *((long *)os_start + 4);	/* routine that handles the reset */
			Supexec(rv);				/* execute it */
	#endif
		}
#endif
	}