Skip to content

Commit

Permalink
Add Fl_Shared_Image *Fl_Image_Surface::highres_image() to draw into h…
Browse files Browse the repository at this point in the history
…igh-resolution bitmap.

Also, change arguments of void Fl_Window::capture_titlebar_and_borders() from
Fl_RGB_Image to F_Shared_Image so, in the future, scaled images having
a drawing size distinct from a pixel size can be returned, to support
high-resolution displays.

git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3-porting@11159 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
  • Loading branch information
Manolo Gouy authored and Manolo Gouy committed Feb 12, 2016
1 parent bc83464 commit bf7c25a
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 40 deletions.
3 changes: 2 additions & 1 deletion FL/Fl_Window.H
Expand Up @@ -35,6 +35,7 @@

class Fl_X;
class Fl_RGB_Image;
class Fl_Shared_Image;


/**
Expand Down Expand Up @@ -97,7 +98,7 @@ class FL_EXPORT Fl_Window : public Fl_Group {
// cursor stuff
Fl_Cursor cursor_default;
// Captures the titlebar and borders of the window, if they exist.
void capture_titlebar_and_borders(Fl_RGB_Image*& top, Fl_RGB_Image*& left, Fl_RGB_Image*& bottom, Fl_RGB_Image*& right);
void capture_titlebar_and_borders(Fl_Shared_Image*& top, Fl_Shared_Image*& left, Fl_Shared_Image*& bottom, Fl_Shared_Image*& right);

protected:
/** Data supporting a non-rectangular window shape */
Expand Down
23 changes: 10 additions & 13 deletions src/Fl_Paged_Device.cxx
Expand Up @@ -20,6 +20,7 @@
*/

#include <FL/Fl_Paged_Device.H>
#include <FL/Fl_Shared_Image.H>
#include <FL/Fl.H>
#include <FL/fl_draw.H>

Expand Down Expand Up @@ -300,29 +301,25 @@ const Fl_Paged_Device::page_format Fl_Paged_Device::page_formats[NO_PAGE_FORMATS

void Fl_Paged_Device::draw_decorated_window(Fl_Window *win, int x_offset, int y_offset)
{
Fl_RGB_Image *top, *left, *bottom, *right;
Fl_Shared_Image *top, *left, *bottom, *right;
win->capture_titlebar_and_borders(top, left, bottom, right);
int wsides = left ? left->w() : 0;
int toph = top ? top->h() : 0;
if (top) {
#ifdef __APPLE__ // PORTME: platform paged device
top->draw(x_offset, y_offset); // draw with transparency
#else
fl_draw_image(top->array, x_offset, y_offset, top->w(), top->h(), top->d());
#endif // __APPLE__ // PORTME: platform paged device
delete top;
top->draw(x_offset, y_offset);
top->release();
}
if (left) {
fl_draw_image(left->array, x_offset, y_offset + toph, left->w(), left->h(), left->d());
delete left;
left->draw(x_offset, y_offset);
left->release();
}
if (right) {
fl_draw_image(right->array, x_offset + win->w() + wsides, y_offset + toph, right->w(), right->h(), right->d());
delete right;
right->draw(x_offset, y_offset);
right->release();
}
if (bottom) {
fl_draw_image(bottom->array, x_offset, y_offset + toph + win->h(), bottom->w(), bottom->h(), bottom->d());
delete bottom;
bottom->draw(x_offset, y_offset);
bottom->release();
}
this->print_widget(win, x_offset + wsides, y_offset + toph);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Fl_Window.cxx
Expand Up @@ -475,7 +475,7 @@ void Fl_Window::wait_for_expose() {

#if defined(FL_PORTING)
# pragma message "FL_PORTING: implement Fl_Window::capture_titlebar_and_borders"
void Fl_Window::capture_titlebar_and_borders(Fl_RGB_Image*& top, Fl_RGB_Image*& left, Fl_RGB_Image*& bottom, Fl_RGB_Image*& right)
void Fl_Window::capture_titlebar_and_borders(Fl_Shared_Image*& top, Fl_Shared_Image*& left, Fl_Shared_Image*& bottom, Fl_Shared_Image*& right)
{
top = left = bottom = right = NULL;
}
Expand Down
15 changes: 8 additions & 7 deletions src/Fl_cocoa.mm
Expand Up @@ -41,6 +41,7 @@
#include <FL/Fl_Tooltip.H>
#include <FL/Fl_Printer.H>
#include <FL/Fl_Copy_Surface.H>
#include <FL/Fl_Shared_Image.H>
#include "drivers/Quartz/Fl_Quartz_Graphics_Driver.h"
#include "drivers/Cocoa/Fl_Cocoa_Screen_Driver.h"
#include <stdio.h>
Expand Down Expand Up @@ -4400,7 +4401,7 @@ static void draw_layer_to_context(CALayer *layer, CGContextRef gc, int w, int h)
/* Returns images of the capture of the window title-bar.
On the Mac OS platform, left, bottom and right are returned NULL; top is returned with depth 4.
*/
void Fl_Window::capture_titlebar_and_borders(Fl_RGB_Image*& top, Fl_RGB_Image*& left, Fl_RGB_Image*& bottom, Fl_RGB_Image*& right)
void Fl_Window::capture_titlebar_and_borders(Fl_Shared_Image*& top, Fl_Shared_Image*& left, Fl_Shared_Image*& bottom, Fl_Shared_Image*& right)
{
left = bottom = right = NULL;
int htop = decorated_h() - h();
Expand All @@ -4409,19 +4410,19 @@ static void draw_layer_to_context(CALayer *layer, CGContextRef gc, int w, int h)
uchar *rgba = new uchar[4 * w() * htop];
CGContextRef auxgc = CGBitmapContextCreate(rgba, w(), htop, 8, 4 * w(), cspace, kCGImageAlphaPremultipliedLast);
CGColorSpaceRelease(cspace);
CGRect rect = CGRectMake(0, 0, w(), htop);
if (layer) {
draw_layer_to_context(layer, auxgc, w(), htop);
} else {
CGImageRef img = Fl_X::CGImage_from_window_rect(this, 0, -htop, w(), htop);
CGContextSaveGState(auxgc);
Fl_X::clip_to_rounded_corners(auxgc, w(), htop);
CGContextDrawImage(auxgc, rect, img);
CGContextDrawImage(auxgc, CGRectMake(0, 0, w(), htop), img);
CGContextRestoreGState(auxgc);
CFRelease(img);
}
top = new Fl_RGB_Image(rgba, w(), htop, 4);
top->alloc_array = 1;
Fl_RGB_Image *toprgb = new Fl_RGB_Image(rgba, w(), htop, 4);
toprgb->alloc_array = 1;
top = Fl_Shared_Image::get(toprgb);
CGContextRelease(auxgc);
}

Expand Down Expand Up @@ -4472,12 +4473,12 @@ static void draw_layer_to_context(CALayer *layer, CGContextRef gc, int w, int h)
fl_gc = NULL;
Fl::check();
// capture the window title bar with no title
Fl_RGB_Image *top, *left, *bottom, *right;
Fl_Shared_Image *top, *left, *bottom, *right;
win->capture_titlebar_and_borders(top, left, bottom, right);
win->label(title); // put back the window title
this->set_current(); // back to the Fl_Paged_Device
top->draw(x_offset, y_offset); // print the title bar
delete top;
top->release();
if (title) { // print the window title
const int skip = 65; // approx width of the zone of the 3 window control buttons
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
Expand Down
24 changes: 15 additions & 9 deletions src/Fl_win32.cxx
Expand Up @@ -30,6 +30,7 @@
#include <FL/Enumerations.H>
#include <FL/Fl_Tooltip.H>
#include <FL/Fl_Paged_Device.H>
#include <FL/Fl_Shared_Image.H>
#include "flstring.h"
#include "Fl_Font.H"
#include <stdio.h>
Expand Down Expand Up @@ -2709,8 +2710,9 @@ int Fl_Window::decorated_h()
On the WIN32 platform, this function exploits a feature of fl_read_image() which, when called
with NULL first argument and when fl_gc is set to the screen device context, captures the window decoration.
*/
void Fl_Window::capture_titlebar_and_borders(Fl_RGB_Image*& top, Fl_RGB_Image*& left, Fl_RGB_Image*& bottom, Fl_RGB_Image*& right)
void Fl_Window::capture_titlebar_and_borders(Fl_Shared_Image*& top, Fl_Shared_Image*& left, Fl_Shared_Image*& bottom, Fl_Shared_Image*& right)
{
Fl_RGB_Image *r_top, *r_left, *r_bottom, *r_right;
top = left = bottom = right = NULL;
if (!shown() || parent() || !border() || !visible()) return;
int wsides, hbottom, bt;
Expand All @@ -2730,19 +2732,23 @@ void Fl_Window::capture_titlebar_and_borders(Fl_RGB_Image*& top, Fl_RGB_Image*&
uchar *rgb;
if (htop) {
rgb = fl_read_image(NULL, r.left, r.top, ww, htop);
top = new Fl_RGB_Image(rgb, ww, htop, 3);
top->alloc_array = 1;
r_top = new Fl_RGB_Image(rgb, ww, htop, 3);
r_top->alloc_array = 1;
top = Fl_Shared_Image::get(r_top);
}
if (wsides) {
rgb = fl_read_image(NULL, r.left, r.top + htop, wsides, h());
left = new Fl_RGB_Image(rgb, wsides, h(), 3);
left->alloc_array = 1;
r_left = new Fl_RGB_Image(rgb, wsides, h(), 3);
r_left->alloc_array = 1;
left = Fl_Shared_Image::get(r_left);
rgb = fl_read_image(NULL, r.right - wsides, r.top + htop, wsides, h());
right = new Fl_RGB_Image(rgb, wsides, h(), 3);
right->alloc_array = 1;
r_right = new Fl_RGB_Image(rgb, wsides, h(), 3);
r_right->alloc_array = 1;
right = Fl_Shared_Image::get(r_right);
rgb = fl_read_image(NULL, r.left, r.bottom-hbottom, ww, hbottom);
bottom = new Fl_RGB_Image(rgb, ww, hbottom, 3);
bottom->alloc_array = 1;
r_bottom = new Fl_RGB_Image(rgb, ww, hbottom, 3);
r_bottom->alloc_array = 1;
bottom = Fl_Shared_Image::get(r_bottom);
}
ReleaseDC(NULL, fl_gc);
fl_window = save_win;
Expand Down
23 changes: 14 additions & 9 deletions src/Fl_x.cxx
Expand Up @@ -2981,8 +2981,9 @@ int Fl_Window::decorated_w()
On the X11 platform, this function exploits a feature of fl_read_image() which, when called
with negative 4th argument, captures the window decoration.
*/
void Fl_Window::capture_titlebar_and_borders(Fl_RGB_Image*& top, Fl_RGB_Image*& left, Fl_RGB_Image*& bottom, Fl_RGB_Image*& right)
void Fl_Window::capture_titlebar_and_borders(Fl_Shared_Image*& top, Fl_Shared_Image*& left, Fl_Shared_Image*& bottom, Fl_Shared_Image*& right)
{
Fl_RGB_Image *r_top, *r_left, *r_bottom, *r_right;
top = left = bottom = right = NULL;
if (decorated_h() == h()) return;
Window from = fl_window;
Expand All @@ -3004,19 +3005,23 @@ void Fl_Window::capture_titlebar_and_borders(Fl_RGB_Image*& top, Fl_RGB_Image*&
uchar *rgb;
if (htop) {
rgb = fl_read_image(NULL, 0, 0, - (w() + 2 * wsides), htop);
top = new Fl_RGB_Image(rgb, w() + 2 * wsides, htop, 3);
top->alloc_array = 1;
r_top = new Fl_RGB_Image(rgb, w() + 2 * wsides, htop, 3);
r_top->alloc_array = 1;
top = Fl_Shared_Image::get(r_top);
}
if (wsides) {
rgb = fl_read_image(NULL, 0, htop, -wsides, h());
left = new Fl_RGB_Image(rgb, wsides, h(), 3);
left->alloc_array = 1;
r_left = new Fl_RGB_Image(rgb, wsides, h(), 3);
r_left->alloc_array = 1;
left = Fl_Shared_Image::get(r_left);
rgb = fl_read_image(NULL, w() + wsides, htop, -wsides, h());
right = new Fl_RGB_Image(rgb, wsides, h(), 3);
right->alloc_array = 1;
r_right = new Fl_RGB_Image(rgb, wsides, h(), 3);
r_right->alloc_array = 1;
right = Fl_Shared_Image::get(r_right);
rgb = fl_read_image(NULL, 0, htop + h(), -(w() + 2*wsides), hbottom);
bottom = new Fl_RGB_Image(rgb, w() + 2*wsides, hbottom, 3);
bottom->alloc_array = 1;
r_bottom = new Fl_RGB_Image(rgb, w() + 2*wsides, hbottom, 3);
r_bottom->alloc_array = 1;
bottom = Fl_Shared_Image::get(r_bottom);
}
fl_window = from;
previous->Fl_Surface_Device::set_current();
Expand Down

0 comments on commit bf7c25a

Please sign in to comment.