Example #1
0
//-------------------------------------------------------------------------------
void MaterialViewer::onClickApply(MyGUI::WidgetPtr)
{
    //Update properties.
    MyGUI::EnumeratorWidgetPtr iter = mWindow->getEnumerator();
    while (iter.next())
    {
        MyGUI::Widget *widget = iter.current();
        if (widget->getUserString("type") == "MaterialProperty") 
            mMaterialSettings[widget->getUserString("property")] = dynamic_cast<MyGUI::Edit*>(widget)->getOnlyText();
    }
    MyGUI::ComboBoxPtr list = GlbVar.gui->findWidget<MyGUI::ComboBox>("cmb_materialType");
    mMaterialType = list->getItemNameAt(list->getIndexSelected());
    
    //Compile.
    compileMaterial();
}
Example #2
0
void VBox::align ()
{
    unsigned int count = getChildCount ();
    size_t v_stretched_count = 0;
    int total_height = 0;
    int total_width = 0;
    std::vector< std::pair<MyGUI::IntSize, bool> > sizes;
    for (unsigned int i = 0; i < count; ++i)
    {
        MyGUI::Widget* w = getChildAt(i);
        bool vstretch = w->getUserString ("VStretch") == "true";
        v_stretched_count += vstretch;
        AutoSizedWidget* aw = dynamic_cast<AutoSizedWidget*>(w);
        if (aw)
        {
            sizes.push_back(std::make_pair(aw->getRequestedSize (), vstretch));
            total_height += aw->getRequestedSize ().height;
            total_width = std::max(total_width, aw->getRequestedSize ().width);
        }
        else
        {
            sizes.push_back (std::make_pair(w->getSize(), vstretch));
            total_height += w->getSize().height;

            if (!(w->getUserString("HStretch") == "true"))
                total_width = std::max(total_width, w->getSize().width);
        }

        if (i != count-1)
            total_height += mSpacing;
    }

    if (mAutoResize && (total_width+mPadding*2 != getSize().width || total_height+mPadding*2 != getSize().height))
    {
        setSize(MyGUI::IntSize(total_width+mPadding*2, total_height+mPadding*2));
        return;
    }


    int curY = 0;
    for (unsigned int i = 0; i < count; ++i)
    {
        if (i==0)
            curY += mPadding;

        MyGUI::Widget* w = getChildAt(i);

        bool hstretch = w->getUserString ("HStretch") == "true";
        int width = hstretch ? total_width : sizes[i].first.width;

        MyGUI::IntCoord widgetCoord;
        widgetCoord.top = curY;
        widgetCoord.left = mPadding + (getSize().width-mPadding*2 - width) / 2;
        int height = sizes[i].second ? sizes[i].first.height + (getSize().height-mPadding*2 - total_height)/v_stretched_count
                     : sizes[i].first.height;
        widgetCoord.height = height;
        widgetCoord.width = width;
        w->setCoord(widgetCoord);
        curY += height;

        if (i != count-1)
            curY += mSpacing;
    }
}
Example #3
0
//-------------------------------------------------------------------------------
void MaterialViewer::init()
{
    //Create the mesh.
    mNode = GlbVar.ogreSmgr->getRootSceneNode()->createChildSceneNode("materialcube-node");
    mEntity = GlbVar.ogreSmgr->createEntity("materialcube-entity", "Mesh_Cube.mesh");
    mNode->attachObject(mEntity);

    //Camera.
    mCameraYawNode = GlbVar.ogreSmgr->getRootSceneNode()->createChildSceneNode("materialviewercamera-yawnode");
    mCameraPitchNode = mCameraYawNode->createChildSceneNode("materialviewercamera-pitchnode");
    mCameraDist = 3;

    //Some test settings.
    mMaterialType = "BaseNormalMapParallax";
    mMaterialSettings["diffuse_tex"] = "WhiteTile1.png";
    mMaterialSettings["normal_tex"] = "WhiteTile_NM.png";
    mMaterialSettings["glow_tex"] = "WhiteLight_GW.png";

    mMaterialSettings["ambient"] = "0.7 0.7 0.7 1";
    mMaterialSettings["diffuse"] = "0.9 0.9 0.9 1";
    mMaterialSettings["specular"] = "0.8 0.8 0.8 1";
    mMaterialSettings["scaleBias"] = "0.04 0.02";
    mMaterialSettings["glow_amount"] = "0.5";

    //First compile.
    compileMaterial();

    //Load the layout.
    MyGUI::LayoutManager::getInstance().loadLayout("MaterialViewer.layout");
    mWindow = GlbVar.gui->findWidget<MyGUI::Window>("win_materialViewer");

    //Callbacks.
    MyGUI::ButtonPtr button = GlbVar.gui->findWidget<MyGUI::Button>("but_applyMaterial");
    button->eventMouseButtonClick += MyGUI::newDelegate(this, &MaterialViewer::onClickApply);

    button = GlbVar.gui->findWidget<MyGUI::Button>("but_saveMaterial");
    button->eventMouseButtonClick += MyGUI::newDelegate(this, &MaterialViewer::onClickSave);

    button = GlbVar.gui->findWidget<MyGUI::Button>("but_createLight");
    button->eventMouseButtonClick += MyGUI::newDelegate(this, &MaterialViewer::onClickCreateLight);

    //Update the editboxes.
    MyGUI::EnumeratorWidgetPtr iter = mWindow->getEnumerator();
    while (iter.next())
    {
        MyGUI::Widget *widget = iter.current();
        if (widget->getUserString("type") == "MaterialProperty") 
            dynamic_cast<MyGUI::Edit*>(widget)->setOnlyText(mMaterialSettings[widget->getUserString("property")]);
    }
    GlbVar.gui->findWidget<MyGUI::Edit>("edt_lightColour")->setOnlyText("0.7 0.7 0.7");

    //Populate the material type list.
    MyGUI::ComboBoxPtr list = GlbVar.gui->findWidget<MyGUI::ComboBox>("cmb_materialType");
    list->insertItemAt(0, "Base");
    list->insertItemAt(1, "BaseNormalMap");
    list->insertItemAt(2, "BaseNormalMapParallax");
    list->insertItemAt(3, "BaseGlow");
    list->insertItemAt(4, "BaseNormalMapGlow");
    list->insertItemAt(5, "BaseNormalMapParallaxGlow");
    list->insertItemAt(6, "BaseTransparent");
    list->setIndexSelected(2);
}