Just out of interest really, as I've never been able to picture in my mind how one would be made (Buttons, text boxes etc.).
Just out of interest really, as I've never been able to picture in my mind how one would be made (Buttons, text boxes etc.).
From an object-oriented perspective, you make an object that is capable of responding to events. Then you extend that and make an object capable of displaying an image. Then you extend that and you make an object capable of storing some input from the user. You keep extending these basic components, adding little bits of functionality at a time.
A button, for instance, is just an object that responds to clicks. It displays an image and maybe some text. When you click it, it might change the image and play a sound, then perform some action. When it's done, it returns to it's original state.
A test box is just an image, but when you click in it and start typing, it displays and stores your text, too.
Then people can declare instances of these objects, change their basic properties, and integrate them into their app.
edit:
I recently did this in Flex - we were trying to create a web-based front-end to an already made Java app, so we had to replicate the old look exactly. All we did we define an object that responded to clicks, and then we defined a button, and sliders, and menus, etc... that extended from that. When we needed a "PlayBack" button - we just extended the base button, and added a little more functionality. Each file ended up only being like 15 or 20 lines - really simple way to look at it.
If I were to make an API in C, I would look at it more in terms of just data. I would maintain a list of all objects on the screen, and provide methods to add objects, move them forward or back etc... Each object would be a struct that had their x-y coordinates, their status (enabled vs. disabled), and "type". Then depending on the "type", I would call a certain method to display that type, and based on it's x-y coordinates, size, status, and other data, it could display it on screen.
Then any time someone clicked, I could go through the list, see if the click occurred on that object, and then execute any commands that were associated with a "click" for that object.
A gigantic stork brings them; sometimes they are made of sugar and spice and everything nice, sometimes just hair and nails and puppy dog tails.How are GUI APIs made?
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge
There are made using existing libraries.
So, what Sean says is pretty much how it works - you have a basic object that can handle events, then a hierarchy of objects that do other things before/during/after receiving the events and handle that.
Drawing an image involves first loading the image into memory from a file in some way (it maybe part of the executable file, as a "resource", created by a resource editor).
A text is a bit more complex in the basic font handling, but once you have fonts and drawing glyphs (symbols within the font, usually a letter, but sometimes a letter consists of more than one glyph - e.g. Ä may be drawn as A and then ¨drawn above it - that depends on how the font-designer decided to go about it - it obviously takes up more space and a bit more effort to have two different characters that are almost the same, compared to making a small addition onto an existing font).
Now that we can draw glyphs/characters, we can quite easily handle keyboard events to fill in the text box, and draw events to draw the text-box.
Of course, it is fairly simple to describe, not quite so easy to actually do this.
We have a GUI API at work, and it's by far the largest component in the "graphics" subsystem (and most likely the largest single component in the whole Embedded OS product).
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
Using a graphics library, the same as any game, like OpenGL or something would work. However, I would imagine that more professional GUIs have their own libraries. At some point, you have to use assembly and place your pixels - anything above that is really just a graphics library of sorts.But how would you go about putting the image for a button on the screen?
Most of the graphics code nowadays is rarely written in assembler code. C compilers are pretty darn good, and for high performance graphics, you'd use a graphics processor to do the ACTUAL placing of pixels in the frame-buffer.
I do definitely agree that graphics libraries are the way to go - OpenVG and QT are among the popular in embedded systems for the 2D side of things.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.