[dia/dia-next: 20/59] Start updating the canvas
- From: Zander <zbrown src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dia/dia-next: 20/59] Start updating the canvas
- Date: Wed, 9 Jan 2019 18:35:58 +0000 (UTC)
commit bc973d858d26990ddbdd0a4549543e26e24d7980
Author: Zander Brown <zbrown gnome org>
Date: Sun Dec 23 19:50:50 2018 +0000
Start updating the canvas
app/disp_callbacks.c | 68 ++++++++++++++--------------
app/display.c | 19 +++++---
app/interface.c | 90 ++++++++++++++++++++++++++++++++-----
app/menus.c | 2 +-
lib/diarenderer.h | 2 +-
lib/renderer/diacairo-interactive.c | 18 ++++----
6 files changed, 135 insertions(+), 64 deletions(-)
---
diff --git a/app/disp_callbacks.c b/app/disp_callbacks.c
index e1af3f9b..68471039 100644
--- a/app/disp_callbacks.c
+++ b/app/disp_callbacks.c
@@ -102,7 +102,7 @@ static void
dia_menu_free(DiaMenu *dia_menu)
{
if (dia_menu->app_data)
- g_object_destroy((GObject *)dia_menu->app_data);
+ g_object_unref((GObject *)dia_menu->app_data);
dia_menu->app_data = NULL;
dia_menu->app_data_free = NULL;
}
@@ -642,19 +642,19 @@ static void
_scroll_step (DDisplay *ddisp, guint keyval)
{
switch (keyval) {
- case GDK_Up :
+ case GDK_KEY_Up :
ddisplay_scroll_up(ddisp);
ddisplay_flush(ddisp);
break;
- case GDK_Down:
+ case GDK_KEY_Down:
ddisplay_scroll_down(ddisp);
ddisplay_flush(ddisp);
break;
- case GDK_Left:
+ case GDK_KEY_Left:
ddisplay_scroll_left(ddisp);
ddisplay_flush(ddisp);
break;
- case GDK_Right:
+ case GDK_KEY_Right:
ddisplay_scroll_right(ddisp);
ddisplay_flush(ddisp);
break;
@@ -924,12 +924,12 @@ ddisplay_canvas_events (GtkWidget *canvas,
GTK_IM_CONTEXT(ddisp->im_context), kevent)) {
switch (kevent->keyval) {
- case GDK_Tab:
+ case GDK_KEY_Tab:
focus = textedit_move_focus(ddisp, focus,
(state & GDK_SHIFT_MASK) == 0);
obj = focus_get_object(focus);
break;
- case GDK_Escape:
+ case GDK_KEY_Escape:
textedit_deactivate_focus();
tool_reset ();
ddisplay_do_update_menu_sensitivity(ddisp);
@@ -957,15 +957,15 @@ ddisplay_canvas_events (GtkWidget *canvas,
return_val = TRUE;
switch(kevent->keyval) {
- case GDK_Home :
- case GDK_KP_Home :
+ case GDK_KEY_Home :
+ case GDK_KEY_KP_Home :
/* match upper left corner of the diagram with it's view */
ddisplay_set_origo(ddisp, ddisp->diagram->data->extents.left,
ddisp->diagram->data->extents.top);
ddisplay_update_scrollbars(ddisp);
ddisplay_add_update_all(ddisp);
break;
- case GDK_End :
- case GDK_KP_End :
+ case GDK_KEY_End :
+ case GDK_KEY_KP_End :
/* match lower right corner of the diagram with it's view */
visible = &ddisp->visible;
ddisplay_set_origo(ddisp,
@@ -974,24 +974,24 @@ ddisplay_canvas_events (GtkWidget *canvas,
ddisplay_update_scrollbars(ddisp);
ddisplay_add_update_all(ddisp);
break;
- case GDK_Page_Up :
- case GDK_KP_Page_Up :
+ case GDK_KEY_Page_Up :
+ case GDK_KEY_KP_Page_Up :
_scroll_page (ddisp, !(state & GDK_CONTROL_MASK) ? DIR_UP : DIR_LEFT);
break;
- case GDK_Page_Down :
- case GDK_KP_Page_Down :
+ case GDK_KEY_Page_Down :
+ case GDK_KEY_KP_Page_Down :
_scroll_page (ddisp, !(state & GDK_CONTROL_MASK) ? DIR_DOWN : DIR_RIGHT);
break;
- case GDK_Up:
- case GDK_Down:
- case GDK_Left:
- case GDK_Right:
+ case GDK_KEY_Up:
+ case GDK_KEY_Down:
+ case GDK_KEY_Left:
+ case GDK_KEY_Right:
if (g_list_length (ddisp->diagram->data->selected) > 0) {
Diagram *dia = ddisp->diagram;
GList *objects = dia->data->selected;
- Direction dir = GDK_Up == kevent->keyval ? DIR_UP :
- GDK_Down == kevent->keyval ? DIR_DOWN :
- GDK_Right == kevent->keyval ? DIR_RIGHT : DIR_LEFT;
+ Direction dir = GDK_KEY_Up == kevent->keyval ? DIR_UP :
+ GDK_KEY_Down == kevent->keyval ? DIR_DOWN :
+ GDK_KEY_Right == kevent->keyval ? DIR_RIGHT : DIR_LEFT;
object_add_updates_list(objects, dia);
object_list_nudge(objects, dia, dir,
/* step one pixel or more with <ctrl> */
@@ -1006,27 +1006,27 @@ ddisplay_canvas_events (GtkWidget *canvas,
_scroll_step (ddisp, kevent->keyval);
}
break;
- case GDK_KP_Add:
- case GDK_plus:
+ case GDK_KEY_KP_Add:
+ case GDK_KEY_plus:
ddisplay_zoom_middle(ddisp, M_SQRT2);
break;
- case GDK_KP_Subtract:
- case GDK_minus:
+ case GDK_KEY_KP_Subtract:
+ case GDK_KEY_minus:
ddisplay_zoom_middle(ddisp, M_SQRT1_2);
break;
- case GDK_Shift_L:
- case GDK_Shift_R:
+ case GDK_KEY_Shift_L:
+ case GDK_KEY_Shift_R:
if (active_tool->type == MAGNIFY_TOOL)
set_zoom_out(active_tool);
break;
- case GDK_Escape:
+ case GDK_KEY_Escape:
view_unfullscreen();
break;
- case GDK_F2:
- case GDK_Return:
+ case GDK_KEY_F2:
+ case GDK_KEY_Return:
gtk_action_activate (menus_get_action ("ToolsTextedit"));
break;
- case GDK_Menu:
+ case GDK_KEY_Menu:
popup_object_menu (ddisp, event);
break;
default:
@@ -1051,8 +1051,8 @@ ddisplay_canvas_events (GtkWidget *canvas,
return_val = TRUE;
} else {
switch(kevent->keyval) {
- case GDK_Shift_L:
- case GDK_Shift_R:
+ case GDK_KEY_Shift_L:
+ case GDK_KEY_Shift_R:
if (active_tool->type == MAGNIFY_TOOL)
set_zoom_in(active_tool);
break;
diff --git a/app/display.c b/app/display.c
index ff5e9fe3..b44700b0 100644
--- a/app/display.c
+++ b/app/display.c
@@ -578,8 +578,9 @@ ddisplay_flush(DDisplay *ddisp)
* GTK_PRIORITY_RESIZE = (G_PRIORITY_HIGH_IDLE + 10)
* Dia's canvas rendering is in between
*/
- if (!ddisp->update_id)
- ddisp->update_id = g_idle_add_full (G_PRIORITY_HIGH_IDLE+15, (GSourceFunc)ddisplay_update_handler,
ddisp, NULL);
+ /*if (!ddisp->update_id)
+ ddisp->update_id = g_idle_add_full (G_PRIORITY_HIGH_IDLE+15, (GSourceFunc)ddisplay_update_handler,
ddisp, NULL);*/
+ gtk_widget_queue_draw (ddisp->canvas);
if (ddisp->display_areas) {
IRectangle *r = (IRectangle *)ddisp->display_areas->data;
dia_log_message ("DispUpdt: %4d,%3d - %4d,%3d\n", r->left, r->top, r->right, r->bottom);
@@ -883,14 +884,16 @@ ddisplay_autoscroll(DDisplay *ddisp, int x, int y)
{
guint16 width, height;
Point scroll;
+ GtkAllocation alloc;
if (! ddisp->autoscroll)
return FALSE;
scroll.x = scroll.y = 0;
- width = GTK_WIDGET(ddisp->canvas)->allocation.width;
- height = GTK_WIDGET(ddisp->canvas)->allocation.height;
+ gtk_widget_get_allocation (GTK_WIDGET (ddisp->canvas), &alloc);
+ width = alloc.width;
+ height = alloc.height;
if (x < 0)
{
@@ -1095,6 +1098,7 @@ ddisplay_set_renderer(DDisplay *ddisp, int aa_renderer)
{
int width, height;
GdkWindow *window = gtk_widget_get_window(ddisp->canvas);
+ GtkAllocation alloc;
/* dont mix new renderer with old updates */
if (ddisp->update_id) {
@@ -1107,8 +1111,9 @@ ddisplay_set_renderer(DDisplay *ddisp, int aa_renderer)
ddisp->aa_renderer = aa_renderer;
- width = ddisp->canvas->allocation.width;
- height = ddisp->canvas->allocation.height;
+ gtk_widget_get_allocation (GTK_WIDGET (ddisp->canvas), &alloc);
+ width = alloc.width;
+ height = alloc.height;
if (!ddisp->aa_renderer){
g_message ("Only antialias renderers supported");
@@ -1588,7 +1593,7 @@ ddisplay_im_context_preedit_reset(DDisplay *ddisp, Focus *focus)
ObjectChange *change;
for (i = 0; i < g_utf8_strlen(ddisp->preedit_string, -1); i++) {
- (focus->key_event)(focus, 0, GDK_BackSpace, NULL, 0, &change);
+ (focus->key_event)(focus, 0, GDK_KEY_BackSpace, NULL, 0, &change);
}
}
diff --git a/app/interface.c b/app/interface.c
index 4bf12676..0457d365 100644
--- a/app/interface.c
+++ b/app/interface.c
@@ -391,15 +391,83 @@ canvas_configure_event (GtkWidget *widget,
* Gone with gtk+-3.0 or better replaced by "draw".
*/
static gboolean
-canvas_expose_event (GtkWidget *widget,
- GdkEventExpose *event,
- DDisplay *ddisp)
+canvas_draw (GtkWidget *widget,
+ cairo_t *ctx,
+ DDisplay *ddisp)
{
+ GSList *l;
+ Rectangle *r, totrect;
+ DiaInteractiveRendererInterface *renderer;
+
+ /* Add all the area (hangover from expose) */
ddisplay_add_display_area (ddisp,
- event->area.x, event->area.y,
- event->area.x + event->area.width,
- event->area.y + event->area.height);
- ddisplay_flush(ddisp);
+ 0, 0,
+ gtk_widget_get_allocated_width (widget),
+ gtk_widget_get_allocated_height (widget));
+
+ g_return_val_if_fail (ddisp->renderer != NULL, FALSE);
+
+ /* Renders updates to pixmap + copies display_areas to canvas(screen) */
+ renderer = DIA_GET_INTERACTIVE_RENDERER_INTERFACE (ddisp->renderer);
+
+ /* Only update if update_areas exist */
+ l = ddisp->update_areas;
+ if (l != NULL)
+ {
+ totrect = *(Rectangle *) l->data;
+
+ g_return_val_if_fail ( renderer->clip_region_clear != NULL
+ && renderer->clip_region_add_rect != NULL, FALSE);
+
+ renderer->clip_region_clear (ddisp->renderer);
+
+ while(l!=NULL) {
+ r = (Rectangle *) l->data;
+
+ rectangle_union(&totrect, r);
+ renderer->clip_region_add_rect (ddisp->renderer, r);
+
+ l = g_slist_next(l);
+ }
+ /* Free update_areas list: */
+ l = ddisp->display_areas;
+ while(l!=NULL) {
+ g_free(l->data);
+ l = g_slist_next(l);
+ }
+ g_slist_free(ddisp->display_areas);
+ ddisp->display_areas = NULL;
+
+ totrect.left -= 0.1;
+ totrect.right += 0.1;
+ totrect.top -= 0.1;
+ totrect.bottom += 0.1;
+
+ ddisplay_render_pixmap(ddisp, &totrect);
+ }
+
+ l = ddisp->display_areas;
+ while(l!=NULL) {
+ g_return_val_if_fail (renderer->copy_to_window, FALSE);
+ renderer->copy_to_window(ddisp->renderer,
+ ctx,
+ 0, 0,
+ gtk_widget_get_allocated_width (widget),
+ gtk_widget_get_allocated_height (widget));
+
+ l = g_slist_next(l);
+ }
+
+ l = ddisp->display_areas;
+ while(l!=NULL) {
+ g_free(l->data);
+ l = g_slist_next(l);
+ }
+ g_slist_free(ddisp->display_areas);
+ ddisp->display_areas = NULL;
+
+ ddisp->update_id = 0;
+
return FALSE;
}
@@ -419,8 +487,8 @@ create_canvas (DDisplay *ddisp)
GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK);
g_signal_connect (G_OBJECT (canvas), "configure-event",
G_CALLBACK (canvas_configure_event), ddisp);
- g_signal_connect (G_OBJECT (canvas), "expose-event",
- G_CALLBACK (canvas_expose_event), ddisp);
+ g_signal_connect (G_OBJECT (canvas), "draw",
+ G_CALLBACK (canvas_draw), ddisp);
#if GTK_CHECK_VERSION(2,18,0)
gtk_widget_set_can_focus (canvas, TRUE);
#else
@@ -827,7 +895,7 @@ create_display_shell(DDisplay *ddisp,
gtk_widget_show (ddisp->shell);
/* before showing up, checking canvas's REAL size */
- if (use_mbar && ddisp->hrule->allocation.width > width)
+ if (use_mbar && gtk_widget_get_allocated_width (ddisp->hrule) > width)
{
/* The menubar is not shrinkable, so the shell will have at least
* the menubar's width. If the diagram's requested width is smaller,
@@ -836,7 +904,7 @@ create_display_shell(DDisplay *ddisp,
* that will be allocated, which the same as the hrule got.
*/
- width = ddisp->hrule->allocation.width;
+ width = gtk_widget_get_allocated_width (ddisp->hrule);
gtk_adjustment_set_upper (ddisp->hsbdata, width);
gtk_adjustment_set_page_increment (ddisp->hsbdata, (width - 1) / 4);
diff --git a/app/menus.c b/app/menus.c
index b39bb73d..f0e243a9 100644
--- a/app/menus.c
+++ b/app/menus.c
@@ -54,7 +54,7 @@
#define DIA_STOCK_OBJECTS_LAYER_BELOW "dia-stock-objects-layer-below"
#define DIA_STOCK_LAYERS "dia-stock-layers"
-#define DIA_SHOW_TEAROFFS TRUE
+#define DIA_SHOW_TEAROFFS FALSE
/* Integrated UI Toolbar Constants */
#define DIA_INTEGRATED_TOOLBAR_ZOOM_COMBO "dia-integrated-toolbar-zoom-combo_entry"
diff --git a/lib/diarenderer.h b/lib/diarenderer.h
index a34cf078..2a4fc6c2 100644
--- a/lib/diarenderer.h
+++ b/lib/diarenderer.h
@@ -306,7 +306,7 @@ struct _DiaInteractiveRendererInterface
GdkRGBA *color);
/*! Copy already rendered content to the given window */
void (*copy_to_window) (DiaRenderer *renderer,
- gpointer window,
+ cairo_t *ctx,
int x, int y, int width, int height);
/*! Support for drawing selected objects highlighted */
void (*draw_object_highlighted) (DiaRenderer *renderer,
diff --git a/lib/renderer/diacairo-interactive.c b/lib/renderer/diacairo-interactive.c
index a728eac0..77e668c7 100644
--- a/lib/renderer/diacairo-interactive.c
+++ b/lib/renderer/diacairo-interactive.c
@@ -83,7 +83,7 @@ static void set_size (DiaRenderer *renderer,
gpointer window,
int width, int height);
static void copy_to_window (DiaRenderer *renderer,
- gpointer window,
+ cairo_t *ctx,
int x, int y, int width, int height);
static void cairo_interactive_renderer_get_property (GObject *object,
@@ -461,18 +461,16 @@ set_size(DiaRenderer *object, gpointer window,
}
static void
-copy_to_window (DiaRenderer *object, gpointer window,
+copy_to_window (DiaRenderer *object, cairo_t *ctx,
int x, int y, int width, int height)
{
DiaCairoInteractiveRenderer *renderer = DIA_CAIRO_INTERACTIVE_RENDERER (object);
- cairo_t *cr;
-
- cr = gdk_cairo_create (GDK_WINDOW(window));
- cairo_set_source_surface (cr, renderer->pixmap, 0.0, 0.0);
- cairo_rectangle (cr, x, y, width > 0 ? width : -width, height > 0 ? height : -height);
- cairo_clip (cr);
- cairo_paint (cr);
- cairo_destroy (cr);
+
+ cairo_set_source_surface (ctx, renderer->pixmap, 0.0, 0.0);
+ cairo_rectangle (ctx, x, y, width > 0 ? width : -width, height > 0 ? height : -height);
+ cairo_clip (ctx);
+ cairo_paint (ctx);
+ cairo_destroy (ctx);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]