Пример #1
0
        private static void Test(int minData, int maxData, int minProxy, int maxProxy)
        {
            LogarithmicMapper mapper = new LogarithmicMapper(minData, maxData, minProxy, maxProxy);

            int m1 = mapper.Map(minData);
            int m2 = mapper.Map(maxData);
            int u1 = mapper.Unmap(minProxy);
            int u2 = mapper.Unmap(maxProxy);

            log.Debug("----------------------------------------");
            log.DebugFormat("data:[{0}..{1}], proxy:[{2}..{3}]", minData, maxData, minProxy, maxProxy);
            log.DebugFormat("data:{0}, proxy:{1}", minData, m1);
            log.DebugFormat("data:{0}, proxy:{1}", maxData, m2);
            log.DebugFormat("proxy:{0}, data:{1}", minProxy, u1);
            log.DebugFormat("proxy:{0}, data:{1}", maxProxy, u2);

            /*
             * //int m3 = mapper.Map((maxData - minData) / 2);
             * //int u3 = mapper.Unmap((maxProxy - minProxy) / 2);
             *
             * int m4 = mapper.Map(0);
             * int m5 = mapper.Map(1001);
             * int u4 = mapper.Unmap(0);
             * int u5 = mapper.Unmap(11);*/
        }
        private void Populate()
        {
            cbAuto.Enabled = property.CanBeAutomatic;

            double min       = double.Parse(property.Minimum, CultureInfo.InvariantCulture);
            double max       = double.Parse(property.Maximum, CultureInfo.InvariantCulture);
            int    minValue  = (int)Math.Max(1, min);
            int    maxValue  = (int)max;
            int    sliderMin = 1;
            int    sliderMax = 10000;

            logMapper = new LogarithmicMapper(minValue, maxValue, sliderMin, sliderMax);

            double value       = double.Parse(property.CurrentValue, CultureInfo.InvariantCulture);
            int    sliderValue = logMapper.Map((int)value);

            updatingValue   = true;
            nud.Minimum     = minValue;
            nud.Maximum     = maxValue;
            nud.Value       = (int)value;
            tbValue.Minimum = sliderMin;
            tbValue.Maximum = sliderMax;
            tbValue.Value   = sliderValue;
            cbAuto.Checked  = property.Automatic;
            updatingValue   = false;

            lblValue.Text = valueMapper((int)value);
        }
        private void nud_ValueChanged(object sender, EventArgs e)
        {
            if (updatingValue)
            {
                return;
            }

            int    numericValue = (int)nud.Value;
            string strValue     = numericValue.ToString(CultureInfo.InvariantCulture);

            property.CurrentValue = strValue;
            lblValue.Text         = valueMapper(numericValue);

            property.Automatic = false;

            updatingValue  = true;
            cbAuto.Checked = property.Automatic;
            tbValue.Value  = logMapper.Map(numericValue);
            updatingValue  = false;

            RaiseValueChanged();
        }