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>
8 eWindowStyle::~eWindowStyle() {}
10 DEFINE_REF(eWindowStyleManager);
12 ePtr<eWindowStyleManager> NewWindowStylePtr(void)
14 ePtr<eWindowStyleManager> ptr;
15 eWindowStyleManager::getInstance(ptr);
19 eWindowStyleManager::eWindowStyleManager()
24 eWindowStyleManager::~eWindowStyleManager()
29 void eWindowStyleManager::getStyle(int style_id, ePtr<eWindowStyle> &style)
31 std::map<int, ePtr<eWindowStyle> >::iterator it = m_current_style.find(style_id);
32 ASSERT(it != m_current_style.end());
36 void eWindowStyleManager::setStyle(int style_id, eWindowStyle *style)
38 m_current_style[style_id] = style;
41 eWindowStyleManager *eWindowStyleManager::m_instance;
43 DEFINE_REF(eWindowStyleSimple);
45 eWindowStyleSimple::eWindowStyleSimple()
47 m_border_left = m_border_right = m_border_bottom = 2;
50 m_fnt = new gFont("Regular", 25);
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);
59 void eWindowStyleSimple::handleNewSize(eWindow *wnd, eSize &size, eSize &offset)
61 // eDebug("handle new size: %d x %d", size.width(), size.height());
63 eWidget *child = wnd->child();
65 wnd->m_clip_region = eRect(ePoint(0, 0), size);
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));
71 void eWindowStyleSimple::paintWindowDecoration(eWindow *wnd, gPainter &painter, const std::string &title)
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);
80 eRect frame(ePoint(0, 0), wnd->size());
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));
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));
96 void eWindowStyleSimple::paintBackground(gPainter &painter, const ePoint &offset, const eSize &size)
98 painter.setBackgroundColor(m_background_color);
102 void eWindowStyleSimple::setStyle(gPainter &painter, int what)
107 painter.setForegroundColor(gColor(0x1F));
109 case styleListboxSelected:
110 painter.setForegroundColor(gColor(0x1F));
111 painter.setBackgroundColor(gColor(0x1A));
113 case styleListboxNormal:
114 painter.setForegroundColor(gColor(0x1C));
115 painter.setBackgroundColor(m_background_color);
117 case styleListboxMarked:
118 painter.setForegroundColor(gColor(0x2F));
119 painter.setBackgroundColor(gColor(0x2A));
121 case styleListboxMarkedAndSelected:
122 painter.setForegroundColor(gColor(0x3F));
123 painter.setBackgroundColor(gColor(0x3A));
128 void eWindowStyleSimple::drawFrame(gPainter &painter, const eRect &frame, int what)
134 c1 = m_border_color_tl;
135 c2 = m_border_color_br;
137 case frameListboxEntry:
138 c1 = m_border_color_br;
139 c2 = m_border_color_tl;
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());
151 RESULT eWindowStyleSimple::getFont(int what, ePtr<gFont> &fnt)
157 fnt = new gFont("Regular", 12);
160 fnt = new gFont("Regular", 20);
163 fnt = new gFont("Regular", 25);
171 eAutoInitPtr<eWindowStyleManager> init_eWindowStyleManager(eAutoInitNumbers::skin, "eWindowStyleManager");