Skip to content

Commit

Permalink
BitmapImage: added pixelSnapping and smoothing properties
Browse files Browse the repository at this point in the history
  • Loading branch information
joshtynjala committed Jan 13, 2025
1 parent 51e42d6 commit a1ff43e
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions src/feathers/controls/BitmapImage.hx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

package feathers.controls;

import openfl.display.PixelSnapping;
import feathers.core.FeathersControl;
import feathers.core.IValidating;
import feathers.layout.Measurements;
Expand All @@ -34,11 +35,13 @@ class BitmapImage extends FeathersControl {
@since 1.4.0
**/
public function new(?source:BitmapData) {
public function new(?source:BitmapData, pixelSnapping:PixelSnapping = AUTO, smoothing:Bool = false) {
initializeBitmapImageTheme();
super();

this.source = source;
this.pixelSnapping = pixelSnapping;
this.smoothing = smoothing;
}

private var content:Bitmap;
Expand Down Expand Up @@ -187,6 +190,18 @@ class BitmapImage extends FeathersControl {
return this._scaleMode;
}

/**
@see [`openfl.display.Bitmap.pixelSnapping`](https://api.openfl.org/openfl/display/Bitmap.html#pixelSnapping)
**/
@:style
public var pixelSnapping:PixelSnapping = AUTO;

/**
@see [`openfl.display.Bitmap.smoothing`](https://api.openfl.org/openfl/display/Bitmap.html#smoothing)
**/
@:style
public var smoothing:Bool = false;

private function initializeBitmapImageTheme():Void {
#if !feathersui_disable_default_theme
feathers.themes.steel.components.SteelBitmapImageStyles.initialize();
Expand All @@ -199,6 +214,16 @@ class BitmapImage extends FeathersControl {
}

override private function update():Void {
var dataInvalid = this.isInvalid(DATA);
var stylesInvalid = this.isInvalid(STYLES);

if (dataInvalid || stylesInvalid) {
if (this.content != null) {
this.content.pixelSnapping = this.pixelSnapping;
this.content.smoothing = this.smoothing;
}
}

this.measure();
this.layoutChildren();
}
Expand Down Expand Up @@ -354,6 +379,6 @@ class BitmapImage extends FeathersControl {
}

private function createBitmap(bitmapData:BitmapData):Bitmap {
return new Bitmap(bitmapData);
return new Bitmap(bitmapData, this.pixelSnapping, this.smoothing);
}
}

0 comments on commit a1ff43e

Please sign in to comment.