add fillHeight option to setBackgroundImage
This commit is contained in:
@@ -305,7 +305,11 @@ public class SwiftPolyvoxFilamentPlugin: NSObject, FlutterPlugin, FlutterTexture
|
|||||||
clear_background_image(viewer)
|
clear_background_image(viewer)
|
||||||
result(true)
|
result(true)
|
||||||
case "setBackgroundImage":
|
case "setBackgroundImage":
|
||||||
set_background_image(viewer, call.arguments as! String)
|
let args = call.arguments as! [Any];
|
||||||
|
|
||||||
|
let path = args[0] as! String
|
||||||
|
let fillHeight = args[1] as! Bool
|
||||||
|
set_background_image(viewer, path, fillHeight)
|
||||||
result(true)
|
result(true)
|
||||||
case "setBackgroundImagePosition":
|
case "setBackgroundImagePosition":
|
||||||
let args = call.arguments as! [Any]
|
let args = call.arguments as! [Any]
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ namespace polyvox {
|
|||||||
Renderer* getRenderer();
|
Renderer* getRenderer();
|
||||||
|
|
||||||
void setBackgroundColor(const float r, const float g, const float b, const float a);
|
void setBackgroundColor(const float r, const float g, const float b, const float a);
|
||||||
void setBackgroundImage(const char* resourcePath);
|
void setBackgroundImage(const char* resourcePath, bool fillHeight);
|
||||||
void clearBackgroundImage();
|
void clearBackgroundImage();
|
||||||
void setBackgroundImagePosition(float x, float y, bool clamp);
|
void setBackgroundImagePosition(float x, float y, bool clamp);
|
||||||
void setCameraExposure(float aperture, float shutterSpeed, float sensitivity);
|
void setCameraExposure(float aperture, float shutterSpeed, float sensitivity);
|
||||||
|
|||||||
@@ -426,7 +426,7 @@ void FilamentViewer::clearBackgroundImage() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FilamentViewer::setBackgroundImage(const char *resourcePath) {
|
void FilamentViewer::setBackgroundImage(const char *resourcePath, bool fillHeight) {
|
||||||
|
|
||||||
string resourcePathString(resourcePath);
|
string resourcePathString(resourcePath);
|
||||||
|
|
||||||
@@ -440,7 +440,18 @@ void FilamentViewer::setBackgroundImage(const char *resourcePath) {
|
|||||||
// TODO - implement stretch/etc
|
// TODO - implement stretch/etc
|
||||||
const Viewport& vp = _view->getViewport();
|
const Viewport& vp = _view->getViewport();
|
||||||
Log("Image width %d height %d vp width %d height %d", _imageWidth, _imageHeight, vp.width, vp.height);
|
Log("Image width %d height %d vp width %d height %d", _imageWidth, _imageHeight, vp.width, vp.height);
|
||||||
_imageScale = mat4f { float(vp.width) / float(_imageWidth) , 0.0f, 0.0f, 0.0f, 0.0f, float(vp.height) / float(_imageHeight), 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f };
|
|
||||||
|
|
||||||
|
float xScale = float(vp.width) / float(_imageWidth);
|
||||||
|
|
||||||
|
float yScale;
|
||||||
|
if(fillHeight) {
|
||||||
|
yScale = 1.0f;
|
||||||
|
} else {
|
||||||
|
yScale = float(vp.height) / float(_imageHeight);
|
||||||
|
}
|
||||||
|
|
||||||
|
_imageScale = mat4f { xScale , 0.0f, 0.0f, 0.0f, 0.0f, yScale , 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f };
|
||||||
|
|
||||||
_imageMaterial->setDefaultParameter("transform", _imageScale);
|
_imageMaterial->setDefaultParameter("transform", _imageScale);
|
||||||
_imageMaterial->setDefaultParameter("image", _imageTexture, _imageSampler);
|
_imageMaterial->setDefaultParameter("image", _imageTexture, _imageSampler);
|
||||||
|
|||||||
@@ -40,8 +40,8 @@ extern "C" {
|
|||||||
((FilamentViewer*)viewer)->clearBackgroundImage();
|
((FilamentViewer*)viewer)->clearBackgroundImage();
|
||||||
}
|
}
|
||||||
|
|
||||||
FLUTTER_PLUGIN_EXPORT void set_background_image(const void* const viewer, const char* path) {
|
FLUTTER_PLUGIN_EXPORT void set_background_image(const void* const viewer, const char* path, bool fillHeight) {
|
||||||
((FilamentViewer*)viewer)->setBackgroundImage(path);
|
((FilamentViewer*)viewer)->setBackgroundImage(path, fillHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
FLUTTER_PLUGIN_EXPORT void set_background_image_position(const void* const viewer, float x, float y, bool clamp) {
|
FLUTTER_PLUGIN_EXPORT void set_background_image_position(const void* const viewer, float x, float y, bool clamp) {
|
||||||
|
|||||||
@@ -131,11 +131,11 @@ class FilamentController {
|
|||||||
await _channel.invokeMethod("clearBackgroundImage");
|
await _channel.invokeMethod("clearBackgroundImage");
|
||||||
}
|
}
|
||||||
|
|
||||||
Future setBackgroundImage(String path) async {
|
Future setBackgroundImage(String path, {bool fillHeight = false}) async {
|
||||||
if (_viewer == null || _resizing) {
|
if (_viewer == null || _resizing) {
|
||||||
throw Exception("No viewer available, ignoring");
|
throw Exception("No viewer available, ignoring");
|
||||||
}
|
}
|
||||||
await _channel.invokeMethod("setBackgroundImage", path);
|
await _channel.invokeMethod("setBackgroundImage", [path, fillHeight]);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future setBackgroundColor(Color color) async {
|
Future setBackgroundColor(Color color) async {
|
||||||
|
|||||||
Reference in New Issue
Block a user