static GtkWidget * create_window (void) { const char * const names[AUD_EQUALIZER_NBANDS] = {N_("31 Hz"), N_("63 Hz"), N_("125 Hz"), N_("250 Hz"), N_("500 Hz"), N_("1 kHz"), N_("2 kHz"), N_("4 kHz"), N_("8 kHz"), N_("16 kHz")}; GtkWidget * window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_title ((GtkWindow *) window, _("Equalizer")); gtk_window_set_type_hint ((GtkWindow *) window, GDK_WINDOW_TYPE_HINT_DIALOG); gtk_window_set_resizable ((GtkWindow *) window, FALSE); gtk_container_set_border_width ((GtkContainer *) window, 6); audgui_destroy_on_escape (window); GtkWidget * vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6); gtk_container_add ((GtkContainer *) window, vbox); gtk_box_pack_start ((GtkBox *) vbox, create_on_off (), FALSE, FALSE, 0); GtkWidget * hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6); gtk_box_pack_start ((GtkBox *) vbox, hbox, FALSE, FALSE, 0); GtkWidget * preamp = create_slider (_("Preamp"), -1, hbox); g_object_set_data ((GObject *) window, "preamp", preamp); gtk_box_pack_start ((GtkBox *) hbox, gtk_separator_new (GTK_ORIENTATION_VERTICAL), FALSE, FALSE, 0); for (int i = 0; i < AUD_EQUALIZER_NBANDS; i ++) { GtkWidget * slider = create_slider (_(names[i]), i, hbox); SPRINTF (slider_id, "slider%d", i); g_object_set_data ((GObject *) window, slider_id, slider); } update_sliders (NULL, window); hook_associate ("set equalizer_preamp", (HookFunction) update_sliders, window); hook_associate ("set equalizer_bands", (HookFunction) update_sliders, window); g_signal_connect (window, "destroy", (GCallback) destroy_cb, NULL); return window; }
/*-------------------------- zoom ---------------------------------*/ int zoom(caddr_t data) { int w, h, up; up = *((int *) data); if (up) { w = zWidth*2; h = zHeight*2; } else { w = zWidth/2; h = zHeight/2; } Resize(w,h); XResizeWindow(theDisp,mainW, w+(color_bar?color_bar_width:0), h+info_height); Window_Level(Lower,Upper); update_sliders(); update_msgs(); }
/*----------------------- Reorient_Volume -------------------------------*/ int Reorient_Volume() { int i, old_h, old_w, old_i, num_volumes; short *volume; int vol_step; /* check that we have a volume */ if ((num_images==1)||(!load_all_images)) { fprintf(stderr,"Only one image found!\n"); return; } /* define new cursors */ XDefineCursor(theDisp,mainW,waitCursor); XDefineCursor(theDisp,cmdW,waitCursor); XFlush(theDisp); if (Verbose) fprintf(stderr,"Volume reorientation in progress...\n"); /* perform the reorientation */ num_volumes = 1; for(i=0; i<ndimensions-3; i++){ num_volumes *= slider_length[i]; } vol_step = Width*Height*slider_length[ndimensions-3]; for(i=0; i<num_volumes; i++){ fprintf(stderr,"Reorienting volume: %d\r", i); volume = &(short_Image[i*vol_step]); _Reorient_Volume(volume, slider_length[ndimensions-3], Width, Height); } /* resize the color bar */ Resize_ColorBar(color_bar_width,slider_length[ndimensions-3]); /* swap the width, height, and num_images variables */ old_h=Height; old_w=Width; old_i=slider_length[ndimensions-3]; zHeight=Height=old_i; zWidth=Width=old_h; slider_length[ndimensions-3]=old_w; num_images=old_w*num_volumes; theImage->width = theImage->bytes_per_line = zWidth; theImage->height = zHeight; /* Scale Image and Resize if necessary */ Scale_Image(P_Min,P_Max); image_number=num_images/2; Resize(Width,Height); XResizeWindow(theDisp,mainW, Width+(color_bar?color_bar_width:0), Height+info_height); /* redraw image and clean up */ DrawWindow(0,0,Width,Height); update_msgs(); update_sliders(); /* don't bother attempting to keep track of rotations */ RW_valid = False; /* define new cursors */ XDefineCursor(theDisp,mainW,mainCursor); XDefineCursor(theDisp,cmdW,cmdCursor); XFlush(theDisp); }
/*---------------------------- Crop ------------------------------*/ int Crop(caddr_t data) { int i, j, index, im, im_index, w, h, x1, x2, y1, y2; /* check that an roi is defined */ if (roi_present != 1) { fprintf(stderr,"An ROI must be drawn before cropping\n"); return; } /* define new cursors */ XDefineCursor(theDisp,mainW,waitCursor); XDefineCursor(theDisp,cmdW,waitCursor); XFlush(theDisp); fprintf(stderr,"Cropping image at (%d,%d) to (%d,%d)\n", roi_x1,roi_y1,roi_x2,roi_y2); /* get roi corners in original image coordinates */ if (roi_x2 < roi_x1) { i = roi_x1; roi_x1 = roi_x2; roi_x2 = i; } if (roi_y2 < roi_y1) { i = roi_y1; roi_y1 = roi_y2; roi_y2 = i; } x1 = roi_x1*(Width-1)/(zWidth-1); x2 = roi_x2*(Width-1)/(zWidth-1); y1 = roi_y1*(Height-1)/(zHeight-1); y2 = roi_y2*(Height-1)/(zHeight-1); crop_x = crop_x + x1; crop_y = crop_y + y1; /* perform cropping in-place */ index=0; for (im=0; im<(load_all_images?num_images:1); im++) { if ((num_images>1)&&load_all_images) fprintf(stderr,"Cropping short image %d\r",im); im_index=Width*Height*im; for (j=y1; j<=y2; j++) { for (i=x1; i<=x2; i++, index++) { short_Image[index]=short_Image[j*Width+i+im_index]; } } } if ((num_images>1)&&load_all_images) fprintf(stderr," \r"); index=0; for (im=0; im<(load_all_images?num_images:1); im++) { if ((num_images>1)&&load_all_images) fprintf(stderr,"Cropping X image %d\r",im); im_index=(bitmap_pad/8)*zWidth*zHeight*im; if (bitmap_pad==8) { for (j=roi_y1; j<=roi_y2; j++) { for (i=roi_x1; i<=roi_x2; i++) { byte_Image[index++]=byte_Image[j*zWidth+i+im_index]; } } } else { for (j=roi_y1; j<=roi_y2; j++) { for (i=roi_x1; i<=roi_x2; i++) { byte_Image[index++]=byte_Image[j*zWidth*4+i*4+im_index]; byte_Image[index++]=byte_Image[j*zWidth*4+i*4+im_index+1]; byte_Image[index++]=byte_Image[j*zWidth*4+i*4+im_index+2]; byte_Image[index++]=byte_Image[j*zWidth*4+i*4+im_index+3]; } } } } if ((num_images>1)&&load_all_images) fprintf(stderr," \r"); /* resize the color bar */ Resize_ColorBar(color_bar_width,abs(roi_y2-roi_y1)+1); /* define new image dimensions */ zWidth = theImage->width = abs(roi_x2 - roi_x1) + 1; theImage->bytes_per_line = (bitmap_pad/8)* (abs(roi_x2 - roi_x1) + 1); zHeight = theImage->height = abs(roi_y2 - roi_y1) + 1; theImage->data = &byte_Image[(bitmap_pad/8)*zWidth*zHeight* (load_all_images?image_number:0)]; Width = abs(x2 - x1) + 1; Height = abs(y2 - y1) + 1; /* resize window and image */ XResizeWindow(theDisp,mainW, zWidth+(color_bar?color_bar_width:0), zHeight+info_height); DrawWindow(0,0,zWidth,zHeight); /* reset window/level step size */ cropped = True; RW_valid = False; steps=((P_Max-P_Min)/(2*zWidth)>=1) ? (P_Max-P_Min)/(2*zWidth): 1; update_msgs(); update_sliders(); /* define new cursors */ XDefineCursor(theDisp,mainW,mainCursor); XDefineCursor(theDisp,cmdW,cmdCursor); XFlush(theDisp); }
/*---------------------------- HandleEvent --------------------------*/ int HandleEvent(XEvent *event) { int i; if(theEvent.xany.window==mainW) { switch (event->type) { case Expose: { XExposeEvent *exp_event = (XExposeEvent *) event; if (exp_event->window==mainW) { DrawWindow(exp_event->x,exp_event->y, exp_event->width, exp_event->height); } } break; case EnterNotify: { if (Selected_Visual_Class==DirectColor) XStoreColors(theDisp,NewCmap,newC,ColorMapSize); if (Selected_Visual_Class!=TrueColor) XInstallColormap(theDisp,NewCmap); } break; case LeaveNotify: { if (Selected_Visual_Class==DirectColor) XStoreColors(theDisp,NewCmap,rootC,ColorMapSize); } break; case KeyPress: { /* allow a quit from the image window */ Handle_KeyPress(event); } break; case MotionNotify: { Handle_Motion(event); } break; case ConfigureNotify: { XConfigureEvent *conf_event = (XConfigureEvent *) event; if (conf_event->window == cmdW && (conf_event->width != cmd_width || conf_event->height != cmd_height)) XResizeWindow(theDisp,cmdW,cmd_width,cmd_height); if (conf_event->window == mainW && (conf_event->width != zWidth+(color_bar?color_bar_width:0) || conf_event->height != zHeight+info_height)) Resize(conf_event->width-(color_bar?color_bar_width:0), conf_event->height-info_height); } break; case ButtonPress: { if (theEvent.xbutton.button==Button1) { if (selzoom_active) { Selective_Zoom((caddr_t)&one); break; } XDefineCursor(theDisp,mainW,roiCursor); XFlush(theDisp); if (roi_present) draw_roi(roi_x1, roi_y1, roi_x2, roi_y2); roi_active = 1; roi_x1 = theEvent.xmotion.x < zWidth ? (theEvent.xmotion.x>0 ? theEvent.xmotion.x : 0) : zWidth-1; roi_y1 = theEvent.xmotion.y < zHeight ? (theEvent.xmotion.y>0 ? theEvent.xmotion.y : 0) : zHeight-1; roi_x2 = roi_x1; roi_y2 = roi_y1; draw_roi(roi_x1, roi_y1, roi_x2, roi_y2); break; } if (theEvent.xbutton.button==Button2) { XDefineCursor(theDisp,mainW,wlCursor); XClearArea(theDisp,mainW,0,zHeight, zWidth,zHeight+info_height,False); XDrawImageString(theDisp,mainW,theMGC, zWidth-XTextWidth(ol_text_finfo, wl_msg,strlen(wl_msg))-4, zHeight+info_height-4,wl_msg,strlen(wl_msg)); XDrawImageString(theDisp,mainW,theMGC,4, zHeight+info_height-4,loc_msg,strlen(loc_msg)); XFlush(theDisp); break; } if (theEvent.xbutton.button==Button3) { /* note: not really 'iconic' anymore, simply map or unmap */ if (cmdW_State==NormalState) { XUnmapWindow(theDisp,cmdW); cmdW_State = IconicState; } else { XMapWindow(theDisp,cmdW); cmdW_State = NormalState; } break; } } break; case ButtonRelease: { int xa, xb, ya, yb; if (theEvent.xbutton.button==Button1 && roi_active) { roi_active = 0; xa = roi_x1*(Width-1)/(zWidth-1); xb = roi_x2*(Width-1)/(zWidth-1); ya = roi_y1*(Height-1)/(zHeight-1); yb = roi_y2*(Height-1)/(zHeight-1); roi_stats(xa, ya, xb, yb, 0); XDefineCursor(theDisp,mainW,mainCursor); XFlush(theDisp); } if (theEvent.xbutton.button==Button2) { XDefineCursor(theDisp,mainW,mainCursor); XFlush(theDisp); if (Scale_Data && (oUpper != Upper || oLower != Lower)) { Rescale(); Window_Level(Lower,Upper); oLower=Lower; oUpper=Upper; } XClearArea(theDisp,mainW,0,zHeight, zWidth,zHeight+info_height,False); if (wl_display) XDrawImageString(theDisp,mainW,theMGC, zWidth-XTextWidth(ol_text_finfo,wl_msg,strlen(wl_msg))-4, zHeight+info_height-4,wl_msg,strlen(wl_msg)); XDrawImageString(theDisp,mainW,theMGC,4, zHeight+info_height-4,loc_msg,strlen(loc_msg)); update_sliders(); update_msgs(); } } break; case UnmapNotify: { if (bitmap_pad==8) { if (Interpolation_Type==BILINEAR) { bilinear_byte_to_byte(byte_Image, Width, Height, icon_byte_image, ICON_WIDTH, ICON_HEIGHT); } else { nneighbour_byte_to_byte(byte_Image, Width, Height, icon_byte_image, ICON_WIDTH, ICON_HEIGHT); } } else { if (Interpolation_Type==BILINEAR) { bilinear_rgbp_to_rgbp(byte_Image, Width, Height, icon_byte_image, ICON_WIDTH, ICON_HEIGHT); } else { nneighbour_rgbp_to_rgbp(byte_Image, Width, Height, icon_byte_image, ICON_WIDTH, ICON_HEIGHT); } } XPutImage(theDisp,iconW,theMGC,iconImage,0,0,0,0, ICON_WIDTH, ICON_HEIGHT); } break; case CirculateNotify: case MapNotify: case DestroyNotify: case GravityNotify: case ReparentNotify: default: break; } /* end of switch */ } /* other command Window events */ if(theEvent.xany.window==cmdW) { switch (event->type) { case Expose: { update_msgs(); } break; case EnterNotify: { if (Selected_Visual_Class==DirectColor) XStoreColors(theDisp,NewCmap,newC,ColorMapSize); if (Selected_Visual_Class!=TrueColor) XInstallColormap(theDisp,NewCmap); } break; case LeaveNotify: { if (Selected_Visual_Class==DirectColor) XStoreColors(theDisp,NewCmap,rootC,ColorMapSize); } break; case UnmapNotify: { cmdW_State = IconicState; } break; case MapNotify: { cmdW_State = NormalState; } break; case ConfigureNotify: { XConfigureEvent *conf_event = (XConfigureEvent *) event; if (conf_event->window == cmdW && (conf_event->width != cmd_width || conf_event->height != cmd_height)) XResizeWindow(theDisp,cmdW,cmd_width,cmd_height); } break; default: break; } } /* button press events */ if (XFindContext(theDisp, theEvent.xany.window, xwin_context, (caddr_t *) &which_xwin)==0) { if(*(which_xwin->event_handler)!=NULL) (*(which_xwin->event_handler))(which_xwin); if (Scale_Data && (oUpper != Upper || oLower != Lower)) { Rescale(); oLower=Lower; oUpper=Upper; } } }