go language development of embedded linux (nine) on embedded GUI

go no official language of the GUI.

In fact, how should I say, demand is not how urgent this together. After all, every language has its own areas of expertise.

On the computer screen or the development of C # or java or QT's swing to the quick. No need to go non-use it, more of a web-based BS architecture mode on the computer.

On the embedded it? I study a lot of GUI, currently not found too satisfied.

The QT, LittlevGL, Guilite, awtk, Nuklear like.

The GUI how do you say? Either too large or rely a lot or the environment will get down for a long time. Some need to spend a lot of effort into learning costs.

But for our embedded applications, not much interface, and some interface is very simple ah, do not spend too much energy at the interface above. With these it is does not add up.

There are the most basic drawing points, draw lines, circle, Photo Gallery enough.

UCGUI this GUI, get embedded basically know it, the more common, open source, and simple to use. You can use the microcontroller.

So, I put UCGUI and Chinese character made a package go language.

It is also very simple to use. What interface you want, draw their own chant, anyway, not much, not fancy interface.

Some people say are too time to achieve their own right, such as the choice of awtk other ZLG, or QT, or littlegl, and GTK. But I say, do not spend the time to spend that time, in fact, end up spending almost all the time, not even his own paintings to the quick. However, if the fancy interface is very complex, it is still considering other GUI it, painted himself too hard.

Quickly and easily realize the function is the best. You do not take the time to buy and sell those GUI yet. Unless it is impossible to achieve, or more harm than good, it can be considered.

There ucGUI such as BUTTON, window like interface controls. But combined with our usage, those almost no furnishings used.

Or use the display of Chinese characters, pictures, points, lines and more.

I call to ucGUI using go do a package. And is simple to use, how easy?

E.g:

func main() {
	fmt.Println("Hello Go")
	GUI_Init()
	GUI_SetBkColor(0x954816)
	GUI_Clear()
	GUI_SetFont(&C.GUI_FontHZ20x20)

	GUI_DispStringAt("PRICE", 60, 156)

	GUI_DispStringAt("票价", 60, 120)

	name := ""
	fmt.Println("over!press any key to continue: ")
	fmt.Scanln(&name)
}

UcGUI packaging process is as follows:

package drivers

/*

#cgo CFLAGS: -Iinclude/header

#cgo LDFLAGS: -Llib -lucgui -lm
#include <stdlib.h>
#include "GUI.h"
//extern const GUI_FONT GUI_FontHZ12;
extern const GUI_FONT GUI_FontHZ20x20;
extern const GUI_FONT GUI_FontHZ32x32;
extern const GUI_FONT GUI_FontHZ76x76;

extern void GUIcache2fb(void);
extern int setGUIcache(unsigned char sta);
extern unsigned char getGUIcache(void);
*/
import "C"
import "unsafe"
import (
	"github.com/axgle/mahonia"
)

var (
	//GUI_FontHZ12    C.GUI_FONT
	GUI_FontHZ20x20 *C.GUI_FONT
	GUI_FontHZ32x32 *C.GUI_FONT
	GUI_FontHZ76x76 *C.GUI_FONT

	GUI_FONT_8_ASCII *C.GUI_FONT

	GUI_FONT_8_1        *C.GUI_FONT
	GUI_FONT_10S_ASCII  *C.GUI_FONT
	GUI_FONT_10S_1      *C.GUI_FONT
	GUI_FONT_10_ASCII   *C.GUI_FONT
	GUI_FONT_10_1       *C.GUI_FONT
	GUI_FONT_13_ASCII   *C.GUI_FONT
	GUI_FONT_13_1       *C.GUI_FONT
	GUI_FONT_13B_ASCII  *C.GUI_FONT
	GUI_FONT_13B_1      *C.GUI_FONT
	GUI_FONT_13H_ASCII  *C.GUI_FONT
	GUI_FONT_13H_1      *C.GUI_FONT
	GUI_FONT_13HB_ASCII *C.GUI_FONT
	GUI_FONT_13HB_1     *C.GUI_FONT
	GUI_FONT_16_ASCII   *C.GUI_FONT
	GUI_FONT_16_1       *C.GUI_FONT
	GUI_FONT_16_HK      *C.GUI_FONT
	GUI_FONT_16_1HK     *C.GUI_FONT
	GUI_FONT_16B_ASCII  *C.GUI_FONT
	GUI_FONT_16B_1      *C.GUI_FONT
	// GUI_FONT_20_ASCII   *C.GUI_FONT
	// GUI_FONT_20_1       *C.GUI_FONT
	// GUI_FONT_20B_ASCII  *C.GUI_FONT
	// GUI_FONT_20B_1      *C.GUI_FONT
	GUI_FONT_24_ASCII  *C.GUI_FONT
	GUI_FONT_24_1      *C.GUI_FONT
	GUI_FONT_24B_ASCII *C.GUI_FONT
	GUI_FONT_24B_1     *C.GUI_FONT
	GUI_FONT_32_ASCII  *C.GUI_FONT
	GUI_FONT_32_1      *C.GUI_FONT
	GUI_FONT_32B_ASCII *C.GUI_FONT
	GUI_FONT_32B_1     *C.GUI_FONT

	GUI_FontD48 *C.GUI_FONT

	Rect C.GUI_RECT
)

const (
	//================
	GUI_TEXTMODE_NORMAL C.int = C.GUI_TEXTMODE_NORMAL
	GUI_TEXTMODE_XOR    C.int = C.GUI_TEXTMODE_XOR
	GUI_TEXTMODE_TRANS  C.int = C.GUI_TEXTMODE_TRANS
	GUI_TEXTMODE_REV    C.int = C.GUI_TEXTMODE_REV
	GUI_TM_NORMAL       C.int = C.GUI_TM_NORMAL
	GUI_TM_XOR          C.int = C.GUI_TM_XOR
	GUI_TM_TRANS        C.int = C.GUI_TM_TRANS
	GUI_TM_REV          C.int = C.GUI_TM_REV

	//===================
	/* Text alignment flags, horizontal */
	GUI_TA_HORIZONTAL C.int = C.GUI_TA_HORIZONTAL
	GUI_TA_LEFT       C.int = C.GUI_TA_LEFT
	GUI_TA_RIGHT      C.int = C.GUI_TA_RIGHT
	GUI_TA_CENTER     C.int = C.GUI_TA_CENTER
	GUI_TA_HCENTER    C.int = C.GUI_TA_CENTER /* easier to remember :-)  */

	/* Text alignment flags, vertical */
	GUI_TA_VERTICAL C.int = C.GUI_TA_VERTICAL
	GUI_TA_TOP      C.int = C.GUI_TA_TOP
	GUI_TA_BOTTOM   C.int = C.GUI_TA_BOTTOM
	GUI_TA_BASELINE C.int = C.GUI_TA_BASELINE
	GUI_TA_VCENTER  C.int = C.GUI_TA_VCENTER

	//===================

	GUI_BLUE         C.uint = C.GUI_BLUE
	GUI_GREEN        C.uint = C.GUI_GREEN
	GUI_RED          C.uint = C.GUI_RED
	GUI_CYAN         C.uint = C.GUI_CYAN
	GUI_MAGENTA      C.uint = C.GUI_MAGENTA
	GUI_YELLOW       C.uint = C.GUI_YELLOW
	GUI_LIGHTBLUE    C.uint = C.GUI_LIGHTBLUE
	GUI_LIGHTGREEN   C.uint = C.GUI_LIGHTGREEN
	GUI_LIGHTRED     C.uint = C.GUI_LIGHTRED
	GUI_LIGHTCYAN    C.uint = C.GUI_LIGHTCYAN
	GUI_LIGHTMAGENTA C.uint = C.GUI_LIGHTMAGENTA
	GUI_LIGHTYELLOW  C.uint = C.GUI_LIGHTYELLOW
	GUI_DARKBLUE     C.uint = C.GUI_DARKBLUE
	GUI_DARKGREEN    C.uint = C.GUI_DARKGREEN
	GUI_DARKRED      C.uint = C.GUI_DARKRED
	GUI_DARKCYAN     C.uint = C.GUI_DARKCYAN
	GUI_DARKMAGENTA  C.uint = C.GUI_DARKMAGENTA
	GUI_DARKYELLOW   C.uint = C.GUI_DARKYELLOW
	GUI_WHITE        C.uint = C.GUI_WHITE
	GUI_LIGHTGRAY    C.uint = C.GUI_LIGHTGRAY
	GUI_GRAY         C.uint = C.GUI_GRAY
	GUI_DARKGRAY     C.uint = C.GUI_DARKGRAY
	GUI_BLACK        C.uint = C.GUI_BLACK
	GUI_BROWN        C.uint = C.GUI_BROWN
	GUI_ORANGE       C.uint = C.GUI_ORANGE
	GUI_TRANSPARENT  C.uint = C.GUI_TRANSPARENT

	TOP_BAR_COLOR C.uint = 0x501f08

	GUI_IdleColor C.uint = 0x954816
)

func init() {
	//GUI_FontHZ12 = C.GUI_FontHZ12
	GUI_FontHZ20x20 = &C.GUI_FontHZ20x20
	GUI_FontHZ32x32 = &C.GUI_FontHZ32x32
	GUI_FontHZ76x76 = &C.GUI_FontHZ76x76

	GUI_FONT_8_1 = &C.GUI_Font8_1
	GUI_FONT_10S_ASCII = &C.GUI_Font10S_ASCII

	GUI_FONT_10S_1 = &C.GUI_Font10S_1
	GUI_FONT_10_ASCII = &C.GUI_Font10_ASCII
	GUI_FONT_10_1 = &C.GUI_Font10_1
	GUI_FONT_13_ASCII = &C.GUI_Font13_ASCII
	GUI_FONT_13_1 = &C.GUI_Font13_1
	GUI_FONT_13B_ASCII = &C.GUI_Font13B_ASCII
	GUI_FONT_13B_1 = &C.GUI_Font13B_1
	GUI_FONT_13H_ASCII = &C.GUI_Font13H_ASCII
	GUI_FONT_13H_1 = &C.GUI_Font13H_1
	GUI_FONT_13HB_ASCII = &C.GUI_Font13HB_ASCII
	GUI_FONT_13HB_1 = &C.GUI_Font13HB_1
	GUI_FONT_16_ASCII = &C.GUI_Font16_ASCII
	GUI_FONT_16_1 = &C.GUI_Font16_1
	GUI_FONT_16_HK = &C.GUI_Font16_HK
	GUI_FONT_16_1HK = &C.GUI_Font16_1HK
	GUI_FONT_16B_ASCII = &C.GUI_Font16B_ASCII
	GUI_FONT_16B_1 = &C.GUI_Font16B_1
	//GUI_FONT_20_ASCII   = &C.GUI_Font20_ASCII
	//GUI_FONT_20_1       = &C.GUI_Font20_1
	//GUI_FONT_20B_ASCII  = &C.GUI_Font20B_ASCII
	//GUI_FONT_20B_1      = &C.GUI_Font20B_1
	GUI_FONT_24_ASCII = &C.GUI_Font24_ASCII
	GUI_FONT_24_1 = &C.GUI_Font24_1
	GUI_FONT_24B_ASCII = &C.GUI_Font24B_ASCII
	GUI_FONT_24B_1 = &C.GUI_Font24B_1
	GUI_FONT_32_ASCII = &C.GUI_Font32_ASCII
	GUI_FONT_32_1 = &C.GUI_Font32_1
	GUI_FONT_32B_ASCII = &C.GUI_Font32B_ASCII
	GUI_FONT_32B_1 = &C.GUI_Font32B_1

	GUI_FontD48 = &C.GUI_FontD48

}

func GUI_Init() {
	C.GUI_Init()
}
func GUI_Clear() {
	C.GUI_Clear()
}

func GUI_SetColor(val C.uint) {
	C.GUI_SetColor(C.ulong(val))
}

func GUI_SetBkColor(val C.uint) {
	C.GUI_SetBkColor(C.ulong(val))
}

func GUI_SetFont(val *C.struct_GUI_FONT) {
	C.GUI_SetFont(val)
}

//注:go中的编码为utf-8,GUI显示汉字使用的GB2312
func GUI_DispStringAt(str string, x, y int) {

	enc := mahonia.NewEncoder("gbk")

	gbk := enc.ConvertString(str)
	cs := C.CString(gbk)
	defer C.free(unsafe.Pointer(cs))
	C.GUI_DispStringAt(cs, C.int(x), C.int(y))

}

func GUI_DispStringHCenterAt(str string, x, y int) {
	enc := mahonia.NewEncoder("gbk")

	gbk := enc.ConvertString(str)
	cs := C.CString(gbk)
	defer C.free(unsafe.Pointer(cs))
	C.GUI_DispStringHCenterAt(cs, C.int(x), C.int(y))
}

func GUI_FillRect(x0, y0, x1, y1 int) {
	C.GUI_FillRect(C.int(x0), C.int(y0), C.int(x1), C.int(y1))
}

func SetRectAera(x0, y0, x1, y1 int) C.GUI_RECT {
	var rClient C.GUI_RECT

	rClient.x0 = C.short(x0)
	rClient.y0 = C.short(y0)
	rClient.x1 = C.short(x1)
	rClient.y1 = C.short(y1)

	return rClient
}

func GUI_DispStringInRect(str string, rect *C.GUI_RECT, align C.int) {

	enc := mahonia.NewEncoder("gbk")

	gbk := enc.ConvertString(str)
	cs := C.CString(gbk)
	defer C.free(unsafe.Pointer(cs))
	C.GUI_DispStringInRect(cs, rect, align)

}
func GUI_SetTextMode(mode C.int) {
	C.GUI_SetTextMode(mode)
}

func GUIcache2fb() {
	C.GUIcache2fb()
}

func SetGUIcache(sta int) {
	C.setGUIcache(C.uchar(sta))
}

func GetGUIcache() int {
	return int(C.getGUIcache())
}

/*
func main() {
	fmt.Println("Hello Go")
	GUI_Init()
	GUI_SetBkColor(0x954816)
	GUI_Clear()
	GUI_SetFont(&C.GUI_FontHZ20x20)

	GUI_DispStringAt("PRICE", 60, 156)

	GUI_DispStringAt("票价", 60, 120)

	name := ""
	fmt.Println("over!press any key to continue: ")
	fmt.Scanln(&name)
}
*/

Finally to say, how to use it? Other people want to use, then certainly not up and running, because ucgui.so not find this library file.

Then the library come from?

According to their needs and platform, cross-compiler source code ucgui it, compiled as ucgui.so. Missing fonts can be packaged into their own.

 

 

 

Published 125 original articles · won praise 165 · views 380 000 +

Guess you like

Origin blog.csdn.net/qq8864/article/details/101705966