Upstream tarball 20080928
[amule.git] / src / BarShader.h
blobbaa0bab66276e4bcd8e205b48cc6027a7c536b4d
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-2008 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 "MuleColour.h"
32 class wxRect;
33 class wxDC;
35 /**
36 * The barshader class is responsible for drawing the chunk-based progress bars used in aMule.
38 * CBarShader represents the chunks of a file through the use of spans, which
39 * cover a range in the file with a certain color. New spans can be added on
40 * the fly and old spans are automatically removed, resized or merged when
41 * necessary.
43 * CBarShader will try to minimize the number of spans when possible.
45 class CBarShader
47 public:
48 /**
49 * Constructor.
51 * @param height The height of the area upon which the span is drawn.
52 * @param width The width of the area upon which the span is drawn.
54 CBarShader(uint32 height = 1, uint32 width = 1);
56 /**
57 * Destructor.
59 ~CBarShader();
61 /**
62 * Sets the width of the drawn bar.
64 * @param width The new width.
66 * Setting this sets the width the bar which is used when it
67 * is drawn and resets the pixel buffer to the fill color.
69 void SetWidth(int width);
71 /**
72 * Sets the height of the drawn bar.
74 * @param height The new height.
76 * Changes the height of the bar, used when it is drawn.
78 void SetHeight( int height );
81 /**
82 * Sets the 3D-depth of the bar
84 * @param depth A value in the range from 1 to 5.
86 void Set3dDepth( int depth );
88 /**
89 * Sets a new filesize.
91 * @param fileSize The new filesize.
93 * Calling this function sets a new filesize, which is the virtual
94 * length of the bar. This function must be called before any filling.
96 void SetFileSize(uint64 fileSize);
98 /**
99 * Fills in a range with a certain color.
101 * @param start The starting position of the new span.
102 * @param end The ending position of the new span. Must be larger than start.
103 * @param colour The colour of the new span.
105 * Calling this function fill the specified range with the specified color.
106 * Any spans completly or partially covered by the new span are either
107 * removed or resized. If the value of end is larger than the current
108 * filesize, the filesize is increased to the value of end.
110 void FillRange(uint64 start, uint64 end, const CMuleColour& colour);
113 * Fill the entire bar with a span of the specified color.
115 * @param colour The colour of the new span.
117 void Fill(const CMuleColour& colour);
120 * Draws the bar on the specifed wxDC.
122 * @param dc The wxDC upon which the bar should be drawn.
123 * @param iLeft The left position from where to start drawing.
124 * @param iTop The top position from where to start drawing.
125 * @param bFlat 3D effect is not applied if this is true.
127 * This functions draws the bar with the height and width specified
128 * through either the contructor or with SetWidth() and SetHeight().
130 void Draw( wxDC* dc, int iLeft, int iTop, bool bFlat );
132 private:
134 * Calculates the modifiers used to create 3d effect.
136 void BuildModifiers();
139 * Fills a rectangle with a given color.
141 * @param dc The DC upon which to draw the bar.
142 * @param rectSpan The area within the specifed DC upon which to draw.
143 * @param color The color of the rectangle.
144 * @param bFlat If this is true, a simple rectangle will be drawn, otherwise the modifers will be applyed to achive a 3D effect.
146 void FillRect(wxDC* dc, const wxRect& rectSpan, const CMuleColour& colour, bool bFlat);
148 //! The width of the drawn bar
149 int m_Width;
150 //! The height of the drawn bar
151 int m_Height;
152 //! The virtual filesize assosiated with the bar
153 uint64 m_FileSize;
154 //! Pointer to array of modifers used to create 3D effect. Size is (m_Height+1)/2 when set.
155 double* m_Modifiers;
156 //! The current 3d level
157 uint16 m_used3dlevel;
159 // color for each pixel across the width is stored here
160 std::vector<CMuleColour> m_Content;
163 #endif
164 // File_checked_for_headers