2010-06-13 01:02:51 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* gimpoverlayframe.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
|
2018-07-12 05:27:07 +08:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2010-06-13 01:02:51 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2010-06-18 19:51:49 +08:00
|
|
|
#include "libgimpmath/gimpmath.h"
|
|
|
|
|
2010-06-13 01:02:51 +08:00
|
|
|
#include "widgets-types.h"
|
|
|
|
|
2018-03-07 22:21:08 +08:00
|
|
|
#include "core/gimp-cairo.h"
|
|
|
|
|
2010-06-13 01:02:51 +08:00
|
|
|
#include "gimpoverlayframe.h"
|
2010-06-18 19:51:49 +08:00
|
|
|
#include "gimpwidgets-utils.h"
|
2010-06-13 01:02:51 +08:00
|
|
|
|
|
|
|
|
2018-05-22 06:35:04 +08:00
|
|
|
static gboolean gimp_overlay_frame_draw (GtkWidget *widget,
|
|
|
|
cairo_t *cr);
|
2010-06-13 01:02:51 +08:00
|
|
|
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (GimpOverlayFrame, gimp_overlay_frame, GTK_TYPE_BIN)
|
|
|
|
|
|
|
|
#define parent_class gimp_overlay_frame_parent_class
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_overlay_frame_class_init (GimpOverlayFrameClass *klass)
|
|
|
|
{
|
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
|
|
|
|
2018-05-22 06:35:04 +08:00
|
|
|
widget_class->draw = gimp_overlay_frame_draw;
|
|
|
|
|
|
|
|
gtk_widget_class_set_css_name (widget_class, "popover");
|
2010-06-13 01:02:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_overlay_frame_init (GimpOverlayFrame *frame)
|
|
|
|
{
|
2010-06-13 05:38:13 +08:00
|
|
|
gtk_widget_set_app_paintable (GTK_WIDGET (frame), TRUE);
|
2010-06-13 01:23:22 +08:00
|
|
|
|
2018-05-22 06:35:04 +08:00
|
|
|
gtk_style_context_add_class (gtk_widget_get_style_context (GTK_WIDGET (frame)),
|
|
|
|
"background");
|
2010-06-13 01:23:22 +08:00
|
|
|
}
|
|
|
|
|
2010-06-13 01:02:51 +08:00
|
|
|
static gboolean
|
2010-10-20 01:11:06 +08:00
|
|
|
gimp_overlay_frame_draw (GtkWidget *widget,
|
|
|
|
cairo_t *cr)
|
2010-06-13 01:02:51 +08:00
|
|
|
{
|
2010-12-29 22:53:15 +08:00
|
|
|
GtkStyleContext *style = gtk_widget_get_style_context (widget);
|
|
|
|
GtkAllocation allocation;
|
|
|
|
gboolean rgba;
|
2018-05-22 06:35:04 +08:00
|
|
|
gint border_radius;
|
2010-06-13 01:02:51 +08:00
|
|
|
|
2010-10-20 01:11:06 +08:00
|
|
|
rgba = gdk_screen_get_rgba_visual (gtk_widget_get_screen (widget)) != NULL;
|
2011-03-19 05:57:13 +08:00
|
|
|
|
2010-06-13 05:38:13 +08:00
|
|
|
if (rgba)
|
|
|
|
{
|
|
|
|
cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
|
2011-03-19 05:57:13 +08:00
|
|
|
cairo_paint (cr);
|
|
|
|
cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
|
2010-06-13 05:38:13 +08:00
|
|
|
}
|
2010-06-13 01:02:51 +08:00
|
|
|
|
2011-03-19 05:57:13 +08:00
|
|
|
gtk_widget_get_allocation (widget, &allocation);
|
2018-05-22 06:35:04 +08:00
|
|
|
|
|
|
|
gtk_style_context_get (style, gtk_style_context_get_state (style),
|
|
|
|
"border-radius", &border_radius,
|
|
|
|
NULL);
|
2010-06-13 01:02:51 +08:00
|
|
|
|
2018-03-07 22:21:08 +08:00
|
|
|
if (rgba)
|
2010-06-13 05:38:13 +08:00
|
|
|
{
|
2018-03-07 22:21:08 +08:00
|
|
|
gimp_cairo_rounded_rectangle (cr,
|
|
|
|
0.0, 0.0,
|
|
|
|
allocation.width, allocation.height,
|
2018-05-22 06:35:04 +08:00
|
|
|
border_radius);
|
2011-03-19 05:57:13 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cairo_rectangle (cr, 0, 0, allocation.width, allocation.height);
|
2010-06-13 05:38:13 +08:00
|
|
|
}
|
2010-06-13 01:02:51 +08:00
|
|
|
|
2018-05-22 06:35:04 +08:00
|
|
|
cairo_clip (cr);
|
2010-06-18 19:51:49 +08:00
|
|
|
|
2018-05-22 06:35:04 +08:00
|
|
|
gtk_render_background (style, cr,
|
|
|
|
0, 0,
|
|
|
|
allocation.width,
|
|
|
|
allocation.height);
|
2010-06-18 19:51:49 +08:00
|
|
|
|
2018-05-22 06:35:04 +08:00
|
|
|
gtk_render_frame (style, cr,
|
|
|
|
0, 0,
|
|
|
|
allocation.width,
|
|
|
|
allocation.height);
|
2011-03-19 05:57:13 +08:00
|
|
|
|
2010-10-20 01:11:06 +08:00
|
|
|
return GTK_WIDGET_CLASS (parent_class)->draw (widget, cr);
|
2010-06-13 01:02:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
GtkWidget *
|
|
|
|
gimp_overlay_frame_new (void)
|
|
|
|
{
|
|
|
|
return g_object_new (GIMP_TYPE_OVERLAY_FRAME, NULL);
|
|
|
|
}
|