void DataFieldBoolean::SetAsFloat(fixed Value) { if (GetAsFixed() != Value) { SetAsBoolean(Value != fixed_zero); } }
ComboList * DataFieldFloat::CreateComboListStepping() { // for DataFieldInteger and DataFieldFloat // builds ComboPopupItemList[] by calling CreateItem for each item in list // sets ComboPopupItemSavedIndex (global) // returns ComboPopupItemCount const fixed ComboListInitValue(-99999); const fixed ComboFloatPrec(0.0001); //rounds float errors to this precision fixed fNext = ComboListInitValue; fixed fCurrent = ComboListInitValue; fixed fLast = ComboListInitValue; TCHAR sTemp[ComboPopupITEMMAX]; int iListCount = 0; int iSelectedIndex = -1; int iStepDirection = 1; // for integer & float step may be negative fixed fBeforeDec = fixed_zero, fAfterDec = fixed_zero, fSavedValue = fixed_zero; fNext = ComboListInitValue; fCurrent = ComboListInitValue; fLast = ComboListInitValue; SetDisableSpeedUp(true); SetDetachGUI(true); // disable display of inc/dec/change values // get step direction for int & float so we can detect if we skipped the value while iterating later TCHAR PropertyValueSaved[ComboPopupITEMMAX]; TCHAR PropertyValueSavedFormatted[ComboPopupITEMMAX]; CopyString(PropertyValueSaved, false); CopyString(PropertyValueSavedFormatted, true); fSavedValue = GetAsFixed(); Inc(); fBeforeDec = GetAsFixed(); Dec(); fAfterDec = GetAsFixed(); if (fAfterDec < fBeforeDec) iStepDirection = 1; else iStepDirection = -1; // reset datafield to top of list (or for large floats, away from selected // item so it will be in the middle) for (iListCount = 0; iListCount < ComboList::MAX_SIZE / 2; iListCount++) { // for floats, go half way down only Dec(); fNext = GetAsFixed(); if (fabs(fNext - fCurrent) < ComboFloatPrec) // we're at start of the list break; if (fabs(fNext - fLast) < ComboFloatPrec) // don't repeat Yes/No/etc (is this needed w/out Bool?) break; fLast = fCurrent; fCurrent = fNext; } fNext = ComboListInitValue; fCurrent = ComboListInitValue; fLast = ComboListInitValue; fCurrent = GetAsFixed(); ComboList *combo_list = new ComboList(); // if we stopped before hitting start of list create <<Less>> value at top of list if (iListCount == ComboList::MAX_SIZE / 2) { // this data index item is checked on close of dialog combo_list->Append(ComboList::Item::PREVIOUS_PAGE, _T("<<More Items>>")); } // now we're at the beginning of the list, so load forward until end for (iListCount = 0; iListCount < ComboList::MAX_SIZE - 3; iListCount++) { // stop at LISTMAX-3 b/c it may make an additional item if it's "off step", and // potentially two more items for <<More>> and << Less>> // test if we've stepped over the selected value which was not a multiple of the "step" if (iSelectedIndex == -1) { // not found yet if (iStepDirection * GetAsFixed() > (fSavedValue + ComboFloatPrec * iStepDirection)) { // step was too large, we skipped the selected value, so add it now iSelectedIndex = combo_list->Append(0, PropertyValueSaved, PropertyValueSavedFormatted); } } if (iSelectedIndex == -1 && fabs(fCurrent - fSavedValue) < ComboFloatPrec) { // selected item index iSelectedIndex = combo_list->size(); } CopyString(sTemp, true); // can't call GetAsString & GetAsStringFormatted together (same output buffer) combo_list->Append(0, GetAsString(), sTemp); Inc(); fNext = GetAsFixed(); if (fabs(fNext - fCurrent) < ComboFloatPrec) // we're at start of the list break; if ((fabs(fNext - fLast) < ComboFloatPrec) && combo_list->size() > 0) //we're at the end of the range break; fLast = fCurrent; fCurrent = fNext; } // if we stopped before hitting end of list create <<More>> value at end of list if (iListCount == ComboList::MAX_SIZE - 3) { // this data index item is checked on close of dialog combo_list->Append(ComboList::Item::NEXT_PAGE, _T("<<More Items>>")); } SetDisableSpeedUp(false); SetDetachGUI(false); // disable dispaly of inc/dec/change values if (iSelectedIndex >= 0) SetAsFloat(fSavedValue); combo_list->ComboPopupItemSavedIndex = iSelectedIndex; return combo_list; }