1// 2// This file is part of the aMule Project. 3// 4// Copyright (c) 2003-2011 aMule Team ( admin@amule.org / http://www.amule.org ) 5// Copyright (c) 2002-2011 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. 10// 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. 15// 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 24// 25 26#ifndef BARSHADER_H 27#define BARSHADER_H 28 29#include "Types.h" // Needed for uint16 and uint32 30#include "MuleColour.h" 31 32class wxRect; 33class wxDC; 34 35/** 36 * The barshader class is responsible for drawing the chunk-based progress bars used in aMule. 37 * 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. 42 * 43 * CBarShader will try to minimize the number of spans when possible. 44 */ 45class CBarShader 46{ 47public: 48 /** 49 * Constructor. 50 * 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. 53 */ 54 CBarShader(unsigned height = 1, unsigned width = 1); 55 56 /** 57 * Destructor. 58 */ 59 ~CBarShader(); 60 61 /** 62 * Sets the width of the drawn bar. 63 * 64 * @param width The new width. 65 * 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. 68 */ 69 void SetWidth(int width); 70 71 /** 72 * Sets the height of the drawn bar. 73 * 74 * @param height The new height. 75 * 76 * Changes the height of the bar, used when it is drawn. 77 */ 78 void SetHeight(unsigned height); 79 80 /** 81 * Sets the 3D-depth of the bar 82 * 83 * @param depth A value in the range from 1 to 5. 84 */ 85 void Set3dDepth(unsigned depth); 86 87 /** 88 * Sets a new filesize. 89 * 90 * @param fileSize The new filesize. 91 * 92 * Calling this function sets a new filesize, which is the virtual 93 * length of the bar. This function must be called before any filling. 94 */ 95 void SetFileSize(uint64 fileSize) { m_FileSize = fileSize; } 96 97 /** 98 * Fills in a range with a certain color. 99 * 100 * @param start The starting position of the new span. 101 * @param end The ending position of the new span. Must be larger than start. 102 * @param colour The colour of the new span. 103 * 104 * Calling this function fill the specified range with the specified color. 105 * Any spans completly or partially covered by the new span are either 106 * removed or resized. If the value of end is larger than the current 107 * filesize, the filesize is increased to the value of end. 108 */ 109 void FillRange(uint64 start, uint64 end, const CMuleColour& colour); 110 111 /** 112 * Fill the entire bar with a span of the specified color. 113 * 114 * @param colour The colour of the new span. 115 */ 116 void Fill(const CMuleColour& colour) 117 { 118 m_Content.clear(); 119 m_Content.resize(m_Width, colour); 120 } 121 122 /** 123 * Draws the bar on the specifed wxDC. 124 * 125 * @param dc The wxDC upon which the bar should be drawn. 126 * @param iLeft The left position from where to start drawing. 127 * @param iTop The top position from where to start drawing. 128 * @param bFlat 3D effect is not applied if this is true. 129 * 130 * This functions draws the bar with the height and width specified 131 * through either the contructor or with SetWidth() and SetHeight(). 132 */ 133 void Draw( wxDC* dc, int iLeft, int iTop, bool bFlat ); 134 135private: 136 /** 137 * Calculates the modifiers used to create 3d effect. 138 */ 139 void BuildModifiers(); 140 141 //! The width of the drawn bar 142 unsigned m_Width; 143 //! The height of the drawn bar 144 unsigned m_Height; 145 //! The virtual filesize assosiated with the bar 146 uint64 m_FileSize; 147 //! Pointer to array of modifers used to create 3D effect. Size is (m_Height+1)/2 when set. 148 double* m_Modifiers; 149 //! The current 3d level 150 uint16 m_used3dlevel; 151 152 // color for each pixel across the width is stored here 153 std::vector<CMuleColour> m_Content; 154}; 155 156#endif 157// File_checked_for_headers 158