use local listbox styles for servicelist
authorAndreas Monzner <andreas.monzner@multimedia-labs.de>
Fri, 9 Nov 2007 13:17:21 +0000 (13:17 +0000)
committerAndreas Monzner <andreas.monzner@multimedia-labs.de>
Fri, 9 Nov 2007 13:17:21 +0000 (13:17 +0000)
add some special skin attributes for servicelist
- foregroundColorMarked
- foregroundColorMarkedSelected
- backgroundColorMarked
- backgroundColorMarkedSelected
- foregroundColorNotAvail (default gray)

lib/python/Components/ServiceList.py
lib/service/listboxservice.cpp
lib/service/listboxservice.h

index 4a27c7682c259503b5fdbc702f7ad97e2ebe66da..46c024dd8017fa3e15ff42c3300bdfbb6a36236f 100644 (file)
@@ -1,5 +1,6 @@
 from HTMLComponent import HTMLComponent
 from GUIComponent import GUIComponent
+from skin import parseColor
 
 from enigma import loadPNG, eListboxServiceContent, eListbox, eServiceCenter, eServiceReference, gFont, eRect
 
@@ -43,6 +44,26 @@ class ServiceList(HTMLComponent, GUIComponent):
                self.mode = self.MODE_NORMAL
                self.onSelectionChanged = [ ]
 
+       def applySkin(self, desktop):
+               attribs = [ ]
+               if self.skinAttributes is not None:
+                       attribs = [ ]
+                       for (attrib, value) in self.skinAttributes:
+                               if attrib == "foregroundColorMarked":
+                                       self.l.setColor(eListboxServiceContent.markedForeground, parseColor(value))
+                               elif attrib == "foregroundColorMarkedSelected":
+                                       self.l.setColor(eListboxServiceContent.markedForegroundSelected, parseColor(value))
+                               elif attrib == "backgroundColorMarked":
+                                       self.l.setColor(eListboxServiceContent.markedBackground, parseColor(value))
+                               elif attrib == "backgroundColorMarkedSelected":
+                                       self.l.setColor(eListboxServiceContent.markedBackgroundSelected, parseColor(value))
+                               elif attrib == "foregroundColorServiceNotAvail":
+                                       self.l.setColor(eListboxServiceContent.serviceNotAvail, parseColor(value))
+                               else:
+                                       attribs.append((attrib, value))
+               self.skinAttributes = attribs
+               return GUIComponent.applySkin(self, desktop)
+
        def connectSelChanged(self, fnc):
                if not fnc in self.onSelectionChanged:
                        self.onSelectionChanged.append(fnc)
index b6d07f4467cabb37d0957e91d1c6f895aa45b243..b59b0f32c5844c7226e994a1d89f012689d73f09 100644 (file)
@@ -262,10 +262,20 @@ DEFINE_REF(eListboxServiceContent);
 eListboxServiceContent::eListboxServiceContent()
        :m_visual_mode(visModeSimple), m_size(0), m_current_marked(false), m_numberoffset(0), m_itemheight(25)
 {
+       memset(m_color_set, 0, sizeof(m_color_set));
        cursorHome();
        eServiceCenter::getInstance(m_service_center);
 }
 
+void eListboxServiceContent::setColor(int color, gRGB &col)
+{
+       if ((color >= 0) && (color < colorElements))
+       {
+               m_color_set[color] = true;
+               m_color[color] = col;
+       }
+}
+
 void eListboxServiceContent::cursorHome()
 {
        if (m_current_marked && m_saved_cursor == m_list.end())
@@ -436,12 +446,74 @@ void eListboxServiceContent::paint(gPainter &painter, eWindowStyle &style, const
 {
        painter.clip(eRect(offset, m_itemsize));
 
-       if (m_current_marked && selected)
-               style.setStyle(painter, eWindowStyle::styleListboxMarked);
-       else if (cursorValid() && isMarked(*m_cursor))
+       bool marked = m_current_marked || (cursorValid() && isMarked(*m_cursor));
+
+       if (marked)
                style.setStyle(painter, selected ? eWindowStyle::styleListboxMarkedAndSelected : eWindowStyle::styleListboxMarked);
        else
                style.setStyle(painter, selected ? eWindowStyle::styleListboxSelected : eWindowStyle::styleListboxNormal);
+
+       eListboxStyle *local_style = 0;
+
+               /* get local listbox style, if present */
+       if (m_listbox)
+               local_style = m_listbox->getLocalStyle();
+
+       if (marked)
+       {
+               if (selected)
+               {
+                       if (m_color_set[markedForegroundSelected])
+                               painter.setForegroundColor(m_color[markedForegroundSelected]);
+                       if (m_color_set[markedBackgroundSelected])
+                               painter.setBackgroundColor(m_color[markedBackgroundSelected]);
+               }
+               else
+               {
+                       if (m_color_set[markedForeground])
+                               painter.setForegroundColor(m_color[markedForeground]);
+                       if (m_color_set[markedBackground])
+                               painter.setBackgroundColor(m_color[markedBackground]);
+               }
+       }
+       else if (local_style)
+       {
+               if (selected)
+               {
+                       /* if we have a local background color set, use that. */
+                       if (local_style->m_background_color_selected_set)
+                               painter.setBackgroundColor(local_style->m_background_color_selected);
+                       /* same for foreground */
+                       if (local_style->m_foreground_color_selected_set)
+                               painter.setForegroundColor(local_style->m_foreground_color_selected);
+               }
+               else
+               {
+                       /* if we have a local background color set, use that. */
+                       if (local_style->m_background_color_set)
+                               painter.setBackgroundColor(local_style->m_background_color);
+                       /* same for foreground */
+                       if (local_style->m_foreground_color_set)
+                               painter.setForegroundColor(local_style->m_foreground_color);
+               }
+       }
+
+       if (!local_style || !local_style->m_transparent_background)
+               /* if we have no transparent background */
+       {
+               /* blit background picture, if available (otherwise, clear only) */
+               if (local_style && local_style->m_background)
+                       painter.blit(local_style->m_background, offset, eRect(), 0);
+               else
+                       painter.clear();
+       } else
+       {
+               if (local_style->m_background)
+                       painter.blit(local_style->m_background, offset, eRect(), gPainter::BT_ALPHATEST);
+               else if (selected && !local_style->m_selection)
+                       painter.clear();
+       }
+
        painter.clear();
        
        if (cursorValid())
@@ -452,8 +524,16 @@ void eListboxServiceContent::paint(gPainter &painter, eWindowStyle &style, const
                eServiceReference ref = *m_cursor;
                bool isPlayable = !(ref.flags & eServiceReference::isDirectory || ref.flags & eServiceReference::isMarker);
 
-               if (isPlayable && service_info && !service_info->isPlayable(*m_cursor, m_is_playable_ignore))
-                       painter.setForegroundColor(gRGB(0xbbbbbb));
+               if (!marked && isPlayable && service_info && !service_info->isPlayable(*m_cursor, m_is_playable_ignore))
+               {
+                       if (m_color_set[serviceNotAvail])
+                               painter.setForegroundColor(m_color[serviceNotAvail]);
+                       else
+                               painter.setForegroundColor(gRGB(0xbbbbbb));
+               }
+
+               if (selected && local_style && local_style->m_selection)
+                       painter.blit(local_style->m_selection, offset, eRect(), gPainter::BT_ALPHATEST);
 
                int xoffset=0;  // used as offset when painting the folder/marker symbol
 
@@ -596,7 +676,7 @@ void eListboxServiceContent::paint(gPainter &painter, eWindowStyle &style, const
                        }
                }
                
-               if (selected)
+               if (selected && (!local_style || !local_style->m_selection))
                        style.drawFrame(painter, eRect(offset, m_itemsize), eWindowStyle::frameListboxEntry);
        }
        
index b64e875f0c4a600a078ffe90f98027269b2e11bb..40c7c64dea9ac516321aee94429a7b82065f7861 100644 (file)
@@ -1,6 +1,7 @@
 #ifndef __lib_service_listboxservice_h
 #define __lib_service_listboxservice_h
 
+#include <lib/gdi/gpixmap.h>
 #include <lib/gui/elistbox.h>
 #include <lib/service/iservice.h>
 #include <set>
@@ -76,7 +77,17 @@ public:
        
        int getItemHeight() { return m_itemheight; }
        int setItemHeight(int height);
+
+       enum {
+               markedForeground,
+               markedForegroundSelected,
+               markedBackground,
+               markedBackgroundSelected,
+               serviceNotAvail,
+               colorElements
+       };
        
+       void setColor(int color, gRGB &col);
 protected:
        void cursorHome();
        void cursorEnd();
@@ -100,6 +111,8 @@ protected:
        eRect m_element_position[celElements];
        ePtr<gFont> m_element_font[celElements];
        ePtr<gPixmap> m_pixmaps[picElements];
+       gRGB m_color[colorElements];
+       bool m_color_set[colorElements];
 private:
        typedef std::list<eServiceReference> list;