public TargetTestBoard() { TestBoard = null; foreach (var dev in SignTest.Enumerate()) { try { TestBoard = new SignTest(dev); break; } catch { } } if (TestBoard == null) { throw new Exception("Unable to attach to a Sign Test board."); } SignComponent[] c = new SignComponent[1]; c[0] = new SignComponent() { X = 0, Y = 0, Width = 32, Height = 32 }; CurrentConfig = new SignConfiguration(c); // Initialize test board. TestBoard.SetMode(SignTest.DeviceMode.On); TestBoard.SetMode(SignTest.DeviceMode.FpgaActive); }
public void SendImage(Bitmap signImage) { lock (this) { SignConfiguration config = CurrentConfig; // For each element in the configuration, render it. for (int i = 0; i < config.Components.Length; i++) { SignComponent c = config.Components[i]; uint[] elementData = new uint[32 * 32]; try { for (int y = 0; y < 32; y++) { for (int x = 0; x < 32; x++) { elementData[x + y * 32] = (uint)signImage.GetPixel(x + c.X, y + c.Y).ToArgb(); } } TestBoard.SendImage32x32(i, elementData); } catch { } // Exceptions are generally due to configuration changes leading bitmap changes. } } }
public SignPreview() { lockObj = new object(); SignName = "Sign Preview"; if (PreviewIndex > 1) { SignName += " " + PreviewIndex; } PreviewIndex++; InitializeComponent(); Text = SignName; SignComponent[] c = new SignComponent[2]; c[0] = new SignComponent() { X = 0, Y = 0, Width = 32, Height = 32 }; c[1] = new SignComponent() { X = 32, Y = 0, Width = 32, Height = 32 }; CurrentConfig = new SignConfiguration(c); ResizeForConfiguration(); }
public bool Overlaps(SignComponent other) { return((X + Width > other.X) && (other.X + other.Width > X) && (Y + Height > other.Y) && (other.Y + other.Height > Y)); }
public EditElement(SignTargetConfigure container, SignComponent c) { Parent = container; Location = c; ImageTile = new PictureBox(); ImageSection = new Bitmap(Location.Width, Location.Height); ImageTile.Image = ImageSection; int scale = SignTargetConfigure.ScaleFactor; ImageTile.Width = Location.Width * scale; ImageTile.Height = Location.Height * scale; ImageTile.Location = new Point(Location.X * scale, Location.Y * scale); ImageTile.SizeMode = PictureBoxSizeMode.StretchImage; ImageTile.Cursor = Cursors.SizeAll; ImageTile.MouseDown += ImageTile_MouseDown; ImageTile.MouseMove += ImageTile_MouseMove; ImageTile.MouseUp += ImageTile_MouseUp; }
void AddNewElement(int width, int height) { SignComponent c = new SignComponent() { Width = width, Height = height }; EditElement e = new EditElement(this, c); // Find a new grid-aligned location that doesn't overlap with any other element for (int y = 0; y < MaxY; y += height) { for (int x = 0; x < MaxX; x += width) { e.Location.X = x; e.Location.Y = y; if (!e.Collides()) { break; } } if (!e.Collides()) { break; } } if (e.Collides()) { // Silently fail. return; } e.SyncLocation(); AddElement(e); ConfigurationChange(); }
void ImageTile_MouseMove(object sender, MouseEventArgs e) { int scale = SignTargetConfigure.ScaleFactor; int maxx = SignTargetConfigure.MaxX; int maxy = SignTargetConfigure.MaxY; int grid = 8; int minMove = grid * scale * 3 / 4; if (Dragging) { int dx = e.X - MouseX; int dy = e.Y - MouseY; int movex = 0; int movey = 0; if (Math.Abs(dx) > minMove) { movex = (int)Math.Round((float)dx / (grid * scale)) * grid; } if (Math.Abs(dy) > minMove) { movey = (int)Math.Round((float)dy / (grid * scale)) * grid; } // Clip to edges if (Location.X + movex < 0) { movex = -Location.X; } if (Location.Y + movey < 0) { movey = -Location.Y; } if (Location.X + movex + Location.Width > maxx) { movex = maxx - Location.X - Location.Width; } if (Location.Y + movey + Location.Height > maxy) { movey = maxy - Location.Y - Location.Height; } SignComponent fallback = Location; // Perform move Location.X += movex; Location.Y += movey; if (Collides()) { // Don't allow overlapping tiles Location = fallback; } else { ImageTile.Location = new Point(Location.X * scale, Location.Y * scale); Parent.ConfigurationChange(); } } }