Verified Commit af3c7836 authored by Zander's avatar Zander 💥

Remove render_pixmap

Use cairo for arrow previews
parent 65917987
......@@ -28,7 +28,7 @@
#include "intl.h"
#include "widgets.h"
#include "diaarrowchooser.h"
#include "render_pixmap.h"
#include "renderer/diacairo.h"
static const char *button_menu_key = "dia-button-menu";
static const char *menuitem_enum_key = "dia-menuitem-value";
......@@ -166,7 +166,7 @@ dia_arrow_preview_expose(GtkWidget *widget, GdkEventExpose *event)
#endif
Point from, to;
Point move_arrow, move_line, arrow_head;
DiaRenderer *renderer;
DiaCairoRenderer *renderer;
DiaArrowPreview *arrow = DIA_ARROW_PREVIEW(widget);
Arrow arrow_type;
GtkMisc *misc = GTK_MISC(widget);
......@@ -175,6 +175,8 @@ dia_arrow_preview_expose(GtkWidget *widget, GdkEventExpose *event)
GdkWindow *win;
int linewidth = 2;
DiaRendererClass *renderer_ops;
cairo_surface_t *surface;
cairo_t *ctx;
width = widget->allocation.width - misc->xpad * 2;
height = widget->allocation.height - misc->ypad * 2;
......@@ -207,37 +209,37 @@ dia_arrow_preview_expose(GtkWidget *widget, GdkEventExpose *event)
point_add(&arrow_head, &move_arrow);
point_add(&to, &move_line);
renderer = new_pixmap_renderer(win, width, height);
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height);
renderer = g_object_new (dia_cairo_renderer_get_type (), NULL);
renderer->with_alpha = TRUE;
renderer->surface = cairo_surface_reference (surface);
renderer_ops = DIA_RENDERER_GET_CLASS (renderer);
renderer_pixmap_set_pixmap(renderer, win, x, y, width, height);
renderer_ops->begin_render(renderer, NULL);
renderer_ops->set_linewidth(renderer, linewidth);
renderer_ops->begin_render(DIA_RENDERER (renderer), NULL);
renderer_ops->set_linewidth(DIA_RENDERER (renderer), linewidth);
{
Color color_bg, color_fg;
GtkStyle *style = gtk_widget_get_style (widget);
/* the text colors are the best approximation to what we had */
#if GTK_CHECK_VERSION(2,18,0)
GdkColor bg = style->base[gtk_widget_get_state(widget)];
#else
GdkColor bg = style->base[GTK_WIDGET_STATE(widget)];
#endif
#if GTK_CHECK_VERSION(2,18,0)
GdkColor fg = style->text[gtk_widget_get_state(widget)];
#else
GdkColor fg = style->text[GTK_WIDGET_STATE(widget)];
#endif
GDK_COLOR_TO_DIA(bg, color_bg);
GDK_COLOR_TO_DIA(fg, color_fg);
renderer_ops->draw_line(renderer, &from, &to, &color_fg);
arrow_draw (renderer, arrow_type.type,
renderer_ops->draw_line(DIA_RENDERER (renderer), &from, &to, &color_fg);
arrow_draw (DIA_RENDERER (renderer), arrow_type.type,
&arrow_head, &from,
arrow_type.length,
arrow_type.width,
linewidth, &color_fg, &color_bg);
}
renderer_ops->end_render(renderer);
renderer_ops->end_render(DIA_RENDERER (renderer));
g_object_unref(renderer);
ctx = gdk_cairo_create (win);
cairo_set_source_surface (ctx, surface, x, y);
cairo_paint (ctx);
}
return TRUE;
......
/* Dia -- an diagram creation/manipulation program
* Copyright (C) 1998 Alexander Larsson
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/* This renderer is similar to RenderGdk, except that it renders onto
* its own little GdkPixmap, doesn't deal with the DDisplay at all, and
* uses a 1-1 mapping between points and pixels. It is used for rendering
* arrows and lines onto selectors. This way, any change in the arrow
* definitions are automatically reflected in the selectors.
*/
/*
* 2002-10-06 : Leaved the original comment but removed almost
* anything else. The 'RendererPixmap' now uses the DiaGdkRenderer which
* is the ported to GObject 'RendererGdk'. No more huge code duplication
* but only some renderer parametrization tweaking. --hb
*/
#include <config.h>
#include <math.h>
#include <stdlib.h>
#include <gdk/gdk.h>
#include "render_pixmap.h"
#include "message.h"
#include "diagdkrenderer.h"
static Rectangle rect;
static real zoom = 1.0;
DiaRenderer *
new_pixmap_renderer(GdkWindow *window, int width, int height)
{
DiaGdkRenderer *renderer;
GdkColor color;
rect.left = 0;
rect.top = 0;
rect.right = width;
rect.bottom = height;
renderer = g_object_new (DIA_TYPE_GDK_RENDERER, NULL);
renderer->transform = dia_transform_new (&rect, &zoom);
renderer->pixmap = gdk_pixmap_new(window, width, height, -1);
renderer->gc = gdk_gc_new(window);
gdk_color_white(gdk_colormap_get_system(), &color);
gdk_gc_set_foreground(renderer->gc, &color);
gdk_draw_rectangle(renderer->pixmap, renderer->gc, 1,
0, 0, width, height);
return DIA_RENDERER(renderer);
}
void
renderer_pixmap_set_pixmap (DiaRenderer *ren,
GdkDrawable *drawable,
int xoffset, int yoffset,
int width, int height)
{
DiaGdkRenderer *renderer = DIA_GDK_RENDERER (ren);
if (renderer->pixmap != NULL)
g_object_unref(renderer->pixmap);
if (renderer->gc != NULL)
g_object_unref(renderer->gc);
g_object_ref(drawable);
renderer->pixmap = drawable;
renderer->gc = gdk_gc_new(drawable);
rect.left = -xoffset;
rect.top = -yoffset;
rect.right = width;
rect.bottom = height;
}
GdkPixmap *
renderer_pixmap_get_pixmap (DiaRenderer *ren)
{
DiaGdkRenderer *renderer = DIA_GDK_RENDERER (ren);
return renderer->pixmap;
}
/* Dia -- an diagram creation/manipulation program
* Copyright (C) 1998 Alexander Larsson
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef RENDER_PIXMAP_H
#define RENDER_PIXMAP_H
#include "diarenderer.h"
DiaRenderer *new_pixmap_renderer(GdkWindow *window, int width, int height);
void renderer_pixmap_set_pixmap(DiaRenderer *renderer,
GdkDrawable *drawable,
int xoffset, int yoffset,
int width, int height);
GdkPixmap *renderer_pixmap_get_pixmap(DiaRenderer *renderer);
#endif /* RENDER_PIXMAP_H */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment