Beispiel #1
0
void imagesc(void *data, int x, int y, const char* type,
             double (*transf)(double), const char **colormap, char *title)
{
  static XtAppContext context;
  Widget drawing_area;
  Widget toplevel;
  Atom wm_delete;
  XEvent event;
  XpmImage *xpmImage;
  Boolean exitFlag = False;
  static Display *display = NULL;
  Arg al[10];
  int ac;
  int argc = 0;

  xpmImage = CreateXpmImage(data, x, y, type, transf, colormap);

  /* create the toplevel shell */
  XtToolkitInitialize();
  if (display == NULL) {
    context = XtCreateApplicationContext();
    display = XtOpenDisplay(context, NULL, NULL, "", NULL, 0, &argc, NULL);
  }
  toplevel =XtAppCreateShell(title, "", applicationShellWidgetClass, display, NULL, 0);

  /* set window size. */
  ac=0;
  XtSetArg(al[ac],XmNmaxWidth,  x); ac++;
  XtSetArg(al[ac],XmNmaxHeight, y); ac++;
  XtSetArg(al[ac],XmNminWidth,  x); ac++;
  XtSetArg(al[ac],XmNminHeight, y); ac++;
  XtSetArg(al[ac],XmNdeleteResponse, XmDO_NOTHING); ac++;
  XtSetValues(toplevel,al,ac);

  ac=0;
  drawing_area=XmCreateDrawingArea(toplevel,"drawing_area",al,ac);
  XtManageChild(drawing_area);
  XtAddCallback(drawing_area,XmNexposeCallback,draw_pixmap,(XtPointer) xpmImage);
  XtAddEventHandler(drawing_area, KeyReleaseMask, false, KeyAction, (XtPointer) &exitFlag);
  XtRealizeWidget(toplevel);
  wm_delete = XInternAtom(XtDisplay(toplevel), "WM_DELETE_WINDOW", False);
  XmAddWMProtocolCallback(toplevel, wm_delete, quitCB, (XtPointer) &exitFlag);
  XmActivateWMProtocol(toplevel, wm_delete);

  while (!exitFlag) {
    XtAppNextEvent(context, &event);
    XtDispatchEvent(&event);
  }

  XtDestroyWidget(drawing_area);
  XtDestroyWidget(toplevel);
  free(xpmImage);
}
Beispiel #2
0
/* callback for palette-change choice */
void pal_ch_cb(FL_OBJECT *a, long l)
{
  const char *ch;
  char **current_xpm;

  ch = fl_get_choice_text( a );
  
  /* copy the RGB selected by the user to the "current" RGB. */

  if( !strcmp(ch,PAL_DOOM) )
    CopyRGB( DAC_Reg, doom_rgb);
  
  else if( !strcmp(ch,PAL_HERETIC) )
    CopyRGB( DAC_Reg, heretic_rgb);

  else if( !strcmp(ch,PAL_E_HERETIC) )
    CopyRGB( DAC_Reg, E_HERETIC_rgb);

  else if( !strcmp(ch,PAL_HEXEN) )
    CopyRGB( DAC_Reg, hexen_rgb);
  
  else if( !strcmp(ch,PAL_STRIFE) )
    CopyRGB( DAC_Reg, strife_rgb);
  
  else if( !strcmp(ch, PAL_USER) && USER_rgb )
    CopyRGB( DAC_Reg, USER_rgb);

  else  /* this should not happen */
    Abort("unknown palette type!\n");

  CreateXpmPalette( DAC_Reg, keep_transparent_color );

  /* redraw current image */
  if ( ( current_xpm = CreateXpmImage( 0, 0, 0, 1, NULL)) ) {
    fl_free_pixmap_pixmap( img_pxm );
    fl_set_pixmap_data( img_pxm, current_xpm );
  } 
}
Beispiel #3
0
/* export_cb : Export Callback
   Export to file the entry highlighted in the browser. */
void export_cb(FL_OBJECT *a, long l)
{
  Int4 index;
  int RetVal;
  unsigned char *pImgBuf;
  short Width;
  short Height;
  const char *format;

  RetVal = fl_get_browser(wad_brow);
  if ( RetVal == 1 )           /* first line is the legend */
    return;
  index = LinearMap[RetVal];
  
  switch (pEntryTag[index])
    {
    case TAG_MUS  : 
      GenFileName(pDirEnt[index].name, ".mus", TmpNameStr);
      RetVal = Gen_MUS_File(WADfp, pDirEnt[index], TmpNameStr);
      break;
    case TAG_SFX  :
      GenFileName(pDirEnt[index].name, ".wav", TmpNameStr);
      RetVal = Gen_WAV_File(WADfp, pDirEnt[index], TmpNameStr);
      break;
    case TAG_FLAT :
    case TAG_FULL :
    case TAG_IMG  :
      pImgBuf = ParseImgBlock(pDirEnt[index], pEntryTag[index], 
			      &Width, &Height, NULL, NULL, WADfp);
      if (pImgBuf == NULL) {
	RetVal = 4;
	break;
      }
      format = fl_get_choice_text( exp_img_fmt_cho );
      if ( !strcmp(format, PCX_STR ) ) {           /* pcx */
	GenFileName(pDirEnt[index].name, ".pcx", TmpNameStr);
	RetVal = PCX_WriteImage(pDirEnt[index], WADfp, Width, Height, 
				pImgBuf, 1, TmpNameStr);
      }
      else {  /* xpm */
	char **xpm;
	GenFileName(pDirEnt[index].name, ".xpm", TmpNameStr);
	/* don't just redraw, we don't know what's in the xpm: */
	xpm = CreateXpmImage( pImgBuf, Width, Height, 0, NULL ); 
	if ( xpm && CreateXpmFile( xpm, TmpNameStr ) ) 
	  RetVal = 0;
	else
	  RetVal = 666; /* why not? */
      }
      break;
    case TAG_HIRES:
      GenFileName(pDirEnt[index].name, ".pcx", TmpNameStr);
      RetVal = PCX_WriteImage(pDirEnt[index], WADfp, 640, 480, 
			      pBitMap, 4, TmpNameStr);
      break;
    default:
      RetVal = 1;
      break;
    }
  
  if (RetVal != 0) {
    Beep();
    Message("error generating external file \"%s\" (%d)\n", 
	   TmpNameStr, RetVal);
  }
  else
    Message("External file \"%s\" created OK\n", TmpNameStr); 
}
Beispiel #4
0
/* Handle the entry internally. Make an image or play the sound.... */
static void HandleInternal( Int4 index )
{
  unsigned char *sndbuf;
  unsigned char *pImgBuf ;
  char **xpmbuf=NULL;
  static char imagetext[50];
  int nc;
  unsigned short samplerate;

  /* Sound sample size: The specs says a short here, with the next
     short empty.  But some entries are (32 bits) ints, and the game
     engine accepts it.  Examples include entries 164--171 (and many
     more) in strife0.wad (shareware v. 1.1), and #50 in the "Clint
     Eastwood DOOM (II?) sfx" pwad.... */
  Uint4 nsamples;
  short w, h, dx, dy;
  
  switch ( pEntryTag[index] )
    {
    case TAG_SFX  : 
      /* Read sound header */
      fseek( WADfp, pDirEnt[index].start + 2, SEEK_SET );
      fread( &samplerate, sizeof(short), 1, WADfp );
      fread( &nsamples, sizeof(Uint4), 1, WADfp );
      if ( nsamples != pDirEnt[index].size - 8)
	Message("Warning, sample size = %d, while Directory size = %d.\n",
		nsamples, pDirEnt[index].size); 
      sndbuf = malloc( nsamples );
      if ( !sndbuf ) {
	Message("can't malloc data for snd buf (%d bytes)\n",nsamples);
	return;
      }
      /* read the samples */
      fread( sndbuf, 1, nsamples, WADfp );
      if ( fl_get_button(rev_but) )            	/* reverse ! */
	ReverseBuffer( sndbuf, nsamples );
      PlayRaw( sndbuf, nsamples, samplerate );
      free( sndbuf );
      break;
    case TAG_FLAT :
    case TAG_FULL :
    case TAG_IMG  : 
      pImgBuf = ParseImgBlock(pDirEnt[index], pEntryTag[index], 
			      &w, &h, &dx, &dy, WADfp);
      /* I planned to use the offsets (dx,dy) for better placement of
	 the image, but I need to find out some useful heuristics
	 for how to do it..... 
	 printf("image: %dx%d, ofs left %d, top %d\n",w,h,dx,dy);
	 */
      if ( pImgBuf && w <= 320 && h <= 200 && 
	   (xpmbuf = CreateXpmImage( pImgBuf, w, h, 0, &nc)) ) {
	fl_free_pixmap_pixmap( img_pxm );
	fl_set_pixmap_data( img_pxm, xpmbuf );
	sprintf(imagetext,"#%d, %dx%d, %d colours",index,w,h,nc);
	fl_set_object_label(img_txt, imagetext);
      }
      else {
	Message("error creating image. (%p, %hdx%hd, %p)\n", 
		pImgBuf, w, h, xpmbuf);
	return;
      }
      break;
    default : Message("entry %d, Not implemented\n",index); break;
    }
}