Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

progressbar_generic.cpp

Go to the documentation of this file.
00001 /*
00002         ClanGUI, copyrights by various people. Have a look in the CREDITS file.
00003         
00004         This sourcecode is distributed using the Library GNU Public Licence,
00005         version 2 or (at your option) any later version. Please read LICENSE
00006         for details.
00007 */
00008 
00009 #include "precomp.h"
00010 #include "progressbar_generic.h"
00011 #include "API/GUI/progressbar.h"
00012 #include "API/GUI/component.h"
00013 #include "API/GUI/component_options.h"
00014 #include "API/GUI/stylemanager.h"
00015 
00017 // Construction:
00018 
00019 CL_ComponentOptions CL_ProgressBar_Generic::create_options(
00020         const CL_Rect &pos,
00021         int steps)
00022 {
00023         CL_ComponentOptions options;
00024 
00025         options.add_option_as_int("x", pos.x1);
00026         options.add_option_as_int("y", pos.y1);
00027         options.add_option_as_int("width", pos.get_width());
00028         options.add_option_as_int("height", pos.get_height());
00029         options.add_option_as_int("steps", steps);
00030 
00031         return options;
00032 }
00033 
00034 CL_ProgressBar_Generic::CL_ProgressBar_Generic(
00035         CL_ProgressBar *self,
00036         const CL_ComponentOptions &options,
00037         CL_StyleManager *style)
00038 :
00039         progressbar(self),
00040         steps(100),
00041         progress(0)
00042 {
00043         if (options.exists("steps"))
00044                 set_steps(options.get_value_as_int("steps"));
00045         else
00046                 set_steps(100);
00047 }
00048 
00050 // Attributes:
00051 
00052 float CL_ProgressBar_Generic::get_percentage() const
00053 {
00054         return (float)progress / steps;
00055 }
00056 
00058 // Operations:
00059 
00060 void CL_ProgressBar_Generic::set_steps(int total_steps)
00061 {
00062         steps = total_steps;
00063 
00064         if(progress > steps)
00065                 progress = steps;
00066 }
00067 
00068 void CL_ProgressBar_Generic::set_progress(int new_progress)
00069 {
00070         progress = new_progress;
00071         if(progress > steps)
00072                 progress = steps;
00073         if(progress < 0)
00074                 progress = 0;
00075 }
00076 
00077 void CL_ProgressBar_Generic::increase(int steps)
00078 {
00079         set_progress(progress + steps);
00080 }
00081 
00082 void CL_ProgressBar_Generic::reset()
00083 {
00084         progress = 0;
00085 }
00086 
00088 // Callbacks:
00089 
00091 // Implementation:
00092 

Generated at Wed Apr 4 19:54:02 2001 for ClanLib by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001