Beispiel #1
0
/*!
 * \copydoc MythUIType::Clear()
 */
void MythUIStateType::Clear()
{
    if (m_ObjectsByName.isEmpty() && m_ObjectsByState.isEmpty())
        return;

    QMap<QString, MythUIType *>::Iterator i;

    for (i = m_ObjectsByName.begin(); i != m_ObjectsByName.end(); ++i)
    {
        DeleteChild(i.value());
    }

    QMap<int, MythUIType *>::Iterator j;

    for (j = m_ObjectsByState.begin(); j != m_ObjectsByState.end(); ++j)
    {
        DeleteChild(j.value());
    }

    m_ObjectsByName.clear();
    m_ObjectsByState.clear();

    m_CurrentState = NULL;
    SetRedraw();
}
Beispiel #2
0
void NodeButton::SetDisabledSelectedNode(INode* val, bool updateSize /*= false*/)
{
	RETURN_IF_EQUAL(mDisabledSelectedNode, val);
	DeleteChild(mDisabledSelectedNode);
	mDisabledSelectedNode = val;
	if (mDisabledSelectedNode!=nullptr)
	{
		InitNode(mDisabledSelectedNode);
		mDisabledSelectedNode->SetName(MEDUSA_PREFIX(DisabledSelected));

		AddChild(mDisabledSelectedNode);
		mDisabledSelectedNode->SetVisible(false);
	}

	if (mButtonState == ButtonState::DisabledSelected)
	{
		OnUpdateNode();
		if (updateSize&&mDisabledSelectedNode!=nullptr)
		{
			SetSize(mDisabledSelectedNode->Size());
		}
	}

	
}
void GraphicalSummaryWnd::GenerateGraph() {
    DeleteSideBars();

    m_sizer.reset(new BarSizer(m_summaries, ClientSize()));

    for (std::map<int, CombatSummary>::iterator it = m_summaries.begin(); it != m_summaries.end(); ++it) {
        if (it->second.total_max_health > EPSILON) {
            it->second.Sort();
            SideBar* box = new SideBar(it->second, *m_sizer);
            m_side_boxes.push_back(box);
            AttachChild(box);
        }
    }

    if (m_options_bar) {
        DebugLogger() << "GraphicalSummaryWnd::GenerateGraph(): m_options_bar "
                         "already exists, calling DeleteChild(m_options_bar) "
                         "before creating a new one.";
        DeleteChild(m_options_bar);
    }
    m_options_bar = new OptionsBar(m_sizer);
    AttachChild(m_options_bar);
    GG::Connect(m_options_bar->ChangedSignal,
                &GraphicalSummaryWnd::HandleButtonChanged,
                this);

    MinSizeChangedSignal();
    DoLayout();
}
Beispiel #4
0
main() {
	BiTNode * n1 = MakeNode(10, NULL, NULL);
	BiTNode * n2 = MakeNode(20, NULL, NULL);
	BiTNode * n3 = MakeNode(30, n1, n2);
	BiTNode * n4 = MakeNode(40, NULL, NULL);
	BiTNode * n5 = MakeNode(50, NULL, NULL);
	BiTNode * n6 = MakeNode(60, n4, n5);
	BiTNode * n7 = MakeNode(70, NULL, NULL);

	BiTree tree = InitBiTree(n7);
	SetLChild(tree, n3);
	SetRChild(tree, n6);

	printf("树的深度为:%d \n", GetDepth(tree));
	printTree(tree, GetDepth(tree));

	printf("\n先序遍历如下:");
	PreOrderTraverse(tree, print);

	printf("\n中序遍历如下:");
	InOrderTraverse(tree, print);

	printf("\n后序遍历如下:");
	PostOrderTraverse(tree, print);

	DeleteChild(tree, 1);
	printf("\n后序遍历如下:");
	PostOrderTraverse(tree, print);

	DestroyBiTree(tree);
	if (IsEmpty(tree))
		printf("\n二叉树为空,销毁完毕\n");
}
Beispiel #5
0
 void main()
 {
   int i;
   PTree T,p;
   TElemType e,e1;
   InitTree(T);
   printf("构造空树后,树空否? %d(1:是 0:否) 树根为%c 树的深度为%d\n",TreeEmpty(T),Root(T),TreeDepth(T));
   CreateTree(T);
   printf("构造树T后,树空否? %d(1:是 0:否) 树根为%c 树的深度为%d\n",TreeEmpty(T),Root(T),TreeDepth(T));
   printf("层序遍历树T:\n");
   TraverseTree(T,vi);
   printf("请输入待修改的结点的值 新值: ");
   scanf("%c%*c%c%*c",&e,&e1);
   Assign(T,e,e1);
   printf("层序遍历修改后的树T:\n");
   TraverseTree(T,vi);
   printf("%c的双亲是%c,长子是%c,下一个兄弟是%c\n",e1,Parent(T,e1),LeftChild(T,e1),RightSibling(T,e1));
   printf("建立树p:\n");
   InitTree(p);
   CreateTree(p);
   printf("层序遍历树p:\n");
   TraverseTree(p,vi);
   printf("将树p插到树T中,请输入T中p的双亲结点 子树序号: ");
   scanf("%c%d%*c",&e,&i);
   InsertChild(T,e,i,p);
   Print(T);
   printf("删除树T中结点e的第i棵子树,请输入e i: ");
   scanf("%c%d",&e,&i);
   DeleteChild(T,e,i);
   Print(T);
 }
Beispiel #6
0
int main()
{
	Status i;
	int j;
	position p;
	TElemType e;
	TElemType s;

	InitBiTree( T );
	CreateBiTree( T );
	printf("After initializing the Tree, is the Tree empty? Yes:1, No:0, the depth is: %d\n", BiTreeEmpty( T ), BiTreeDepth(T));
	i = Root( T, &e );
	if( i )
		printf("The root of the tree is: %d\n", e);
	else
		printf("The tree is empty!\n");

	printf("Traverse_1:\n");
	LevelOrderTraverse( T, visit );

	printf("Traverse_2:\n");
	InOrderTraverse( T, visit );

	printf("Traverse_3:\n");
	PostOrderTraverse( T, visit );

	printf("input the level number to be modified \n");
	scanf(" %d%d", &p.level, &p.order);
	e = Value( T, p);

	printf("The old value is %d, input new value: ", e);
	scanf(" %d", &e);

	Assign( T, p, e);
	printf("Traverse_1:\n");
	PreOrderTraverse( T, visit );

	printf("The parent of node %d is %d, left and right children are: ", e, Parent(T, e));
	printf("%d, %d, left and rignt brothers are:", LeftChild(T, e), RightChild(T, e));
	printf("%d, %d\n", LeftSibling(T, e), RightSibling(T, e));

	InitBiTree( s );
	printf("Initializing a Tree that has empty right subtree:\n");
	CreateBiTree( s );

	printf("The tree s insert to the tree T, input the parent node of s, s is left subtree or right subtree.");
	scanf(" %d%d%d", &p.level, &p.order, &j);
	DeleteChild( T, p, j);
	Print( T );

	clearBiTRee( T );
	printf("After clearing the tree, is the tree empty? Yes:1, No:0 %d\n", BiTreeEmpty( T ), BiTreeDepth(T));
	i = Root( T, &e );

	if( i )
		printf("The root of the bitree is %d\n", e);
	else
		printf("The tree is empty, no root!\n");
}
Beispiel #7
0
void BaseFeatureLayer::OnReturn(INode* sender, TapGestureEventArg& e)
{
	DeleteChild(mCurrentLayer);
	mCurrentLayer = nullptr;
	SceneManager::Instance().RunningScene()->PopLayer(LayerPopFlags::DeleteCurrentLayerAsync);


}
Beispiel #8
0
void GalaxySetupWnd::PreviewImageChanged(boost::shared_ptr<GG::Texture> new_image) {
    if (m_preview_image) {
        DeleteChild(m_preview_image);
        m_preview_image = 0;
    }
    m_preview_image = new GG::StaticGraphic(m_preview_ul.x, m_preview_ul.y, PREVIEW_SZ.x, PREVIEW_SZ.y, new_image, GG::GRAPHIC_FITGRAPHIC);
    AttachChild(m_preview_image);
}
Beispiel #9
0
void clRowEntry::DeleteAllChildren()
{
    while(!m_children.empty()) {
        clRowEntry* c = m_children[0];
        // DeleteChild will remove it from the array
        DeleteChild(c);
    }
}
void GraphicalSummaryWnd::DeleteSideBars() {
    for(std::vector<SideBar*>::iterator it = m_side_boxes.begin();
            it != m_side_boxes.end();
            ++it) {
        DeleteChild(*it);
    }
    m_side_boxes.clear();
}
Beispiel #11
0
void People::GoOut(){
	if(IsValid()){
		int64 ParentID = GetParentID();
		int64 ChildID  = GetSpaceID();
		DeleteChild(ParentID,ChildID);
		m_ID = -1;
	}
}
Beispiel #12
0
void SubtitleScreen::Clear708Cache(int num)
{
    if (!m_708imageCache[num].isEmpty())
    {
        foreach(MythUIType* image, m_708imageCache[num])
            DeleteChild(image);
        m_708imageCache[num].clear();
    }
}
Beispiel #13
0
bool IScene::DeleteLayer(ILayer* layer, LayerDeleteFlags deleteFlags /*= LayerDeleteFlags::None*/)
{
	if (deleteFlags.Has(LayerDeleteFlags::Async))
	{
		NodeSweeper::Instance().Add(layer);
		return layer != nullptr;
	}
	else
	{
		return DeleteChild(layer);
	}
}
void test_DeleteChild(void) {
	BINARY_TREE_TYPE tree = get_test_tree(
			"1, 2, 3, , 5, 6, , , , 51, 52, 61, 62, , ");
	if (tree == NULL)
		return;

	BINARY_TREE_NODE *node;
	Status status = ERROR;
	Position position;

	node = get_node(tree, 2);
	status = DeleteChild(tree, node, Right);
	CU_ASSERT_EQUAL(status, OK);
	position.level = 3;
	position.order = 2;
	CU_ASSERT_EQUAL(Value(tree, position), 0);

	node = get_node(tree, 2);
	status = DeleteChild(tree, node, Left);
	CU_ASSERT_EQUAL(status, OK);
}
Beispiel #15
0
 void main()
 {
   Status i;
   int j;
   position p;
   TElemType e;
   SqBiTree T,s;
   InitBiTree(T);
   CreateBiTree(T);
   printf("建立二叉树后,树空否?%d(1:是 0:否) 树的深度=%d\n",BiTreeEmpty(T),BiTreeDepth(T));
   i=Root(T,&e);
   if(i)
     printf("二叉树的根为:%d\n",e);
   else
     printf("树空,无根\n");
   printf("层序遍历二叉树:\n");
   LevelOrderTraverse(T,visit);
   printf("中序遍历二叉树:\n");
   InOrderTraverse(T,visit);
   printf("后序遍历二叉树:\n");
   PostOrderTraverse(T,visit);
   printf("请输入待修改结点的层号 本层序号: ");
   scanf("%d%d",&p.level,&p.order);
   e=Value(T,p);
   printf("待修改结点的原值为%d请输入新值: ",e);
   scanf("%d",&e);
   Assign(T,p,e);
   printf("先序遍历二叉树:\n");
   PreOrderTraverse(T,visit);
   printf("结点%d的双亲为%d,左右孩子分别为",e,Parent(T,e));
   printf("%d,%d,左右兄弟分别为",LeftChild(T,e),RightChild(T,e));
   printf("%d,%d\n",LeftSibling(T,e),RightSibling(T,e));
   InitBiTree(s);
   printf("建立右子树为空的树s:\n");
   CreateBiTree(s);
   printf("树s插到树T中,请输入树T中树s的双亲结点 s为左(0)或右(1)子树: ");
   scanf("%d%d",&e,&j);
   InsertChild(T,e,j,s);
   Print(T);
   printf("删除子树,请输入待删除子树根结点的层号 本层序号 左(0)或右(1)子树: ");
   scanf("%d%d%d",&p.level,&p.order,&j);
   DeleteChild(T,p,j);
   Print(T);
   ClearBiTree(T);
   printf("清除二叉树后,树空否?%d(1:是 0:否) 树的深度=%d\n",BiTreeEmpty(T),BiTreeDepth(T));
   i=Root(T,&e);
   if(i)
     printf("二叉树的根为:%d\n",e);
   else
     printf("树空,无根\n");
 }
Beispiel #16
0
void XMLParagraph::DeleteLeaf(size_t nLeaf)
{
    auto pNode   = LeafRef(nLeaf).Node();
    auto pParent = pNode->Parent();

    while(pParent && (pParent->FirstChild() == pParent->LastChild())){
        pNode   = pParent;
        pParent = pParent->Parent();
    }

    if(pParent){
        pParent->DeleteChild(pNode);
    }
}
Beispiel #17
0
void BaseFeatureLayer::OnRight(INode* sender, TapGestureEventArg& e)
{
	RETURN_IF(mLayers.Count() <= 1);


	++mIndex;
	mIndex %= mLayers.Count();

	StringRef layerName = mLayers[mIndex];
	DeleteChild(mCurrentLayer);
	mCurrentLayer = nullptr;
	mCurrentLayer = (BaseCaseLayer*)SceneManager::Instance().RunningScene()->CreateLayer(layerName, StringRef::Empty, IEventArg::Empty, LayerCreateFlags::AlwaysCreate);
	mCurrentLayer->SetLogicZ(-1);
	AddChild(mCurrentLayer);
}
Beispiel #18
0
    Octant::~Octant()
    {
        if (root_)
        {
            // Remove the drawables (if any) from this octant to the root octant
            for (auto& obj : drawables_)
            {
                obj->SetOctant(root_);
                root_->drawables_.push_back(obj);
            }
            drawables_.clear();
            numDrawables_ = 0;
        }

        for (unsigned i = 0; i < NUM_OCTANTS; ++i)
            DeleteChild(i);
    }
Beispiel #19
0
void SubtitleScreen::ExpireSubtitles(void)
{
    VideoOutput    *videoOut = m_player->GetVideoOutput();
    VideoFrame *currentFrame = videoOut ? videoOut->GetLastShownFrame() : NULL;
    long long now = currentFrame ? currentFrame->timecode : LLONG_MAX;
    QMutableHashIterator<MythUIType*, long long> it(m_expireTimes);
    while (it.hasNext())
    {
        it.next();
        if (it.value() < now)
        {
            DeleteChild(it.key());
            it.remove();
            SetRedraw();
        }
    }
}
Beispiel #20
0
bool IScene::DeleteLayer(StringRef editorFile, LayerDeleteFlags deleteFlags/*=LayerDeleteFlags::None*/)
{
	if (deleteFlags.Has(LayerDeleteFlags::Async))
	{
		INode* layer = FindChild(editorFile);
		if (layer != nullptr)
		{
			NodeSweeper::Instance().Add(layer);
		}
		return layer != nullptr;
	}
	else
	{
		return DeleteChild(editorFile);
	}

}
void SystemResourceSummaryBrowseWnd::Clear() {
    DeleteChild(m_production_label);
    DeleteChild(m_allocation_label);
    DeleteChild(m_import_export_label);

    for (std::vector<std::pair<GG::Label*, GG::Label*> >::iterator it = m_production_labels_and_amounts.begin(); it != m_production_labels_and_amounts.end(); ++it) {
        DeleteChild(it->first);
        DeleteChild(it->second);
    }
    m_production_labels_and_amounts.clear();

    for (std::vector<std::pair<GG::Label*, GG::Label*> >::iterator it = m_allocation_labels_and_amounts.begin(); it != m_allocation_labels_and_amounts.end(); ++it) {
        DeleteChild(it->first);
        DeleteChild(it->second);
    }
    m_allocation_labels_and_amounts.clear();

    for (std::vector<std::pair<GG::Label*, GG::Label*> >::iterator it = m_import_export_labels_and_amounts.begin(); it != m_import_export_labels_and_amounts.end(); ++it) {
        DeleteChild(it->first);
        DeleteChild(it->second);
    }
    m_import_export_labels_and_amounts.clear();
}
void main()
{
	int i;
	CSTree T, p, q;
	TElemType e, e1;

	InitTree(T);
	printf("构造空树后,树空否?%d(1:是 0:否)。树根为%c,树的深度为%d。\n",
	       TreeEmpty(T), Root(T), TreeDepth(T));
	CreateTree(T);
	printf("构造树T后,树空否?%d(1:是 0:否)。树根为%c,树的深度为%d。\n",
	       TreeEmpty(T), Root(T), TreeDepth(T));
	printf("层序遍历树T:\n");
	LevelOrderTraverse(T, visit);
	printf("请输入待修改的结点的值 新值:");
	scanf("%c%*c%c%*c", &e, &e1);
	Assign(T, e, e1);
	printf("层序遍历修改后的树T:\n");
	LevelOrderTraverse(T, visit);
	printf("%c的双亲是%c,长子是%c,下一个兄弟是%c。\n", e1, Parent(T, e1),
	       LeftChild(T, e1), RightSibling(T, e1));
	printf("建立树p:\n");
	CreateTree(p);
	printf("层序遍历树p:\n");
	LevelOrderTraverse(p, visit);
	printf("将树p插到树T中,请输入T中p的双亲结点 子树序号:");
	scanf("%c%d%*c", &e, &i);
	q = Point(T, e);
	InsertChild(T, q, i, p);
	printf("层序遍历修改后的树T:\n");
	LevelOrderTraverse(T, visit);
	printf("先根遍历树T:\n");
	PreOrderTraverse(T, visit);
	printf("\n后根遍历树T:\n");
	PostOrderTraverse(T, visit);
	printf("\n删除树T中结点e的第i棵子树,请输入e i:");
	scanf("%c%d", &e, &i);
	q = Point(T, e);
	DeleteChild(T, q, i);
	printf("层序遍历修改后的树T:\n");
	LevelOrderTraverse(T, visit);
	DestroyTree(T);
}
void pawsShortcutWindow::RebuildMatrix()
{
    size_t matrixWidth, matrixHeight;
    pawsButton * button;
    size_t i, k;

    // delete old matrix
    for (i=0; i < matrix.GetSize(); i++)
    {
        for (k=0; k < matrix[i].GetSize(); k++)
        {
            DeleteChild(matrix[i][k]);
        }
    }            
    matrix.DeleteAll();
    
    CalcMatrixSize(matrixWidth, matrixHeight);
    
    // create new matrix
    matrix.SetSize(matrixWidth);
    for (i=0; i < matrix.GetSize(); i++)
    {
        matrix[i].SetSize(matrixHeight);
        for (k=0; k < matrix[i].GetSize(); k++)
        {
            button = new pawsButton;
            button->SetSound("gui.shortcut");
            AddChild(button);
            button->SetBackground(buttonBackgroundImage);
            matrix[i][k] = button;
        }
    }

    UpdateMatrix();
    LayoutMatrix();
    
    CS_ASSERT(matrix.GetSize()>0);
    if (scrollBar != NULL)
    {    
        scrollBar->SetMaxValue(ceil(    NUM_SHORTCUTS / (float)(matrixWidth*matrixHeight)    )   - 1   );
    }        
}
Beispiel #24
0
int main(int argc,char *argv[])
{
	int i;
	TElemType e,tempe;
	PTree T,C;

	InitTree(T);
	InitTree(C);

	printf("������:");
	CreateTree(T);
	CreateTree(C);
	printf("\n������:");
	TraverseTree(T,Visit);
	printf("\n");
	TraverseTree(C,Visit);

	printf("\n����:%c",Root(T));
	printf("\n����i:");
	scanf("%d%*c",&i);
	printf("\n��ֵ:%c",(tempe=Value(T,i)));
	printf("\n��ֵ:");
	scanf("%c%*c",&e);
	Assign(T,tempe,e);
	printf("\n���ڵ㡢���ӡ����ֵܣ��������:%c %c %c %d %d",
		
		Value(T,Parent(T,e)),
		Value(T,LeftChild(T,e)),Value(T,RightSibling(T,e)),
		TreeDepth(T),TreeEmpty(T));
	printf("\n��������:");
	InsertChild(T,e,1,C);
	TraverseTree(T,Visit);
	printf("\nɾ�������:");
	DeleteChild(T,e,1);
	TraverseTree(T,Visit);

	DestroyTree(T);
	DestroyTree(C);
	return 0;
}
Beispiel #25
0
 void main()
 {
   int i;
   CSTree T,p,q;
   TElemType e,e1;
   InitTree(&T);
   printf("构造空树后,树空否? %d(1:是 0:否) 树根为%c 树的深度为%d\n",TreeEmpty(T),Root(T),TreeDepth(T));
   CreateTree(&T);
   printf("构造树T后,树空否? %d(1:是 0:否) 树根为%c 树的深度为%d\n",TreeEmpty(T),Root(T),TreeDepth(T));
   printf("先根遍历树T:\n");
   PreOrderTraverse(T,vi);
   printf("\n请输入待修改的结点的值 新值: ");
   scanf("%c%*c%c%*c",&e,&e1);
   Assign(&T,e,e1);
   printf("后根遍历修改后的树T:\n");
   PostOrderTraverse(T,vi);
   printf("\n%c的双亲是%c,长子是%c,下一个兄弟是%c\n",e1,Parent(T,e1),LeftChild(T,e1),RightSibling(T,e1));
   printf("建立树p:\n");
   InitTree(&p);
   CreateTree(&p);
   printf("层序遍历树p:\n");
   LevelOrderTraverse(p,vi);
   printf("\n将树p插到树T中,请输入T中p的双亲结点 子树序号: ");
   scanf("%c%d%*c",&e,&i);
   q=Point(T,e);
   InsertChild(&T,q,i,p);
   printf("层序遍历树T:\n");
   LevelOrderTraverse(T,vi);
   printf("\n删除树T中结点e的第i棵子树,请输入e i: ");
   scanf("%c%d",&e,&i);
   q=Point(T,e);
   DeleteChild(&T,q,i);
   printf("层序遍历树T:\n",e,i);
   LevelOrderTraverse(T,vi);
   printf("\n");
   DestroyTree(&T);
 }
void pawsTreeNode::Clear()
{
    while(firstChild != NULL)
        DeleteChild(firstChild);
}
void SystemResourceSummaryBrowseWnd::UpdateAllocation(GG::Y& top) {
    // adds pairs of labels for allocation of resources in system, starting at vertical position \a top and
    // updates \a top to be the vertical position after the last entry
    for (unsigned int i = 0; i < m_allocation_labels_and_amounts.size(); ++i) {
        DeleteChild(m_allocation_labels_and_amounts[i].first);
        DeleteChild(m_allocation_labels_and_amounts[i].second);
    }
    m_allocation_labels_and_amounts.clear();

    TemporaryPtr<const System> system = GetSystem(m_system_id);
    if (!system || m_resource_type == INVALID_RESOURCE_TYPE)
        return;


    m_allocation = 0.0;


    // add label-value pair for each resource-consuming object in system to indicate amount of resource consumed
    std::vector<TemporaryPtr<const UniverseObject> > objects =
        Objects().FindObjects<const UniverseObject>(system->ContainedObjectIDs());

    for (std::vector<TemporaryPtr<const UniverseObject> >::const_iterator it = objects.begin();
         it != objects.end(); ++it)
    {
        TemporaryPtr<const UniverseObject> obj = *it;

        // display information only for the requested player
        if (m_empire_id != ALL_EMPIRES && !obj->OwnedBy(m_empire_id))
            continue;   // if m_empire_id == ALL_EMPIRES, display resource production for all empires.  otherwise, skip this resource production if it's not owned by the requested player


        std::string name = obj->Name();


        double allocation = ObjectResourceConsumption(obj, m_resource_type, m_empire_id);


        // don't add summary entries for objects that consume no resource.  (otherwise there would be a loooong pointless list of 0's
        if (allocation <= 0.0) {
            if (allocation < 0.0)
                ErrorLogger() << "object " << obj->Name() << " is reported having negative " << boost::lexical_cast<std::string>(m_resource_type) << " consumption";
            continue;
        }


        m_allocation += allocation;

        std::string amount_text = DoubleToString(allocation, 3, false);


        GG::Label* label = new CUILabel(name, GG::FORMAT_RIGHT);
        label->MoveTo(GG::Pt(GG::X0, top));
        label->Resize(GG::Pt(LabelWidth(), row_height));
        AttachChild(label);


        GG::Label* value = new CUILabel(amount_text);
        value->MoveTo(GG::Pt(LabelWidth(), top));
        value->Resize(GG::Pt(ValueWidth(), row_height));
        AttachChild(value);

        m_allocation_labels_and_amounts.push_back(std::pair<GG::Label*, GG::Label*>(label, value));

        top += row_height;
    }


    if (m_allocation_labels_and_amounts.empty()) {
        // add "blank" line to indicate no allocation
        GG::Label* label = new CUILabel(UserString("NOT_APPLICABLE"), GG::FORMAT_RIGHT);
        label->MoveTo(GG::Pt(GG::X0, top));
        label->Resize(GG::Pt(LabelWidth(), row_height));
        AttachChild(label);

        GG::Label* value = new CUILabel("");
        value->MoveTo(GG::Pt(LabelWidth(), top));
        value->Resize(GG::Pt(ValueWidth(), row_height));
        AttachChild(value);

        m_allocation_labels_and_amounts.push_back(std::pair<GG::Label*, GG::Label*>(label, value));

        top += row_height;
    }


    // set consumption / allocation label
    std::string resource_text = "";
    switch (m_resource_type) {
    case RE_INDUSTRY:
        resource_text = UserString("INDUSTRY_CONSUMPTION"); break;
    case RE_RESEARCH:
        resource_text = UserString("RESEARCH_CONSUMPTION"); break;
    case RE_TRADE:
        resource_text = UserString("TRADE_CONSUMPTION");    break;
    default:
        resource_text = UserString("UNKNOWN_VALUE_SYMBOL"); break;
    }

    std::string system_allocation_text = DoubleToString(m_allocation, 3, false);

    // for research only, local allocation makes no sense
    if (m_resource_type == RE_RESEARCH && m_allocation == 0.0)
        system_allocation_text = UserString("NOT_APPLICABLE");


    m_allocation_label->SetText(boost::io::str(FlexibleFormat(UserString("RESOURCE_ALLOCATION_TOOLTIP")) %
                                                              resource_text %
                                                              system_allocation_text));

    // height of label already added to top outside this function
}
void SystemResourceSummaryBrowseWnd::UpdateProduction(GG::Y& top) {
    // adds pairs of labels for ResourceCenter name and production of resource starting at vertical position \a top
    // and updates \a top to the vertical position after the last entry
    for (unsigned int i = 0; i < m_production_labels_and_amounts.size(); ++i) {
        DeleteChild(m_production_labels_and_amounts[i].first);
        DeleteChild(m_production_labels_and_amounts[i].second);
    }
    m_production_labels_and_amounts.clear();

    TemporaryPtr<const System> system = GetSystem(m_system_id);
    if (!system || m_resource_type == INVALID_RESOURCE_TYPE)
        return;


    m_production = 0.0;


    // add label-value pair for each resource-producing object in system to indicate amount of resource produced
    std::vector<TemporaryPtr<const UniverseObject> > objects =
        Objects().FindObjects<const UniverseObject>(system->ContainedObjectIDs());

    for (std::vector<TemporaryPtr<const UniverseObject> >::const_iterator it = objects.begin();
         it != objects.end(); ++it)
    {
        TemporaryPtr<const UniverseObject> obj = *it;

        // display information only for the requested player
        if (m_empire_id != ALL_EMPIRES && !obj->OwnedBy(m_empire_id))
            continue;   // if m_empire_id == -1, display resource production for all empires.  otherwise, skip this resource production if it's not owned by the requested player

        TemporaryPtr<const ResourceCenter> rc = boost::dynamic_pointer_cast<const ResourceCenter>(obj);
        if (!rc) continue;

        std::string name = obj->Name();
        double production = rc->InitialMeterValue(ResourceToMeter(m_resource_type));
        m_production += production;

        std::string amount_text = DoubleToString(production, 3, false);


        GG::Label* label = new CUILabel(name, GG::FORMAT_RIGHT);
        label->MoveTo(GG::Pt(GG::X0, top));
        label->Resize(GG::Pt(LabelWidth(), row_height));
        AttachChild(label);

        GG::Label* value = new CUILabel(amount_text);
        value->MoveTo(GG::Pt(LabelWidth(), top));
        value->Resize(GG::Pt(ValueWidth(), row_height));
        AttachChild(value);

        m_production_labels_and_amounts.push_back(std::pair<GG::Label*, GG::Label*>(label, value));

        top += row_height;
    }


    if (m_production_labels_and_amounts.empty()) {
        // add "blank" line to indicate no production
        GG::Label* label = new CUILabel(UserString("NOT_APPLICABLE"));
        label->MoveTo(GG::Pt(GG::X0, top));
        label->Resize(GG::Pt(LabelWidth(), row_height));
        AttachChild(label);

        GG::Label* value = new CUILabel("");
        value->MoveTo(GG::Pt(LabelWidth(), top));
        value->Resize(GG::Pt(ValueWidth(), row_height));
        AttachChild(value);

        m_production_labels_and_amounts.push_back(std::pair<GG::Label*, GG::Label*>(label, value));

        top += row_height;
    }


    // set production label
    std::string resource_text = "";
    switch (m_resource_type) {
    case RE_INDUSTRY:
        resource_text = UserString("INDUSTRY_PRODUCTION");  break;
    case RE_RESEARCH:
        resource_text = UserString("RESEARCH_PRODUCTION");  break;
    case RE_TRADE:
        resource_text = UserString("TRADE_PRODUCTION");     break;
    default:
        resource_text = UserString("UNKNOWN_VALUE_SYMBOL"); break;
    }

    m_production_label->SetText(boost::io::str(FlexibleFormat(UserString("RESOURCE_PRODUCTION_TOOLTIP")) %
                                                              resource_text %
                                                              DoubleToString(m_production, 3, false)));

    // height of label already added to top outside this function
}
Beispiel #29
0
void BDOverlayScreen::DisplayBDOverlay(BDOverlay *overlay)
{
    if (!overlay || !m_player)
        return;

    if (!overlay->m_data)
    {
        m_overlayArea = overlay->m_position;
        SetArea(MythRect(m_overlayArea));
        DeleteAllChildren();
        m_overlayMap.clear();
        SetRedraw();
        LOG(VB_PLAYBACK, LOG_INFO, LOC +
            QString("Initialised Size: %1x%2 (%3+%4) Plane: %5 Pts: %6")
                .arg(overlay->m_position.width())
                .arg(overlay->m_position.height())
                .arg(overlay->m_position.left())
                .arg(overlay->m_position.top())
                .arg(overlay->m_plane)
                .arg(overlay->m_pts));
        BDOverlay::DeleteOverlay(overlay);
        return;
    }

    if (!m_overlayArea.isValid())
    {
        LOG(VB_GENERAL, LOG_ERR, LOC +
            "Error: Overlay image submitted before initialisation.");
    }

    VideoOutput *vo = m_player->GetVideoOutput();
    if (!vo)
        return;

    QRect   rect = overlay->m_position;
    QString hash = QString("%1+%2+%3x%4")
                    .arg(rect.left()).arg(rect.top())
                    .arg(rect.width()).arg(rect.height());

    // remove if we already have this overlay
    if (m_overlayMap.contains(hash))
    {
        LOG(VB_PLAYBACK, LOG_DEBUG, LOC + QString("Removing %1 (%2 left)")
            .arg(hash).arg(m_overlayMap.size()));
        MythUIImage *old = m_overlayMap.take(hash);
        DeleteChild(old);
    }

    // convert the overlay palette to ARGB
    uint32_t *origpalette = (uint32_t *)(overlay->m_palette);
    QVector<unsigned int> palette;
    for (int i = 0; i < 256; i++)
    {
        int y  = (origpalette[i] >> 0) & 0xff;
        int cr = (origpalette[i] >> 8) & 0xff;
        int cb = (origpalette[i] >> 16) & 0xff;
        int a  = (origpalette[i] >> 24) & 0xff;
        int r  = int(y + 1.4022 * (cr - 128));
        int b  = int(y + 1.7710 * (cb - 128));
        int g  = int(1.7047 * y - (0.1952 * b) - (0.5647 * r));
        if (r < 0) r = 0;
        if (g < 0) g = 0;
        if (b < 0) b = 0;
        if (r > 0xff) r = 0xff;
        if (g > 0xff) g = 0xff;
        if (b > 0xff) b = 0xff;
        palette.push_back((a << 24) | (r << 16) | (g << 8) | b);
    }

    // convert the image to QImage
    QImage img(rect.size(), QImage::Format_Indexed8);
    memcpy(img.bits(), overlay->m_data, rect.width() * rect.height());
    img.setColorTable(palette);
    img.convertToFormat(QImage::Format_ARGB32);

    // add to screen
    QRect scaled = vo->GetImageRect(rect);
    if (scaled.size() != rect.size())
    {
        img = img.scaled(scaled.width(), scaled.height(),
                         Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
    }

    MythPainter *osd_painter = vo->GetOSDPainter();
    MythImage* image = NULL;
    if (osd_painter)
         image = osd_painter->GetFormatImage();

    if (image)
    {
        image->Assign(img);
        MythUIImage *uiimage = new MythUIImage(this, "bdoverlay");
        if (uiimage)
        {
            uiimage->SetImage(image);
            uiimage->SetArea(MythRect(scaled));
            m_overlayMap.insert(hash, uiimage);
            LOG(VB_PLAYBACK, LOG_DEBUG, LOC + QString("Added %1 (%2 tot)")
                .arg(hash).arg(m_overlayMap.size()));
        }
    }

    SetRedraw();
    BDOverlay::DeleteOverlay(overlay);
}
Beispiel #30
0
//SqBiTree的测试程序
int main(int argc,char *argv[])
{
	int i=0;
	char buf[1024];
	char e,newe;
	char *temp;
	bool k;
	position p;
	BiTree T,C;
	BiTree q,q2;

	InitBiTree(T);
	InitBiTree(C);

	printf("输入数据创建二叉树(#表示空):");
	scanf("%s%*c",buf);
	temp=buf;
	CreateBiTree(T,temp,i);

	printf("\n遍历(前、中、后、层):");
	PreOrderTraverse(T,Visit);
	printf("\n");
	InOrderTraverse(T,Visit);
	printf("\n");
	PostOrderTraverse(T,Visit);
	printf("\n");
	LevelOrderTraverse(T,Visit);

	printf("\n二叉树是否为空:%s",BiTreeEmpty(T)==1?"空":"非空");
	printf("\n树的深度:%d",BiTreeDepth(T));

	printf("\n根节点的左孩子、双亲、左右孩子、左右兄弟节点");
	q=LeftChild(T,*T);
	printf("\n%c %c %c %c %c %c",q==NULL?Nil:q->e,(q2=Parent(T,*q))==NULL?Nil:q2->e,(q2=LeftChild(T,*q))==NULL?Nil:q2->e,
		(q2=RightChild(T,*q))==NULL?Nil:q2->e,(q2=LeftSibling(T,*q))==NULL?Nil:q2->e,
		(q2=RightSibling(T,*q))==NULL?Nil:q2->e);
	
	printf("\n节点的新值:");
	scanf("%c%*c",&newe);
	Assign(T,*q,newe);

	printf("\n替换后遍历(前、中、后、层):");
	PreOrderTraverse(T,Visit);
	printf("\n");
	InOrderTraverse(T,Visit);
	printf("\n");
	PostOrderTraverse(T,Visit);
	printf("\n");
	LevelOrderTraverse(T,Visit);

	printf("\n输入数据创建二叉树(#表示空):");
	scanf("%s%*c",buf);
	temp=buf;
	i=0;
	CreateBiTree(C,temp,i);
	printf("\n输入要插入数据的层、序号和左右子树(0左1右):");
	scanf("%d%d%d%*c",&p.level,&p.order,&k);
	InsertChild(T,p,k,C);
	
	printf("\n遍历(前、中、后、层):");
	PreOrderTraverse(T,Visit);
	printf("\n");
	InOrderTraverse(T,Visit);
	printf("\n");
	PostOrderTraverse(T,Visit);
	printf("\n");
	LevelOrderTraverse(T,Visit);

	printf("\n删除%d层%d个节点的右子树后遍历:",p.level,p.order);
	DeleteChild(T,p,1);

	printf("\n遍历(前、中、后、层):");
	PreOrderTraverse(T,Visit);
	printf("\n");
	InOrderTraverse(T,Visit);
	printf("\n");
	PostOrderTraverse(T,Visit);
	printf("\n");
	LevelOrderTraverse(T,Visit);

	DestroyBiTree(T);
	system("pause");
	return 0;
}