aboutsummaryrefslogtreecommitdiff
path: root/lib/gdi
diff options
context:
space:
mode:
authorFelix Domke <tmbinc@elitedvb.net>2005-03-30 07:28:17 +0000
committerFelix Domke <tmbinc@elitedvb.net>2005-03-30 07:28:17 +0000
commitab5aa90e1e05a89845c6e802ef1b2366d203aa45 (patch)
tree24b8f67a1cc123481b3f21fdc026795969a073cf /lib/gdi
parentcfe43ee16030fd37f6bce9ba99e367c15ecbf44f (diff)
downloadenigma2-ab5aa90e1e05a89845c6e802ef1b2366d203aa45.tar.gz
enigma2-ab5aa90e1e05a89845c6e802ef1b2366d203aa45.zip
- default fonts handled in windowstyle
- fixed 32bit ARGB support (drawLine) - add sdl (but currently disabled) - fixed /dev/vc/0 -> /dev/stdin for console input - added alignment to label - fixed skin parsing (getElementsByTagName didn't do what i expected)
Diffstat (limited to 'lib/gdi')
-rw-r--r--lib/gdi/Makefile.am2
-rw-r--r--lib/gdi/gfont.cpp3
-rw-r--r--lib/gdi/gfont.h41
-rw-r--r--lib/gdi/gpixmap.cpp31
-rw-r--r--lib/gdi/gpixmap.h34
-rw-r--r--lib/gdi/grc.cpp15
-rw-r--r--lib/gdi/grc.h11
-rw-r--r--lib/gdi/sdl.cpp85
-rw-r--r--lib/gdi/sdl.h27
9 files changed, 203 insertions, 46 deletions
diff --git a/lib/gdi/Makefile.am b/lib/gdi/Makefile.am
index 419163c7..abb75b79 100644
--- a/lib/gdi/Makefile.am
+++ b/lib/gdi/Makefile.am
@@ -5,4 +5,4 @@ noinst_LIBRARIES = libenigma_gdi.a
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
diff --git a/lib/gdi/gfont.cpp b/lib/gdi/gfont.cpp
new file mode 100644
index 00000000..14fc8f37
--- /dev/null
+++ b/lib/gdi/gfont.cpp
@@ -0,0 +1,3 @@
+#include <lib/gdi/gfont.h>
+
+DEFINE_REF(gFont);
diff --git a/lib/gdi/gfont.h b/lib/gdi/gfont.h
new file mode 100644
index 00000000..d6697ce0
--- /dev/null
+++ b/lib/gdi/gfont.h
@@ -0,0 +1,41 @@
+#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
diff --git a/lib/gdi/gpixmap.cpp b/lib/gdi/gpixmap.cpp
index 7b7b91a8..c2c75e7a 100644
--- a/lib/gdi/gpixmap.cpp
+++ b/lib/gdi/gpixmap.cpp
@@ -1,8 +1,6 @@
#include <lib/gdi/gpixmap.h>
#include <lib/gdi/region.h>
-DEFINE_REF(gFont);
-
gLookup::gLookup()
:size(0), lookup(0)
{
@@ -107,7 +105,7 @@ void gPixmap::unlock()
void gPixmap::fill(const gRegion &region, const gColor &color)
{
- int i;
+ unsigned int i;
for (i=0; i<region.rects.size(); ++i)
{
const eRect &area = region.rects[i];
@@ -139,7 +137,7 @@ void gPixmap::fill(const gRegion &region, const gColor &color)
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];
@@ -269,11 +267,27 @@ static inline int sgn(int a)
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;
@@ -292,6 +306,7 @@ void gPixmap::line(const gRegion &clip, ePoint start, ePoint dst, gColor color)
} else
swap=0;
e = 2*dy-dx;
+
int lasthit = 0;
for(i=1; i<=dx; i++)
{
@@ -328,7 +343,11 @@ void gPixmap::line(const gRegion &clip, ePoint start, ePoint dst, gColor color)
} 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)
{
diff --git a/lib/gdi/gpixmap.h b/lib/gdi/gpixmap.h
index 396d92b7..e549787c 100644
--- a/lib/gdi/gpixmap.h
+++ b/lib/gdi/gpixmap.h
@@ -81,40 +81,6 @@ struct gLookup
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;
diff --git a/lib/gdi/grc.cpp b/lib/gdi/grc.cpp
index a63aef92..e7748967 100644
--- a/lib/gdi/grc.cpp
+++ b/lib/gdi/grc.cpp
@@ -302,6 +302,10 @@ void gPainter::clippop()
void gPainter::flush()
{
+ gOpcode o;
+ o.opcode = gOpcode::flush;
+ o.dc = m_dc.grabRef();
+ m_rc->submit(o);
}
void gPainter::end()
@@ -340,15 +344,16 @@ void gDC::exec(gOpcode *o)
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;
@@ -454,6 +459,8 @@ void gDC::exec(gOpcode *o)
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);
}
diff --git a/lib/gdi/grc.h b/lib/gdi/grc.h
index f6829902..8de5dadf 100644
--- a/lib/gdi/grc.h
+++ b/lib/gdi/grc.h
@@ -17,6 +17,7 @@
#include <lib/gdi/erect.h>
#include <lib/gdi/gpixmap.h>
#include <lib/gdi/region.h>
+#include <lib/gdi/gfont.h>
class eTextPara;
@@ -44,6 +45,8 @@ struct gOpcode
setClip, addClip, popClip,
+ flush,
+
end,shutdown
} opcode;
@@ -178,10 +181,16 @@ public:
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);
diff --git a/lib/gdi/sdl.cpp b/lib/gdi/sdl.cpp
new file mode 100644
index 00000000..591487f4
--- /dev/null
+++ b/lib/gdi/sdl.cpp
@@ -0,0 +1,85 @@
+#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");
diff --git a/lib/gdi/sdl.h b/lib/gdi/sdl.h
new file mode 100644
index 00000000..20ff04fa
--- /dev/null
+++ b/lib/gdi/sdl.h
@@ -0,0 +1,27 @@
+#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