4
* Copyright (C) 1997,98 Rasca, Berlin
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21
* This file contains the Xt GUI's options dialog
25
#include "../config.h" /* autoconf output */
30
#include <X11/Intrinsic.h>
31
#include <X11/StringDefs.h>
32
#include <X11/Shell.h>
36
#include "Xw/Button.h"
37
#include "Xw/Toggle.h"
38
#include "xt_options.h"
47
static Widget wShell, wFps, wFile, wMaxFrames, wMaxTime, wQuality;
48
static Widget wCompress, wCodec, wShm, wMouse, wMouseType;
49
extern Widget next, prev;
52
void ChangeLabel (int pic_no);
53
static void CbOk (Widget w, XtPointer client_data, XtPointer call_data);
54
static void CbSave (Widget w, XtPointer client_data, XtPointer call_data);
55
static void CbCancel (Widget w, XtPointer client_data, XtPointer call_data);
56
static void CbActivate (Widget w, XtPointer client_data, XtPointer call_data);
60
* read the new values and close the window
63
CbOk (Widget w, XtPointer client_data, XtPointer call_data)
70
Job *job = (Job *) sJob;
72
str = XwFieldGetString (wQuality);
75
val_int = job_quality ();
76
sscanf (str, "%d", &val_int);
77
job_set_quality (val_int);
82
str = XwFieldGetString (wCompress);
85
val_int = job_compression ();
86
sscanf (str, "%d", &val_int);
87
job_set_compression (val_int);
92
str = XwFieldGetString (wFps);
95
val_float = job_fps ();
96
sscanf (str, "%f", &val_float);
97
job_set_fps (val_float);
102
str = XwFieldGetString (wFile);
110
str = XwFieldGetString (wMaxFrames);
113
sscanf (str, "%d", &job->max_frames);
117
str = XwFieldGetString (wMaxTime);
120
sscanf (str, "%f", &job->max_time);
124
str = XwFieldGetString (wCodec);
128
Boolean found = FALSE;
130
for (i = 0; i < NUMCODECS; i ++) {
131
if (strcmp(tCodecNames[i], str) == 0) a = i;
133
if (a < CODEC_MPEG1) {
135
fprintf(stderr, "Unsupported Codec selected, resetting to MPEG1!\n");
137
job->targetCodec = a;
143
XtVaGetValues (wShm, XtNstate, &val_int, NULL);
145
job->flags |= FLG_USE_SHM;
148
job->flags &= ~FLG_USE_SHM;
152
XtVaGetValues (wMouse, XtNstate, &val_int, NULL);
154
XtVaGetValues (wMouseType, XtNstate, &val_int, NULL);
156
job->mouseWanted = 2;
158
job->mouseWanted = 1;
161
job->mouseWanted = 0;
164
XtDestroyWidget (wShell);
165
ChangeLabel (job->pic_no);
167
// unset autocontinue unless we capture to movie and file is mutable
168
if ( job->flags & FLG_AUTO_CONTINUE && ( (! is_filename_mutable(job->file)) ||
169
(! job->flags & FLG_MULTI_IMAGE) ) ) {
170
job->flags &= ~FLG_AUTO_CONTINUE;
171
fprintf(stderr, "Output not a video file or no counter in filename\nDisabling autocontinue!\n");
174
/* previous and next buttons have different meanings for on-the-fly encoding
175
* and individual frame capture */
176
if (( job->flags & FLG_MULTI_IMAGE ) == 0 ) {
177
if (job->pic_no > job->step ) XtSetSensitive(prev, True);
178
else XtSetSensitive(prev, False);
180
if ( is_filename_mutable(job->file) ) {
181
XtSetSensitive(next, True);
182
XtSetSensitive(prev, True);
184
XtSetSensitive(next, False);
185
if (job->movie_no > 0 ) XtSetSensitive(prev, True);
186
else XtSetSensitive(prev, False);
196
CbSave (Widget w, XtPointer client_data, XtPointer call_data)
205
char file[PATH_MAX+1];
207
Job *job = (Job *) sJob ;
209
str = XwFieldGetString (wQuality);
212
val_int = job_quality ();
213
sscanf (str, "%d", &val_int);
214
job_set_quality (val_int);
219
str = XwFieldGetString (wCompress);
222
val_int = job_compression ();
223
sscanf (str, "%d", &val_int);
224
job_set_compression (val_int);
229
str = XwFieldGetString (wFps);
232
val_float = job_fps ();
233
sscanf (str, "%f", &val_float);
234
job_set_fps (val_float);
239
str = XwFieldGetString (wFile);
247
str = XwFieldGetString (wMaxFrames);
250
sscanf (str, "%d", &job->max_frames);
254
str = XwFieldGetString (wMaxTime);
257
sscanf (str, "%f", &job->max_time);
261
str = XwFieldGetString (wCodec);
265
Boolean found = FALSE;
267
for (i = 0; i < NUMCODECS; i ++) {
268
if (strcmp(tCodecNames[i], str) == 0) a = i;
270
if (a < CODEC_MPEG1) {
272
fprintf(stderr, "Unsupported Codec selected, resetting to MPEG1!\n");
274
job->targetCodec = a;
280
XtVaGetValues (wShm, XtNstate, &val_int, NULL);
282
job->flags |= FLG_USE_SHM;
285
job->flags &= ~FLG_USE_SHM;
289
XtVaGetValues (wMouse, XtNstate, &val_int, NULL);
291
XtVaGetValues (wMouseType, XtNstate, &val_int, NULL);
293
job->mouseWanted = 2;
295
job->mouseWanted = 1;
298
job->mouseWanted = 0;
301
if ( ! XVC_WriteOptionsFile(job) ) {
302
fprintf(stderr, "Unable to write personal options file!\n");
309
CbCancel (Widget w, XtPointer client_data, XtPointer call_data)
311
XtDestroyWidget (wShell);
317
CbActivate (Widget w, XtPointer client_data, XtPointer call_data)
319
static Time t = CurrentTime;
320
Widget next = (Widget) client_data;
323
printf ("%s: CbActivate()\n", __FILE__);
325
if (XtCallAcceptFocus (next, &t))
326
XtSetKeyboardFocus (XtParent(w), next);
331
* create the options dialog window
334
CbOptions (Widget w, XtPointer client_data, XtPointer call_data)
338
Job *job = (Job *) client_data;
339
Widget frame, box, info;
340
Widget fps_lbl, file_lbl, max_frames_lbl, max_time_lbl, quality_lbl;
341
Widget compress_lbl, codec_lbl, mouse_lbl, ok, cancel, save;
343
char str[PATH_MAX+1];
347
printf ("CbOptions() fps=%f\n", job->fps);
349
wShell = XtVaCreatePopupShell ("options", transientShellWidgetClass,
350
GetToplevel(w), XtNinput, TRUE, NULL);
351
frame = XtVaCreateManagedWidget ("frame", xwBoxWidgetClass, wShell, NULL);
353
info = XtVaCreateManagedWidget ("info", xwLabelWidgetClass, frame,
354
XtNshadowType, XtShadowNone, NULL);
356
sprintf (str, "%f", job->fps);
357
box = XtVaCreateManagedWidget ("box", xwBoxWidgetClass, frame,
358
XtNorientation, XtorientHorizontal, NULL);
359
wFps = XtVaCreateManagedWidget ("fps_val", xwFieldWidgetClass, box,
360
XtNstring, str, XtNonlyNumber, True, NULL);
361
fps_lbl =XtVaCreateManagedWidget ("fps", xwLabelWidgetClass, box, NULL);
363
sprintf (str, "%s", job->file);
364
box = XtVaCreateManagedWidget ("box", xwBoxWidgetClass, frame,
365
XtNorientation, XtorientHorizontal, NULL);
366
wFile = XtVaCreateManagedWidget ("file_val", xwFieldWidgetClass, box,
367
XtNstring, str, XtNprev, wFps, NULL);
368
file_lbl =XtVaCreateManagedWidget ("file", xwLabelWidgetClass, box, NULL);
370
sprintf (str, "%d", job->max_frames);
371
box = XtVaCreateManagedWidget ("box", xwBoxWidgetClass, frame,
372
XtNorientation, XtorientHorizontal, NULL);
373
wMaxFrames = XtVaCreateManagedWidget ("max_frames_val", xwFieldWidgetClass,
374
box, XtNstring, str, XtNonlyNumber, True,
375
XtNprev, wFile, NULL);
376
max_frames_lbl = XtVaCreateManagedWidget ("max_frames", xwLabelWidgetClass,
379
sprintf (str, "%f", job->max_time);
380
box = XtVaCreateManagedWidget ("box", xwBoxWidgetClass, frame,
381
XtNorientation, XtorientHorizontal, NULL);
382
wMaxTime = XtVaCreateManagedWidget ("max_time_val", xwFieldWidgetClass,
383
box, XtNstring, str, XtNonlyNumber, True,
384
XtNprev, wMaxFrames, NULL);
385
max_time_lbl =XtVaCreateManagedWidget ("max_time", xwLabelWidgetClass,
388
sprintf (str, "%d", job->quality);
389
box = XtVaCreateManagedWidget ("box", xwBoxWidgetClass, frame,
390
XtNorientation, XtorientHorizontal, NULL);
391
wQuality = XtVaCreateManagedWidget ("quality_val", xwFieldWidgetClass,
392
box, XtNstring, str, XtNonlyNumber, True,
393
XtNlength, 3, XtNprev, wMaxTime, NULL);
394
quality_lbl = XtVaCreateManagedWidget ("quality", xwLabelWidgetClass, box,
398
sprintf (str, "%d", job->compress);
399
box = XtVaCreateManagedWidget ("box", xwBoxWidgetClass, frame,
400
XtNorientation, XtorientHorizontal, NULL);
401
wCompress = XtVaCreateManagedWidget ("compress_val", xwFieldWidgetClass,
402
box, XtNstring, str, XtNlength, 1,
403
XtNonlyNumber, True, XtNprev, wQuality, NULL);
404
compress_lbl = XtVaCreateManagedWidget ("compress", xwLabelWidgetClass,
407
sprintf (str, "%s", tCodecNames[(job->targetCodec)]);
408
box = XtVaCreateManagedWidget ("box", xwBoxWidgetClass, frame,
409
XtNorientation, XtorientHorizontal, NULL);
410
wCodec = XtVaCreateManagedWidget ("codec_val", xwFieldWidgetClass,
411
box, XtNstring, str, XtNprev, wCompress, NULL);
412
codec_lbl = XtVaCreateManagedWidget ("codec (e.g. MPEG4)", xwLabelWidgetClass,
415
box = XtVaCreateManagedWidget ("box", xwBoxWidgetClass, frame,
416
XtNorientation, XtorientHorizontal, NULL);
417
wShm = XtVaCreateManagedWidget ("shm", xwToggleWidgetClass, box,
418
XtNstate, (Boolean)(job->flags & FLG_USE_SHM ? 1:0),
419
XtNprev, wCodec, NULL);
421
wMouse = XtVaCreateManagedWidget ("mouse", xwToggleWidgetClass, box,
422
XtNstate, (Boolean)((job->mouseWanted > 0) ? 1:0),
423
XtNprev, wShm, NULL);
425
wMouseType = XtVaCreateManagedWidget ("black", xwToggleWidgetClass, box,
426
XtNstate, (Boolean)((job->mouseWanted > 1) ? 1:0),
427
XtNprev, wMouse, NULL);
432
box = XtVaCreateManagedWidget ("box", xwBoxWidgetClass, frame,
433
XtNorientation, XtorientHorizontal, NULL);
434
ok = XtVaCreateManagedWidget ("ok", xwButtonWidgetClass, box,
435
XtNprev, wShm, NULL);
436
cancel = XtVaCreateManagedWidget ("cancel", xwButtonWidgetClass, box,
438
save = XtVaCreateManagedWidget ("save", xwButtonWidgetClass, box,
439
XtNprev, cancel, XtNnext, wFps, NULL);
441
XtVaSetValues (cancel, XtNnext, save, NULL);
442
XtVaSetValues (ok, XtNnext, cancel, NULL);
443
XtVaSetValues (wShm, XtNnext, ok, NULL);
444
XtVaSetValues (wCompress, XtNnext, wShm, NULL);
445
XtVaSetValues (wQuality, XtNnext, wCompress, NULL);
446
XtVaSetValues (wMaxTime, XtNnext, wQuality, NULL);
447
XtVaSetValues (wMaxFrames, XtNnext, wMaxTime, NULL);
448
XtVaSetValues (wFile, XtNnext, wMaxFrames, NULL);
449
XtVaSetValues (wFps, XtNnext, wFile, XtNprev, save, NULL);
451
XtAddCallback (wFps, XtNactivateCallback, CbActivate, wFile);
452
XtAddCallback (wFile, XtNactivateCallback, CbActivate, wMaxFrames);
453
XtAddCallback (wMaxFrames, XtNactivateCallback, CbActivate, wMaxTime);
454
XtAddCallback (wMaxTime, XtNactivateCallback, CbActivate, wQuality);
455
XtAddCallback (wQuality, XtNactivateCallback, CbActivate, wCompress);
456
XtAddCallback (wCompress, XtNactivateCallback, CbActivate, wShm);
458
XtAddCallback (ok, XtNcallback, CbOk, job);
459
XtAddCallback (cancel, XtNcallback, CbCancel, NULL);
460
XtAddCallback (save, XtNcallback, CbSave, job);
462
XtTranslateCoords (w, 0, 0, &x, &y);
463
XtVaSetValues (wShell, XtNx, x, XtNy, y, NULL);
465
XtPopup (wShell, XtGrabNonexclusive);
471
OptionDoneAction (Widget w, XEvent *ev, String *parms, Cardinal *num_parms)
474
if (*parms[0] == '1') {
475
CbOk (w, (XtPointer)DLG_OK, NULL);
476
} else if (*parms[0] == '2') {
477
CbSave (w, (XtPointer)DLG_SAVE, NULL);
479
CbCancel (w, NULL, NULL);
487
OptionOpenAction (Widget w, XEvent *ev, String *parms, Cardinal *num_parms)
489
Job *job = job_ptr();
490
CbOptions (w, (XtPointer) job, (XtPointer) NULL);