How to implement custom drawing in GtkButton in GTK4 using C - gtk4

I'm porting some of my Objective C (macOS, Cocoa) applications to Linux/Windows. I decided to use GTK4. I'd appreciate an example of how to overload the GtkButton drawing method to do my custom drawing. I'd like to draw some symbols on a button using Cairo.

Related

embed a X11 window in a gtk+3 widget

I would like to embed a simple X11 window in a gtk widget.
I have found this gist https://gist.github.com/pastapojken/69f1e223fd926425f7ae770a95ec79a2 which does almost but not quite what I am looking for: It allows to add gtk widgets inside an X window, not the contrary.
I don't know if I am being clear as I am quite a newbie in both X11 and gtk. So here is a quick schema:
So is this even possible, any advice on how to make this work ? I feel like all I need to do is inherit from GtkWidget and set its GdkWindow to a wrapper of the XID like this:
win = gdk_x11_window_foreign_new_for_display(display, xid);
gtk_widget_set_window(myWidget, win);
But I was not sucessful this way, all I get is two top level windows as shown below.
I am running Fedora 32 on X11, NOT wayland
thanks!

SDL_Surface into GTK Window

I'm currently making a project in my IT School and I work with SDL (The project is image processing and stuff like that), and currently I just display the image with SDL without interface (buttons etc...). I know a little bit about GTK so I want to know if I can display an image (here a SDL_Surface) into a GTK window
I made some research but nothing was very clear...
Thank you !
Drawing widgets using SDL
Drawing widgets(menu, buttons etc) using SDL drawing functions and handling actions by tracking the cursor position during the occurrence of event(on which item the cursor was while the event was performed).
This becomes very complicated and would be better to use an existing GUI library with some simple hacks. You can find code example for drawing a button here.
Copying SDL surface into target GUI widget
This involves copying pixel by pixel(predefined functions might be available to do the same, gdk_draw_rgb_image in case of gtk) of the sdl surface into target gui widget(can be a drawingArea in case of GTK).
Merging SDL window into a GUI widget
In X11 and win32 systems each windows are given with a window id and by default sdl and gtk would have separate window id resulting two different windows, we can exploit SDL_CreateWindowFrom function to use single window for sdl and gtk in which we will force both the libraries to use a single window id.
You can find similar question here.
GTK Plug and Socket
Plug and Socket enables embeeding widget from one process to another. GTK will create a socket and pass the socket id to SDL and SDL would create window from that socket ID.
Event loop handling:
After merging SDL with GTK you might find gtk and sdl have their own event loops hence handling events might not be as expected. To solve that issue you can handle
events in GTK and propagate the event to SDL using SDL_PushEvent function and vice versa in case you are using user defined events.
.
.
static SDL_Event SDLevent;
switch(event->keyval)
{
case GDK_KEY_m:
SDLevent.type = SDL_KEYUP;
SDLevent.key.keysym.sym = SDLK_m;
SDL_PushEvent(&SDLevent);
break;
.
.
.
This link has a nice explanation for above methods.

drawing with cairo over a GtkBox not using GtkDrawingArea

I program my application in C using GTK+3 and cairo.
is there a way to draw a line on top of a Vertical GtkBox ?
the thing is that I need to mark an area with a line. the area is a row of a vertical GtkBox, which is not a GtkDrawingArea.
is that possible?
any information regarding the issue would be greatly appreciated.
I'm using glade in order to create the Gtk Vertical Box.
I connected a callback to the draw signal and I marked 'After' in glade which actually calls my callback after the basic drawing. which allows me to draw on top of the elements inside it.
as simple as that ;)

How to do simple shape drawing in GTK?

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

OpenGL, Showing Text and getting values using C

This has been my problem since I started using openGL.
What code am I going to use to show text and get value. I could not use printf and scanf and my only header file is glut.h.
This has been my problem since I started using openGL.
What code am I going to use to show text
Difficult subject, because OpenGL itself doesn't deal with text output. You can:
render text to an image and display that
create a texture atlas from the glyphs of a font, then render from that font texture
draw the font glyph outlines as geometry
If you Google "OpenGL font rendering" you'll get a large number of results of papers on the topic. Recent and old ones alike.
and get value.
Not with OpenGL. OpenGL is a drawing API. You send it points, lines and triangles, and it draws nice pictures for you. User input is outside the scope of OpenGL. That's on part of the GUI system. Most likely one of
Windows GDI
MacOS Cocoa
X11
Standard user input event processing applies. Usually one uses a toolkit like Qt, GTK or similar. Those toolkits deal with user input processing through their event mechanism.
http://linux.die.net/man/3/glutstrokestring
How about this?
#include <openglut.h>
glutStrokeString(GLUT_STROKE_ROMAN, "I will draw this string at the origin of the model");

Resources