From dbde470f8d9803d6986ff57b7dfcb40d679508b7 Mon Sep 17 00:00:00 2001 From: Manolo Gouy Date: Tue, 10 Mar 2015 21:06:22 +0000 Subject: Added Fl_Shared_Image::scale(width, height) to support scaled image drawing (STR #3185). Useful for printing, PostScript or PDF output, or retina displays. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@10615 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- src/Fl_Pixmap.cxx | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'src/Fl_Pixmap.cxx') diff --git a/src/Fl_Pixmap.cxx b/src/Fl_Pixmap.cxx index 8064979dd..2bb776b6b 100644 --- a/src/Fl_Pixmap.cxx +++ b/src/Fl_Pixmap.cxx @@ -135,6 +135,21 @@ void Fl_Quartz_Graphics_Driver::draw(Fl_Pixmap *pxm, int XP, int YP, int WP, int copy_offscreen(X, Y, W, H, (Fl_Offscreen)pxm->id_, cx, cy); } +int Fl_Quartz_Graphics_Driver::draw_scaled(Fl_Pixmap *img, int XP, int YP, int WP, int HP) { + int X, Y, W, H; + fl_clip_box(XP,YP,WP,HP,X,Y,W,H); // X,Y,W,H will give the unclipped area of XP,YP,WP,HP + if (W == 0 || H == 0) return 1; + fl_push_no_clip(); // remove the FLTK clip that can't be rescaled + CGContextSaveGState(fl_gc); + CGContextClipToRect(fl_gc, CGRectMake(X, Y, W, H)); // this clip path will be rescaled & translated + CGContextTranslateCTM(fl_gc, XP, YP); + CGContextScaleCTM(fl_gc, float(WP)/img->w(), float(HP)/img->h()); + draw(img, 0, 0, img->w(), img->h(), 0, 0); + CGContextRestoreGState(fl_gc); + fl_pop_clip(); // restore FLTK's clip + return 1; +} + #elif defined(WIN32) void Fl_GDI_Graphics_Driver::draw(Fl_Pixmap *pxm, int XP, int YP, int WP, int HP, int cx, int cy) { int X, Y, W, H; @@ -181,6 +196,20 @@ void Fl_GDI_Printer_Graphics_Driver::draw(Fl_Pixmap *pxm, int XP, int YP, int WP } } +int Fl_GDI_Printer_Graphics_Driver::draw_scaled(Fl_Pixmap *img, int XP, int YP, int WP, int HP) { + XFORM old_tr, tr; + GetWorldTransform(fl_gc, &old_tr); // storing old transform + tr.eM11 = float(WP)/float(img->w()); + tr.eM22 = float(HP)/float(img->h()); + tr.eM12 = tr.eM21 = 0; + tr.eDx = XP; + tr.eDy = YP; + ModifyWorldTransform(fl_gc, &tr, MWT_LEFTMULTIPLY); + draw(img, 0, 0, img->w(), img->h(), 0, 0); + SetWorldTransform(fl_gc, &old_tr); +} + + #else // Xlib void Fl_Xlib_Graphics_Driver::draw(Fl_Pixmap *pxm, int XP, int YP, int WP, int HP, int cx, int cy) { int X, Y, W, H; -- cgit v1.2.3