Exemple #1
0
bool PorkerTestCase::Initialize(UIScreen* pUIScreen)
{
	m_pBackGroundImagePiece = IResourceMgr::GetInstance().FindImagePiece("backgorund");
	if(!m_pBackGroundImagePiece) return false;
	
	m_pTile = new Tile(m_pBackGroundImagePiece);
	m_pRootNode = IResourceMgr::GetInstance().CreateRootNode();
	m_pRootNode->AttachObject(m_pTile);

	UIButton* pButtonNormal = new UIButton(pUIScreen);
	pButtonNormal->SetText("Normal");
	pButtonNormal->ConnectEvent(UMI_CLICKED, this, (MSG_CALLBACK)&PorkerTestCase::OnNormalButtonClicked);

	UIButton* pButtonGray = new UIButton(pUIScreen);
	pButtonGray->SetText("Gray");
	pButtonGray->SetPosition(0.0f, 60.0f);
	pButtonGray->ConnectEvent(UMI_CLICKED, this, (MSG_CALLBACK)& PorkerTestCase::OnGrayButtonClicked);
	return true;
}
SampleSelector::SampleSelector(Context* context) :
    Object(context)
{
    UIView* view = FeatureExamples::GetUIView();

    UILayout* rootLayout = new UILayout(context_);
    rootLayout->SetAxis(UI_AXIS_Y);
    rootLayout->SetRect(view->GetRect());
    view->AddChild(rootLayout);

    const char* examples[] = {
        "Hello World",
        "Hello GUI",
        "Render to Texture",
        "2D Sprite",
        "2D Physics",
        "2D Constraints",
        "2D Rope",
        "2D Spriter Animation",
        "3D Static Scene",
        "3D Animating Scene",
        "3D Light Animation",
        "3D Billboards",
        "3D Particles",
        "3D Physics",
        "3D Skeletal Animation",
        "3D Decals",
        "3D Character",
        "3D Dynamic Geometry",
        "3D Ragdolls",
        "3D Vehicle Demo",
        "3D Crowd Navigation",
        "3D Water",
        "3D Multiple Viewports"
    };

    for (size_t i = 0; i < sizeof(examples) / sizeof(examples[0]); i++)
    {
        UIButton* button = new UIButton(context_);
        button->SetLayoutMinWidth(128);
        button->SetText(examples[i]);
        button->SetId(examples[i]);
        button->SubscribeToEvent(button, E_WIDGETEVENT, ATOMIC_HANDLER(SampleSelector, HandleWidgetEvent));
        rootLayout->AddChild(button);
    }

    Input* input = GetSubsystem<Input>();
    input->SetMouseVisible(true);
    input->SetMouseMode(MM_FREE);

    // Subscribe key up event
    SubscribeToEvent(E_KEYUP, ATOMIC_HANDLER(SampleSelector, HandleKeyUp));

    context->RegisterSubsystem(this);
}
Exemple #3
0
void HelloGUI::CreateDraggableFish()
{
    ResourceCache* cache = GetSubsystem<ResourceCache>();
    Graphics* graphics = GetSubsystem<Graphics>();

    // Create a draggable Fish button
    Button* draggableFish = new Button(context_);
    draggableFish->SetTexture(cache->GetResource<Texture2D>("Textures/UrhoDecal.dds")); // Set texture
    draggableFish->SetBlendMode(BLEND_ADD);
    draggableFish->SetSize(128, 128);
    draggableFish->SetPosition((graphics->GetWidth() - draggableFish->GetWidth()) / 2, 200);
    draggableFish->SetName("Fish");
    uiRoot_->AddChild(draggableFish);

    // Add a tooltip to Fish button
 //   ToolTip* toolTip = new ToolTip(context_);
 //   draggableFish->AddChild(toolTip);
 //   toolTip->SetPosition(IntVector2(draggableFish->GetWidth() + 5, draggableFish->GetWidth() / 2)); // slightly offset from close button

 //   BorderImage* textHolder = new BorderImage(context_);
 //   toolTip->AddChild(textHolder);
 //   textHolder->SetStyle("ToolTipBorderImage");
 //   
	//Text* toolTipText = new Text(context_);
 //   textHolder->AddChild(toolTipText);
 //   toolTipText->SetStyle("ToolTipText");
 //   toolTipText->SetText("Please drag me!");

	//////////////////////////////////////////////////////////////////////////
	SpriteSheet2D* playerSheet = cache->GetResource<SpriteSheet2D>("Urho2D/height_864/Razor.plist", false);

	UIButton::SetDefaultSkin(playerSheet, "a26.png", "a20.png", "a15.png", "a12.png");
	UIButton::RegisterObject(context_);

	//
	UIButton* testButton = new UIButton(context_);
	testButton->SetPosition(100, 100);
	
	uiRoot_->AddChild(testButton);
	testButton->SetText("test");
	testButton->SetToolTip("Click me.......................");

    // Subscribe draggableFish to Drag Events (in order to make it draggable)
    // See "Event list" in documentation's Main Page for reference on available Events and their eventData
    SubscribeToEvent(draggableFish, E_DRAGBEGIN, HANDLER(HelloGUI, HandleDragBegin));
    SubscribeToEvent(draggableFish, E_DRAGMOVE, HANDLER(HelloGUI, HandleDragMove));
    SubscribeToEvent(draggableFish, E_DRAGEND, HANDLER(HelloGUI, HandleDragEnd));
}