Hello, I'm just getting started with Raspberry Pi 4, starting to learn my way around the Raspbian desktop and compiling my first programs in C (I prefer C and C++).
I'd like to get started with graphical programming, and the paradigm I prefer is the "Canvas" model... I just create a window and then I can select brushes and pens and draw lines, circles, rectangles, polygons within the bounds of the windows. (I am coming from windows, and their GDI subsystem provides this nicely and ends up being pretty powerful). I prefer this approach because you can truly customize your UIs and I don't mind the extra work involved.
Most of the C/C++ GUI support I've seen so far has been "widget" based, just gives you a bunch of buttons and controls. This is fine as long as they also give you access to the "canvas", but I haven't seen that yet.
Also, I don't care if I have to operate outside the desktop, it doesn't have to be a "window". As long as I can access the screen with some primitive graphical support and fonts, from a C or C++ program and still can access the RPi hardware such as SPI and GPIO, I'm all set.
Thanks for any thoughts.
Re: "canvas" type graphical library?
You could look at Gtk+ and it's "drawing area" widget which is how you can use the underlying Cairo 2D drawing library.
This will get you started : http://zetcode.com/gfx/cairo/
PeterO
This will get you started : http://zetcode.com/gfx/cairo/
PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson
Re: "canvas" type graphical library?
I suspect this is pretty much ubiquitous.
Pygame has Surface and Draw https://www.pygame.org/docs/ref/draw.html
tkinter has Canvas with create_line etc https://kite.com/python/docs/Tkinter.Canvas
The same is in SDL2
pi3D, which I think can be used for 2D, has canvas https://pi3d.github.io/html/_modules/pi ... anvas.html
Ditto Qt
If you look into most GUI libraries chances are you'll find a Canvas and drawing primitives supported.
Pygame has Surface and Draw https://www.pygame.org/docs/ref/draw.html
tkinter has Canvas with create_line etc https://kite.com/python/docs/Tkinter.Canvas
The same is in SDL2
pi3D, which I think can be used for 2D, has canvas https://pi3d.github.io/html/_modules/pi ... anvas.html
Ditto Qt
If you look into most GUI libraries chances are you'll find a Canvas and drawing primitives supported.
Re: "canvas" type graphical library?
pi3d canvas is a bit of a cheat really. pi3d uses OpenGL functionality which is very fast but the 2Dness is simply rendering 3D points, lines and triangles with no perspective. Which is 2D I suppose but things like filled polygons, line ends and corners, anti-aliasing and bezier curves have to be constructed with a bit of effort. For C/C++ applications Gtk, SDL2 and Qt are pretty standard and work fine on RPi
also https://groups.google.com/forum/?hl=en-GB&fromgroups=#!forum/pi3d
Re: "canvas" type graphical library?
Be aware that the lines, circles etc. created on Tk's Canvas aren't just drawn on to a bitmap that you can forget about, they are objects in their own right and will still be there and drawn even if subsequent elements are added that cover them.PiGraham wrote: ↑Tue Mar 17, 2020 12:47 pmtkinter has Canvas with create_line etc https://kite.com/python/docs/Tkinter.Canvas
If you treat Tk's Canvas as a bitmap and constantly draw over elements (like drawing a filled rectangle to 'erase' part of the Canvas) you will end up slowing everything down as the whole list of objects on a Canvas gets redrawn even if they are obscured. It does mean however that you can do things like move, resize or delete a line and it will correctly update.
She who travels light — forgot something.
Please note that my name doesn't start with the @ character so can people please stop writing it as if it does!
Please note that my name doesn't start with the @ character so can people please stop writing it as if it does!
-
- Posts: 1398
- Joined: Tue Mar 20, 2018 9:53 pm
Re: "canvas" type graphical library?
Check out raylib that's beginner friendly and can run on the pi with or without a desktop.
https://www.raylib.com
https://www.raylib.com