Upstream tarball 20080304
[amule.git] / src / BarShader.h
blobd47fa13303a121aac600dc9e9a3eedfffd3233ea
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
30 #include "RangeMap.h" // Needed for CRangeMap
33 class wxRect;
34 class wxDC;
37 /**
38 * The barshader class is responsible for drawing the chunk-based progress bars used in aMule.
40 * CBarShader represents the chunks of a file through the use of spans, which
41 * cover a range in the file with a certain color. New spans can be added on
42 * the fly and old spans are automatically removed, resized or merged when
43 * necessary.
45 * CBarShader will try to minimize the number of spans when possible.
47 class CBarShader
49 public:
50 /**
51 * Constructor.
53 * @param height The height of the area upon which the span is drawn.
54 * @param width The width of the area upon which the span is drawn.
56 CBarShader(uint32 height = 1, uint32 width = 1);
58 /**
59 * Destructor.
61 ~CBarShader();
63 /**
64 * Sets the width of the drawn bar.
66 * @param width The new width.
68 * Setting this sets the width the bar which is used when it
69 * is drawn. The BarShader automatically fits the intire span-
70 * structure inside this area.
72 void SetWidth(int width) {
73 m_Width = width;
76 /**
77 * Sets the height of the drawn bar.
79 * @param height The new height.
81 * Changes the height of the bar, used when it is drawn.
83 void SetHeight( int height );
86 /**
87 * Sets the 3D-depth of the bar
89 * @param depth A value in the range from 1 to 5.
91 void Set3dDepth( int depth );
94 /**
95 * Returns the current width of the bar.
97 * @return The width of the bar.
99 int GetWidth() const {
100 return m_Width;
104 * Returns the current height of the bar.
106 * @return The height of the bar.
108 int GetHeight() const {
109 return m_Height;
113 * Returns the current 3D-depth of the bar.
115 * @return The 3D-depth of the bar.
117 int Get3dDepth() const {
118 return m_used3dlevel;
123 * Removes all spans from the bar.
125 * Calling this function deletes all current spans and fills the
126 * bar with a black span from 0 to filesize.
128 void Reset();
131 * Sets a new filesize.
133 * @param fileSize The new filesize.
135 * Calling this function sets a new filesize, which is the virtual
136 * length of the bar. This function does not change any spans already
137 * present and therefore, they might end up pointing past current
138 * filesize if the size if smaller than before.
140 void SetFileSize(uint64 fileSize);
143 * Fills in a range with a certain color.
145 * @param start The starting position of the new span.
146 * @param end The ending position of the new span. Must be larger than start.
147 * @param color The color of the new span.
149 * Calling this function fill the specified range with the specified color.
150 * Any spans completly or partially covered by the new span are either
151 * removed or resized. If the value of end is larger than the current
152 * filesize, the filesize is increased to the value of end.
154 void FillRange(uint64 start, uint64 end, const uint32 color);
157 * Fill the entire bar with a span of the specified color.
159 * @param color The color of the new span.
161 void Fill(uint32 color);
164 * Draws the bar on the specifed wxDC.
166 * @param dc The wxDC upon which the bar should be drawn.
167 * @param iLeft The left position from where to start drawing.
168 * @param iTop The top position from where to start drawing.
169 * @param bFlat 3D effect is not applied if this is true.
171 * This functions draws the bar with the height and width specified
172 * through either the contructor or with SetWidth() and SetHeight().
174 void Draw( wxDC* dc, int iLeft, int iTop, bool bFlat );
176 private:
178 * Calculates the modifiers used to create 3d effect.
180 void BuildModifiers();
183 * Fills a rectangle with a given color.
185 * @param dc The DC upon which to draw the bar.
186 * @param rectSpan The area within the specifed DC upon which to draw.
187 * @param color The color of the rectangle.
188 * @param bFlat If this is true, a simple rectangle will be drawn, otherwise the modifers will be applyed to achive a 3D effect.
190 void FillRect(wxDC* dc, const wxRect& rectSpan, uint32 color, bool bFlat);
192 //! The width of the drawn bar
193 int m_Width;
194 //! The height of the drawn bar
195 int m_Height;
196 //! The virtual filesize assosiated with the bar
197 uint64 m_FileSize;
198 //! Pointer to array of modifers used to create 3D effect. Size is (m_Height+1)/2 when set.
199 double* m_Modifiers;
200 //! The current 3d level
201 uint16 m_used3dlevel;
204 //! SpanList is defined as a CRangeMap with uint32s as range-data
205 typedef CRangeMap<uint32> SpanList;
206 //! The list of spans. This list is kept sorted.
207 SpanList m_spanlist;
210 #endif
211 // File_checked_for_headers