在自制操作系统中开发GUI环境
我制作了一个带有 c 内核的桌面操作系统,可以打印“hello world”。我正在尝试为我的操作系统制作一个 GUI(自定义窗口管理器,按钮),但我遇到了麻烦。我看了一个教程:
http://www.osdever.net/tutorials/view/ gui-development
是否有适用于 C 桌面操作系统的任何类型的 GUI 教程?
ps 没有 Linux 也没有 DOS。仅C标准。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为您不需要这里的特殊教程。最基本的 GUI 的核心包括管理代表窗口、按钮、图片、文本框等的矩形对象列表。
每个类似的矩形对象都有其 x 和 y 坐标以及尺寸(宽度和高度)。它还具有 z(深度)坐标,用于指示哪些对象位于其下方(它们的 z 较小)以及哪些对象位于其上方(它们的 z 较大)。
每个矩形对象还有一个指向其父对象和子对象的指针。这使得用更小、更简单的矩形组成任意复杂的窗口变得容易。对象。例如,当您抓取一个窗口并移动它时,使用这些父/子指针您可以移动所有对象。或者,如果外部对象接收到事件,它可以将其转发给其内部子对象进行处理,反之亦然。
当涉及到渲染所有这些矩形对象时,其中一些可能会被其他对象部分或完全遮挡,最重要的是找出所有对象中哪些是可见的、不可见的和部分可见的,因为你不想这样做很多不必要的工作。为了有效地绘制对象,您希望每个像素最多绘制一次(总是或大多数时间)。除了需要的矩形相交/细分代码之外,这还表明每个对象都知道如何有效地绘制自身的任意矩形部分。这对于纯色对象来说是最微不足道的。对于图片来说,它或多或少是简单的(除非您想就地进行图像缩放和颜色减少/转换)。对于文本和矢量对象来说这是最难的。
您甚至可以用小矩形对象组成鼠标指针对象,并使用与所有其他对象相同的代码绘制和重绘它。只需确保指针的 z(深度)坐标使得指针始终位于所有其他对象的顶部。
这就是总体思路。
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.
我的建议是仔细研究已经存在的和过去存在的 GUI 系统。查看他们的 API,并尝试了解它们的底层工作原理。 Alex 的回答 提供了一个很好的总体起点,但并非所有环境都以完全相同的方式工作。一定要看看他们的架构。它们是客户端/服务器还是整体式的?应用程序如何与他们通信?一旦您了解了所有这些,您就可以开始设计您的系统。找出您的窗口管理器/应用程序服务器/x 服务器等价物所在的位置,构建通信通道并开始编码。弄清楚所有这些组件如何与您的内核进行通信——这非常重要。
与内核开发不同,除非你非常激进,否则你几乎肯定会构建一些看起来有点像 unix 或有点像 VMS 的东西,但为了方便起见混合了 minix 和 mach 的元素,构建 GUI 框架更加复杂,有很多不同的变化,这可能就是为什么没有那么多好的教程的原因。
我个人的灵感来自 BeOS。我喜欢他们的做法,所以我复制了他们的做法,尽管与任何事情一样,你也需要看看他们所犯的一些错误,并尽量不要复制它们。 BeOS 也有不少错误。
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.