From e082c0fe07bde3f6c5f4301e2b795ccd9ad8be5c Mon Sep 17 00:00:00 2001 From: "Gergely POLONKAI (W00d5t0ck)" Date: Tue, 3 Sep 2013 18:12:02 +0200 Subject: [PATCH] Added chat log on the topic of 2D drawing --- graphics-help-from-irc.txt | 52 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 graphics-help-from-irc.txt diff --git a/graphics-help-from-irc.txt b/graphics-help-from-irc.txt new file mode 100644 index 0000000..4d5b6d4 --- /dev/null +++ b/graphics-help-from-irc.txt @@ -0,0 +1,52 @@ + hello + what is the best way to create still 2D graphics? + cairo + it has a fairly nice interface like "go to this point, then to this point, draw a line, draw an arc" and so on + can it handle external images? + like pngs, etc? + I have svg, as it scales better + but basicly, yes + you can use librsvg to render svgs to cairo, in vector form + if you go through a different image loader library (like GdkPixbuf) then you'll end up rasterising it first + the first version is more to my likes + you might find this helpful: http://cgit.freedesktop.org/~cworth/svg2pdf/tree/svg2pdf.c + shows how to render an svg to a cairo pdf surface + but you could just as well use it for other cairo surfaces, including the ones you get out of gtk +* nkoep kilépett (Read error: 145 (Connection timed out)) + thank you + are you making something that you want to end up on the screen eventually? + yes + and possibly to save it to an image file later + depending on your app, you'll either want to create a cairo image surface and draw to it, then draw the image surface to the screen from your gtk draw() function + or just draw directly to gtk's cairo context from your draw function + cairo_surface_write_to_png() will help with that +* yoseforb kilépett (Remote closed the connection) + I'll take a look then +* yoseforb (~yoseforb@164.138.127.79) csatlakozott ide: #gtk+ + and if I want to get a bit farther? Like I want to add some actions to the svg parts? E.g. tooltips should appear when I hover a specific "sub-image" + that would be complicated + I was more than sure :) + particularly if you wanted to do it for named parts of the svg file... + if you want to do it for a particular hard-coded coordinate you could use a motion notify event and a handler that does a popup when the mouse is over the area you care about + but i don't think rsvg has any mechanism for saying "the box with xml id 'foo' is at these coordinates" + no, the svg files I load are small icons actually + no named parts + probably would not be too hard then + they are svg onlf for scalability + from the Gtk side, you're probably going to want to use a GtkDrawingArea + I've already figured out that, I'm currently digging my nose into Gtk documentation to see how to draw on it + then do gtk_widget_add_events() on it for GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK | GDK_POINTER_MOTION_MASK + actually there is an API for that in rsvg, but it's horribly slow + W00d5t0ck: connect to the "draw" signal on the drawing area + it will hand you a cairo_t as one of the arguments + draw on it.... + well, id -> rect, but not the other way + chpe: neat. that's very useful. + W00d5t0ck: what language are you using? + if it's anything other than C, you almost certainly want to subclass GtkDrawingArea + I'm only familiar enough with C + and if it is C, and you know how to subclass, i'd still recommend doing it that way, and overriding the 'draw' function in the subclass + I've done subclassing back in Gtk 2, with C + it's the same deal still + so I think it won't be a problem + 'cept gtk2 didn't have 'draw'