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

mmsborder.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/mmsborder.h"
00034 #include "mmsgui/mmsguitools.h"
00035 #include <math.h>
00036 
00037 void drawBorder(unsigned int borderThickness, bool borderRCorners, MMSFBSurface *borderimages[],
00038                 MMSFBRectangle bordergeom[], bool *bordergeomset, MMSFBSurface *surface,
00039                 unsigned int x, unsigned int y, unsigned int width, unsigned int height, MMSFBColor color,
00040                 MMSImageManager *im, unsigned char brightness, unsigned char opacity) {
00041     int bic = 8;
00042 
00043     /* draw border? */
00044     if (!borderThickness)
00045         return;
00046 
00047     /* lock */
00048     surface->lock();
00049 
00050     /* set the blitting flags */
00051     unsigned char alpha = 255;
00052     if (color.a) alpha = color.a;
00053     surface->setBlittingFlagsByBrightnessAlphaAndOpacity(brightness, alpha, opacity);
00054 
00055     /* draw images around the widget */
00056     /* FIRST: corners */
00057     /* image #1 (top-left) */
00058     if (borderimages[0]) {
00059         borderimages[0]->lock();
00060         if (!*bordergeomset) {
00061             int ww, hh;
00062             borderimages[0]->getSize(&ww, &hh);
00063             bordergeom[0].x = x;
00064             bordergeom[0].y = y;
00065             bordergeom[0].w = ww;
00066             bordergeom[0].h = hh;
00067         }
00068         surface->stretchBlit(borderimages[0], NULL, &bordergeom[0]);
00069         borderimages[0]->unlock();
00070         bic--;
00071     }
00072     else {
00073         if (borderRCorners) {
00074             bordergeom[0].x = x;
00075             bordergeom[0].y = y;
00076             bordergeom[0].w = 2*borderThickness;
00077             bordergeom[0].h = 2*borderThickness;
00078         }
00079         else {
00080             bordergeom[0].x = x;
00081             bordergeom[0].y = y;
00082             bordergeom[0].w = borderThickness;
00083             bordergeom[0].h = borderThickness;
00084         }
00085     }
00086     /* image #3 (top-right) */
00087     if (borderimages[2]) {
00088         borderimages[2]->lock();
00089         if (!*bordergeomset) {
00090             int ww, hh;
00091             borderimages[2]->getSize(&ww, &hh);
00092             bordergeom[2].x = x + width - ww;
00093             bordergeom[2].y = y;
00094             bordergeom[2].w = ww;
00095             bordergeom[2].h = hh;
00096         }
00097         surface->stretchBlit(borderimages[2], NULL, &bordergeom[2]);
00098         bic--;
00099         borderimages[2]->unlock();
00100     }
00101     else {
00102         if (borderRCorners) {
00103             bordergeom[2].x = x + width - 2*borderThickness;
00104             bordergeom[2].y = y;
00105             bordergeom[2].w = 2*borderThickness;
00106             bordergeom[2].h = 2*borderThickness;
00107         }
00108         else {
00109             bordergeom[2].x = x + width - borderThickness;
00110             bordergeom[2].y = y;
00111             bordergeom[2].w = borderThickness;
00112             bordergeom[2].h = borderThickness;
00113         }
00114     }
00115     /* image #5 (bottom-right) */
00116     if (borderimages[4]) {
00117         borderimages[4]->lock();
00118         if (!*bordergeomset) {
00119             int ww, hh;
00120             borderimages[4]->getSize(&ww, &hh);
00121             bordergeom[4].x = x + width - ww;
00122             bordergeom[4].y = y + height - hh;
00123             bordergeom[4].w = ww;
00124             bordergeom[4].h = hh;
00125         }
00126         surface->stretchBlit(borderimages[4], NULL, &bordergeom[4]);
00127         borderimages[4]->unlock();
00128         bic--;
00129     }
00130     else {
00131         if (borderRCorners) {
00132             bordergeom[4].x = x + width - 2*borderThickness;
00133             bordergeom[4].y = y + height - 2*borderThickness;
00134             bordergeom[4].w = 2*borderThickness;
00135             bordergeom[4].h = 2*borderThickness;
00136         } else {
00137             bordergeom[4].x = x + width - borderThickness;
00138             bordergeom[4].y = y + height - borderThickness;
00139             bordergeom[4].w = borderThickness;
00140             bordergeom[4].h = borderThickness;
00141         }
00142     }
00143     /* image #7 (bottom-left) */
00144     if (borderimages[6]) {
00145         borderimages[6]->lock();
00146         if (!*bordergeomset) {
00147             int ww, hh;
00148             borderimages[6]->getSize(&ww, &hh);
00149             bordergeom[6].x = x;
00150             bordergeom[6].y = y + height - hh;
00151             bordergeom[6].w = ww;
00152             bordergeom[6].h = hh;
00153         }
00154         surface->stretchBlit(borderimages[6], NULL, &bordergeom[6]);
00155         borderimages[6]->unlock();
00156         bic--;
00157     }
00158     else {
00159         if (borderRCorners) {
00160             bordergeom[6].x = x;
00161             bordergeom[6].y = y + height - 2*borderThickness;
00162             bordergeom[6].w = 2*borderThickness;
00163             bordergeom[6].h = 2*borderThickness;
00164         } else {
00165             bordergeom[6].x = x;
00166             bordergeom[6].y = y + height - borderThickness;
00167             bordergeom[6].w = borderThickness;
00168             bordergeom[6].h = borderThickness;
00169         }
00170     }
00171 
00172     /* SECOND: horizontal/vertical lines */
00173     /* image #2 (top) */
00174     if (borderimages[1]) {
00175         borderimages[1]->lock();
00176         if (!*bordergeomset) {
00177             int ww, hh;
00178             borderimages[1]->getSize(&ww, &hh);
00179             bordergeom[1].x = bordergeom[0].x + bordergeom[0].w;
00180             bordergeom[1].y = y;
00181             bordergeom[1].w = bordergeom[2].x - bordergeom[1].x;
00182             bordergeom[1].h = hh;
00183         }
00184         surface->stretchBlit(borderimages[1], NULL, &bordergeom[1]);
00185         borderimages[1]->unlock();
00186         bic--;
00187     }
00188     else {
00189         bordergeom[1].x = bordergeom[0].x + bordergeom[0].w;
00190         bordergeom[1].y = y;
00191         bordergeom[1].w = bordergeom[2].x - bordergeom[1].x;
00192         bordergeom[1].h = borderThickness;
00193     }
00194     /* image #4 (right) */
00195     if (borderimages[3]) {
00196         borderimages[3]->lock();
00197         if (!*bordergeomset) {
00198             int ww, hh;
00199             borderimages[3]->getSize(&ww, &hh);
00200             bordergeom[3].x = x + width - ww;
00201             bordergeom[3].y = bordergeom[2].y + bordergeom[2].h;
00202             bordergeom[3].w = ww;
00203             bordergeom[3].h = bordergeom[4].y - bordergeom[3].y;
00204         }
00205         surface->stretchBlit(borderimages[3], NULL, &bordergeom[3]);
00206         borderimages[3]->unlock();
00207         bic--;
00208     }
00209     else {
00210         bordergeom[3].x = x + width - borderThickness;
00211         bordergeom[3].y = bordergeom[2].y + bordergeom[2].h;
00212         bordergeom[3].w = borderThickness;
00213         bordergeom[3].h = bordergeom[4].y - bordergeom[3].y;
00214     }
00215     /* image #6 (bottom) */
00216     if (borderimages[5]) {
00217         borderimages[5]->lock();
00218         if (!*bordergeomset) {
00219             int ww, hh;
00220             borderimages[5]->getSize(&ww, &hh);
00221             bordergeom[5].x = bordergeom[6].x + bordergeom[6].w;
00222             bordergeom[5].y = y + height - hh;
00223             bordergeom[5].w = bordergeom[4].x - bordergeom[5].x;
00224             bordergeom[5].h = hh;
00225         }
00226         surface->stretchBlit(borderimages[5], NULL, &bordergeom[5]);
00227         borderimages[5]->unlock();
00228         bic--;
00229     }
00230     else {
00231         bordergeom[5].x = bordergeom[6].x + bordergeom[6].w;
00232         bordergeom[5].y = y + height - borderThickness;
00233         bordergeom[5].w = bordergeom[4].x - bordergeom[5].x;
00234         bordergeom[5].h = borderThickness;
00235     }
00236     /* image #8 (left) */
00237     if (borderimages[7]) {
00238         borderimages[7]->lock();
00239         if (!*bordergeomset) {
00240             int ww, hh;
00241             borderimages[7]->getSize(&ww, &hh);
00242             bordergeom[7].x = x;
00243             bordergeom[7].y = bordergeom[0].y + bordergeom[0].h;
00244             bordergeom[7].w = ww;
00245             bordergeom[7].h = bordergeom[6].y - bordergeom[7].y;
00246         }
00247         surface->stretchBlit(borderimages[7], NULL, &bordergeom[7]);
00248         borderimages[7]->unlock();
00249         bic--;
00250     }
00251     else {
00252         bordergeom[7].x = x;
00253         bordergeom[7].y = bordergeom[0].y + bordergeom[0].h;
00254         bordergeom[7].w = borderThickness;
00255         bordergeom[7].h = bordergeom[6].y - bordergeom[7].y;
00256     }
00257 
00258     /* border geom is set */
00259     *bordergeomset = true;
00260 
00261     /* if bic not 0 then at least one borderimage is not set  */
00262     if (bic) {
00263         /* draw lines around the widget */
00264         /* here we create surfaces and draw lines only once */
00265 
00266         /* get the pixelformat of windows surface */
00267 /*        DFBSurfacePixelFormat pixelformat;
00268         surface->GetPixelFormat(surface, &pixelformat);
00269 pixelformat=DSPF_ALUT44;
00270 */
00271         /* FIRST: corners */
00272         /* (top-left) */
00273         if (!borderimages[0]) {
00274             /* create newImage surface */
00275             if ((borderimages[0] = im->newImage("", bordergeom[0].w, bordergeom[0].h))) {
00276                 borderimages[0]->lock();
00277                 borderimages[0]->clear();
00278                 if (color.a) {
00279                     borderimages[0]->setColor(color.r, color.g, color.b, 255);
00280                     if (borderRCorners) {
00281                         /* draw a round corner with circles */
00282                         if (bordergeom[0].w > 1) {
00283                             int j1 = bordergeom[0].w - 1;
00284                             int j2 = j1-1;
00285                             borderimages[0]->drawCircle(j1, j1, j1, 6, 7);
00286                             for (unsigned int i = 1; i < borderThickness; i++) {
00287                                 int j3 = j1-i;
00288                                 borderimages[0]->drawCircle(j2, j1, j3, 6, 7);
00289                                 borderimages[0]->drawCircle(j1, j2, j3, 6, 7);
00290                                 borderimages[0]->drawCircle(j1, j1, j3, 6, 7);
00291                             }
00292                         }
00293                     }
00294                     else {
00295                         // the corner is like an rectangle
00296                         borderimages[0]->fillRectangle(0, 0, bordergeom[0].w, bordergeom[0].h);
00297                     }
00298                 }
00299 
00300                 /* set the blitting flags */
00301                 surface->setBlittingFlagsByBrightnessAlphaAndOpacity(brightness, alpha, opacity);
00302 
00303                 /* blit the first time */
00304                 surface->stretchBlit(borderimages[0], NULL, &bordergeom[0]);
00305                 borderimages[0]->unlock();
00306             }
00307         }
00308         /* (top-right) */
00309         if (!borderimages[2]) {
00310             /* create newImage surface */
00311             if ((borderimages[2] = im->newImage("", bordergeom[2].w, bordergeom[2].h))) {
00312                 borderimages[2]->lock();
00313                 borderimages[2]->clear();
00314                 if (color.a) {
00315                     borderimages[2]->setColor(color.r, color.g, color.b, 255);
00316                     if (borderRCorners) {
00317                         /* draw a round corner with circles */
00318                         if (bordergeom[2].w > 1) {
00319                             int j1 = bordergeom[2].w - 1;
00320                             int j2 = j1-1;
00321                             borderimages[2]->drawCircle(0, j1, j1, 0, 1);
00322                             for (unsigned int i = 1; i < borderThickness; i++) {
00323                                 int j3 = j1-i;
00324                                 borderimages[2]->drawCircle(1, j1, j3, 0, 1);
00325                                 borderimages[2]->drawCircle(0, j2, j3, 0, 1);
00326                                 borderimages[2]->drawCircle(0, j1, j3, 0, 1);
00327                             }
00328                         }
00329                     }
00330                     else {
00331                         // the corner is like an rectangle
00332                         borderimages[2]->fillRectangle(0, 0, bordergeom[2].w, bordergeom[2].h);
00333                     }
00334                 }
00335 
00336                 /* set the blitting flags */
00337                 surface->setBlittingFlagsByBrightnessAlphaAndOpacity(brightness, alpha, opacity);
00338 
00339                 /* blit the first time */
00340                 surface->stretchBlit(borderimages[2], NULL, &bordergeom[2]);
00341                 borderimages[2]->unlock();
00342             }
00343         }
00344         /* (bottom-right) */
00345         if (!borderimages[4]) {
00346             /* create newImage surface */
00347             if ((borderimages[4] = im->newImage("", bordergeom[4].w, bordergeom[4].h))) {
00348                 borderimages[4]->lock();
00349                 borderimages[4]->clear();
00350                 if (color.a) {
00351                     borderimages[4]->setColor(color.r, color.g, color.b, 255);
00352                     if (borderRCorners) {
00353                         /* draw a round corner with circles */
00354                         if (bordergeom[4].w > 1) {
00355                             int j1 = bordergeom[4].w - 1;
00356                             borderimages[4]->drawCircle(0, 0, j1, 2, 3);
00357                             for (unsigned int i = 1; i < borderThickness; i++) {
00358                                 int j3 = j1-i;
00359                                 borderimages[4]->drawCircle(1, 0, j3, 2, 3);
00360                                 borderimages[4]->drawCircle(0, 1, j3, 2, 3);
00361                                 borderimages[4]->drawCircle(0, 0, j3, 2, 3);
00362                             }
00363                         }
00364                     }
00365                     else {
00366                         // the corner is like an rectangle
00367                         borderimages[4]->fillRectangle(0, 0, bordergeom[4].w, bordergeom[4].h);
00368                     }
00369                 }
00370 
00371                 /* set the blitting flags */
00372                 surface->setBlittingFlagsByBrightnessAlphaAndOpacity(brightness, alpha, opacity);
00373 
00374                 /* blit the first time */
00375                 surface->stretchBlit(borderimages[4], NULL, &bordergeom[4]);
00376                 borderimages[4]->unlock();
00377             }
00378         }
00379         /* (bottom-left) */
00380         if (!borderimages[6]) {
00381             /* create newImage surface */
00382             if ((borderimages[6] = im->newImage("", bordergeom[6].w, bordergeom[6].h))) {
00383                 borderimages[6]->lock();
00384                 borderimages[6]->clear();
00385                 if (color.a) {
00386                     borderimages[6]->setColor(color.r, color.g, color.b, 255);
00387                     if (borderRCorners) {
00388                         /* draw a round corner with circles */
00389                         if (bordergeom[6].w > 1) {
00390                             int j1 = bordergeom[6].w - 1;
00391                             int j2 = j1-1;
00392                             borderimages[6]->drawCircle(j1, 0, j1, 4, 5);
00393                             for (unsigned int i = 1; i < borderThickness; i++) {
00394                                 int j3 = j1-i;
00395                                 borderimages[6]->drawCircle(j2, 0, j3, 4, 5);
00396                                 borderimages[6]->drawCircle(j1, 1, j3, 4, 5);
00397                                 borderimages[6]->drawCircle(j1, 0, j3, 4, 5);
00398                             }
00399                         }
00400                     }
00401                     else {
00402                         // the corner is like an rectangle
00403                         borderimages[6]->fillRectangle(0, 0, bordergeom[6].w, bordergeom[6].h);
00404                     }
00405                 }
00406 
00407                 /* set the blitting flags */
00408                 surface->setBlittingFlagsByBrightnessAlphaAndOpacity(brightness, alpha, opacity);
00409 
00410                 /* blit the first time */
00411                 surface->stretchBlit(borderimages[6], NULL, &bordergeom[6]);
00412                 borderimages[6]->unlock();
00413             }
00414         }
00415 
00416         /* SECOND: horizontal/vertical lines */
00417         /* (top) */
00418         if (!borderimages[1]) {
00419             /* create newImage surface */
00420             if ((borderimages[1] = im->newImage("", bordergeom[1].w, bordergeom[1].h))) {
00421                 borderimages[1]->lock();
00422                 borderimages[1]->clear();
00423                 if (color.a) {
00424                     borderimages[1]->setColor(color.r, color.g, color.b, 255);
00425                     borderimages[1]->fillRectangle(0, 0, bordergeom[1].w, bordergeom[1].h);
00426                 }
00427 
00428                 /* set the blitting flags */
00429                 surface->setBlittingFlagsByBrightnessAlphaAndOpacity(brightness, alpha, opacity);
00430 
00431                 /* blit the first time */
00432                 surface->stretchBlit(borderimages[1], NULL, &bordergeom[1]);
00433                 borderimages[1]->unlock();
00434             }
00435         }
00436         /* (right) */
00437         if (!borderimages[3]) {
00438             /* create newImage surface */
00439             if ((borderimages[3] = im->newImage("", bordergeom[3].w, bordergeom[3].h))) {
00440                 borderimages[3]->lock();
00441                 borderimages[3]->clear();
00442                 if (color.a) {
00443                     borderimages[3]->setColor(color.r, color.g, color.b, 255);
00444                     borderimages[3]->fillRectangle(0, 0, bordergeom[3].w, bordergeom[3].h);
00445                 }
00446 
00447                 /* set the blitting flags */
00448                 surface->setBlittingFlagsByBrightnessAlphaAndOpacity(brightness, alpha, opacity);
00449 
00450                 /* blit the first time */
00451                 surface->stretchBlit(borderimages[3], NULL, &bordergeom[3]);
00452                 borderimages[3]->unlock();
00453             }
00454         }
00455         /* (bottom) */
00456         if (!borderimages[5]) {
00457             /* create newImage surface */
00458             if ((borderimages[5] = im->newImage("", bordergeom[5].w, bordergeom[5].h))) {
00459                 borderimages[5]->lock();
00460                 borderimages[5]->clear();
00461                 if (color.a) {
00462                     borderimages[5]->setColor(color.r, color.g, color.b, 255);
00463                     borderimages[5]->fillRectangle(0, 0, bordergeom[5].w, bordergeom[5].h);
00464                 }
00465 
00466                 /* set the blitting flags */
00467                 surface->setBlittingFlagsByBrightnessAlphaAndOpacity(brightness, alpha, opacity);
00468 
00469                 /* blit the first time */
00470                 surface->stretchBlit(borderimages[5], NULL, &bordergeom[5]);
00471                 borderimages[5]->unlock();
00472             }
00473         }
00474         /* (left) */
00475         if (!borderimages[7]) {
00476             /* create newImage surface */
00477             if ((borderimages[7] = im->newImage("", bordergeom[7].w, bordergeom[7].h))) {
00478                 borderimages[7]->lock();
00479                 borderimages[7]->clear();
00480                 if (color.a) {
00481                     borderimages[7]->setColor(color.r, color.g, color.b, 255);
00482                     borderimages[7]->fillRectangle(0, 0, bordergeom[7].w, bordergeom[7].h);
00483                 }
00484 
00485                 /* set the blitting flags */
00486                 surface->setBlittingFlagsByBrightnessAlphaAndOpacity(brightness, alpha, opacity);
00487 
00488                 /* blit the first time */
00489                 surface->stretchBlit(borderimages[7], NULL, &bordergeom[7]);
00490                 borderimages[7]->unlock();
00491             }
00492         }
00493     }
00494 
00495     /* unlock */
00496     surface->unlock();
00497 }
00498 

Generated by doxygen