public Example_SVG(Base parent) : base(parent) { m_PreviewPanel = new DoubleBufferedControl(this); m_PreviewPanel.SetBounds(0, 0, 300, 300); m_PreviewPanel.ClientBackColor = Color.FromArgb(0, 128, 128, 128); m_PreviewPanel.Paint += new GUI.PaintEventHandler(PreviewPanel_Paint); m_PreviewPanel.SoftwareRender = true; m_DrawingPanel = new DoubleBufferedControl(this); m_DrawingPanel.ClientBackColor = Color.FromArgb(0, 128, 128, 128); m_DrawingPanel.Dock = Pos.Fill; m_DrawingPanel.Paint += new GUI.PaintEventHandler(DrawingPanel_Paint); m_DrawingPanel.Resize += new EventHandler(DrawingPanel_Resize); m_DrawingPanel.MouseDown += new GUI.MouseEventHandler(DrawingPanel_MouseDown); m_DrawingPanel.MouseUp += new GUI.MouseEventHandler(DrawingPanel_MouseUp); m_DrawingPanel.MouseMove += new GUI.MouseEventHandler(DrawingPanel_MouseMove); m_DrawingPanel.MouseWheel += new GUI.MouseEventHandler(DrawingPanel_MouseWheel); //m_DrawingPanel.SoftwareRender = true; // Opacity (create before resize) m_OpacityControl = new Base(m_DrawingPanel); m_OpacityControl.SetBounds(10, 30, 20, 200); }
////[CLSCompliant(false)] protected override void OnPaintOffScreen(PaintEventArgs e) { // Sort the satellites by signal if (_Satellites == null) { return; } // Decide which collection to display List <Satellite> SatellitesToDraw = null; List <Satellite> SatellitesToRender = null; float BarWidth; try { #if PocketPC if (LicenseManager.UsageMode == LicenseUsageMode.Designtime) { //SatellitesToRender = SatelliteCollection.Random(45); } else { if (_Satellites == null) { return; } SatellitesToRender = new List <Satellite>(); foreach (Satellite satellite in _Satellites) { // Don't draw if the satellite is stale if (!satellite.IsActive) { continue; } // Add it in SatellitesToRender.Add(satellite); } Thread.Sleep(0); } #else if (_Satellites == null) { return; } SatellitesToRender = new List <Satellite>(); for (int index = 0; index < _Satellites.Count; index++) { Satellite satellite = _Satellites[index]; // Don't draw if the satellite is stale if (!satellite.IsActive && !DesignMode) { continue; } // Add it in SatellitesToRender.Add(satellite); } #endif // Make a fake collection if necessary if (SatellitesToRender.Count == 0) { return; } // Sort the list by PRN SatellitesToRender.Sort(); // Calculate the width of each bar float TotalWidth = (Width - _GapWidth) / SatellitesToRender.Count; BarWidth = TotalWidth - _GapWidth; SatellitesToDraw = new List <Satellite>(); // If if the bars are thin, see if we can exclude 0 dB satellites if (BarWidth < 15) { // Display only the satellites with a > 0 dB signal foreach (Satellite satellite in SatellitesToRender) { // Draw if the signal is > 0 if (!satellite.SignalToNoiseRatio.IsEmpty) { SatellitesToDraw.Add(satellite); } } // If there's anything left, recalculate if (SatellitesToDraw.Count == 0) { return; } // Recalculate bar/total width TotalWidth = (Width - _GapWidth) / SatellitesToDraw.Count; BarWidth = TotalWidth - _GapWidth; } else { // Display only the satellites with a > 0 dB signal foreach (Satellite satellite in SatellitesToRender) { // Draw if the signal is > 0 SatellitesToDraw.Add(satellite); } } // Anything to do? if (SatellitesToDraw.Count == 0) { return; } // Now draw each one float StartX = _GapWidth; float StartY = (float)(Height - e.Graphics.MeasureString("10", _PseudorandomNumberFont).Height); float ScaleFactor = (float)(StartY - e.Graphics.MeasureString("10", _SignalStrengthLabelFont).Height) / 50.0f; foreach (Satellite satellite in SatellitesToDraw) { float SatelliteY = StartY - (satellite.SignalToNoiseRatio.Value * ScaleFactor); // Each icon is 30x30, so we'll translate it by half the distance if (satellite.IsFixed) { SizeF PrnSize = e.Graphics.MeasureString(satellite.PseudorandomNumber.ToString(CultureInfo.CurrentCulture), _PseudorandomNumberFont); #if PocketPC e.Graphics.FillEllipse(pSatelliteFixBrush, (int)(StartX + (BarWidth * 0.5) - (PrnSize.Width * 0.5) - 4.0), (int)(StartY - 4), (int)(PrnSize.Width + 8), (int)(PrnSize.Height + 8)); #else using (SolidBrush FixBrush = new SolidBrush(Color.FromArgb(Math.Min(255, _FixedSatellites.Count * 20), _SatelliteFixColor))) { e.Graphics.FillEllipse(FixBrush, (float)(StartX + (BarWidth * 0.5) - (PrnSize.Width * 0.5) - 4.0), StartY - 4, PrnSize.Width + 8, PrnSize.Height + 8); } #endif } StartX += _GapWidth; StartX += BarWidth; } StartX = _GapWidth; foreach (Satellite satellite in SatellitesToDraw) { // If the signal is 0dB, skip it if (satellite.SignalToNoiseRatio.Value == 0) { continue; } // Keep drawing the satellite float SatelliteY = StartY - (Math.Min(satellite.SignalToNoiseRatio.Value, 50) * ScaleFactor); #if PocketPC // Draw a rectangle for each satellite SolidBrush FillBrush = new SolidBrush(GetFillColor(satellite.SignalToNoiseRatio)); e.Graphics.FillRectangle(FillBrush, (int)StartX, (int)SatelliteY, (int)BarWidth, (int)(StartY - SatelliteY)); FillBrush.Dispose(); Pen FillPen = new Pen(GetOutlineColor(satellite.SignalToNoiseRatio)); e.Graphics.DrawRectangle(FillPen, (int)StartX, (int)SatelliteY, (int)BarWidth, (int)(StartY - SatelliteY)); FillPen.Dispose(); #else // Get the fill color Color BarColor = GetFillColor(satellite.SignalToNoiseRatio); float BarHue = BarColor.GetHue(); // Create gradients for a glass effect Color topTopColor = DoubleBufferedControl.ColorFromAhsb(255, BarHue, 0.2958f, 0.7292f); Color topBottomColor = DoubleBufferedControl.ColorFromAhsb(255, BarHue, 0.5875f, 0.35f); Color bottomTopColor = DoubleBufferedControl.ColorFromAhsb(255, BarHue, 0.7458f, 0.2f); Color bottomBottomColor = DoubleBufferedControl.ColorFromAhsb(255, BarHue, 0.6f, 0.4042f); // Draw a rectangle for each satellite RectangleF TopRect = new RectangleF(StartX, SatelliteY, BarWidth, Convert.ToSingle((StartY - SatelliteY) * 0.5)); using (Brush TopFillBrush = new LinearGradientBrush(TopRect, topTopColor, topBottomColor, LinearGradientMode.Vertical)) { e.Graphics.FillRectangle(TopFillBrush, TopRect); } // Draw a rectangle for each satellite RectangleF BottomRect = new RectangleF(StartX, SatelliteY + TopRect.Height, BarWidth, TopRect.Height); using (Brush BottomFillBrush = new LinearGradientBrush(BottomRect, bottomTopColor, bottomBottomColor, LinearGradientMode.Vertical)) { e.Graphics.FillRectangle(BottomFillBrush, BottomRect); } using (Pen FillPen = new Pen(GetOutlineColor(satellite.SignalToNoiseRatio), 1.0f)) { e.Graphics.DrawRectangle(FillPen, StartX, SatelliteY, BarWidth, StartY - SatelliteY); } #endif string PrnString = satellite.PseudorandomNumber.ToString(CultureInfo.CurrentCulture); SizeF PrnSize = e.Graphics.MeasureString(PrnString, _PseudorandomNumberFont); e.Graphics.DrawString(PrnString, _PseudorandomNumberFont, _PseudorandomNumberBrush, (float)(StartX + (BarWidth * 0.5) - (PrnSize.Width * 0.5)), StartY); string RenderString = satellite.SignalToNoiseRatio.ToString("0 dB", CultureInfo.CurrentCulture); SizeF SignalSize = e.Graphics.MeasureString(RenderString, _SignalStrengthLabelFont); if (SignalSize.Width > BarWidth) { RenderString = satellite.SignalToNoiseRatio.ToString("0 dB", CultureInfo.CurrentCulture).Replace(" dB", ""); SignalSize = e.Graphics.MeasureString(RenderString, _SignalStrengthLabelFont); } e.Graphics.DrawString(RenderString, _SignalStrengthLabelFont, _SignalStrengthLabelBrush, (float)(StartX + (BarWidth * 0.5) - (SignalSize.Width * 0.5)), SatelliteY - SignalSize.Height); StartX += _GapWidth; StartX += BarWidth; } } catch (NullReferenceException) { // Don't throw because the control is shutting down } catch { throw; } // finally // { // if (SatellitesToDraw != null) // SatellitesToDraw.Dispose(); // if (SatellitesToRender != null) // SatellitesToRender.Dispose(); // } }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); /*TEMP * saveFileDialog1 = new System.Windows.Forms.SaveFileDialog(); * saveFileDialog1.DefaultExt = "svg"; * saveFileDialog1.Filter = "SVG Files (*.svg)|*.svg";*/ // Refresh bRefresh = new Alt.GUI.Temporary.Gwen.Control.Button(m_RightPanel); bRefresh.Text = "Refresh"; bRefresh.Dock = Pos.Bottom; bRefresh.Margin = new Margin(0, 20, 5, GUI.Config.Logo.PixelHeight); bRefresh.Click += new EventHandler(bRefresh_Click); // Save bSave = new Alt.GUI.Temporary.Gwen.Control.Button(m_RightPanel); bSave.Text = "Save as SVG File"; bSave.Dock = Pos.Top; bSave.Margin = new Margin(0, 20, 0, 0); bSave.IsHidden = true; // Drawing Panel Base DrawingPanelHolder = new Base(m_Splitter); m_DrawingPanel = new DoubleBufferedControl(DrawingPanelHolder); m_DrawingPanel.UseTransparentBackground = false; m_DrawingPanel.Dock = Pos.Fill; m_DrawingPanel.Paint += new GUI.PaintEventHandler(DrawingPanel_Paint); m_DrawingPanel.MouseWheel += new GUI.MouseEventHandler(DrawingPanel_MouseWheel); m_DrawingPanel.Resize += new EventHandler(DrawingPanel_Resize); m_DrawingPanel.Margin = new Margin(0, GUI.Config.Logo.PixelHeight, 0, GUI.Config.Logo.PixelHeight); m_DrawingPanel.DrawBorder = true; m_DrawingPanel.BorderColor = Color.DodgerBlue * 0.6; // m_Splitter.SetPanel(1, m_RightPanel); m_Splitter.SetPanel(0, DrawingPanelHolder); m_Splitter.SetHValue(0.83f); // Neet to correct groupBoxes groupBox_Geometry.AutoSizeToContents = false; groupBox_BooleanOperation.AutoSizeToContents = false; groupBox_Options.AutoSizeToContents = false; // Core subjects = new Polygons(); clips = new Polygons(); solution = new Polygons(); this.Focus(); }
protected override void OnBackColorChanged(EventArgs e) { base.OnBackColorChanged(e); Color BackgroundColor; if (BackColor.Equals(Color.Transparent)) { if (Parent != null) { BackgroundColor = Parent.BackColor; } else { BackgroundColor = Color.White; } } else { BackgroundColor = BackColor; } // Get the hue of the background color float hue = BackgroundColor.GetHue(); float saturation = BackgroundColor.GetSaturation(); float bright = BackgroundColor.GetBrightness(); float alpha = BackgroundColor.A; // Get a value which is darker or lighter CircleEdge = DoubleBufferedControl.ColorFromAhsb(220, hue, saturation, bright * 0.2f); CircleBack = DoubleBufferedControl.ColorFromAhsb(190, hue, saturation, bright * 0.4f); CircleCenter = DoubleBufferedControl.ColorFromAhsb(210, hue, saturation, bright * 0.7f); CircleBright = DoubleBufferedControl.ColorFromAhsb(250, hue, saturation, bright * 1.0f); #region Draw the faded edge of the circle to give spherical depth GlassShadowColorBlend.Colors = new Color[] { CircleEdge, CircleBack, CircleCenter, CircleCenter }; GlassShadowColorBlend.Positions = new float[] { 0.00F, 0.25f, 0.7f, 1.0f }; #endregion #region Set the colors of the reflection // If the background color is black, make the class reflection white if (BackgroundColor.Equals(Color.Black)) { float WhiteHue = Color.White.GetHue(); float WhiteSaturation = Color.White.GetSaturation(); float WhiteBright = Color.White.GetBrightness(); CircleCenter = DoubleBufferedControl.ColorFromAhsb(210, WhiteHue, WhiteSaturation, WhiteBright * 0.7f); CircleBright = DoubleBufferedControl.ColorFromAhsb(250, WhiteHue, WhiteSaturation, WhiteBright * 1.0f); GlassReflectionColorBlend.Colors = new Color[] { CircleBright, Color.FromArgb(200, CircleCenter), Color.FromArgb(10, CircleCenter), Color.Transparent }; } else { Color NearWhite = DoubleBufferedControl.ColorFromAhsb(255, hue, saturation, 1.0f); GlassReflectionColorBlend.Colors = new Color[] { NearWhite, Color.FromArgb(200, CircleCenter), Color.FromArgb(10, CircleCenter), Color.Transparent }; } GlassReflectionColorBlend.Positions = new float[] { 0F, 0.15f, 0.35F, 1.0f }; MakeBrushes(); #endregion }