aboutsummaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorGravatar Hanspeter Portner <dev@open-music-kontrollers.ch>2018-04-23 19:37:26 +0200
committerGravatar Hanspeter Portner <dev@open-music-kontrollers.ch>2018-04-23 19:37:26 +0200
commit6d838575318990a7287e8c6a95988a1b06d00e33 (patch)
tree68b20370dfb382e857c0262788c3d1633247fdc5 /plugins
parentb6b37d2eac75732c754c7cc5a44fdf4369c4e1ae (diff)
downloadsynthpod-6d838575318990a7287e8c6a95988a1b06d00e33.zip
synthpod-6d838575318990a7287e8c6a95988a1b06d00e33.tar.gz
synthpod-6d838575318990a7287e8c6a95988a1b06d00e33.tar.bz2
synthpod-6d838575318990a7287e8c6a95988a1b06d00e33.tar.xz
nk: fix aspect ratio handling of canvases.
Diffstat (limited to 'plugins')
-rw-r--r--plugins/synthpod_common_nk.c39
1 files changed, 23 insertions, 16 deletions
diff --git a/plugins/synthpod_common_nk.c b/plugins/synthpod_common_nk.c
index 0d8a53a..d18bb46 100644
--- a/plugins/synthpod_common_nk.c
+++ b/plugins/synthpod_common_nk.c
@@ -2097,7 +2097,7 @@ _cairo_init(mod_t *mod, int w, int h)
LV2_Inline_Display_Image_Surface *surf = &mod->cairo.image_surface;
surf->width = w;
- surf->height = w > h ? h : w; // try to use 1:1 ratio
+ surf->height = h;
surf->stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, surf->width);
surf->data = realloc(surf->data, surf->stride * surf->height);
if(!surf->data)
@@ -2151,7 +2151,7 @@ _render(plughandle_t *handle, mod_t *mod, uint32_t w, uint32_t h,
{
LV2_Inline_Display_Image_Surface *surf = &mod->cairo.image_surface;
- float aspect_ratio = 0.f;
+ float aspect_ratio = 1.f;
int W;
int H;
@@ -2161,12 +2161,7 @@ _render(plughandle_t *handle, mod_t *mod, uint32_t w, uint32_t h,
aspect_ratio = param->val.f;
}
- if(aspect_ratio == 0.f)
- {
- W = w;
- H = h;
- }
- else if(aspect_ratio <= 1.f)
+ if(aspect_ratio < 1.f)
{
W = h * aspect_ratio;
H = h;
@@ -2176,6 +2171,11 @@ _render(plughandle_t *handle, mod_t *mod, uint32_t w, uint32_t h,
W = w;
H = w / aspect_ratio;
}
+ else // aspect_ratio == 1.f
+ {
+ W = w;
+ H = h;
+ }
if( (surf->width != W) || (surf->height != H) || !surf->data)
{
@@ -2190,8 +2190,8 @@ _render(plughandle_t *handle, mod_t *mod, uint32_t w, uint32_t h,
// create OpenGl texture from image data
const void *data = mod->cairo.image_surface.data;
- w = mod->cairo.image_surface.width;
- h = mod->cairo.image_surface.height;
+ w = surf->width;
+ h = surf->height;
_image_free(handle, &mod->idisp.img);
mod->idisp.img = _image_new(handle, w, h, data);
@@ -6456,17 +6456,24 @@ _expose_mod(plughandle_t *handle, struct nk_context *ctx, struct nk_rect space_b
if(!_image_empty(&mod->idisp.img))
{
- float w = mod->dim.x;
+ const float aspect = (float)mod->idisp.w / mod->idisp.h;
+ float w;
float h;
- if(mod->idisp.w > w)
+ if(aspect < 1.f)
{
- h = w * mod->idisp.h / mod->idisp.w;
+ h = mod->dim.x;
+ w = h * aspect;
}
- else
+ else if(aspect > 1.f)
+ {
+ w = mod->dim.x;
+ h = w / aspect;
+ }
+ else // aspect == 1.f
{
- w = mod->idisp.w;
- h = mod->idisp.h;
+ w = mod->dim.x;
+ h = mod->dim.x;
}
const struct nk_rect body2 = {