private void GetScreensFromToolbars(CarToolBar root, CarToolBar current, ICollection <SawMillScreen> screens) { foreach (CarToolBarButton button in current.Buttons) { if (button.Data is SawMillScreen) { screens.Add(button.Data as SawMillScreen); } else if (button.Data is CarToolBar) { if (button.Data != root) { this.GetScreensFromToolbars(root, button.Data as CarToolBar, screens); } } } }
private List <SawMillScreen> BuildToolbars() { this.mainToolBar = new CarToolBar(); CarToolBar gaugeToolBar = new CarToolBar(); CarToolBar scatterToolBar = new CarToolBar(); CarToolBar heatMapToolBar = new CarToolBar(); CarToolBar exitToolBar = new CarToolBar(); int leftButtonWidth = 50; List <CarToolBarButton> mainButtons = new List <CarToolBarButton>(); mainButtons.Add(new CarToolBarButton("<", exitToolBar, leftButtonWidth)); // placeholder for back button in other menus mainButtons.Add(new CarToolBarButton("Gauges", gaugeToolBar)); mainButtons.Add(new CarToolBarButton("Scatter Plots", scatterToolBar)); mainButtons.Add(new CarToolBarButton("Tables", heatMapToolBar)); mainButtons[1].Selected = true; mainToolBar.Buttons = mainButtons; List <CarToolBarButton> gaugeButtons = new List <CarToolBarButton>(); gaugeButtons.Add(new CarToolBarButton("<", mainToolBar, leftButtonWidth)); gaugeButtons.Add(new CarToolBarButton("Main", new SixPackScreen("Main", GetSixPackParameters("Main")))); gaugeButtons.Add(new CarToolBarButton("Boost", new SixPackScreen("Boost", GetSixPackParameters("Boost")))); gaugeButtons.Add(new CarToolBarButton("Timing", new SixPackScreen("Timing", GetSixPackParameters("Timing")))); gaugeButtons.Add(new CarToolBarButton("Misfire", new SixPackScreen("Roughness", GetSixPackParameters("Roughness")))); gaugeButtons.Add(new CarToolBarButton("Trims", new SixPackScreen("Fuel Trim", GetSixPackParameters("FTrim")))); gaugeButtons.Add(new CarToolBarButton("A", new SixPackScreen("A", GetSixPackParameters("A")))); gaugeButtons.Add(new CarToolBarButton("B", new SixPackScreen("B", GetSixPackParameters("B")))); gaugeButtons[1].Selected = true; gaugeToolBar.Buttons = gaugeButtons; List <CarToolBarButton> scatterButtons = new List <CarToolBarButton>(); scatterButtons.Add(new CarToolBarButton("<", mainToolBar, leftButtonWidth)); scatterButtons.Add(new CarToolBarButton("MAF", new RpmMafScreen(Settings.Default.MaxRpm, Settings.Default.MaxMafGS))); scatterButtons.Add(new CarToolBarButton("Load", new RpmLoadScreen(Settings.Default.MaxRpm, Settings.Default.MaxLoadGRev))); scatterButtons.Add(new CarToolBarButton("AFR", new AfrScatterScreen(Settings.Default.MaxMafGS))); scatterButtons.Add(new CarToolBarButton("Compressor", new CompressorMapScreen(Settings.Default.MaxMafGS, Settings.Default.MaxAbsoluteBoostBar))); scatterButtons[1].Selected = true; scatterToolBar.Buttons = scatterButtons; List <CarToolBarButton> heatMapButtons = new List <CarToolBarButton>(); heatMapButtons.Add(new CarToolBarButton("<", mainToolBar, leftButtonWidth)); heatMapButtons.Add(new CarToolBarButton("Knock", new KnockScreen(Settings.Default.MaxRpm, Settings.Default.MaxLoadGRev))); heatMapButtons.Add(new CarToolBarButton("AFR", new AfrHeatMapScreen(Settings.Default.MaxRpm, Settings.Default.MaxLoadGRev))); heatMapButtons.Add(new CarToolBarButton("Boost", new BoostScreen(Settings.Default.MaxRpm))); heatMapButtons.Add(new CarToolBarButton("VE", new VEScreen(Settings.Default.MaxRpm, Settings.Default.MaxAbsoluteBoostBar))); heatMapButtons.Add(new CarToolBarButton("IVE", new IVEScreen(Settings.Default.MaxRpm, Settings.Default.MaxLoadGRev))); // TODO: boost targets (also need UI to choose min/max/avg) heatMapButtons[1].Selected = true; heatMapToolBar.Buttons = heatMapButtons; List <CarToolBarButton> exitButtons = new List <CarToolBarButton>(); if (Settings.Default.CarPC) { exitButtons.Add(new CarToolBarButton("<", minimizeButtonData, leftButtonWidth)); exitButtons.Add(new CarToolBarButton("Main Menu", mainToolBar)); } else { exitButtons.Add(new CarToolBarButton("<", mainToolBar, leftButtonWidth)); exitButtons.Add(new CarToolBarButton("Minimize", minimizeButtonData)); } exitButtons.Add(new CarToolBarButton("Exit", exitButtonData)); exitToolBar.Buttons = exitButtons; this.toolBar = mainToolBar; List <SawMillScreen> screens = new List <SawMillScreen>(); GetScreensFromToolbars(mainToolBar, mainToolBar, screens); return(screens); }
/// <summary> /// Single Click /// </summary> void SawMillMainForm_Click(object sender, EventArgs e) { if (this.IsMinimized()) { return; } Point mouse = this.PointToClient(new Point(MousePosition.X, MousePosition.Y)); CarToolBarButton button = this.toolBar.HitTest(mouse.X, mouse.Y, this.GetToolbarBounds()); if (button == null) { this.sawMill.SingleClick(); return; } if (button.Data is SawMillScreen) { this.toolBar.Select(button); if (this.sawMill.CurrentScreen != button.Data) { this.sawMill.SetCurrentScreen(button.Data as SawMillScreen); using (Graphics graphics = this.CreateGraphics()) { this.Repaint(graphics); } } } else if (button.Data is CarToolBar) { if (button != this.toolBar.Buttons[0]) { this.toolBar.Select(button); } this.toolBar = button.Data as CarToolBar; this.DrawToolbar(); foreach (CarToolBarButton toolBarButton in this.toolBar.Buttons) { if (toolBarButton.Selected && toolBarButton.Data is SawMillScreen) { this.sawMill.SetCurrentScreen(toolBarButton.Data as SawMillScreen); break; } } } else if (button.Data is string) { if ((string)button.Data == exitButtonData) { this.toolBar.Select(button); this.DrawToolbar(); this.sawMill.BeginClose(this.SawMill_CloseCallback, null); } else if ((string)button.Data == minimizeButtonData) { this.toolBar.Select(button); this.DrawToolbar(); if (Settings.Default.BackButton == "SendToBack") { this.SendToBack(); this.toolBar.Select(null); this.toolBar = this.mainToolBar; } else { this.WindowState = FormWindowState.Minimized; this.toolBar.Select(null); this.toolBar = this.mainToolBar; } } this.DrawToolbar(); } }