fix for default ac3
[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(int style_id, ePtr<eWindowStyle> &style)
23 {
24         style = m_current_style[style_id];
25 }
26
27 void eWindowStyleManager::setStyle(int style_id, eWindowStyle *style)
28 {
29         m_current_style[style_id] = 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("Regular", 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         case styleListboxMarkedAndSelected:
113                 painter.setForegroundColor(gColor(0x3F));
114                 painter.setBackgroundColor(gColor(0x3A));
115                 break;
116         }
117 }
118
119 void eWindowStyleSimple::drawFrame(gPainter &painter, const eRect &frame, int what)
120 {
121         gColor c1, c2;
122         switch (what)
123         {
124         case frameButton:
125                 c1 = m_border_color_tl;
126                 c2 = m_border_color_br;
127                 break;
128         case frameListboxEntry:
129                 c1 = m_border_color_br;
130                 c2 = m_border_color_tl;
131                 break;
132         }
133         
134         painter.setForegroundColor(c2);
135         painter.line(frame.topLeft1(), frame.topRight1());
136         painter.line(frame.topRight1(), frame.bottomRight1());
137         painter.setForegroundColor(c1);
138         painter.line(frame.bottomRight1(), frame.bottomLeft1());
139         painter.line(frame.bottomLeft1(), frame.topLeft1());
140 }
141
142 RESULT eWindowStyleSimple::getFont(int what, ePtr<gFont> &fnt)
143 {
144         fnt = 0;
145         switch (what)
146         {
147         case fontStatic:
148                 fnt = new gFont("Regular", 12);
149                 break;
150         case fontButton:
151                 fnt = new gFont("Regular", 20);
152                 break;
153         case fontTitlebar:
154                 fnt = new gFont("Regular", 25);
155                 break;
156         default:
157                 return -1;
158         }
159         return 0;
160 }
161
162 eAutoInitPtr<eWindowStyleManager> init_eWindowStyleManager(eAutoInitNumbers::skin, "eWindowStyleManager");