博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
CWidgetMgr---cpp
阅读量:6001 次
发布时间:2019-06-20

本文共 6659 字,大约阅读时间需要 22 分钟。

#include "WidgetMgr.h"#include "XWidget.h"#include "Config.h"#include "XButton.h"#include "XImage.h"#include "XStatic.h"#include "XNoTouch.h"#include "XSroll.h"CWidgetMgr* CWidgetMgr::g_pUiMgr = NULL;CWidgetMgr::CWidgetMgr(){    m_deqWnd.clear();}CWidgetMgr::~CWidgetMgr(){    m_deqWnd.clear();}CWidgetMgr* CWidgetMgr::getInstance(){    if (!g_pUiMgr)    {        g_pUiMgr = new CWidgetMgr();        ASSERT(g_pUiMgr);    }    return g_pUiMgr;}void CWidgetMgr::destroy(){    SAFE_DELETE(g_pUiMgr);}bool CWidgetMgr::addWnd( CXWindow* pWnd, PRIORITY tpOrder /*= TP_NORMAL*/ ){    ASSERT(pWnd);    for (deque
::iterator it = m_deqWnd.begin(); it != m_deqWnd.end(); it++) { if (pWnd == (*it)) { CCLog("error: CWidgetMgr::addWnd"); ASSERT(false); } } m_deqWnd.push_back(pWnd); //设置窗口的优先级 //数字越低优先级越高 //pWnd->setTouchPriority((TOUCH_PRIORITY)tpOrder); return true;}void CWidgetMgr::eraseWnd( int nId ){ for (unsigned int i = 0; i < m_deqWnd.size(); i++ ) { if (nId == m_deqWnd[i]->getId()) { m_deqWnd.erase(m_deqWnd.begin() + i); } }}CXWindow* CWidgetMgr::getWnd( int nId ){ for (unsigned int i = 0; i < m_deqWnd.size(); i++ ) { if (nId == m_deqWnd[i]->getId()) { return m_deqWnd[i]; } } CCLog("error: CWidgetMgr::getWnd"); return NULL;}CXWindow* CWidgetMgr::loadWidget( CXWidget* pWnd, int nId ){ vector
& vecWidgetInfo = *(CConfig::getInstance()->getWidgetInfo()); for (unsigned int i = 0; i < vecWidgetInfo.size(); i++) { if (vecWidgetInfo[i].nId == nId) { pWnd->init(vecWidgetInfo[i].nId, vecWidgetInfo[i].tPos, vecWidgetInfo[i].rRect, vecWidgetInfo[i].strPic.c_str()); pWnd->setAnchorPoint(vecWidgetInfo[i].tAnchor); vector
& vecCtrlInfo = vecWidgetInfo[i].m_vecCtrlInfo; for (unsigned int j = 0; j < vecCtrlInfo.size(); j++) { switch( vecCtrlInfo[j].wType) { case CtrlInfo::_IDC_BTN : { CXButton* pBtn = CXButton::create(vecCtrlInfo[j].nId, vecCtrlInfo[j].tPos,vecCtrlInfo[j].rRect, vecCtrlInfo[j].strPic.c_str(), NULL, vecCtrlInfo[j].strAudioFile.c_str()); if (pBtn) { pBtn->setAnchorPoint(vecCtrlInfo[j].tAnchor); pBtn->setBtnType((CXButton::BTN_TYPE)vecCtrlInfo[j].btnType); pBtn->setBtnState((CXButton::BTN_STATE)vecCtrlInfo[j].btnState); pWnd->addCtrl(pBtn,0); } } break; case CtrlInfo::_IDC_IMG: { CXImage* pImg = CXImage::create(vecCtrlInfo[j].nId, vecCtrlInfo[j].tPos, vecCtrlInfo[j].rRect, vecCtrlInfo[j].strPic.c_str()); if (pImg) { pWnd->setAnchorPoint(vecCtrlInfo[j].tAnchor); pWnd->addCtrl(pImg,0); } } break; case CtrlInfo::_IDC_STA: { CXStatic* pSta = CXStatic::create(vecCtrlInfo[j].nId, vecCtrlInfo[j].tPos,vecCtrlInfo[j].rRect, vecCtrlInfo[j].strFont.c_str(),vecCtrlInfo[j].nFontSize, vecCtrlInfo[j].wAlignment, (CXStatic::LabelType)vecCtrlInfo[j].wLabelType); if (pSta) { pSta->setAnchorPoint(vecCtrlInfo[j].tAnchor); pSta->setText(vecCtrlInfo[j].strText.c_str()); pSta->setColor(vecCtrlInfo[j].color3B); pWnd->addCtrl(pSta,0); } } break; case CtrlInfo::_IDC_SROLL: { CXSroll* pSroll = CXSroll::create(vecCtrlInfo[j].nId, vecCtrlInfo[j].tPos, vecCtrlInfo[j].rRect, NULL); if (pSroll) { pSroll->setSrollType((CXSroll::XSrollType)vecCtrlInfo[j].wRollType); pSroll->setBounds(vecCtrlInfo[j].fBounds); vector
& widgetInfo = *CConfig::getInstance()->getSrollInfoByKey(vecCtrlInfo[j].strItem.c_str()); for (vector
::iterator it = widgetInfo.begin(); it != widgetInfo.end(); it++) { CXWidget* pWidget = CXWidget::create(it->nId, it->tPos, it->rRect, it->strPic.c_str(), NULL); for (vector
::iterator itCtrl = it->m_vecCtrlInfo.begin(); itCtrl != it->m_vecCtrlInfo.end(); itCtrl++) { switch( itCtrl->wType) { case CtrlInfo::_IDC_BTN : { CXButton* pBtn = CXButton::create(itCtrl->nId, itCtrl->tPos,itCtrl->rRect, itCtrl->strPic.c_str(), NULL, itCtrl->strAudioFile.c_str()); if (pBtn) { pBtn->setAnchorPoint(itCtrl->tAnchor); pBtn->setBtnType((CXButton::BTN_TYPE)itCtrl->btnType); pBtn->setBtnState((CXButton::BTN_STATE)itCtrl->btnState); pWidget->addCtrl(pBtn,0); pBtn->setTouchEnabled(false); } } break; case CtrlInfo::_IDC_IMG: { CXImage* pImg = CXImage::create(itCtrl->nId, itCtrl->tPos, itCtrl->rRect, itCtrl->strPic.c_str()); if (pImg) { pWnd->setAnchorPoint(itCtrl->tAnchor); pWidget->addCtrl(pImg,0); } } break; case CtrlInfo::_IDC_STA: { CXStatic* pSta = CXStatic::create(itCtrl->nId, itCtrl->tPos,itCtrl->rRect, itCtrl->strFont.c_str(),itCtrl->nFontSize,itCtrl->wAlignment, (CXStatic::LabelType)itCtrl->wLabelType); if (pSta) { pSta->setAnchorPoint(itCtrl->tAnchor); pSta->setText(itCtrl->strText.c_str()); pSta->setColor(itCtrl->color3B); pWidget->addCtrl(pSta,0); } } break; default: break; } } pSroll->addItem(pWidget, 0); } pWnd->addCtrl(pSroll,0); } } break; case CtrlInfo::_IDC_NOT: { CXNoTouch* pNot = CXNoTouch::create(vecCtrlInfo[j].nId, vecCtrlInfo[j].tPos, vecCtrlInfo[j].rRect); if (pNot) { pNot->setNoTouchType((CXNoTouch::NoTouchType)vecCtrlInfo[j].notType); pNot->setAnchorPoint(vecCtrlInfo[j].tAnchor); pNot->setTouchPriority((TOUCH_PRIORITY)vecCtrlInfo[j].nPriority); pWnd->addCtrl(pNot,0); } } break; default: break; } } return pWnd; } } return NULL;}void CWidgetMgr::clearAllWnd(){ for(deque
::iterator it = m_deqWnd.begin(); it != m_deqWnd.end(); it++ ) { (*it)->removeFromParentAndCleanup(true); } m_deqWnd.clear();}

 

转载地址:http://mibmx.baihongyu.com/

你可能感兴趣的文章
唯美MACD-完全版
查看>>
Canvas中 drawImage绘制图片不显示
查看>>
MyEclipse新建Server项目
查看>>
茵茵的第一课
查看>>
Linux实战教学笔记53:开源虚拟化KVM(一)搭建部署与概述
查看>>
PAT 1007
查看>>
USACO习题:Friday the Thirteenth
查看>>
C++ VS2012 内存泄露检测
查看>>
zabbix 批量添加聚合图形
查看>>
北京交通大学第六届新生程序设计竞赛题解
查看>>
求解点关于直线的距离、垂足、对称点公式
查看>>
洛谷 P1577 切绳子【二分答案】
查看>>
用 Google Map 的 Geocoder 接口来反向地址解析
查看>>
在中小型公司如何做好测试——论测试计划的重要性
查看>>
BSS段、数据段、代码段、堆与栈
查看>>
python调用c/c++写的dll
查看>>
r语言ggplot2误差棒图快速指南
查看>>
python之处理异常
查看>>
c++中的虚函数
查看>>
遍历form表单里面的表单元素,取其value
查看>>