00001 /************************************************************************ 00002 filename: CEGUIProgressBar.cpp 00003 created: 13/4/2004 00004 author: Paul D Turner 00005 00006 purpose: Implementation of ProgressBar widget base class 00007 *************************************************************************/ 00008 /************************************************************************* 00009 Crazy Eddie's GUI System (http://www.cegui.org.uk) 00010 Copyright (C)2004 - 2005 Paul D Turner (paul@cegui.org.uk) 00011 00012 This library is free software; you can redistribute it and/or 00013 modify it under the terms of the GNU Lesser General Public 00014 License as published by the Free Software Foundation; either 00015 version 2.1 of the License, or (at your option) any later version. 00016 00017 This library is distributed in the hope that it will be useful, 00018 but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00020 Lesser General Public License for more details. 00021 00022 You should have received a copy of the GNU Lesser General Public 00023 License along with this library; if not, write to the Free Software 00024 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00025 *************************************************************************/ 00026 #include "elements/CEGUIProgressBar.h" 00027 00028 // Start of CEGUI namespace section 00029 namespace CEGUI 00030 { 00031 const String ProgressBar::EventNamespace("ProgressBar"); 00032 00033 /************************************************************************* 00034 Definitions of Properties for this class 00035 *************************************************************************/ 00036 ProgressBarProperties::CurrentProgress ProgressBar::d_currentProgressProperty; 00037 ProgressBarProperties::StepSize ProgressBar::d_stepSizeProperty; 00038 00039 00040 /************************************************************************* 00041 Event name constants 00042 *************************************************************************/ 00043 const String ProgressBar::EventProgressChanged( (utf8*)"ProgressChanged" ); 00044 const String ProgressBar::EventProgressDone( (utf8*)"ProgressDone" ); 00045 00046 00047 /************************************************************************* 00048 Constructor for ProgressBar class 00049 *************************************************************************/ 00050 ProgressBar::ProgressBar(const String& type, const String& name) : 00051 Window(type, name), 00052 d_progress(0), 00053 d_step(0.01f) 00054 { 00055 addProgressBarEvents(); 00056 addProgressBarProperties(); 00057 } 00058 00059 00060 /************************************************************************* 00061 Destructor for ProgressBar 00062 *************************************************************************/ 00063 ProgressBar::~ProgressBar(void) 00064 { 00065 } 00066 00067 00068 /************************************************************************* 00069 set the current progress. 00070 *************************************************************************/ 00071 void ProgressBar::setProgress(float progress) 00072 { 00073 // legal progress rangeis : 0.0f <= progress <= 1.0f 00074 progress = (progress < 0.0f) ? 0.0f : (progress > 1.0f) ? 1.0f : progress; 00075 00076 if (progress != d_progress) 00077 { 00078 // update progress and fire off event. 00079 d_progress = progress; 00080 WindowEventArgs args(this); 00081 onProgressChanged(args); 00082 00083 // if new progress is 100%, fire off the 'done' event as well. 00084 if (d_progress == 1.0f) 00085 { 00086 onProgressDone(args); 00087 } 00088 00089 } 00090 00091 } 00092 00093 00094 /************************************************************************* 00095 Add progress bar specific events to the window 00096 *************************************************************************/ 00097 void ProgressBar::addProgressBarEvents(void) 00098 { 00099 addEvent(EventProgressChanged); 00100 addEvent(EventProgressDone); 00101 } 00102 00103 /************************************************************************* 00104 event triggered when progress changes 00105 *************************************************************************/ 00106 void ProgressBar::onProgressChanged(WindowEventArgs& e) 00107 { 00108 requestRedraw(); 00109 00110 fireEvent(EventProgressChanged, e, EventNamespace); 00111 } 00112 00113 00114 /************************************************************************* 00115 event triggered when progress reaches 100% 00116 *************************************************************************/ 00117 void ProgressBar::onProgressDone(WindowEventArgs& e) 00118 { 00119 fireEvent(EventProgressDone, e, EventNamespace); 00120 } 00121 00122 /************************************************************************* 00123 add properties defined for this class 00124 *************************************************************************/ 00125 void ProgressBar::addProgressBarProperties(void) 00126 { 00127 addProperty(&d_stepSizeProperty); 00128 addProperty(&d_currentProgressProperty); 00129 } 00130 00131 00132 } // End of CEGUI namespace section