Здравствуйте! Необходимо реализовать бегущую строку текста на gtk. Для примера вот движущаяся окружность:
#include <gtk/gtk.h>
#define WIDTH 1920
#define HEIGHT 360
//gcc `pkg-config --cflags gtk+-3.0` -o test test.c `pkg-config --libs gtk+-3.0`
gboolean pos = 0.0;
gboolean timer_func (gpointer data) {
GtkWidget *widget = (GtkWidget *)data;
gtk_widget_queue_draw(widget);
return TRUE;
}
gboolean draw_callback (GtkWidget *widget, cairo_t *cr, gpointer data) {
guint width, height;
GdkRGBA color;
pos += 5.0;
width = gtk_widget_get_allocated_width (widget);
height = gtk_widget_get_allocated_height (widget);
cairo_arc (cr,
pos, height / 2.0,
MIN (width, height) / 2.0,
0, 2 * G_PI);
gtk_style_context_get_color (gtk_widget_get_style_context (widget),
0,
&color);
gdk_cairo_set_source_rgba (cr, &color);
cairo_fill (cr);
if(pos >= WIDTH) pos =0;
return TRUE;
}
void activate (GtkApplication* app, gpointer user_data) {
GtkWidget *window;
window = gtk_application_window_new (app);
gtk_window_set_title (GTK_WINDOW (window), "Window");
gtk_window_set_default_size (GTK_WINDOW (window), WIDTH, HEIGHT);
GtkWidget *drawing_area = gtk_drawing_area_new ();
gtk_widget_set_size_request (drawing_area, WIDTH, HEIGHT);
g_signal_connect (G_OBJECT (drawing_area), "draw",
G_CALLBACK (draw_callback), NULL);
gtk_container_add(GTK_CONTAINER(window),drawing_area);
gtk_widget_show_all (window);
g_timeout_add(1, timer_func, (gpointer) drawing_area);
}
int main (int argc, char **argv) {
GtkApplication *app;
int status;
app = gtk_application_new ("org.gtk.example", G_APPLICATION_FLAGS_NONE);
g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
status = g_application_run (G_APPLICATION (app), argc, argv);
g_object_unref (app);
return status;
}