You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

216 lines
6.7KB

  1. //
  2. // "$Id: Fl_Image.H 8338 2011-01-30 09:24:40Z manolo $"
  3. //
  4. // Image header file for the Fast Light Tool Kit (FLTK).
  5. //
  6. // Copyright 1998-2011 by Bill Spitzak and others.
  7. //
  8. // This library is free software; you can redistribute it and/or
  9. // modify it under the terms of the GNU Library General Public
  10. // License as published by the Free Software Foundation; either
  11. // version 2 of the License, or (at your option) any later version.
  12. //
  13. // This library is distributed in the hope that it will be useful,
  14. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. // Library General Public License for more details.
  17. //
  18. // You should have received a copy of the GNU Library General Public
  19. // License along with this library; if not, write to the Free Software
  20. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  21. // USA.
  22. //
  23. // Please report all bugs and problems on the following page:
  24. //
  25. // http://www.fltk.org/str.php
  26. //
  27. /* \file
  28. Fl_Image, Fl_RGB_Image classes . */
  29. #ifndef Fl_Image_H
  30. # define Fl_Image_H
  31. # include "Enumerations.H"
  32. class Fl_Widget;
  33. struct Fl_Menu_Item;
  34. struct Fl_Label;
  35. /**
  36. Fl_Image is the base class used for caching and
  37. drawing all kinds of images in FLTK. This class keeps track of
  38. common image data such as the pixels, colormap, width, height,
  39. and depth. Virtual methods are used to provide type-specific
  40. image handling.</P>
  41. <P>Since the Fl_Image class does not support image
  42. drawing by itself, calling the draw() method results in
  43. a box with an X in it being drawn instead.
  44. */
  45. class FL_EXPORT Fl_Image {
  46. int w_, h_, d_, ld_, count_;
  47. const char * const *data_;
  48. // Forbid use of copy contructor and assign operator
  49. Fl_Image & operator=(const Fl_Image &);
  50. Fl_Image(const Fl_Image &);
  51. protected:
  52. /**
  53. Sets the current image width in pixels.
  54. */
  55. void w(int W) {w_ = W;}
  56. /**
  57. Sets the current image height in pixels.
  58. */
  59. void h(int H) {h_ = H;}
  60. /**
  61. Sets the current image depth.
  62. */
  63. void d(int D) {d_ = D;}
  64. /**
  65. Sets the current line data size in bytes.
  66. */
  67. void ld(int LD) {ld_ = LD;}
  68. /**
  69. Sets the current array pointer and count of pointers in the array.
  70. */
  71. void data(const char * const *p, int c) {data_ = p; count_ = c;}
  72. void draw_empty(int X, int Y);
  73. static void labeltype(const Fl_Label *lo, int lx, int ly, int lw, int lh, Fl_Align la);
  74. static void measure(const Fl_Label *lo, int &lw, int &lh);
  75. public:
  76. /**
  77. Returns the current image width in pixels.
  78. */
  79. int w() const {return w_;}
  80. /** Returns the current image height in pixels.
  81. */
  82. int h() const {return h_;}
  83. /**
  84. Returns the current image depth.
  85. The return value will be 0 for bitmaps, 1 for
  86. pixmaps, and 1 to 4 for color images.</P>
  87. */
  88. int d() const {return d_;}
  89. /**
  90. Returns the current line data size in bytes.
  91. Line data is extra data that is included
  92. after each line of color image data and is normally not present.
  93. */
  94. int ld() const {return ld_;}
  95. /**
  96. The count() method returns the number of data values
  97. associated with the image. The value will be 0 for images with
  98. no associated data, 1 for bitmap and color images, and greater
  99. than 2 for pixmap images.
  100. */
  101. int count() const {return count_;}
  102. /**
  103. Returns a pointer to the current image data array.
  104. Use the count() method to find the size of the data array.
  105. */
  106. const char * const *data() const {return data_;}
  107. /**
  108. The constructor creates an empty image with the specified
  109. width, height, and depth. The width and height are in pixels.
  110. The depth is 0 for bitmaps, 1 for pixmap (colormap) images, and
  111. 1 to 4 for color images.
  112. */
  113. Fl_Image(int W, int H, int D) {w_ = W; h_ = H; d_ = D; ld_ = 0; count_ = 0; data_ = 0;}
  114. virtual ~Fl_Image();
  115. virtual Fl_Image *copy(int W, int H);
  116. /**
  117. The copy() method creates a copy of the specified
  118. image. If the width and height are provided, the image is
  119. resized to the specified size. The image should be deleted (or in
  120. the case of Fl_Shared_Image, released) when you are done
  121. with it.
  122. */
  123. Fl_Image *copy() { return copy(w(), h()); }
  124. virtual void color_average(Fl_Color c, float i);
  125. /**
  126. The inactive() method calls
  127. color_average(FL_BACKGROUND_COLOR, 0.33f) to produce
  128. an image that appears grayed out. <I>This method does not
  129. alter the original image data.</I>
  130. */
  131. void inactive() { color_average(FL_GRAY, .33f); }
  132. virtual void desaturate();
  133. virtual void label(Fl_Widget*w);
  134. virtual void label(Fl_Menu_Item*m);
  135. /**
  136. Draws the image with a bounding box.
  137. This form specifies
  138. a bounding box for the image, with the origin
  139. (upper-lefthand corner) of the image offset by the cx
  140. and cy arguments.
  141. */
  142. virtual void draw(int X, int Y, int W, int H, int cx=0, int cy=0); // platform dependent
  143. /**
  144. Draws the image.
  145. This form specifies the upper-lefthand corner of the image.
  146. */
  147. void draw(int X, int Y) {draw(X, Y, w(), h(), 0, 0);} // platform dependent
  148. virtual void uncache();
  149. };
  150. /**
  151. The Fl_RGB_Image class supports caching and drawing
  152. of full-color images with 1 to 4 channels of color information.
  153. Images with an even number of channels are assumed to contain
  154. alpha information, which is used to blend the image with the
  155. contents of the screen.</P>
  156. <P>Fl_RGB_Image is defined in
  157. &lt;FL/Fl_Image.H&gt;, however for compatibility reasons
  158. &lt;FL/Fl_RGB_Image.H&gt; should be included.
  159. */
  160. class FL_EXPORT Fl_RGB_Image : public Fl_Image {
  161. friend class Fl_Quartz_Graphics_Driver;
  162. friend class Fl_GDI_Graphics_Driver;
  163. friend class Fl_Xlib_Graphics_Driver;
  164. public:
  165. const uchar *array;
  166. int alloc_array; // Non-zero if array was allocated
  167. private:
  168. #if defined(__APPLE__) || defined(WIN32)
  169. void *id_; // for internal use
  170. void *mask_; // for internal use (mask bitmap)
  171. #else
  172. unsigned id_; // for internal use
  173. unsigned mask_; // for internal use (mask bitmap)
  174. #endif // __APPLE__ || WIN32
  175. public:
  176. /** The constructor creates a new image from the specified data. */
  177. Fl_RGB_Image(const uchar *bits, int W, int H, int D=3, int LD=0) :
  178. Fl_Image(W,H,D), array(bits), alloc_array(0), id_(0), mask_(0) {data((const char **)&array, 1); ld(LD);}
  179. virtual ~Fl_RGB_Image();
  180. virtual Fl_Image *copy(int W, int H);
  181. Fl_Image *copy() { return copy(w(), h()); }
  182. virtual void color_average(Fl_Color c, float i);
  183. virtual void desaturate();
  184. virtual void draw(int X, int Y, int W, int H, int cx=0, int cy=0);
  185. void draw(int X, int Y) {draw(X, Y, w(), h(), 0, 0);}
  186. virtual void label(Fl_Widget*w);
  187. virtual void label(Fl_Menu_Item*m);
  188. virtual void uncache();
  189. };
  190. #endif // !Fl_Image_H
  191. //
  192. // End of "$Id: Fl_Image.H 8338 2011-01-30 09:24:40Z manolo $".
  193. //