Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Developing a GUI environment in home-made OS

I have made a desktop os with a kernel in c that prints "hello world". I am trying to make a GUI (custom window manager, buttons) for my os in c but I am having trouble. I looked at one tutorial:

http://www.osdever.net/tutorials/view/gui-development

Are there any types of GUI tutorials that are for a desktop operating system in C?

p.s. no Linux and no DOS. only C standard.

like image 589
Coder404 Avatar asked Jan 22 '12 22:01

Coder404


2 Answers

I don't think you need a special tutorial here. The core of the most basic GUI consists of managing a list of rectangular objects that represent windows, buttons, pictures, textboxes, etc.

Every rectangular object like that has its x- and y-coordinates and dimensions (width and height). It also has a z (depth) coordinate that tells what objects are below it (their z's are smaller) and what objects are above it (their z's are greater).

Every rectangular object also has a pointer to its parent and to its children. This makes it easy to compose arbitrarily complex windows of smaller and simpler rect. objects. For example, when you grab a window and move it, using these parent/children pointers you can move all objects. Or, if the outer object receives an event, it can forward it to its inner children for handling and vice versa.

When it comes to rendering all these rectangular objects, some of which can be partially or fully obscured by others, the most important thing is to figure out which of all the objects are visible, invisible and partially visible because you don't want to do a lot of unnecessary work. To efficiently draw objects you want to draw every pixel at most once (always or most of the time). In addition to the rectangle-intersecting/subdividing code that'll be needed, this also suggests that every object know how to draw any arbitrary rectangular portion of itself efficiently. This is most trivial for solid-color objects. For pictures it's more or less straightforward (unless you want to have image scaling and color reduction/transformation in-place). For text and vector objects it's hardest.

You can even compose your mouse pointer object out of small rectangular objects and have it drawn and redrawn by the same code as for all other objects. Just make sure the pointer's z (depth) coordinate is such that the pointer is always on top of all other objects.

That's the general idea.

like image 171
Alexey Frunze Avatar answered Oct 12 '22 19:10

Alexey Frunze


My recommendation would be to look hard at GUI systems that already exist and that have existed in the past. Look at their APIs, and try to figure out how they work underneath. Alex's answer gives a good general starting point, but not all environments work in quite the same way. Be sure to look at their architecture too. Are they client/server, or monolithic? How do the apps communicate with them? Once you've understood all of that, you can start designing your system. Figure out where your window manager/app server/x server equivalent lives, build the communication channels and start coding. Figure out how all of those components need to talk to your kernel too - thats really important.

Unlike kernel development where unless you're being really radical you're almost certainly building something that looks a bit like unix or a bit like VMS but with elements of minix and mach mixed in for expediency, building a GUI framework is more complicated with many different variations which is probably why there are not so many good tutorials.

My personal inspiration is BeOS. I liked the way they did it, so I copied that although as with anything you need to look at some of the mistakes they made too and try not to copy them. BeOS had its fair share of mistakes.

like image 31
Stewart Avatar answered Oct 12 '22 19:10

Stewart