summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorguillaume <guillaume>2007-01-28 19:46:46 +0000
committerguillaume <guillaume>2007-01-28 19:46:46 +0000
commitff3cdf51e314d58449d79f3fcbc56ebe823360df (patch)
tree1aa73c5797737f6c46d025eef1e4c4622836b331
parentb4e034d172e3e950c58f49e48462900b5959a53c (diff)
downloadberyl-desktop-manager-ff3cdf51e314d58449d79f3fcbc56ebe823360df.tar.gz
beryl-desktop-manager-ff3cdf51e314d58449d79f3fcbc56ebe823360df.tar.bz2
bdm: renderText
-rw-r--r--src/bdm.c64
-rw-r--r--src/bdm.h3
2 files changed, 64 insertions, 3 deletions
diff --git a/src/bdm.c b/src/bdm.c
index 3772018..8a71662 100644
--- a/src/bdm.c
+++ b/src/bdm.c
@@ -11,6 +11,8 @@
#include <gdk/gdkx.h>
#include <gdk/gdkprivate.h>
#include <cairo/cairo.h>
+#include <pango/pango.h>
+#include <pango/pangocairo.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
@@ -48,6 +50,65 @@ static void renderImage(cairo_t * cr, BDMImage * image, ScreenArea * area)
}
+static void updateFont (BDMText * text)
+{
+ if (text->font != NULL)
+ pango_font_description_free (text->font);
+
+ text->font = pango_font_description_new ();
+
+ pango_font_description_set_family (text->font, text->family);
+ pango_font_description_set_absolute_size (text->font,
+ text->size * PANGO_SCALE);
+
+ pango_font_description_set_style (text->font, PANGO_STYLE_NORMAL);
+
+ if (text->style & TEXT_STYLE_BOLD)
+ pango_font_description_set_weight (text->font, PANGO_WEIGHT_BOLD);
+
+ if (text->style & TEXT_STYLE_ITALIC)
+ pango_font_description_set_style (text->font, PANGO_STYLE_ITALIC);
+}
+
+static void renderText (cairo_t * cr, BDMText * text, ScreenArea * area)
+{
+ PangoLayout *layout;
+ int w, h;
+
+ if (text->attrib->updateFont)
+ updateFont (text);
+
+ layout = pango_cairo_create_layout (cr);
+ if (!layout)
+ {
+ fprintf (stderr, "Error: Couldn't create pango layout\n");
+ return;
+ }
+
+ pango_layout_set_font_description (layout, text->font);
+
+ if (text->ellipsize)
+ pango_layout_set_ellipsize (layout, PANGO_ELLIPSIZE_END);
+
+ pango_layout_set_text (layout, text->text, -1);
+
+ pango_cairo_update_layout (cr, layout);
+
+ cairo_set_source_rgba(cr,0,0,0,0);
+ cairo_paint(cr);
+ cairo_save(cr);
+
+ cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
+
+ cairo_set_source_rgba (cr, text->color[0] / 65535.0, text->color[1] / 65535.0,
+ text->color[2] / 65535.0, text->color[3] / 65535.0);
+
+ pango_cairo_show_layout (cr, layout);
+ g_object_unref (layout);
+
+ cairo_restore (cr);
+}
+
static void updateWidgets(cairo_t * cr,ScreenArea * area)
{
BDMWidget * widget = widgetList->head;
@@ -63,14 +124,11 @@ static void updateWidgets(cairo_t * cr,ScreenArea * area)
if (image->attrib->needsPainting)
renderImage(cr,image,area);
}
- // DO TEXT
- /*
for (text = widget->getText(); text; text=text->next)
{
if (text->attrib->needsPainting)
renderText(cr,text,area);
}
- */
}
}
diff --git a/src/bdm.h b/src/bdm.h
index 604491d..1e487a2 100644
--- a/src/bdm.h
+++ b/src/bdm.h
@@ -76,6 +76,7 @@ typedef struct _BDMPaintAttribs
int alpha;
int needsPainting;
+ int updateFont;
} BDMPaintAttribs;
typedef struct _BDMImage BDMImage;
@@ -103,10 +104,12 @@ struct _BDMText
char * text;
BDMWidget * widget;
+ PangoFontDescription *font;
char *family;
int size;
unsigned short color[4];
unsigned int style;
+ unsigned short ellipsize;
} ;
typedef struct _BDMEvent