int main() { while(1) { //If left bumper is hit (or if both sensors are hit) if(digital(lSensor)) { //Backup bk(lMotor); bk(rMotor); sleep(backupTime); //Move Right moveRight(velocity); sleep(turnTime); } //If just right bumper is hit else if(digital(rSensor)) { //Backup bk(lMotor); bk(rMotor); sleep(backupTime); //Move Left moveLeft(velocity); sleep(turnTime); } //No Sensor is Hit else { //Move Forward moveForward(velocity); } } }
void touch_back(int sen) { while(digital(TOUCH_SEN) == 0) { bk(MOT_RIGHT); bk(MOT_LEFT); } }
void MainInterface::paintEvent(QPaintEvent *event) { /*画背景图*/ QPixmap bk(":/img/res/bk.png"); QPainter painter(this); painter.drawPixmap(this->rect(),bk); }
int main(int argc, char *argv[]) { QApplication a(argc, argv); MainWindow w; w.show(); BKTree<string> bk(&levenshteinDistance); bk.insert("book"); bk.insert("BOOKS"); bk.insert("cake"); bk.insert("boo"); bk.insert("cape"); bk.insert("cart"); bk.insert("boon"); bk.insert("cook"); bk.save("prueba"); bk.toPNG("prueba"); for(auto &iter:bk.find("caqe",1)) cout<<iter<<endl; return a.exec(); }
int main() { char *psz, szLine[MAX_LINE_LEN]; int iFreq[256]; int iNoCases, iCaseLoop, iChar, iLowerCaseChar; gets(szLine); sscanf(szLine, "%d", &iNoCases); /* scanf("%d", &iNoCases); */ for (iCaseLoop = 0; iCaseLoop < iNoCases; iCaseLoop++) { gets(szLine); /* scanf("%s", szLine); */ memset(iFreq + 'a', 0, ('z' - 'a' + 1) * sizeof(int)); memset(iFreq + 'A', 0, ('Z' - 'A' + 1) * sizeof(int)); for (psz = szLine; *psz; psz++) iFreq[*psz & 0xFF]++; iLen = 0; iCharCountParam = 0; for (iChar = 'A'; iChar <= 'Z'; iChar++) { if (iFreq[iChar]) { arrListParam[iCharCountParam].cChar = iChar; arrListParam[iCharCountParam++].iCount = iFreq[iChar]; iLen += iFreq[iChar]; } iLowerCaseChar = iChar - 'A' + 'a'; if (iFreq[iLowerCaseChar]) { arrListParam[iCharCountParam].cChar = iLowerCaseChar; arrListParam[iCharCountParam++].iCount = iFreq[iLowerCaseChar]; iLen += iFreq[iLowerCaseChar]; } } bk(0); } return 0; }
std::vector<std::string> anagrams(std::vector<std::string> &strs) { std::map<int, std::vector<Bucket> > buckets; for (size_t i = 0; i < strs.size(); ++i) { std::vector<int> key = this->calcKey(strs[i]); int hash = this->calcHash(key); std::vector<Bucket> &bucket(buckets[hash]); bool ok = false; for (size_t j = 0; j < bucket.size(); ++j) { Bucket &bk(bucket[j]); if (ok = this->equal(bk.key, key)) { bk.val.push_back(strs[i]); break; } } if (!ok) { bucket.push_back(Bucket()); bucket.back().key = key; bucket.back().val.push_back(strs[i]); } } std::vector<std::string> result; for (std::map<int, std::vector<Bucket> >::const_iterator iter = buckets.begin(); iter != buckets.end(); ++iter) { const std::vector<Bucket> &bucket(iter->second); for (size_t j = 0; j < bucket.size(); ++j) { const Bucket &bk(bucket[j]); if (bk.val.size() > 1) std::copy(bk.val.begin(), bk.val.end(), std::back_inserter(result)); } } return (result); }
int wb_dbms::del_family(wb_dbms_txn *txn, wb_dbms_cursor *cp, pwr_tOid poid) { int ret = 0; #if 0 dbName name; name.poid = poid; name.normname = ""; pwr_tOid oid = 0; FamilyKey nk(po, ); FamiltData nd(&oid, sizeof(oid)); wb_dbms_cursor *ncp; cp->dup(*ncp, 0); while ((ret = cp->get(&nk, &nd, DB_NEXT)) != DB_NOTFOUND) { del_family(txn, ncp, oid); cp->del(); oh_k ok(nd); oh_d od(); m_dbms_ohead->get(txn, &ok, &od, 0); wb_DbClistK ck(od); m_db_class->del(txn, &ck, 0); wb_DbBodyK bk(od); m_db_obody->del(txn, &bk, 0); m_db_ohead->del(txn, &ok, 0); } ncp->close(); ret = m_db_name->del(txn, &key, 0); #endif return ret; }
static QImage makeSplashImage(LiteApi::IApplication *app) { QRect r(0,0,400,280); QImage image(r.size(),QImage::Format_ARGB32_Premultiplied); QPainter painter(&image); painter.setRenderHint(QPainter::Antialiasing,true); QLinearGradient lg(0,0,r.width(),r.height()); lg.setColorAt(0.0,qRgb(0,125,127)); lg.setColorAt(1.0,qRgb(0,88,127)); QBrush bk(lg); painter.fillRect(r,bk); int th = r.height()*2/5; int bh = r.height()-th; painter.fillRect(1,th,r.width()-2,bh-1,Qt::white); QFont font("Timer",32); font.setPointSize(32); font.setItalic(true); painter.setPen(Qt::white); painter.setFont(font); painter.drawText(2,2,r.width()-2,th,Qt::AlignCenter,app->ideFullName()); font.setPointSize(9); font.setItalic(false); font.setBold(true); painter.setPen(Qt::black); painter.setFont(font); painter.drawText(10,th,r.width()-10,bh,Qt::AlignLeft|Qt::AlignVCenter,app->ideCopyright()); painter.drawImage(r.width()-145,r.height()-145,QImage("icon:/images/liteide-logo128.png")); return image; }
void MapperRoomRender::renderDummy(int dc_x, int dc_y) { int x = dc_x; int y = dc_y; CRect bk( x, y, x+m_size, y+m_size ); CRect p(1, 1, 1, 1); bk.DeflateRect(&p); fillBkg(bk.left,bk.top,bk.right-bk.left,bk.bottom-bk.top); }
/* * Class: Motor * Method: bk * Signature: (I)V */ JNIEXPORT void JNICALL Java_cbccore_low_Motor_bk(JNIEnv* env, jobject obj, jint motor) { #ifdef CBC return bk(motor); #else printf("Java_cbccore_low_Motor_bk stub\n"); #endif }
void Test_BronKerbosch::testRun() { BronKerbosch bk(this->p); bk.run(); std::list<std::list<unsigned long>> result = bk.get_result_list(); std::list<std::list<unsigned long>> check = {{3,4},{3,5},{1,5},{1,6,7},{0,2,4},{0,7,6,2}}; CPPUNIT_ASSERT(check == result); }
void Resource::readBank(const MemEntry *me, uint8_t *dstBuf) { uint16_t n = me - _memList; debug(DBG_BANK, "Resource::readBank(%d)", n); Bank bk(_dataDir); if (!bk.read(me, dstBuf)) { error("Resource::readBank() unable to unpack entry %d\n", n); } }
bool FilterTranspose::Apply( BitKey & iBitList, STEP_CODE_DATA_STRUCT & io_sdc ) { bool result = false; if(iBitList == ivBitKey) { BitKey bk(ivSingleBitPos); iBitList = bk; result = true; } return result; }
void bk(int iStep) { int i; if (iStep == iLen) { arrListSol[iStep] = '\0'; printf("%s\n", arrListSol); } for (i = 0; i < iCharCountParam; i++) if (arrListParam[i].iCount > 0) { arrListSol[iStep] = arrListParam[i].cChar; arrListParam[i].iCount -= 1; bk(iStep + 1); arrListParam[i].iCount += 1; } }
std::string function_algebra_polynomial1D::write_code_eval(::std::ostream& out, int& vnum, ::std::string const& var) const { ::std::string bk(makename("bk",vnum++)); ::std::string x1(makename("xtmp",vnum)); ::std::string r(makename("poly",vnum)); int n = degree(); out << "double " << bk << "(" << coeffs[n+1] << ");\n" << "double " << x1 << "(" << var << ");\n"; for(int k =1;k<=degree();k++){ out << bk << " *= " << x1 << "; " << bk << " += " << coeffs[n+1-k] << ";\n"; } out << "double " << r << "(" << bk << ");\n"; return r; }
void Resource::readBank(const MemEntry *me, uint8 *dstBuf) { uint16 n = me - _memList; debug(DBG_BANK, "Resource::readBank(%d)", n); #ifdef USE_UNPACKED_DATA char bankEntryName[64]; sprintf(bankEntryName, "ootw-%02X-%d.dump", n, me->type); File f; if (!f.open(bankEntryName, _dataDir)) { error("Resource::readBank() unable to open '%s' file\n", bankEntryName); } f.read(dstBuf, me->unpackedSize); #else Bank bk(_dataDir); if (!bk.read(me, dstBuf)) { error("Resource::readBank() unable to unpack entry %d\n", n); } #endif }
int Ardb::Type(const DBID& db, const Slice& key) { if (GetValue(db, key, NULL) == 0) { return KV; } int type = -1; Slice empty; KeyObject sk(key, SET_META, db); if (0 == GetValue(sk, NULL)) { return SET_ELEMENT; } KeyObject lk(key, LIST_META, db); if (0 == GetValue(lk, NULL)) { return LIST_META; } KeyObject zk(key, ZSET_META, db); if (0 == GetValue(zk, NULL)) { return ZSET_ELEMENT_SCORE; } HashKeyObject hk(key, empty, db); GET_KEY_TYPE(hk, type); if (type > 0) { return type; } KeyObject tk(key, TABLE_META, db); if (0 == GetValue(tk, NULL)) { return TABLE_META; } KeyObject bk(key, BITSET_META, db); if (0 == GetValue(bk, NULL)) { return BITSET_META; } return -1; }
vector<int> twoSum(vector<int>& nums, int target) { vector<int> bk(nums); sort(nums.begin(), nums.end()); vector<int> res; int lo=0, hi=nums.size()-1; int val1=-1, val2=-1; while (lo<hi) { if (nums[lo]+nums[hi]==target) { val1 = nums[lo]; val2 = nums[hi]; break; } else if (nums[lo]+nums[hi]<target) lo++; else hi--; } for (int i=0; i<nums.size(); i++) { if (bk[i]==val1 || bk[i]==val2) res.push_back(i+1); } return res; }
int main(int argc,char *argv[]) { QApplication a(argc,argv); QDir dir; QStringList filters; filters<<"*.png"<<"*.PNG"; dir.setNameFilters(filters); dir.setPath("."); QFileInfoList list = dir.entryInfoList(); QFileInfo k; QImage image(46,list.size()*46,QImage::Format_RGB32); QPainter imgpainter(&image); QImage bk(":/bk/bk.png"); bk=bk.scaled(46,46); for(int i=0;i<list.size();++i){ QImage im; k=list[i]; im.load(k.fileName()); QImage temp=im.scaled(40,40); QImage paintDevice=bk; QPainter painter(&paintDevice); QPen pen; pen.setColor(QColor("#a5a9d7")); pen.setWidth(1); painter.setPen(pen); painter.drawRoundedRect(0,0,45,45,2,2); painter.drawImage(3,3,temp); painter.end(); qreal y=46.0*i; imgpainter.save(); imgpainter.translate(0.0,y); imgpainter.drawImage(0,0,paintDevice); imgpainter.restore(); } image.save("pattern.png","PNG"); QMessageBox::information(0,"Notify","Image Composed Complete"); exit(0); return a.exec(); }
int Ardb::Type(const DBID& db, const Slice& key) { if (Exists(db, key)) { return KV; } int type = -1; Slice empty; SetKeyObject sk(key, empty, db); GET_KEY_TYPE(sk, type); if (type < 0) { ZSetScoreKeyObject zk(key, empty, db); GET_KEY_TYPE( zk, type); if (type < 0) { HashKeyObject hk(key, empty, db); GET_KEY_TYPE( hk, type); if (type < 0) { KeyObject lk(key, LIST_META, db); GET_KEY_TYPE( lk, type); if (type < 0) { KeyObject tk(key, TABLE_META, db); GET_KEY_TYPE(tk, type); if (type < 0) { KeyObject bk(key, BITSET_META, db); GET_KEY_TYPE(bk, type); } } } } } return type; }
void COwnerDrawnListControl::DrawItem(LPDRAWITEMSTRUCT pdis) { COwnerDrawnListItem *item = (COwnerDrawnListItem *)(pdis->itemData); CDC *pdc = CDC::FromHandle(pdis->hDC); CRect rcItem(pdis->rcItem); if(m_showGrid) { rcItem.bottom--; rcItem.right--; } CDC dcmem; dcmem.CreateCompatibleDC(pdc); CBitmap bm; bm.CreateCompatibleBitmap(pdc, rcItem.Width(), rcItem.Height()); CSelectObject sobm(&dcmem, &bm); dcmem.FillSolidRect(rcItem - rcItem.TopLeft(), GetItemBackgroundColor(pdis->itemID)); bool drawFocus = (pdis->itemState & ODS_FOCUS) != 0 && HasFocus() && IsFullRowSelection(); CArray<int, int> order; order.SetSize(GetHeaderCtrl()->GetItemCount()); GetHeaderCtrl()->GetOrderArray(order.GetData(), int(order.GetSize())); CRect rcFocus = rcItem; rcFocus.DeflateRect(0, LABEL_Y_MARGIN - 1); for(int i = 0; i < order.GetSize(); i++) { int subitem = order[i]; CRect rc = GetWholeSubitemRect(pdis->itemID, subitem); CRect rcDraw = rc - rcItem.TopLeft(); int focusLeft = rcDraw.left; if(!item->DrawSubitem(subitem, &dcmem, rcDraw, pdis->itemState, NULL, &focusLeft)) { item->DrawSelection(this, &dcmem, rcDraw, pdis->itemState); CRect rcText = rcDraw; rcText.DeflateRect(TEXT_X_MARGIN, 0); CSetBkMode bk(&dcmem, TRANSPARENT); CSelectObject sofont(&dcmem, GetFont()); CString s = item->GetText(subitem); UINT align = IsColumnRightAligned(subitem) ? DT_RIGHT : DT_LEFT; // Get the correct color in case of compressed or encrypted items COLORREF textColor = item->GetItemTextColor(); // Except if the item is selected - in this case just use standard colors if((pdis->itemState & ODS_SELECTED) && (HasFocus() || IsShowSelectionAlways()) && (IsFullRowSelection())) { textColor = GetItemSelectionTextColor(pdis->itemID); } // Set the text color CSetTextColor tc(&dcmem, textColor); // Draw the (sub)item text dcmem.DrawText(s, rcText, DT_SINGLELINE | DT_VCENTER | DT_WORD_ELLIPSIS | DT_NOPREFIX | align); // Test: dcmem.FillSolidRect(rcDraw, 0); } if(focusLeft > rcDraw.left) { if(drawFocus && i > 0) { pdc->DrawFocusRect(rcFocus); } rcFocus.left = focusLeft; } rcFocus.right = rcDraw.right; pdc->BitBlt(rcItem.left + rcDraw.left, rcItem.top + rcDraw.top, rcDraw.Width(), rcDraw.Height(), &dcmem, rcDraw.left, rcDraw.top, SRCCOPY); } if(drawFocus) { pdc->DrawFocusRect(rcFocus); } }
void secure() { char cha,daff[30];int s=0; setcolor(15);settextstyle(2,0,5); cleardevice();setbkcolor(0); bk();setcolor(15);rectangle(0,0,getmaxx(),getmaxy()); //outtextxy(250,14,"username");rectangle(320,13,600,28); outtextxy(250,40,"password");rectangle(320,40,600,55); settextstyle(2,0,4);cha=0; while(cha!=13) { if(kbhit()) { cha=getch(); if(cha!=8 && s<=200) {sprintf(daff,"%c",cha);outtextxy(330+s,14,daff); s+=10;} if(cha==8 && s>0 && s<=210) {setfillstyle(0,1); bar(330+s,14,330+s-10,24);s-=10;} }} cha=0; s=0; while(cha!=13) { if(kbhit()) { cha=getch(); if(cha!=8 && s<200) {sprintf(daff,"%c",cha);outtextxy(330+s,40,"*");s+=10;} if(cha==8 && s>0 && s<=210) {setfillstyle(0,1); bar(330+s,42,330+s-10,50);s-=10;} }} cha=0; cleardevice();setbkcolor(0); setcolor(3);settextstyle(2,0,5); outtextxy(40,100,"Payment mode"); setcolor(4); outtextxy(40,130,"credit"); setcolor(15); outtextxy(40,140,"debit"); outtextxy(40,150,"net banking."); pay=0;cha=0; while(cha!=27) { if(kbhit()) { cha=getch(); if(cha==80 && pay<2) {pay++;select_pay(pay);} if(cha==72 && pay>0) {pay--;select_pay(pay);} if(cha==13) break; }} }
void main(){ int gdriver = EGA, gmode = EGAHI, errorcode; initgraph(&gdriver, &gmode, "c:\\tc\\bgi"); bk(); travel(); gravitas(); tvar=0; m1c=m2c=adc=chdc=0; signup_traction(); while(ch!=27) { if(kbhit()) { ch=getch(); if(ch==77) {way(1);} if(ch==75) {way(0);} if(ch==80) {menu1();setcolor(6);settextstyle(2,0,4); outtextxy(68,180,"<-");break;} }} flag1: city(); m1c=0; while(ch!=27) { gravitas(); if(kbhit()) { ch=getch(); if(ch==80 && m1c<=15) //i city {menu1();city();++m1c;ibar();tarrow(m1c);mcounter(m1c);} if(ch==72 && m1c>=1 && m1c<=15) {menu1();city();m1c--;ibar();tarrow(m1c);mcounter(m1c);} if(ch==80 && m1c>=16 && m1c<=33) //2 city {menu1();city2();m1c++;ibar();tarrow(m1c);mcounter(m1c);} if(ch==72 && m1c>=16 && m1c<=33) {menu1();city2();m1c--;ibar();tarrow(m1c);mcounter(m1c);} if(ch==80 && m1c>=34 && m1c<=51) //3 city {menu1();city3();m1c++;ibar();tarrow(m1c);mcounter(m1c);} if(ch==72 && m1c>=34 && m1c<=51) {menu1();city3();m1c--;ibar();tarrow(m1c);mcounter(m1c);} if(ch==80 && m1c>=52 && m1c<56) //4 city {menu1();city4();m1c++;ibar();tarrow(m1c);mcounter(m1c);} if(ch==72 && m1c>=52 && m1c<=56) {menu1();city4();m1c--;ibar();tarrow(m1c);mcounter(m1c);} if(ch==13) {from=m1c; bk(); travel(); mcounter(m1c);from=m1c;if(tvar)tmcounter(m2c);break;} if(ch==77) { bk();travel();menu2();tcity();mcounter(m1c);from=m1c;menu2();break;} }} //flag2: m2c=0; while(ch!=27) { gravitas(); if(kbhit()) { ch=getch(); if(ch==80 && m2c<=15) //i city {menu2();tcity();++m2c;tbar();arrow(m2c);tmcounter(m2c);} if(ch==72 && m2c>=1 && m2c<=15) {menu2();tcity();m2c--;tbar();arrow(m2c);tmcounter(m2c);} if(ch==80 && m2c>=16 && m2c<=33) //2 city {menu2();tcity2();m2c++;tbar();arrow(m2c);tmcounter(m2c);} if(ch==72 && m2c>=16 && m2c<=33) {menu2();tcity2();m2c--;tbar();arrow(m2c);tmcounter(m2c);} if(ch==80 && m2c>=34 && m2c<=51) //3 city {menu2();tcity3();m2c++;tbar();arrow(m2c);tmcounter(m2c);} if(ch==72 && m2c>=34 && m2c<=51) {menu2();tcity3();m2c--;tbar();arrow(m2c);tmcounter(m2c);} if(ch==80 && m2c>=52 && m2c<56) //4 city {menu2();tcity4();m2c++;tbar();arrow(m2c);tmcounter(m2c);} if(ch==72 && m2c>=52 && m2c<=56) {menu2();tcity4();m2c--;tbar();arrow(m2c);tmcounter(m2c);} if(ch==13) {to=m2c; bk(); travel(); tvar=1;tmcounter(m2c);to=m2c;mcounter(m1c);break;} if(ch==75) {bk();travel(); to =m2c; tvar=1; tmcounter(m2c);to=m2c;menu1(); //goto flag1; break;} } } while(ch!=27) { gravitas(); if(kbhit()) { ch=getch(); if(ch==80 && adc<10) {admenu();adult(); adc++; adarrow(adc); adcounter(adc);} if(ch==72 && adc>0) {admenu();adult(); adc--; adarrow(adc);adcounter(adc);} if(ch==77) {adno=adc;chmenu();bk(); travel();tmcounter(m2c);mcounter(m1c);adcounter(adc);break;} if(ch==13) {adno=adc;bk(); travel();tmcounter(m2c);mcounter(m1c);adcounter(adc);break;} }} while(ch!=27) { gravitas(); if(kbhit()) { ch=getch(); if(ch==80 && chdc<10) {chmenu();child(); chdc++; charrow(chdc); chcounter(chdc);} if(ch==72 && chdc>0) {chmenu();child(); chdc--; charrow(chdc);chcounter(chdc);} if(ch==77) {chno=chdc;chmenu();bk(); travel();tmcounter(m2c);mcounter(m1c);adcounter(adc);chcounter(chdc); break;} if(ch==13) {chno=chdc;bk(); travel();tmcounter(m2c);mcounter(m1c);adcounter(adc);chcounter(chdc); break;} }} while(ch!=27) { gravitas(); if(kbhit()) { ch=getch(); if(ch==80 && inc<10) {inmenu();infant(); inc++; inarrow(inc); incounter(inc);} if(ch==72 && inc>0) {inmenu();infant(); inc--; inarrow(inc);incounter(inc);} if(ch==77) {inno=inc;inmenu();bk(); travel();tmcounter(m2c);mcounter(m1c);adcounter(adc);chcounter(chdc);incounter(inc); break;} if(ch==13) {inno=chdc;bk(); travel();tmcounter(m2c);mcounter(m1c);adcounter(adc);chcounter(chdc);incounter(inc); break;} }} while(ch!=27) { gravitas(); if(kbhit()) { ch=getch(); if(ch==77) {ecob(1);suit=1;} if(ch==75) {ecob(0);suit=0;} if(ch==13) {break;} } } setcolor(1);settextstyle(2,0,4); ch=0; while(ch!=13) { if(kbhit()) {da+=8; ch=getch(); if(isalnum(ch) && da<=95) {sprintf(dater,"%c",ch); outtextxy(da,272,dater);} if(ch==8 && da>=45 && da<=180) {da=da-8; setfillstyle(1,15); bar(da,272,da+8,285); da=da-8;} }} if(suit==0)flight(to); if(suit==1)bflight(to); traction(); secure(); money_transfer(); getch(); closegraph();}
void money_transfer() { char num,number[20],type[5];int n=0,t=0,coff=1; setcolor(15);settextstyle(2,0,5); setfillstyle(0,0); bar(20,120,100,180);bar(300,10,500,50); cleardevice();setbkcolor(0); outtextxy(30,314,"Enter the 10-digit Pin number:"); rectangle(260,314,600,334); num=0; while(num!=13) { setcolor(15);settextstyle(2,0,4); if(kbhit()) { num=getch(); if(isdigit(num) && num!=8 && n<100){ sprintf(number,"%c",num);outtextxy(265+n,314,"*");n+=10;} if(num==8 && n>0 && n<=100) {setfillstyle(0,1); bar(265+n,314,265+n-10,328);n-=10; } }} captcha(); num=0;n=0;w=0; while(num!=13) { settextstyle(2,0,4); if(kbhit()) { num=getch(); if(num!=8 && n<60){ sprintf(number,"%c",num); outtextxy(20+n,272,number);n+=10;} if(num==8 && n>0 && n<=60) {setfillstyle(1,15); bar(20+n,272,20+n-10,283);n-=10;} }} setfillstyle(0,0); bar(30,305,400,330); cleardevice();setbkcolor(0);num=0;bk(); setcolor(15);settextstyle(2,0,5); outtextxy(40,150,"accept the whole fare to transfer from your account?"); outtextxy(70,200,"yes(y)");outtextxy(130,200,"no(n)"); num=getch(); sprintf(number,"%c",num); outtextxy(40,230,number); if(num=='y') {cleardevice();setcolor(0);setcolor(3);settextstyle(2,0,5);bk(); outtextxy(50,240,"transaction is complete.successfully transmitted from your account."); } else { cleardevice();setcolor(3);settextstyle(2,0,5); outtextxy(50,240,"interupt caused.transaction stopped."); } }
void MapperRoomRender::renderRoom(int x, int y, const Room *r) { CRect rp( x, y, x+m_size, y+m_size ); //CRect base(rp); int cs = m_csize; // corridor size to draw (included) int ds = 2; // doors offset to draw (included) - x= lefx - ds, len = cs + ds + ds int rs = (cs- m_roomsizeDeflate) * 2; rp.DeflateRect(cs, cs, rs, rs); CRect bk(rp); bk.DeflateRect(2,2,0,0); HPEN old1 = m_hdc.SelectPen(m_black); rp.OffsetRect(1, 1); renderRect(rp.left,rp.top,rp.right-rp.left,rp.bottom-rp.top); rp.OffsetRect(-1, -1); m_hdc.SelectPen(m_white); renderRect(rp.left,rp.top,rp.right-rp.left,rp.bottom-rp.top); int offset = (rp.right - rp.left - cs) / 2; // start points for corridors - top, bottom, left, right int leftx = rp.left + offset; int topy = rp.top + offset; POINT ct = { leftx, rp.top }; POINT cb = { leftx, rp.bottom }; POINT cl = { rp.left, topy }; POINT cr = { rp.right, topy }; if (r->dirs[RD_NORTH].exist) { if (anotherZone(r, RD_NORTH)) { int x0 = ct.x; int x = ct.x - ds; int y = ct.y - 1; int len = cs + ds + ds; m_hdc.SelectPen(m_exit); renderLine(x,y,len,0); renderLine(x,y+1,len,0); renderLine(x,y+2,len,0); m_hdc.SelectPen(m_exitL); renderLine(x0,y+1,cs,0); } else if (neighbor(r, RD_NORTH)) { int x = ct.x; int x2 = x + cs; int y = ct.y; int len = -(cs+2); m_hdc.SelectPen(m_black); renderLine(x+1, y, 0, len); renderLine(x2, y, 0, len); m_hdc.SelectPen(m_white); renderLine(x, y, 0, len); renderLine(x2-1, y, 0, len); renderLine(x2, y, 1, 1); m_hdc.SelectPen(m_bkg); renderLine(x2-1, y+1, 1, 1); len = -(cs + 3); fillBkg(x + 2, y + 2, cs - 3, len); // затираем стенку } else { m_hdc.SelectPen(m_white); int x = ct.x + cs / 2; int y = ct.y; int dx = 0; int dy = 0; if (!calcDestOffset(dx, dy, r, RD_NORTH)) { renderLine(x, y, 0, -3); renderLine(x+1, y, 0, -3); } else { dy = dy + rp.bottom-rp.top; renderArrow(x+dx, y+dy, -5, 5, 5, 4, 1, 0); renderLine(x, y, dx, dy); renderLine(x+1, y, dx, dy); } } if (r->dirs[RD_NORTH].door) { int x = ct.x - ds; int y = ct.y; int len = cs + ds + ds; m_hdc.SelectPen(m_door); renderLine(x, y, len, 0); m_hdc.SelectPen(m_black); renderLine(x,y+1,len,0); } } if (r->dirs[RD_SOUTH].exist) { if (anotherZone(r, RD_SOUTH)) { int x0 = cb.x; int x = cb.x - ds; int y = cb.y + 1; int len = cs + ds + ds; m_hdc.SelectPen(m_exit); renderLine(x, y, len, 0); renderLine(x, y - 1, len, 0); renderLine(x, y - 2, len, 0); m_hdc.SelectPen(m_exitL); renderLine(x0, y - 1, cs, 0); } else if (neighbor(r, RD_SOUTH)) { int x = cb.x; int x2 = x + cs; int y = cb.y; int len = cs + 2; m_hdc.SelectPen(m_black); renderLine(x + 1, y, 0, len); renderLine(x2, y, 0, len); m_hdc.SelectPen(m_white); renderLine(x, y, 0, len); renderLine(x2 - 1, y, 0, len); m_hdc.SelectPen(m_bkg); renderLine(x+1, y-1, 1, 1); len = cs + 3; fillBkg(x + 2, y - 2, cs-3, len); // затираем стенку } else { m_hdc.SelectPen(m_white); int x = cb.x + cs / 2; int y = cb.y; int dx = 0; int dy = 0; if (!calcDestOffset(dx, dy, r, RD_SOUTH)) { renderLine(x, y, 0, 3); renderLine(x+1, y, 0, 3); } else { dy = dy - (rp.bottom-rp.top); renderArrow(x+dx, y+dy, -5, -5, 5, -4, 1, 0); renderLine(x, y, dx, dy); renderLine(x+1, y, dx, dy); } } if (r->dirs[RD_SOUTH].door) { int x = cb.x - ds; int y = cb.y ; int len = cs + ds + ds; m_hdc.SelectPen(m_door); renderLine(x, y, len, 0); m_hdc.SelectPen(m_black); renderLine(x, y-1, len, 0); } } if (r->dirs[RD_WEST].exist) { if (anotherZone(r, RD_WEST)) { int y0 = cl.y; int y = cl.y - ds; int x = cl.x + 1; int len = cs + ds + ds; m_hdc.SelectPen(m_exit); renderLine(x, y, 0, len); renderLine(x-1 , y, 0, len); renderLine(x-2, y, 0, len); m_hdc.SelectPen(m_exitL); renderLine(x-1, y0, 0, cs); } else if (neighbor(r, RD_WEST)) { int x = cl.x; int y = cl.y; int y2 = cl.y + cs; int len = -(cs + 2); m_hdc.SelectPen(m_black); renderLine(x, y+1, len, 0); renderLine(x, y2, len, 0 ); m_hdc.SelectPen(m_white); renderLine(x, y, len, 0); renderLine(x, y2-1, len, 0); renderLine(x, y2, 1, 1); m_hdc.SelectPen(m_bkg); renderLine(x + 1, y2 - 1, 1, 1); len = -(cs + 3); fillBkg(x+2, y + 2, len, cs - 3); // затираем стенку } else { m_hdc.SelectPen(m_white); int x = cl.x; int y = cl.y + cs / 2; int dx = 0; int dy = 0; if (!calcDestOffset(dx, dy, r, RD_WEST)) { renderLine(x, y, -3, 0); renderLine(x, y+1, -3, 0); } else { dx = dx + rp.right-rp.left; renderArrow(x+dx, y+dy, 5, -5, 4, 5, -1, 0); renderLine(x, y, dx, dy); renderLine(x, y+1, dx, dy); } } if (r->dirs[RD_WEST].door) { int x = cl.x; int y = cl.y - ds; int len = cs + ds + ds; m_hdc.SelectPen(m_door); renderLine(x, y, 0, len); m_hdc.SelectPen(m_black); renderLine(x+1, y, 0, len); } } if (r->dirs[RD_EAST].exist) { if (anotherZone(r, RD_EAST)) { int y0 = cr.y; int y = cr.y - ds; int x = cr.x - 1; int len = cs + ds + ds; m_hdc.SelectPen(m_exit); renderLine(x, y, 0, len); renderLine(x + 1, y, 0, len); renderLine(x + 2, y, 0, len); m_hdc.SelectPen(m_exitL); renderLine(x + 1, y0, 0, cs); } else if (neighbor(r, RD_EAST)) { int x = cr.x; int y = cr.y; int y2 = cr.y + cs; int len = cs + 2; m_hdc.SelectPen(m_black); renderLine(x, y + 1, len, 0); renderLine(x, y2, len, 0); m_hdc.SelectPen(m_white); renderLine(x, y, len, 0); renderLine(x, y2 - 1, len, 0); m_hdc.SelectPen(m_bkg); renderLine(x-1 , y+1, 1, 1); len = cs + 3; fillBkg(x - 2, y + 2, len, cs - 3); // затираем стенку } else { m_hdc.SelectPen(m_white); int x = cr.x; int y = cr.y + cs / 2; int dx = 0; int dy = 0; if (!calcDestOffset(dx, dy, r, RD_EAST)) { renderLine(x, y, 3, 0); renderLine(x, y+1, 3, 0); } else { dx = dx - (rp.right-rp.left); renderArrow(x+dx, y+dy, -5, -5, -4, 5, 0, 1); renderLine(x, y, dx, dy); renderLine(x, y+1, dx, dy); } } if (r->dirs[RD_EAST].door) { int x = cr.x; int y = cr.y - ds; int len = cs + ds + ds; m_hdc.SelectPen(m_door); renderLine(x, y, 0, len); m_hdc.SelectPen(m_black); renderLine(x - 1, y, 0, len); } } int bkw = bk.Width()-1; int bkh = bk.Height()-1; if (!r->selected) { if (!r->use_color) fillBkg(bk.left, bk.top, bkw, bkh ); else fillColor(bk.left, bk.top, bkw, bkh, r->color); } else { fillColor(bk.left, bk.top, bkw, bkh, RGB(255, 255, 255)); } if (r->icon > 0) { int icons_count = m_plist->GetImageCount(); int icon_size = m_icons_size; int x = bk.left + (bk.Width() - icon_size) / 2 - 1; int y = bk.top + (bk.Height() - icon_size) / 2 - 1; if (r->icon <= icons_count) { HICON icon = m_plist->GetIcon(r->icon - 1); ::DrawIconEx(m_hdc, x, y, icon, icon_size, icon_size, 1, NULL, DI_NORMAL); } } int de = cs + 1; // size up/down corridor if (r->dirs[RD_UP].exist) { int x = rp.left + 3; int y = rp.top + 3; int x2 = x + de; int y2 = y + de; m_hdc.SelectPen(m_black); renderLine(x2, y, 0, de); renderLine(x2, y2, -de, 0); m_hdc.SelectPen(m_white); renderLine(x,y2,0,-de); renderLine(x,y,de+1,0); if (r->dirs[RD_UP].door) { fillWhite(x+1,y+1,de-1,de-1); } else if (!r->dirs[RD_UP].next_room) // unknown room { fillBlack(x+1,y+1,de-1,de-1); } if (anotherZone(r, RD_UP)) { fillExit(x+1,y+1,de-1,de-1); m_hdc.SelectPen(m_exitL); renderLine(x2, y, 0, de); renderLine(x2, y2, -de, 0); renderLine(x,y2,0,-de); renderLine(x,y,de+1,0); } } if (r->dirs[RD_DOWN].exist) { int x = rp.right - 3; int y = rp.bottom - 3; int x2 = x - de; int y2 = y - de; m_hdc.SelectPen(m_black); renderLine(x2, y, 0, -de); renderLine(x2, y2, de, 0); m_hdc.SelectPen(m_white); renderLine(x,y2,0,de); renderLine(x,y,-de-1,0); if (r->dirs[RD_DOWN].door) { fillWhite(x,y,-de+1,-de+1); } else if (!r->dirs[RD_DOWN].next_room) // unknown room { fillBlack(x,y,-de+1,-de+1); } if (anotherZone(r, RD_DOWN)) { fillExit(x,y,-de+1,-de+1); m_hdc.SelectPen(m_exitL); renderLine(x2, y, 0, -de); renderLine(x2, y2, de, 0); renderLine(x,y2,0,de); renderLine(x,y,-de-1,0); } } m_hdc.SelectPen(old1); }
SEXP msbsvar_irf(SEXP gibbs, SEXP msbsvar, SEXP nsteps) { int i, k, n, N2, h, m, p, n0max, ns=INTEGER(nsteps)[0]; int *db, *dF, *dxi, *dQ, N210pct, pctct=0; SEXP bR, FR, xiR, QR, Ui, IRFlist, IRFtmp; // Rprintf("ns = %d\n",ns); // Get b, F, xi, Q, SS, dims from gibbs object PROTECT(bR = VECTOR_ELT(gibbs,0)); db=getdims(bR); // Rprintf("b(%d,%d)\n",db[0],db[1]); PROTECT(FR = VECTOR_ELT(gibbs,1)); dF=getdims(FR); // Rprintf("F(%d,%d)\n",dF[0],dF[1]); PROTECT(xiR= VECTOR_ELT(gibbs,2)); dxi=getdims(xiR); // Rprintf("xi(%d,%d)\n",dxi[0],dxi[1]); PROTECT(QR = VECTOR_ELT(gibbs,3)); dQ=getdims(QR); UNPROTECT(1); // Rprintf("Q(%d,%d)\n",dQ[0],dQ[1]); // Rprintf("Gibbs Objects and Dimensions Assigned\n"); // Reconstruct constants N2=db[0]; h=(int)sqrt((double)dQ[1]); n0max=db[1]/h; m=dxi[1]/h; p=((dF[1]/(h*m))-1)/m; N210pct=N2/10; // Rprintf("N2=%d\nh=%d\nm=%d\np=%d\nn0max=%d\n",N2,h,m,p,n0max); // Get Ui from msbsvar PROTECT(Ui=VECTOR_ELT(msbsvar,7)); Matrix bsample=R2Cmat(bR,N2,n0max*h); Matrix Fsample=R2Cmat(FR,N2,m*(m*p+1)*h); Matrix xisample=R2Cmat(xiR,N2,m*h); ColumnVector bk(n0max), Fk(m*(m*p+1)), bvec(m*m*p); bk=0.0; Fk=0.0; bvec=0.0; DiagonalMatrix xik(m), sqrtxik(m); xik=0.0; sqrtxik=0.0; Matrix Q(h,h), A0(m,m), A0i(m,m), fmat(m,m*p+1), sqrtwish, impulse(N2,m*m*ns); double *pFk; int IRFdims[]={N2,ns,m*m}; PROTECT(IRFlist=allocVector(VECSXP,h)); // Loop over regimes for(k=1;k<=h;k++){ // Rprintf("\n==========\nRegime %d\n==========\n",k); pctct=0; // Compute impulse responses for every draw of regime k for(n=1;n<=N2;n++){ // Rprintf("\nDraw %d:\n",n); // Get values for draw 'n', regime 'k' bk=bsample.SubMatrix(n,n,(k-1)*n0max+1,k*n0max).t(); // Rprintf("--bk(%d): ",bk.Storage()); //printCVector(bk); Fk=Fsample.SubMatrix(n,n,(k-1)*m*(m*p+1)+1,k*m*(m*p+1)).t(); pFk=Fk.Store(); // Rprintf("--Fk(%d): ",Fk.Storage()); //printCVector(Fk); for(i=1;i<=m;i++) xik(i)=sqrt(xisample(n,(k-1)*m+i)); // Rprintf("--xik(%d)/sqrtxik(%d) defined\n",m,m); // Compute A0/A0^-1/sqrtwish for regime k A0=b2a(bk,Ui); //Rprintf("--A0(%d,%d):",m,m); //printMatrix(A0); A0i=A0.i(); //Rprintf("--A0^-1(%d,%d):",m,m); //printMatrix(A0i); sqrtwish=(A0*xik).i(); //Rprintf("--sqrtwish(%d,%d):",m,m); //printMatrix(sqrtwish); // Compute beta vector fmat.ReSize(m,m*p+1); fmat<<pFk; fmat=fmat.t(); fmat=(fmat.Rows(1,m*p)*A0i).t(); bvec=fmat.AsColumn(); // Rprintf("--fmat(%d,%d):",m,m*p+1); printMatrix(fmat); // Rprintf("bvec_%d:", n); printCVector(bvec); // Compute IRF impulse.Row(n)=irf_var_from_beta(sqrtwish.t(), bvec, ns).t(); if (!(n%N210pct)) Rprintf("Regime %d: Monte Carlo IRF %d percent complete (Iteration %d)\n",k,++pctct*10,n); } // Create and class Robj for impulses, load into IRFlist PROTECT(IRFtmp=C2R3D(impulse,IRFdims)); setclass(IRFtmp,"mc.irf.BSVAR"); SET_VECTOR_ELT(IRFlist, k-1, IRFtmp); UNPROTECT(1); } UNPROTECT(5); return IRFlist; }
// Draws an item label (icon, text) in all parts of the WinDirStat view // the rest is drawn by DrawItem() void COwnerDrawnListItem::DrawLabel(COwnerDrawnListControl *list, CImageList *il, CDC *pdc, CRect& rc, UINT state, int *width, int *focusLeft, bool indent) const { CRect rcRest = rc; // Increase indentation according to tree-level if(indent) { rcRest.left += GENERAL_INDENT; } // Prepare to draw the file/folder icon ASSERT(GetImage() < il->GetImageCount()); IMAGEINFO ii; il->GetImageInfo(GetImage(), &ii); CRect rcImage(ii.rcImage); if(width == NULL) { // Draw the color with transparent background CPoint pt(rcRest.left, rcRest.top + rcRest.Height() / 2 - rcImage.Height() / 2); il->SetBkColor(CLR_NONE); il->Draw(pdc, GetImage(), pt, ILD_NORMAL); } // Decrease size of the remainder rectangle from left rcRest.left += rcImage.Width(); CSelectObject sofont(pdc, list->GetFont()); rcRest.DeflateRect(list->GetTextXMargin(), 0); CRect rcLabel = rcRest; pdc->DrawText(GetText(0), rcLabel, DT_SINGLELINE | DT_VCENTER | DT_WORD_ELLIPSIS | DT_CALCRECT | DT_NOPREFIX); rcLabel.InflateRect(LABEL_INFLATE_CX, 0); rcLabel.top = rcRest.top + LABEL_Y_MARGIN; rcLabel.bottom = rcRest.bottom - LABEL_Y_MARGIN; CSetBkMode bk(pdc, TRANSPARENT); COLORREF textColor = ::GetSysColor(COLOR_WINDOWTEXT); if(width == NULL && (state & ODS_SELECTED) != 0 && (list->HasFocus() || list->IsShowSelectionAlways())) { // Color for the text in a highlighted item (usually white) textColor = list->GetHighlightTextColor(); CRect selection = rcLabel; // Depending on "FullRowSelection" style if(list->IsFullRowSelection()) { selection.right = rc.right; } // Fill the selection rectangle background (usually dark blue) pdc->FillSolidRect(selection, list->GetHighlightColor()); } else { // Use the color designated for this item // This is currently only for encrypted and compressed items textColor = GetItemTextColor(); } // Set text color for device context CSetTextColor stc(pdc, textColor); if(width == NULL) { // Draw the actual text pdc->DrawText(GetText(0), rcRest, DT_SINGLELINE | DT_VCENTER | DT_WORD_ELLIPSIS | DT_NOPREFIX); } rcLabel.InflateRect(1, 1); *focusLeft = rcLabel.left; if((state & ODS_FOCUS) != 0 && list->HasFocus() && width == NULL && !list->IsFullRowSelection()) { pdc->DrawFocusRect(rcLabel); } if(width == NULL) { DrawAdditionalState(pdc, rcLabel); } rcLabel.left = rc.left; rc = rcLabel; if(width != NULL) { *width = rcLabel.Width() + 5; // Don't know, why +5 } }