diff options
| author | Manolo Gouy <Manolo> | 2015-03-11 06:21:17 +0000 |
|---|---|---|
| committer | Manolo Gouy <Manolo> | 2015-03-11 06:21:17 +0000 |
| commit | e69467bbc95e699a7e140d73b3f9b58f97f79eaa (patch) | |
| tree | 35aca3339bc4cb00824772c9998065e1dd83dbd4 /src | |
| parent | dbde470f8d9803d6986ff57b7dfcb40d679508b7 (diff) | |
Implementation of Fl_Shared_Image::scale(width, height) for scaled image drawing - cont'd
Shorter implementation based on Fl_Graphics_Driver::draw_scaled(Fl_Image *,...).
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@10616 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src')
| -rw-r--r-- | src/Fl_Image.cxx | 22 | ||||
| -rw-r--r-- | src/Fl_Pixmap.cxx | 29 | ||||
| -rw-r--r-- | src/Fl_Shared_Image.cxx | 15 | ||||
| -rw-r--r-- | src/ps_image.cxx | 17 |
4 files changed, 11 insertions, 72 deletions
diff --git a/src/Fl_Image.cxx b/src/Fl_Image.cxx index e4e88478e..340b1bcd4 100644 --- a/src/Fl_Image.cxx +++ b/src/Fl_Image.cxx @@ -548,21 +548,13 @@ static int start(Fl_RGB_Image *img, int XP, int YP, int WP, int HP, int w, int h return 0; } -/** Draws an Fl_RGB_Image scaled to width \p W & height \p H with top-left corner at \em X,Y +/** Draws an Fl_Image scaled to width \p W & height \p H with top-left corner at \em X,Y \return zero when the graphics driver doesn't implement scaled drawing, non-zero if it does implement it. */ -int Fl_Graphics_Driver::draw_scaled(Fl_RGB_Image *img, int X, int Y, int W, int H) { +int Fl_Graphics_Driver::draw_scaled(Fl_Image *img, int X, int Y, int W, int H) { return 0; } -/** Draws an Fl_Pixmap scaled to width \p W & height \p H with top-left corner at \em X,Y - \return zero when the graphics driver doesn't implement scaled drawing, non-zero if it does implement it. - */ -int Fl_Graphics_Driver::draw_scaled(Fl_Pixmap *img, int X, int Y, int W, int H) { - return 0; -} - - #ifdef __APPLE__ static void imgProviderReleaseData (void *info, const void *data, size_t size) { @@ -627,7 +619,7 @@ void Fl_Quartz_Graphics_Driver::draw(Fl_RGB_Image *img, int XP, int YP, int WP, } } -int Fl_Quartz_Graphics_Driver::draw_scaled(Fl_RGB_Image *img, int XP, int YP, int WP, int HP) { +int Fl_Quartz_Graphics_Driver::draw_scaled(Fl_Image *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; @@ -636,7 +628,7 @@ int Fl_Quartz_Graphics_Driver::draw_scaled(Fl_RGB_Image *img, int XP, int YP, in 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); + img->draw(0, 0, img->w(), img->h(), 0, 0); CGContextRestoreGState(fl_gc); fl_pop_clip(); // restore FLTK's clip return 1; @@ -688,7 +680,7 @@ void Fl_GDI_Graphics_Driver::draw(Fl_RGB_Image *img, int XP, int YP, int WP, int } } -int Fl_GDI_Printer_Graphics_Driver::draw_scaled(Fl_RGB_Image *img, int XP, int YP, int WP, int HP) { +int Fl_GDI_Printer_Graphics_Driver::draw_scaled(Fl_Image *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()); @@ -697,9 +689,9 @@ int Fl_GDI_Printer_Graphics_Driver::draw_scaled(Fl_RGB_Image *img, int XP, int Y tr.eDx = XP; tr.eDy = YP; ModifyWorldTransform(fl_gc, &tr, MWT_LEFTMULTIPLY); - Fl_GDI_Graphics_Driver::draw(img, 0, 0, img->w(), img->h(), 0, 0); + img->draw(0, 0, img->w(), img->h(), 0, 0); SetWorldTransform(fl_gc, &old_tr); -return 1; + return 1; } #else diff --git a/src/Fl_Pixmap.cxx b/src/Fl_Pixmap.cxx index 2bb776b6b..8064979dd 100644 --- a/src/Fl_Pixmap.cxx +++ b/src/Fl_Pixmap.cxx @@ -135,21 +135,6 @@ 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; @@ -196,20 +181,6 @@ 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; diff --git a/src/Fl_Shared_Image.cxx b/src/Fl_Shared_Image.cxx index 4a05a46ef..3c2aa4b85 100644 --- a/src/Fl_Shared_Image.cxx +++ b/src/Fl_Shared_Image.cxx @@ -338,19 +338,8 @@ void Fl_Shared_Image::draw(int X, int Y, int W, int H, int cx, int cy) { return; } fl_push_clip(X, Y, W, H); - int use_scaled_image = 0, done; - if (image_->d() == 0) { // handles Fl_Bitmap - use_scaled_image = 1; - } - else if (image_->count() >= 2) { // handles Fl_Pixmap - done = fl_graphics_driver->draw_scaled((Fl_Pixmap*)image_, X-cx, Y-cy, w(), h()); - if (done == 0) use_scaled_image = 1; - } - else { // handles Fl_RGB_Image - done = fl_graphics_driver->draw_scaled((Fl_RGB_Image*)image_, X-cx, Y-cy, w(), h()); - if (done == 0) use_scaled_image = 1; - } - if (use_scaled_image) { + int done = fl_graphics_driver->draw_scaled(image_, X-cx, Y-cy, w(), h()); + if (!done) { if (scaled_image_ && (scaled_image_->w() != w() || scaled_image_->h() != h())) { delete scaled_image_; scaled_image_ = NULL; diff --git a/src/ps_image.cxx b/src/ps_image.cxx index ca71121b9..0cee215e3 100644 --- a/src/ps_image.cxx +++ b/src/ps_image.cxx @@ -602,27 +602,14 @@ void Fl_PostScript_Graphics_Driver::draw(Fl_RGB_Image * rgb,int XP, int YP, int mask=0; } -int Fl_PostScript_Graphics_Driver::draw_scaled(Fl_RGB_Image *rgb, int XP, int YP, int WP, int HP){ - int X, Y, W, H; - 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; - push_no_clip(); // remove the FLTK clip that can't be rescaled - clocale_printf("%d %d %i %i CL\n", X, Y, W, H); - clocale_printf("GS %d %d TR %f %f SC GS\n", XP, YP, float(WP)/rgb->w(), float(HP)/rgb->h()); - draw(rgb, 0, 0, rgb->w(), rgb->h(), 0, 0); - clocale_printf("GR GR\n"); - pop_clip(); // restore FLTK's clip - return 1; -} - -int Fl_PostScript_Graphics_Driver::draw_scaled(Fl_Pixmap *img, int XP, int YP, int WP, int HP){ +int Fl_PostScript_Graphics_Driver::draw_scaled(Fl_Image *img, int XP, int YP, int WP, int HP){ int X, Y, W, H; 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; push_no_clip(); // remove the FLTK clip that can't be rescaled clocale_printf("%d %d %i %i CL\n", X, Y, W, H); clocale_printf("GS %d %d TR %f %f SC GS\n", XP, YP, float(WP)/img->w(), float(HP)/img->h()); - draw(img, 0, 0, img->w(), img->h(), 0, 0); + img->draw(0, 0, img->w(), img->h(), 0, 0); clocale_printf("GR GR\n"); pop_clip(); // restore FLTK's clip return 1; |
