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