From 892a348b7331b66f27e41e3ac6b91cd924243d81 Mon Sep 17 00:00:00 2001 From: James Bursa Date: Sun, 17 Oct 2004 21:51:06 +0000 Subject: [PATCH] [project @ 2004-10-17 21:51:06 by bursa] Update to use plotters for HTML redraw. svn path=/import/netsurf/; revision=1322 --- gtk/gtk_bitmap.c | 30 ------- gtk/gtk_gui.c | 4 +- gtk/gtk_plotters.c | 215 +++++++++++++++++++++++++++++++++++++++++++++ gtk/gtk_window.c | 128 ++++----------------------- 4 files changed, 235 insertions(+), 142 deletions(-) create mode 100644 gtk/gtk_plotters.c diff --git a/gtk/gtk_bitmap.c b/gtk/gtk_bitmap.c index 3a228a5ef..7db84ffe2 100644 --- a/gtk/gtk_bitmap.c +++ b/gtk/gtk_bitmap.c @@ -114,36 +114,6 @@ void bitmap_destroy(struct bitmap *bitmap) } -/** - * Render a bitmap. - */ - -bool bitmap_redraw(struct content *c, int x, int y, - int width, int height, - int clip_x0, int clip_y0, int clip_x1, int clip_y1, - float scale, unsigned long background_colour) -{ - GdkPixbuf *scaled; - - scaled = gdk_pixbuf_scale_simple((GdkPixbuf *) c->bitmap, - width, height, - GDK_INTERP_BILINEAR); - if (!scaled) - return false; - - gdk_draw_pixbuf(current_drawable, current_gc, - scaled, - 0, 0, - x, y, - width, height, - GDK_RGB_DITHER_NORMAL, 0, 0); - - g_object_unref(scaled); - - return true; -} - - /** * Save a bitmap in the platform's native format. * diff --git a/gtk/gtk_gui.c b/gtk/gtk_gui.c index df7db3011..1977c5f43 100644 --- a/gtk/gtk_gui.c +++ b/gtk/gtk_gui.c @@ -40,7 +40,7 @@ void gui_init2(int argc, char** argv) void gui_poll(bool active) { - /*netsurf_quit =*/ gtk_main_iteration_do(!active); + gtk_main_iteration_do(!active); } @@ -48,7 +48,7 @@ void gui_multitask(void) { gui_in_multitask = true; while (gtk_events_pending()) - /*netsurf_quit =*/ gtk_main_iteration(); + gtk_main_iteration(); gui_in_multitask = false; } diff --git a/gtk/gtk_plotters.c b/gtk/gtk_plotters.c new file mode 100644 index 000000000..86ba56fa9 --- /dev/null +++ b/gtk/gtk_plotters.c @@ -0,0 +1,215 @@ +/* + * This file is part of NetSurf, http://netsurf.sourceforge.net/ + * Licensed under the GNU General Public License, + * http://www.opensource.org/licenses/gpl-license + * Copyright 2004 James Bursa + */ + +/** \file + * Target independent plotting (GDK / GTK+ implementation). + */ + +#include +#include +#include "netsurf/desktop/plotters.h" +#include "netsurf/render/font.h" +#include "netsurf/utils/log.h" + + +extern GtkWidget *current_widget; +extern GdkDrawable *current_drawable; +extern GdkGC *current_gc; + + +static bool nsgtk_plot_clg(colour c); +static bool nsgtk_plot_rectangle(int x0, int y0, int width, int height, + colour c, bool dotted); +static bool nsgtk_plot_line(int x0, int y0, int x1, int y1, int width, + colour c, bool dotted, bool dashed); +static bool nsgtk_plot_polygon(int *p, unsigned int n, colour fill); +static bool nsgtk_plot_fill(int x0, int y0, int x1, int y1, colour c); +static bool nsgtk_plot_clip(int clip_x0, int clip_y0, + int clip_x1, int clip_y1); +static bool nsgtk_plot_text(int x, int y, struct font_data *font, + const char *text, size_t length, colour bg, colour c); +static bool nsgtk_plot_disc(int x, int y, int radius, colour colour); +static bool nsgtk_plot_bitmap(int x, int y, int width, int height, + struct bitmap *bitmap, colour bg); +static bool nsgtk_plot_bitmap_tile(int x, int y, int width, int height, + struct bitmap *bitmap, colour bg, + bool repeat_x, bool repeat_y); +static void nsgtk_set_colour(colour c); + + +struct plotter_table plot; + +const struct plotter_table nsgtk_plotters = { + nsgtk_plot_clg, + nsgtk_plot_rectangle, + nsgtk_plot_line, + nsgtk_plot_polygon, + nsgtk_plot_fill, + nsgtk_plot_clip, + nsgtk_plot_text, + nsgtk_plot_disc, + nsgtk_plot_bitmap, + nsgtk_plot_bitmap_tile +}; + + +bool nsgtk_plot_clg(colour c) +{ + return true; +} + + +bool nsgtk_plot_rectangle(int x0, int y0, int width, int height, + colour c, bool dotted) +{ + nsgtk_set_colour(c); + gdk_draw_rectangle(current_drawable, current_gc, + FALSE, x0, y0, width, height); + return true; +} + + +bool nsgtk_plot_line(int x0, int y0, int x1, int y1, int width, + colour c, bool dotted, bool dashed) +{ + nsgtk_set_colour(c); + gdk_draw_line(current_drawable, current_gc, + x0, y0, x1, y1); + return true; +} + + +bool nsgtk_plot_polygon(int *p, unsigned int n, colour fill) +{ + unsigned int i; + GdkPoint q[n]; + for (i = 0; i != n; i++) { + q[i].x = p[i * 2]; + q[i].y = p[i * 2 + 1]; + } + nsgtk_set_colour(fill); + gdk_draw_polygon(current_drawable, current_gc, + TRUE, q, n); + return true; +} + + +bool nsgtk_plot_fill(int x0, int y0, int x1, int y1, colour c) +{ + nsgtk_set_colour(c); + gdk_draw_rectangle(current_drawable, current_gc, + TRUE, x0, y0, x1 - x0, y1 - y0); + return true; +} + + +bool nsgtk_plot_clip(int clip_x0, int clip_y0, + int clip_x1, int clip_y1) +{ + GdkRectangle clip = { clip_x0, clip_y0, + clip_x1 - clip_x0 + 1, clip_y1 - clip_y0 + 1 }; + gdk_gc_set_clip_rectangle(current_gc, &clip); + return true; +} + + +bool nsgtk_plot_text(int x, int y, struct font_data *font, + const char *text, size_t length, colour bg, colour c) +{ + PangoContext *context; + PangoLayout *layout; + PangoLayoutLine *line; + GdkColor colour = { 0, + ((c & 0xff) << 8) | (c & 0xff), + (c & 0xff00) | (c & 0xff00 >> 8), + ((c & 0xff0000) >> 8) | (c & 0xff0000 >> 16) }; + + context = gtk_widget_get_pango_context(current_widget); + layout = pango_layout_new(context); + pango_layout_set_font_description(layout, + (const PangoFontDescription *) font->id); + pango_layout_set_text(layout, text, length); + + line = pango_layout_get_line(layout, 0); + + gdk_draw_layout_line_with_colors(current_drawable, current_gc, + x, y, line, &colour, 0); + + g_object_unref(layout); + + return true; +} + + +bool nsgtk_plot_disc(int x, int y, int radius, colour colour) +{ + return true; +} + + +bool nsgtk_plot_bitmap(int x, int y, int width, int height, + struct bitmap *bitmap, colour bg) +{ + GdkPixbuf *pixbuf = (GdkPixbuf *) bitmap; + + if (gdk_pixbuf_get_width(pixbuf) == width && + gdk_pixbuf_get_height(pixbuf) == height) { + gdk_draw_pixbuf(current_drawable, current_gc, + pixbuf, + 0, 0, + x, y, + width, height, + GDK_RGB_DITHER_NORMAL, 0, 0); + + } else { + GdkPixbuf *scaled; + scaled = gdk_pixbuf_scale_simple(pixbuf, + width, height, + GDK_INTERP_BILINEAR); + if (!scaled) + return false; + + gdk_draw_pixbuf(current_drawable, current_gc, + scaled, + 0, 0, + x, y, + width, height, + GDK_RGB_DITHER_NORMAL, 0, 0); + + g_object_unref(scaled); + } + + return true; +} + + +bool nsgtk_plot_bitmap_tile(int x, int y, int width, int height, + struct bitmap *bitmap, colour bg, + bool repeat_x, bool repeat_y) +{ + return true; +} + + +void nsgtk_set_colour(colour c) +{ + int r, g, b; + GdkColor colour; + + r = c & 0xff; + g = (c & 0xff00) >> 8; + b = (c & 0xff0000) >> 16; + + colour.red = r | (r << 8); + colour.green = g | (g << 8); + colour.blue = b | (b << 8); + colour.pixel = (r << 16) | (g << 8) | b; + + gdk_color_alloc(gtk_widget_get_colormap(current_widget), + &colour); + gdk_gc_set_foreground(current_gc, &colour); +} diff --git a/gtk/gtk_window.c b/gtk/gtk_window.c index 912fff78f..3a8081b3e 100644 --- a/gtk/gtk_window.c +++ b/gtk/gtk_window.c @@ -15,6 +15,7 @@ #include "netsurf/desktop/browser.h" #include "netsurf/desktop/gui.h" #include "netsurf/desktop/netsurf.h" +#include "netsurf/desktop/plotters.h" #include "netsurf/render/box.h" #include "netsurf/render/font.h" #include "netsurf/render/form.h" @@ -33,11 +34,12 @@ struct gui_window { int old_width; struct browser_window *bw; }; -static GtkWidget *current_widget; +GtkWidget *current_widget; GdkDrawable *current_drawable; GdkGC *current_gc; +static void gui_window_destroy_event(GtkWidget *widget, gpointer data); static gboolean gui_window_expose_event(GtkWidget *widget, GdkEventExpose *event, gpointer data); static gboolean gui_window_url_key_press_event(GtkWidget *widget, @@ -139,6 +141,9 @@ struct gui_window *gui_create_browser_window(struct browser_window *bw, g->old_width = drawing_area->allocation.width; g->bw = bw; + g_signal_connect(G_OBJECT(window), "destroy", + G_CALLBACK(gui_window_destroy_event), g); + g_signal_connect(G_OBJECT(drawing_area), "expose_event", G_CALLBACK(gui_window_expose_event), g); g_signal_connect(G_OBJECT(drawing_area), "configure_event", @@ -152,6 +157,16 @@ struct gui_window *gui_create_browser_window(struct browser_window *bw, } +void gui_window_destroy_event(GtkWidget *widget, gpointer data) +{ + struct gui_window *g = data; + gui_window_destroy(g); + netsurf_quit = true; +} + + +extern const struct plotter_table nsgtk_plotters; + gboolean gui_window_expose_event(GtkWidget *widget, GdkEventExpose *event, gpointer data) { @@ -165,6 +180,8 @@ gboolean gui_window_expose_event(GtkWidget *widget, current_drawable = widget->window; current_gc = gdk_gc_new(current_drawable); + plot = nsgtk_plotters; + content_redraw(c, 0, 0, widget->allocation.width, widget->allocation.height, @@ -338,112 +355,3 @@ void gui_window_remove_caret(struct gui_window *g) void gui_window_new_content(struct gui_window *g) { } - - -bool html_redraw(struct content *c, int x, int y, - int width, int height, - int clip_x0, int clip_y0, int clip_x1, int clip_y1, - float scale, unsigned long background_colour) -{ - html_redraw_box(c, c->data.html.layout->children, x, y); - return true; -} - - -void html_redraw_box(struct content *content, struct box *box, - int x, int y) -{ - struct box *c; - int width, height; - int padding_left, padding_top; - int padding_width, padding_height; - int x0, y0, x1, y1; - - x += box->x; - y += box->y; - width = box->width; - height = box->height; - padding_left = box->padding[LEFT]; - padding_top = box->padding[TOP]; - padding_width = (box->padding[LEFT] + box->width + - box->padding[RIGHT]); - padding_height = (box->padding[TOP] + box->height + - box->padding[BOTTOM]); - - x0 = x; - y1 = y - 1; - x1 = x0 + padding_width - 1; - y0 = y1 - padding_height + 1; - - /* if visibility is hidden render children only */ - if (box->style && box->style->visibility == CSS_VISIBILITY_HIDDEN) { - for (c = box->children; c; c = c->next) - html_redraw_box(content, c, x, y); - return; - } - - /* background colour */ - if (box->style != 0 && box->style->background_color != TRANSPARENT) { - int r, g, b; - GdkColor colour; - - r = box->style->background_color & 0xff; - g = (box->style->background_color & 0xff00) >> 8; - b = (box->style->background_color & 0xff0000) >> 16; - - colour.red = r | (r << 8); - colour.green = g | (g << 8); - colour.blue = b | (b << 8); - colour.pixel = (r << 16) | (g << 8) | b; - - gdk_color_alloc(gtk_widget_get_colormap(current_widget), - &colour); - gdk_gc_set_foreground(current_gc, &colour); - gdk_draw_rectangle(current_drawable, current_gc, - TRUE, x, y, padding_width, padding_height); - } - -/* gdk_draw_rectangle(current_drawable, current_gc, */ -/* FALSE, x, y, padding_width, padding_height); */ - - if (box->object) { - content_redraw(box->object, x + padding_left, y - padding_top, - width, height, x0, y0, x1, y1, 1.0, 0xFFFFFF); - - } else if (box->gadget && box->gadget->type == GADGET_CHECKBOX) { - - } else if (box->gadget && box->gadget->type == GADGET_RADIO) { - - } else if (box->gadget && box->gadget->type == GADGET_FILE) { - - } else if (box->text && box->font) { - PangoContext *context; - PangoLayout *layout; - GdkColor colour = { 0, - ((box->style->color & 0xff) << 8) | - (box->style->color & 0xff), - (box->style->color & 0xff00) | - (box->style->color & 0xff00 >> 8), - ((box->style->color & 0xff0000) >> 8) | - (box->style->color & 0xff0000 >> 16) }; - - context = gtk_widget_get_pango_context(current_widget); - layout = pango_layout_new(context); - pango_layout_set_font_description(layout, - (const PangoFontDescription *)box->font->id); - pango_layout_set_text(layout, box->text, box->length); - - gdk_draw_layout_with_colors(current_drawable, current_gc, - x, y, layout, &colour, 0); - - g_object_unref(layout); - - } else { - for (c = box->children; c; c = c->next) - if (c->type != BOX_FLOAT_LEFT && c->type != BOX_FLOAT_RIGHT) - html_redraw_box(content, c, x, y); - - for (c = box->float_children; c; c = c->next_float) - html_redraw_box(content, c, x, y); - } -}