themes: Workaround for bug where a background color of RGB 0,0,0 in Black color schem...
[ntk.git] / src / Fl_Tiled_Image.cxx
blob5894f7c8cd9e9929da2de4b791b484d845e00eb5
1 //
2 // "$Id: Fl_Tiled_Image.cxx 7903 2010-11-28 21:06:39Z matt $"
3 //
4 // Tiled image code for the Fast Light Tool Kit (FLTK).
5 //
6 // Copyright 1998-2010 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.
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
21 // USA.
23 // Please report all bugs and problems on the following page:
25 // http://www.fltk.org/str.php
29 #include <FL/Fl.H>
30 #include <FL/Fl_Tiled_Image.H>
31 #include <FL/fl_draw.H>
33 /**
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
40 Fl_Image(W,H,0) {
41 image_ = i;
42 alloc_image_ = 0;
44 if (W == 0) w(Fl::w());
45 if (H == 0) h(Fl::h());
47 /**
48 The destructor frees all memory and server resources that are used by
49 the tiled image.
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...
72 void
73 Fl_Tiled_Image::color_average(Fl_Color c, // I - Color to blend with
74 float i) { // I - Blend fraction
75 if (!alloc_image_) {
76 image_ = image_->copy();
77 alloc_image_ = 1;
80 image_->color_average(c, i);
85 // 'Fl_Tiled_Image::desaturate()' - Convert the image to grayscale...
88 void
89 Fl_Tiled_Image::desaturate() {
90 if (!alloc_image_) {
91 image_ = image_->copy();
92 alloc_image_ = 1;
95 image_->desaturate();
100 // 'Fl_Tiled_Image::draw()' - Draw a shared image...
103 void
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);
116 X += cx;
117 Y += cy;
119 /* X = X - (X % image_->w()); */
120 /* Y = Y - (Y % image_->h()); */
122 W += X;
123 H += Y;
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);
129 fl_pop_clip();
134 // End of "$Id: Fl_Tiled_Image.cxx 7903 2010-11-28 21:06:39Z matt $".