summaryrefslogtreecommitdiff
path: root/FL
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 /FL
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 'FL')
-rw-r--r--FL/Fl_Bitmap.H3
-rw-r--r--FL/Fl_Graphics_Driver.H8
-rw-r--r--FL/Fl_Image.H49
-rw-r--r--FL/Fl_Pixmap.H1
-rw-r--r--FL/Fl_SVG_Image.H7
-rw-r--r--FL/Fl_Shared_Image.H15
6 files changed, 42 insertions, 41 deletions
diff --git a/FL/Fl_Bitmap.H b/FL/Fl_Bitmap.H
index 9bd648292..cb638e66e 100644
--- a/FL/Fl_Bitmap.H
+++ b/FL/Fl_Bitmap.H
@@ -45,9 +45,6 @@ private:
/** for internal use */
fl_uintptr_t id_;
float cache_scale_; // graphics scaling value when id_ was computed
-
-protected:
- virtual int draw_scaled(int X, int Y, int W, int H);
public:
/** The constructors create a new bitmap from the specified bitmap data */
diff --git a/FL/Fl_Graphics_Driver.H b/FL/Fl_Graphics_Driver.H
index b2c15272a..c1588703b 100644
--- a/FL/Fl_Graphics_Driver.H
+++ b/FL/Fl_Graphics_Driver.H
@@ -141,9 +141,9 @@ protected:
matrix *fl_matrix; /**< Points to the current coordinate transformation matrix */
virtual void global_gc();
/** Support function for Fl_Pixmap drawing */
- virtual fl_uintptr_t cache(Fl_Pixmap *img, int w, int h, const char *const*array) { return 0; }
+ virtual fl_uintptr_t cache(Fl_Pixmap *img) { return 0; }
/** Support function for Fl_Bitmap drawing */
- virtual fl_uintptr_t cache(Fl_Bitmap *img, int w, int h, const uchar *array) { return 0; }
+ virtual fl_uintptr_t cache(Fl_Bitmap *img) { return 0; }
/** Support function for Fl_RGB_Image drawing */
virtual void uncache(Fl_RGB_Image *img, fl_uintptr_t &id_, fl_uintptr_t &mask_) { }
// --- implementation is in src/drivers/xxx/Fl_xxx_Graphics_Driver_image.cxx
@@ -173,7 +173,6 @@ protected:
the image offset by the cx and cy arguments.
*/
virtual void draw(Fl_Bitmap *bm, int XP, int YP, int WP, int HP, int cx, int cy) {}
- virtual void draw(Fl_Shared_Image *shared, int X, int Y);
virtual void copy_offscreen(int x, int y, int w, int h, Fl_Offscreen pixmap, int srcx, int srcy);
/** Support function for image drawing */
@@ -393,7 +392,7 @@ public:
virtual const char *font_name(int num) {return NULL;}
/** Support for Fl::set_font() */
virtual void font_name(int num, const char *name) {}
- /** Support function for Fl_Shared_Image drawing */
+ // Draws an Fl_Image scaled to width W & height H
virtual int draw_scaled(Fl_Image *img, int X, int Y, int W, int H);
/** Support function for fl_overlay_rect() and scaled GUI.
Defaut implementation may be enough */
@@ -460,7 +459,6 @@ protected:
virtual void draw_unscaled(Fl_Bitmap *bm, float s, int XP, int YP, int WP, int HP, int cx, int cy) {}
virtual void draw(Fl_RGB_Image *img, int XP, int YP, int WP, int HP, int cx, int cy);
virtual void draw_unscaled(Fl_RGB_Image *img, float s, int XP, int YP, int WP, int HP, int cx, int cy) {}
- virtual void draw(Fl_Shared_Image *shared, int X, int Y);
virtual void point(int x, int y);
virtual void point_unscaled(float x, float y) {}
virtual void rect(int x, int y, int w, int h);
diff --git a/FL/Fl_Image.H b/FL/Fl_Image.H
index 4a1b56d79..75e5820b9 100644
--- a/FL/Fl_Image.H
+++ b/FL/Fl_Image.H
@@ -43,9 +43,9 @@ enum Fl_RGB_Scaling {
/**
- \brief Base class for image caching and drawing.
+ \brief Base class for image caching, scaling and drawing.
- Fl_Image is the base class used for caching and drawing all kinds of images
+ Fl_Image is the base class used for caching, scaling and drawing all kinds of images
in FLTK. This class keeps track of common image data such as the pixels,
colormap, width, height, and depth. Virtual methods are used to provide
type-specific image handling.
@@ -63,9 +63,10 @@ public:
private:
int w_, h_, d_, ld_, count_;
+ int pixel_w_, pixel_h_;
const char * const *data_;
- static Fl_RGB_Scaling RGB_scaling_;
-
+ static Fl_RGB_Scaling RGB_scaling_; // method used when copying RGB images
+ static Fl_RGB_Scaling scaling_algorithm_; // method used to rescale RGB source images before drawing
// Forbid use of copy constructor and assign operator
Fl_Image & operator=(const Fl_Image &);
Fl_Image(const Fl_Image &);
@@ -75,11 +76,11 @@ protected:
/**
Sets the current image width in pixels.
*/
- void w(int W) {w_ = W;}
+ void w(int W) {w_ = W; pixel_w_ = W;}
/**
Sets the current image height in pixels.
*/
- void h(int H) {h_ = H;}
+ void h(int H) {h_ = H; pixel_h_ = H;}
/**
Sets the current image depth.
*/
@@ -104,19 +105,31 @@ protected:
static void labeltype(const Fl_Label *lo, int lx, int ly, int lw, int lh, Fl_Align la);
static void measure(const Fl_Label *lo, int &lw, int &lh);
- virtual int draw_scaled(int X, int Y, int W, int H);
+ int draw_scaled(int X, int Y, int W, int H);
public:
/**
- Returns the current image width in pixels.
+ Returns the current image width in FLTK units.
+ The values of w() and pixel_w() are identical unless scale() has been called
+ after which they may differ.
*/
int w() const {return w_;}
/**
- Returns the current image height in pixels.
+ Returns the current image height in FLTK units.
+ The values of h() and pixel_h() are identical unless scale() has been called
+ after which they may differ.
*/
int h() const {return h_;}
/**
+ Returns the image width in pixels.
+ */
+ int pixel_w() {return pixel_w_;}
+ /**
+ Returns the image height in pixels.
+ */
+ int pixel_h() {return pixel_h_;}
+ /**
Returns the current image depth.
The return value will be 0 for bitmaps, 1 for
pixmaps, and 1 to 4 for color images.</P>
@@ -188,15 +201,28 @@ public:
// set RGB image scaling method
static void RGB_scaling(Fl_RGB_Scaling);
-
// get RGB image scaling method
static Fl_RGB_Scaling RGB_scaling();
+
/** Use this method if you have an Fl_Image object and want to know whether it is derived
from class Fl_RGB_Image.
If the method returns non-NULL, then the image in question is
derived from Fl_RGB_Image, and the returned value is a pointer to this image.
*/
virtual Fl_RGB_Image *as_rgb_image() {return NULL;}
+ // set the image drawing size
+ virtual void scale(int width, int height, int proportional = 1, int can_expand = 0);
+ /** Sets what algorithm is used when resizing a source image to draw it.
+ The default algorithm is FL_RGB_SCALING_BILINEAR.
+ Drawing an Fl_Image is sometimes performed by first resizing the source image
+ and then drawing the resized copy. This occurs, e.g., when drawing to screen under X11
+ without Xrender support after having called scale().
+ This function controls what method is used when the image to be resized is an Fl_RGB_Image.
+ \version 1.4
+ */
+ static void scaling_algorithm(Fl_RGB_Scaling algorithm) {scaling_algorithm_ = algorithm; }
+ /** Gets what algorithm is used when resizing a source image to draw it. */
+ static Fl_RGB_Scaling scaling_algorithm() {return scaling_algorithm_;}
};
@@ -229,9 +255,6 @@ private:
fl_uintptr_t mask_;
float cache_scale_; // graphics scaling value when id_ was computed
-protected:
- virtual int draw_scaled(int X, int Y, int W, int H);
-
public:
Fl_RGB_Image(const uchar *bits, int W, int H, int D=3, int LD=0);
diff --git a/FL/Fl_Pixmap.H b/FL/Fl_Pixmap.H
index d7104863c..7a4c50144 100644
--- a/FL/Fl_Pixmap.H
+++ b/FL/Fl_Pixmap.H
@@ -45,7 +45,6 @@ class FL_EXPORT Fl_Pixmap : public Fl_Image {
protected:
void measure();
- virtual int draw_scaled(int X, int Y, int W, int H);
public:
diff --git a/FL/Fl_SVG_Image.H b/FL/Fl_SVG_Image.H
index 27611016f..d9c5b76c8 100644
--- a/FL/Fl_SVG_Image.H
+++ b/FL/Fl_SVG_Image.H
@@ -34,9 +34,8 @@ struct NSVGimage;
If the image has loaded correctly, w(), h(), and d() should return values greater than zero.
Rasterization is not done until the image is first drawn or resize() is called. Therefore,
- \ref array is NULL until then. The delayed rasterization ensures an Fl_Shared_Image based on
- an SVG image and scaled to its display size by Fl_Shared_Image::scale() will be
- always rasterized to the exact screen resolution.
+ \ref array is NULL until then. The delayed rasterization ensures an Fl_SVG_Image is always rasterized
+ to the exact screen resolution at which it is drawn.
The Fl_SVG_Image class draws images computed by \c nanosvg: one known limitation is that text
within \c <text\></text\> blocks is not rendered.
@@ -118,8 +117,6 @@ private:
void rasterize_(int W, int H);
void init_(const char *filename, const char *filedata, Fl_SVG_Image *copy_source);
Fl_SVG_Image(Fl_SVG_Image *source);
-protected:
- virtual int draw_scaled(int X, int Y, int W, int H);
public:
/** Set this to \c false to allow image re-scaling that alters the image aspect ratio.
Upon object creation, proportional is set to \c true, and the aspect ratio is kept constant.*/
diff --git a/FL/Fl_Shared_Image.H b/FL/Fl_Shared_Image.H
index a62f4db97..9b5dad13d 100644
--- a/FL/Fl_Shared_Image.H
+++ b/FL/Fl_Shared_Image.H
@@ -31,7 +31,7 @@ typedef Fl_Image *(*Fl_Shared_Handler)(const char *name, uchar *header,
// Shared images class.
/**
- This class supports caching, loading, scaling, and drawing of image files.
+ This class supports caching, loading, and drawing of image files.
Most applications will also want to link against the fltk_images library
and call the fl_register_images() function to support standard image
@@ -54,9 +54,6 @@ class FL_EXPORT Fl_Shared_Image : public Fl_Image {
friend class Fl_PNG_Image;
friend class Fl_Graphics_Driver;
-private:
- static Fl_RGB_Scaling scaling_algorithm_; // method used to rescale RGB source images
- Fl_Image *scaled_image_;
protected:
static Fl_Shared_Image **images_; // Shared images
@@ -108,7 +105,6 @@ public:
virtual void desaturate();
virtual void draw(int X, int Y, int W, int H, int cx = 0, int cy = 0);
void draw(int X, int Y) { draw(X, Y, w(), h(), 0, 0); }
- void scale(int width, int height, int proportional = 1, int can_expand = 0);
virtual void uncache();
static Fl_Shared_Image *find(const char *name, int W = 0, int H = 0);
@@ -118,15 +114,6 @@ public:
static int num_images();
static void add_handler(Fl_Shared_Handler f);
static void remove_handler(Fl_Shared_Handler f);
- /** Sets what algorithm is used when resizing a source image.
- The default algorithm is FL_RGB_SCALING_BILINEAR.
- Drawing an Fl_Shared_Image is sometimes performed by first resizing the source image
- and then drawing the resized copy. This occurs, e.g., when drawing to screen under Linux
- after having called Fl_Shared_Image::scale().
- This function controls what method is used when the image to be resized is an Fl_RGB_Image.
- \version 1.3.4
- */
- static void scaling_algorithm(Fl_RGB_Scaling algorithm) {scaling_algorithm_ = algorithm; }
};
//