void FrameBuffer::DrawPoint(int u, int v, int psize, unsigned int color) { for (int i = v - psize/2; i <= v + psize/2; i++) { for (int j = u - psize/2; j <= u + psize/2; j++) { SetSafe(j, i, color); } } }
void FrameBuffer::FillCircle(float cx, float cy, float r, unsigned int color) { for(float x = cx - r; x < cx + r; x++) { for(float y = cy - r; y < cy + r; y++) { float dx = cx - x; float dy = cy - y; if ((dx*dx + dy*dy) <= (r*r)) { SetSafe(x,y,color); } } } }
//8-way symmetry circle void FrameBuffer::DrawCircle(float cx, float cy, float r, unsigned int color) { SetSafe(cx + r, cy, color); SetSafe(cx, cx + r, color); SetSafe(cx, cy - r, color); float x = 1.0f; float y = r; y = sqrt((r*r) - 1) + 0.5; while (x < y) { SetSafe(cx + y, cy - x, color); SetSafe(cx - y, cy + x, color); SetSafe(cx - y, cy - x, color); SetSafe(cx + x, cy + y, color); SetSafe(cx + x, cy - y, color); SetSafe(cx - x, cy + y, color); SetSafe(cx - x, cy - y, color); SetSafe(cx + y, cy + x, color); y = sqrt((r*r) - (x*x)) + 0.5; x++; } if (abs(x - y) < 0.01) { SetSafe(cx + x, cy + y, color); SetSafe(cx + x, cy - y, color); SetSafe(cx - x, cy + y, color); SetSafe(cx - x, cy - y, color); } }
void Undo(WORD Flags) /* Flags: 0 = called as vi-like undo: * undo of whole last operation, * a second undo reverts the undo operation, * entered as character 'u'; * 1 = called as Windows-like undo: * undo last change at one position, * repeated undos go further back in history, * entered as <Alt+Bksp>, menu, or tool button; * 2 = repeated vi-like undo ('.'): * can repeat both undo and redo; * 4 = vi-like undo of whole line: * not yet implemented, * entered as character 'U'; */ { LPUNDO lpUndo; BOOL fUndone = FALSE; ULONG StartSkip = (ULONG)-1; extern INT HexEditFirstNibble; if (Flags & 3) lpUndo = NextSequenceUndo; else { lpUndo = NextSequenceUndo = LastUndo; if (LastUndo != NULL) { LastUndo->Flags |= UD_START; if (LastUndo->Flags & UD_BYUNDO) { if (Redoing && LastUndo->UndoRef!=NULL) lpUndo = LastUndo->UndoRef; Redoing ^= TRUE^FALSE; } else Redoing = FALSE; } } if (lpUndo==NULL || (Redoing && !(lpUndo->Flags & UD_BYUNDO))) { Error(219); return; } if (IsViewOnly()) return; if (UtfEncoding == 16) { /*any undo ops must be double-byte, check before doing anything...*/ LPUNDO lp = lpUndo; ULONG Skip; while (lp != NULL) { if ((Skip = lpUndo->Pos) != (ULONG)-1) { if (lp->DelFill & 1 || lp->Inserted & 1) { ErrorBox(MB_ICONSTOP, 260); return; } if (StartSkip == (ULONG)-1) StartSkip = Skip; if (Flags & 1) break; } if (lp->Flags & UD_NEWOP && StartSkip != (ULONG)-1) break; lp = lp->Prev; } StartSkip = (ULONG)-1; } HideEditCaret(); wsprintf(QueryString, "%s %s, used mem %lu", Redoing ? "redoing" : "undoing", lpUndo->Flags & UD_BYUNDO ? "undo" : "non-undo", UndoMemUsed); QueryTime = GetTickCount(); GlobalUndoFlags |= UD_BYUNDO; StartWithRemove = lpUndo->Flags & UD_START; StartUndoSequence(); if (FirstUndo == NULL || (FirstUndo->Next == NULL && FirstUndo != lpUndo)) lpUndo = NULL; StartWithRemove = TRUE; HexEditFirstNibble = -1; while (lpUndo != NULL) { POSITION Pos; ULONG Skip; if ((Skip = lpUndo->Pos) != (ULONG)-1) { if (StartSkip == (ULONG)-1) StartSkip = Skip; Pos.p = FirstPage; while (Skip >= Pos.p->Fill) { if (!Pos.p->Next) { if (Skip != Pos.p->Fill) { /*must not occur*/ assert(Skip == Pos.p->Fill); /*!?*/ return; } break; } Skip -= Pos.p->Fill; Pos.p = Pos.p->Next; } if (SelectCount) { InvalidateArea(&SelectStart, SelectCount, 1); SelectCount = 0; UpdateWindow(hwndMain); } Pos.i = (UINT)Skip; Pos.f = 0; /*TODO: check flags to be filled here*/ if (lpUndo->Inserted) { SelectStart = Pos; SelectCount = lpUndo->Inserted; SelectBytePos = CountBytes(&SelectStart); DeleteSelected(3); fUndone = TRUE; Indenting = FALSE; } if (lpUndo->DelFill) { LPSTR Buf; LONG ByteCount = CountBytes(&Pos); if (lpUndo->Flags & UD_GLOBALMEM) Buf = GlobalLock(lpUndo->DelMem); else Buf = (LPBYTE)lpUndo + sizeof(UNDO); if (Buf != NULL) { NewPosition(&Pos); InsertBuffer(Buf, lpUndo->DelFill, 0); fUndone = TRUE; if (lpUndo->Flags & UD_GLOBALMEM) GlobalUnlock(lpUndo->DelMem); /*reposition to current position...*/ Pos.p = FirstPage; Pos.i = 0; Advance(&Pos, ByteCount); if (lpUndo->Flags & UD_SELECT && Flags & 1) { SelectStart = Pos; SelectCount = lpUndo->DelFill; SelectBytePos = CountBytes(&SelectStart); InvalidateArea(&SelectStart, SelectCount, 0); CheckClipboard(); } } else ErrorBox(MB_ICONSTOP, 313); } if (Flags & 1) break; } if (lpUndo->Flags & UD_NEWOP && StartSkip != (ULONG)-1) break; lpUndo = lpUndo->Prev; } GlobalUndoFlags = 0; if (lpUndo != NULL) { if (lpUndo->Flags & UD_SAFE) { EnableToolButton(IDB_SAVE, FALSE); SetSafe(FALSE); GlobalUndoFlags = UD_SAFE; } else if (fUndone) SetUnsafe(); LastUndo->UndoRef = NextSequenceUndo = lpUndo->Prev; #if 0 // if (NextSequenceUndo!=NULL && lpUndo->Flags & UD_BYUNDO // && !(NextSequenceUndo->Flags&UD_BYUNDO)) // NextSequenceUndo->Flags &= ~UD_START; #endif } else { if (fUndone) SetUnsafe(); NextSequenceUndo = NULL; } if (Redoing) CheckForUndoneToRelease(FALSE); /*...undo information about redo and previous undo is not needed anymore * because the original undo information will be used instead. */ if (StartSkip != (ULONG)-1) { CurrPos.p = FirstPage; CurrPos.i = 0; Advance(&CurrPos, StartSkip); FindValidPosition(&CurrPos, (WORD)(Mode==InsertMode || Mode==ReplaceMode)); GetXPos(&CurrCol); } if (lpUndo==NULL || NextSequenceUndo==NULL) EnableToolButton(IDB_UNDO, FALSE); ShowEditCaret(); }