blob: 1857480aff8be78eddc7fdcb9868b42e09ddaa07 [file] [log] [blame]
DRC2ff39b82011-07-28 08:38:59 +00001//
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.
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
28
29#include <FL/Fl.H>
30#include <FL/Fl_Tiled_Image.H>
31#include <FL/fl_draw.H>
32
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.
36*/
37Fl_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;
43
44 if (W == 0) w(Fl::w());
45 if (H == 0) h(Fl::h());
46}
47/**
48 The destructor frees all memory and server resources that are used by
49 the tiled image.
50*/
51 Fl_Tiled_Image::~Fl_Tiled_Image() {
52 if (alloc_image_) delete image_;
53}
54
55
56//
57// 'Fl_Tiled_Image::copy()' - Copy and resize a tiled image...
58//
59
60Fl_Image * // O - New image
61Fl_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);
65}
66
67
68//
69// 'Fl_Tiled_Image::color_average()' - Blend colors...
70//
71
72void
73Fl_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;
78 }
79
80 image_->color_average(c, i);
81}
82
83
84//
85// 'Fl_Tiled_Image::desaturate()' - Convert the image to grayscale...
86//
87
88void
89Fl_Tiled_Image::desaturate() {
90 if (!alloc_image_) {
91 image_ = image_->copy();
92 alloc_image_ = 1;
93 }
94
95 image_->desaturate();
96}
97
98
99//
100// 'Fl_Tiled_Image::draw()' - Draw a shared image...
101//
102
103void
104Fl_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();
113
114 fl_push_clip(X, Y, W, H);
115
116 X += cx;
117 Y += cy;
118
119 X = X - (X % image_->w());
120 Y = Y - (Y % image_->h());
121
122 W += X;
123 H += Y;
124
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);
128
129 fl_pop_clip();
130}
131
132
133//
134// End of "$Id: Fl_Tiled_Image.cxx 7903 2010-11-28 21:06:39Z matt $".
135//