Logo
  • Main Page
  • Related Pages
  • Modules
  • Classes
  • Files

mmsguitools.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2005-2007 Stefan Schwarzer, Jens Schneider,             *
00003  *                           Matthias Hardt, Guido Madaus                  *
00004  *                                                                         *
00005  *   Copyright (C) 2007-2008 BerLinux Solutions GbR                        *
00006  *                           Stefan Schwarzer & Guido Madaus               *
00007  *                                                                         *
00008  *   Copyright (C) 2009-2013 BerLinux Solutions GmbH                       *
00009  *                                                                         *
00010  *   Authors:                                                              *
00011  *      Stefan Schwarzer   <stefan.schwarzer@diskohq.org>,                 *
00012  *      Matthias Hardt     <matthias.hardt@diskohq.org>,                   *
00013  *      Jens Schneider     <jens.schneider@diskohq.org>,                   *
00014  *      Guido Madaus       <guido.madaus@diskohq.org>,                     *
00015  *      Patrick Helterhoff <patrick.helterhoff@diskohq.org>,               *
00016  *      René Bählkow       <rene.baehlkow@diskohq.org>                     *
00017  *                                                                         *
00018  *   This library is free software; you can redistribute it and/or         *
00019  *   modify it under the terms of the GNU Lesser General Public            *
00020  *   License version 2.1 as published by the Free Software Foundation.     *
00021  *                                                                         *
00022  *   This library is distributed in the hope that it will be useful,       *
00023  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00024  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
00025  *   Lesser General Public License for more details.                       *
00026  *                                                                         *
00027  *   You should have received a copy of the GNU Lesser General Public      *
00028  *   License along with this library; if not, write to the                 *
00029  *   Free Software Foundation, Inc.,                                       *
00030  *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA            *
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         /* its not px */
00041         pos = hint.rfind("%");
00042         if (pos == std::string::npos) {
00043             /* its not %, failed */
00044             pos = hint.rfind("$");
00045             if (pos == std::string::npos) {
00046                 /* its not $, failed */
00047                 return false;
00048             }
00049             else {
00050                 /* use factor with secondaxis parameter */
00051                 int pix = (int)(atof(hint.substr(0,pos).c_str()) * (double)secondaxis);
00052                 if (pix > maxpixel) {
00053                     /* greater than maxpixel, failed */
00054                     return false;
00055                 }
00056                 if (retpix) *retpix = pix;
00057                 return true;
00058             }
00059         }
00060         else {
00061             /* calculate percent to pixel */
00062             int pix = atoi(hint.substr(0,pos).c_str());
00063             if (pix > 100) {
00064                 /* greater than 100%, failed */
00065                 return false;
00066             }
00067             pix = (pix * maxpixel) / 100;
00068 
00069             if (hint.substr(pos+1,1)=="-") {
00070                 /* subtract a value from calculated percent size */
00071                 pix-=atoi(hint.substr(pos+2).c_str());
00072             }
00073             else
00074             if (hint.substr(pos+1,1)=="+") {
00075                 /* add a value to calculated percent size */
00076                 pix+=atoi(hint.substr(pos+2).c_str());
00077             }
00078 
00079             if (retpix) *retpix = pix;
00080             return true;
00081         }
00082     }
00083     else {
00084         /* use pixel values */
00085         int pix = atoi(hint.substr(0,pos).c_str());
00086         if (pix > maxpixel) {
00087             /* greater than maxpixel, failed */
00088             return false;
00089         }
00090 
00091         if (hint.substr(pos+2,1)=="-") {
00092             /* subtract a value from pixel */
00093             pix-=atoi(hint.substr(pos+3).c_str());
00094         }
00095         else
00096         if (hint.substr(pos+2,1)=="+") {
00097             /* add a value to pixel */
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 //    IDirectFB              *mydfb = NULL;
00111     IDirectFBImageProvider *myimage = NULL;
00112     string                 imagefile;
00113 
00114     /* free old image */
00115     if (*image) {
00116         (*image)->Release(*image);
00117         *image = NULL;
00118     }
00119 
00120     /* build filename */
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     /* open dfb access */
00134 /*    if (!dfb) {
00135         if(DirectFBCreate(&mydfb)!= DFB_OK)
00136             return false;
00137     }
00138     else
00139         mydfb = dfb;*/
00140 
00141 //    if (mydfb->CreateImageProvider(mydfb, imagefile.c_str(), &myimage) != DFB_OK) {
00142     if (!mmsfb->createImageProvider(&myimage, imagefile)) {
00143 /*        if (!dfb)
00144             mydfb->Release(mydfb);*/
00145         if (myimage)
00146             myimage->Release(myimage);
00147         DEBUGMSG("MMSGUI", "cannot load image file '%s'", imagefile.c_str());
00148         return false;
00149     }
00150 
00151 /*    if (!dfb)
00152         mydfb->Release(mydfb);*/
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     /* sanity checks */
00165     if (filename.empty())
00166         return false;
00167 
00168     if (filename.at(filename.size()-1) == '/')
00169         return false;
00170 
00171     /* build filename */
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     // a frame every 50ms
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 

Generated by doxygen