2 // "$Id: Fl_Tiled_Image.cxx 7903 2010-11-28 21:06:39Z matt $"
4 // Tiled image code for the Fast Light Tool Kit (FLTK).
6 // Copyright 1998-2010 by Bill Spitzak and others.
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.
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.
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
23 // Please report all bugs and problems on the following page:
25 // http://www.fltk.org/str.php
30 #include <FL/Fl_Tiled_Image.H>
31 #include <FL/fl_draw.H>
34 The constructors create a new tiled image containing the specified image.
35 Use a width and height of 0 to tile the whole window/widget.
37 Fl_Tiled_Image::Fl_Tiled_Image(Fl_Image
*i
, // I - Image to tile
38 int W
, // I - Width of tiled area
39 int H
) : // I - Height of tiled area
44 if (W
== 0) w(Fl::w());
45 if (H
== 0) h(Fl::h());
48 The destructor frees all memory and server resources that are used by
51 Fl_Tiled_Image::~Fl_Tiled_Image() {
52 if (alloc_image_
) delete image_
;
57 // 'Fl_Tiled_Image::copy()' - Copy and resize a tiled image...
60 Fl_Image
* // O - New image
61 Fl_Tiled_Image::copy(int W
, // I - New width
62 int H
) { // I - New height
63 if (W
== w() && H
== h()) return this;
64 else return new Fl_Tiled_Image(image_
, W
, H
);
69 // 'Fl_Tiled_Image::color_average()' - Blend colors...
73 Fl_Tiled_Image::color_average(Fl_Color c
, // I - Color to blend with
74 float i
) { // I - Blend fraction
76 image_
= image_
->copy();
80 image_
->color_average(c
, i
);
85 // 'Fl_Tiled_Image::desaturate()' - Convert the image to grayscale...
89 Fl_Tiled_Image::desaturate() {
91 image_
= image_
->copy();
100 // 'Fl_Tiled_Image::draw()' - Draw a shared image...
104 Fl_Tiled_Image::draw(int X
, // I - Starting X position
105 int Y
, // I - Starting Y position
106 int W
, // I - Width of area to be filled
107 int H
, // I - Height of area to be filled
108 int cx
, // I - "Source" X position
109 int cy
) { // I - "Source" Y position
110 if (!image_
->w() || !image_
->h()) return;
111 if (W
== 0) W
= Fl::w();
112 if (H
== 0) H
= Fl::h();
114 fl_push_clip(X
, Y
, W
, H
);
119 X
= X
- (X
% image_
->w());
120 Y
= Y
- (Y
% image_
->h());
125 for (int yy
= Y
; yy
< H
; yy
+= image_
->h())
126 for (int xx
= X
; xx
< W
; xx
+= image_
->w())
127 image_
->draw(xx
, yy
);
134 // End of "$Id: Fl_Tiled_Image.cxx 7903 2010-11-28 21:06:39Z matt $".