00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include "mmsgui/mmsguitools.h"
00034 #include <stdlib.h>
00035
00036 bool getPixelFromSizeHint(int *retpix, string hint, int maxpixel, int secondaxis) {
00037 std::string::size_type pos;
00038 pos = hint.rfind("px");
00039 if (pos == std::string::npos) {
00040
00041 pos = hint.rfind("%");
00042 if (pos == std::string::npos) {
00043
00044 pos = hint.rfind("$");
00045 if (pos == std::string::npos) {
00046
00047 return false;
00048 }
00049 else {
00050
00051 int pix = (int)(atof(hint.substr(0,pos).c_str()) * (double)secondaxis);
00052 if (pix > maxpixel) {
00053
00054 return false;
00055 }
00056 if (retpix) *retpix = pix;
00057 return true;
00058 }
00059 }
00060 else {
00061
00062 int pix = atoi(hint.substr(0,pos).c_str());
00063 if (pix > 100) {
00064
00065 return false;
00066 }
00067 pix = (pix * maxpixel) / 100;
00068
00069 if (hint.substr(pos+1,1)=="-") {
00070
00071 pix-=atoi(hint.substr(pos+2).c_str());
00072 }
00073 else
00074 if (hint.substr(pos+1,1)=="+") {
00075
00076 pix+=atoi(hint.substr(pos+2).c_str());
00077 }
00078
00079 if (retpix) *retpix = pix;
00080 return true;
00081 }
00082 }
00083 else {
00084
00085 int pix = atoi(hint.substr(0,pos).c_str());
00086 if (pix > maxpixel) {
00087
00088 return false;
00089 }
00090
00091 if (hint.substr(pos+2,1)=="-") {
00092
00093 pix-=atoi(hint.substr(pos+3).c_str());
00094 }
00095 else
00096 if (hint.substr(pos+2,1)=="+") {
00097
00098 pix+=atoi(hint.substr(pos+3).c_str());
00099 }
00100
00101 if (retpix) *retpix = pix;
00102 return true;
00103 }
00104 }
00105
00106
00107
00108 #ifdef __HAVE_DIRECTFB__
00109 bool loadImage(IDirectFBImageProvider **image, string path, string filename) {
00110
00111 IDirectFBImageProvider *myimage = NULL;
00112 string imagefile;
00113
00114
00115 if (*image) {
00116 (*image)->Release(*image);
00117 *image = NULL;
00118 }
00119
00120
00121 imagefile = path;
00122 if (imagefile != "") imagefile+= "/";
00123 imagefile += filename;
00124
00125 DEBUGMSG("MMSGUI", "using image file '%s'", imagefile.c_str());
00126
00127 if (filename == "")
00128 return false;
00129
00130 if (filename.substr(filename.size()-1) == "/")
00131 return false;
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142 if (!mmsfb->createImageProvider(&myimage, imagefile)) {
00143
00144
00145 if (myimage)
00146 myimage->Release(myimage);
00147 DEBUGMSG("MMSGUI", "cannot load image file '%s'", imagefile.c_str());
00148 return false;
00149 }
00150
00151
00152
00153
00154 *image = myimage;
00155
00156 return true;
00157 }
00158 #endif
00159
00160 bool loadFont(MMSFBFont **font, string path, string filename, int width, int height) {
00161 MMSFBFont *myfont = NULL;
00162 string fontfile;
00163
00164
00165 if (filename.empty())
00166 return false;
00167
00168 if (filename.at(filename.size()-1) == '/')
00169 return false;
00170
00171
00172 if(path.empty()) {
00173 fontfile = filename;
00174 } else {
00175 fontfile = path + "/" + filename;
00176 }
00177 fixPathStr(fontfile);
00178
00179 DEBUGMSG("MMSGUI", "using font file '%s'", fontfile.c_str());
00180
00181 if (!mmsfb->createFont(&myfont, fontfile, width, height)) {
00182 if (myfont)
00183 delete myfont;
00184 DEBUGMSG("MMSGUI", "cannot load font file '%s'", fontfile.c_str());
00185 return false;
00186 }
00187
00188 if (*font)
00189 delete *font;
00190
00191 *font = myfont;
00192
00193 return true;
00194 }
00195
00196
00197 unsigned int getFrameNum(unsigned int delay_time) {
00198
00199 unsigned int ret = delay_time / 50;
00200 if (ret < 2) ret = 2;
00201 return ret;
00202 }
00203
00204 unsigned int getFrameDelay(unsigned int start_ts, unsigned int end_ts) {
00205 unsigned int diff = getMDiff(start_ts, end_ts);
00206 if (25 > diff)
00207 return 25-diff;
00208 else
00209 return 0;
00210 }
00211