Browse Source

fix compilation with older rsvg

master
Alexandros Theodotou 3 years ago
parent
commit
30d51a15d0
Signed by: alex
GPG Key ID: 022EAE42313D70F3
  1. 15
      inc/ztoolkit/ztk_button.h
  2. 7
      meson.build
  3. 23
      src/rsvg.c
  4. 6
      src/ztk_button.c

15
inc/ztoolkit/ztk_button.h

@ -20,6 +20,7 @@ @@ -20,6 +20,7 @@
#ifndef __Z_TOOLKIT_ZTK_BUTTON_H__
#define __Z_TOOLKIT_ZTK_BUTTON_H__
#include "ztoolkit/rsvg.h"
#include "ztoolkit/ztk_color.h"
#include "ztoolkit/ztk_widget.h"
@ -77,23 +78,25 @@ typedef struct ZtkButton @@ -77,23 +78,25 @@ typedef struct ZtkButton
/** Button type. */
ZtkButtonType type;
#ifdef HAVE_RSVG
/** Normal state SVG. */
ZtkRsvgHandle * normal_svg;
/** Hovered SVG. */
ZtkRsvgHandle * hover_svg;
/** Padding to add when using SVGs to control
* their size. */
int hpadding;
int vpadding;
/**
* Clicked SVG.
*
* This will also be used for when toggled.
*/
ZtkRsvgHandle * clicked_svg;
#endif
/** Padding to add when using SVGs to control
* their size. */
int hpadding;
int vpadding;
/** If this is 1, background colors will be drawn,
* regardless if there is a \ref
@ -142,6 +145,7 @@ ztk_button_make_labeled ( @@ -142,6 +145,7 @@ ztk_button_make_labeled (
ZtkButton * self,
const char * label);
#ifdef HAVE_RSVG
/**
* Makes a button with SVGs.
*/
@ -153,6 +157,7 @@ ztk_button_make_svged ( @@ -153,6 +157,7 @@ ztk_button_make_svged (
ZtkRsvgHandle * svg_normal,
ZtkRsvgHandle * svg_hover,
ZtkRsvgHandle * svg_clicked);
#endif
/**
* Makes a customly drawn button.

7
meson.build

@ -67,8 +67,12 @@ if os_linux @@ -67,8 +67,12 @@ if os_linux
endif
if get_option('enable_rsvg')
deps += dependency('librsvg-2.0')
rsvg_dep = dependency('librsvg-2.0', version: '>=2.14')
deps += rsvg_dep
cdata.set('HAVE_RSVG', 1)
if rsvg_dep.version().version_compare('>=2.46')
cdata.set('HAVE_RSVG_2_46', 1)
endif
endif
# create config.h
@ -95,6 +99,7 @@ common_cflags = cc.get_supported_arguments([ @@ -95,6 +99,7 @@ common_cflags = cc.get_supported_arguments([
'-Wignored-qualifiers',
'-Wno-cast-function-type',
])
strict_cflags = []
if get_option ('strict_flags')
strict_cflags = cc.get_supported_arguments([
#'-Werror=cast-qual',

23
src/rsvg.c

@ -93,6 +93,7 @@ ztk_rsvg_draw ( @@ -93,6 +93,7 @@ ztk_rsvg_draw (
cairo_t * cr,
ZtkRect * rect)
{
#ifdef HAVE_RSVG_2_46
RsvgRectangle viewport = {
rect->x, rect->y, rect->width, rect->height };
GError * err = NULL;
@ -102,6 +103,28 @@ ztk_rsvg_draw ( @@ -102,6 +103,28 @@ ztk_rsvg_draw (
{
return -1;
}
#else
int rwidth =
ztk_rsvg_get_width (handle);
int rheight =
ztk_rsvg_get_height (handle);
double xscale =
(double) rect->width / (double) rwidth ;
double yscale =
(double) rect->height / (double) rheight;
double scale = MIN (xscale, yscale);
double leftover_x =
rect->width - scale * rwidth;
double leftover_y =
rect->height - scale * rheight;
cairo_save (cr);
cairo_translate (cr, rect->x + leftover_x / 2, rect->y + leftover_y / 2);
cairo_scale (
cr, scale, scale);
rsvg_handle_render_cairo (
(RsvgHandle *) handle, cr);
cairo_restore (cr);
#endif
return 0;
}

6
src/ztk_button.c

@ -75,6 +75,7 @@ button_draw_cb ( @@ -75,6 +75,7 @@ button_draw_cb (
case ZTK_BTN_LBL:
/* TODO draw label */
break;
#ifdef HAVE_RSVG
case ZTK_BTN_SVG:
if ((state & ZTK_WIDGET_STATE_PRESSED) ||
(self->is_toggle &&
@ -92,9 +93,12 @@ button_draw_cb ( @@ -92,9 +93,12 @@ button_draw_cb (
DRAW_SVG (normal_svg);
}
break;
#endif
case ZTK_BTN_CUSTOM:
self->custom_draw_cb (widget, cr, data);
break;
default:
break;
}
#undef DRAW_SVG
@ -193,6 +197,7 @@ ztk_button_make_labeled ( @@ -193,6 +197,7 @@ ztk_button_make_labeled (
strcpy (self->lbl, label);
}
#ifdef HAVE_RSVG
/**
* Makes a button with SVGs.
*/
@ -213,6 +218,7 @@ ztk_button_make_svged ( @@ -213,6 +218,7 @@ ztk_button_make_svged (
self->hover_svg = svg_hover;
self->clicked_svg = svg_clicked;
}
#endif
/**
* Makes a customly drawn button.

Loading…
Cancel
Save