Skip to content

Commit

Permalink
use Std.int rather than Math.round
Browse files Browse the repository at this point in the history
  • Loading branch information
ianharrigan committed Mar 31, 2024
1 parent 9db6022 commit 2aa0071
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions haxe/ui/components/ColorPicker.hx
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,10 @@ private class HSVColorPickerImpl extends ColorPickerImpl {
var isDisabled = picker.disabled;
var stepX = 100 / cx;
var stepY = 100 / cy;
var l = cx * 4;
for (y in 0...cy) {
for (x in 0...cx) {
var i:Int = y * (cx * 4) + x * 4;
var i:Int = y * l + x * 4;
var pixel = ColorUtil.hsvToRGBF(_currentColorHSV.h - 1, (x + 1) * stepX, 100 - (y * stepY));
if (isDisabled) {
var greypixel = ColorUtil.rgbToGray(Math.round(pixel.r), Math.round(pixel.g), Math.round(pixel.b));
Expand All @@ -266,9 +267,9 @@ private class HSVColorPickerImpl extends ColorPickerImpl {
_saturationValueGraphBytes.set(i + 2, greypixel);
_saturationValueGraphBytes.set(i + 3, 0xFF);
} else {
_saturationValueGraphBytes.set(i + 0, Math.round(pixel.r));
_saturationValueGraphBytes.set(i + 1, Math.round(pixel.g));
_saturationValueGraphBytes.set(i + 2, Math.round(pixel.b));
_saturationValueGraphBytes.set(i + 0, Std.int(pixel.r));
_saturationValueGraphBytes.set(i + 1, Std.int(pixel.g));
_saturationValueGraphBytes.set(i + 2, Std.int(pixel.b));
_saturationValueGraphBytes.set(i + 3, 0xFF);
}
}
Expand Down Expand Up @@ -307,9 +308,10 @@ private class HSVColorPickerImpl extends ColorPickerImpl {

var isDisabled = picker.disabled;
var step = 360 / cx;
var l = cx * 4;
for (y in 0...cy) {
for (x in 0...cx) {
var i:Int = y * (cx * 4) + x * 4;
var i:Int = y * l + x * 4;
var c = ColorUtil.hsvToRGBF(x * step, 100, 100);
if (isDisabled) {
var greypixel = ColorUtil.rgbToGray(Math.round(c.r), Math.round(c.g), Math.round(c.b));
Expand All @@ -318,9 +320,9 @@ private class HSVColorPickerImpl extends ColorPickerImpl {
_hueGraphBytes.set(i + 2, greypixel);
_hueGraphBytes.set(i + 3, 0xFF);
} else {
_hueGraphBytes.set(i + 0, Math.round(c.r));
_hueGraphBytes.set(i + 1, Math.round(c.g));
_hueGraphBytes.set(i + 2, Math.round(c.b));
_hueGraphBytes.set(i + 0, Std.int(c.r));
_hueGraphBytes.set(i + 1, Std.int(c.g));
_hueGraphBytes.set(i + 2, Std.int(c.b));
_hueGraphBytes.set(i + 3, 0xFF);
}
}
Expand Down

0 comments on commit 2aa0071

Please sign in to comment.