glib: modular test fixtures?
Maybe I've just been up too late and am not thinking straight, but I suppose it doesn't hurt to ask... is there some way to use the Glib testing framework so as to have modular fixtures that could be combined or separated on a per-test basis? I'm staring at the API, but not seeing it. What I mean is: Say, I have test function A, which needs a fixture providing an open FILE stream, and test function B, which needs a fixture providing an character buffer, and test function C, which needs both. Ideally, I would be able to simply write a file stream fixture, and a character buffer fixture, and then somehow use both in test function C. Obviously, one approach would be to write a single fixture which provides both the FILE stream and the character buffer, and pass that to all functions. But then it starts to get complicated if, say, I add a test function D, which needs the same FILE stream, but a character buffer of a different size. Add enough functions, and I end up with a bunch of massive, clumsy fixtures (and fixture functions) that repeat a lot of the same code, yet differ slightly from each other. -- frigidcode.com indicium.us ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
GRegex regular expression failing to match
I'm trying glib's GRegex functionality for the first time, and apparently I am doing something wrong. I have some code like so: code: GError * error = NULL; GRegex * regex = g_regex_new (^/(d+)$, 0, 0, error); if (error != NULL) { // ... } GMatchInfo * match_info; g_regex_match (regex, path, 0, match_info); if (g_match_info_matches (match_info)) { gchar * word = g_match_info_fetch (match_info, 1); // ... } In my unit test, I pass in in the string /1, hoping to match and then pull out the number. A GError is not thrown (so my GRegex is compiling), but g_match_info_matches() is returning FALSE. Is there anything wrong with the regexp, or perhaps my g_regex_new() options, or anything else obvious? -- frigidcode.com indicium.us ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
clarification: GErrors and GQuarks
Quick glib question here: I've been getting into glib's error reporting system and trying to integrate it into some code. (My code is using glib, but not GTK+ itself.) Overall it seems rather straightforward, but there was one point I was hoping for clarification on: In the g_set_error() parameters, the domain parameter is a GQuark. Does this mean that I am supposed to use something like g_quark_from_string (MODULE_ERROR_DOMAIN_NAME) for that parameter each time I call g_set_error? That would make sense, from what I've read in the GQuark part of the API. But I'm a little confused because the example given in the API for g_set_error() usage does not do this. (In the example, they just pass in some mysterious constant of unexplained origin.) -- frigidcode.com indicium.us ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Crediting beta testers?
I've really appreciated how convenient the GtkAboutDialog class is and especially the gtk_show_about_dialog() function. The only thing that seems to be missing: There is a property for every basic kind of credit that could be given (authors, translators, artists, etc.) but no property for (beta) testers. I would think that would be a rather popular one, and in my case beta testing is about the only thing I don't do myself. I am curious if anyone ever thought of adding a component for that. Or perhaps some kind of miscellaneous credits field, for giving credit to people who don't fit in any other category? -- frigidcode.com indicium.us ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
desktop integration: program launcher entry and icon
This is not strictly speaking a gtk+ question, but I was hoping someone might help me out anyway: how do I go about integrating my application properly with the desktop, i.e., so that my program shows up with an entry and an icon in the application menu of Gnome, Xfce4, and all other compatible desktop environments? If anyone could point me to a good Web page on the subject, I would be appreciative. I can't seem to get the right search results for this question. -- frigidcode.com indicium.us ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
glib: standard GLib types
Stupid noobish question here, but inquiring minds were wondering: is there any benefit to doing gint increment (gint) instead of int increment (int) It seems like the two are exactly identical, except that in the former case, you have permanently tied you function to glib. I can see perhaps the benefit of gint64, guint64, et cetera, to portably fix bit widths, but I'm not quite seeing the benefit of the fundamental type replacements. -- frigidcode.com indicium.us ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
learning gtk+ well: Which book to buy?
Hi. I want to have a thorough and well-formed understanding of how to use gtk+, which I'm not quite getting from the API. What would be the best book I can buy right now? The most up-to-date book I see is Foundations of GTK+ Development (2007) but not having a lot of money to experiment with, I was hoping to get your recommendations before buying anything. -- frigidcode.com indicium.us ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: key press events holding keys down
On 03/19/2012 03:34 AM, Chris Vine wrote: Since GtkWidget objects have key-press-event and a key-release-event signals that you can connect to (and from your explanation, clearly you have connected to), you will probably need to explain why these don't do what you want in order to get a meaningful answer. Most people would monitor these in conjunction with gdk_event_get_keyval() or gdk_event_get_keycode() and keep state. Chris I'm currently attempting to code a simple space combat game. In my game it is possible (quite likely) that two keys will be held down at the same time (especially the up arrow and another arrow) e.g. to turn and to accelerate at the same time. Currently I monitor for key press events as you say; the problem is that key press events are only being generated for the last key that was pressed. So if a user attempts to turn and accelerate at the same time, he will actually only do one or the other, depending on which key he happened to press last. If I could just check whether or not a key is currently depressed, then I could check both keys between a main loop iteration and handle them appropriately. This is precisely what I used to do back when I was using ClanLib, which had a function just for this purpose. An additional problem is that, although key press events do get repeated, they do not get repeated immediately; it seems that there is a brief delay (half a second or so, but noticeable) between the first key press event and the subsequent stream of them. This is the same effect I notice when using a word processor. -- frigidcode.com indicium.us ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: key press events holding keys down
On 03/19/2012 11:02 AM, Chris Vine wrote: On Mon, 19 Mar 2012 09:21:27 -0800 Christopher Howard christopher.how...@frigidcode.com wrote: On 03/19/2012 03:34 AM, Chris Vine wrote: Since GtkWidget objects have key-press-event and a key-release-event signals that you can connect to (and from your explanation, clearly you have connected to), you will probably need to explain why these don't do what you want in order to get a meaningful answer. Most people would monitor these in conjunction with gdk_event_get_keyval() or gdk_event_get_keycode() and keep state. Chris I'm currently attempting to code a simple space combat game. In my game it is possible (quite likely) that two keys will be held down at the same time (especially the up arrow and another arrow) e.g. to turn and to accelerate at the same time. Currently I monitor for key press events as you say; the problem is that key press events are only being generated for the last key that was pressed. So if a user attempts to turn and accelerate at the same time, he will actually only do one or the other, depending on which key he happened to press last. A key remains pressed until a key-release-event for it is received. That is what I meant by 'keep state'. Chris So, you are saying that if I receive a key-press-event, I should artificially generate a key-release-event, which will allow more key-press-events to be generated? How should I go about doing this? -- frigidcode.com indicium.us ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: key press events holding keys down
On 03/19/2012 12:49 PM, Chris Vine wrote: On Mon, 19 Mar 2012 20:35:33 +0100 David Nečas y...@physics.muni.cz wrote: On Mon, Mar 19, 2012 at 07:25:22PM +, Chris Vine wrote: Are you saying that on your hardware, holding one key down blocks press and release events for all other keys? I am not saying you are wrong, but I find that surprising. IMO Christopher observes this: 1) press A 2) press B while still holding A 3) release B while still holding A You get no auto-repeat key events for A after 3) even though you still hold it. Thank you, that is the basic idea, although it is more precisely: 1) Press A 2) Press B while while still holding A * I get no auto-repeat key events for A even though I am still holding it* I.e., as soon as the second key is pressed (before even being released) I stop receiving any key press events for the first key. And, of course, don't forget what I mentioned about the initial delay in getting any repeating stream of key events. The solution can be either using something more low level(?) or simply *NOT* getting your key events from Gdk key events and ignoring autorepeat altogether. (This is probably what has been – unclearly – already suggested.) I'm open minded to any approach that gets me where I want to go. Though, it seems like the simplest approach would be some (probably low level) means of just checking whether any particular key is (de-)pressed at that moment. Ah yes, I think that is the actual issue for the OP. However, the question which he asked and to which I responded was under Gtk+, how does one check whether or not any particular keyboard key is currently pressed? and the answer to that is to monitor key press and key release events and keep state. Please note, that precisely I asked how I would go about checking whether or not a key /is/ currently pressed (i.e., de-pressed). Not whether or not it /has/ been pressed. It must be possible to do this on some level because I wrote software in ClanLib a few years ago that did this using a function provided by ClanLib. (I'm not trying to exalt ClanLib as a great or better library, I'm just saying that is why I know it is possible.) However, I wouldn't advise abandoning GDK just because his real question is something different: it may be better to code the game by reference to edge events, that is changes of state, rather than by auto-repeat, which was not intended for that purpose. Chris So, you mean, receive both key press and key release events, and then maintain my own tracking of whether or not the key is currently being held down? Okay, that makes sense to me, provided of course I can be certain that all key press and key release events are properly reported to my program (otherwise my internal state my gets screwed) and in the correct order. However, the approach I was hoping for, i.e. simply checking the current reality state of a key (whether it is actually pressed down or not) sounds more convenient. If anyone could tell me how to do that, I would be grateful. BTW, in the ClanLib program I did something like so: code: -- // initialize keyboard object CL_InputDevice keyboard = window.get_ic().get_keyboard(); // ...snip... // start main loop /* get_keycode() would check if that key was currently depressed Obviously, not a very practical approach for word processing or typing into a text box, but simple and quite appropriate in, say, a space combat game */ if(keyboard.get_keycode(49)) // do something else if(keyboard.get_keycode(50)) // do something else else if(keyboard.get_keycode(51)) // do this thing else if(keyboard.get_keycode(52)) // do that thing // update graphics, etc. // end main loop -- get_keycode() was a method of CL_InputDevice. From the current API (2.3) http://clanlib.org/docs/clanlib-2.3/reference_doxygen/classCL__InputDevice.html: quote: -- boolget_keycode (int keycode) const Returns true if the passed key code is down for this device. -- I'll admit, I haven't looked yet to see how ClanLib does this at the implementation level, but if there was a similar function in Gdk or Gtk+ or where ever, that would be convenient (regardless of how it was implemented). -- frigidcode.com indicium.us ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: key press events holding keys down
On 03/16/2012 04:29 PM, Christopher Howard wrote: I control the spacecraft with the arrow keys, which I do by grabbing the GdkEventKey and then checking it against GDK_KEY_Left, GDK_KEY_Right, and so forth. Strictly speaking what I am concerned with is whether or not the key is held down, but this seems to work because the key event gets repeated. However, if one of the arrows is held down, and another arrow is pressed, then it shuts off events for the first arrow. That's bad, of course, because in my game the player may want to hold down two arrows keys at once (e.g., UP for acceleration and LEFT to turn the spacecraft). So... Okay, having got no responses, let me ask the question in a more direct manner: under Gtk+, how does one check whether or not any particular keyboard key is currently pressed? I know this is possible because I used to do it back in my ClanLib days. I see in the Gdk docs that there is a GdkDevice object, but it is not clear to me how to create or utilize this to such an end. -- frigidcode.com indicium.us ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
key press events holding keys down
Hey guys -- thanks again for the help I received recently regarding several noobie issues. I'm still working on my space combat game, and came across this little problem: I control the spacecraft with the arrow keys, which I do by grabbing the GdkEventKey and then checking it against GDK_KEY_Left, GDK_KEY_Right, and so forth. Strictly speaking what I am concerned with is whether or not the key is held down, but this seems to work because the key event gets repeated. However, if one of the arrows is held down, and another arrow is pressed, then it shuts off events for the first arrow. That's bad, of course, because in my game the player may want to hold down two arrows keys at once (e.g., UP for acceleration and LEFT to turn the spacecraft). So... * are there configuration settings I need to adjust to change how these GdKEventKeys are generated? or * is there some totally different method of checking and handling key depression state that I should be using? -- frigidcode.com indicium.us ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
cairo: multiple sprites images in one PNG
Question for the veterans: I'm coding a simple space combat game with GTK+. For the sprites, I know I can do this to draw: code: -- ship_surf = cairo_image_surface_create_from_png(ship.png); // ... cairo_set_source_surface (cr, ship_surf, x, y); cairo_paint (cr); -- But what if I want, for ease of maintainability (and less system I/O calls) to put a whole bunch of sprites in one PNG? Is it possible for me to either... * load one PNG image into a surface, and then draw to a CR using only a small part of that surface? or * load one PNG into a surface, and then split that surface into multiple smaller surfaces? It wasn't quite clear to me from the documentation how to go about this. -- frigidcode.com indicium.us ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: GtkDrawingArea size
On 03/08/2012 01:54 AM, Tadej Borovšak wrote: Hello. 2012/3/7 Christopher Howard christopher.how...@frigidcode.com: Hello again. So, I recently started a project to create a certain board game (in C) using gtk+, and I just started learning gtk+. I was planning to draw the board graphics, pieces, etc. all into one GtkDrawingArea. So, how do I fix the size of the drawing area so it doesn't get larger or smaller than my graphics? I would add a wrapper GtkAlignment around my drawing area, set it's xalign and yalign propertes to 0.5, it's xscale and yscale to 0, pack GtkDrawingArea inside it and fix it's size using gtk_window_set_size_request(). Have a look at this simple app: #include gtk/gtk.h #define WIDTH 300 #define HEIGHT 400 static gboolean cb_draw (GtkWidget *w, GdkEventExpose *e) { cairo_t *cr = gdk_cairo_create (e-window); cairo_set_source_rgb (cr, 1.0, 1.0, 0.0); cairo_paint (cr); cairo_destroy (cr); return TRUE; } int main (intargc, char **argv) { GtkWidget *window, *align, *area; gtk_init (argc, argv); window = gtk_window_new (GTK_WINDOW_TOPLEVEL); g_signal_connect (window, destroy, gtk_main_quit, NULL); align = gtk_alignment_new (0.5, 0.5, 0, 0); gtk_container_add (GTK_CONTAINER (window), align); area = gtk_drawing_area_new (); gtk_widget_set_size_request (area, WIDTH, HEIGHT); g_signal_connect (area, expose-event, G_CALLBACK (cb_draw), NULL); gtk_container_add (GTK_CONTAINER (align), area); gtk_widget_show_all (window); gtk_main (); return 0; } Cheers, Tadej Thanks for the help. Is there a way to turn off the small resizing graphic that appears at the bottom right of the window? (It looks like three small diagonal lines.) Even if this did not actually prevent resizing it would make sense in my case not to have it showing. -- frigidcode.com indicium.us ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: GtkDrawingArea size
On 03/06/2012 02:08 PM, Christopher Howard wrote: Hello again. So, I recently started a project to create a certain board game (in C) using gtk+, and I just started learning gtk+. I was planning to draw the board graphics, pieces, etc. all into one GtkDrawingArea. So, how do I fix the size of the drawing area so it doesn't get larger or smaller than my graphics? The alternative, I suppose, would be to scale everything against the actual size of the drawing area (cairo can resize bitmap images, no?) but presumably that would be a lot more complicated to code, and I would still need to constrain the proportions of width to height. ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list Bump. I'm trying to look through some other projects to see how this is done, but I would appreciate it if anyone happens to know of the top of their head. -- frigidcode.com indicium.us ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: GtkDrawingArea size
On 03/07/2012 11:37 AM, Bernhard Schuster wrote: If you did not yet start implementing it, goocanvas might be another option to the bare stuff. goocanvas allows you to set a fixed paper size. I think the halign and valign properties are what I was looking for. It seems that, if I do an align center, that the widget never grows larger than its requested size, though it still can shrink. code: -- gtk_widget_set_size_request (my_widget, 256, 256); gtk_widget_set_halign(my_widget, GTK_ALIGN_CENTER); gtk_widget_set_valign(my_widget, GTK_ALIGN_CENTER); -- -- frigidcode.com indicium.us ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
noob question: g_signal_connect()
Hi. I've installed the api documentation from the source code for both gtk+ and glib, but I can't seem to find an api description of g_signal_connect(). The examples I usually see are along the lines of code -- g_signal_connect (G_OBJECT (button[0]), draw, G_CALLBACK (draw_callback), NULL); -- Could somebody please explain two things: 1) What is the purpose of the string in the second position in the parameter list? 2) What is the purpose of the fourth parameter slot, with the NULL in it? Can other options go there? -- frigidcode.com indicium.us ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list