| 
 | 
 
1.先说下Ui的input部分 
在GUI部分输入输出通常是需要采用回调函数来处理的 
比如: 
 
void G_CALL MousePosCallBack(int x,int y) 
{ 
    UIWidgetManager::Instance().OnMouseMove(x, y); 
}所以我就先给引擎的Input部分加入了几个输入输出回调函数以方便使用 
 
2.然后上几个UI小图 
 
  
  
  
相关的代码: 
void RenderGUI(); 
 
RefPtr<Device> device; 
RefPtr<Input>  input; 
Panel *panel = NULL;  
ProgressBar *progressbar = NULL; 
Button *button1 = NULL; 
Button *button2 = NULL; 
Button *button3 = NULL; 
Button *button4 = NULL;  
  
void G_CALL MouseStateCallBack(int mouse,int action) 
{ 
    int x,y; 
    input->GetMousePosition(x,y);  
    if(action == KEY_PRESS && mouse == MOUSE_BUTTON_LEFT) 
    { 
        UIWidgetManager::Instance().OnLeftButtonDown(x,y);           
    } 
    else if(action == KEY_PRESS && mouse == MOUSE_BUTTON_RIGHT) 
    { 
        UIWidgetManager::Instance().OnRightButtonDown(x,y);   
    } 
    else if(action == KEY_RELEASE && mouse == MOUSE_BUTTON_LEFT) 
    { 
        UIWidgetManager::Instance().OnLeftButtonUp(x,y);  
    } 
    else if(action == KEY_RELEASE && mouse == MOUSE_BUTTON_RIGHT) 
    { 
        UIWidgetManager::Instance().OnRightButtonUp(x,y);     
    } 
} 
 
void G_CALL MousePosCallBack(int x,int y) 
{ 
    UIWidgetManager::Instance().OnMouseMove(x, y); 
} 
  
bool G_CALL IsShiftPressed() 
{ 
    return false; 
} 
 
bool G_CALL IsAltPressed() 
{ 
    return false; 
} 
 
bool G_CALL IsCtrlPressed() 
{ 
    return false;  
}  
 
void SettingPanel(); 
 
int main() 
{ 
    device = InitDevice("UI测试1"); 
    input = device->GetInput(); 
    input->AttachMouseState(&MouseStateCallBack); 
    input->AttachMousePos(&MousePosCallBack); 
    core::TextDesc::SetDefaultFont(engine_string("simhei.ttf")); 
     
    UIWidgetManager::Instance().Initialize(&IsShiftPressed,&IsAltPressed,&IsCtrlPressed); 
    UIWidgetManager::Instance().AppResized(640,480); 
    SettingPanel(); 
    BEGIN_LOOP(device) 
       glClearColor(0.1,0.1,0.2,1.0f); 
       glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );    
       RenderGUI();     
    END_LOOP(device) 
     
    return 0; 
} 
 
void SettingPanel() 
{ 
    panel = new Panel(Rectf(10,75,180,180),NULL); 
     
    button1 = new Button(panel,L"寮€?娓告?); 
    button2 = new Button(panel,L"淇?瀛?娓告??"); 
    button3 = new Button(panel,L"杞藉?ユ父??"); 
    button4 = new Button(panel,L"?€?烘父?); 
    progressbar = new ProgressBar(panel,Rectf(150,90,40,220),UI_DIRECTION_VERTICAL); 
    progressbar->SetPercentage(65.0f); 
       
    panel->AddChildWidget(button1); 
    panel->AddChildWidget(button2); 
    panel->AddChildWidget(button3); 
    panel->AddChildWidget(button4); 
  
    panel->AddChildWidget(progressbar); 
     
    button1->SetSize(Vector2f(120,40)); 
    button2->SetSize(Vector2f(120,40)); 
    button3->SetSize(Vector2f(120,40)); 
    button4->SetSize(Vector2f(120,40)); 
    button1->SetPosition(Vector2f(20,90)); 
    button2->SetPosition(Vector2f(20,150)); 
    button3->SetPosition(Vector2f(20,210)); 
    button4->SetPosition(Vector2f(20,270));   
     
    UIWidgetManager::Instance().AddWidget(panel);       
} 
 
void RenderGUI() 
{ 
    float precent = progressbar->GetPercentage(); 
    precent += 1.0f; 
    if(precent >= 100.0f) 
        precent = 0.0f; 
    progressbar->SetPercentage(precent);     
    UIWidgetManager::Instance().Update();       
} 
 
 
 
对于UI部分基本上所有的常见器件都需要一个一个设计 
一次性做完太难了 
而且设计的不好就需要重新设计 
所以我决定先设计以下几个器件 Widget,Panel,StaticText,SliderBar 
其余的等把基本框架做成熟了再做吧 
 |   
 
 
 
 |