コード例 #1
0
ファイル: HsvPicker.cs プロジェクト: the6th/UIWidgets.AddOns
        void slideEvent(RenderBox getBox, BoxConstraints box, Offset globalPosition)
        {
            float localDx  = getBox.globalToLocal(globalPosition).dx - 15f;
            float progress = localDx.clamp(0f, box.maxWidth - 30f) / (box.maxWidth - 30f);

            switch (trackType)
            {
            case TrackType.hue:
                // 360 is the same as zero
                // if set to 360, sliding to end goes to zero
                onColorChanged(hsvColor.withHue(progress * 359));

                break;

            case TrackType.saturation:
                onColorChanged(hsvColor.withSaturation(progress));
                break;

            case TrackType.saturationForHSL:
                onColorChanged(Utils.hslToHsv(Utils.hsvToHsl(hsvColor).withSaturation(progress)));
                break;

            case TrackType.value:
                onColorChanged(hsvColor.withValue(progress));
                break;

            case TrackType.lightness:
                onColorChanged(Utils.hslToHsv(Utils.hsvToHsl(hsvColor).withLightness(progress)));
                break;

            case TrackType.red:
                onColorChanged(HSVColorExtention.fromColor(hsvColor.toColor().withRed((progress * 0xff).round())));
                break;

            case TrackType.green:
                onColorChanged(HSVColorExtention.fromColor(hsvColor.toColor().withGreen((progress * 0xff).round())));
                break;

            case TrackType.blue:
                onColorChanged(HSVColorExtention.fromColor(hsvColor.toColor().withBlue((progress * 0xff).round())));
                break;

            case TrackType.alpha:
                onColorChanged(hsvColor.withAlpha(localDx.clamp(0f, box.maxWidth - 30f) / (box.maxWidth - 30f)));
                break;
            }
        }