summaryrefslogtreecommitdiff
path: root/src/Fl_Shared_Image.cxx
diff options
context:
space:
mode:
authorManolo Gouy <Manolo>2018-03-19 17:43:18 +0000
committerManolo Gouy <Manolo>2018-03-19 17:43:18 +0000
commit916b44e361f275555c5f22b9d91c973ccc089037 (patch)
treea36b734804a82d3e5d4bd900bc9031b8fe60d35a /src/Fl_Shared_Image.cxx
parentc4f7c09b7bacbfe19d1dcea5a28eeb30b1136a95 (diff)
New member function Fl_Image::scale(int width, int height) to set the FLTK size of an image.
Each image has now two sizes implemented as follows: - the pixel size is stored in private members pixel_w_ and pixel_h_ with public accessors pixel_w() and pixel_h() - the FLTK size is stored in private members w_ and h_ and read by w() and h() - when the image is constructed, the two sizes have the same value - the protected w(int) and h(int) member functions set both FLTK and pixel sizes. - the public scale(int, int) member function is essentially nothing but set the FLTK size and don't change the pixel size. - when the image is drawn, its FLTK size determines how big it is drawn, its pixel size determines how much data are available to draw it. FLTK 1.3.4 with FL_ABI_VERSION=10304 contained an equivalent member function but only for the Fl_Shared_Image class. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.4@12776 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src/Fl_Shared_Image.cxx')
-rw-r--r--src/Fl_Shared_Image.cxx59
1 files changed, 5 insertions, 54 deletions
diff --git a/src/Fl_Shared_Image.cxx b/src/Fl_Shared_Image.cxx
index b2e00f6b3..e8cfb3fb9 100644
--- a/src/Fl_Shared_Image.cxx
+++ b/src/Fl_Shared_Image.cxx
@@ -123,7 +123,6 @@ Fl_Shared_Image::Fl_Shared_Image() : Fl_Image(0,0,0) {
original_ = 0;
image_ = 0;
alloc_image_ = 0;
- scaled_image_= 0;
}
@@ -144,7 +143,6 @@ Fl_Shared_Image::Fl_Shared_Image(const char *n, // I - Filename
image_ = img;
alloc_image_ = !img;
original_ = 1;
- scaled_image_= 0;
if (!img) reload();
else update();
@@ -211,7 +209,6 @@ Fl_Shared_Image::update() {
Fl_Shared_Image::~Fl_Shared_Image() {
if (name_) delete[] (char *)name_;
if (alloc_image_) delete image_;
- delete scaled_image_;
}
@@ -357,7 +354,6 @@ Fl_Shared_Image::desaturate() {
update();
}
-
//
// 'Fl_Shared_Image::draw()' - Draw a shared image...
//
@@ -366,59 +362,14 @@ void Fl_Shared_Image::draw(int X, int Y, int W, int H, int cx, int cy) {
Fl_Image::draw(X, Y, W, H, cx, cy);
return;
}
- bool need_clip = (W != w() || H != h() || cx || cy);
- if (need_clip) fl_push_clip(X, Y, W, H);
- fl_graphics_driver->draw(this, X-cx, Y-cy);
- if (need_clip) fl_pop_clip();
-}
-
-
-/** Sets the drawing size of the shared image.
- This function gives the shared image its own size, independently from the size of the original image
- that is typically larger.
- This can be useful to draw a shared image on a drawing surface with more than 1 pixel per
- FLTK unit: all pixels of the original image become available to fill an area of the drawing surface
- sized at <tt>width,height</tt> FLTK units.
- Examples of such drawing surfaces: HiDPI displays, laser printers, PostScript files, PDF printers.
-
- \param width,height maximum width and height (in FLTK units) to use when drawing the shared image
- \param proportional if not null, keep the width and height of the shared image proportional to those of its original image
- \param can_expand if null, the width and height of the shared image will not exceed those of the original image
-
- \version 1.3.4
-
- Example code: scale an image to fit in a box
- \code
- Fl_Box *b = ... // a box
- Fl_Shared_Image *shared = Fl_Shared_Image::get("/path/to/picture.jpeg"); // read a picture file
- shared->scale(b->w(), b->h()); // set the drawing size of the shared image to the size of the box
- b->image(shared); // use the shared image as the box image
- b->align(FL_ALIGN_INSIDE | FL_ALIGN_CENTER | FL_ALIGN_CLIP); // the image is to be drawn centered in the box
- \endcode
- */
-void Fl_Shared_Image::scale(int width, int height, int proportional, int can_expand)
-{
- w(width);
- h(height);
- if (!image_ || image_->fail()) return;
- if (!proportional && can_expand) return;
- if (!proportional && width <= image_->w() && height <= image_->h()) return;
- float fw = image_->w() / float(width);
- float fh = image_->h() / float(height);
- if (proportional) {
- if (fh > fw) fw = fh;
- else fh = fw;
- }
- if (!can_expand) {
- if (fw < 1) fw = 1;
- if (fh < 1) fh = 1;
- }
- w(int(image_->w() / fw));
- h(int(image_->h() / fh));
+ // transiently set the drawing size of image_ to that of the shared image
+ int width = image_->w(), height = image_->h();
+ image_->scale(w(), h(), 0, 1);
+ image_->draw(X, Y, W, H, cx, cy);
+ image_->scale(width, height, 0, 1);
}
-Fl_RGB_Scaling Fl_Shared_Image::scaling_algorithm_ = FL_RGB_SCALING_BILINEAR;
//