+ int cur_drag = dragging;
+ switch( event->type ) {
+ case ButtonPress:
+ if( cur_drag > 0 ) return 1;
+ x0 = event->xbutton.x_root;
+ y0 = event->xbutton.y_root;
+ if( !cur_drag ) {
+ draw_selection(-1);
+ if( event->xbutton.button == RIGHT_BUTTON ) break;
+ if( x0>=get_x() && x0<get_x()+get_w() &&
+ y0>=get_y() && y0<get_y()+get_h() ) break;
+ }
+ x1 = x0; y1 = y0;
+ draw_selection(1);
+ dragging = 1;
+ return 1;
+ case ButtonRelease:
+ dragging = 0;
+ case MotionNotify:
+ if( cur_drag > 0 ) {
+ x1 = event->xbutton.x_root;
+ y1 = event->xbutton.y_root;
+ draw_selection(0);
+ }
+ return 1;
+ default:
+ return 0;
+ }
+
+ int cx = lx0, cy = ly0;
+ int cw = lx1-lx0, ch = ly1-ly0;
+ hide_window();
+ sync_display();
+ grab_thread->done = 1;
+
+ MWindow *mwindow = grab_thread->mwindow;
+ Preferences *preferences = mwindow->preferences;
+ char filename[BCTEXTLEN];
+ static const char *exts[] = { "png", "jpg", "tif", "ppm" };
+ time_t tt; time(&tt);
+ struct tm tm; localtime_r(&tt,&tm);
+ snprintf(filename,sizeof(filename),"%s/%s_%04d%02d%02d-%02d%02d%02d.%s",
+ preferences->snapshot_path, _("grab"),
+ 1900+tm.tm_year,1+tm.tm_mon,tm.tm_mday,
+ tm.tm_hour,tm.tm_min,tm.tm_sec, exts[mode]);
+ char *asset_path = FileSystem::basepath(filename);
+ Asset *asset = new Asset(asset_path);
+ delete [] asset_path;
+ switch( mode ) {
+ case GRABSHOT_PNG:
+ asset->format = FILE_PNG;
+ asset->png_use_alpha = 1;
+ break;
+ case GRABSHOT_JPEG:
+ asset->format = FILE_JPEG;
+ asset->jpeg_quality = 90;
+ break;
+ case GRABSHOT_TIFF:
+ asset->format = FILE_TIFF;
+ asset->tiff_cmodel = 0;
+ asset->tiff_compression = 0;
+ break;
+ case GRABSHOT_PPM:
+ asset->format = FILE_PPM;
+ break;
+ }
+
+// no odd dimensions
+ int rw = get_root_w(0), rh = get_root_h(0);
+ if( cx < 0 ) { cw += cx; cx = 0; }
+ if( cy < 0 ) { ch += cy; cy = 0; }
+ if( cx+cw > rw ) cw = rw-cx;
+ if( cy+ch > rh ) ch = rh-cy;
+ if( !cw || !ch ) return 1;
+
+ VFrame vframe(cw,ch, BC_RGB888);
+ if( cx+cw < rw ) ++cw;
+ if( cy+ch < rh ) ++ch;
+ BC_Capture capture_bitmap(cw,ch, 0);
+ capture_bitmap.capture_frame(&vframe, cx,cy);
+
+ asset->width = vframe.get_w();
+ asset->height = vframe.get_h();
+ asset->audio_data = 0;
+ asset->video_data = 1;
+ asset->video_length = 1;
+ asset->layers = 1;
+
+ File file;
+ int fcolor_model = mwindow->edl->session->color_model;
+ int processors = preferences->project_smp + 1;
+ if( processors > 8 ) processors = 8;
+ file.set_processors(processors);
+ int ret = file.open_file(preferences, asset, 0, 1);
+ if( !ret ) {
+ file.start_video_thread(1, fcolor_model,
+ processors > 1 ? 2 : 1, 0);
+ VFrame ***frames = file.get_video_buffer();
+ VFrame *frame = frames[0][0];
+ frame->transfer_from(&vframe);
+ ret = file.write_video_buffer(1);
+ file.close_file();
+ }
+ if( !ret ) {
+ asset->awindow_folder = AW_MEDIA_FOLDER;
+ mwindow->edl->assets->append(asset);
+ mwindow->awindow->gui->async_update_assets();
+ }
+ else {
+ eprintf(_("grabshot render failed"));
+ asset->remove_user();
+ }
+