00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "FL/Fl_Value_Slider.H"
00024 #include "FL/Fl_Hold_Browser.H"
00025 #include "FL/Fl_Button.H"
00026 #include "FL/Fl_Input.H"
00027 #include "FL/forms.H"
00028
00029 #include "MaterialFltkMenu.h"
00030 #include "MaterialList.h"
00031 #include "CmdMaterial.h"
00032 #include "CommandQueue.h"
00033 #include "VMDApp.h"
00034
00035 void MaterialFltkMenu::slider_cb(Fl_Widget *w, void *v) {
00036 MaterialFltkMenu *self = (MaterialFltkMenu *)v;
00037 int matprop;
00038 if (w == self->ambient) {
00039 matprop = MAT_AMBIENT;
00040 } else if (w == self->diffuse ) {
00041 matprop = MAT_DIFFUSE;
00042 } else if (w == self->specular) {
00043 matprop = MAT_SPECULAR;
00044 } else if (w == self->shininess) {
00045 matprop = MAT_SHININESS;
00046 } else if (w == self->mirror) {
00047 matprop = MAT_MIRROR;
00048 } else if (w == self->opacity) {
00049 matprop = MAT_OPACITY;
00050 } else if (w == self->outline) {
00051 matprop = MAT_OUTLINE;
00052 } else if (w == self->outlinewidth) {
00053 matprop = MAT_OUTLINEWIDTH;
00054 } else if (w == self->transmode) {
00055 matprop = MAT_TRANSMODE;
00056 } else {
00057 return;
00058 }
00059 self->app->material_change(
00060 self->app->materialList->material_name(self->curmat), matprop,
00061 (matprop == MAT_TRANSMODE) ? float(((Fl_Check_Button *)w)->value()) : float(((Fl_Slider *)w)->value()));
00062 }
00063
00064 void MaterialFltkMenu::createnew_cb(Fl_Widget *w, void *v) {
00065 MaterialFltkMenu *self = (MaterialFltkMenu *)v;
00066 MaterialList *mlist = self->app->materialList;
00067 self->app->material_add(NULL, mlist->material_name(self->curmat));
00068 }
00069
00070 void MaterialFltkMenu::delete_cb(Fl_Widget *w, void *v) {
00071 MaterialFltkMenu *self = (MaterialFltkMenu *)v;
00072 self->app->material_delete(
00073 self->app->materialList->material_name(self->curmat));
00074 }
00075
00076 void MaterialFltkMenu::default_cb(Fl_Widget *, void *v) {
00077 MaterialFltkMenu *self = (MaterialFltkMenu *)v;
00078 self->app->material_restore_default(self->curmat);
00079 }
00080
00081 void MaterialFltkMenu::browser_cb(Fl_Widget *w, void *v) {
00082 MaterialFltkMenu *self = (MaterialFltkMenu *)v;
00083 self->curmat = ((Fl_Hold_Browser *)w)->value()-1;
00084 self->set_sliders();
00085 }
00086
00087 void MaterialFltkMenu::name_cb(Fl_Widget *w, void *v) {
00088 MaterialFltkMenu *self = (MaterialFltkMenu *)v;
00089 MaterialList *mlist = self->app->materialList;
00090 if (!self->app->material_rename(mlist->material_name(self->curmat),
00091 ((Fl_Input *)w)->value())) {
00092
00093 self->nameinput->value(
00094 self->app->materialList->material_name(self->curmat));
00095 }
00096 }
00097
00098 MaterialFltkMenu::MaterialFltkMenu(VMDApp *vmdapp)
00099 : VMDFltkMenu("material", "Materials", vmdapp) {
00100
00101 init();
00102 command_wanted(Command::MATERIAL_RENAME);
00103 command_wanted(Command::MATERIAL_CHANGE);
00104 command_wanted(Command::MATERIAL_ADD);
00105 command_wanted(Command::MATERIAL_DELETE);
00106 command_wanted(Command::MATERIAL_DEFAULT);
00107
00108 curmat = 0;
00109 fill_material_browser();
00110 set_sliders();
00111 }
00112
00113 void MaterialFltkMenu::init() {
00114 size(270,405);
00115 {
00116 { browser = new Fl_Hold_Browser(10, 10, 145, 130);
00117 VMDFLTKTOOLTIP(browser, "Select material to edit")
00118 browser->color(VMDMENU_BROWSER_BG);
00119 browser->selection_color(VMDMENU_BROWSER_SEL);
00120 browser->callback(browser_cb, this);
00121 }
00122 Fl_Button *b = new Fl_Button(165, 10, 95, 25, "Create New");
00123 #if defined(VMDMENU_WINDOW)
00124 b->color(VMDMENU_WINDOW, FL_GRAY);
00125 #endif
00126 VMDFLTKTOOLTIP(b, "Create a new copy of the selected material")
00127 b->callback(createnew_cb, this);
00128
00129 deletebutton = new Fl_Button(165, 35, 95, 25, "Delete");
00130 #if defined(VMDMENU_WINDOW)
00131 deletebutton->color(VMDMENU_WINDOW, FL_GRAY);
00132 #endif
00133 VMDFLTKTOOLTIP(deletebutton, "Delete the selected material")
00134 deletebutton->callback(delete_cb, this);
00135
00136 defaultbutton = new Fl_Button(165, 60, 95, 25, "Default");
00137 #if defined(VMDMENU_WINDOW)
00138 defaultbutton->color(VMDMENU_WINDOW, FL_GRAY);
00139 #endif
00140 VMDFLTKTOOLTIP(defaultbutton, "Reset built-in materials to defaults")
00141 defaultbutton->callback(default_cb, this);
00142
00143 { nameinput = new Fl_Input(165, 115, 95, 25);
00144 VMDFLTKTOOLTIP(nameinput, "Rename this material")
00145 nameinput->color(VMDMENU_VALUE_BG, VMDMENU_VALUE_SEL);
00146 nameinput->when(FL_WHEN_ENTER_KEY);
00147 nameinput->callback(name_cb, this);
00148 }
00149 { Fl_Value_Slider* o = ambient = new Fl_Value_Slider(10, 160, 170, 20, "Ambient");
00150 VMDFLTKTOOLTIP(o, "Affects how dark the darkest object/shadow can be")
00151 o->type(FL_HORIZONTAL);
00152 o->color(VMDMENU_MATSLIDER_BG, VMDMENU_MATSLIDER_FG);
00153 o->align(FL_ALIGN_RIGHT);
00154 o->callback(slider_cb, this);
00155 }
00156 { Fl_Value_Slider* o = diffuse = new Fl_Value_Slider(10, 185, 170, 20, "Diffuse");
00157 VMDFLTKTOOLTIP(o, "Diffuse reflectance (paper, dull wood)")
00158 o->type(FL_HORIZONTAL);
00159 o->color(VMDMENU_MATSLIDER_BG, VMDMENU_MATSLIDER_FG);
00160 o->align(FL_ALIGN_RIGHT);
00161 o->callback(slider_cb, this);
00162 }
00163 { Fl_Value_Slider* o = specular = new Fl_Value_Slider(10, 210, 170, 20, "Specular");
00164 VMDFLTKTOOLTIP(o, "Specular reflectance (glass, glossy materials)")
00165 o->type(FL_HORIZONTAL);
00166 o->color(VMDMENU_MATSLIDER_BG, VMDMENU_MATSLIDER_FG);
00167 o->align(FL_ALIGN_RIGHT);
00168 o->callback(slider_cb, this);
00169 }
00170 { Fl_Value_Slider* o = shininess = new Fl_Value_Slider(10, 235, 170, 20, "Shininess");
00171 VMDFLTKTOOLTIP(o, "Degree of shininess (size of specular highlight is smaller as shininess is increased)")
00172 o->type(FL_HORIZONTAL);
00173 o->color(VMDMENU_MATSLIDER_BG, VMDMENU_MATSLIDER_FG);
00174 o->align(FL_ALIGN_RIGHT);
00175 o->callback(slider_cb, this);
00176 }
00177 { Fl_Value_Slider* o = mirror = new Fl_Value_Slider(10, 260, 170, 20, "Mirror");
00178 VMDFLTKTOOLTIP(o, "Mirror reflection (ray tracing only)")
00179 o->type(FL_HORIZONTAL);
00180 o->color(VMDMENU_MATSLIDER_BG, VMDMENU_MATSLIDER_FG);
00181 o->align(FL_ALIGN_RIGHT);
00182 o->callback(slider_cb, this);
00183 }
00184 { Fl_Value_Slider* o = opacity = new Fl_Value_Slider(10, 285, 170, 20, "Opacity");
00185 VMDFLTKTOOLTIP(o, "Degree of opacity (1.0 - transparency)")
00186 o->type(FL_HORIZONTAL);
00187 o->color(VMDMENU_MATSLIDER_BG, VMDMENU_MATSLIDER_FG);
00188 o->align(FL_ALIGN_RIGHT);
00189 o->callback(slider_cb, this);
00190 }
00191 { Fl_Value_Slider* o = outline = new Fl_Value_Slider(10, 310, 170, 20, "Outline");
00192 VMDFLTKTOOLTIP(o, "Outline shading saturation")
00193 o->type(FL_HORIZONTAL);
00194 o->range(0.0, 4.0);
00195 o->color(VMDMENU_MATSLIDER_BG, VMDMENU_MATSLIDER_FG);
00196 o->align(FL_ALIGN_RIGHT);
00197 o->callback(slider_cb, this);
00198 }
00199 { Fl_Value_Slider* o = outlinewidth = new Fl_Value_Slider(10, 335, 170, 20, "OutlineWidth");
00200 VMDFLTKTOOLTIP(o, "Width/breadth of outline shading effect")
00201 o->type(FL_HORIZONTAL);
00202 o->color(VMDMENU_MATSLIDER_BG, VMDMENU_MATSLIDER_FG);
00203 o->align(FL_ALIGN_RIGHT);
00204 o->callback(slider_cb, this);
00205 }
00206 {
00207 Fl_Check_Button * o = transmode = new Fl_Check_Button(10, 360, 270, 25, "Angle-Modulated Transparency");
00208 VMDFLTKTOOLTIP(o, "Enable angle modulated transparency (edge-on is more opaque)")
00209 o->callback(slider_cb, this);
00210 }
00211 end();
00212 }
00213 }
00214
00215 void MaterialFltkMenu::fill_material_browser() {
00216
00217 MaterialList *mlist = app->materialList;
00218 browser->clear();
00219 for (int j=0; j<mlist->num(); j++)
00220 browser->add(mlist->material_name(j));
00221 browser->select(curmat+1);
00222 }
00223
00224 void MaterialFltkMenu::set_sliders() {
00225
00226 MaterialList *mlist = app->materialList;
00227 ambient->value(mlist->get_ambient(curmat));
00228 specular->value(mlist->get_specular(curmat));
00229 diffuse->value(mlist->get_diffuse(curmat));
00230 shininess->value(mlist->get_shininess(curmat));
00231 mirror->value(mlist->get_mirror(curmat));
00232 opacity->value(mlist->get_opacity(curmat));
00233 outline->value(mlist->get_outline(curmat));
00234 outlinewidth->value(mlist->get_outlinewidth(curmat));
00235 transmode->value((int) mlist->get_transmode(curmat));
00236 nameinput->value(mlist->material_name(curmat));
00237
00238 if (curmat == 0 || curmat == 1) {
00239 deletebutton->deactivate();
00240 nameinput->deactivate();
00241 defaultbutton->activate();
00242 } else {
00243 deletebutton->activate();
00244 nameinput->activate();
00245 defaultbutton->deactivate();
00246 }
00247 }
00248
00249 int MaterialFltkMenu::act_on_command(int type, Command *cmd) {
00250 switch (type) {
00251 case Command::MATERIAL_ADD:
00252 case Command::MATERIAL_DELETE:
00253 fill_material_browser();
00254 browser->select(browser->size());
00255 curmat = browser->size()-1;
00256 set_sliders();
00257 break;
00258 case Command::MATERIAL_RENAME:
00259 fill_material_browser();
00260 nameinput->value(app->materialList->material_name(curmat));
00261 break;
00262 case Command::MATERIAL_CHANGE:
00263 case Command::MATERIAL_DEFAULT:
00264 set_sliders();
00265 break;
00266 }
00267 return 0;
00268 }
00269