Original, reprinted please indicate the source. Copyright (c) 2011
Dingmaotu (http://blog.163.com/dingmaotu@126)
1. Introduction
Fltk is a lightweight C ++ interface library whose name is fast light toolkit. The features and advantages of fltk are light: small size, static connection, and graphic interface function only. However, its widgets (or control) refer to buttons and text boxes. Here I call them "controls") are rich, from simple buttons and input boxes (fl_input) until the fl_gl_window of OpenGL is integrated, there are many types. It also comes with a fluid graphic interface designer, which is a bit like a super lightweight VB6, which is very convenient for small programs.
The basic idea of fltk is to abstract the most basic graph rendering functions of a platform (such as painting points, lines, and pixel BLT) to achieve cross-platform implementation, all other graphic elements are drawn by themselves using these basic functions. Therefore, cross-platform interface libraries such as fltk, QT, and GTK + are the same as those of directui. If there are good designers, it is easy to use fltk to implement beautiful interfaces, but fltk's widgets is rather ugly.
Because of its small size and simple design, fltk is used by many embedded developers. In this series, I mainly talk about desktop Development (I have no embedded experience ).
2. Design and version
The Design of fltk is not good. It uses a large number of global variables and the naming is ugly. But it is very practical in general and easy to learn. Fltk has several versions in total, of which version 1.1 is the most stable and has stopped development, but does not support Unicode and internationalization, so it is a bit difficult to process Chinese. 1.3 is currently the most active development, and Unicode is supported through UTF-8, and the latest version has the option dedicated to cp936 (not many Chinese users ?). Rc7 was released two days ago, and the final version will be released in a few days. Currently, 1.3 is recommended. 2. version X is designed to improve the original design. It uses namespace and is much more comfortable to name. However, it lacks many features compared to 1.3 and is relatively inactive in development, because after 1.3, fltk3 is about to begin development. We need to combine Series 1 and Series 2 to design a new architecture, and the source code is compatible with 1 and 2 (Amazing, huh ?).
3. Comment
Fltk is an ideal pure interface library for C ++. It is easy to learn. You can learn how to use C ++ to write graphics programs when getting started with C ++. If it is a large program, I suggest using QT. QT is not only an interface library, it contains all aspects (parallel, database, network, etc.), but also very professional, it can be regarded as a cross-platform General C ++ library, just as JAVA supports Java platform and C ++ supports QT. QT is perfect except for being a little bigger. However, the C ++ standard programming style tends to be generic, which is very different from the Java series. So now I want to learn the standard library and use boost. Boost is not only bulky, but not fully functional without QT, but promising. Now there is a lack of boost. UI. I feel that if fltk is re-designed to conform to the generic style, it is suitable to act as the boost: Ui role.
4. Download and install
In Linux, It is very convenient to install anything. In most cases, someone has packed the package. Even if you download the source code and compile it yourself, it is convenient to use the common configure, make, make install. In Windows, you need to compile it yourself. If Visual Studio is used, open and compile the project files vc6, vc2008, and vc2010 under the IDE directory. However, I am using the msys + mingw environment, so the compilation method is the same as that of Linux. The source code package contains detailed download and installation instructions for various platforms. Here, we will only give a brief description of my environment.
We recommend that you do not use VC at the beginning to learn C ++, but be familiar with the command line. In Windows, msys + mingw is a good choice. We recommend that you download the latest mingw compiler and msys from nuwen.net. The release comes with many useful libraries, including boost, which are suitable for beginners. The installation and configuration of this compiler are not mentioned here. Please solve it by yourself (maybe I will write a related tutorial in the future ).
In addition, you need to select a good editor. notepad ++ is a good choice in windows. Otherwise, reading many text files is inconvenient (for example, many readme files are in UNIX format and cannot be recognized by common editors, it cannot display line breaks, a mess ). In addition, people with energy can choose vim or Emacs, which is easy to integrate into msys. I will use the Emacs 24 beta version here.
First download the source code package, decompress it to a directory (I became fltk_src), and switch to the directory:
Configure -- Help
Check the options. For example, if you want to enable or disable a feature, note that cp936 is disabled by default and needs to be enabled, but UTF-8 is generally enough, if the source code is saved in UTF-8 format. Then -- prefix = installation directory. The default value is/usr/local/. In msys, it is the local folder of the msys root directory, so the default value is quite good. Generally, all compiled and installed libraries are put in this directory, which is easy to delete. Do not directly load these libraries into the root directory of the mingw compiler and mix them together. Because the default options are sufficient
Configure
After the execution is completed
Make & make
Install
The/usr/local/installed on the necessary files will be compiled and compiled, where/usr/local/bincontains fluid.exe (Interface Designer) and fltk-config (options are provided for the compiler during compilation ), /usr/local/include/FL/contains the header file, and/usr/local/LIB contains the relevant static Connection Library (fltk is very small and does not need to be compiled into DLL ), /usr/local/share/doc/examples is the source code of some examples.
In fact, in the test and examples of the source code directory, there are some examples of source code worth learning. The programs in test are compiled. You can open the test/demo.exe program, let's see what the fltk program looks like.