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