//----------------------------------------------------------------------------
bool GamePlayApp::OnIdle ()
{
	bool odle = Application::OnIdle();
	if (!odle)
		return false;

	if (IsIsInBackground())
		return false;

	if (!mIsProjectCreated)
		return false;

	Project *proj = Project::GetSingletonPtr();
	if (!proj)
		return false;

	Scene *scene = proj->GetScene();

	UIView *uiView = PX2_UIM.GetDefaultView();

	if (mRenderer->PreDraw())
	{
		mRenderer->SetViewport(0, 0, mWidth, mHeight);
		
		mRenderer->InitRenderStates();
		mRenderer->ClearBuffers();

		// scene
		if (scene)
		{
			mRenderer->SetCamera(scene->GetCameraActor()->GetCamera());
			scene->CallRendererSetViewport();
			mRenderer->Draw(scene->GetCuller().GetVisibleSet().Sort());
		}

		// ui
		if (uiView && proj->IsShowUI())
		{
			mRenderer->InitRenderStates();
			mRenderer->ClearDepthBuffer();

			CameraPtr beforeCam = mRenderer->GetCamera();

			mRenderer->SetCamera(uiView->GetCamera());
			uiView->CallRendererSetViewport ();
			mRenderer->Draw(uiView->GetCuller().GetVisibleSet().Sort());
			if (proj->IsShowProjectInfo())
			{				
				DrawInfo(uiView->GetCamera());
			}

			mRenderer->SetCamera(beforeCam);
		}

		mRenderer->PostDraw();
		mRenderer->DisplayColorBuffer();
	}

	return true;
}
示例#2
0
void UIView::setLocalPosition(float x, float y)
{
	UIView* parent = getParent();
	if(parent)
	{
		setPosition(parent->getPosition() + vec2(x,y));
	}
}
示例#3
0
vec2 UIView::getLocalPosition()
{
	UIView* parent = getParent();
	
	if(!parent)
		return vec2(0.f, 0.f);

	return getPosition() - parent->getPosition();
}
示例#4
0
/// Destroys the control and removes from the hierarchy
void UIView::destroy()
{
	UIView* parent = getParent();
	if(parent)
	{
		// I can remove myself from my parent's list
		parent->destroyChild(this);
	}
}
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);
}
示例#6
0
/// Check if any of the children items are expandible (subtrees)
bool UIComponentTreeView::isSubTree(int index)
{
	UIView* item = mParent->getChild(index);

	for(size_t i = 0; i < item->getChildCount(); ++i)
	{
		if(item->getChild(i)->getComponent<UIComponentTreeView>())
			return true;
	}

	return false;
}
示例#7
0
//----------------------------------------------------------------------------
void UICurveGroup::OnChildUIAfterPicked(int info,Movable *child)
{
	if (mBackground == child)
	{
		UIView *view = UIManager::GetSingleton().GetUIView("CurveEditWindow");
		int pickedSize = (int)view->GetPickedPicBoxs().size();
		if (1 == pickedSize)
		{
			EditSystem::GetSingleton().GetCurveEdit()
				->SetSelectedUICurveGroup(this);
		}
	}
}
示例#8
0
/// Creates a new UIView, names it and attaches it as a child, then returns it
UIView* UIView::createChild(const String& name)
{
	// Instance a new view
	UIView* view = new UIView();
	view->setName(name);
	view->setPosition(getPosition());

	//view->addComponent(new UIComponentDebugColor(Color(100,100,100,100)));

	// Attach
	attach(view);

	return view;
}
示例#9
0
void Pi::HandleEscKey()
{
	if (currentView != 0) {
		if (currentView == Pi::game->GetSectorView()) {
			SetView(Pi::game->GetWorldView());
		} else if ((currentView == Pi::game->GetSystemView()) || (currentView == Pi::game->GetSystemInfoView())) {
			SetView(Pi::game->GetSectorView());
		} else {
			UIView *view = dynamic_cast<UIView *>(currentView);
			if (view) {
				// checks the template name
				const char *tname = view->GetTemplateName();
				if (tname) {
					if (!strcmp(tname, "GalacticView")) {
						SetView(Pi::game->GetSectorView());
					} else if (!strcmp(tname, "InfoView") || !strcmp(tname, "StationView")) {
						SetView(Pi::game->GetWorldView());
					}
				}
			}
		}
	}
}
示例#10
0
void UIComponentTreeView::updateItemPositions()
{
	float offset_y = 0.f;
	for(size_t i = 0; i < mParent->getChildCount(); ++i)
	{
		UIView* child = mParent->getChild(i);
		child->setPosition(child->getPosition().x, mParent->getPosition().y + offset_y);

		offset_y += child->getSize().y + 2.f;

		if(mSubTreeView)
		{
			Log("Child %d sizeY %f stays at %f", i, child->getSize().y, child->getPosition().y);
		}
	}
}
示例#11
0
void UIView::setFrame(UIRect frame)
{
    UIRect curRect, origRect;

    curRect.width = _bounds.width;
    curRect.height = _bounds.height;
    curRect.x = _center.x - _bounds.width / 2.0f;
    curRect.y = _center.y - _bounds.height / 2.0f;

    origRect = curRect;

    curRect = frame;

    if ( _autoresizeSubviews && _subviews != NULL ) {
        if ( curRect.width != origRect.width || curRect.height != origRect.height ) {
            CGSize delta, parentSize;

            delta.width = curRect.width - origRect.width;
            delta.height = curRect.height - origRect.height;
            parentSize.width = curRect.width;
            parentSize.height = curRect.height;

            int count = _subviews->count();

            //  Go through each subview and resize it
            for ( int i = 0; i < count; i ++ ) {
                UIView *subview = (UIView *) _subviews->objectAtIndex(i);

                if ( subview->_autoresizingMask == UIViewAutoresizingNone ) continue;
                
                UIRect curFrame, origFrame;
                curFrame = subview->getFrame();
                origFrame = curFrame;

                float left, middle, right, hdivision = 0.0f, numdivisions;

                left = curFrame.x;
                middle = curFrame.width;
                right = parentSize.width - (left + middle);

                numdivisions = 0.0f;
                if (subview->_autoresizingMask & UIViewAutoresizingFlexibleLeftMargin ) {
                    hdivision += left;
                    numdivisions += 1.0f;
                }
                if ( subview->_autoresizingMask & UIViewAutoresizingFlexibleWidth ) {
                    hdivision += middle;
                    numdivisions += 1.0f;
                }
                if ( subview->_autoresizingMask & UIViewAutoresizingFlexibleRightMargin ) {
                    hdivision += right;
                    numdivisions += 1.0f;
                }

                if (subview->_autoresizingMask & UIViewAutoresizingFlexibleLeftMargin ) {
                    if ( hdivision != left && hdivision != 0.0f ) {
                        curFrame.x += delta.width * left / hdivision;
                    } else {
                        curFrame.x += delta.width / numdivisions;
                    }
                }
                if ( subview->_autoresizingMask & UIViewAutoresizingFlexibleWidth ) {
                    if ( hdivision != middle && hdivision != 0.0f ) {
                        curFrame.width += delta.width * middle / hdivision;
                    } else {
                        curFrame.width += delta.width / numdivisions;
                    }
                }

                float top, height, bottom, vdivision = 0.0f;

                top = curFrame.y;
                height = curFrame.height;
                bottom = parentSize.height - (top + height);
                
                numdivisions = 0.0f;
                if (subview->_autoresizingMask & UIViewAutoresizingFlexibleTopMargin ) {
                    vdivision += top;
                    numdivisions += 1.0f;
                }
                if ( subview->_autoresizingMask & UIViewAutoresizingFlexibleHeight ) {
                    vdivision += height;
                    numdivisions += 1.0f;
                }
                if ( subview->_autoresizingMask & UIViewAutoresizingFlexibleBottomMargin ) {
                    vdivision += bottom;
                    numdivisions += 1.0f;
                }

                if (subview->_autoresizingMask & UIViewAutoresizingFlexibleTopMargin ) {
                    if ( vdivision != top && vdivision != 0.0f ) {
                        curFrame.y += delta.height * top / vdivision;
                    } else {
                        curFrame.y += delta.height / numdivisions;
                    }
                }
                if ( subview->_autoresizingMask & UIViewAutoresizingFlexibleHeight ) {
                    if ( vdivision != height && vdivision != 0.0f ) {
                        curFrame.height += delta.height * height / vdivision;
                    } else {
                        curFrame.height += delta.height / numdivisions;
                    }
                }

                curFrame.x = floorf(curFrame.x);
                curFrame.y = floorf(curFrame.y);
                curFrame.width = ceilf(curFrame.width);
                curFrame.height = ceilf(curFrame.height);

                subview->setFrame(curFrame);
            }
        }
    }

    _bounds.width = curRect.width;
    _bounds.height = curRect.height;
    _center.x = curRect.x + curRect.width / 2.0f;
    _center.y = curRect.y + curRect.height / 2.0f;
}
示例#12
0
/// This is called ONLY when a new item is added to the tree view
/// All items added are in the same level in the tree
void UIComponentTreeView::onChildAttached(UIView* child)
{
	Log("CHILD ADDED %s", child->getName().c_str());

	// Immediately set this children to its right spot
	float offsetY = 0.f;
	for(size_t i = 0; i < mParent->getChildCount(); ++i)
	{
		offsetY += mParent->getChild(i)->getSize().y + 2.f;
	}
	if(mSubTreeView)
		child->setRect(mParent->getPosition().x, mParent->getPosition().y + offsetY, mParent->getSize().x, mLineHeight);
	else
		child->setRect(mParent->getPosition().x, mParent->getPosition().y + offsetY, mParent->getSize().x, mLineHeight);	

	//if(mSubTreeLevel == 1)
	//	child->addComponent(new UIComponentDebugColor(Color::Grass));
	//if(mSubTreeLevel == 0)
		//child->addComponent(new UIComponentDebugColor(Color::Blue));
	//if(mSubTreeLevel == 2)
	//	child->addComponent(new UIComponentDebugColor(Color::Bittersweet));

	// All children added to a tree view become TreeViewItem, whether they are collapsible or not
	child->addComponent(new UIComponentTreeViewItem());

	child->onNewChild.connect(sigc::bind(sigc::mem_fun(this, &UIComponentTreeView::onChildAddedToChild), child));

	// I want to be informed when any of the items change size to reposition things..
	//child->onSizeChanged.connect(sigc::mem_fun(this, &UIComponentTreeView::updateItemPositions));

	child->mPadding.left = (mSubTreeLevel + 1) * 20.f;

	// If this is a subgroup tree view, needs to expand and shrink
	if(mSubTreeView)
	{
		// Grow the container to fit one more item
		mParent->setSize(mParent->getSize().x, mParent->getSize().y + 32.f);

		// Grow the actual item too which contains this container
		mParent->getParent()->setSize(mParent->getParent()->getSize().x, mParent->getParent()->getSize().y + 32.f);

		// For level 1 tree views, there is no need to update the parent, but for any deeper, the increase needs to propagate
		int treeLevel = mSubTreeLevel;
		UIView* subTreeContainer = mParent;
		UIView* itemContainer = subTreeContainer->getParent();
		while(treeLevel >= 1)
		{
			// propagate the growth
			subTreeContainer = itemContainer->getParent();
			itemContainer = subTreeContainer->getParent();

			// Grow the container to fit one more item
			subTreeContainer->setSize(subTreeContainer->getSize().x, subTreeContainer->getSize().y + 32.f);

			// Grow the actual item too which contains this container
			itemContainer->getParent()->setSize(itemContainer->getParent()->getSize().x, itemContainer->getParent()->getSize().y + 32.f);

			treeLevel--;
		}

		//Log("ADDED ITEM TO A SUBTREE, SUBTREE CONTAINER NOW %f", mParent->getSize().y);
	}
}