Using GtkTreeViewDropPosition in drag and drop
I haven't worked with drag and drop all that much. I have an application in which I'm dragging rows from one tree view onto another tree view. It's working great except for one piece... Using the gtk_tree_view_get_dest_row_at_pos () in the drag-motion signal handler, I am able to get the GtkTreeViewDropPosition and change the drop indicator accordingly based on the return value (root nodes accept drop into, child nodes only show dropping before or after). However, using that same call to gtk_tree_view_get_dest_row_at_pos () in the drag-data-recieved signal handler gets the path okay, but does not set the GtkTreeViewDropPosition. Thus, the row is not always dropped into the position that was indicated by the motion event. Can anybody tell me why the GtkTreeViewDropPosition wouldn't be obtainable in the drag-data-recieved handler? -- - Micah Carrick Developer - http://www.micahcarrick.com GTK+ Forums - http://www.gtkforums.com ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Scrolling text in Gtk
In the book Foundations of GTK+ Development, there is a chapter on creating custom widgets in which a marquee widget is created (which scrolls text across the widget). You could take a look at the source code from the book available at www.gtkbook.com - Micah Carrick Developer - http://www.micahcarrick.com GTK+ Forums - http://www.gtkforums.com Tuvok wrote: Hi, What I need to do, is to make a bar with scrolling text inside it (like the bars with stock prices on tv). I've tried two methods, both of which are very slow. I've done it with Canvas and with Cairo. Below follows code. Did I do something wrong? Is there a way to make this code run faster? Should I use some different libraries for it? Rendering 4 such windows (1680x50) takes up 40-50% on both cores (AMD X2, 2.4GHz). Method I: Canvas The rendering part of code: GtkWidget *canvasWdg; GnomeCanvasItem *text; GnomeCanvasGroup *rootGroup; ifstream in(filename); string textLine; getline(in, textLine); canvasWdg = gnome_canvas_new(); gtk_container_add(GTK_CONTAINER(window), canvasWdg); gnome_canvas_set_scroll_region(GNOME_CANVAS(canvasWdg), 0.0, 0.0, width*1.0, height*1.0); rootGroup = gnome_canvas_root(GNOME_CANVAS(canvasWdg)); text = gnome_canvas_item_new(rootGroup, GNOME_TYPE_CANVAS_TEXT, x, 0.0, y, 0.0, text, textLine.c_str(), anchor, GTK_ANCHOR_NW, fill_color, white, size, (int)((height*0.7)*1000), size-set, TRUE, NULL); double x1, x2, y1, y2; gnome_canvas_item_get_bounds(GNOME_CANVAS_ITEM(text), x1, y1, x2, y2); // align the text in window: gnome_canvas_item_move(GNOME_CANVAS_ITEM(text), 1.0*width, ((height*1.0)/2-(y2-y1)/2)); g_timeout_add(40, moveText, text); gtk_widget_show_all(window); and the timeout function: gboolean moveText(void *text) { gnome_canvas_item_move(GNOME_CANVAS_ITEM((GnomeCanvasItem*)text), -2.0, 0.0); return TRUE; } Method II: Cairo I've made a Gtk widget, which draws with cairo on expose event; I'll put here only the expose function: static gboolean mdk_text_scroller_expose(GtkWidget *textScroller, GdkEventExpose *event) { MdkTextScroller *ts = MDK_TEXT_SCROLLER(textScroller); cairo_t *cr; cr = gdk_cairo_create(textScroller-window); gdk_cairo_region(cr, event-region); cairo_clip(cr); cairo_select_font_face(cr, Sans, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); cairo_set_font_size(cr, ts-size); cairo_move_to(cr, ts-x+ts-xOffset, ts-y+ts-yOffset); cairo_set_source_rgb(cr, 1.0, 1.0, 1.0); cairo_show_text(cr, ts-text); if (ts-width == 0 || ts-height == 0) { cairo_text_extents_t ext; cairo_text_extents(cr, ts-text, ext); ts-width = ext.width; ts-height = ext.height; } if (ts-width+ts-xOffset+100 0) { cairo_move_to(cr, ts-x+ts-xOffset+ts-width+100, ts-y +ts-yOffset); cairo_show_text(cr, ts-text); } if (ts-x+ts-xOffset+ts-width 0) { ts-xOffset=ts-xOffset+ts-width+100; } cairo_stroke(cr); cairo_destroy(cr); } it's then redrawn with the same timeout call: gboolean moveText(void *text) { mdk_change_text_position((GtkWidget*)text, -1, 0); gtk_widget_queue_draw((GtkWidget*)text); return TRUE; } ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Scrolling text in Gtk
On Mon, May 26, 2008 at 3:23 PM, Tuvok [EMAIL PROTECTED] wrote: What I need to do, is to make a bar with scrolling text inside it (like the bars with stock prices on tv). A more modern canvas library such as goocanvas comes with animation support, it should be really trivial to implement. You can find goocanvas here: http://live.gnome.org/GooCanvas cheers -- Gian Mario Tagliaretti ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Draw in a GdkPixbuf
Hi list! I'm trying to find a way to draw in a GdkPixbuf (for example draw a rectangle on the pixbuf) and save the result to a file afterwards. I found in devhelp the gdk_draw_* functions, but to use them I need a GdkPixmap. gdk_pixmap_new requires a GdkDrawable. The problem is that I'm developping a command line application, so I don't use GTK, only glib, gdk, and gdk-pixbuf. Even creating the GdkPixmap with a NULL GdkDrawable, I can't workaround the problem, because the documentation of gdk_draw_pixbuf tells me that All windows have a colormap, however, pixmaps only have colormap by default if they were created with a non-NULL window argument. Otherwise a colormap must be set on them with gdk_drawable_set_colormap(). Trying to get a colormap requires other stuff, which requires other stuff, and so on... As this seems to be quite old-fashioned way of doing things, I tried to see if cairo could do the trick. But it seems there's no way to draw to a GdkPixbuf with cairo (I'm unfamiliar with cairo). So, does anyone have an hint on how to draw and save an image from a GdkPixbuf, with gdk or cairo ? Thanks for you help, Luis ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Draw in a GdkPixbuf
Take a look at the executable 'gtk-demo'. It should have been installed with gtk's development tools; i.e. already loaded on you machine. Hint: double click the sample for a live preview, then look at the source code. Additionally, here is a link to glinegraph, a simple line graph widget written twice, once in gdk and again in cairo. http://sourceforge.net/project/showfiles.php?group_id=157888package_id=191712 James, On Thu, 2008-05-29 at 03:18 +0200, Luis Menina wrote: Hi list! I'm trying to find a way to draw in a GdkPixbuf (for example draw a rectangle on the pixbuf) and save the result to a file afterwards. I found in devhelp the gdk_draw_* functions, but to use them I need a GdkPixmap. gdk_pixmap_new requires a GdkDrawable. The problem is that I'm developping a command line application, so I don't use GTK, only glib, gdk, and gdk-pixbuf. Even creating the GdkPixmap with a NULL GdkDrawable, I can't workaround the problem, because the documentation of gdk_draw_pixbuf tells me that All windows have a colormap, however, pixmaps only have colormap by default if they were created with a non-NULL window argument. Otherwise a colormap must be set on them with gdk_drawable_set_colormap(). Trying to get a colormap requires other stuff, which requires other stuff, and so on... As this seems to be quite old-fashioned way of doing things, I tried to see if cairo could do the trick. But it seems there's no way to draw to a GdkPixbuf with cairo (I'm unfamiliar with cairo). So, does anyone have an hint on how to draw and save an image from a GdkPixbuf, with gdk or cairo ? Thanks for you help, Luis ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list