游戏开发论坛

 找回密码
 立即注册
搜索
查看: 3996|回复: 0

盖莫游戏引擎-GUI-小图

[复制链接]

56

主题

94

帖子

98

积分

注册会员

Rank: 2

积分
98
发表于 2010-6-19 18:10:00 | 显示全部楼层 |阅读模式
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
其余的等把基本框架做成熟了再做吧
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2025-7-1 18:46

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表