bool PvPSearchGame::init() { this->isShowBottom = false; this->isShowTop = false; mLoadingCancel = NULL; CCNode* root = CCNode::create(); root->setPosition(ccp(-320, -960)); this->addChild(root); CCSprite* bg = GetSprite("pvp/pvp_bg.jpg"); bg->setAnchorPoint(ccp(0, 0)); root->addChild(bg); mLoading = CCLabelTTF::create("正在匹配对手中", FONT_CN, 32); mLoading->setPosition(ccp(320, 810)); root->addChild(mLoading); std::string text = std::string("服务器连接状态: ") + (PuzzleRPC::getInstance()->getPvP()->isConnected() ? "正常" : "断开"); mServerStatus = CCLabelTTF::create(text.c_str(), FONT_CN, 32); mServerStatus->setPosition(ccp(320, 750)); root->addChild(mServerStatus); mLoadingAnim = GetSprite("loading_anim1.png"); mLoadingAnim->setAnchorPoint(ccp(0.5, 0)); mLoadingAnim->setPosition(ccp(330, 250)); root->addChild(mLoadingAnim); ButtonSprite* stop = ButtonSprite::create(createBtn("退出", ButtonType::NORMAL_RED), createBtn("退出", ButtonType::NORMAL_RED)); stop->setOnClickListener([=](){ this->stopMatching(); }); stop->setPosition(ccp(320, 45)); root->addChild(stop); PuzzleRPC::getInstance()->getPvP()->setFindMatchReceiver(this); return true; }
/**************************************************************************** * CheatMenu ***************************************************************************/ int CheatMenu(const char * gameID) { int choice = 0; bool exit = false; int ret = 1; // because destroy GuiSound must wait while sound playing is finished, we use a global sound if(!btnClick2) btnClick2=new GuiSound(button_click2_pcm, button_click2_pcm_size, Settings.sfxvolume); // GuiSound btnClick(button_click2_pcm, button_click2_pcm_size, Settings.sfxvolume); char imgPath[100]; snprintf(imgPath, sizeof(imgPath), "%sbutton_dialogue_box.png", CFG.theme_path); GuiImageData btnOutline(imgPath, button_dialogue_box_png); snprintf(imgPath, sizeof(imgPath), "%ssettings_background.png", CFG.theme_path); GuiImageData settingsbg(imgPath, settings_background_png); GuiImage settingsbackground(&settingsbg); GuiTrigger trigA; trigA.SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A); GuiTrigger trigB; trigB.SetButtonOnlyTrigger(-1, WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B, PAD_BUTTON_B); GuiText backBtnTxt(tr("Back") , 22, THEME.prompttext); backBtnTxt.SetMaxWidth(btnOutline.GetWidth()-30); GuiImage backBtnImg(&btnOutline); GuiButton backBtn(&backBtnImg,&backBtnImg, 2, 3, -140, 400, &trigA, NULL, btnClick2,1); backBtn.SetLabel(&backBtnTxt); backBtn.SetTrigger(&trigB); GuiText createBtnTxt(tr("Create") , 22, THEME.prompttext); createBtnTxt.SetMaxWidth(btnOutline.GetWidth()-30); GuiImage createBtnImg(&btnOutline); GuiButton createBtn(&createBtnImg,&createBtnImg, 2, 3, 160, 400, &trigA, NULL, btnClick2,1); createBtn.SetLabel(&createBtnTxt); char txtfilename[55]; snprintf(txtfilename,sizeof(txtfilename),"%s%s.txt",Settings.TxtCheatcodespath,gameID); GCTCheats c; int check = c.openTxtfile(txtfilename); int download =0; switch (check) { case -1: WindowPrompt(tr("Error"),tr("Cheatfile is blank"),tr("OK")); break; case 0: download = WindowPrompt(tr("Error"),tr("No Cheatfile found"),tr("Download Now"),tr("Cancel")); if (download==1) { download = CodeDownload(gameID); if(download < 0 || c.openTxtfile(txtfilename) != 1) break; } else break; case 1: int cntcheats = c.getCnt(); customOptionList cheatslst(cntcheats); GuiCustomOptionBrowser chtBrowser(400, 280, &cheatslst, CFG.theme_path, "bg_options_settings.png", bg_options_settings_png, 1, 90); chtBrowser.SetPosition(0, 90); chtBrowser.SetAlignment(ALIGN_CENTRE, ALIGN_TOP); chtBrowser.SetClickable(true); GuiText titleTxt(c.getGameName().c_str(), 28, (GXColor) {0, 0, 0, 255}); titleTxt.SetAlignment(ALIGN_CENTRE, ALIGN_TOP); titleTxt.SetMaxWidth(350, GuiText::SCROLL); titleTxt.SetPosition(12,40); for (int i = 0; i <= cntcheats; i++) { cheatslst.SetValue(i, "%s",c.getCheatName(i).c_str()); cheatslst.SetName(i, "OFF"); } HaltGui(); GuiWindow w(screenwidth, screenheight); w.Append(&settingsbackground); w.Append(&titleTxt); w.Append(&backBtn); w.Append(&createBtn); w.Append(&chtBrowser); mainWindow->SetState(STATE_DISABLED); mainWindow->ChangeFocus(&w); mainWindow->Append(&w); ResumeGui(); while (!exit) { VIDEO_WaitVSync (); ret = chtBrowser.GetClickedOption(); if (ret != -1) { const char *strCheck = cheatslst.GetName(ret); if (strncmp(strCheck,"ON",2) == 0) { cheatslst.SetName(ret,"%s","OFF"); } else if (strncmp(strCheck,"OFF",3) == 0) { cheatslst.SetName(ret,"%s","ON"); } } if (createBtn.GetState() == STATE_CLICKED) { createBtn.ResetState(); if (cntcheats > 0) { int selectednrs[30]; int x = 0; for (int i = 0; i <= cntcheats; i++) { const char *strCheck = cheatslst.GetName(i); if (strncmp(strCheck,"ON",2) == 0) { selectednrs[x] = i; x++; } } if (x == 0) { WindowPrompt(tr("Error"),tr("No cheats were selected"),tr("OK")); } else { subfoldercreate(Settings.Cheatcodespath); string chtpath = Settings.Cheatcodespath; string gctfname = chtpath + c.getGameID() + ".gct"; c.createGCT(selectednrs,x,gctfname.c_str()); WindowPrompt(tr("GCT File created"),NULL,tr("OK")); exit = true; break; } } else WindowPrompt(tr("Error"),tr("Could not create GCT file"),tr("OK")); } if (backBtn.GetState() == STATE_CLICKED) { backBtn.ResetState(); exit = true; break; } } HaltGui(); mainWindow->SetState(STATE_DEFAULT); mainWindow->Remove(&w); ResumeGui(); break; } return choice; }
void GUI::createBtns(int state) { wchar_t* level = (wchar_t*)levelList[currentLevel].c_str(); wchar_t* difficulty = (wchar_t*)difficultyList[currentDifficulty].c_str(); if(state == STATE_MENU) { this->nrOfBtns = 3; this->menuBtns = new Button[nrOfBtns]; this->menuBtns[0] = createBtn(D3DXVECTOR2(0.5f*(0.4f*SCREEN_WIDTH),0.5f*(0.7f*SCREEN_HEIGHT)), STARTGAME); this->menuBtns[1] = createBtn(D3DXVECTOR2(0.5f*(0.4f*SCREEN_WIDTH),0.5f*(0.9f*SCREEN_HEIGHT)), SETTINGS); this->menuBtns[2] = createBtn(D3DXVECTOR2(0.5f*(0.4f*SCREEN_WIDTH),0.5f*(1.1f*SCREEN_HEIGHT)), QUIT); } else if(state == STATE_SETTINGS) { this->nrOfBtns = 2; this->menuBtns = new Button[nrOfBtns]; this->menuBtns[0] = createBtn(D3DXVECTOR2(0.5f*(0.4f*SCREEN_WIDTH),0.5f*(0.7f*SCREEN_HEIGHT)), MUTE); this->menuBtns[1] = createBtn(D3DXVECTOR2(0.5f*(0.4f*SCREEN_WIDTH),0.5f*(1.5f*SCREEN_HEIGHT)), BACK); } else if(state == STATE_PAUSED) { this->nrOfBtns = 3; this->menuBtns = new Button[nrOfBtns]; this->menuBtns[0] = createBtn(D3DXVECTOR2(0.5f*(0.4f*SCREEN_WIDTH),0.5f*(0.7f*SCREEN_HEIGHT)), PAUSED_CONTINUE); this->menuBtns[1] = createBtn(D3DXVECTOR2(0.5f*(0.4f*SCREEN_WIDTH),0.5f*(0.9f*SCREEN_HEIGHT)), SETTINGS); this->menuBtns[2] = createBtn(D3DXVECTOR2(0.5f*(0.4f*SCREEN_WIDTH),0.5f*(1.1f*SCREEN_HEIGHT)), MAIN_MENU); for(int i = 0; i < this->nrOfBtns; i++) { setLeftAligned(this->menuBtns[i].text); } } else if(state == STATE_NEWGAME) { int time = Statistics::Getinstance()->readScoreFromFile("highscore.txt", convertWstrToStr(level)+".txt"); char temp[255]; string score = itoa(time, temp, 10); if(score == "0") { score = "No score set yet."; } else { string best = "Best time: "; int min = time/60; int sek = time%60; if(min != 0) { best.append( itoa(min, temp, 10) ); best.append(" min "); } best.append ( itoa(sek, temp, 10) ); best.append(" sek"); score = best; } bestTime = convertStrToWstr(score); this->nrOfBoxes = 3; this->textBoxes = new Text[nrOfBoxes]; this->textBoxes[0] = createTextBox(D3DXVECTOR2(0.5f*(0.4f*SCREEN_WIDTH),0.5f*(0.7f*SCREEN_HEIGHT)), level, 36, 0xffa8a8a8); this->textBoxes[1] = createTextBox(D3DXVECTOR2(0.5f*(0.4f*SCREEN_WIDTH),0.5f*(0.9f*SCREEN_HEIGHT)), difficulty, 36, 0xffa8a8a8); this->textBoxes[2] = createTextBox(D3DXVECTOR2(0.5f*(0.4f*SCREEN_WIDTH),0.5f*(1.1f*SCREEN_HEIGHT)), (wchar_t*)bestTime.c_str(), 24, 0xffa8a8a8); this->nrOfBtns = 6; this->menuBtns = new Button[nrOfBtns]; this->menuBtns[0] = createBtn(D3DXVECTOR2(textBoxes[0].pos.x - 80, textBoxes[0].pos.y), LAST); this->menuBtns[1] = createBtn(D3DXVECTOR2(textBoxes[0].pos.x + 80, textBoxes[0].pos.y), NEXT); this->menuBtns[2] = createBtn(D3DXVECTOR2(textBoxes[1].pos.x - 80, textBoxes[1].pos.y), LAST); this->menuBtns[3] = createBtn(D3DXVECTOR2(textBoxes[1].pos.x + 80, textBoxes[1].pos.y), NEXT); this->menuBtns[4] = createBtn(D3DXVECTOR2(0.4f*(0.5*SCREEN_WIDTH),0.5f*(1.45f*SCREEN_HEIGHT)), STARTGAME); this->menuBtns[5] = createBtn(D3DXVECTOR2(0.4f*(0.5*SCREEN_WIDTH),0.5f*(1.6f*SCREEN_HEIGHT)), BACK); } else if(state == STATE_LOADING) { this->nrOfBoxes = 1; this->textBoxes = new Text[nrOfBoxes]; this->textBoxes[0] = createTextBox(D3DXVECTOR2(0.5f*(1*SCREEN_WIDTH),0.5f*(1*SCREEN_HEIGHT)), L"LOADING", 150, 0xffa8a8a8); } else if(state == STATE_WIN) { getEndStats(); this->nrOfBoxes+=1; Text* temp = new Text[this->nrOfBoxes]; for(int i = 0; i < this->nrOfBoxes-1; i++) { temp[i] = this->textBoxes[i]; } delete []this->textBoxes; this->textBoxes = NULL; this->textBoxes = temp; for(int i = 0; i < 8; i++) { setLeftAligned(this->textBoxes[i]); } this->textBoxes[8] = createTextBox(D3DXVECTOR2(0.5f*(1*SCREEN_WIDTH),0.5f*(0.55f*SCREEN_HEIGHT)), L"You Won!", 62, 0xffa8a8a8); this->nrOfBtns =2; this->menuBtns = new Button[nrOfBtns]; this->menuBtns[0] = createBtn(D3DXVECTOR2(0.5f*(0.8f*SCREEN_WIDTH),0.5f*(1.6f*SCREEN_HEIGHT)), MAIN_MENU); this->menuBtns[1] = createBtn(D3DXVECTOR2(0.5f*(1.2f*SCREEN_WIDTH),0.5f*(1.6f*SCREEN_HEIGHT)), RETRY); Statistics::Getinstance()->writeScoreToFile( "highscore.txt" ); } else if(state == STATE_LOSE) { getEndStats(); this->nrOfBoxes+=1; Text* temp = new Text[this->nrOfBoxes]; for(int i = 0; i < this->nrOfBoxes-1; i++) { temp[i] = this->textBoxes[i]; } delete []this->textBoxes; this->textBoxes = NULL; this->textBoxes = temp; for(int i = 0; i < 8; i++) { setLeftAligned(this->textBoxes[i]); } this->textBoxes[8] = createTextBox(D3DXVECTOR2(0.5f*(1*SCREEN_WIDTH),0.5f*(0.55f*SCREEN_HEIGHT)), L"You Lost", 62, 0xffa8a8a8); this->nrOfBtns = 2; this->menuBtns = new Button[nrOfBtns]; this->menuBtns[0] = createBtn(D3DXVECTOR2(0.5f*(0.8f*SCREEN_WIDTH),0.5f*(1.6f*SCREEN_HEIGHT)), MAIN_MENU); this->menuBtns[1] = createBtn(D3DXVECTOR2(0.5f*(1.2f*SCREEN_WIDTH),0.5f*(1.6f*SCREEN_HEIGHT)), RETRY); } }
void TuiManager::parseControl(Node* container,xml_node<char> *item) { int tag = atof(item->first_attribute("tag")->value()); int x = atof(item->first_attribute("x")->value()); int y = atof(item->first_attribute("y")->value()); int w = atoi(item->first_attribute("width")->value()); int h = atoi(item->first_attribute("height")->value()); int rotation = atof(item->first_attribute("rotation")->value()); if(strcmp(item->first_attribute("type")->value(), kTuiContainerPanel) == 0){//panel CWidgetWindow* pPanel = createPanel(tag,x,y,w,h,rotation); container->addChild(pPanel); //recursive for( xml_node<char> *iitem = item->first_node( kTuiNodeControl );iitem != NULL; iitem = iitem->next_sibling()){ parseControl(pPanel,iitem); } }else if (strcmp(item->first_attribute("type")->value(), kTuiControlCell) == 0){//cell //recursive for (xml_node<char> *iitem = item->first_node(kTuiNodeControl); iitem != NULL; iitem = iitem->next_sibling()){ parseControl(container, iitem); } }else if(strcmp(item->first_attribute("type")->value(),kTuiControlImage) == 0){//image const char* file = item->first_attribute("image")->value(); float scaleX = atof(item->first_attribute("scaleX")->value()); float scaleY = atof(item->first_attribute("scaleY")->value()); CImageView *pImg = createImage(tag, file, scaleX, scaleY, x, y, rotation); container->addChild(pImg); }else if(strcmp(item->first_attribute("type")->value(),kTuiControlImage9) == 0){//image9 const char* file = item->first_attribute("image")->value(); float w = atof(item->first_attribute("width")->value()); float h = atof(item->first_attribute("height")->value()); float up = atof(item->first_attribute("up")->value()); float down = atof(item->first_attribute("down")->value()); float left = atof(item->first_attribute("left")->value()); float right = atof(item->first_attribute("right")->value()); CImageViewScale9 *pImg = createImage9(tag,file,x,y,w,h,up,down,left,right,rotation); container->addChild(pImg); }else if(strcmp(item->first_attribute("type")->value(),kTuiControlButton) == 0){//button const char* normal = item->first_attribute("normal")->value(); const char* select = item->first_attribute("select")->value(); const char* disable = item->first_attribute("disable")->value(); float w = atof(item->first_attribute("width")->value()); float h = atof(item->first_attribute("height")->value()); CButton *pBtn = createBtn(tag,normal,select,disable,x,y,w,h,rotation); container->addChild(pBtn); }else if(strcmp(item->first_attribute("type")->value(),kTuiControlToggleView) == 0){//toggleView const char* normal = item->first_attribute("normal")->value(); const char* select = item->first_attribute("select")->value(); const char* disable = item->first_attribute("disable")->value(); float exclusion = atof(item->first_attribute("exclusion")->value()); CToggleView* toggle = createToggleView(tag,exclusion,normal,select,disable,x,y,rotation); container->addChild(toggle); }else if(strcmp(item->first_attribute("type")->value(),kTuiControlSlider) == 0){//slider const char* bg = item->first_attribute("bg")->value(); const char* progress = item->first_attribute("progress")->value(); const char* thumb = item->first_attribute("thumb")->value(); CSlider *pSlider = createSlider(tag,bg,progress,thumb,x,y,rotation); container->addChild(pSlider); }else if(strcmp(item->first_attribute("type")->value(),kTuiControlProgress) == 0){//progress const char* bg = item->first_attribute("bg")->value(); const char* progress = item->first_attribute("progress")->value(); CProgressBar *pProgress = createProgress(tag,bg,progress,x,y,rotation); container->addChild(pProgress); }else if(strcmp(item->first_attribute("type")->value(),kTuiControlLabel) == 0){//label float size = atof(item->first_attribute("textSize")->value()); int alignment = atoi(item->first_attribute("alignment")->value()); const char* text = item->first_attribute("text")->value(); const char* font = item->first_attribute("textFont")->value(); float w = atof(item->first_attribute("width")->value()); float h = atof(item->first_attribute("height")->value()); int r = atoi(item->first_attribute("red")->value()); int g = atoi(item->first_attribute("green")->value()); int b = atoi(item->first_attribute("blue")->value()); int r2 = atoi(item->first_attribute("strokeRed")->value()); int g2 = atoi(item->first_attribute("strokeGreen")->value()); int b2 = atoi(item->first_attribute("strokeBlue")->value()); int strokeSize = atoi(item->first_attribute("strokeSize")->value()); int shadowDistance = atoi(item->first_attribute("shadowDistance")->value()); int shadowBlur = atoi(item->first_attribute("shadowBlur")->value()); CLabel *pLabel = createLabel(tag, text, font, alignment, size, r, g, b, x, y, w, h, r2,g2,b2,strokeSize,shadowDistance,shadowBlur,rotation); container->addChild(pLabel); }else if(strcmp(item->first_attribute("type")->value(),kTuiControlLabelAtlas) == 0){//labelAtlas const char* imgPath = item->first_attribute("image")->value(); float w = atof(item->first_attribute("width")->value()); float h = atof(item->first_attribute("height")->value()); CLabelAtlas *pLabAtlas = createLabelAtlas(tag,imgPath,x,y,w,h,rotation); container->addChild(pLabAtlas); }else if(strcmp(item->first_attribute("type")->value(),kTuiControlArmature) == 0){//armature const char* xml = item->first_attribute("xml")->value(); const char* png = item->first_attribute("png")->value(); const char* plist = item->first_attribute("plist")->value(); const char* name = item->first_attribute("name")->value(); Armature *pArmature = createArmature(tag,name,png,plist,xml,x,y,rotation); container->addChild(pArmature); }else if(strcmp(item->first_attribute("type")->value(),kTuiControlAnim) == 0){//animation const char* png = item->first_attribute("png")->value(); const char* plist = item->first_attribute("plist")->value(); const char* name = item->first_attribute("name")->value(); Sprite *pSprite = createAnim(tag,name,png,plist,x,y,rotation); container->addChild(pSprite); }else if(strcmp(item->first_attribute("type")->value(),kTuiControlControl) == 0){//controlView const char* baseboard = item->first_attribute("baseboard")->value(); const char* joystick = item->first_attribute("joystick")->value(); CControlView *pControl = createControl(tag,baseboard,joystick,x,y,rotation); container->addChild(pControl); }else if (strcmp(item->first_attribute("type")->value(), kTuiContainerScroll) == 0){//scrollView float w = atof(item->first_attribute("width")->value()); float h = atof(item->first_attribute("height")->value()); int direction = atof(item->first_attribute("direction")->value()); int innerWidth = atoi(item->first_attribute("innerWidth")->value()); int innerHeight = atoi(item->first_attribute("innerHeight")->value()); CScrollView *pView = createScrollView(tag, direction, innerWidth, innerHeight, x, y, w, h, rotation); container->addChild(pView); //recursive for (xml_node<char> *iitem = item->first_node(kTuiNodeControl); iitem != NULL; iitem = iitem->next_sibling()){ parseControl(pView->getContainer(), iitem); } }else if (strcmp(item->first_attribute("type")->value(), kTuiContainerLayout) == 0){//layout float w = atof(item->first_attribute("width")->value()); float h = atof(item->first_attribute("height")->value()); CLayout *pLayout = createLayout(tag, x, y, w, h, rotation); container->addChild(pLayout); //recursive for (xml_node<char> *iitem = item->first_node(kTuiNodeControl); iitem != NULL; iitem = iitem->next_sibling()){ parseControl(pLayout, iitem); } Vector<Node*> vet = pLayout->getChildren(); for (Node *pChild : vet){//Offset coordinates Because CLayout zero point in the lower left corner pChild->setPosition(pChild->getPosition() + Point(w / 2, h / 2)); } }else if(strcmp(item->first_attribute("type")->value(),kTuiControlListView) == 0){//listView float w = atof(item->first_attribute("width")->value()); float h = atof(item->first_attribute("height")->value()); const char* img = item->first_attribute("image")->value(); float num = atof(item->first_attribute("num")->value()); CListView* pList = createListView(tag,img,x,y,w,h,rotation); container->addChild(pList); for(int i=0; i<num;i++){//add item xml_node<char> *iitem = item->first_node( kTuiNodeControl ); w = atof(iitem->first_attribute("width")->value()); h = atof(iitem->first_attribute("height")->value()); CLayout *pLayout = createLayout(i,0,0,w,h,rotation); for( xml_node<char> *iiitem = iitem->first_node( kTuiNodeControl );iiitem!=NULL; iiitem = iiitem->next_sibling()){ parseControl(pLayout,iiitem); } Vector<Node*> vet = pLayout->getChildren(); for(Node *pChild : vet){//Offset coordinates Because CLayout zero point in the lower left corner if(pChild->getTag() > 0) pChild->setPosition(pChild->getPosition()+Point(w/2,h/2)); } pList->insertNodeAtLast(pLayout); } pList->reloadData(); }else if(strcmp(item->first_attribute("type")->value(),kTuiControlPageView) == 0){//pageView float w = atof(item->first_attribute("width")->value()); float h = atof(item->first_attribute("height")->value()); float num = atoi(item->first_attribute("num")->value()); int dir = atoi(item->first_attribute("direction")->value()); const char* img = item->first_attribute("image")->value(); CPageView *pPageView = createPageView(tag, img, dir, num, x, y, w, h, rotation); container->addChild(pPageView); }else if(strcmp(item->first_attribute("type")->value(),kTuiControlCheckBox) == 0){//checkBox const char* normal1 = item->first_attribute("normal1")->value(); const char* normal2 = item->first_attribute("normal2")->value(); const char* select1 = item->first_attribute("select1")->value(); const char* select2 = item->first_attribute("select2")->value(); const char* disable1 = item->first_attribute("disable1")->value(); const char* disable2 = item->first_attribute("disable2")->value(); CCheckBox *pCheckBox = createCheckBox(tag,normal1,normal2,select1,select2,disable1,disable2,x,y,rotation); container->addChild(pCheckBox); }else if(strcmp(item->first_attribute("type")->value(),kTuiControlArmatureBtn) == 0){//ArmatureBtn const char* png = item->first_attribute("png")->value(); const char* plist = item->first_attribute("plist")->value(); const char* name = item->first_attribute("name")->value(); const char* xml = item->first_attribute("xml")->value(); ArmatureBtn *pArmBtn = createArmatureBtn(tag,name,png,plist,xml,x,y,rotation); container->addChild(pArmBtn); }else if(strcmp(item->first_attribute("type")->value(),kTuiControlNumbericStepper) == 0){//NumbericStepper const char* lnormal = item->first_attribute("lnormal")->value(); const char* rnormal = item->first_attribute("rnormal")->value(); const char* lselect = item->first_attribute("lselect")->value(); const char* rselect = item->first_attribute("rselect")->value(); const char* ldisable = item->first_attribute("ldisable")->value(); const char* rdisable = item->first_attribute("rdisable")->value(); const char* stepBg = item->first_attribute("stepBg")->value(); NumericStepper *pNumStep = createNumStep(tag,lnormal,lselect,ldisable,rnormal,rselect,rdisable,stepBg,x,y,rotation); container->addChild(pNumStep); }else if(strcmp(item->first_attribute("type")->value(),kTuiControlPaticle) == 0){//Paticle const char* plist = item->first_attribute("plist")->value(); ParticleSystem *pPartical = createParticle(tag,plist,x,y); container->addChild(pPartical); }else if (strcmp(item->first_attribute("type")->value(), kTuiControlTable) == 0){//TableView float w = atof(item->first_attribute("width")->value()); float h = atof(item->first_attribute("height")->value()); float num = atoi(item->first_attribute("num")->value()); int dir = atoi(item->first_attribute("direction")->value()); int cellWidth = atoi(item->first_attribute("cellWidth")->value()); int cellHeight = atoi(item->first_attribute("cellHeight")->value()); const char* img = item->first_attribute("image")->value(); CTableView *pView = createTableView(tag, img, dir, num, cellWidth, cellHeight, x, y, w, h, rotation); container->addChild(pView); }else if (strcmp(item->first_attribute("type")->value(), kTuiControlGridView) == 0){//GridView float w = atof(item->first_attribute("width")->value()); float h = atof(item->first_attribute("height")->value()); int cellWidth = atoi(item->first_attribute("cellWidth")->value()); int cellHeight = atoi(item->first_attribute("cellHeight")->value()); int column = atoi(item->first_attribute("column")->value()); int num = atoi(item->first_attribute("num")->value()); const char* img = item->first_attribute("image")->value(); CGridView *pView = createGridView(tag, img, column, num, cellWidth, cellHeight, x, y, w, h, rotation); container->addChild(pView); }else if (strcmp(item->first_attribute("type")->value(), kTuiControlGridPageView) == 0){//GridPageView float w = atof(item->first_attribute("width")->value()); float h = atof(item->first_attribute("height")->value()); int cellWidth = atoi(item->first_attribute("cellWidth")->value()); int cellHeight = atoi(item->first_attribute("cellHeight")->value()); int column = atoi(item->first_attribute("column")->value()); int row = atoi(item->first_attribute("row")->value()); int num = atoi(item->first_attribute("num")->value()); int dir = atoi(item->first_attribute("direction")->value()); const char* img = item->first_attribute("image")->value(); CGridPageView *pView = createGridPageView(tag, img, dir, column, row, num, cellWidth, cellHeight, x, y, w, h, rotation); container->addChild(pView); }else if(strcmp(item->first_attribute("type")->value(),kTuiControlEditBox) == 0){//EditBox float w = atof(item->first_attribute("width")->value()); float h = atof(item->first_attribute("height")->value()); const char* img = item->first_attribute("image")->value(); int inputMode = atoi(item->first_attribute("inputMode")->value()); int inputFlag = atoi(item->first_attribute("inputFlag")->value()); EditBox *pEdit = createEditBox(tag, img, inputMode, inputFlag, x, y, w, h, rotation); container->addChild(pEdit); }else if (strcmp(item->first_attribute("type")->value(), kTuiControlMovieView) == 0){//MovieView const char* png = item->first_attribute("png")->value(); const char* plist = item->first_attribute("plist")->value(); const char* json = item->first_attribute("json")->value(); MovieView *pMovieView = createMovieView(tag, json, plist, png, x, y, rotation); container->addChild(pMovieView); }else if (strcmp(item->first_attribute("type")->value(), kTuiContainerCircleMenu) == 0){//CircleMenu float w = atof(item->first_attribute("width")->value()); float h = atof(item->first_attribute("height")->value()); CircleMenu *pMenu = createCircleMenu(tag, x, y, w, h, rotation); container->addChild(pMenu); //recursive for (xml_node<char> *iitem = item->first_node(kTuiNodeControl); iitem != NULL; iitem = iitem->next_sibling()){ parseControl(pMenu, iitem); } pMenu->reloadData(); } }
int main(int argc, char **argv) { /* define the event handlers for the events */ DACallbacks eventCallbacks = { destroy, /* destroy */ buttonPress, /* buttonPress */ buttonRelease, /* buttonRelease */ mouseMove, /* motion (mouse) */ mouseEnter, /* mouse enters window */ mouseLeave, /* mouse leaves window */ NULL /* timeout */ }; /* define regions (x, y, width, height) that need event-handling */ Region clipRegion = XCreateRegion(); DARect btn = {0, 0, 16, 16}, square = {0, 25, 22, 22}, slider = {24, 0, 23, 48}; /* define what to do if an event occurs in a rectangle */ DAActionRect *buttonPressRects, *buttonReleaseRects, *mouseMoveRects, *mouseEnterRects, *mouseLeaveRects; buttonPressRects = malloc(3 * sizeof(DAActionRect)); buttonPressRects[0] = setRectAction(btn, btnDown); buttonPressRects[1] = setRectAction(square, squareDown); buttonPressRects[2] = setRectAction(slider, sliderDown); buttonReleaseRects = malloc(2 * sizeof(DAActionRect)); buttonReleaseRects[0] = setRectAction(btn, btnUp); buttonReleaseRects[1] = setRectAction(slider, sliderUp); mouseMoveRects = malloc(sizeof(DAActionRect)); mouseMoveRects[0] = setRectAction(slider, sliderMove); mouseEnterRects = malloc(sizeof(DAActionRect)); mouseEnterRects[0] = setRectAction(slider, sliderEnter); mouseLeaveRects = malloc(2 * sizeof(DAActionRect)); mouseLeaveRects[0] = setRectAction(btn, btnLeave); mouseLeaveRects[1] = setRectAction(slider, sliderLeave); /* XXX: make action rectangles available outside main() * ...libDockapp should be able to do this... (reminder) */ actionRects = malloc(6 * sizeof(DAActionRect *)); actionRects[0] = buttonPressRects; actionRects[1] = buttonReleaseRects; actionRects[2] = mouseMoveRects; actionRects[3] = mouseEnterRects; actionRects[4] = mouseLeaveRects; actionRects[5] = NULL; /* provide standard command-line options */ DAParseArguments( argc, argv, /* Where the options come from */ NULL, 0, /* Our list with options - none as you can see */ "This is the help text for the rectangle example of how to " "use libDockapp.\n", "Rectangle example version 1.0"); /* Tell libdockapp what version we expect it to be, so that you can use * older programs with newer versions of libdockapp with less risc for * compatibility problems. */ DASetExpectedVersion(20030126); /* Initialize a dockapp */ DAInitialize( "", /* Use default display */ "daRectangleExample", /* WM_CLASS hint; don't use chars in [.?*: ] */ 48, 48, /* geometry of dockapp internals */ argc, argv /* (needed internally) */ ); /* Create a pixmap to draw on, and to display */ pixmap = DAMakePixmap(); /* size == dockapp geometry (48,48) */ colors = setGCs(pixmap); XFillRectangle(DADisplay, pixmap, DAClearGC, 0, 0, 48, 48); XClearWindow(DADisplay, DAWindow); /* Make a "Region" from the shapes we have */ XUnionRectWithRegion(&btn, clipRegion, clipRegion); XUnionRectWithRegion(&square, clipRegion, clipRegion); XUnionRectWithRegion(&slider, clipRegion, clipRegion); /* Make this region a window shape mask */ XShapeCombineRegion(DADisplay, DAWindow, ShapeBounding, 0, 0, clipRegion, ShapeSet); /* We don't need the region anymore (it is copied by XShapeCombineRegion). * XXX: That's not certain, it is not documented. XSetRegion does so, * though, so it is a likely assumption that it does copy. */ XDestroyRegion(clipRegion); /* The cursor we want to use. * Specify 'None' for the default, * or one from X11/cursorfont.h */ pointer = XCreateFontCursor(DADisplay, XC_based_arrow_up); XDefineCursor(DADisplay, DAWindow, pointer); /* a square with an image that changes when clicked (A button). */ createBtn(btn); /* a square that shows the number of the mouse-button pressed on click. */ createSquare(square); /* a slider a using two dashed line GC's. */ createSlider(slider); /* Tell libdockapp this is the pixmap that we want to show */ DASetPixmap(pixmap); /* Process events every 100ms */ DASetTimeout(100); /* set event callbacks */ DASetCallbacks(&eventCallbacks); /* Display the pixmap we said it to show */ DAShow(); /* Process events and keep the dockapp running */ DAEventLoop(); return 0; }