我尝试在 Windows 上使用 cairo 和 gtk+-3.6.1 制作一个简单的 rounded_rectangle,但出现问题。认为这个版本的 gtk+-3.6.1 在取自http://www.tarnyko.net/en/的 Windows 上出现问题。以下是我的代码中的一些错误::blocks IDE
main.c(文件);
#include <stdlib.h>
#include <gtk/gtk.h>
#include "roundedrectangle.h"
int main(int argc, char *argv[])
{
gtk_init(&argc, &argv);
GtkWidget *win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
//cairo_surface_t *surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 100, 100);
//cairo_t *cr = cairo_create(surface);
GtkWidget *image = gtk_image_new_from_file("C:/Users/Doudieu/Desktop/image.png");
gtk_widget_set_app_paintable(image, TRUE);
gtk_container_add(GTK_CONTAINER(win), image);
struct user_data data = {50,50,100,100,20};
user_t *dat;
dat = &data;
//g_signal_connect(G_OBJECT(win), "expose-event", G_CALLBACK(drawing), (gpointer)dat);
g_signal_connect(G_OBJECT(image), "expose-event", G_CALLBACK(drawing), (gpointer)dat);
gtk_widget_show_all(win);
gtk_main();
return 0;
}
roundedrectangle.c(文件):
#include "roundedrectangle.h"
int rounded_rectangle(cairo_t *cr, double x, double y, double width, double height, double radius[4])
{
if(((width<2*radius[0])&&(width<2*radius[1])&&(width<2*radius[2])&&(width<2*radius[3]))||((width<2*radius[0])&&(width<2*radius[1])&&(width<2*radius[2])&&(width<2*radius[3])))
{
printf("values of radius not good\n");
return -1;
}
double from_degre = PI/180;
//Corner C
cairo_arc(cr, x+width-radius[2], y+height-radius[2], radius[2], 0*from_degre, 90*from_degre);
//Corner D
cairo_arc(cr, x+radius[3], y+height-radius[3], radius[3], 90*from_degre, 180*from_degre);
//Corner A
cairo_arc(cr, x+radius[0], y+radius[0], radius[0], 180*from_degre, 270*from_degre);
//Corner B
cairo_arc(cr, x+width-radius[1], y+radius[1], radius[1], 270*from_degre, 360*from_degre);
cairo_close_path(cr);
return 0;
}
int rounded_rectangle_uni(cairo_t *cr, double x, double y, double width, double height, double radius)
{
double radius_uni[4] = {radius, radius, radius, radius};
if( rounded_rectangle( cr, x, y, width, height, radius_uni ) == -1)
{
printf("values of radius not good\n");
return -1;
}
return 0;
}
gboolean drawing(GtkWidget *win, cairo_t *cr, gpointer data)
{
GtkAllocation allo;
if(gtk_widget_get_app_paintable(win) == FALSE)
{
printf("background will be erase after\n");
return FALSE;
}
cairo_t *c = gdk_cairo_create(GDK_DRAWABLE(win->window));
gtk_widget_get_allocation(win, &allo);
struct user_data dat = *((user_t *)data);
cairo_set_source_rgba(c, 0.2, 0.1, 0, 1);
cairo_set_line_width(c, 4);
rounded_rectangle_uni(c, allo.x, allo.y, dat.width, dat.height, dat.border_radius);
cairo_stroke(c);
cairo_set_source_rgba(c, 0.0, 0.1, 0.2, 0.5);
rounded_rectangle_uni(c, allo.x, allo.y, dat.width, dat.height, dat.border_radius);
cairo_fill(c);
cairo_destroy(c);
return TRUE;
}
gboolean drawing1(GtkWidget *win, cairo_t *cr, gpointer data)
{
return TRUE;
}
roundedrectangle.h(文件):
#ifndef ROUNDED_RECTANGLE_H_INCLUDED
#define ROUNDED_RECTANGLE_H_INCLUDED
#endif // ROUNDED_RECTANGLE_H_INCLUDED
#include <gtk/gtk.h>
#include <math.h>
#define PI 3.141592653589793238462643383
typedef struct user_data user_t;
int rounded_rectangle(cairo_t *cr, double x, double y, double width, double height, double radius[4]);
int rounded_rectangle_uni(cairo_t *cr, double x, double y, double width, double height, double radius);
struct user_data
{
double x;
double y;
double width;
double height;
int border_radius;
};
gboolean drawing(GtkWidget *win, cairo_t *cr, gpointer data);
gboolean drawing1(GtkWidget *win, cairo_t *cr, gpointer data);
来自代码块输出的错误:
-------------- Build: Debug in cairo (compiler: GNU GCC Compiler)---------------
mingw32-gcc.exe -mms-bitfields -Wall -g -mms-bitfields -Ic:/gtk+/include/atk-1.0 -Ic:/gtk+/include/cairo -Ic:/gtk+/include/gdk-pixbuf-2.0 -Ic:/gtk+/include/glib-2.0 -Ic:/gtk+/lib/glib-2.0/include -Ic:/gtk+/include/pango-1.0 -Ic:/gtk+/include -Ic:/gtk+/include/freetype2 -Ic:/gtk+/include/libpng14 -IC:/GTK+-3.6.1/include/gtk-3.0 -IC:\gtk+\include -IC:\gtk+\include\gtk-2.0 -IC:\gtk+\include\cairo -IC:\gtk+\include\gdk -IC:\gtk+\include\glib-2.0 -IC:\gtk+\lib\glib-2.0\include -IC:\gtk+\include\pango-1.0 -IC:\gtk+\lib\gtk-2.0\include -IC:\gtk+\include\atk-1.0 -IC:\gtk+\include\gdk-pixbuf-2.0 -c C:\Users\Doudieu\Desktop\cairo\main.c -o obj\Debug\main.o
In file included from C:/GTK+-3.6.1/include/gtk-3.0/gdk/gdk.h:31:0,
from C:/GTK+-3.6.1/include/gtk-3.0/gtk/gtk.h:30,
from C:\Users\Doudieu\Desktop\cairo\main.c:2:
C:/GTK+-3.6.1/include/gtk-3.0/gdk/gdkversionmacros.h:147:6: error: missing binary operator before token "("
C:/GTK+-3.6.1/include/gtk-3.0/gdk/gdkversionmacros.h:155:5: error: missing binary operator before token "("
C:/GTK+-3.6.1/include/gtk-3.0/gdk/gdkversionmacros.h:158:5: error: missing binary operator before token "("
C:/GTK+-3.6.1/include/gtk-3.0/gdk/gdkversionmacros.h:164:5: error: missing binary operator before token "("
C:/GTK+-3.6.1/include/gtk-3.0/gdk/gdkversionmacros.h:172:5: error: missing binary operator before token "("
C:/GTK+-3.6.1/include/gtk-3.0/gdk/gdkversionmacros.h:178:5: error: missing binary operator before token "("
C:/GTK+-3.6.1/include/gtk-3.0/gdk/gdkversionmacros.h:186:5: error: missing binary operator before token "("
C:/GTK+-3.6.1/include/gtk-3.0/gdk/gdkversionmacros.h:192:5: error: missing binary operator before token "("
C:/GTK+-3.6.1/include/gtk-3.0/gdk/gdkversionmacros.h:200:5: error: missing binary operator before token "("
C:/GTK+-3.6.1/include/gtk-3.0/gdk/gdkversionmacros.h:206:5: error: missing binary operator before token "("
C:/GTK+-3.6.1/include/gtk-3.0/gdk/gdkversionmacros.h:214:5: error: missing binary operator before token "("
In file included from C:/GTK+-3.6.1/include/gtk-3.0/gtk/gtkwindow.h:33:0,
from C:/GTK+-3.6.1/include/gtk-3.0/gtk/gtkdialog.h:33,
from C:/GTK+-3.6.1/include/gtk-3.0/gtk/gtkaboutdialog.h:30,
from C:/GTK+-3.6.1/include/gtk-3.0/gtk/gtk.h:31,
from C:\Users\Doudieu\Desktop\cairo\main.c:2:
C:/GTK+-3.6.1/include/gtk-3.0/gtk/gtkapplication.h:77:1: error: unknown type name 'GMenuModel'
C:/GTK+-3.6.1/include/gtk-3.0/gtk/gtkapplication.h:80:49: error: unknown type name 'GMenuModel'
C:/GTK+-3.6.1/include/gtk-3.0/gtk/gtkapplication.h:83:1: error: unknown type name 'GMenuModel'
C:/GTK+-3.6.1/include/gtk-3.0/gtk/gtkapplication.h:86:49: error: unknown type name 'GMenuModel'
In file included from C:/GTK+-3.6.1/include/gtk-3.0/gtk/gtkmenu.h:34:0,
from C:/GTK+-3.6.1/include/gtk-3.0/gtk/gtklabel.h:35,
from C:/GTK+-3.6.1/include/gtk-3.0/gtk/gtkaccellabel.h:36,
from C:/GTK+-3.6.1/include/gtk-3.0/gtk/gtk.h:33,
from C:\Users\Doudieu\Desktop\cairo\main.c:2:
C:/GTK+-3.6.1/include/gtk-3.0/gtk/gtkmenushell.h:117:41: error: unknown type name 'GMenuModel'
In file included from C:/GTK+-3.6.1/include/gtk-3.0/gtk/gtklabel.h:35:0,
from C:/GTK+-3.6.1/include/gtk-3.0/gtk/gtkaccellabel.h:36,
from C:/GTK+-3.6.1/include/gtk-3.0/gtk/gtk.h:33,
from C:\Users\Doudieu\Desktop\cairo\main.c:2:
C:/GTK+-3.6.1/include/gtk-3.0/gtk/gtkmenu.h:119:44: error: unknown type name 'GMenuModel'
In file included from C:/GTK+-3.6.1/include/gtk-3.0/gtk/gtk.h:58:0,
from C:\Users\Doudieu\Desktop\cairo\main.c:2:
C:/GTK+-3.6.1/include/gtk-3.0/gtk/gtkbutton.h:84:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'void'
C:/GTK+-3.6.1/include/gtk-3.0/gtk/gtkbutton.h:86:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'void'
C:/GTK+-3.6.1/include/gtk-3.0/gtk/gtkbutton.h:88:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'void'
C:/GTK+-3.6.1/include/gtk-3.0/gtk/gtkbutton.h:90:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'void'
In file included from C:/GTK+-3.6.1/include/gtk-3.0/gtk/gtk.h:131:0,
from C:\Users\Doudieu\Desktop\cairo\main.c:2:
C:/GTK+-3.6.1/include/gtk-3.0/gtk/gtkmenubar.h:73:42: error: unknown type name 'GMenuModel'
In file included from C:/GTK+-3.6.1/include/gtk-3.0/gtk/gtk.h:132:0,
from C:\Users\Doudieu\Desktop\cairo\main.c:2:
C:/GTK+-3.6.1/include/gtk-3.0/gtk/gtkmenubutton.h:82:46: error: unknown type name 'GMenuModel'
C:/GTK+-3.6.1/include/gtk-3.0/gtk/gtkmenubutton.h:84:1: error: unknown type name 'GMenuModel'
Process terminated with status 1 (0 minutes, 2 seconds)
24 errors, 0 warnings (0 minutes, 2 seconds)