diff options
| -rw-r--r-- | FL/Fl_Image_Surface.H | 1 | ||||
| -rw-r--r-- | FL/fl_draw.H | 2 | ||||
| -rw-r--r-- | documentation/src/drawing.dox | 2 | ||||
| -rw-r--r-- | src/Fl_Image_Surface.cxx | 40 | ||||
| -rw-r--r-- | test/offscreen.cxx | 2 |
5 files changed, 34 insertions, 13 deletions
diff --git a/FL/Fl_Image_Surface.H b/FL/Fl_Image_Surface.H index fe8d4c2ad..1daf4bc63 100644 --- a/FL/Fl_Image_Surface.H +++ b/FL/Fl_Image_Surface.H @@ -86,6 +86,7 @@ public: void origin(int x, int y); int printable_rect(int *w, int *h); Fl_Offscreen offscreen(); + static void rescale(Fl_Image_Surface*& surf); }; diff --git a/FL/fl_draw.H b/FL/fl_draw.H index c7f3dd8bb..9783f45d0 100644 --- a/FL/fl_draw.H +++ b/FL/fl_draw.H @@ -512,7 +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); +FL_EXPORT void fl_rescale_offscreen(Fl_Offscreen &ctx); /** @} */ diff --git a/documentation/src/drawing.dox b/documentation/src/drawing.dox index d93f1bfe4..046963fb7 100644 --- a/documentation/src/drawing.dox +++ b/documentation/src/drawing.dox @@ -1156,7 +1156,7 @@ void fl_copy_offscreen(int x, int y, int w, int h, Fl_Offscreen osrc, int srcx, Copy a rectangular area of the size \p w*h from \p srcx,srcy in the offscreen buffer into the current drawing surface at \p x,y. -void fl_scale_offscreen(Fl_Offscreen &osrc) +void fl_rescale_offscreen(Fl_Offscreen &osrc) \par Adapts the offscreen's size in pixels to a changed value of the scale factor while keeping the offscreen's graphical content. 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 : + <table> + <tr> <th>Fl_Offscreen-based approach</th><th>Fl_Image_Surface-based approach</th> </tr> + <tr> <td>Fl_Offscreen off = fl_create_offscreen(w, h)</td><td>Fl_Image_Surface *surface = new Fl_Image_Surface(w, h, 1)</td> </tr> + <tr> <td>fl_begin_offscreen(off)</td><td>Fl_Surface_Device::push_current(surface)</td> </tr> + <tr> <td>fl_end_offscreen()</td><td>Fl_Surface_Device::pop_current()</td> </tr> + <tr> <td>fl_copy_offscreen(x,y,w,h, off, sx,sy)</td><td>fl_copy_offscreen(x,y,w,h, surface->offscreen(), sx,sy)</td> </tr> + <tr> <td>fl_rescale_offscreen(off)</td><td>Fl_Image_Surface::rescale(surface)</td> </tr> + <tr> <td>fl_delete_offscreen(off)</td><td>delete surface</td> </tr> + </table> */ 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 <tt>Fl_Graphics_Driver::default_driver().scale()</tt>. \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(); } /** @} */ diff --git a/test/offscreen.cxx b/test/offscreen.cxx index e6780f640..23cd368a6 100644 --- a/test/offscreen.cxx +++ b/test/offscreen.cxx @@ -99,7 +99,7 @@ void oscr_box::draw() { if (scale != Fl_Graphics_Driver::default_driver().scale()) { // the screen scaling factor has changed - fl_scale_offscreen(oscr); + fl_rescale_offscreen(oscr); scale = Fl_Graphics_Driver::default_driver().scale(); } fl_copy_offscreen(xo, yo, wd, ht, oscr, page_x, page_y); |
