From 4ede9cec29698d2ca3b195e764f228c0da44e02c Mon Sep 17 00:00:00 2001 From: Manolo Gouy Date: Mon, 7 May 2018 13:43:28 +0000 Subject: New Fl_Image_Surface::rescale() class function and document equivalence between Fl_Offscreen-based and Fl_Image_Surface-based approaches. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.4@12907 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- src/Fl_Image_Surface.cxx | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) (limited to 'src/Fl_Image_Surface.cxx') diff --git a/src/Fl_Image_Surface.cxx b/src/Fl_Image_Surface.cxx index bcacd2aad..c374c3fda 100644 --- a/src/Fl_Image_Surface.cxx +++ b/src/Fl_Image_Surface.cxx @@ -119,6 +119,21 @@ Fl_Offscreen Fl_Image_Surface::get_offscreen_before_delete_() { return keep; } +/** Adapts an Fl_Image_Surface object to the new value of the GUI scale factor. + \version 1.4 + */ +void Fl_Image_Surface::rescale(Fl_Image_Surface*& surface) { + Fl_RGB_Image *rgb = surface->image(); + int w, h; + surface->printable_rect(&w, &h); + delete surface; + surface = new Fl_Image_Surface(w, h, 1); + Fl_Surface_Device::push_current(surface); + rgb->draw(0,0); + Fl_Surface_Device::pop_current(); + delete rgb; +} + // implementation of the fl_XXX_offscreen() functions static Fl_Image_Surface **offscreen_api_surface = NULL; @@ -148,6 +163,17 @@ static int find_slot(void) { // return an available slot to memorize an Fl_Image The pixel size of the created graphics buffer is equal to the number of pixels in an area of the screen containing the current window sized at \p w,h FLTK units. This pixel size varies with the value of the scale factor of this screen. + \note Work with the fl_XXX_offscreen() functions is equivalent to work with + an Fl_Image_Surface object, as follows : + + + + + + + + +
Fl_Offscreen-based approachFl_Image_Surface-based approach
Fl_Offscreen off = fl_create_offscreen(w, h)Fl_Image_Surface *surface = new Fl_Image_Surface(w, h, 1)
fl_begin_offscreen(off)Fl_Surface_Device::push_current(surface)
fl_end_offscreen()Fl_Surface_Device::pop_current()
fl_copy_offscreen(x,y,w,h, off, sx,sy)fl_copy_offscreen(x,y,w,h, surface->offscreen(), sx,sy)
fl_rescale_offscreen(off)Fl_Image_Surface::rescale(surface)
fl_delete_offscreen(off)delete surface
*/ Fl_Offscreen fl_create_offscreen(int w, int h) { int rank = find_slot(); @@ -196,22 +222,16 @@ void fl_end_offscreen() { value is given by Fl_Graphics_Driver::default_driver().scale(). \version 1.4 */ -void fl_scale_offscreen(Fl_Offscreen &ctx) { - int i, w, h; +void fl_rescale_offscreen(Fl_Offscreen &ctx) { + int i; 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); - ctx = fl_create_offscreen(w, h); - fl_begin_offscreen(ctx); - rgb->draw(0, 0); - fl_end_offscreen(); - delete rgb; + Fl_Image_Surface::rescale(offscreen_api_surface[i]); + ctx = offscreen_api_surface[i]->offscreen(); } /** @} */ -- cgit v1.2.3