00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #if !defined(EXTRA_H_INCLUDED)
00015 #define EXTRA_H_INCLUDED
00016
00017 #include <time.h>
00018 #include <stdio.h>
00019 #include "styles.h"
00020
00021
00022 namespace sjgui
00023 {
00024 using namespace SJGUI_USE_STYLE;
00025 namespace extra
00026 {
00034 class CFPSLabel : public CLabel
00035 {
00036 long m_time;
00037 long m_oldtime;
00038 int m_iFPS;
00039
00040
00041 int m_iOldFPS;
00042
00043
00044 long m_lPeriod;
00045
00046
00047 std::string m_strTemplate;
00048 public:
00049 CFPSLabel():CLabel()
00050 {
00051 m_iFPS=0;
00052 m_iOldFPS=0;
00053 m_strTemplate="FPS:%d";
00054 m_time=clock();
00055 m_lPeriod=1000;
00056 CLabel::SetText("0");
00057 }
00064 void SetText(std::string str){m_strTemplate=str;};
00066 void OnDraw()
00067 {
00068 m_iFPS++;
00069 long new_time=clock();
00070
00071 if(m_time<new_time)
00072 {
00073
00074 int iFPS=(int)(m_iFPS/((double)(new_time-m_oldtime)/m_lPeriod));
00075 if(m_iOldFPS!=iFPS)
00076 {
00077 char buf[50];
00078 sprintf(buf,m_strTemplate.data(),iFPS);
00079 CLabel::SetText(buf);
00080 m_iOldFPS=iFPS;
00081 }
00082
00083 m_iFPS=0;
00084 m_oldtime=new_time;
00085 m_time=new_time+m_lPeriod;
00086 }
00087 CLabel::OnDraw();
00088 }
00089 };
00100 class CFPSLabelDropIn : public CFPSLabel
00101 {
00102 public:
00104 virtual void OnReshape()
00105 {
00106
00107 if(GetParentWnd()!=NULL)
00108 PosWnd(0,GetParentWnd()->GetHeight()-GetHeight(),
00109 GetParentWnd()->GetWidth(), GetHeight());
00110 else
00111 PosWnd(0,GetScreenHeight()-GetHeight(),
00112 GetScreenWidth(), GetHeight());
00113 CFPSLabel::OnReshape();
00114 }
00115 };
00116
00117
00118 }
00119 }
00120
00121 #endif // !defined(EXTRA_H_INCLUDED)