diff options
| -rw-r--r-- | FL/fl_draw.H | 1 | ||||
| -rw-r--r-- | src/Fl_Image_Surface.cxx | 24 | ||||
| -rw-r--r-- | test/offscreen.cxx | 4 |
3 files changed, 26 insertions, 3 deletions
diff --git a/FL/fl_draw.H b/FL/fl_draw.H index d312ff191..9e0c37844 100644 --- a/FL/fl_draw.H +++ b/FL/fl_draw.H @@ -512,6 +512,7 @@ FL_EXPORT Fl_Offscreen fl_create_offscreen(int w, int h); FL_EXPORT void fl_begin_offscreen(Fl_Offscreen b); FL_EXPORT void fl_end_offscreen(void); FL_EXPORT void fl_delete_offscreen(Fl_Offscreen bitmap); +FL_EXPORT void fl_scale_offscreen(Fl_Offscreen &ctx); /** @} */ diff --git a/src/Fl_Image_Surface.cxx b/src/Fl_Image_Surface.cxx index c45ddbc16..63b0c18fc 100644 --- a/src/Fl_Image_Surface.cxx +++ b/src/Fl_Image_Surface.cxx @@ -178,6 +178,30 @@ void fl_end_offscreen() { Fl_Surface_Device::pop_current(); } +/** Adapts an offscreen buffer to a changed value of the graphical scaling factor. + The \p ctx argument must have been created by fl_create_offscreen() + and the calling context must not be between fl_begin_offscreen() and fl_end_offscreen(). + */ +void fl_scale_offscreen(Fl_Offscreen &ctx) { + int i, w, h; + for (i = 0; i < count_offscreens; i++) { + if (offscreen_api_surface[i] && offscreen_api_surface[i]->offscreen() == ctx) { + break; + } + } + if (i >= count_offscreens) return; + Fl_RGB_Image *rgb = offscreen_api_surface[i]->image(); + offscreen_api_surface[i]->printable_rect(&w, &h); + fl_delete_offscreen(ctx); + Fl_Shared_Image *shared = Fl_Shared_Image::get(rgb); + shared->scale(w, h, 0, 1); + ctx = fl_create_offscreen(w, h); + fl_begin_offscreen(ctx); + shared->draw(0, 0); + fl_end_offscreen(); + shared->release(); +} + /** @} */ diff --git a/test/offscreen.cxx b/test/offscreen.cxx index 91e0174ef..bcb140f49 100644 --- a/test/offscreen.cxx +++ b/test/offscreen.cxx @@ -114,9 +114,7 @@ int oscr_box::handle(int ev) int ret = Fl_Box::handle(ev); if (ev == FL_HIDE && oscr) { - fl_delete_offscreen(oscr); - oscr = 0; - iters = num_iterations + 1; + fl_scale_offscreen(oscr); } // handle dragging of visible page area - if a valid context exists if (has_oscr()) |
