private void select(UIPadHandle selectThis, bool flip = true) { for (int i = 0; i < m_padsUI.Count; i++) { if (selectThis == m_padsUI[i]) { if (false == m_padsUI[i].Selected || !flip) { //Try to disconnect even when not connected so that the program knows that it doesn't need to connect anymore m_padsControl[i].disconnect(); m_lastSelected = selectThis; m_padsUI[i].Selected = true; } else if (true == m_padsUI[i].Selected && flip) { m_padsControl[i].connect(); m_padsUI[i].Selected = false; if (m_lastSelected == selectThis) //if the last selected is the one we are unselecting, we don't know which one was selected before that { m_lastSelected = null; } } } else { if ((SelectionMode.Single == m_mode && !m_padsControl[i].isConnected()) || (SelectionMode.Multiple == m_mode && !m_padsControl[i].isConnected() && false == m_padsUI[i].Selected) ) { m_padsControl[i].connect(); m_padsUI[i].Selected = false; } } } }
//Selects a new pad that has just been added/connected private void selectNew(UIPadHandle selectThis) { for (int i = 0; i < m_padsUI.Count; i++) { if (selectThis == m_padsUI[i]) { if (false == m_padsUI[i].Selected) { m_lastSelected = selectThis; m_padsUI[i].Selected = true; m_padsUI[i].IdentifyState = (AppState.Identification_Mode == m_state) ? true : false; } else if (true == m_padsUI[i].Selected) { m_padsControl[i].connect(); m_padsUI[i].Selected = false; m_lastSelected = null; } } else { if ((SelectionMode.Single == m_mode && !m_padsControl[i].isConnected()) || (SelectionMode.Multiple == m_mode && !m_padsControl[i].isConnected() && false == m_padsUI[i].Selected) ) { m_padsControl[i].connect(); m_padsUI[i].Selected = false; } } } }
private void shape_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { if (e.ChangedButton == MouseButton.Left) //&& e.ClickCount == 1) // Single Click { if (AppState.Selection_Mode == m_state) { if (m_padsUI.Count > 0) { select((UIPadHandle)sender); } } else { if (m_padsUI.Count > 0) { m_MouseOverSource = (UIPadHandle)sender; m_MouseOverSource.MouseCapture = true; m_captured = true; x_shape = m_MouseOverSource.XPos; x_canvas = e.GetPosition(canvas).X; y_shape = m_MouseOverSource.YPos; y_canvas = e.GetPosition(canvas).Y; } } } }
private void loadPads(wgssSTU.UsbDevices usbDevices) { for (int i = 0; i < m_padsControl.Count; i++) { UIPadHandle ph = new UIPadHandle(usbDevices[i].fileName, i, canvas); ph.ProductID = m_padsControl[i].getProductId(); ph.BorderThickness = 0; ph.Width = PadPixelWidth; ph.Height = PadPixelHeight; ph.XOffset = m_bitmapRes[ph.IDIndex].m_screen.m_pos.X; ph.YOffset = m_bitmapRes[ph.IDIndex].m_screen.m_pos.Y; ph.MouseDown += shape_MouseLeftButtonDown; ph.MouseMove += shape_MouseMove; ph.MouseUp += shape_MouseLeftButtonUp; ph.ImgSource = m_bitmapRes[ph.IDIndex].m_img; ph.WarningSource = m_warning; ph.Selected = false; ph.IdentifyState = false; ph.BorderThickness = m_selectThickness; m_padsUI.Add(ph); } }
public void AddDevice(wgssSTU.IUsbDevice addDev) { SpaceFinder sf = new SpaceFinder(canvas.ActualWidth, canvas.ActualHeight, m_padsUI, PadPixelWidth, PadPixelHeight); Point pos = sf.getFreeSpace(); int jn = GetNextNum(); UIPadHandle ph = new UIPadHandle(addDev.fileName, jn, canvas); m_padsControl.Add(new PadHandle(this, addDev, m_state, ph.Num)); ph.ProductID = addDev.idProduct; ph.Width = m_bitmapRes[ph.IDIndex].m_img.PixelWidth + 2 * m_selectThickness; ph.Height = m_bitmapRes[ph.IDIndex].m_img.PixelHeight + 2 * m_selectThickness; ph.XOffset = m_bitmapRes[ph.IDIndex].m_screen.m_pos.X; ph.YOffset = m_bitmapRes[ph.IDIndex].m_screen.m_pos.Y; ph.MouseDown += shape_MouseLeftButtonDown; ph.MouseMove += shape_MouseMove; ph.MouseUp += shape_MouseLeftButtonUp; ph.XPos = pos.X; ph.YPos = pos.Y; ph.ImgSource = m_bitmapRes[ph.IDIndex].m_img; ph.WarningSource = m_warning; ph.Width = PadPixelWidth; ph.Height = PadPixelHeight; ph.Selected = false; ph.IdentifyState = false; ph.BorderThickness = m_selectThickness; m_padsUI.Add(ph); selectNew(ph); if (AppState.Identification_Mode == m_state) { showPadNumberOnMonitor(m_padsUI.Count - 1); } setMinSizesCanvas(); }
public void RemoveDevice(wgssSTU.IUsbDevice remDev) { for (int j = 0; j < m_padsUI.Count; j++) { if (m_padsUI[j].Filename == remDev.fileName) { if (m_MouseOverSource != null && m_MouseOverSource.Filename == remDev.fileName) { m_MouseOverSource = null; } if (m_lastSelected != null && m_lastSelected.Filename == remDev.fileName) { m_lastSelected = null; } m_padsUI[j].RemoveFromCanvas(); m_padsUI.RemoveAt(j); m_padsControl[j].removeDevice(j, m_padsControl); break; } } setMinSizesCanvas(); }