* @returns <>
* @author Martin Schaller (04/2008)
*/
-struct graphics * graphics_overlay_new(struct graphics *parent, struct point *p, int w, int h)
+struct graphics * graphics_overlay_new(struct graphics *parent, struct point *p, int w, int h, int alpha)
{
struct graphics *this_;
this_=g_new0(struct graphics, 1);
- this_->priv=parent->meth.overlay_new(parent->priv, &this_->meth, p, w, h);
+ this_->priv=parent->meth.overlay_new(parent->priv, &this_->meth, p, w, h, alpha);
return this_;
}
this_->gc[2]=graphics_gc_new(this_);
graphics_gc_set_background(this_->gc[2], &(struct color) { 0xffff, 0xffff, 0xffff, 0xffff });
graphics_gc_set_foreground(this_->gc[2], &(struct color) { 0x0000, 0x0000, 0x0000, 0xffff });
- this_->meth.background_gc(this_->priv, this_->gc[0]->priv);
+ graphics_background_gc(this_, this_->gc[0]);
navit_sharedir = getenv("NAVIT_SHAREDIR");
}
this_->meth.draw_image(this_->priv, gc->priv, p, img->priv);
}
+
//##############################################################################################################
//# Description:
//# Comment:
return 1;
}
+void
+graphics_background_gc(struct graphics *this_, struct graphics_gc *gc)
+{
+ this_->meth.background_gc(this_->priv, gc ? gc->priv : NULL);
+}
#include "attr.h"
#include "popup.h"
graphics_gc_set_background(gra->gc[0], &l->color);
graphics_gc_set_foreground(gra->gc[0], &l->color);
gra->default_font = g_strdup(l->font);
- gra->meth.background_gc(gra->priv, gra->gc[0]->priv);
+ graphics_background_gc(gra, gra->gc[0]);
gra->meth.draw_mode(gra->priv, draw_mode_begin);
gra->meth.draw_rectangle(gra->priv, gra->gc[0]->priv, &p, 32767, 32767);
xdisplay_draw(displaylist->dl, gra, l, order+l->order_delta);
struct graphics_font_priv *(*font_new)(struct graphics_priv *gr, struct graphics_font_methods *meth, char *font, int size, int flags);
struct graphics_gc_priv *(*gc_new)(struct graphics_priv *gr, struct graphics_gc_methods *meth);
void (*background_gc)(struct graphics_priv *gr, struct graphics_gc_priv *gc);
- struct graphics_priv *(*overlay_new)(struct graphics_priv *gr, struct graphics_methods *meth, struct point *p, int w, int h);
+ struct graphics_priv *(*overlay_new)(struct graphics_priv *gr, struct graphics_methods *meth, struct point *p, int w, int h, int alpha);
struct graphics_image_priv *(*image_new)(struct graphics_priv *gr, struct graphics_image_methods *meth, char *path, int *w, int *h, struct point *hot);
void *(*get_data)(struct graphics_priv *gr, char *type);
void (*image_free)(struct graphics_priv *gr, struct graphics_image_priv *priv);
struct callback;
struct graphics *graphics_new(struct attr *parent, struct attr **attrs);
int graphics_get_attr(struct graphics *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter);
-struct graphics *graphics_overlay_new(struct graphics *parent, struct point *p, int w, int h);
+struct graphics *graphics_overlay_new(struct graphics *parent, struct point *p, int w, int h, int alpha);
void graphics_init(struct graphics *this_);
void *graphics_get_data(struct graphics *this_, char *type);
void graphics_add_callback(struct graphics *this_, struct callback *cb);
void graphics_overlay_disable(struct graphics *this_, int disable);
void graphics_draw_image(struct graphics *this_, struct graphics_gc *gc, struct point *p, struct graphics_image *img);
int graphics_draw_drag(struct graphics *this_, struct point *p);
+void graphics_background_gc(struct graphics *this_, struct graphics_gc *gc);
void display_add(struct displaylist *displaylist, struct item *item, int count, struct point *pnt, char *label);
int graphics_ready(struct graphics *this_);
void graphics_displaylist_draw(struct graphics *gra, struct displaylist *displaylist, struct transformation *trans, struct layout *l, int callback);
int win_h;
int visible;
int overlay_disabled;
+ int a;
struct graphics_priv *parent;
struct graphics_priv *overlays;
struct graphics_priv *next;
GdkGC *gc;
struct graphics_priv *gr;
int level;
+ char r,g,b,a;
};
struct graphics_image_priv {
gdkc.red=c->r;
gdkc.green=c->g;
gdkc.blue=c->b;
+ gc->r=c->r >> 8;
+ gc->g=c->g >> 8;
+ gc->b=c->b >> 8;
+ gc->a=c->a >> 8;
gdk_colormap_alloc_color(gc->gr->colormap, &gdkc, FALSE, TRUE);
if (fg) {
gdk_gc_set_foreground(gc->gc, &gdkc);
#endif
static void
-overlay_draw(struct graphics_priv *parent, struct graphics_priv *overlay, int window)
+overlay_rect(struct graphics_priv *parent, struct graphics_priv *overlay, GdkRectangle *r)
+{
+ r->x=overlay->p.x;
+ if (r->x < 0)
+ r->x += parent->width;
+ r->y=overlay->p.y;
+ if (r->y < 0)
+ r->y += parent->height;
+ r->width=overlay->width;
+ if (r->width < 0)
+ r->width += parent->width;
+ r->height=overlay->height;
+ if (r->height < 0)
+ r->height += parent->height;
+}
+
+static void
+overlay_draw(struct graphics_priv *parent, struct graphics_priv *overlay, GdkRectangle *r, GdkPixmap *pixmap, GdkGC *gc)
{
GdkPixbuf *pixbuf,*pixbuf2;
- GtkWidget *widget=parent->widget;
guchar *pixels1, *pixels2, *p1, *p2;
- int x,y,w,h;
+ int x,y;
int rowstride1,rowstride2;
int n_channels1,n_channels2;
+ GdkRectangle or;
+ struct graphics_gc_priv *bg=overlay->background_gc;
- if (! parent->drawable)
- return;
if (parent->overlay_disabled || overlay->overlay_disabled)
return;
- w=overlay->width;
- if (w < 0)
- w+=parent->width;
- h=overlay->height;
- if (h < 0)
- h+=parent->height;
- pixbuf=gdk_pixbuf_get_from_drawable(NULL, overlay->drawable, NULL, 0, 0, 0, 0, w, h);
+ dbg(1,"r->x=%d r->y=%d r->width=%d r->height=%d\n", r->x, r->y, r->width, r->height);
+ overlay_rect(parent, overlay, &or);
+ dbg(1,"or.x=%d or.y=%d or.width=%d or.height=%d\n", or.x, or.y, or.width, or.height);
+ or.x-=r->x;
+ or.y-=r->y;
+ pixbuf=gdk_pixbuf_get_from_drawable(NULL, overlay->drawable, NULL, 0, 0, 0, 0, or.width, or.height);
pixbuf2=gdk_pixbuf_new(gdk_pixbuf_get_colorspace(pixbuf), TRUE, gdk_pixbuf_get_bits_per_sample(pixbuf),
- gdk_pixbuf_get_width(pixbuf), gdk_pixbuf_get_height(pixbuf));
-
+ or.width, or.height);
rowstride1 = gdk_pixbuf_get_rowstride (pixbuf);
rowstride2 = gdk_pixbuf_get_rowstride (pixbuf2);
pixels1=gdk_pixbuf_get_pixels (pixbuf);
pixels2=gdk_pixbuf_get_pixels (pixbuf2);
n_channels1 = gdk_pixbuf_get_n_channels (pixbuf);
n_channels2 = gdk_pixbuf_get_n_channels (pixbuf2);
- for (y = 0 ; y < h ; y++) {
- for (x = 0 ; x < w ; x++) {
+ for (y = 0 ; y < or.height ; y++) {
+ for (x = 0 ; x < or.width ; x++) {
p1 = pixels1 + y * rowstride1 + x * n_channels1;
p2 = pixels2 + y * rowstride2 + x * n_channels2;
p2[0]=p1[0];
p2[1]=p1[1];
p2[2]=p1[2];
- p2[3]=127;
+ if (bg && p1[0] == bg->r && p1[1] == bg->g && p1[2] == bg->b)
+ p2[3]=bg->a;
+ else
+ p2[3]=overlay->a;
}
}
- x=overlay->p.x;
- if (x < 0)
- x+=parent->width;
- y=overlay->p.y;
- if (y < 0)
- y+=parent->height;
- if (window) {
- if (overlay->background_ready)
- gdk_draw_drawable(parent->drawable, widget->style->fg_gc[GTK_WIDGET_STATE(widget)], overlay->background, 0, 0, x, y, w, h);
- }
- else {
- gdk_draw_drawable(overlay->background, widget->style->fg_gc[GTK_WIDGET_STATE(widget)], parent->drawable, x, y, 0, 0, w, h);
- overlay->background_ready=1;
- }
- gdk_draw_pixbuf(parent->drawable, widget->style->fg_gc[GTK_WIDGET_STATE(widget)], pixbuf2, 0, 0, x, y, w, h, GDK_RGB_DITHER_NONE, 0, 0);
- if (window)
- gdk_draw_drawable(widget->window, widget->style->fg_gc[GTK_WIDGET_STATE(widget)], parent->drawable, x, y, x, y, w, h);
+ gdk_draw_pixbuf(pixmap, gc, pixbuf2, 0, 0, or.x, or.y, or.width, or.height, GDK_RGB_DITHER_NONE, 0, 0);
g_object_unref(pixbuf);
g_object_unref(pixbuf2);
-#if 0
- gdk_draw_drawable(gr->gra->drawable,
- gr->gra->widget->style->fg_gc[GTK_WIDGET_STATE(gr->gra->widget)],
- img->gra->drawable,
- 0, 0, p->x, p->y, img->gra->width, img->gra->height);
-#endif
}
static void
}
static void
-draw_mode(struct graphics_priv *gr, enum draw_mode_num mode)
+gtk_drawing_area_draw(struct graphics_priv *gr, GdkRectangle *r)
{
- struct graphics_priv *overlay;
+ GdkPixmap *pixmap;
GtkWidget *widget=gr->widget;
+ GdkGC *gc=widget->style->fg_gc[GTK_WIDGET_STATE(widget)];
+ struct graphics_priv *overlay;
+
+ if (! gr->drawable)
+ return;
+ pixmap = gdk_pixmap_new(widget->window, r->width, r->height, -1);
+ if ((gr->p.x || gr->p.y) && gr->background_gc)
+ gdk_draw_rectangle(pixmap, gr->background_gc->gc, TRUE, 0, 0, r->width, r->height);
+ gdk_draw_drawable(pixmap, gc, gr->drawable, r->x, r->y, gr->p.x, gr->p.y, r->width, r->height);
+ overlay=gr->overlays;
+ while (overlay) {
+ overlay_draw(gr,overlay,r,pixmap,gc);
+ overlay=overlay->next;
+ }
+ gdk_draw_drawable(widget->window, gc, pixmap, 0, 0, r->x, r->y, r->width, r->height);
+ g_object_unref(pixmap);
+}
+static void
+draw_mode(struct graphics_priv *gr, enum draw_mode_num mode)
+{
+ GdkRectangle r;
#if 0
if (mode == draw_mode_begin) {
if (! gr->parent && gr->background_gc)
#endif
if (mode == draw_mode_end && gr->mode != draw_mode_cursor) {
if (gr->parent) {
- overlay_draw(gr->parent, gr, 1);
+ overlay_rect(gr->parent, gr, &r);
+ gtk_drawing_area_draw(gr->parent, &r);
} else {
- overlay=gr->overlays;
- while (overlay) {
- overlay_draw(gr, overlay, 0);
- overlay=overlay->next;
- }
- if (gr->p.x || gr->p.y) {
- if(!gr->background_ready) {
- gr->background = gdk_pixmap_new(widget->window, gr->width, gr->width, -1);
- gdk_draw_rectangle(gr->background, gr->background_gc->gc, TRUE, 0, 0, gr->width, gr->height);
- gr->background_ready = 1;
- }
- gdk_draw_drawable(widget->window,
- widget->style->fg_gc[GTK_WIDGET_STATE(widget)],
- gr->background,
- 0, 0, 0, 0, -1, -1);
- }
- gdk_draw_drawable(widget->window,
- widget->style->fg_gc[GTK_WIDGET_STATE(widget)],
- gr->drawable,
- 0, 0, gr->p.x, gr->p.y, -1, -1);
+ r.x=0;
+ r.y=0;
+ r.width=gr->width;
+ r.height=gr->height;
+ gtk_drawing_area_draw(gr, &r);
}
}
gr->mode=mode;
gra->visible=1;
if (! gra->drawable)
configure(widget, NULL, user_data);
+ gtk_drawing_area_draw(gra, &event->area);
+#if 0
gdk_draw_drawable(widget->window, widget->style->fg_gc[GTK_WIDGET_STATE(widget)],
gra->drawable, event->area.x, event->area.y,
event->area.x, event->area.y,
event->area.width, event->area.height);
+#endif
return FALSE;
}
}
static struct graphics_priv *
-overlay_new(struct graphics_priv *gr, struct graphics_methods *meth, struct point *p, int w, int h)
+overlay_new(struct graphics_priv *gr, struct graphics_methods *meth, struct point *p, int w, int h, int alpha)
{
struct graphics_priv *this=graphics_gtk_drawing_area_new_helper(meth);
this->drawable=gdk_pixmap_new(gr->widget->window, w, h, -1);
this->parent=gr;
this->background=gdk_pixmap_new(gr->widget->window, w, h, -1);
this->next=gr->overlays;
+ this->a=alpha >> 8;
gr->overlays=this;
return this;
}
struct graphics *navit_gr;
struct color c;
navit_gr=navit_get_graphics(nav);
- this->gr=graphics_overlay_new(navit_gr, &this->p, this->w, this->h);
+ this->gr=graphics_overlay_new(navit_gr, &this->p, this->w, this->h, 65535);
this->bg=graphics_gc_new(this->gr);
- c.r=0; c.g=0; c.b=0; c.a=65535;
+ c.r=0; c.g=0; c.b=0; c.a=32767;
graphics_gc_set_foreground(this->bg, &c);
+ graphics_background_gc(this->gr, this->bg);
this->white=graphics_gc_new(this->gr);
c.r=65535; c.g=65535; c.b=65535; c.a=65535;
struct color c;
char *flag=g_strjoin(NULL,getenv("NAVIT_SHAREDIR"), "/xpm/flag_wh_bk.xpm", NULL);
navit_gr=navit_get_graphics(nav);
- this->gr=graphics_overlay_new(navit_gr, &this->p, this->w, this->h);
+ this->gr=graphics_overlay_new(navit_gr, &this->p, this->w, this->h, 65535);
this->bg=graphics_gc_new(this->gr);
- c.r=0; c.g=0; c.b=0; c.a=0;
+ c.r=0; c.g=0; c.b=0; c.a=32767;
graphics_gc_set_foreground(this->bg, &c);
+ graphics_background_gc(this->gr, this->bg);
this->white=graphics_gc_new(this->gr);
c.r=65535; c.g=65535; c.b=65535; c.a=65535;
if (map)
mr=map_rect_new(map, NULL);
if (mr)
- item=map_rect_get_item(mr);
+ while ((item=map_rect_get_item(mr)) && item->type == type_nav_position);
if (item) {
name=item_to_name(item->type);
dbg(1,"name=%s\n", name);
struct graphics *navit_gr;
struct color c;
navit_gr=navit_get_graphics(nav);
- this->gr=graphics_overlay_new(navit_gr, &this->p, this->w, this->h);
+ this->gr=graphics_overlay_new(navit_gr, &this->p, this->w, this->h, 65535);
this->bg=graphics_gc_new(this->gr);
- c.r=0; c.g=0; c.b=0; c.a=0;
+ c.r=0; c.g=0; c.b=0; c.a=32767;
graphics_gc_set_foreground(this->bg, &c);
+ graphics_background_gc(this->gr, this->bg);
this->white=graphics_gc_new(this->gr);
c.r=65535; c.g=65535; c.b=65535; c.a=65535;
struct color c;
navit_gr=navit_get_graphics(nav);
this->active=-1;
- this->gr=graphics_overlay_new(navit_gr, &this->p, this->w, this->h);
+ this->gr=graphics_overlay_new(navit_gr, &this->p, this->w, this->h, 65535);
this->bg=graphics_gc_new(this->gr);
- c.r=0; c.g=0; c.b=0; c.a=65535;
+ c.r=0; c.g=0; c.b=0; c.a=32767;
graphics_gc_set_foreground(this->bg, &c);
+ graphics_background_gc(this->gr, this->bg);
this->white=graphics_gc_new(this->gr);
c.r=65535; c.g=65535; c.b=65535; c.a=65535;