Upstream tarball 20080603
[amule.git] / src / BarShader.h
blob31f62c9197f008403a419ed91e0e488037d5a95f
1 //
2 // This file is part of the aMule Project.
3 //
4 // Copyright (c) 2003-2008 aMule Team ( admin@amule.org / http://www.amule.org )
5 // Copyright (c) 2002 Merkur ( devs@emule-project.net / http://www.emule-project.net )
6 //
7 // Any parts of this program derived from the xMule, lMule or eMule project,
8 // or contributed by third-party developers are copyrighted by their
9 // respective authors.
11 // This program is free software; you can redistribute it and/or modify
12 // it under the terms of the GNU General Public License as published by
13 // the Free Software Foundation; either version 2 of the License, or
14 // (at your option) any later version.
16 // This program is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU General Public License for more details.
20 //
21 // You should have received a copy of the GNU General Public License
22 // along with this program; if not, write to the Free Software
23 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #ifndef BARSHADER_H
27 #define BARSHADER_H
29 #include "Types.h" // Needed for uint16 and uint32
32 class wxRect;
33 class wxDC;
36 /**
37 * The barshader class is responsible for drawing the chunk-based progress bars used in aMule.
39 * CBarShader represents the chunks of a file through the use of spans, which
40 * cover a range in the file with a certain color. New spans can be added on
41 * the fly and old spans are automatically removed, resized or merged when
42 * necessary.
44 * CBarShader will try to minimize the number of spans when possible.
46 class CBarShader
48 public:
49 /**
50 * Constructor.
52 * @param height The height of the area upon which the span is drawn.
53 * @param width The width of the area upon which the span is drawn.
55 CBarShader(uint32 height = 1, uint32 width = 1);
57 /**
58 * Destructor.
60 ~CBarShader();
62 /**
63 * Sets the width of the drawn bar.
65 * @param width The new width.
67 * Setting this sets the width the bar which is used when it
68 * is drawn and resets the pixel buffer to the fill color.
70 void SetWidth(int width);
72 /**
73 * Sets the height of the drawn bar.
75 * @param height The new height.
77 * Changes the height of the bar, used when it is drawn.
79 void SetHeight( int height );
82 /**
83 * Sets the 3D-depth of the bar
85 * @param depth A value in the range from 1 to 5.
87 void Set3dDepth( int depth );
89 /**
90 * Sets a new filesize.
92 * @param fileSize The new filesize.
94 * Calling this function sets a new filesize, which is the virtual
95 * length of the bar. This function must be called before any filling.
97 void SetFileSize(uint64 fileSize);
99 /**
100 * Fills in a range with a certain color.
102 * @param start The starting position of the new span.
103 * @param end The ending position of the new span. Must be larger than start.
104 * @param color The color of the new span.
106 * Calling this function fill the specified range with the specified color.
107 * Any spans completly or partially covered by the new span are either
108 * removed or resized. If the value of end is larger than the current
109 * filesize, the filesize is increased to the value of end.
111 void FillRange(uint64 start, uint64 end, uint32 color);
114 * Fill the entire bar with a span of the specified color.
116 * @param color The color of the new span.
118 void Fill(uint32 color);
121 * Draws the bar on the specifed wxDC.
123 * @param dc The wxDC upon which the bar should be drawn.
124 * @param iLeft The left position from where to start drawing.
125 * @param iTop The top position from where to start drawing.
126 * @param bFlat 3D effect is not applied if this is true.
128 * This functions draws the bar with the height and width specified
129 * through either the contructor or with SetWidth() and SetHeight().
131 void Draw( wxDC* dc, int iLeft, int iTop, bool bFlat );
133 private:
135 * Calculates the modifiers used to create 3d effect.
137 void BuildModifiers();
140 * Fills a rectangle with a given color.
142 * @param dc The DC upon which to draw the bar.
143 * @param rectSpan The area within the specifed DC upon which to draw.
144 * @param color The color of the rectangle.
145 * @param bFlat If this is true, a simple rectangle will be drawn, otherwise the modifers will be applyed to achive a 3D effect.
147 void FillRect(wxDC* dc, const wxRect& rectSpan, uint32 color, bool bFlat);
150 * Blend in a single pixel
152 void BlendPixel(uint32 index, uint32 color, double covered);
154 //! The width of the drawn bar
155 int m_Width;
156 //! The height of the drawn bar
157 int m_Height;
158 //! The virtual filesize assosiated with the bar
159 uint64 m_FileSize;
160 //! Pointer to array of modifers used to create 3D effect. Size is (m_Height+1)/2 when set.
161 double* m_Modifiers;
162 //! The current 3d level
163 uint16 m_used3dlevel;
165 // color for each pixel across the width is stored here
166 std::vector<uint32> m_Content;
169 #endif
170 // File_checked_for_headers