#include <cairo.h>
#include <gtk/gtk.h>
#include <math.h>
static void
draw_round_rectangle (cairo_t * cr,
double x, double y,
double width, double height, double r)
{
cairo_move_to (cr, x + r, y);
cairo_line_to (cr, x + width - r, y);
cairo_move_to (cr, x + width, y + r);
cairo_line_to (cr, x + width, y + height - r);
cairo_move_to (cr, x + width - r, y + height);
cairo_line_to (cr, x + r, y + height);
cairo_move_to (cr, x, y + height - r);
cairo_line_to (cr, x, y + r);
cairo_arc (cr, x + r, y + r, r, M_PI, 3 * M_PI / 2.0);
cairo_arc (cr, x + width - r, y + r, r, 3 * M_PI / 2, 2 * M_PI);
cairo_arc (cr, x + width - r, y + height - r, r, 0, M_PI / 2);
cairo_arc (cr, x + r, y + height - r, r, M_PI / 2, M_PI);
}
gboolean on_expose_event (GtkWidget *widget, GdkEventExpose *event, cairo_surface_t *bg)
{
cairo_t *cr;
cairo_pattern_t *pattern;
pattern = cairo_pattern_create_for_surface (bg);
cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT);
cr = gdk_cairo_create (widget->window);
cairo_set_source (cr, pattern);
cairo_paint (cr);
cairo_pattern_destroy (pattern);
cairo_destroy (cr);
return FALSE;
}
typedef struct _ImageButtonPrivate ImageButtonPrivate;
typedef struct _GroupWidget GroupWidget;
struct _ImageButtonPrivate
{
gboolean hovered;
gboolean activated;
int id;
GroupWidget *group;
};
struct _Group
GTK 背景透明button (GtkImage + EventBox)
最新推荐文章于 2021-06-03 18:28:45 发布