# MiniGUI Technology White Paper (Ver 0.1)

Chen Lei (chenlei@minigui.org), Nov 11th 2000
Wei Yongming (ymwei@minigui.org), Nov 14th 2000

## 1 Introduction

### 1.1 What is the MiniGUI

MiniGUI is a kind of GUI-supporting system for embedded systems or real time systems. It's mainly run on the Linux console. In fact, it can run on any kinds of POSIX-compliant system, which support POSIX threads. MiniGUI provides Win32-like APIs, and we can easily get the easy-to-use graphic interface. The basic component of MiniGUI is window. There are four types of MiniGUI windows, namely, main windows, dialog boxes, controls and sub-windows. The main window can either separately belongs to a thread or as the child window of other main window belonging to one thread together. We call the later form 'dependency' or 'hosting'. Every thread has a message-queue. The underlay of MiniGUI collects the events of hard devices and sends messages to windows. This is an event-driven mechanism.

### 1.2 Why Should We Use MiniGUI

Since there is a very critical environment in embedded systems, the GUI running on them must be as little as possible. The goal of MiniGUI is a compact GUI support system, therefore it can be widely used in embedded systems of industry fields or household fields.

### 1.3 The Major Features of MiniGUI

- A LGPLed pure free software
- Providing complete multi-window mechanism
- Multi-window running on single threads
- Dependencies of the main window in single thread
- Providing predefined controls, namely, static, button, single-line-editor, multi-line-editor, list box, progress bar and toolbar
- Dialog
- Messaging between windows
- Graphics Device Interface
- Providing support for M$ Windows resource file, such as Bitmap, Icon, and Cursor
- Caret
- Timer
- Accelerate keys
- Providing support for multi-character set (ISO8859-1, GB2312, Big5 at present) and multi-fonts (any Raster Bitmap Fonts, TrueType Fonts, and Adobe Type1 Fonts at present)
- Chinese Input method (Quanpin, Wubi, Intelligent Pinyin, etc.)
- Supporting GIF, JPG, BMP, PCX pictures
- Misc. (including Beep, ETC/INI file operations, etc)

Also, as a GUI support system for real-time or embedded system, MiniGUI has important features as the following:

- Small Footprint. The full functional library size is 300KB
- Configurable. It can be configured and compiled according your needs
- Stable and High Efficiency. MiniGUI has been applied in many critical system, such as, the HappyLinux's setup program and some Computer Numeric Control (CNC) system
- Portability. By now, MiniGUI can run on X Window and the Linux console. The CIT EEOS develop group has successfully ported MiniGUI to their POSIX-compliant system. MiniGUI now can run some embedded systems made by Cirrus Logic and ADS, the later is based on Intel StrongARM.

In the development of MiniGUI version 0.3.xx, we realized the following new features:

- Graphic Abstract Layer. The layer has almost no influence on the API, but it makes it easy greatly to port and debug. Currently, there are two graphic engines, namely SVGALib and LibGGI. When it using LibGGI, MiniGUI applications can run and debug on X window. Relationally there is a abstract layer of input events.
- Support for Multi-Fonts and Multi-Charsets Relies on The LOGFONT of DC (Device Context). Both multi-fonts and multi-charsets can be easily expanded. On starting, the application can shift between the system charsets, such as GB or BIG5. When using DrawText or TextOut functions, we can get other charsets by specifying font. It is possible that a window to show variant languages' fonts.

### 1.5 The Main Specifications of MiniGUI

#### 1.4.1 The Size of MiniGUI-Based Application

- Linux kernel: 300KB - 500KB (depending on system)
- MiniGUI supporting libraries: 300KB - 400KB
- MiniGUI resource (fonts, bitmaps ,etc.): 800KB
- Input method: 400KB
- Applications: 1MB - 2MB (depending on system)
- Totally: 2MB - 4MB. By reduce some features, it can be even compact.

#### 1.4.2 Hardware Support in MiniGUI

The requirement of MiniGUI is mainly display devices. On standard PC, MiniGUI realizes the graphics by using SVGALib, and it can provide to the most extent compatibility by using VESA BIOS. But in the embed system, the display devices are usually special. We suggest to rewrite the underlay graphics device driver by implementing a graphics engine and an input engine which compliant to our GAL and IAL interface.

#### 1.4.3 The Portability of MiniGUI

MiniGUI can be ported to any system that is POSIX-compliant and provides support for POSIX threads. Note that generally the underlay graphic interface is system specified. You are needed to rewrite it.

## 2 Goal and Major Features

### 2.1 Goal: Compact and Configurable

Originally, MiniGUI is designed to fit the need of an industry Computer Numerical Control (CNC) system. The industry CNC system is designed by Tsinghua University for a machine tool. After comparing DOS, Windows 98, Windows NT and Linux, the team decided to choose RT-Linux in order to fit the responsibility of real-time of 2ms or even shorter. But the problem is the user interface.. X Window is not fit to real time control system, and at that time, the localization of X Window is not very fine. Thus they decided to develop a GUI by themselves. That is the reason of the invention of MiniGUI, accordingly, MiniGUI is very compact and highly efficient. At present, the industry control system is finished and MiniGUI plays a significant role in it.

To fit the requirement of variant embedded systems, MiniGUI is designed to be configurable. With the help of Automake and Autoconf facilities in Linux, we realized a number of optional configurations.

### 2.2 Important Features of MiniGUI

#### 2.2.1 Multi-Thread and Multi-Window

There are four basic windows in MiniGUI, namely, main window, dialog, control and the child window.

The main window in MiniGUI is similar to the application's main window in M$ Windows. But there are some important differences. Each main window in MiniGUI is a separate thread. We can create main window and the according thread. Each thread has a message queue, all main window belonging to one thread can get message from it and handle it with the window callback procedure.

#### 2.2.2 Dialog and Standard Control

The dialog in MiniGUI is a special window, it works together with controls.

The following are supported controls:

- Static
- Edit (single line and multi-line)
- Button (radio button, check box and common button)
- List box
- Processing bar
- Toolbar

#### 2.2.3 Other GUI Elements

MiniGUI also supports some common GUI elements, such as, drop-down menu, caret, timer, cursor and accelerator.

#### 2.2.4 Message and Message Loop

We use message driving as the skeleton for applications. In a message-driving application, the system collects the events of peripheral devices (e.g. keyboard and mouse) and translates them into predefined messages. Usually, a application has its own message queue and it can create a message loop to wait and handle specified message.

#### 2.2.5 Graphics and Input Abstract Layer

We added the conception of the GAL and IAL (Graphics and Input Abstract Layer). The abstract layer is similar to the VFS (Virtual file system) in Linux kernel. It defines a group of abstract operations that independent to any special hardware. All the graphic operations and input handles are based on it. With the help of GAL and IAL, MiniGUI can run smoothly on different graphic engines, such as, SVGALib and LibGGI. We have finished the graphic engine for SVGALib and LibGGI. Now we are developing our private graphic engine through which, we can eventually optimize efficiency of MiniGUI to most extent.

#### 2.2.6 Multi-Font and Multi-Charset

We added the conception of logical font. It's the top level interface through which MiniGUI deal with texts (the text input and the text analysis). The logical font interface summarize all kinds of fonts (e.g., SongTi, HeiTi, and KaiTi, etc.) and charsets (ISO-8859, GB2312, Big5 and UNICODE, etc). Thus we can show different fonts in different charset in a uniform interface. This is an OOP technology. At present, MiniGUI can support any kind of raster font, vector font (e.g., TureType and Adobe Type1) and multi-charset (e.g., GB2312, Big5, etc.).

### 2.3 The Architecture of MiniGUI

As Figure 1 shows that MiniGUI is constructed with several layers. The GAL and IAL provide the underlay graphic support and the input device driving. The middle layer is the kernel level of MiniGUI including many important modules for windowing system. And the top level is the APIs (Application programming interfaces).

The GAL and IAL provide the bottom graphic and input interface, and PThread is a C library provide support to the kernel level thread. MiniGUI run under multi-thread mode. Many of its modules is run under threads. Its also support multi-window in thread mode.

As MiniGUI is designed for embed or real time system, the application on it usually has a single function. Thus multi-thread mode is more useful.

In the multi-thread environment, similar to traditional UNIX IPC (Inter-Process Communication), there is need to communication and synchronize between threads. For example, the thread, which manages windows, maintains the global window list. While, other threads can not modify this list directly, they must obey the FIFO rule. This is commonly called client/server mode. MiniGUI realizes the 'Micro C/S' mode by the synchronize mechanism between threads. We call it 'Micro C/S' because the server and client here is different threads in one process not different processes.

The key of this technique is the data structure of message. For example, the desktop micro-server manages the creation and destruction of windows. When a thread want desktop to create a window, first, it puts a message in the message queue of desktop, then turn to sleep to wait for desktop to handle the request. If desktop finishes current task or it is in sleeping state, it can handle this request immediately. When it complete, it will wake up the waiting thread and return it a result.

### 2.4 The OOP technique in MiniGUI

#### 2.4.1 Control Class and Control

Each control in MiniGUI belongs to certain window class. It is the instance of the according window class. This is similar to the conception of class and object in the OOP. On earth, each control's message is responded to the callback function of its control class. Thus every control belonging to same control class will keep uniform interface and operations. While, if we handle the message before it reach the default call back function, we can realize over loading. For example, the normal edit control can receive all the keyboard input, if we want it to just respond to number, we can mask the nonnumeric char. In fact this is the inheriting and deriving.

#### 2.4.2 GAL and IAL

The system maintains a registered array of graphics engines to save data structure of each graphics engine. And the system uses a pointer to hold the currently used graphics engine. Usually, the system maintains at least two engines, one is a 'dumb' engine which does not do any actual output, another one is actually used by the system, for example, the LibGGI or the SVGALib. The data structure of graphics engine defines some information about this engine, namely, id, properties, etc. Note that it realizes the interfaces defined by the GAL, such as, initialization, termination, graphical context management, point-drawing function, line-drawing function, box-filling function, pallete function, etc.

If the hardware adopted in certain project is a little abnormal and is not supported by the current engine, you can write your own engine with the interface according to the GAL and specify it in MiniGUI. In fact, this is the polymorphism of the OO technique.

With the help of the GAL and IAL, we enhance the portability of MiniGUI greatly and make it easier to develop and debug. For example, we can develop and debug our MiniGUI applications on the X Window and run it on certain embedded hardware platform.

#### 2.4.3 Multi-Font and Multi-Charset

Compared with the GAL and IAL, the multi-font and multi-charset is more complex. As referred above, we realize the output and analyzing of fonts. In fact, the two part interact with each other. When we output certain font, especially the multi-byte charset, namely, the GB2312 and the BIG5, we need to analyze the text in order to find out whether it is a double-byte char.

### 2.5 Typical Applications Based on MiniGUI

#### 2.5.1 The HappyLinux Installer

HappyLinux is a simplified Chinese Linux Distribution developed by a vendor. Its installer is based on MiniGUI. The source code is ported from the Red Hat Linux 6.0 setup. And we added some other feature to make the interface more user friendly, such as the on-line help as shown in Figure 2 and Figure 3.

#### 2.5.2 VACS-III System

The VACS-III (Virtual Axes Control System) is a CNC system run on RT-Linux. It is developed by the Dept. of Precision Instrument of Tsinghua University. It is also built on MiniGUI. As shown in Figure 4.

#### 2.5.3 Ehome

Ehome is an intelligent household appliance using Web technology. It can be used for network shopping and realty management. The client side is a simplified Web browser. Figure 5 shows the browser's interface framework and Figure 6 is the networking shopping interface of ehome.

#### 2.5.4 Others

VConGUI is a virtual console On MiniGUI as shown in Figure 7.

Bomb is a clone of M$ Windows minesweeper as shown in Figure 8.

Russia Block is the MiniGUI version of the classic PC game as shown in Figure 9.

#### 2.5.5 Multi-Font Support of MiniGUI

Figure 10 shows the multi-font support of MiniGUI.

## 3 Some Important Algorithm of MiniGUI

The following is some important algorithm concerned with GUI support system.

### 3.1 Message Transfer

The messages or events transfer is the first problem that a GUI system faces.

Commonly, a message has some kind of data associated with it. The data can have variant meaning according to message.

As a way of communication between windows, we provides several mechanisms for message transfer. In some case, when a window send a message, it will not continue until result is returned. This is called 'sending message'. While, in other cases, a window may just want to notify the target window, and it will return as soon as it finishes notification. This is called 'posting message'. There is a more complex situation. When a window is waiting for a message which may be very slow to return, the window can set a timeout value when call the sending message function so that is can resume in the case the message it send can not be handled in time. We also must pay attention to some special messages, for example, the timer. When the frequency of a timer is very high, and the speed of the handle timer expiration is very slow. When we send or post a message for the timer, the message queue will be blocked at sooner or later. The last problem is the priority. As usual, we should first consider with the message of mouse or keyboard, and then the PAINT message and timer, etc.

### 3.2 The Graphic Context and the Coordinate Mapping

#### 3.2.1 Graphics Device Context

MiniGUI adopts the graphics device context (GDC) conception that is widely used in M$ Windows and X Window. Each graphics context defines a rectangle showed on the screen of computer. When we call graphics output functions, when must specify an initialized or an existing DC. Each graphic output is forced in the rectangle area specified in the DC. In a multi-window system, the output of each graphic device is clipped in order to avoid interacting with each other.

#### 3.2.2 The Clipping Area

The clipping area is a defined area in the graphic device. Only the output within the clipping area is visible on the screen. At present, the clipping area of MiniGUI is defined as a list of no-intersected rectangles.

#### 3.2.3 The Mapping Mode

The mapping mode rules how to map the output of special DC into the device coordinate. The original of the graphics device coordinate is defined as the left-top corner of the device rectangle. The X-axis increases to the right and the Y-axis increases to the downward. This is called the device coordinate.

We can define our own logical coordinate through the mapping mode operating functions of the GDI module. The logical coordinate can be the vertical or horizontal reverse, scaling, or offset. Generally, the logical coordinate is the same as the device coordinate.

### 3.3 The Window Management

The window management is closely related to clipping. The key is the Z-order of the window. In fact, MiniGUI maintains two Z-orders, one of normal windows the other is of top-most windows.

Author: WEI Yongming (ymwei@minigui.org)
Copyright (C) 2000, WEI Yongming