eRCConsoleDriver driver;
eRCConsole device;
public:
- eRCConsoleInit(): driver("/dev/vc/0"), device(&driver)
+ eRCConsoleInit(): driver("/dev/stdin"), device(&driver)
{
}
};
RESULT eDVBService::getName(const eServiceReference &ref, std::string &name)
{
name = m_service_name;
+ return 0;
}
int eDVBService::checkFilter(const eServiceReferenceDVB &ref, const eDVBChannelQuery &query)
libenigma_gdi_a_SOURCES = \
region.cpp grc.cpp epng.cpp erect.cpp fb.cpp font.cpp font_arabic.cpp gfbdc.cpp \
- glcddc.cpp gpixmap.cpp lcd.cpp
+ glcddc.cpp gpixmap.cpp lcd.cpp sdl.cpp gfont.cpp
--- /dev/null
+#include <lib/gdi/gfont.h>
+
+DEFINE_REF(gFont);
--- /dev/null
+#ifndef __lib_gdi_gfont_h
+#define __lib_gdi_gfont_h
+
+#include <lib/base/object.h>
+#include <string>
+
+/**
+ * \brief A softreference to a font.
+ *
+ * The font is specified by a name and a size.
+ * \c gFont is part of the \ref gdi.
+ */
+class gFont: public iObject
+{
+DECLARE_REF(gFont);
+public:
+
+ std::string family;
+ int pointSize;
+
+ /**
+ * \brief Constructs a font with the given name and size.
+ * \param family The name of the font, for example "NimbusSansL-Regular Sans L Regular".
+ * \param pointSize the size of the font in PIXELS.
+ */
+ gFont(const std::string &family, int pointSize):
+ family(family), pointSize(pointSize)
+ {
+ }
+
+ virtual ~gFont()
+ {
+ }
+
+ gFont()
+ :pointSize(0)
+ {
+ }
+};
+
+#endif
#include <lib/gdi/gpixmap.h>
#include <lib/gdi/region.h>
-DEFINE_REF(gFont);
-
gLookup::gLookup()
:size(0), lookup(0)
{
void gPixmap::fill(const gRegion ®ion, const gColor &color)
{
- int i;
+ unsigned int i;
for (i=0; i<region.rects.size(); ++i)
{
const eRect &area = region.rects[i];
void gPixmap::blit(const gPixmap &src, ePoint pos, const gRegion &clip, int flag)
{
- for (int i=0; i<clip.rects.size(); ++i)
+ for (unsigned int i=0; i<clip.rects.size(); ++i)
{
eRect area=eRect(pos, src.getSize());
area&=clip.rects[i];
void gPixmap::line(const gRegion &clip, ePoint start, ePoint dst, gColor color)
{
- __u8 *srf = (__u8*)surface->data;
+ __u8 *srf8 = 0;
+ __u32 *srf32 = 0;
int stride = surface->stride;
if (clip.rects.empty())
return;
+
+ __u32 col;
+ if (surface->bpp == 8)
+ {
+ srf8 = (__u8*)surface->data;
+ } else if (surface->bpp == 32)
+ {
+ srf32 = (__u32*)surface->data;
+
+ if (surface->clut.data && color < surface->clut.colors)
+ col=(surface->clut.data[color].a<<24)|(surface->clut.data[color].r<<16)|(surface->clut.data[color].g<<8)|(surface->clut.data[color].b);
+ else
+ col=0x10101*color;
+ col^=0xFF000000;
+ }
int xa = start.x(), ya = start.y(), xb = dst.x(), yb = dst.y();
int dx, dy, x, y, s1, s2, e, temp, swap, i;
} else
swap=0;
e = 2*dy-dx;
+
int lasthit = 0;
for(i=1; i<=dx; i++)
{
} while (!clip.rects[a].contains(x, y));
lasthit = a;
}
- srf[y * stride + x] = color;
+
+ if (srf8)
+ srf8[y * stride + x] = color;
+ if (srf32)
+ srf32[y * stride/4 + x] = col;
fail:
while (e>=0)
{
void build(int size, const gPalette &pal, const gRGB &start, const gRGB &end);
};
-/**
- * \brief A softreference to a font.
- *
- * The font is specified by a name and a size.
- * \c gFont is part of the \ref gdi.
- */
-class gFont: public iObject
-{
-DECLARE_REF(gFont);
-public:
-
- std::string family;
- int pointSize;
-
- /**
- * \brief Constructs a font with the given name and size.
- * \param family The name of the font, for example "NimbusSansL-Regular Sans L Regular".
- * \param pointSize the size of the font in PIXELS.
- */
- gFont(const std::string &family, int pointSize):
- family(family), pointSize(pointSize)
- {
- }
-
- virtual ~gFont()
- {
- }
-
- gFont()
- :pointSize(0)
- {
- }
-};
-
struct gSurface
{
int type;
void gPainter::flush()
{
+ gOpcode o;
+ o.opcode = gOpcode::flush;
+ o.dc = m_dc.grabRef();
+ m_rc->submit(o);
}
void gPainter::end()
case gOpcode::renderText:
{
ePtr<eTextPara> para = new eTextPara(o->parm.renderText->area);
+ int flags = o->parm.renderText->flags;
assert(m_current_font);
para->setFont(m_current_font);
- para->renderString(o->parm.renderText->text, 0);
+ para->renderString(o->parm.renderText->text, (flags & gPainter::RT_WRAP) ? RS_WRAP : 0);
- if (o->parm.renderText->flags & gPainter::RT_HALIGN_RIGHT)
+ if (flags & gPainter::RT_HALIGN_RIGHT)
para->realign(eTextPara::dirRight);
- else if (o->parm.renderText->flags & gPainter::RT_HALIGN_CENTER)
+ else if (flags & gPainter::RT_HALIGN_CENTER)
para->realign(eTextPara::dirCenter);
- else if (o->parm.renderText->flags & gPainter::RT_HALIGN_BLOCK)
+ else if (flags & gPainter::RT_HALIGN_BLOCK)
para->realign(eTextPara::dirBlock);
ePoint offset = m_current_offset;
m_current_offset = o->parm.setOffset->value;
delete o->parm.setOffset;
break;
+ case gOpcode::flush:
+ break;
default:
eFatal("illegal opcode %d. expect memory leak!", o->opcode);
}
#include <lib/gdi/erect.h>
#include <lib/gdi/gpixmap.h>
#include <lib/gdi/region.h>
+#include <lib/gdi/gfont.h>
class eTextPara;
setClip, addClip, popClip,
+ flush,
+
end,shutdown
} opcode;
enum
{
// todo, make mask. you cannot align both right AND center AND block ;)
+ RT_HALIGN_LEFT = 0, /* default */
RT_HALIGN_RIGHT = 1,
RT_HALIGN_CENTER = 2,
RT_HALIGN_BLOCK = 4,
- RT_VALIGN_CENTER = 8
+
+ RT_VALIGN_TOP = 0, /* default */
+ RT_VALIGN_CENTER = 8,
+ RT_VALIGN_BOTTOM = 16,
+
+ RT_WRAP = 32
};
void renderText(const eRect &position, const std::string &string, int flags=0);
--- /dev/null
+#include <lib/gdi/sdl.h>
+
+#include <lib/base/init.h>
+#include <lib/base/init_num.h>
+
+#include <SDL.h>
+
+gSDLDC *gSDLDC::m_instance;
+
+gSDLDC::gSDLDC()
+{
+ if (SDL_Init(SDL_INIT_VIDEO) < 0)
+ {
+ eWarning("Could not initialize SDL: %s", SDL_GetError());
+ return;
+ }
+
+ m_screen = SDL_SetVideoMode(720, 576, 32, SDL_HWSURFACE);
+ if (!m_screen)
+ {
+ eWarning("Could not create SDL surface: %s", SDL_GetError());
+ return;
+ }
+
+ m_instance=this;
+
+ m_surface.type = 0;
+ m_surface.x = m_screen->w;
+ m_surface.y = m_screen->h;
+ m_surface.bpp = m_screen->format->BitsPerPixel;
+ m_surface.bypp = m_screen->format->BytesPerPixel;
+ m_surface.stride = m_screen->pitch;
+ m_surface.data = m_screen->pixels;
+ m_surface.clut.colors=256;
+ m_surface.clut.data=new gRGB[m_surface.clut.colors];
+
+ m_pixmap = new gPixmap(&m_surface);
+
+ memset(m_surface.clut.data, 0, sizeof(*m_surface.clut.data)*m_surface.clut.colors);
+}
+
+gSDLDC::~gSDLDC()
+{
+ SDL_Quit();
+ m_instance=0;
+}
+
+void gSDLDC::setPalette()
+{
+ if (!m_surface.clut.data)
+ return;
+
+/* for (int i=0; i<256; ++i)
+ {
+ fb->CMAP()->red[i]=ramp[m_surface.clut.data[i].r]<<8;
+ fb->CMAP()->green[i]=ramp[m_surface.clut.data[i].g]<<8;
+ fb->CMAP()->blue[i]=ramp[m_surface.clut.data[i].b]<<8;
+ fb->CMAP()->transp[i]=rampalpha[m_surface.clut.data[i].a]<<8;
+ if (!fb->CMAP()->red[i])
+ fb->CMAP()->red[i]=0x100;
+ }
+ fb->PutCMAP(); */
+}
+
+void gSDLDC::exec(gOpcode *o)
+{
+ switch (o->opcode)
+ {
+ case gOpcode::setPalette:
+ {
+ gDC::exec(o);
+ setPalette();
+ break;
+ }
+ case gOpcode::flush:
+ SDL_Flip(m_screen);
+ eDebug("FLUSH");
+ break;
+ default:
+ gDC::exec(o);
+ break;
+ }
+}
+
+eAutoInitPtr<gSDLDC> init_gSDLDC(eAutoInitNumbers::graphic-1, "gSDLDC");
--- /dev/null
+#ifndef __lib_gdi_sdl_h
+#define __lib_gdi_sdl_h
+
+#include "fb.h"
+#include "gpixmap.h"
+#include "grc.h"
+
+#include <SDL.h>
+
+class gSDLDC: public gDC
+{
+ SDL_Surface *m_screen;
+ static gSDLDC *m_instance;
+ void exec(gOpcode *opcode);
+
+ void setPalette();
+ gSurface m_surface;
+public:
+
+ gSDLDC();
+ virtual ~gSDLDC();
+ static int getInstance(ePtr<gSDLDC> &ptr) { if (!m_instance) return -1; ptr = m_instance; return 0; }
+ int islocked() { return 0; }
+};
+
+
+#endif
eButton::eButton(eWidget *parent): eLabel(parent)
{
+ /* default to center alignment */
+ m_valign = alignCenter;
+ m_halign = alignCenter;
}
void eButton::push()
eLabel::eLabel(eWidget *parent): eWidget(parent)
{
+ ePtr<eWindowStyle> style;
+ getStyle(style);
+ style->getFont(eWindowStyle::fontStatic, m_font);
+
+ /* default to topleft alignment */
+ m_valign = alignTop;
+ m_halign = alignLeft;
}
int eLabel::event(int event, void *data, void *data2)
eWidget::event(event, data, data2);
gPainter &painter = *(gPainter*)data2;
- ePtr<gFont> fnt = new gFont("Arial", 14);
- painter.setFont(fnt);
+ painter.setFont(m_font);
style->setStyle(painter, eWindowStyle::styleLabel);
- painter.renderText(eRect(0, 0, size().width(), size().height()), m_text, gPainter::RT_HALIGN_CENTER|gPainter::RT_VALIGN_CENTER);
+
+ int flags = 0;
+ if (m_valign == alignTop)
+ flags |= gPainter::RT_VALIGN_TOP;
+ else if (m_valign == alignCenter)
+ flags |= gPainter::RT_VALIGN_CENTER;
+ else if (m_valign == alignBottom)
+ flags |= gPainter::RT_VALIGN_BOTTOM;
+
+ if (m_halign == alignLeft)
+ flags |= gPainter::RT_HALIGN_LEFT;
+ else if (m_halign == alignCenter)
+ flags |= gPainter::RT_HALIGN_CENTER;
+ else if (m_halign == alignRight)
+ flags |= gPainter::RT_HALIGN_RIGHT;
+ else if (m_halign == alignBlock)
+ flags |= gPainter::RT_HALIGN_BLOCK;
+
+ flags |= gPainter::RT_WRAP;
+ painter.renderText(eRect(0, 0, size().width(), size().height()), m_text, flags);
return 0;
}
+ case evtChangedFont:
case evtChangedText:
+ case evtChangedAlignment:
invalidate();
return 0;
default:
m_text = string;
event(evtChangedText);
}
+
+void eLabel::setFont(gFont *font)
+{
+ m_font = font;
+ event(evtChangedFont);
+}
+
+void eLabel::setVAlign(int align)
+{
+ m_valign = align;
+ event(evtChangedAlignment);
+}
+
+void eLabel::setHAlign(int align)
+{
+ m_halign = align;
+ event(evtChangedAlignment);
+}
public:
eLabel(eWidget *parent);
void setText(const std::string &string);
+ void setFont(gFont *font);
+
+ enum
+ {
+ alignLeft,
+ alignTop=alignLeft,
+ alignCenter,
+ alignRight,
+ alignBottom=alignRight,
+ alignBlock
+ };
+
+ void setVAlign(int align);
+ void setHAlign(int align);
protected:
+ ePtr<gFont> m_font;
+ int m_valign, m_halign;
int event(int event, void *data=0, void *data2=0);
private:
enum eLabelEvent
{
- evtChangedText = evtUserWidget
+ evtChangedText = evtUserWidget,
+ evtChangedFont,
+ evtChangedAlignment
};
std::string m_text;
};
painter.setBackgroundColor(m_background_color);
painter.clear();
+ painter.flush();
+
m_dirty_region = gRegion();
}
painter.line(frame.bottomLeft1(), frame.topLeft1());
}
+RESULT eWindowStyleSimple::getFont(int what, ePtr<gFont> &fnt)
+{
+ fnt = 0;
+ switch (what)
+ {
+ case fontStatic:
+ fnt = new gFont("Arial", 12);
+ break;
+ case fontButton:
+ fnt = new gFont("Arial", 20);
+ break;
+ case fontTitlebar:
+ fnt = new gFont("Arial", 25);
+ break;
+ default:
+ return -1;
+ }
+ return 0;
+}
+
+#if 0
DEFINE_REF(eWindowStyleSkinned);
eWindowStyleSkinned::eWindowStyleSkinned()
{
}
+#endif
frameButton,
frameListboxEntry
};
+
+ enum {
+ fontStatic,
+ fontButton,
+ fontTitlebar
+ };
+
+ virtual RESULT getFont(int what, ePtr<gFont> &font) = 0;
virtual ~eWindowStyle() = 0;
-
};
class eWindowStyleSimple: public eWindowStyle
void paintBackground(gPainter &painter, const ePoint &offset, const eSize &size);
void setStyle(gPainter &painter, int what);
void drawFrame(gPainter &painter, const eRect &frame, int what);
+ RESULT getFont(int what, ePtr<gFont> &font);
};
+#if 0
class eWindowStyleSkinned: public eWindowStyle
{
DECLARE_REF(eWindowStyleSkinned);
void drawBorder(gPainter &painter, const eSize &size, const struct borderSet &border, int where);
};
+#endif
#endif
#include <lib/components/scan.h>
#include <lib/nav/pcore.h>
#include <lib/actions/action.h>
+#include <lib/gdi/gfont.h>
extern void runMainloop();
extern void quitMainloop();
%include <lib/components/scan.h>
%include <lib/nav/pcore.h>
%include <lib/actions/action.h>
+%include <lib/gdi/gfont.h>
/************** eptr **************/
"""
<skin>
<screen name="mainMenu" position="300,100" size="300,300" title="real main menu">
- <widget name="okbutton" position="10,190" size="280,50" />
+ <widget name="okbutton" position="10,190" size="280,50" font="Arial:20" valign="center" halign="center" />
<widget name="title" position="10,10" size="280,20" />
<widget name="menu" position="10,30" size="280,140" />
</screen>
""")
+def elementsWithTag(el, tag):
+ for x in el:
+ if x.nodeType != xml.dom.minidom.Element.nodeType:
+ continue
+ if x.tagName == tag:
+ yield x
def parsePosition(str):
x, y = str.split(',')
x, y = str.split(',')
return eSize(int(x), int(y))
+def parseFont(str):
+ name, size = str.split(':')
+ return gFont(name, int(size))
+
def applyAttributes(guiObject, node):
# walk all attributes
for p in range(node.attributes.length):
value = str(a.value)
# and set attributes
- if attrib == 'position':
- guiObject.move(parsePosition(value))
- elif attrib == 'size':
- guiObject.resize(parseSize(value))
- elif attrib == 'title':
- guiObject.setTitle(value)
- elif attrib != 'name':
- print "unsupported attribute " + attrib + "=" + value
+ try:
+ if attrib == 'position':
+ guiObject.move(parsePosition(value))
+ elif attrib == 'size':
+ guiObject.resize(parseSize(value))
+ elif attrib == 'title':
+ guiObject.setTitle(value)
+ elif attrib == 'font':
+ guiObject.setFont(parseFont(value))
+ elif attrib == "valign":
+ try:
+ guiObject.setVAlign(
+ { "top": guiObject.alignTop,
+ "center": guiObject.alignCenter,
+ "bottom": guiObject.alignBottom
+ }[value])
+ except KeyError:
+ print "valign must be either top, center or bottom!"
+ elif attrib == "halign":
+ try:
+ guiObject.setHAlign(
+ { "left": guiObject.alignLeft,
+ "center": guiObject.alignCenter,
+ "right": guiObject.alignRight,
+ "block": guiObject.alignBlock
+ }[value])
+ except KeyError:
+ print "halign must be either left, center, right or block!"
+ elif attrib != 'name':
+ print "unsupported attribute " + attrib + "=" + value
+ except AttributeError:
+ print "widget %s (%s) doesn't support attribute %s!" % ("", guiObject.__class__.__name__, attrib)
def applyGUIskin(screen, parent, skin, name):
myscreen = None
# first, find the corresponding screen element
- skin = dom.getElementsByTagName("skin")[0]
- screens = skin.getElementsByTagName("screen")
- del skin
- for x in screens:
+ skin = dom.childNodes[0]
+ assert skin.tagName == "skin", "root element in skin must be 'skin'!"
+
+ for x in elementsWithTag(skin.childNodes, "screen"):
if x.getAttribute('name') == name:
myscreen = x
+ del skin
assert myscreen != None, "no skin for screen '" + name + "' found!"
applyAttributes(parent, myscreen)
# now walk all widgets
- for widget in myscreen.getElementsByTagName("widget"):
+ for widget in elementsWithTag(myscreen.childNodes, "widget"):
wname = widget.getAttribute('name')
if wname == None:
print "widget has no name!"