Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

MaterialFltkMenu.C

Go to the documentation of this file.
00001 /***************************************************************************
00002  *cr
00003  *cr            (C) Copyright 1995-2011 The Board of Trustees of the
00004  *cr                        University of Illinois
00005  *cr                         All Rights Reserved
00006  *cr
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  * RCS INFORMATION:
00011  *
00012  *      $RCSfile: MaterialFltkMenu.C,v $
00013  *      $Author: johns $        $Locker:  $             $State: Exp $
00014  *      $Revision: 1.27 $      $Date: 2011/01/26 16:06:47 $
00015  *
00016  ***************************************************************************
00017  * DESCRIPTION:
00018  *   Material properties GUI form
00019  ***************************************************************************/
00020 
00021 // generated by Fast Light User Interface Designer (fluid) version 1.0100
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->opacity) {
00047     matprop = MAT_OPACITY; 
00048   } else if (w == self->outline) {
00049     matprop = MAT_OUTLINE; 
00050   } else if (w == self->outlinewidth) {
00051     matprop = MAT_OUTLINEWIDTH; 
00052   } else if (w == self->transmode) {
00053     matprop = MAT_TRANSMODE; 
00054   } else {
00055     return;
00056   } 
00057   self->app->material_change(
00058     self->app->materialList->material_name(self->curmat), matprop, 
00059          (matprop == MAT_TRANSMODE) ? float(((Fl_Check_Button *)w)->value()) : float(((Fl_Slider *)w)->value()));
00060 }
00061 
00062 void MaterialFltkMenu::createnew_cb(Fl_Widget *w, void *v) {
00063   MaterialFltkMenu *self = (MaterialFltkMenu *)v;
00064   MaterialList *mlist = self->app->materialList;
00065   self->app->material_add(NULL, mlist->material_name(self->curmat));
00066 }
00067 
00068 void MaterialFltkMenu::delete_cb(Fl_Widget *w, void *v) {
00069   MaterialFltkMenu *self = (MaterialFltkMenu *)v;
00070   self->app->material_delete(
00071       self->app->materialList->material_name(self->curmat));
00072 }
00073 
00074 void MaterialFltkMenu::default_cb(Fl_Widget *, void *v) {
00075   MaterialFltkMenu *self = (MaterialFltkMenu *)v;
00076   self->app->material_restore_default(self->curmat);
00077 }
00078 
00079 void MaterialFltkMenu::browser_cb(Fl_Widget *w, void *v) {
00080   MaterialFltkMenu *self = (MaterialFltkMenu *)v;
00081   self->curmat = ((Fl_Hold_Browser *)w)->value()-1;
00082   self->set_sliders();
00083 }
00084 
00085 void MaterialFltkMenu::name_cb(Fl_Widget *w, void *v) {
00086   MaterialFltkMenu *self = (MaterialFltkMenu *)v;
00087   MaterialList *mlist = self->app->materialList;
00088   if (!self->app->material_rename(mlist->material_name(self->curmat), 
00089         ((Fl_Input *)w)->value())) {
00090     // command failed; reset the name to its original value
00091     self->nameinput->value(
00092         self->app->materialList->material_name(self->curmat));
00093   }
00094 }
00095   
00096 MaterialFltkMenu::MaterialFltkMenu(VMDApp *vmdapp)
00097 : VMDFltkMenu("material", "Materials", vmdapp) {
00098 
00099   init();
00100   command_wanted(Command::MATERIAL_RENAME);
00101   command_wanted(Command::MATERIAL_CHANGE);
00102   command_wanted(Command::MATERIAL_ADD);
00103   command_wanted(Command::MATERIAL_DELETE);
00104   command_wanted(Command::MATERIAL_DEFAULT);
00105 
00106   curmat = 0;
00107   fill_material_browser();
00108   set_sliders();
00109 }
00110 
00111 void MaterialFltkMenu::init() {
00112   size(270,380);
00113   {
00114     { browser = new Fl_Hold_Browser(10, 10, 145, 130);
00115       VMDFLTKTOOLTIP(browser, "Select material to edit")
00116       browser->color(VMDMENU_BROWSER_BG);
00117       browser->selection_color(VMDMENU_BROWSER_SEL);
00118       browser->callback(browser_cb, this);
00119     }
00120     Fl_Button *b = new Fl_Button(165, 10, 95, 25, "Create New");
00121 #if defined(VMDMENU_WINDOW)
00122     b->color(VMDMENU_WINDOW, FL_GRAY);
00123 #endif
00124     VMDFLTKTOOLTIP(b, "Create a new copy of the selected material")
00125     b->callback(createnew_cb, this);
00126 
00127     deletebutton = new Fl_Button(165, 35, 95, 25, "Delete");
00128 #if defined(VMDMENU_WINDOW)
00129     deletebutton->color(VMDMENU_WINDOW, FL_GRAY);
00130 #endif
00131     VMDFLTKTOOLTIP(deletebutton, "Delete the selected material")
00132     deletebutton->callback(delete_cb, this);
00133 
00134     defaultbutton = new Fl_Button(165, 60, 95, 25, "Default");
00135 #if defined(VMDMENU_WINDOW)
00136     defaultbutton->color(VMDMENU_WINDOW, FL_GRAY);
00137 #endif
00138     VMDFLTKTOOLTIP(defaultbutton, "Reset built-in materials to defaults")
00139     defaultbutton->callback(default_cb, this);
00140  
00141     { nameinput = new Fl_Input(165, 115, 95, 25);
00142       VMDFLTKTOOLTIP(nameinput, "Rename this material")
00143       nameinput->color(VMDMENU_VALUE_BG, VMDMENU_VALUE_SEL);
00144       nameinput->when(FL_WHEN_ENTER_KEY);
00145       nameinput->callback(name_cb, this);
00146     }
00147     { Fl_Value_Slider* o = ambient = new Fl_Value_Slider(10, 160, 170, 20, "Ambient");
00148       VMDFLTKTOOLTIP(o, "Affects how dark the darkest object/shadow can be")
00149       o->type(FL_HORIZONTAL);
00150       o->color(VMDMENU_MATSLIDER_BG, VMDMENU_MATSLIDER_FG);
00151       o->align(FL_ALIGN_RIGHT);
00152       o->callback(slider_cb, this);
00153     }
00154     { Fl_Value_Slider* o = diffuse = new Fl_Value_Slider(10, 185, 170, 20, "Diffuse");
00155       VMDFLTKTOOLTIP(o, "Diffuse reflectance (paper, dull wood)")
00156       o->type(FL_HORIZONTAL);
00157       o->color(VMDMENU_MATSLIDER_BG, VMDMENU_MATSLIDER_FG);
00158       o->align(FL_ALIGN_RIGHT);
00159       o->callback(slider_cb, this);
00160     }
00161     { Fl_Value_Slider* o = specular = new Fl_Value_Slider(10, 210, 170, 20, "Specular");
00162       VMDFLTKTOOLTIP(o, "Specular reflectance (glass, glossy materials)")
00163       o->type(FL_HORIZONTAL);
00164       o->color(VMDMENU_MATSLIDER_BG, VMDMENU_MATSLIDER_FG);
00165       o->align(FL_ALIGN_RIGHT);
00166       o->callback(slider_cb, this);
00167     }
00168     { Fl_Value_Slider* o = shininess = new Fl_Value_Slider(10, 235, 170, 20, "Shininess");
00169       VMDFLTKTOOLTIP(o, "Degree of shininess (size of specular highlight is smaller as shininess is increased)")
00170       o->type(FL_HORIZONTAL);
00171       o->color(VMDMENU_MATSLIDER_BG, VMDMENU_MATSLIDER_FG);
00172       o->align(FL_ALIGN_RIGHT);
00173       o->callback(slider_cb, this);
00174     }
00175     { Fl_Value_Slider* o = opacity = new Fl_Value_Slider(10, 260, 170, 20, "Opacity");
00176       VMDFLTKTOOLTIP(o, "Degree of opacity (1.0 - transparency)")
00177       o->type(FL_HORIZONTAL);
00178       o->color(VMDMENU_MATSLIDER_BG, VMDMENU_MATSLIDER_FG);
00179       o->align(FL_ALIGN_RIGHT);
00180       o->callback(slider_cb, this);
00181     }
00182     { Fl_Value_Slider* o = outline = new Fl_Value_Slider(10, 285, 170, 20, "Outline");
00183       VMDFLTKTOOLTIP(o, "Outline shading saturation")
00184       o->type(FL_HORIZONTAL);
00185       o->range(0.0, 4.0); // allow a much larger range of values
00186       o->color(VMDMENU_MATSLIDER_BG, VMDMENU_MATSLIDER_FG);
00187       o->align(FL_ALIGN_RIGHT);
00188       o->callback(slider_cb, this);
00189     }
00190     { Fl_Value_Slider* o = outlinewidth = new Fl_Value_Slider(10, 310, 170, 20, "OutlineWidth");
00191       VMDFLTKTOOLTIP(o, "Width/breadth of outline shading effect")
00192       o->type(FL_HORIZONTAL);
00193       o->color(VMDMENU_MATSLIDER_BG, VMDMENU_MATSLIDER_FG);
00194       o->align(FL_ALIGN_RIGHT);
00195       o->callback(slider_cb, this);
00196     }
00197     {
00198       Fl_Check_Button * o = transmode = new Fl_Check_Button(10, 335, 270, 25, "Angle-Modulated Transparency");
00199       VMDFLTKTOOLTIP(o, "Enable angle modulated transparency (edge-on is more opaque)")
00200       o->callback(slider_cb, this);
00201     }
00202     end();
00203   }
00204 }
00205 
00206 void MaterialFltkMenu::fill_material_browser() {
00207   // Get the material names from the MaterialList and post them
00208   MaterialList *mlist = app->materialList;
00209   browser->clear();
00210   for (int j=0; j<mlist->num(); j++)
00211     browser->add(mlist->material_name(j));
00212   browser->select(curmat+1);
00213 }
00214 
00215 void MaterialFltkMenu::set_sliders() {
00216   // Set the values to those of the currently highlighted material 
00217   MaterialList *mlist = app->materialList;
00218   ambient->value(mlist->get_ambient(curmat));
00219   specular->value(mlist->get_specular(curmat));
00220   diffuse->value(mlist->get_diffuse(curmat));
00221   shininess->value(mlist->get_shininess(curmat));
00222   opacity->value(mlist->get_opacity(curmat));
00223   outline->value(mlist->get_outline(curmat));
00224   outlinewidth->value(mlist->get_outlinewidth(curmat));
00225   transmode->value((int) mlist->get_transmode(curmat));
00226   nameinput->value(mlist->material_name(curmat));
00227 
00228   if (curmat == 0 || curmat == 1) {
00229     deletebutton->deactivate();
00230     nameinput->deactivate();
00231     defaultbutton->activate();
00232   } else {
00233     deletebutton->activate();
00234     nameinput->activate();
00235     defaultbutton->deactivate();
00236   }
00237 }
00238 
00239 int MaterialFltkMenu::act_on_command(int type, Command *cmd) {
00240   switch (type) {
00241     case Command::MATERIAL_ADD:
00242     case Command::MATERIAL_DELETE:
00243       fill_material_browser();
00244       browser->select(browser->size());
00245       curmat = browser->size()-1;
00246       set_sliders();
00247       break;
00248     case Command::MATERIAL_RENAME:
00249       fill_material_browser();
00250       nameinput->value(app->materialList->material_name(curmat));
00251       break;
00252     case Command::MATERIAL_CHANGE:
00253     case Command::MATERIAL_DEFAULT:
00254       set_sliders();
00255       break;
00256   }
00257   return 0;
00258 }
00259  

Generated on Sat May 26 01:48:04 2012 for VMD (current) by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002