|
fltk 1.3.0rc3
About: FLTK (Fast Light Tool Kit) is a cross-platform C++ GUI toolkit for UNIX/Linux (X11), Microsoft Windows, and MacOS X. Release candidate.
SfR Fresh Dox: fltk-1.3.0rc3-source.tar.gz ("inofficial" and yet experimental doxygen-generated source code documentation) ![]() |
00001 // 00002 // "$Id: Fl_Tiled_Image.cxx 7903 2010-11-28 21:06:39Z matt $" 00003 // 00004 // Tiled image code for the Fast Light Tool Kit (FLTK). 00005 // 00006 // Copyright 1998-2010 by Bill Spitzak and others. 00007 // 00008 // This library is free software; you can redistribute it and/or 00009 // modify it under the terms of the GNU Library General Public 00010 // License as published by the Free Software Foundation; either 00011 // version 2 of the License, or (at your option) any later version. 00012 // 00013 // This library is distributed in the hope that it will be useful, 00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 // Library General Public License for more details. 00017 // 00018 // You should have received a copy of the GNU Library General Public 00019 // License along with this library; if not, write to the Free Software 00020 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 00021 // USA. 00022 // 00023 // Please report all bugs and problems on the following page: 00024 // 00025 // http://www.fltk.org/str.php 00026 // 00027 00028 00029 #include <FL/Fl.H> 00030 #include <FL/Fl_Tiled_Image.H> 00031 #include <FL/fl_draw.H> 00032 00037 Fl_Tiled_Image::Fl_Tiled_Image(Fl_Image *i, // I - Image to tile 00038 int W, // I - Width of tiled area 00039 int H) : // I - Height of tiled area 00040 Fl_Image(W,H,0) { 00041 image_ = i; 00042 alloc_image_ = 0; 00043 00044 if (W == 0) w(Fl::w()); 00045 if (H == 0) h(Fl::h()); 00046 } 00051 Fl_Tiled_Image::~Fl_Tiled_Image() { 00052 if (alloc_image_) delete image_; 00053 } 00054 00055 00056 // 00057 // 'Fl_Tiled_Image::copy()' - Copy and resize a tiled image... 00058 // 00059 00060 Fl_Image * // O - New image 00061 Fl_Tiled_Image::copy(int W, // I - New width 00062 int H) { // I - New height 00063 if (W == w() && H == h()) return this; 00064 else return new Fl_Tiled_Image(image_, W, H); 00065 } 00066 00067 00068 // 00069 // 'Fl_Tiled_Image::color_average()' - Blend colors... 00070 // 00071 00072 void 00073 Fl_Tiled_Image::color_average(Fl_Color c, // I - Color to blend with 00074 float i) { // I - Blend fraction 00075 if (!alloc_image_) { 00076 image_ = image_->copy(); 00077 alloc_image_ = 1; 00078 } 00079 00080 image_->color_average(c, i); 00081 } 00082 00083 00084 // 00085 // 'Fl_Tiled_Image::desaturate()' - Convert the image to grayscale... 00086 // 00087 00088 void 00089 Fl_Tiled_Image::desaturate() { 00090 if (!alloc_image_) { 00091 image_ = image_->copy(); 00092 alloc_image_ = 1; 00093 } 00094 00095 image_->desaturate(); 00096 } 00097 00098 00099 // 00100 // 'Fl_Tiled_Image::draw()' - Draw a shared image... 00101 // 00102 00103 void 00104 Fl_Tiled_Image::draw(int X, // I - Starting X position 00105 int Y, // I - Starting Y position 00106 int W, // I - Width of area to be filled 00107 int H, // I - Height of area to be filled 00108 int cx, // I - "Source" X position 00109 int cy) { // I - "Source" Y position 00110 if (!image_->w() || !image_->h()) return; 00111 if (W == 0) W = Fl::w(); 00112 if (H == 0) H = Fl::h(); 00113 00114 fl_push_clip(X, Y, W, H); 00115 00116 X += cx; 00117 Y += cy; 00118 00119 X = X - (X % image_->w()); 00120 Y = Y - (Y % image_->h()); 00121 00122 W += X; 00123 H += Y; 00124 00125 for (int yy = Y; yy < H; yy += image_->h()) 00126 for (int xx = X; xx < W; xx += image_->w()) 00127 image_->draw(xx, yy); 00128 00129 fl_pop_clip(); 00130 } 00131 00132 00133 // 00134 // End of "$Id: Fl_Tiled_Image.cxx 7903 2010-11-28 21:06:39Z matt $". 00135 //