00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00023 #ifndef INCLUDE_VALUE_EDITOR
00024 #define INCLUDE_VALUE_EDITOR
00025
00026 #include "3d.h"
00027 #include "resource.h"
00028
00029 #define SPEED 6
00030 #define SPEED_PAD 45
00031 #define SPEED_DELTA 1
00032 #define SPEED_PAD_DELTA 10
00033 #define DELTA_FOG 0.5
00034
00038 template <class T> class ValueNamed
00039 {
00040 public:
00041 T value;
00042 MyString description;
00043
00044 public:
00045 ValueNamed()
00046 {
00047 Zero();
00048 }
00049
00050 void Zero()
00051 {
00052 value = 0;
00053 description = "";
00054 }
00055
00056 void operator=(ValueNamed &source)
00057 {
00058 value = source.value;
00059 description = source.description;
00060 }
00061
00062 void Set (T _value,char *_desciption)
00063 {
00064 value = _value;
00065 description = _desciption;
00066 }
00067 };
00068
00072 template <class T> class ValueEditor
00073 {
00074 public:
00075 MyString valueText;
00076 MyString info;
00077 MyString variable;
00078 T minValue;
00079 T maxValue;
00080 T *value;
00081 HTREEITEM hItem;
00082
00083 typedef ValueNamed<T> ValueNamedCour;
00084 MyList<ValueNamedCour> specials;
00085
00086 public:
00087 ValueEditor()
00088 {
00089 Zero();
00090 }
00091
00092 void Zero()
00093 {
00094 hItem=NULL;
00095 info="";
00096 variable="";
00097 valueText="";
00098 minValue=0;
00099 maxValue=1;
00100 value = NULL;
00101 specials.SuprAll();
00102 }
00103
00104 void operator=(ValueEditor &source)
00105 {
00106 hItem=source.hItem;
00107 info=source.info;
00108 variable=source.variable;
00109 minValue=source.minValue;
00110 maxValue=source.maxValue;
00111 value=source.value;
00112 valueText=source.valueText;
00113 specials = source.specials;
00114 }
00115
00116 ValueEditor<T> * GetCopy()
00117 {
00118 ValueEditor<T> *newOne = new ValueEditor<T>;
00119 *newOne=*this;
00120 return newOne;
00121 }
00122
00123 void InterpretedText(MyString &interpretedText,char *_valueText=NULL,T *_value=NULL)
00124 {
00125 if (_valueText) valueText=_valueText;
00126 if (_value) value=_value;
00127
00128 interpretedText="";
00129
00130 for (int i=0;i<valueText.size;i++)
00131 if (valueText[i]=='\t') interpretedText<<*value;
00132 else interpretedText<<valueText[i];
00133 }
00134
00135 void Set(char *_variable,char *_info,T _minValue,T _maxValue,HTREEITEM _hItem)
00136 {
00137 hItem=_hItem;
00138 info=_info;
00139 variable=_variable;
00140 minValue=_minValue;
00141 maxValue=_maxValue;
00142 }
00143
00144 void MAJ_TreeItem(HWND hWnd)
00145 {
00146 MyString text;
00147 InterpretedText(text);
00148 TVITEM item;
00149 item.mask = TVIF_HANDLE | TVIF_TEXT;
00150 item.hItem = hItem;
00151 item.pszText=text;
00152 TreeView_SetItem(GetDlgItem(hWnd,IDC_TREE_ELEM),&item);
00153 }
00154
00155 void AddSpecial(T special,char *description)
00156 {
00157 ValueNamed<T> valSpecial;
00158 valSpecial.Set(special,description);
00159 specials+=valSpecial;
00160 }
00161
00162 void MAJ_ValueMin(HWND hWnd)
00163 {
00164 MAJ_Value(hWnd,minValue);
00165 }
00166
00167 void MAJ_ValueMax(HWND hWnd)
00168 {
00169 MAJ_Value(hWnd,maxValue);
00170 }
00171
00172 void MAJ_ValueMids(HWND hWnd)
00173 {
00174 MAJ_Value(hWnd,(T)((minValue+maxValue)/2.0));
00175 }
00176
00177 void MAJ_Value(HWND hWnd,T _value,BOOL refresh=TRUE)
00178 {
00179 if (value) *value=_value;
00180 if (refresh)
00181 {
00182 MAJ_Value(hWnd);
00183 MAJ_Specials(hWnd);
00184 MAJ_Slider(hWnd);
00185 }
00186 }
00187
00188 void MAJ_Value(HWND hWnd)
00189 {
00190 MyString text;
00191 if (value) text<<*value;
00192 Edit_SetText(GetDlgItem(hWnd,IDC_EDIT_VALUE),text);
00193 }
00194
00195 void Get_Value(HWND hWnd)
00196 {
00197 char text[64];
00198 MyString textTmp;
00199 Edit_GetText(GetDlgItem(hWnd,IDC_EDIT_VALUE),text,64);
00200 textTmp = text;
00201 MAJ_Value(hWnd,(T)textTmp.ToDouble(),FALSE);
00202 }
00203
00204 void MAJ_Slider(HWND hWnd)
00205 {
00206 if (!(this&&value)) return;
00207 BOOL isActive = !(!minValue && maxValue==-1);
00208 Static_Enable(GetDlgItem(hWnd,IDC_SLIDER_PAD),isActive);
00209 double xPos = 0;
00210 xPos = (100.0f*(*value-minValue))/(maxValue-minValue);
00211 SendMessage(GetDlgItem(hWnd,IDC_SLIDER_PAD), TBM_SETPOS, TRUE, (LPARAM)xPos);
00212 }
00213
00214 void MAJ_Specials(HWND hWnd,int num=-1)
00215 {
00216 HWND hWndCtrl = GetDlgItem(hWnd,IDC_COMBO_SPECIALS);
00217 ComboBox_ResetContent(hWndCtrl);
00218 MyString text;
00219 BOOL active = this&&value?TRUE:FALSE;
00220 if (active&&specials.GetNbElem())
00221 {
00222 ComboBox_Enable(hWndCtrl,TRUE);
00223 ComboBox_AddString(hWndCtrl,"<Nothing>");
00224 int numSel = 0;
00225 int numCur = 0;
00226 T valueCur = num==-1?*value:specials[num].value;
00227
00228 for (specials=0;specials.More();specials++)
00229 {
00230 text="";
00231 numCur++;
00232 T valueSpe = specials()->value;
00233 text<<specials()->description<<" (="<<valueSpe<<")";
00234 if (valueCur==valueSpe) numSel=numCur;
00235 ComboBox_AddString(hWndCtrl,text);
00236 }
00237 ComboBox_SetCurSel(hWndCtrl,numSel);
00238 if (num!=-1)
00239 {
00240 *value=valueCur;
00241 MAJ_Value(hWnd);
00242 }
00243 }
00244 else ComboBox_Enable(GetDlgItem(hWnd,IDC_COMBO_SPECIALS),FALSE);
00245 }
00246 void MAJ(HWND hWnd)
00247 {
00248 HWND hWndMin = GetDlgItem(hWnd,IDC_BUTTON_MIN);
00249 HWND hWndMax = GetDlgItem(hWnd,IDC_BUTTON_MAX);
00250 HWND hWndMids = GetDlgItem(hWnd,IDC_BUTTON_MIDS);
00251 HWND hWndValue= GetDlgItem(hWnd,IDC_EDIT_VALUE);
00252 HWND hWndInfo= GetDlgItem(hWnd,IDC_STATIC_VARIABLE);
00253 HWND hWndStaticValue= GetDlgItem(hWnd,IDC_STATIC1);
00254
00255 BOOL active = this&&value?TRUE:FALSE;
00256 if (active)
00257 {
00258 MyString text;
00259 text<<"Value: ["<<minValue<<";"<<maxValue<<"]";
00260 Static_SetText(hWndStaticValue,text);
00261 Static_Enable(hWndStaticValue,TRUE);
00262 Edit_Enable(hWndValue,TRUE);
00263 MAJ_Value(hWnd);
00264 Static_Enable(hWndMin,TRUE);
00265 Static_Enable(hWndMids,TRUE);
00266 Static_Enable(hWndMax,TRUE);
00267 Static_SetText(hWndInfo,info);
00268 }
00269 else
00270 {
00271 Static_SetText(hWndStaticValue,"Value: []");
00272 Edit_SetText(hWndValue,"");
00273 Static_Enable(hWndValue,FALSE);
00274 Static_Enable(hWndMin,FALSE);
00275 Static_Enable(hWndMids,FALSE);
00276 Static_Enable(hWndMax,FALSE);
00277 Static_SetText(hWndInfo,"Select a value to edit it");
00278 }
00279 MAJ_Specials(hWnd);
00280 MAJ_Slider(hWnd);
00281 }
00282 };
00283
00284 LRESULT WINAPI DebugStructProc(HWND hDlg,UINT message,WPARAM wParam,LPARAM lParam);
00285 LRESULT WINAPI ValueEditorProc(HWND hDlg,UINT message,WPARAM wParam,LPARAM lParam);
00286
00287 #endif