00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "frame_selector.h"
00022
00023 #include <string.h>
00024 #include <stdio.h>
00025
00026 #include <FL/Fl.H>
00027 #include <FL/Fl_Window.H>
00028 #include <FL/Fl_Button.H>
00029 #include <FL/Fl_Value_Input.H>
00030 #include <FL/Fl_Box.H>
00031
00033 class FrameSelector : public Fl_Window {
00034 public:
00035 FrameSelector(const char *, const char *, int);
00036 static void first_cb(Fl_Widget *w, void *v);
00037 static void last_cb(Fl_Widget *w, void *v);
00038 int do_dialog();
00039
00040 Fl_Button *okbutton;
00041 Fl_Button *cancelbutton;
00042 Fl_Value_Input *firstvalue;
00043 Fl_Value_Input *lastvalue;
00044 Fl_Value_Input *stridevalue;
00045 Fl_Box *molnamelabel;
00046 Fl_Box *messagelabel;
00047
00048 const int maxframe;
00049 };
00050
00051 void FrameSelector::first_cb(Fl_Widget *w, void *v) {
00052 Fl_Value_Input *counter = (Fl_Value_Input *)w;
00053 FrameSelector *sel = (FrameSelector *)v;
00054
00055 double val = counter->value();
00056 if (val < 0) {
00057
00058 if (sel->maxframe > 0)
00059 counter->value(sel->maxframe);
00060 else
00061 counter->value(0);
00062 } else if (sel->maxframe >= 0 && val > sel->maxframe) {
00063 counter->value(0);
00064 }
00065 }
00066
00067 void FrameSelector::last_cb(Fl_Widget *w, void *v) {
00068 Fl_Value_Input *counter = (Fl_Value_Input *)w;
00069 FrameSelector *sel = (FrameSelector *)v;
00070
00071 double val = counter->value();
00072
00073 if (val < 0) {
00074
00075 if (sel->maxframe > 0)
00076 counter->value(sel->maxframe);
00077 else
00078 counter->value(-1);
00079 } else if (sel->maxframe >= 0 && val > sel->maxframe) {
00080 counter->value(0);
00081 }
00082 }
00083
00084
00085 int FrameSelector::do_dialog() {
00086 int result = 0;
00087 hotspot(this);
00088 show();
00089 while(1) {
00090 Fl::wait();
00091 Fl_Widget *o = Fl::readqueue();
00092 if (o == okbutton) {result=1; break;}
00093 else if (o == cancelbutton || o == this) break;
00094 }
00095 hide();
00096 return result;
00097 }
00098
00099
00100 FrameSelector::FrameSelector(const char *message, const char *molname, int max)
00101 : Fl_Window(240, 275, "Frame Selector"), maxframe(max) {
00102
00103 messagelabel = new Fl_Box(0, 10, 240, 20, message);
00104 messagelabel->align(FL_ALIGN_INSIDE|FL_ALIGN_CENTER);
00105
00106 molnamelabel = new Fl_Box(0, 37, 240, 20, molname);
00107 molnamelabel->align(FL_ALIGN_INSIDE|FL_ALIGN_CENTER);
00108
00109 { Fl_Box* o = new Fl_Box(10, 70, 220, 20, "In the range...");
00110 o->align(FL_ALIGN_INSIDE|FL_ALIGN_LEFT);
00111 }
00112
00113 firstvalue = new Fl_Value_Input(75, 100, 100, 25, "First: ");
00114 firstvalue->minimum(0);
00115 firstvalue->maximum((double)max);
00116 firstvalue->step(1);
00117 firstvalue->value(0);
00118 firstvalue->align(FL_ALIGN_LEFT);
00119
00120 lastvalue = new Fl_Value_Input(75, 130, 100, 25, "Last: ");
00121 lastvalue->minimum(0);
00122 lastvalue->maximum((double)max);
00123 lastvalue->step(1);
00124 lastvalue->value((double)max);
00125 lastvalue->align(FL_ALIGN_LEFT);
00126
00127 { Fl_Box* o = new Fl_Box(10, 170, 220, 20, "And keeping frames every...");
00128 o->align(FL_ALIGN_INSIDE|FL_ALIGN_LEFT);
00129 }
00130
00131 stridevalue = new Fl_Value_Input(75, 200, 100, 25, "Stride: ");
00132 stridevalue->minimum(1);
00133 stridevalue->maximum((double)max+1);
00134 stridevalue->step(1);
00135 stridevalue->value(1);
00136 stridevalue->align(FL_ALIGN_LEFT);
00137
00138 okbutton = new Fl_Button(45, 240, 85, 25, "Select");
00139 cancelbutton = new Fl_Button(150, 240, 60, 25, "Cancel");
00140
00141 set_modal();
00142 end();
00143 }
00144
00145
00146 int frame_selector(const char *message, const char *molname, int maxframe,
00147 int *first, int *last, int *stride) {
00148 char *molstr=new char[strlen(molname)+3];
00149 sprintf(molstr, "\"%s\"", molname);
00150
00151 FrameSelector *f = new FrameSelector(message, molstr, maxframe);
00152 if (*first < 0) *first = maxframe;
00153 if (*last < 0) *last = maxframe;
00154 f->firstvalue->value((double)*first);
00155 f->lastvalue->value((double)*last);
00156 f->stridevalue->value((double)*stride);
00157
00158 int ok = f->do_dialog();
00159
00160 if (ok) {
00161 *first = (int)f->firstvalue->value();
00162 *last = (int)f->lastvalue->value();
00163 *stride = (int)f->stridevalue->value();
00164 }
00165 delete f;
00166 delete[] molstr;
00167
00168 return ok;
00169 }
00170
00171
00172
00173 int frame_delete_selector(const char *molname, int maxframe,
00174 int *first, int *last, int *stride) {
00175 char *molstr=new char[strlen(molname)+3];
00176 sprintf(molstr, "\"%s\"", molname);
00177
00178 FrameSelector *f = new FrameSelector("Select frames to delete for:", molstr, maxframe);
00179 f->firstvalue->value((double)*first);
00180 f->lastvalue->value((double)*last);
00181 f->stridevalue->minimum(0);
00182 f->stridevalue->value((double)*stride);
00183 f->okbutton->label("Delete");
00184
00185 int ok = f->do_dialog();
00186
00187 if (ok) {
00188 *first = (int)f->firstvalue->value();
00189 *last = (int)f->lastvalue->value();
00190 *stride = (int)f->stridevalue->value();
00191 }
00192 delete f;
00193 delete[] molstr;
00194
00195 return ok;
00196 }
00197
00198
00199