Hey Guys, I am building a cards game which displays a stack of Cards( Some thing like Solitaire). I was wondering you give me some advise regarding it? Also if you could direct me to a tutorial for stuff like these( I am already going through the gtk doc).
You should check what have already be done in GnomeGames :
Aisleriot
Blackjack
Get the code and see how they have done it. It seems that they render each and every card :
For example, in Aisleriot source code, in game.h, you have the definition of an ArSlot struct which stores all the cards of one slot. In there, you can see that they define the 'expansion' union which is just defining the offset between the cards.
So if you wish to create a heap of cards, you can draw each one of them, or if you consider it's too slow, just draw a few cards with a random offset of one or two pixels, and then draw the last card on the top : with this algorithm, your heap of cards looks like a heap, and it's quick to render on screen.
Unfortunately, there's no widget included in GTK+ that displays stack of cards, so yu have to write one yourself. You should use GtkDrawingArea (preferably by subclassing it), and in handler for expose_event signal do your drawing stuff. To draw you can use either plain GDK which is more basic, or use Cairo, which is more flexible drawing library (nb. Cairo is used by GTK+ anyway, so it's not additional dependency. If you want more, you can even use OpenGL (then you have to use GtkGlExt library).
GTK Tutorial has a chapter dedicated for creating own widgets.
Related
Is there a way to change the clutter perspective for a given container or widget?
The clutter perspective controls how all the clutter actors on the screen are displayed when rotated, translated, scaled, etc.
What I would really like to do is to change the perspective's origin from the center of the screen to another coordinate.
I have messed with a few of the stage methods. However, I haven't had much luck understanding some of the results, and often I hit some stability issues.
I know there are transformation matrices that do all the logic under the hood, and there are documented ways to change the transform matrices. Honestly, I haven't researched much further and just though I would ask for guidance before spending a lot of time on it.
Which leads me to another question regarding the matrices and transformations. Can one of these matrices be used to skew an actor? Or deform it into a trapezoid, etc? And any idea how to get started on that, ie. what a skew matrix would look like?
Finally, does anyone know why the clip path was deprecated? It seems that would have worked for what I ultimately want to do: draw irregular shaped 2d objects on the screen If I can implement an answer to question 2, then I guess a clip box with a transformation can be used here.
1, I do not know if (or how) one might change the Clutter stage's focal point.
2 A skew or shear transformation matrix is easy enough to construct, and can be implemented in the GJS Clutter functions Clutter.Actor.set_transform(T) and Clutter.Actor.set_child_transform(T) where T is a Clutter.Matrix .
This does present another problem, however, for the current codebase; and this leads to another question. (I guess I should post it somewhere else). But, when a transform is set on a clutter actor (or its children), the rest of the actor's properties are ignored. This has the added effect that the Tweener library cannot be used for animation of these properties.
3 Finally, one can use Cairo to draw irregular shaped objects and paths on a Clutter actor, however, the reactive area for the actor (ie. mouse-enter and -leave events) will still be for the entire actor, not defined by the Cairo path.
The Gtk+ 3 migration guide shows how the GdkEventExpose.region field can be used to provide a fine-grained area for re-rendering widgets. We already do something like this in Inkscape to avoid rendering excessive amounts of complicated stuff on our drawing canvas.
However, the example in the guide shows how to do this for the old Gtk+ 2 expose_event handler.
How do I do the equivalent in a new Gtk+ 3 draw handler, which receives a "ready-clipped" Cairo context as a parameter, rather than a GdkEventExpose?
I guess one possibility is to use cairo_copy_clip_rectangle_list on the "ready-clipped" cairo context to obtain a list of rectangles that make up the region to draw. Does anyone have any experience of using this? Does it seem like a sensible approach?
Yes, you should use cairo_copy_clip_rectangle_list() on the cairo_t that you get in your widget's ::draw() signal handler. See this commit for an example:
http://git.gnome.org/browse/vte/commit/?id=21a064ac8b5925108b0ab9bd6516664c8cd3e268
Since I have not much clue, I decided to check the source code. GDK emits a GDK_EXPOSE event on a window and creates the GdkEventExpose instance for this.
This event is then handled in gtk/gtkmain.c via gtk_widget_send_expose():
http://git.gnome.org/browse/gtk+/tree/gtk/gtkwidget.c?id=eecb9607a5c0ee38eadb446545beccd0922cb0b8#n6104
This function clips the cairo_t to GdkEventExpose.region, as you already learned in the docs.
This then calls _gtk_widget_draw_internal() which emits the actual draw signal:
http://git.gnome.org/browse/gtk+/tree/gtk/gtkwidget.c?id=eecb9607a5c0ee38eadb446545beccd0922cb0b8#n5726
As far as I can see, nothing here let's you access the clip region directly. In gtk_widget_send_expose() the GdkEvent is added as userdata to the cairo context. However, this is not accessible, because all the involved functions and variables are static. So you'll have to use cairo_copy_clip_rectangle_list().
However, this sounds quite inefficent. First gdk_cairo_region transforms the region into a number of calls to cairo_rectangle and then cairo transforms this from its internal representation into a cairo_rectangle_list_t (which may fail if the clip is, for some reason, not a region). If you see this being slow, it might make sense to have some shortcut for this added to gtk directly.
I have written my own software pipeline for 3D graphics in C (just to prove to myself I could do it) and, having seen it work, I want to use it in DLL form as a library for Visual Basic .NET. I have had good success with mixing C and VB in this way in the past (C does the hard work in a DLL, VB looks pretty), but what I want to do now is a little different. My software renderer needs to display the graphics in a VB form, most likely on a panel. Ideally, I would do one of two things. First, I could create an instance of a Bitmap class in Visual Basic, somehow pass a pointer to the pixel array to a rendering function in C, then paint the bitmap to the panel. Or second, I could somehow control the graphics on the panel more directly, but I'm not sure how that would work. Does anybody know how I could accomplish my goal?
Edit:
Up to this point I have been using SDL to display graphics.
I believe I may have found what I am looking for here.
http://msdn.microsoft.com/en-us/library/5ey6h79d.aspx
I will come back with more information as soon as I try my plan out. Basically, I can get the address of the pixel array for a bitmap with the lock bits method. I can pass this to my C rendering function. It should work perfectly.
I am new to Gtk and want to do simple drawing of shapes like circles and rectangles. I was looking at the gnome tutorial and the hello word example. However the curves section is undocumented. I was wondering if someone could point me in the right direction as to what should I look at, and maybe if I need to include some other supplementary library to draw?
The preferred drawing API in GTK 2 and 3 is Cairo. But if you need to develop a diagram program, with nodes that can react to events, you will need also to use a canvas, like GooCanvas.
Check out http://developer.gnome.org/gtk3/3.2/GtkDrawingArea.html about the GtkDrawingArea, plus http://developer.gnome.org/gdk/stable/gdk-Drawing-Primitives.html about Gdk-Drawing-Primitives and you are on the go.
You might also go a bit further by using this link and check out Cairo directly http://www.cairographics.org
i need to make a program where i have to detect the edge of a subimage (like a face in a portrait) using canny detector. then i need to filter that portion out and paste it in another background. it is like mixing 2 layers. can anybody give me any algorithm for this? or any idea about the process?
You are probably aware that the task of selecting a subimage is most known Region of Interest (ROI).
Edge detection with canny shouldn't be a problem since OpenCV implements it as cvCanny().
For what I understand you want to overlap two images. I suppose you want to add one image on top of each other? Take a look at step 2 on the first link I suggest: Adding Two Images with Different Size
If you want to BLEND them, then check these instructions. I have used them before to draw over the webcam window.