Commit 002003a2 authored by Michael Natterer's avatar Michael Natterer 😴

app: add new files gimpdisplayshell-style.[ch]

which contains functions to set styles on a cairo_t.
parent 1a609d63
......@@ -71,6 +71,8 @@ libappdisplay_a_sources = \
gimpdisplayshell-scroll.h \
gimpdisplayshell-selection.c \
gimpdisplayshell-selection.h \
gimpdisplayshell-style.c \
gimpdisplayshell-style.h \
gimpdisplayshell-title.c \
gimpdisplayshell-title.h \
gimpdisplayshell-transform.c \
......
......@@ -21,7 +21,6 @@
#include <gtk/gtk.h>
#include "libgimpbase/gimpbase.h"
#include "libgimpcolor/gimpcolor.h"
#include "libgimpmath/gimpmath.h"
#include "libgimpwidgets/gimpwidgets.h"
......@@ -52,17 +51,15 @@
#include "gimpdisplayshell-render.h"
#include "gimpdisplayshell-scale.h"
#include "gimpdisplayshell-scroll.h"
#include "gimpdisplayshell-style.h"
#include "gimpdisplayshell-transform.h"
/* local function prototypes */
static void gimp_display_shell_set_grid_style (GimpDisplayShell *shell,
GimpGrid *grid,
cairo_t *cr);
static GdkGC * gimp_display_shell_get_pen_gc (GimpDisplayShell *shell,
GimpContext *context,
GimpActiveColor active);
static GdkGC * gimp_display_shell_get_pen_gc (GimpDisplayShell *shell,
GimpContext *context,
GimpActiveColor active);
/* public functions */
......@@ -690,73 +687,6 @@ gimp_display_shell_draw_area (GimpDisplayShell *shell,
/* private functions */
static void
gimp_display_shell_set_grid_style (GimpDisplayShell *shell,
GimpGrid *grid,
cairo_t *cr)
{
cairo_set_line_width (cr, 1.0);
switch (grid->style)
{
case GIMP_GRID_ON_OFF_DASH:
case GIMP_GRID_DOUBLE_DASH:
{
guchar *data = g_malloc0 (8 * 8 * 4);
guchar fg_r, fg_g, fg_b, fg_a;
guchar bg_r, bg_g, bg_b, bg_a;
gint x, y;
guchar *d;
cairo_surface_t *surface;
static cairo_user_data_key_t data_key;
gimp_rgba_get_uchar (&grid->fgcolor, &fg_r, &fg_g, &fg_b, &fg_a);
if (grid->style == GIMP_GRID_DOUBLE_DASH)
gimp_rgba_get_uchar (&grid->bgcolor, &bg_r, &bg_g, &bg_b, &bg_a);
else
bg_r = bg_g = bg_b = bg_a = 0;
d = data;
for (y = 0; y < 8; y++)
{
for (x = 0; x < 8; x++)
{
if ((y < 4 && x < 4) || (y >= 4 && x >= 4))
GIMP_CAIRO_ARGB32_SET_PIXEL (d, fg_r, fg_g, fg_b, fg_a);
else
GIMP_CAIRO_ARGB32_SET_PIXEL (d, bg_r, bg_g, bg_b, bg_a);
d += 4;
}
}
surface = cairo_image_surface_create_for_data (data,
CAIRO_FORMAT_ARGB32,
8, 8, 8 * 4);
cairo_surface_set_user_data (surface, &data_key,
data, (cairo_destroy_func_t) g_free);
cairo_set_source_surface (cr, surface, 0, 0);
cairo_surface_destroy (surface);
cairo_pattern_set_extend (cairo_get_source (cr),
CAIRO_EXTEND_REPEAT);
}
break;
case GIMP_GRID_DOTS:
case GIMP_GRID_INTERSECTIONS:
case GIMP_GRID_SOLID:
cairo_set_source_rgb (cr,
grid->fgcolor.r,
grid->fgcolor.g,
grid->fgcolor.b);
break;
}
}
static GdkGC *
gimp_display_shell_get_pen_gc (GimpDisplayShell *shell,
GimpContext *context,
......
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimpdisplayshell-style.c
* Copyright (C) 2010 Michael Natterer <mitch@gimp.org>
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <gegl.h>
#include <gtk/gtk.h>
#include "libgimpcolor/gimpcolor.h"
#include "libgimpwidgets/gimpwidgets.h"
#include "display-types.h"
#include "core/gimpgrid.h"
#include "gimpdisplayshell.h"
#include "gimpdisplayshell-style.h"
void
gimp_display_shell_set_grid_style (GimpDisplayShell *shell,
GimpGrid *grid,
cairo_t *cr)
{
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
g_return_if_fail (GIMP_IS_GRID (grid));
g_return_if_fail (cr != NULL);
cairo_set_line_width (cr, 1.0);
switch (grid->style)
{
case GIMP_GRID_ON_OFF_DASH:
case GIMP_GRID_DOUBLE_DASH:
{
guchar *data = g_malloc0 (8 * 8 * 4);
guchar fg_r, fg_g, fg_b, fg_a;
guchar bg_r, bg_g, bg_b, bg_a;
gint x, y;
guchar *d;
cairo_surface_t *surface;
static cairo_user_data_key_t data_key;
gimp_rgba_get_uchar (&grid->fgcolor, &fg_r, &fg_g, &fg_b, &fg_a);
if (grid->style == GIMP_GRID_DOUBLE_DASH)
gimp_rgba_get_uchar (&grid->bgcolor, &bg_r, &bg_g, &bg_b, &bg_a);
else
bg_r = bg_g = bg_b = bg_a = 0;
d = data;
for (y = 0; y < 8; y++)
{
for (x = 0; x < 8; x++)
{
if ((y < 4 && x < 4) || (y >= 4 && x >= 4))
GIMP_CAIRO_ARGB32_SET_PIXEL (d, fg_r, fg_g, fg_b, fg_a);
else
GIMP_CAIRO_ARGB32_SET_PIXEL (d, bg_r, bg_g, bg_b, bg_a);
d += 4;
}
}
surface = cairo_image_surface_create_for_data (data,
CAIRO_FORMAT_ARGB32,
8, 8, 8 * 4);
cairo_surface_set_user_data (surface, &data_key,
data, (cairo_destroy_func_t) g_free);
cairo_set_source_surface (cr, surface, 0, 0);
cairo_surface_destroy (surface);
cairo_pattern_set_extend (cairo_get_source (cr),
CAIRO_EXTEND_REPEAT);
}
break;
case GIMP_GRID_DOTS:
case GIMP_GRID_INTERSECTIONS:
case GIMP_GRID_SOLID:
cairo_set_source_rgb (cr,
grid->fgcolor.r,
grid->fgcolor.g,
grid->fgcolor.b);
break;
}
}
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimpdisplayshell-style.h
* Copyright (C) 2010 Michael Natterer <mitch@gimp.org>
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*/
#ifndef __GIMP_DISPLAY_SHELL_STYLE_H__
#define __GIMP_DISPLAY_SHELL_STYLE_H__
void gimp_display_shell_set_grid_style (GimpDisplayShell *shell,
GimpGrid *grid,
cairo_t *cr);
#endif /* __GIMP_DISPLAY_SHELL_STYLE_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