mirror of
https://github.com/fltk/fltk.git
synced 2026-06-04 15:32:12 +08:00
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
This commit is contained in:
@@ -86,6 +86,7 @@ public:
|
|||||||
void origin(int x, int y);
|
void origin(int x, int y);
|
||||||
int printable_rect(int *w, int *h);
|
int printable_rect(int *w, int *h);
|
||||||
Fl_Offscreen offscreen();
|
Fl_Offscreen offscreen();
|
||||||
|
static void rescale(Fl_Image_Surface*& surf);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -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_begin_offscreen(Fl_Offscreen b);
|
||||||
FL_EXPORT void fl_end_offscreen(void);
|
FL_EXPORT void fl_end_offscreen(void);
|
||||||
FL_EXPORT void fl_delete_offscreen(Fl_Offscreen bitmap);
|
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);
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
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.
|
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
|
\par
|
||||||
Adapts the offscreen's size in pixels to a changed value of the scale factor
|
Adapts the offscreen's size in pixels to a changed value of the scale factor
|
||||||
while keeping the offscreen's graphical content.
|
while keeping the offscreen's graphical content.
|
||||||
|
|||||||
+30
-10
@@ -119,6 +119,21 @@ Fl_Offscreen Fl_Image_Surface::get_offscreen_before_delete_() {
|
|||||||
return keep;
|
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
|
// implementation of the fl_XXX_offscreen() functions
|
||||||
|
|
||||||
static Fl_Image_Surface **offscreen_api_surface = NULL;
|
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
|
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.
|
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.
|
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) {
|
Fl_Offscreen fl_create_offscreen(int w, int h) {
|
||||||
int rank = find_slot();
|
int rank = find_slot();
|
||||||
@@ -196,22 +222,16 @@ void fl_end_offscreen() {
|
|||||||
value is given by <tt>Fl_Graphics_Driver::default_driver().scale()</tt>.
|
value is given by <tt>Fl_Graphics_Driver::default_driver().scale()</tt>.
|
||||||
\version 1.4
|
\version 1.4
|
||||||
*/
|
*/
|
||||||
void fl_scale_offscreen(Fl_Offscreen &ctx) {
|
void fl_rescale_offscreen(Fl_Offscreen &ctx) {
|
||||||
int i, w, h;
|
int i;
|
||||||
for (i = 0; i < count_offscreens; i++) {
|
for (i = 0; i < count_offscreens; i++) {
|
||||||
if (offscreen_api_surface[i] && offscreen_api_surface[i]->offscreen() == ctx) {
|
if (offscreen_api_surface[i] && offscreen_api_surface[i]->offscreen() == ctx) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (i >= count_offscreens) return;
|
if (i >= count_offscreens) return;
|
||||||
Fl_RGB_Image *rgb = offscreen_api_surface[i]->image();
|
Fl_Image_Surface::rescale(offscreen_api_surface[i]);
|
||||||
offscreen_api_surface[i]->printable_rect(&w, &h);
|
ctx = offscreen_api_surface[i]->offscreen();
|
||||||
fl_delete_offscreen(ctx);
|
|
||||||
ctx = fl_create_offscreen(w, h);
|
|
||||||
fl_begin_offscreen(ctx);
|
|
||||||
rgb->draw(0, 0);
|
|
||||||
fl_end_offscreen();
|
|
||||||
delete rgb;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|||||||
+1
-1
@@ -99,7 +99,7 @@ void oscr_box::draw()
|
|||||||
{
|
{
|
||||||
if (scale != Fl_Graphics_Driver::default_driver().scale()) {
|
if (scale != Fl_Graphics_Driver::default_driver().scale()) {
|
||||||
// the screen scaling factor has changed
|
// the screen scaling factor has changed
|
||||||
fl_scale_offscreen(oscr);
|
fl_rescale_offscreen(oscr);
|
||||||
scale = Fl_Graphics_Driver::default_driver().scale();
|
scale = Fl_Graphics_Driver::default_driver().scale();
|
||||||
}
|
}
|
||||||
fl_copy_offscreen(xo, yo, wd, ht, oscr, page_x, page_y);
|
fl_copy_offscreen(xo, yo, wd, ht, oscr, page_x, page_y);
|
||||||
|
|||||||
Reference in New Issue
Block a user