fix linked tuners (i hope)
[enigma2.git] / lib / gui / ewindowstyle.cpp
1 #include <lib/base/eerror.h>
2 #include <lib/gdi/esize.h>
3 #include <lib/gui/ewindow.h>
4 #include <lib/gui/ewindowstyle.h>
5 #include <lib/base/init.h>
6 #include <lib/base/init_num.h>
7
8 eWindowStyle::~eWindowStyle() {}
9
10 DEFINE_REF(eWindowStyleManager);
11
12 eWindowStyleManager::eWindowStyleManager()
13 {
14         m_instance = this;
15 }
16
17 eWindowStyleManager::~eWindowStyleManager()
18 {
19         m_instance = 0;
20 }
21
22 void eWindowStyleManager::getStyle(ePtr<eWindowStyle> &style)
23 {
24         style = m_current_style;
25 }
26
27 void eWindowStyleManager::setStyle(eWindowStyle *style)
28 {
29         m_current_style = style;
30 }
31
32 eWindowStyleManager *eWindowStyleManager::m_instance;
33
34 DEFINE_REF(eWindowStyleSimple);
35
36 eWindowStyleSimple::eWindowStyleSimple()
37 {
38         m_border_left = m_border_right = m_border_bottom = 2;
39         m_border_top = 30;
40
41         m_fnt = new gFont("Arial", 25);
42         
43         m_border_color_tl = gColor(0x1f);
44         m_border_color_br = gColor(0x14);
45         m_title_color_back = gColor(0x20);
46         m_title_color = gColor(0x2f);
47         m_background_color = gColor(0x19);
48 }
49
50 void eWindowStyleSimple::handleNewSize(eWindow *wnd, eSize &size, eSize &offset)
51 {
52 //      eDebug("handle new size: %d x %d", size.width(), size.height());
53         
54         eWidget *child = wnd->child();
55         
56         wnd->m_clip_region = eRect(ePoint(0, 0), size);
57         
58         child->move(ePoint(m_border_left, m_border_top));
59         child->resize(eSize(size.width() - m_border_left - m_border_right, size.height() - m_border_top - m_border_bottom));
60 }
61
62 void eWindowStyleSimple::paintWindowDecoration(eWindow *wnd, gPainter &painter, const std::string &title)
63 {
64         painter.setForegroundColor(m_title_color_back);
65         painter.fill(eRect(2, 2, wnd->size().width() - 4, m_border_top - 4));
66         painter.setBackgroundColor(m_title_color_back);
67         painter.setForegroundColor(m_title_color);
68         painter.setFont(m_fnt);
69         painter.renderText(eRect(3, 3, wnd->size().width() - 6, m_border_top - 6), title);
70
71         eRect frame(ePoint(0, 0), wnd->size());
72
73         painter.setForegroundColor(m_background_color);
74         painter.line(frame.topLeft1(), frame.topRight1());
75         painter.line(frame.topLeft1(), frame.bottomLeft1());
76         painter.setForegroundColor(m_border_color_tl);
77         painter.line(frame.topLeft1()+eSize(1,1), frame.topRight1()+eSize(0,1));
78         painter.line(frame.topLeft1()+eSize(1,1), frame.bottomLeft1()+eSize(1,0));
79
80         painter.setForegroundColor(m_border_color_br);
81         painter.line(frame.bottomLeft()+eSize(1,-1), frame.bottomRight()+eSize(0,-1));
82         painter.line(frame.topRight1()+eSize(-1,1), frame.bottomRight1()+eSize(-1, 0));
83         painter.line(frame.bottomLeft()+eSize(1,-2), frame.bottomRight()+eSize(0,-2));
84         painter.line(frame.topRight1()+eSize(-0,1), frame.bottomRight1()+eSize(-0, 0));
85 }
86
87 void eWindowStyleSimple::paintBackground(gPainter &painter, const ePoint &offset, const eSize &size)
88 {
89         painter.setBackgroundColor(m_background_color);
90         painter.clear();
91 }
92
93 void eWindowStyleSimple::setStyle(gPainter &painter, int what)
94 {
95         switch (what)
96         {
97         case styleLabel:
98                 painter.setForegroundColor(gColor(0x1F));
99                 break;
100         case styleListboxSelected:
101                 painter.setForegroundColor(gColor(0x1F));
102                 painter.setBackgroundColor(gColor(0x1A));
103                 break;
104         case styleListboxNormal:
105                 painter.setForegroundColor(gColor(0x1C));
106                 painter.setBackgroundColor(m_background_color);
107                 break;
108         case styleListboxMarked:
109                 painter.setForegroundColor(gColor(0x2F));
110                 painter.setBackgroundColor(gColor(0x2A));
111                 break;
112         }
113 }
114
115 void eWindowStyleSimple::drawFrame(gPainter &painter, const eRect &frame, int what)
116 {
117         gColor c1, c2;
118         switch (what)
119         {
120         case frameButton:
121                 c1 = m_border_color_tl;
122                 c2 = m_border_color_br;
123                 break;
124         case frameListboxEntry:
125                 c1 = m_border_color_br;
126                 c2 = m_border_color_tl;
127                 break;
128         }
129         
130         painter.setForegroundColor(c2);
131         painter.line(frame.topLeft1(), frame.topRight1());
132         painter.line(frame.topRight1(), frame.bottomRight1());
133         painter.setForegroundColor(c1);
134         painter.line(frame.bottomRight1(), frame.bottomLeft1());
135         painter.line(frame.bottomLeft1(), frame.topLeft1());
136 }
137
138 RESULT eWindowStyleSimple::getFont(int what, ePtr<gFont> &fnt)
139 {
140         fnt = 0;
141         switch (what)
142         {
143         case fontStatic:
144                 fnt = new gFont("Arial", 12);
145                 break;
146         case fontButton:
147                 fnt = new gFont("Arial", 20);
148                 break;
149         case fontTitlebar:
150                 fnt = new gFont("Arial", 25);
151                 break;
152         default:
153                 return -1;
154         }
155         return 0;
156 }
157
158 eAutoInitPtr<eWindowStyleManager> init_eWindowStyleManager(eAutoInitNumbers::skin, "eWindowStyleManager");