예제 #1
0
        private void updateFilters()
        {
            int world, id;

            if (cbxForce.Enabled && cbxForce.Checked)
            {
                Filter filter = (Filter)cmbFilter.SelectedItem;
                world = filter.World;
                id    = filter.ID;
            }
            else
            {
                world = dsrProcess.GetWorld();
                id    = dsrProcess.GetFilter();
            }

            if (world != 255 && (world != lastWorld || id != lastFilter))
            {
                lastWorld  = world;
                lastFilter = id;

                Filter activeFilter  = activeProfile.GetActiveFilter(world, id);
                Filter appliedFilter = activeProfile.GetAppliedFilter(world, id);
                if (activeFilter == null || appliedFilter == null)
                {
                    if (unknownFilter > 0)
                    {
                        unknownFilter--;
                    }
                    else if (unknownFilter == 0)
                    {
                        txtError.Text = "Unknown filter: " + world + ", " + id;
                        unknownFilter = -1;
                    }
                }
                else
                {
                    unknownFilter = UNKNOWN_FILTER_TIMEOUT;

                    if (cbxShowActive.Checked)
                    {
                        editingFilter          = true;
                        cmbFilter.SelectedItem = activeFilter;
                        editingFilter          = false;
                    }

                    Filter filter;
                    if (cbxForce.Enabled && cbxForce.Checked)
                    {
                        filter = (Filter)cmbFilter.SelectedItem;
                    }
                    else
                    {
                        filter = appliedFilter;
                    }

                    long now = DateTimeOffset.Now.ToUnixTimeMilliseconds();
                    // Instant reset
                    if (newFilter == null)
                    {
                        newFilter = filter;
                    }
                    // Normal fade
                    else if (oldFilter == null)
                    {
                        oldFilter = newFilter;
                        newFilter = filter;
                    }
                    // Interrupt fade in progress
                    else
                    {
                        oldFilter = Filter.Lerp(oldFilter, newFilter, (float)(now - startTime) / (endTime - startTime));
                        newFilter = filter;
                    }
                    startTime = now;
                    endTime   = now + FADE_TIME;
                }
            }

            if (newFilter != null)
            {
                long   now = DateTimeOffset.Now.ToUnixTimeMilliseconds();
                Filter filter;
                if (oldFilter == null || now > endTime)
                {
                    filter    = newFilter;
                    oldFilter = null;
                }
                else
                {
                    filter = Filter.Lerp(oldFilter, newFilter, (float)(now - startTime) / (endTime - startTime));
                }

                if (!cbxDisable.Checked)
                {
                    dsrProcess.SetFilterValues(filter.BrightnessR, filter.BrightnessG, filter.BrightnessB,
                                               filter.ContrastR, filter.ContrastG, filter.ContrastB, filter.Saturation, filter.Hue);
                    dsrProcess.SetFilterOverride(true);
                }
            }
        }