00001 #ifndef OglGui_ProgressBar_h
00002 #define OglGui_ProgressBar_h
00003
00004 #ifndef OglGui_Window_h
00005 #include "OglGui/Window.h"
00006 #endif
00007
00008 namespace OglGui
00009 {
00010
00011 class ProgressBar : public Window
00012 {
00013 public:
00014
00015 ProgressBar(Window* parent, int x, int y, int width, int height,
00016 int borderType = BEV_ETCHED) :
00017 Window(parent, x, y, width, height)
00018 {
00019 Init(borderType);
00020 }
00021
00022 ProgressBar(Window* parent, int width, int height,
00023 int borderType=BEV_ETCHED) :
00024 Window(parent, width, height)
00025 {
00026 Init(borderType);
00027 }
00028
00029 void SetProgress(float val)
00030 {
00031 mPercentage = val;
00032 }
00033
00034 float GetProgress()
00035 {
00036 return mPercentage;
00037 }
00038
00039 void SetHorizontal(bool mode=true)
00040 {
00041 mHorizontal = mode;
00042 }
00043
00044 void SetColors(ULONG startCol=oglLIGHTGREY, ULONG endCol=oglDARKGREEN)
00045 {
00046 mStartColor = startCol;
00047 mEndColor = endCol;
00048 }
00049
00050 void ShowPercentage(bool mode=true)
00051 {
00052 mShowPercentage = mode;
00053 }
00054
00055 virtual void DisplayFunc()
00056 {
00057 OGC myOGC;
00058 ULONG opaq = 0xff000000;
00059 int bInfo[3];
00060 int w = WndWidth(), h = WndHeight();
00061 float mrg = 3;
00062
00063 mPercentage = (mPercentage > 100.0f) ? 100.0f : mPercentage;
00064 if (mPercentage <= 0.0f)
00065 return;
00066
00067 if (GetBorderType() < 2 )
00068 mrg--;
00069 if( w < 4 || h < 4 )
00070 mrg = 0.0f;
00071
00072 w = (mHorizontal ? mPercentage/100.0f : 1.0f) * (w-2*mrg);
00073 h = (mHorizontal ? 1.0f : mPercentage/100.0f) * (h-2*mrg);
00074
00075 OGCSave(&myOGC);
00076
00077 if ( (mStartColor & opaq) != opaq || (mEndColor & opaq) != opaq )
00078 oglSys.StartBlend(bInfo);
00079
00080 if (mHorizontal)
00081 SetFillColors(mStartColor, mEndColor, mEndColor, mStartColor, 0);
00082 else
00083 SetFillColors(mEndColor, mEndColor, mStartColor, mStartColor, 0);
00084
00085 if (IsRounded() )
00086 {
00087 float r0,r1,r2,r3;
00088 GetRoundness(r0,r1,r2,r3);
00089 FillRoundRectExt(mrg, mrg, w, h, r0, r1, r2, r3 );
00090 }
00091 else
00092 FillRectangle(mrg, mrg, w, h);
00093
00094 if (mShowPercentage)
00095 oglSys.PosColPrintf(mOglWnd, 0, mrg, mForeGroundColor,
00096 "%3.0f%s", mPercentage,"%");
00097
00098 if ( (mStartColor & opaq) != opaq || (mEndColor & opaq) != opaq )
00099 oglSys.EndBlend(bInfo);
00100
00101 OGCRestore(&myOGC);
00102 }
00103
00104 private :
00105
00106 float mPercentage;
00107 bool mShowPercentage;
00108 bool mHorizontal;
00109 ULONG mStartColor, mEndColor;
00110
00111 void
00112 Init(int borderType)
00113 {
00114 mPercentage = 0.0f;
00115 mShowPercentage = false;
00116 mHorizontal = true;
00117 SetColors();
00118 SetBorderType(borderType);
00119 SetBorderBackground(oglTrLIGHTGREY);
00120 }
00121 };
00122
00123 }
00124
00125 #endif