1 /*
2 FXiTe - The Free eXtensIble Text Editor
3 Copyright (c) 2009-2011 Jeffrey Pohlmeyer <yetanothergeek@gmail.com>
4
5 This program is free software; you can redistribute it and/or modify it
6 under the terms of the GNU General Public License version 3 as
7 published by the Free Software Foundation.
8
9 This software is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19
20 #include <fx.h>
21 #include "shady_tabs.h"
22
23 FXDEFMAP(ShadyTabs) ShadyTabsMap[]={};
24
25 FXIMPLEMENT(ShadyTabs,FXTabBook,ShadyTabsMap,ARRAYNUMBER(ShadyTabsMap));
26
27
ShadyTabs(FXComposite * p,FXObject * tgt,FXSelector sel,FXuint opts,FXint x,FXint y,FXint w,FXint h,FXint pl,FXint pr,FXint pt,FXint pb)28 ShadyTabs::ShadyTabs( FXComposite* p, FXObject* tgt, FXSelector sel ,FXuint opts, FXint x, FXint y,
29 FXint w, FXint h,FXint pl, FXint pr,FXint pt,FXint pb
30 ):FXTabBook(p,tgt,sel,opts,x,y,w,h,pl,pr,pt,pb)
31 {
32
33 }
34
35 #define brightness(c) ( \
36 ( (299*FXREDVAL(c)) + (587*FXGREENVAL(c)) + (114*FXBLUEVAL(c)) ) / 1000 )
37
38
39
shade(FXColor c,bool brighten,bool istext,FXColor other)40 static FXColor shade(FXColor c, bool brighten, bool istext, FXColor other)
41 {
42 FXfloat h=0, s=0, v=0; // H is 0..360; S is 0..1; V is 0..255
43 FXfloat r=FXREDVAL(c), g=FXGREENVAL(c), b=FXBLUEVAL(c);
44 FXfloat d=.07;
45 fxrgb_to_hsv(h,s,v,r,g,b);
46 if (brighten) {
47 if (istext) {
48 if ( brighten && (brightness(c)>brightness(other))) { d=.10; }
49 } else {
50 if (v>240) {
51 if (s>0.50) { s=0.50; }
52 } else {
53 if (v<84) { v=84; }
54 if (v<160) { d=.10; }
55 }
56 }
57 } else if (istext && (v>240)) { v=240; }
58 v=brighten?v*(1.0+d):v*(1.0-d);
59 if (v>255) { v=255; } else if (v<0) { v=0; }
60 fxhsv_to_rgb(r,g,b,h,s,v);
61 return FXRGB(r,g,b);
62 }
63
64
65
setTabColor(FXTabItem * t,bool active)66 void ShadyTabs::setTabColor(FXTabItem*t, bool active)
67 {
68 t->setBackColor(shade(getApp()->getBaseColor(),active,false,getApp()->getForeColor()));
69 t->setTextColor(shade(getApp()->getForeColor(),active,true, getApp()->getBaseColor()));
70 if (active) {
71 if (brightness(t->getTextColor())>brightness(t->getBackColor())) {
72 t->setHiliteColor(makeHiliteColor(getApp()->getHiliteColor()));
73 } else {
74 t->setHiliteColor(getShadowColor());
75 }
76 } else {
77 t->setHiliteColor(getApp()->getHiliteColor());
78 }
79 return;
80 }
81
82
83
UpdateTabs()84 void ShadyTabs::UpdateTabs()
85 {
86 bool istab;
87 FXWindow*w;
88 for (w=getFirst(),istab=true; w; w=w->getNext(),istab=!istab) {
89 if (istab) {
90 setTabColor((FXTabItem*)w,false);
91 }
92 }
93 if ((w=childAtIndex(getCurrent()*2))) {
94 setTabColor((FXTabItem*)w,true);
95 if ( (w=w->getNext()) && (w=w->getFirst()) ) { w->setFocus(); }
96 }
97 }
98
99
100
setCurrent(FXint i,FXbool notify)101 void ShadyTabs::setCurrent(FXint i, FXbool notify)
102 {
103 FXTabBook::setCurrent(i, notify);
104 UpdateTabs();
105 }
106
107
108
onCmdOpenItem(FXObject * sender,FXSelector sel,void * p)109 long ShadyTabs::onCmdOpenItem(FXObject* sender, FXSelector sel, void* p)
110 {
111 long rv=FXTabBook::onCmdOpenItem(sender,sel,p);
112 UpdateTabs();
113 return rv;
114 }
115
116