| 1 | /* Copyright 2012 Kjetil S. Matheussen |
| 2 | |
| 3 | This program is free software; you can redistribute it and/or |
| 4 | modify it under the terms of the GNU General Public License |
| 5 | as published by the Free Software Foundation; either version 2 |
| 6 | of the License, or (at your option) any later version. |
| 7 | |
| 8 | This program is distributed in the hope that it will be useful, |
| 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | GNU General Public License for more details. |
| 12 | |
| 13 | You should have received a copy of the GNU General Public License |
| 14 | along with this program; if not, write to the Free Software |
| 15 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
| 16 | |
| 17 | |
| 18 | |
| 19 | #ifdef COMPILING_RADIUM |
| 20 | extern struct Root *root; |
| 21 | #else |
| 22 | extern QColor *g_colors; |
| 23 | #endif |
| 24 | |
| 25 | |
| 26 | static inline QColor mix_colors(const QColor &c1, const QColor &c2, float how_much){ |
| 27 | |
| 28 | float a1 = how_much; |
| 29 | float a2 = 1.0f-a1; |
| 30 | |
| 31 | if(c1.red()==0 && c1.green()==0 && c1.blue()==0){ // some of the black lines doesn't look look very good. |
| 32 | int r = 74*a1 + c2.red()*a2; |
| 33 | int g = 74*a1 + c2.green()*a2; |
| 34 | int b = 74*a1 + c2.blue()*a2; |
| 35 | |
| 36 | return QColor(r,g,b); |
| 37 | }else{ |
| 38 | |
| 39 | int r = c1.red()*a1 + c2.red()*a2; |
| 40 | int g = c1.green()*a1 + c2.green()*a2; |
| 41 | int b = c1.blue()*a1 + c2.blue()*a2; |
| 42 | |
| 43 | return QColor(r,g,b); |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | |
| 48 | static inline void SLIDERPAINTERPAINTER_paint(QPainter *p, int x1, int y1, int x2, int y2, bool is_enabled, float val, QString text, bool alternative_color){ |
| 49 | #ifdef COMPILING_RADIUM |
| 50 | QColor *colors = static_cast<EditorWidget*>(root->song->tracker_windows->os_visual.widget)->colors; |
| 51 | #else |
| 52 | QColor *colors = g_colors; |
| 53 | #endif |
| 54 | |
| 55 | int height = y2-y1; |
| 56 | int width = x2-x1; |
| 57 | |
| 58 | QColor col1; |
| 59 | QColor col1b; |
| 60 | |
| 61 | int col1num = 11; |
| 62 | |
| 63 | if(is_enabled){ |
| 64 | QColor c(98,59,33); |
| 65 | |
| 66 | col1 = c.light(90); |
| 67 | col1b = colors[13].light(100); |
| 68 | }else{ |
| 69 | col1 = mix_colors(colors[col1num], Qt::gray, 0.8f); |
| 70 | col1b = mix_colors(colors[col1num].light(110), Qt::gray, 0.8f); |
| 71 | } |
| 72 | |
| 73 | if(alternative_color==true) |
| 74 | col1 = QColor(200,200,200); |
| 75 | |
| 76 | if(alternative_color==false){ |
| 77 | col1.setAlpha(80); |
| 78 | col1b.setAlpha(100); |
| 79 | }else{ |
| 80 | col1.setAlpha(120); |
| 81 | col1b.setAlpha(120); |
| 82 | } |
| 83 | |
| 84 | if(height > width){ // i.e. vertical |
| 85 | int pos=scale(val,0,1,0,height); |
| 86 | p->fillRect(0,pos,width,height-pos,col1); |
| 87 | }else{ |
| 88 | int pos=scale(val,0,1,0,width); |
| 89 | QLinearGradient gradient(0,0,width,height*3/4); |
| 90 | if(alternative_color==false) |
| 91 | gradient.setColorAt(0,col1.light(100)); |
| 92 | else |
| 93 | gradient.setColorAt(0,col1.light(150)); |
| 94 | gradient.setColorAt(1,col1b); |
| 95 | |
| 96 | p->setPen(QPen(QColor(Qt::gray).light(50),1)); |
| 97 | p->setBrush(gradient); |
| 98 | p->drawRect(0 ,0, pos, height); |
| 99 | p->setBrush(QBrush()); |
| 100 | } |
| 101 | |
| 102 | p->setPen(QPen(colors[11].light(110),1)); |
| 103 | p->drawRect(0,0,width,height); |
| 104 | |
| 105 | QRect rect(5,2,width-5,height-2); |
| 106 | |
| 107 | if(text!=""){ |
| 108 | QColor c(colors[1]); |
| 109 | if(is_enabled){ |
| 110 | c.setAlpha(160); |
| 111 | p->setPen(QPen(c,1)); |
| 112 | }else{ |
| 113 | c.setAlpha(60); |
| 114 | p->setPen(QPen(c,1)); |
| 115 | } |
| 116 | p->drawText(rect, Qt::AlignLeft, text); |
| 117 | } |
| 118 | |
| 119 | } |
| 120 |