public MSFake() { InitializeComponent(); this.DoubleBuffered = true; // filename in case filename is added later on filename = "Untitled*"; // ensure selection box doesn't get drawn on top of pic_selection.SendToBack(); // initialize bools sel_mouse_down = false; mouse_down = false; selected_box = false; show_toolbox = true; show_colors = true; // initialize various states _tool = TOOLS.Pencil; _curve_state = CURVESTATES.NoClick; _color = Color.Red; // set up font collection fonts = new List<string>(); FontFamily[] fontList = new System.Drawing.Text.InstalledFontCollection().Families; foreach (FontFamily font in fontList) fonts.Add(font.Name); cmb_fonts.DataSource = fonts; // set up canvas to be drawn on canvas = new Bitmap(panel_canvas.Width, panel_canvas.Height); }
private void CurveToolUp(MouseEventArgs e) { // functions as a state machine, changing // states when the mouse is released // while using the bezier curve tool switch (_curve_state) { case CURVESTATES.NoClick: _ending_point = new Point(e.X, e.Y); _curve_state = CURVESTATES.OneClick; break; case CURVESTATES.Drawn: _curve_state = CURVESTATES.NoClick; break; } }
private void btn_clear_Click(object sender, EventArgs e) { if (selected_box) { // if a selection is made, clear selection box only pic_selection.Image = null; pic_selection.Invalidate(); } else { // if no selection is made, clear entire canvas and // states canvas = new Bitmap(panel_canvas.Width, panel_canvas.Height); status_bar.Text = "Wiped canvas."; _curve_state = CURVESTATES.NoClick; last_x = null; last_y = null; panel_canvas.Invalidate(); } }
private void CurveToolDown(MouseEventArgs e) { // functions as a state machine for the bezier // curve tool, only drawing it after the correct // number of clicks have been made switch (_curve_state) { case CURVESTATES.NoClick: _starting_point = new Point(e.X, e.Y); break; case CURVESTATES.OneClick: _bez_1 = new Point(e.X, e.Y); _curve_state = CURVESTATES.TwoClicks; break; case CURVESTATES.TwoClicks: using (Graphics g = Graphics.FromImage(canvas)) { g.DrawBezier(new Pen(_color, Convert.ToSingle(updn_brush_size.Value)), _starting_point, _bez_1, new Point(e.X, e.Y), _ending_point); panel_canvas.Invalidate(); } _curve_state = CURVESTATES.Drawn; break; } }