int EBuffer::KillLine() { int Y = VToR(CP.Row); if (Y == RCount - 1) { if (DelText(Y, 0, LineLen())) return 1; } else if (DelLine(Y)) return 1; return 0; }
int EBuffer::BlockSort(int Reverse) { int rq; ELine *oldL; if (CheckBlock() == 0) return 0; if (RCount == 0) return 0; SortMinRow = BB.Row; SortMaxRow = BE.Row; if (BlockMode != bmStream || BE.Col == 0) SortMaxRow--; if (SortMinRow >= SortMaxRow) return 1; SortBuffer = this; SortReverse = Reverse; switch (BlockMode) { case bmLine: case bmStream: SortMinCol = -1; SortMaxCol = -1; break; case bmColumn: SortMinCol = BB.Col; SortMaxCol = BE.Col; break; } SortRows = (int *)malloc((SortMaxRow - SortMinRow + 1) * sizeof(int)); if (SortRows == 0) { free(SortRows); return 0; } for (rq = 0; rq <= SortMaxRow - SortMinRow; rq++) SortRows[rq] = rq + SortMinRow; qsort(SortRows, SortMaxRow - SortMinRow + 1, sizeof(int), SortProc); // now change the order of lines according to new order in Rows array. for (rq = 0; rq <= SortMaxRow - SortMinRow; rq++) { oldL = RLine(SortRows[rq]); if (InsLine(1 + rq + SortMaxRow, 0) == 0) return 0; if (InsChars(1 + rq + SortMaxRow, 0, oldL->Count, oldL->Chars) == 0) return 0; } for (rq = 0; rq <= SortMaxRow - SortMinRow; rq++) if (DelLine(SortMinRow) == 0) return 0; free(SortRows); return 1; }
//函数功能:删线 //参数: long CMapEditor10View::DeleteLinLBU(CPoint point) { CString str; int LineNum; FindNearLine(point,LineNum); EraseLine(LineNum); //图像中删除编号LineNum的线 DelLine(LineNum); return 1; }
//删除工具栏 BOOL RingDockSite::DelBar(RingDockBar* dockbar,BOOL bUpdate/*=TRUE*/) { if(dockbar && dockbar->GetChild() && dockbar->GetChild()->GetParent() == m_hWnd) { LPRINGBARLINEINFO line = NULL,save = dockbar->m_lineInfo; int nSize = BarOutLine(dockbar,TRUE,line); //line作为引用,由BarOutLine设置 if(line == NULL) DelLine(save); UpdateLine(line,nSize,bUpdate); return TRUE; } return FALSE; }
/*** delarg - deletes current selected area * * Purpose: * <graphic> and <quote> delete previously selected text. Here we do it * * Input: * pArg pointer to current ARG structure * * Output: * None * * Notes: * *************************************************************************/ void delarg ( ARG * pArg ) { fl fl; switch (pArg->argType) { case STREAMARG: DelStream (pFileHead, pArg->arg.streamarg.xStart, pArg->arg.streamarg.yStart, pArg->arg.streamarg.xEnd, pArg->arg.streamarg.yEnd ); fl.col = pArg->arg.streamarg.xStart; fl.lin = pArg->arg.streamarg.yStart; break; case LINEARG: DelLine (TRUE, pFileHead, pArg->arg.linearg.yStart, pArg->arg.linearg.yEnd); fl.col = 0; fl.lin = pArg->arg.linearg.yStart; break; case BOXARG: DelBox (pFileHead, pArg->arg.boxarg.xLeft, pArg->arg.boxarg.yTop, pArg->arg.boxarg.xRight, pArg->arg.boxarg.yBottom); fl.col = pArg->arg.boxarg.xLeft; fl.lin = pArg->arg.boxarg.yTop; break; default: return; } cursorfl(fl); }
///////////////////////////////////////////////////////////// // //加入工具栏,工具栏必须是本窗口的子窗口且dockbar已调用SetDockSite加入到本停靠坞 //函数自动判断该工具栏是新加入或需要调整位置 //lprc为相对于父窗口坐标 // ///////////////////////////////////////////////////////////// BOOL RingDockSite::AddBar(RingDockBar* dockbar,LPRECT lprc) { if(dockbar && dockbar->m_pSite == this) { int m,nSize,nDel=0; LPRINGBARLINEINFO tmp = NULL; LPRINGBARLINEINFO lpline = NULL; BOOL bLast = FALSE; RECT rc; if(lprc) { CopyRect(&rc,lprc); MapWindowPoints(m_parent->Handle(),m_hWnd,(LPPOINT)&rc,2); lprc = &rc; //指定位置停靠,先根据lprc的中线判断停靠位置 if(IsVert()) { if(dockbar->IsAllLineBar()) { m = lprc->left; lprc = NULL; } else m = (lprc->left + lprc->right)/2; } else { if(dockbar->IsAllLineBar()) { m = lprc->top; lprc = NULL; } else m = (lprc->top + lprc->bottom)/2; } } else m = 9999; //加到最后 //寻找要停靠的行 lpline = GetDockLine(m); LPRINGBARLINEINFO save = dockbar->m_lineInfo; if(save) //已停靠在本窗口位置 { nDel = BarOutLine(dockbar,(lpline != save),tmp); if(tmp == NULL && lpline != save) { //要删除行 DelLine(save); } } nSize = AddBarInLine(dockbar,lpline,lprc); if(dockbar->IsSizeBar()) { if(lpline->m_nSizeBarCnt == 0) nSize += m_SplitterSize; lpline->m_nSizeBarCnt ++; if(lprc == NULL) //第一次加入 dockbar->InitDockSize(); SetSizeSplitRect(lpline); } UpdateLine(NULL,nSize + nDel); return TRUE; } else return FALSE; }
//函数功能:连接两条线 //参数:线号1 2 long CMapEditor10View::ConnectLins(int lin1,int lin2) { int i=0; int j=0; int lin1num; int lin2num; double disX; double disY; CPoint temp; POINT Lin1[500]; POINT Lin2[500]; linnum1=SelectLinCon(lin1,Lin1); linnum2=SelectLinCon(lin2,Lin2); int resultType=HowToCon(Lin1,Lin2,linnum1-1,linnum2-1); if(linnum1==0 || linnum1==0) return 0; else switch(resultType) { case 0 : //尾跟头连 { for(i=0;i< linnum1;i++) linPnt[i]=Lin1[i]; for(i=linnum1;i< linnum2+linnum1;i++) { linPnt[i]=Lin2[i-linnum1]; } } break; case 1 : //尾跟尾连 { for(i=0;i< linnum1;i++) linPnt[i]=Lin1[i]; for(j=linnum1,i= linnum1+linnum2;i>=linnum1;i--,j++) { linPnt[j]=Lin2[i-linnum1-1]; } } break; case 2 : // 头跟头连 { for(i=0;i< linnum1;i++) linPnt[i]=Lin1[linnum1-i-1]; for(i=linnum1;i< linnum2+linnum1;i++) { linPnt[i]=Lin2[i-linnum1]; } } break; case 3 : // 头跟尾连 { for(i=0;i< linnum1;i++) linPnt[i]=Lin1[linnum1-i-1]; for(j=linnum1,i= linnum1+linnum2;i>=linnum1;i--,j++) { linPnt[j]=Lin2[i-linnum1-1]; } } break; default: break; } LinPntNum=linnum1+linnum2; EraseLine(lin1); //擦除两条线 EraseLine(lin2); DelLine(lin1); //文件中删除两条线 DelLine(lin2); WriteConLine(); DrawConLine(); firstlinnum=0; seclinnum=0; isfirst=0; issecond=0; LinPntNum=0; return 1; }
int EBuffer::BlockKill() { EPoint B, E; int L; int Y = -1; AutoExtend = 0; if (CheckBlock() == 0) return 0; if (RCount <= 0) return 0; B = BB; E = BE; Draw(B.Row, -1); // if (MoveToPos(B.Col, B.Row) == 0) return 0; #ifdef CONFIG_UNDOREDO if (BFI(this, BFI_Undo) == 1) { if (PushULong(CP.Col) == 0) return 0; if (PushULong(CP.Row) == 0) return 0; if (PushUChar(ucPosition) == 0) return 0; } #endif switch (BlockMode) { case bmLine: Y = VToR(CP.Row); if (Y >= B.Row) { if (Y >= E.Row) { if (SetPosR(CP.Col, Y - (E.Row - B.Row)) == 0) return 0; } else { if (SetPosR(CP.Col, B.Row) == 0) return 0; } } for (L = B.Row; L < E.Row; L++) if (DelLine(B.Row) == 0) return 0; break; case bmColumn: Y = VToR(CP.Row); if (Y >= B.Row && Y < E.Row) { if (CP.Col >= B.Col) { if (CP.Col >= E.Col) { if (SetPos(CP.Col - (E.Col - B.Col), CP.Row) == 0) return 0; } else { if (SetPos(B.Col, CP.Row) == 0) return 0; } } } for (L = B.Row; L < E.Row; L++) if (DelText(L, B.Col, E.Col - B.Col) == 0) return 0; break; case bmStream: Y = VToR(CP.Row); if (B.Row == E.Row) { if (Y == B.Row) { if (CP.Col >= B.Col) { if (CP.Col >= E.Col) { if (SetPos(CP.Col - (E.Col - B.Col), CP.Row) == 0) return 0; } else { if (SetPos(B.Col, CP.Row) == 0) return 0; } } } if (DelText(B.Row, B.Col, E.Col - B.Col) == 0) return 0; } else { if (Y >= B.Row) { if (Y > E.Row || (Y == E.Row && E.Col == 0)) { if (SetPosR(CP.Col, Y - (E.Row - B.Row)) == 0) return 0; } else if (Y == E.Row) { if (CP.Col >= E.Col) { if (SetPosR(CP.Col - E.Col + B.Col, B.Row) == 0) return 0; } else { if (SetPosR(B.Col, B.Row) == 0) return 0; } } else { if (SetPosR(B.Col, B.Row) == 0) return 0; } } if (DelText(E.Row, 0, E.Col) == 0) return 0; for (L = B.Row + 1; L < E.Row; L++) if (DelLine(B.Row + 1) == 0) return 0; if (DelText(B.Row, B.Col, -1) == 0) return 0; if (JoinLine(B.Row, B.Col) == 0) return 0; } break; } return BlockUnmark(); }
int ThreadFunc(void * unused){ int old_time,cur_time,x,y; old_time = cur_time = SDL_GetTicks(); while( !gameOver ){ while( alive ){ while( !Operation.isEmpty() && alive){ EnterCriticalSection(&cs); Operation.DeleteQ(command); curblk.ClearCube(); switch( command ){ case MOVEDOWN: curblk.MoveDown(); break; case MOVELEFT: curblk.MoveLeft(); break; case MOVERIGHT:curblk.MoveRight(); break; case ROTATE : curblk.Rotate(); break; } if( command == TURNNEXT ){ //有的特殊命令最好特殊处理 curblk.TurnNext(); break; } curblk.DrawCube(); Screen.flip(); LeaveCriticalSection(&cs); } cur_time = SDL_GetTicks(); SDL_Delay(1); if( !AIMode ){ if( cur_time - old_time < 500 ) continue; old_time = cur_time; Operation.AddQ(MOVEDOWN); }else{ if( cur_time - old_time < 50 ) continue; old_time = cur_time; x = curblk.x; y = curblk.y; if( BestRotate>0 ){ Operation.AddQ(ROTATE); BestRotate -= 1; continue; } if( BestPath[x][y+1] ){ Operation.AddQ(MOVEDOWN); BestPath[x][y+1] = 0; y += 1; continue; }else if( BestPath[x+1][y] ){ Operation.AddQ(MOVERIGHT); BestPath[x+1][y] = 0; x += 1; continue; }else if( BestPath[x-1][y] ){ Operation.AddQ(MOVELEFT); BestPath[x-1][y] = 0; x -= 1; continue; } alive = 0; } } while(DelLine()); Operation.ClearQ(); ShowCube(); ShowScore(); if( AIMode ) Search(); alive = 1; } return 0; }
int EBuffer::Find(SearchReplaceOptions &opt) { int slen = strlen(opt.strSearch); int Options = opt.Options; int rlen = strlen(opt.strReplace); RxNode *R = NULL; opt.resCount = -1; opt.lastInsertLen = 0; if (slen == 0) return 0; if (Options & SEARCH_BLOCK) { if (CheckBlock() == 0) return 0; } if (Options & SEARCH_RE) { R = RxCompile(opt.strSearch); if (R == 0) { View->MView->Win->Choice(GPC_ERROR, "Find", 1, "O&K", "Invalid regular expression."); return 0; } } if (Options & SEARCH_GLOBAL) { if (Options & SEARCH_BLOCK) { if (Options & SEARCH_BACK) { if (SetPosR(BE.Col, BE.Row) == 0) goto error; } else { if (SetPosR(BB.Col, BB.Row) == 0) goto error; } } else { if (Options & SEARCH_BACK) { if (RCount < 1) goto error; if (SetPosR(LineLen(RCount - 1), RCount - 1) == 0) goto error; } else { if (SetPosR(0, 0) == 0) goto error; } } } opt.resCount = 0; while (1) { if (Options & SEARCH_RE) { if (FindRx(R, opt) == 0) goto end; } else { if (FindStr(opt.strSearch, slen, opt) == 0) goto end; } opt.resCount++; if (opt.Options & SEARCH_REPLACE) { char ask = 'A'; if (!(Options & SEARCH_NASK)) { char ch; while (1) { Draw(VToR(CP.Row), 1); Redraw(); switch (View->MView->Win->Choice(0, "Replace", 5, "&Yes", "&All", "&Once", "&Skip", "&Cancel", "Replace with %s?", opt.strReplace)) { case 0: ch = 'Y'; break; case 1: ch = 'A'; break; case 2: ch = 'O'; break; case 3: ch = 'N'; break; case 4: case -1: default: ch = 'Q'; break; } if (ch == 'Y') { ask = 'Y'; goto ok_rep; } if (ch == 'N') { ask = 'N'; goto ok_rep; } if (ch == 'Q') { ask = 'Q'; goto ok_rep; } if (ch == 'A') { ask = 'A'; goto ok_rep; } if (ch == 'O') { ask = 'O'; goto ok_rep; } } ok_rep: if (ask == 'N') goto try_join; if (ask == 'Q') goto end; if (ask == 'A') Options |= SEARCH_NASK; } if (Options & SEARCH_RE) { PELine L = RLine(Match.Row); int P, R; char *PR = 0; int LR = 0; R = Match.Row; P = Match.Col; P = CharOffset(L, P); if (0 == RxReplace(opt.strReplace, L->Chars, L->Count, MatchRes, &PR, &LR)) { if (DelText(R, Match.Col, MatchLen) == 0) goto error; if (PR && LR > 0) if (InsText(R, Match.Col, LR, PR) == 0) goto error; if (PR) free(PR); rlen = LR; } } else { if (DelText(Match.Row, Match.Col, MatchLen) == 0) goto error; if (InsText(Match.Row, Match.Col, rlen, opt.strReplace) == 0) goto error; // Cursor remains at start of inserted string. If there is recursive // replace pattern, fte can go it infinite loop. // Workaround: Move cursor to end of inserted string opt.lastInsertLen = strlen(opt.strReplace); } if (!(Options & SEARCH_BACK)) { MatchLen = rlen; MatchCount = rlen; } if (ask == 'O') goto end; } try_join: if (Options & SEARCH_JOIN) { char ask = 'A'; if (!(Options & SEARCH_NASK)) { char ch; while (1) { Draw(VToR(CP.Row), 1); Redraw(); switch (View->MView->Win->Choice(0, "Join Line", 5, "&Yes", "&All", "&Once", "&Skip", "&Cancel", "Join lines %d and %d?", 1 + VToR(CP.Row), 1 + VToR(CP.Row) + 1)) { case 0: ch = 'Y'; break; case 1: ch = 'A'; break; case 2: ch = 'O'; break; case 3: ch = 'N'; break; case 4: case -1: default: ch = 'Q'; break; } if (ch == 'Y') { ask = 'Y'; goto ok_join; } if (ch == 'N') { ask = 'N'; goto ok_join; } if (ch == 'Q') { ask = 'Q'; goto ok_join; } if (ch == 'A') { ask = 'A'; goto ok_join; } if (ch == 'O') { ask = 'O'; goto ok_join; } } ok_join: if (ask == 'N') goto try_split; if (ask == 'Q') goto end; if (ask == 'A') Options |= SEARCH_NASK; } if (JoinLine(Match.Row, Match.Col) == 0) goto error; if (ask == 'O') goto end; } try_split: if (Options & SEARCH_SPLIT) { char ask = 'A'; if (!(Options & SEARCH_NASK)) { char ch; while (1) { Draw(VToR(CP.Row), 1); Redraw(); switch(View->MView->Win->Choice(0, "Split Line", 5, "&Yes", "&All", "&Once", "&Skip", "&Cancel", "Split line %d?", VToR(CP.Row))) { case 0: ch = 'Y'; break; case 1: ch = 'A'; break; case 2: ch = 'O'; break; case 3: ch = 'S'; break; case 4: case -1: default: ch = 'Q'; break; } if (ch == 'Y') { ask = 'Y'; goto ok_split; } else if (ch == 'N') { ask = 'N'; goto ok_split; } else if (ch == 'Q') { ask = 'Q'; goto ok_split; } else if (ch == 'A') { ask = 'A'; goto ok_split; } else if (ch == 'O') { ask = 'O'; goto ok_split; } } ok_split: if (ask == 'N') goto try_delete; if (ask == 'Q') goto end; if (ask == 'A') Options |= SEARCH_NASK; } if (SplitLine(Match.Row, Match.Col + strlen(opt.strReplace)) == 0) goto error; if (ask == 'O') goto end; } try_delete: if (Options & SEARCH_DELETE) { char ask = 'A'; if (!(Options & SEARCH_NASK)) { char ch; while (1) { Draw(VToR(CP.Row), 1); Redraw(); switch (View->MView->Win->Choice(0, "Delete Line", 5, "&Yes", "&All", "&Once", "&Skip", "&Cancel", "Delete line %d?", VToR(CP.Row))) { case 0: ch = 'Y'; break; case 1: ch = 'A'; break; case 2: ch = 'O'; break; case 3: ch = 'N'; break; case 4: case -1: default: ch = 'Q'; break; } if (ch == 'Y') { ask = 'Y'; goto ok_delete; } if (ch == 'N') { ask = 'N'; goto ok_delete; } if (ch == 'Q') { ask = 'Q'; goto ok_delete; } if (ch == 'A') { ask = 'A'; goto ok_delete; } if (ch == 'O') { ask = 'O'; goto ok_delete; } } ok_delete: if (ask == 'N') goto next; if (ask == 'Q') goto end; if (ask == 'A') Options |= SEARCH_NASK; } if (Match.Row == RCount - 1) { if (DelText(Match.Row, 0, LineLen()) == 0) goto error; } else if (DelLine(Match.Row) == 0) goto error; if (ask == 'O') goto end; if (!(Options & SEARCH_ALL)) break; goto last; } next: if (!(Options & SEARCH_ALL)) break; Options |= SEARCH_NEXT; last: ; } end: // end of search if (R) RxFree(R); if (Options & SEARCH_ALL) Msg(S_INFO, "%d match(es) found.", opt.resCount); else { if (opt.resCount == 0) { Msg(S_INFO, "[%s] not found", opt.strSearch); return 0; } } return 1; error: if (R) { RxFree(R); } View->MView->Win->Choice(GPC_ERROR, "Find", 1, "O&K", "Error in search/replace."); return 0; }