void RedoChange(CellChange change) { SetCharacter(change.X, change.Y, change.NewCharacter); SetBackgroundColor(change.X, change.Y, change.NewBackgroundColor); SetCharacterColor(change.X, change.Y, change.NewCharacterColor); SetCellOpacity(change.X, change.Y, change.NewOpacity); SetSpecialInfo(change.X, change.Y, change.NewSpecialInfo); }
void UndoChange(CellChange change) { SetCharacter(change.X, change.Y, change.OldCharacter); SetBackgroundColor(change.X, change.Y, change.OldBackgroundColor); SetCharacterColor(change.X, change.Y, change.OldCharacterColor); SetCellOpacity(change.X, change.Y, change.OldOpacity); SetSpecialInfo(change.X, change.Y, change.OldSpecialInfo); }
public void BlitString(List<CellChange> changes, string text, Color color, int x, int y) { for (int i = 0; i < text.Length; ++i) { if (x + i < width && y < height) { CellChange change = new CellChange(); change.X = x + i; change.Y = y; int c = x + i; int r = y; change.OldCharacter = GetCharacter(c, r); change.OldBackgroundColor = GetBackgroundColor(c, r); change.OldCharacterColor = GetCharacterColor(c, r); change.OldOpacity = IsCellOpaque(c, r); change.OldSpecialInfo = GetSpecialInfo(c, r); change.NewCharacter = text[i]; change.NewBackgroundColor = change.OldBackgroundColor; change.NewCharacterColor = color; change.NewOpacity = change.OldOpacity; change.NewSpecialInfo = change.OldSpecialInfo; changes.Add(change); SetCharacter(x + i, y, text[i]); SetCharacterColor(x + i, y, color); } } }
private void SurfacePanel_MouseDown(object sender, MouseEventArgs e) { HandleDrag(0, 0); //handle one-time click inputs if (e.Button == MouseButtons.Left) { if (surface != null && surface.IsInBounds(SelectedCell)) { //handle input for all valid selected cells int c = SelectedCell.X; int r = SelectedCell.Y; List<CellChange> changes = new List<CellChange>(); //a cell was clicked on. Handle the appropriate behavior for the selected mode. switch (Mode) { case InputMode.ToggleOpacity: for (int i = 0; i < selectionSize.X; ++i) { for (int j = 0; j < selectionSize.Y; ++j) { int x = c + i; int y = r + j; CellChange change = new CellChange(); change.X = x; change.Y = y; change.OldCharacter = surface.GetCharacter(c, r); change.OldBackgroundColor = surface.GetBackgroundColor(c, r); change.OldCharacterColor = surface.GetCharacterColor(c, r); change.OldOpacity = surface.IsCellOpaque(c, r); change.OldSpecialInfo = surface.GetSpecialInfo(c, r); change.NewCharacter = change.OldCharacter; change.NewBackgroundColor = change.OldBackgroundColor; change.NewCharacterColor = change.OldCharacterColor; change.NewOpacity = change.OldOpacity; change.NewSpecialInfo = change.OldSpecialInfo; if (c + i < surface.Width && r + j < surface.Height) { change.NewOpacity = !surface.IsCellOpaque(x, y); surface.SetCellOpacity(c + i, r + j, !surface.IsCellOpaque(c + i, r + j)); } changes.Add(change); } } break; case InputMode.SmallText: ShortTextForm form = new ShortTextForm(); DialogResult result = form.ShowDialog(this); if (result == DialogResult.OK) { surface.BlitString(changes, form.ChosenText, (Parent as EditorForm).BrushControl.CharacterColor, c, r); Refresh(); } break; case InputMode.LongText: LongTextForm longTextForm = new LongTextForm(); DialogResult longResult = longTextForm.ShowDialog(this); if (longResult == DialogResult.OK) { surface.BlitStringMultiline(changes, longTextForm.ChosenText, (Parent as EditorForm).BrushControl.CharacterColor, c, r, selectionSize.X, selectionSize.Y); Refresh(); } break; case InputMode.FillCells: EditorForm parent = (Parent as EditorForm); BrushControl brushControl = parent.BrushControl; if (brushControl.PaintCharacter) { FloodFillChar(changes, c, r, brushControl.Character); } if (brushControl.PaintBackgroundColor) { FloodFillBack(changes, c, r, brushControl.BackgroundColor); } if (brushControl.PaintCharacterColor) { FloodFillFore(changes, c, r, brushControl.CharacterColor); } Refresh(); break; case InputMode.EyeDropper: parent = (Parent as EditorForm); brushControl = parent.BrushControl; if (brushControl.PaintCharacter) { brushControl.Character = surface.GetCharacter(c, r); } if (brushControl.PaintBackgroundColor) { brushControl.BackgroundColor = surface.GetBackgroundColor(c, r); } if (brushControl.PaintCharacterColor) { brushControl.CharacterColor = surface.GetCharacterColor(c, r); } break; case InputMode.Shapes: firstCorner = selectedCell; break; } AddAction(changes); } } RefreshRect(new Rectangle(selectedCell.X, selectedCell.Y, selectionSize.X, selectionSize.Y)); DrawCursor(new Point(selectedCell.X, selectedCell.Y)); }
private void HandleDrag(int dx, int dy) { //handle dragging click inputs if (Control.MouseButtons.HasFlag(MouseButtons.Left)) { if (surface != null && surface.IsInBounds(SelectedCell)) { RefreshRect(new Rectangle(selectedCell.X - dx, selectedCell.Y - dy, selectionSize.X, selectionSize.Y)); List<CellChange> changes = new List<CellChange>(); //handle input for all valid selected cells for (int c = SelectedCell.X, i = 0; c < surface.Width && i < SelectionSize.X; ++c, ++i) { for (int r = SelectedCell.Y, j = 0; r < surface.Height && j < SelectionSize.Y; ++r, ++j) { if (c < 0) continue; if (r < 0) continue; bool valid = false; if (dx > 0 && i < selectionSize.X - dx) valid = true; if (dy > 0 && j < selectionSize.Y - dy) valid = true; if (dx < 0 && selectionSize.X - i < -dx) valid = true; if (dy < 0 && selectionSize.Y - j < -dy) valid = true; if (dx == 0 || dy == 0) valid = true; if (selectionSize == new Point(1, 1)) valid = true; if (!valid) continue; //a cell was clicked on. Handle the appropriate behavior for the selected mode. bool changed = false; CellChange change = new CellChange(); change.X = c; change.Y = r; change.OldCharacter = surface.GetCharacter(c, r); change.OldBackgroundColor = surface.GetBackgroundColor(c, r); change.OldCharacterColor = surface.GetCharacterColor(c, r); change.OldOpacity = surface.IsCellOpaque(c, r); change.OldSpecialInfo = surface.GetSpecialInfo(c, r); change.NewCharacter = change.OldCharacter; change.NewBackgroundColor = change.OldBackgroundColor; change.NewCharacterColor = change.OldCharacterColor; change.NewOpacity = change.OldOpacity; change.NewSpecialInfo = change.OldSpecialInfo; switch (Mode) { case InputMode.PaintBrush: EditorForm parent = (Parent as EditorForm); BrushControl brushControl = parent.BrushControl; if (brushControl.PaintCharacter) { change.NewCharacter = brushControl.Character; surface.SetCharacter(c, r, brushControl.Character); changed = true; } if (brushControl.PaintBackgroundColor) { change.NewBackgroundColor = brushControl.BackgroundColor; surface.SetBackgroundColor(c, r, brushControl.BackgroundColor); changed = true; } if (brushControl.PaintCharacterColor) { change.NewCharacterColor = brushControl.CharacterColor; surface.SetCharacterColor(c, r, brushControl.CharacterColor); changed = true; } break; case InputMode.SpecialInfo: string label = (Parent as EditorForm).SpecialInfoControl.SelectedLabel; if (label == "[Clear Info]") { label = ""; } change.NewSpecialInfo = label; surface.SetSpecialInfo(c, r, label); changed = true; break; } if (changed) changes.Add(change); } } DrawCursor(new Point(selectedCell.X, selectedCell.Y)); AddAction(changes); } } }
private void FloodFillFore(List<CellChange> changes, int x, int y, Color value) { Color prevValue = surface.GetCharacterColor(x, y); if (prevValue.R == value.R && prevValue.G == value.G && prevValue.B == value.B) return; CellChange change = new CellChange(); change.X = x; change.Y = y; int c = x; int r = y; change.OldCharacter = surface.GetCharacter(c, r); change.OldBackgroundColor = surface.GetBackgroundColor(c, r); change.OldCharacterColor = surface.GetCharacterColor(c, r); change.OldOpacity = surface.IsCellOpaque(c, r); change.OldSpecialInfo = surface.GetSpecialInfo(c, r); change.NewCharacter = change.OldCharacter; change.NewBackgroundColor = change.OldBackgroundColor; change.NewCharacterColor = value; change.NewOpacity = change.OldOpacity; change.NewSpecialInfo = change.OldSpecialInfo; changes.Add(change); surface.SetCharacterColor(x, y, value); if (x > 0 && surface.GetCharacterColor(x - 1, y) == prevValue) { FloodFillFore(changes, x - 1, y, value); } if (y > 0 && surface.GetCharacterColor(x, y - 1) == prevValue) { FloodFillFore(changes, x, y - 1, value); } if (x < surface.Width - 1 && surface.GetCharacterColor(x + 1, y) == prevValue) { FloodFillFore(changes, x + 1, y, value); } if (y < surface.Height - 1 && surface.GetCharacterColor(x, y + 1) == prevValue) { FloodFillFore(changes, x, y + 1, value); } }
public void ClearTransparency() { //add cell changes to stack List<CellChange> changes = new List<CellChange>(); for (int x = 0; x < surface.Width; ++x) { for (int y = 0; y < surface.Height; ++y) { CellChange change = new CellChange(); change.X = x; change.Y = y; change.OldCharacter = surface.GetCharacter(x, y); change.OldBackgroundColor = surface.GetBackgroundColor(x, y); change.OldCharacterColor = surface.GetCharacterColor(x, y); change.OldOpacity = surface.IsCellOpaque(x, y); change.OldSpecialInfo = surface.GetSpecialInfo(x, y); change.NewCharacter = change.OldCharacter; change.NewBackgroundColor = change.OldBackgroundColor; change.NewCharacterColor = change.OldCharacterColor; change.NewOpacity = true; change.NewSpecialInfo = change.OldSpecialInfo; changes.Add(change); } } AddAction(changes); surface.ClearTransparency(); }