gimp/app/display/gimpdisplayshell-style.c
Michael Natterer 3e1b14fd1a app: add widgets/gimpcairo.[ch] for cairo utility functions
and move the stipple pattern creation function there.
2010-08-27 14:41:30 +02:00

278 lines
8.6 KiB
C

/* 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 <string.h>
#include <gegl.h>
#include <gtk/gtk.h>
#include "libgimpcolor/gimpcolor.h"
#include "libgimpwidgets/gimpwidgets.h"
#include "display-types.h"
#include "core/gimpcontext.h"
#include "core/gimpgrid.h"
#include "core/gimplayermask.h"
#include "widgets/gimpcairo.h"
#include "gimpdisplayshell.h"
#include "gimpdisplayshell-style.h"
static const GimpRGB guide_normal_fg = { 0.0, 0.0, 0.0, 1.0 };
static const GimpRGB guide_normal_bg = { 0.0, 0.5, 1.0, 1.0 };
static const GimpRGB guide_active_fg = { 0.0, 0.0, 0.0, 1.0 };
static const GimpRGB guide_active_bg = { 1.0, 0.0, 0.0, 1.0 };
static const GimpRGB sample_point_normal = { 0.0, 0.5, 1.0, 1.0 };
static const GimpRGB sample_point_active = { 1.0, 0.0, 0.0, 1.0 };
static const GimpRGB layer_fg = { 0.0, 0.0, 0.0, 1.0 };
static const GimpRGB layer_bg = { 1.0, 1.0, 0.0, 1.0 };
static const GimpRGB layer_group_fg = { 0.0, 0.0, 0.0, 1.0 };
static const GimpRGB layer_group_bg = { 0.0, 1.0, 1.0, 1.0 };
static const GimpRGB layer_mask_fg = { 0.0, 0.0, 0.0, 1.0 };
static const GimpRGB layer_mask_bg = { 0.0, 1.0, 0.0, 1.0 };
static const GimpRGB selection_out_fg = { 1.0, 1.0, 1.0, 1.0 };
static const GimpRGB selection_out_bg = { 0.5, 0.5, 0.5, 1.0 };
static const GimpRGB selection_in_fg = { 0.0, 0.0, 0.0, 1.0 };
static const GimpRGB selection_in_bg = { 1.0, 1.0, 1.0, 1.0 };
/* public functions */
void
gimp_display_shell_set_guide_style (GimpDisplayShell *shell,
cairo_t *cr,
gboolean active)
{
cairo_pattern_t *pattern;
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
g_return_if_fail (cr != NULL);
cairo_set_line_width (cr, 1.0);
if (active)
pattern = gimp_cairo_stipple_pattern_create (&guide_active_fg,
&guide_active_bg,
0);
else
pattern = gimp_cairo_stipple_pattern_create (&guide_normal_fg,
&guide_normal_bg,
0);
cairo_set_source (cr, pattern);
cairo_pattern_destroy (pattern);
}
void
gimp_display_shell_set_sample_point_style (GimpDisplayShell *shell,
cairo_t *cr,
gboolean active)
{
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
g_return_if_fail (cr != NULL);
cairo_set_line_width (cr, 1.0);
if (active)
cairo_set_source_rgb (cr,
sample_point_active.r,
sample_point_active.g,
sample_point_active.b);
else
cairo_set_source_rgb (cr,
sample_point_normal.r,
sample_point_normal.g,
sample_point_normal.b);
}
void
gimp_display_shell_set_grid_style (GimpDisplayShell *shell,
cairo_t *cr,
GimpGrid *grid)
{
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
g_return_if_fail (cr != NULL);
g_return_if_fail (GIMP_IS_GRID (grid));
cairo_set_line_width (cr, 1.0);
switch (grid->style)
{
cairo_pattern_t *pattern;
case GIMP_GRID_ON_OFF_DASH:
case GIMP_GRID_DOUBLE_DASH:
if (grid->style == GIMP_GRID_DOUBLE_DASH)
{
pattern = gimp_cairo_stipple_pattern_create (&grid->fgcolor,
&grid->bgcolor,
0);
}
else
{
GimpRGB bg = { 0.0, 0.0, 0.0, 0.0 };
pattern = gimp_cairo_stipple_pattern_create (&grid->fgcolor,
&bg,
0);
}
cairo_set_source (cr, pattern);
cairo_pattern_destroy (pattern);
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;
}
}
void
gimp_display_shell_set_cursor_style (GimpDisplayShell *shell,
cairo_t *cr)
{
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
g_return_if_fail (cr != NULL);
cairo_set_line_width (cr, 1.0);
cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
}
void
gimp_display_shell_set_pen_style (GimpDisplayShell *shell,
cairo_t *cr,
GimpContext *context,
GimpActiveColor active,
gint width)
{
GimpRGB rgb;
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
g_return_if_fail (cr != NULL);
g_return_if_fail (GIMP_IS_CONTEXT (context));
cairo_set_antialias (cr, CAIRO_ANTIALIAS_NONE);
cairo_set_line_width (cr, width);
cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND);
switch (active)
{
case GIMP_ACTIVE_COLOR_FOREGROUND:
gimp_context_get_foreground (context, &rgb);
break;
case GIMP_ACTIVE_COLOR_BACKGROUND:
gimp_context_get_background (context, &rgb);
break;
}
cairo_set_source_rgb (cr, rgb.r, rgb.g, rgb.b);
}
void
gimp_display_shell_set_layer_style (GimpDisplayShell *shell,
cairo_t *cr,
GimpDrawable *drawable)
{
cairo_pattern_t *pattern;
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
g_return_if_fail (cr != NULL);
g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
cairo_set_line_width (cr, 1.0);
if (GIMP_IS_LAYER_MASK (drawable))
{
pattern = gimp_cairo_stipple_pattern_create (&layer_mask_fg,
&layer_mask_bg,
0);
}
else if (gimp_viewable_get_children (GIMP_VIEWABLE (drawable)))
{
pattern = gimp_cairo_stipple_pattern_create (&layer_group_fg,
&layer_group_bg,
0);
}
else
{
pattern = gimp_cairo_stipple_pattern_create (&layer_fg,
&layer_bg,
0);
}
cairo_set_source (cr, pattern);
cairo_pattern_destroy (pattern);
}
void
gimp_display_shell_set_selection_out_style (GimpDisplayShell *shell,
cairo_t *cr)
{
cairo_pattern_t *pattern;
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
g_return_if_fail (cr != NULL);
cairo_set_line_width (cr, 1.0);
pattern = gimp_cairo_stipple_pattern_create (&selection_out_fg,
&selection_out_bg,
0);
cairo_set_source (cr, pattern);
cairo_pattern_destroy (pattern);
}
void
gimp_display_shell_set_selection_in_style (GimpDisplayShell *shell,
cairo_t *cr,
gint index)
{
cairo_pattern_t *pattern;
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
g_return_if_fail (cr != NULL);
cairo_set_line_width (cr, 1.0);
pattern = gimp_cairo_stipple_pattern_create (&selection_in_fg,
&selection_in_bg,
index);
cairo_set_source (cr, pattern);
cairo_pattern_destroy (pattern);
}