我正在使用 goocanvas 在 GTK 框架上绘制一个简单的图表,图表尺寸基于同一窗口上的值。当用户使用微调按钮更改界面上的值时,图表应实时更改其尺寸。
我成功设法在gtk window-> hbox->框架之上渲染初始图表。
问题在于何时更改值。它在图纸上重新绘制。
goo canvas有没有“清晰”的功能?
还是有其他方法可以达到预期效果吗?
当前代码:
<button data-bind="click: insideClick, clickBubble: false">
Inside click.
</button>
当点击名为“measure”的按钮时,它的处理程序称为“ofruta” 在“ofruta”中它调用绘图函数。
这是一种正确的方法吗?
答案 0 :(得分:1)
以下是基于https://developer.gnome.org/goocanvas/unstable/goocanvas-model-view-canvas.html的示例:
#include <stdlib.h>
#include <goocanvas.h>
static gboolean on_rect_button_press (GooCanvasItem *view,
GooCanvasItem *target,
GdkEventButton *event,
gpointer data);
static gboolean on_delete_event (GtkWidget *window,
GdkEvent *event,
gpointer unused_data);
GooCanvasItemModel *root, *rect_model, *text_model, *path;
int main (int argc, char *argv[]) {
GtkWidget *window, *scrolled_win, *canvas;
GooCanvasItem *rect_item;
gtk_set_locale ();
gtk_init (&argc, &argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_default_size (GTK_WINDOW (window), 640, 600);
gtk_widget_show (window);
g_signal_connect (window, "delete_event", (GtkSignalFunc) on_delete_event,
NULL);
scrolled_win = gtk_scrolled_window_new (NULL, NULL);
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_win),
GTK_SHADOW_IN);
gtk_widget_show (scrolled_win);
gtk_container_add (GTK_CONTAINER (window), scrolled_win);
canvas = goo_canvas_new ();
gtk_widget_set_size_request (canvas, 600, 450);
goo_canvas_set_bounds (GOO_CANVAS (canvas), 0, 0, 1000, 1000);
gtk_widget_show (canvas);
gtk_container_add (GTK_CONTAINER (scrolled_win), canvas);
root = goo_canvas_group_model_new (NULL, NULL);
rect_model = goo_canvas_rect_model_new (root, 100, 100, 400, 400,
"line-width", 10.0,
"radius-x", 20.0,
"radius-y", 10.0,
"stroke-color", "yellow",
"fill-color", "red",
NULL);
text_model = goo_canvas_text_model_new (root, "Hello World", 300, 300, -1,
GTK_ANCHOR_CENTER,
"font", "Sans 24",
NULL);
goo_canvas_item_model_rotate (text_model, 45, 300, 300);
goo_canvas_set_root_item_model (GOO_CANVAS (canvas), root);
GooCanvasLineDash *dash = goo_canvas_line_dash_new (2, 5.0, 5.0);
const char *buf = "M 0 128 L 1000 256";
path = goo_canvas_path_model_new (root, buf,
"stroke-color", "red",
"line-dash", dash,
NULL);
rect_item = goo_canvas_get_item (GOO_CANVAS (canvas), rect_model);
g_signal_connect (rect_item, "button_press_event",
(GtkSignalFunc) on_rect_button_press, NULL);
goo_canvas_line_dash_unref(dash);
gtk_main ();
return 0;
}
static gboolean on_rect_button_press (GooCanvasItem *item,
GooCanvasItem *target,
GdkEventButton *event,
gpointer data) {
g_print ("rect item received button press event\n");
static float a = 128, b = 256;
a += 16, b += 16;
char buf[64];
snprintf(buf, sizeof(buf), "M 0 %f L 1000 %f", a, b);
g_object_set(G_OBJECT(path), "data", buf, NULL);
return TRUE;
}
static gboolean on_delete_event (GtkWidget *window,
GdkEvent *event,
gpointer unused_data) {
exit (0);
}
通过使用data
修改路径的g_object_set
属性,当点击矩形时,它会移动。属性名称应取自文档,例如https://developer.gnome.org/goocanvas/unstable/GooCanvasPathModel.html