summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWildemann Stefan <stefan.wildemann@corpuls.com>2019-08-07 10:05:09 +0200
committerWildemann Stefan <stefan.wildemann@corpuls.com>2019-08-07 10:05:09 +0200
commit46deec5bad55a2620034bf5adefb901e04c799f4 (patch)
treebc1b0a8b5e3b800ceeda3c10745590c41acfedfe
parentbbcb2e2f74758d0ceabe70cec6879e80a9494ddf (diff)
downloadnavit-46deec5bad55a2620034bf5adefb901e04c799f4.tar.gz
Add polygon with hole and dpi support to gtk_drawing_area
-rw-r--r--navit/graphics/gtk_drawing_area/graphics_gtk_drawing_area.c73
1 files changed, 63 insertions, 10 deletions
diff --git a/navit/graphics/gtk_drawing_area/graphics_gtk_drawing_area.c b/navit/graphics/gtk_drawing_area/graphics_gtk_drawing_area.c
index b61ac2403..35896791b 100644
--- a/navit/graphics/gtk_drawing_area/graphics_gtk_drawing_area.c
+++ b/navit/graphics/gtk_drawing_area/graphics_gtk_drawing_area.c
@@ -181,7 +181,8 @@ static struct graphics_gc_priv *gc_new(struct graphics_priv *gr, struct graphics
}
-static struct graphics_image_priv *image_new(struct graphics_priv *gr, struct graphics_image_methods *meth, char *name, int *w, int *h, struct point *hot, int rotation) {
+static struct graphics_image_priv *image_new(struct graphics_priv *gr, struct graphics_image_methods *meth, char *name,
+ int *w, int *h, struct point *hot, int rotation) {
GdkPixbuf *pixbuf;
struct graphics_image_priv *ret;
const char *option;
@@ -293,6 +294,33 @@ static void draw_polygon(struct graphics_priv *gr, struct graphics_gc_priv *gc,
cairo_fill(gr->cairo);
}
+static void draw_polygon_with_holes (struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int count,
+ int hole_count, int* ccount, struct point **holes) {
+ int i;
+ int j;
+ cairo_fill_rule_t old_rule;
+ set_drawing_color(gr->cairo, gc->c);
+ /* remember current fill rule */
+ old_rule = cairo_get_fill_rule (gr->cairo);
+ /* set fill rule */
+ cairo_set_fill_rule(gr->cairo, CAIRO_FILL_RULE_EVEN_ODD);
+ cairo_move_to(gr->cairo, p[0].x, p[0].y);
+ for (i=1; i<count; i++) {
+ cairo_line_to(gr->cairo, p[i].x, p[i].y);
+ }
+ for(j = 0; j < hole_count; j ++) {
+ if(hole_count > 0) {
+ cairo_move_to(gr->cairo, holes[j][0].x, holes[j][0].y);
+ for(i=0; i < ccount[j]; i ++) {
+ cairo_line_to(gr->cairo, holes[j][i].x, holes[j][i].y);
+ }
+ }
+ }
+ cairo_fill(gr->cairo);
+ /* restore fill rule */
+ cairo_set_fill_rule (gr->cairo,old_rule);
+}
+
static void draw_rectangle(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int w, int h) {
cairo_save(gr->cairo);
// Use OPERATOR_SOURCE to overwrite old contents even when drawing with transparency.
@@ -310,7 +338,8 @@ static void draw_circle(struct graphics_priv *gr, struct graphics_gc_priv *gc, s
cairo_stroke(gr->cairo);
}
-static void draw_rgb_image_buffer(cairo_t *cairo, int buffer_width, int buffer_height, int draw_pos_x, int draw_pos_y, int stride, unsigned char *buffer) {
+static void draw_rgb_image_buffer(cairo_t *cairo, int buffer_width, int buffer_height, int draw_pos_x, int draw_pos_y,
+ int stride, unsigned char *buffer) {
cairo_surface_t *buffer_surface = cairo_image_surface_create_for_data(
buffer, CAIRO_FORMAT_ARGB32, buffer_width, buffer_height, stride);
cairo_set_source_surface(cairo, buffer_surface, draw_pos_x, draw_pos_y);
@@ -318,7 +347,8 @@ static void draw_rgb_image_buffer(cairo_t *cairo, int buffer_width, int buffer_h
cairo_surface_destroy(buffer_surface);
}
-static void display_text_draw(struct font_freetype_text *text, struct graphics_priv *gr, struct graphics_gc_priv *fg, struct graphics_gc_priv *bg, struct point *p) {
+static void display_text_draw(struct font_freetype_text *text, struct graphics_priv *gr, struct graphics_gc_priv *fg,
+ struct graphics_gc_priv *bg, struct point *p) {
int i,x,y,stride;
struct font_freetype_glyph *g, **gp;
struct color transparent= {0x0,0x0,0x0,0x0};
@@ -359,7 +389,8 @@ static void display_text_draw(struct font_freetype_text *text, struct graphics_p
}
}
-static void draw_text(struct graphics_priv *gr, struct graphics_gc_priv *fg, struct graphics_gc_priv *bg, struct graphics_font_priv *font, char *text, struct point *p, int dx, int dy) {
+static void draw_text(struct graphics_priv *gr, struct graphics_gc_priv *fg, struct graphics_gc_priv *bg,
+ struct graphics_font_priv *font, char *text, struct point *p, int dx, int dy) {
struct font_freetype_text *t;
if (! font) {
@@ -384,13 +415,15 @@ static void draw_text(struct graphics_priv *gr, struct graphics_gc_priv *fg, str
gr->freetype_methods.text_destroy(t);
}
-static void draw_image(struct graphics_priv *gr, struct graphics_gc_priv *fg, struct point *p, struct graphics_image_priv *img) {
+static void draw_image(struct graphics_priv *gr, struct graphics_gc_priv *fg, struct point *p,
+ struct graphics_image_priv *img) {
gdk_cairo_set_source_pixbuf(gr->cairo, img->pixbuf, p->x, p->y);
cairo_paint(gr->cairo);
}
#ifdef HAVE_IMLIB2
-static unsigned char* create_buffer_with_stride_if_required(unsigned char *input_buffer, int w, int h, size_t bytes_per_pixel, size_t output_stride) {
+static unsigned char* create_buffer_with_stride_if_required(unsigned char *input_buffer, int w, int h,
+ size_t bytes_per_pixel, size_t output_stride) {
int line;
size_t input_offset, output_offset;
unsigned char *out_buf;
@@ -408,7 +441,8 @@ static unsigned char* create_buffer_with_stride_if_required(unsigned char *input
return out_buf;
}
-static void draw_image_warp(struct graphics_priv *gr, struct graphics_gc_priv *fg, struct point *p, int count, struct graphics_image_priv *img) {
+static void draw_image_warp(struct graphics_priv *gr, struct graphics_gc_priv *fg, struct point *p, int count,
+ struct graphics_image_priv *img) {
int w,h;
DATA32 *intermediate_buffer;
unsigned char* intermediate_buffer_aligned;
@@ -503,7 +537,8 @@ static void overlay_rect(struct graphics_priv *parent, struct graphics_priv *ove
r->height += parent->height;
}
-static void overlay_draw(struct graphics_priv *parent, struct graphics_priv *overlay, GdkRectangle *re, cairo_t *cairo) {
+static void overlay_draw(struct graphics_priv *parent, struct graphics_priv *overlay, GdkRectangle *re,
+ cairo_t *cairo) {
GdkRectangle or, ir;
if (parent->overlay_disabled || overlay->overlay_disabled || overlay->overlay_autodisabled)
return;
@@ -866,7 +901,8 @@ static int set_attr(struct graphics_priv *gr, struct attr *attr) {
}
}
-static struct graphics_priv *overlay_new(struct graphics_priv *gr, struct graphics_methods *meth, struct point *p, int w, int h, int wraparound) {
+static struct graphics_priv *overlay_new(struct graphics_priv *gr, struct graphics_methods *meth, struct point *p,
+ int w, int h, int wraparound) {
int w2,h2;
struct graphics_priv *this=graphics_gtk_drawing_area_new_helper(meth);
this->widget=gr->widget;
@@ -965,6 +1001,20 @@ static void *get_data(struct graphics_priv *this, char const *type) {
return NULL;
}
+/**
+ * @brief Return number of dots per inch
+ * @param gr self handle
+ * @return dpi value
+ */
+static navit_float get_dpi(struct graphics_priv * gr) {
+ gdouble dpi = 96;
+ GdkScreen *screen = gtk_widget_get_screen(gr->widget);
+ if(screen != NULL) {
+ dpi = gdk_screen_get_resolution (screen);
+ }
+ return (navit_float) dpi;
+}
+
static struct graphics_methods graphics_methods = {
graphics_destroy,
draw_mode,
@@ -993,6 +1043,8 @@ static struct graphics_methods graphics_methods = {
set_attr,
NULL, /* show_native_keyboard */
NULL, /* hide_native_keyboard */
+ get_dpi, /* get dpi */
+ draw_polygon_with_holes
};
static struct graphics_priv *graphics_gtk_drawing_area_new_helper(struct graphics_methods *meth) {
@@ -1010,7 +1062,8 @@ static struct graphics_priv *graphics_gtk_drawing_area_new_helper(struct graphic
return this;
}
-static struct graphics_priv *graphics_gtk_drawing_area_new(struct navit *nav, struct graphics_methods *meth, struct attr **attrs, struct callback_list *cbl) {
+static struct graphics_priv *graphics_gtk_drawing_area_new(struct navit *nav, struct graphics_methods *meth,
+ struct attr **attrs, struct callback_list *cbl) {
int i;
GtkWidget *draw;
struct attr *attr;