從2008年年底我就一直想設計一套基于OpenGL的游戲專用GUI系統出來
當然有人說現在不是有現成的嗎?CEGUI...
使用這個當然沒什么問題
但是覺得自己開發的游戲引擎還是配備一個套自行開發的GUI系統比較好(比如irr)
當然在下面使用若干子庫(比如freetype,sigc++等等)還是沒有問題的
也是從那個時候看了很多GUI系統,比如CEGUI,MyGUI,GLOOEY,UFO GUI,UI LIB 等等
之后我開始設計了一個套GUI系統但是感覺問題多多
一個主要的問題就是沒有處理好事件
現在重新看UI系統
設計她的前置條件有
1.良好的字體渲染器
2.對象系列化
3.中文輸入.
4.其它
UI系統應該包括的內容(個人感覺)
1.UI事件
2.UI工廠(或者管理器)
3.UI控件對象(按鍵,組合框等等)
4.UI邊框(裝飾器)
5.UI布局管理器
6.其它
故從蓋莫引擎2.1.2版本起我會逐步加入新設計的GUI引擎
下面是我的開胃菜
GUI主題色
設置這個的目的是為了統一GUI控件顏色而不需要一個一個設計它
下面是實現很簡單的!
class G_DLL_API UIThemeColor : public Object
{
public:
////////////////////////////////////////////////////////
/// 獲取默認主題色
////////////////////////////////////////////////////////
static UIThemeColor GetDefaultTheme();
public:
////////////////////////////////////////////////////////
/// 構造,析構主題色
////////////////////////////////////////////////////////
UIThemeColor();
UIThemeColor(const Color &normal,const Color &disable,const Color &focus,const Color &tagged);
UIThemeColor(UIThemeColor &theme);
~UIThemeColor(){}
////////////////////////////////////////////////////////
/// 使用默認主題色
////////////////////////////////////////////////////////
void UseDefaultTheme();
////////////////////////////////////////////////////////
/// 重新設置,獲取主題色
////////////////////////////////////////////////////////
void SetThemeColor(const Color &normal,const Color &disable,const Color &focus,const Color &tagged);
void GetThemeColor(Color &normal,Color &disable,Color &focus,Color &tagged);
////////////////////////////////////////////////////////
/// 設置,獲取主題正常色
////////////////////////////////////////////////////////
void SetNormalColor(const Color &color){this->color[0] = color;}
Color GetNormalColor()const{return color[0];}
////////////////////////////////////////////////////////
/// 設置,獲取主題不可用色
////////////////////////////////////////////////////////
void SetDisableColor(const Color &color){this->color[1] = color;}
Color GetDisableColor()const{return color[0];}
////////////////////////////////////////////////////////
/// 設置,獲取主題聚焦顏色
////////////////////////////////////////////////////////
void SetFocusColor(const Color &color){this->color[2] = color;}
Color GetFocusColor()const{return color[2];}
////////////////////////////////////////////////////////
/// 設置,獲取主題(被選中的)顏色
////////////////////////////////////////////////////////
void SetTaggedColor(const Color &color){this->color[3] = color;}
Color GetTaggedColor()const{return color[3];}
private:
static UIThemeColor themecolor;
//! 當前保留一個空的顏色值
static const int themecolor_number = 5;
Color color[themecolor_number];
然后每個控件包含一個主題色對象
(當前這里認為控件有4個狀態.正常,禁止,聚焦,選中)