From 18bcefe83be64d389702be04944f27cc7919e1f2 Mon Sep 17 00:00:00 2001 From: StapleButter Date: Thu, 7 Dec 2017 02:41:46 +0100 Subject: [PATCH] libui: add parameter to uiDrawBitmapDraw() to specify filtering --- src/libui_sdl/libui/ui.h | 2 +- src/libui_sdl/libui/unix/draw.c | 4 ++-- src/libui_sdl/libui/windows/draw.cpp | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/libui_sdl/libui/ui.h b/src/libui_sdl/libui/ui.h index 908574d6..f9923f89 100644 --- a/src/libui_sdl/libui/ui.h +++ b/src/libui_sdl/libui/ui.h @@ -505,7 +505,7 @@ _UI_EXTERN void uiDrawRestore(uiDrawContext *c); // bitmap API _UI_EXTERN uiDrawBitmap* uiDrawNewBitmap(uiDrawContext* c, int width, int height); _UI_EXTERN void uiDrawBitmapUpdate(uiDrawBitmap* bmp, const void* data); -_UI_EXTERN void uiDrawBitmapDraw(uiDrawContext* c, uiDrawBitmap* bmp, uiRect* srcrect, uiRect* dstrect); +_UI_EXTERN void uiDrawBitmapDraw(uiDrawContext* c, uiDrawBitmap* bmp, uiRect* srcrect, uiRect* dstrect, bool filter); _UI_EXTERN void uiDrawFreeBitmap(uiDrawBitmap* bmp); // TODO manage the use of Text, Font, and TextFont, and of the uiDrawText prefix in general diff --git a/src/libui_sdl/libui/unix/draw.c b/src/libui_sdl/libui/unix/draw.c index cbdffea3..cf5ce7c8 100644 --- a/src/libui_sdl/libui/unix/draw.c +++ b/src/libui_sdl/libui/unix/draw.c @@ -185,10 +185,9 @@ void uiDrawBitmapUpdate(uiDrawBitmap* bmp, const void* data) cairo_surface_mark_dirty(bmp->bmp); } -void uiDrawBitmapDraw(uiDrawContext* c, uiDrawBitmap* bmp, uiRect* srcrect, uiRect* dstrect) +void uiDrawBitmapDraw(uiDrawContext* c, uiDrawBitmap* bmp, uiRect* srcrect, uiRect* dstrect, bool filter) { cairo_save(c->cr); - cairo_rectangle(c->cr, dstrect->X, dstrect->Y, dstrect->Width, dstrect->Height); cairo_translate(c->cr, dstrect->X, dstrect->Y); @@ -201,6 +200,7 @@ void uiDrawBitmapDraw(uiDrawContext* c, uiDrawBitmap* bmp, uiRect* srcrect, uiRe } cairo_set_source_surface(c->cr, bmp->bmp, -srcrect->X, -srcrect->Y); + cairo_pattern_set_filter(cairo_get_source(c->cr), filter ? CAIRO_FILTER_BILINEAR : CAIRO_FILTER_NEAREST); cairo_clip(c->cr); cairo_paint(c->cr); diff --git a/src/libui_sdl/libui/windows/draw.cpp b/src/libui_sdl/libui/windows/draw.cpp index 84b43c58..5294e553 100644 --- a/src/libui_sdl/libui/windows/draw.cpp +++ b/src/libui_sdl/libui/windows/draw.cpp @@ -555,12 +555,12 @@ void uiDrawBitmapUpdate(uiDrawBitmap* bmp, const void* data) bmp->bmp->CopyFromMemory(&rekt, data, bmp->Stride); } -void uiDrawBitmapDraw(uiDrawContext* c, uiDrawBitmap* bmp, uiRect* srcrect, uiRect* dstrect) +void uiDrawBitmapDraw(uiDrawContext* c, uiDrawBitmap* bmp, uiRect* srcrect, uiRect* dstrect, bool filter) { D2D_RECT_F _srcrect = D2D1::RectF(srcrect->X, srcrect->Y, srcrect->X+srcrect->Width, srcrect->Y+srcrect->Height); D2D_RECT_F _dstrect = D2D1::RectF(dstrect->X, dstrect->Y, dstrect->X+dstrect->Width, dstrect->Y+dstrect->Height); - c->rt->DrawBitmap(bmp->bmp, &_dstrect, 1.0f, D2D1_BITMAP_INTERPOLATION_MODE_LINEAR, &_srcrect); + c->rt->DrawBitmap(bmp->bmp, &_dstrect, 1.0f, filter ? D2D1_BITMAP_INTERPOLATION_MODE_LINEAR : D2D1_BITMAP_INTERPOLATION_MODE_NEAREST_NEIGHBOR, &_srcrect); } void uiDrawFreeBitmap(uiDrawBitmap* bmp)