Changeset 12574 for branches/FitnessLandscapeAnalysis/HeuristicLab.Problems.NK.Views/BoolMatrixBitmapView.cs
- Timestamp:
- 07/02/15 13:52:10 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/FitnessLandscapeAnalysis/HeuristicLab.Problems.NK.Views/BoolMatrixBitmapView.cs
r7141 r12574 1 using System; 2 using System.Collections.Generic; 1 #region License Information 2 /* HeuristicLab 3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 * 5 * This file is part of HeuristicLab. 6 * 7 * HeuristicLab is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation, either version 3 of the License, or 10 * (at your option) any later version. 11 * 12 * HeuristicLab is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>. 19 */ 20 #endregion 21 22 using System; 3 23 using System.ComponentModel; 4 24 using System.Drawing; 5 using System.Data;6 using System.Linq;7 using System.Text;8 using System.Windows.Forms;9 using HeuristicLab.MainForm;10 25 using HeuristicLab.Core.Views; 11 26 using HeuristicLab.Data; 12 using System.Threading;27 using HeuristicLab.MainForm; 13 28 14 29 namespace HeuristicLab.Problems.NK { 15 30 16 [View("BoolMatrix BitmapView")]31 [View("BoolMatrixView")] 17 32 [Content(typeof(BoolMatrix), IsDefaultView = false)] 18 33 public sealed partial class BoolMatrixView : ItemView { 34 private BackgroundWorker worker; 19 35 20 36 public new BoolMatrix Content { … … 25 41 public BoolMatrixView() { 26 42 InitializeComponent(); 27 } 43 } 28 44 29 protected override void DeregisterContentEvents() { 30 Content.ToStringChanged -= new EventHandler(Content_ToStringChanged);45 protected override void DeregisterContentEvents() { 46 Content.ToStringChanged -= Content_ToStringChanged; 31 47 base.DeregisterContentEvents(); 32 } 48 } 33 49 34 50 protected override void RegisterContentEvents() { 35 51 base.RegisterContentEvents(); 36 Content.ToStringChanged += new EventHandler(Content_ToStringChanged);52 Content.ToStringChanged += Content_ToStringChanged; 37 53 } 38 54 … … 43 59 #endregion 44 60 45 private BackgroundWorker worker;46 61 private void Rebuild() { 62 int width = pictureBox.Width; 63 int height = pictureBox.Height; 64 int tileWidth = width / Content.Columns; 65 int tileHeight = height / Content.Rows; 66 int border = (int)Math.Round((tileWidth + tileHeight) / 2.0 * 0.05); 67 var bitmap = new Bitmap(width, height); 68 47 69 if (worker != null) 48 70 worker.CancelAsync(); 71 72 if (tileWidth == 0 || tileHeight == 0) { 73 using (Graphics g = Graphics.FromImage(bitmap)) { 74 g.DrawString("BoolMatrix is to big to draw.", DefaultFont, new SolidBrush(Color.Black), 10.0f, height / 2.0f); 75 g.Flush(); 76 } 77 pictureBox.Image = bitmap; 78 return; 79 } 80 49 81 worker = new BackgroundWorker(); 50 82 worker.WorkerSupportsCancellation = true; 51 Thread.Sleep(1);52 var bitmap = new Bitmap(Content.Rows*4, Content.Columns*4);53 83 worker.DoWork += (s, a) => { 54 84 using (Graphics g = Graphics.FromImage(bitmap)) { 55 for (int i = 0; i <Content.Rows; i++) {56 for (int j = 0; j <Content.Columns; j++) {85 for (int i = 0; i < Content.Rows; i++) { 86 for (int j = 0; j < Content.Columns; j++) { 57 87 if (worker.CancellationPending) { 58 88 a.Cancel = true; 59 89 break; 60 90 } 61 g.FillRectangle(Content[i, j] ? Brushes. Green : Brushes.Red,62 i*4, j*4, 3, 3);91 g.FillRectangle(Content[i, j] ? Brushes.Black : Brushes.White, i * tileWidth, j * tileHeight, 92 tileWidth - border, tileHeight - border); 63 93 } 64 94 } … … 78 108 base.OnContentChanged(); 79 109 if (Content == null) { 80 pictureBox.Image = new Bitmap(1, 1); 110 pictureBox.Image = new Bitmap(1, 1); 81 111 } else { 82 112 Rebuild(); 83 113 } 84 114 } 85 86 protected override void SetEnabledStateOfControls() {87 base.SetEnabledStateOfControls();88 }89 90 #region Event Handlers (child controls)91 #endregion92 115 } 93 116 }
Note: See TracChangeset
for help on using the changeset viewer.