Skip to content

Commit

Permalink
Custom Group Box for db Margin
Browse files Browse the repository at this point in the history
  • Loading branch information
tomvdb committed Jul 13, 2024
1 parent 5a2046d commit 8f1fc05
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 82 deletions.
3 changes: 2 additions & 1 deletion MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions MediaSources/Winterhill/WinterhillProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ private bool BuildSourceProperties()
_tuner_properties[c].AddItem("frequency", "Frequency" ,_genericContextStrip);
_tuner_properties[c].AddItem("offset", "Freq Offset", _genericContextStrip);
_tuner_properties[c].AddItem("nim_frequency", "Nim Frequency");
_tuner_properties[c].AddItem("symbol_rate", "Symbol Rate / Modcod", _genericContextStrip);
_tuner_properties[c].AddItem("symbol_rate", "Symbol Rate", _genericContextStrip);
_tuner_properties[c].AddItem("modcod", "Modcod");
_tuner_properties[c].AddItem("service_name", "Service Name");
_tuner_properties[c].AddItem("service_name_provider", "Service Name Provider");
Expand Down Expand Up @@ -542,6 +542,8 @@ private void UpdateInfo(monitorMessage mm)
}
else
{
_tuner_properties[c].UpdateBigLabel("");

Log.Information("Stopping " + c.ToString() + " - " + rx.scanstate.ToString());

VideoChangeCB?.Invoke(c + 1, false);
Expand All @@ -557,6 +559,8 @@ private void UpdateInfo(monitorMessage mm)
_streamer[c].stream = false;
_tuner_properties[c].UpdateStreamButtonColor("media_controls_" + c.ToString(), Color.Transparent);
}


}

demodstate[c] = rx.scanstate;
Expand Down Expand Up @@ -637,7 +641,7 @@ private void UpdateInfo(monitorMessage mm)
}

_tuner_properties[c].UpdateValue("ts_port", rx.ts_port.ToString());
_tuner_properties[c].UpdateBigLabel(rx.dbmargin.ToString());
_tuner_properties[c].UpdateBigLabel("D" + rx.dbmargin.ToString());

//Log.Information("(S)ROLF Test: " + rx.mer);
//Log.Information("(D)ROLF Test: " + Convert.ToDouble(rx.mer).ToString());
Expand Down
2 changes: 1 addition & 1 deletion Resources/BuildDate.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2024/07/13 11:17:32.80
2024/07/13 18:17:53.68
58 changes: 0 additions & 58 deletions Utilities/CollapsibleGroupBox.cs

This file was deleted.

59 changes: 59 additions & 0 deletions Utilities/CustomGroupBox.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace opentuner.Utilities
{
// an attempt at making a collapsable group box :p

public class CustomGroupBox : GroupBox
{

public string db_margin = "";

public CustomGroupBox()
{
this.SetStyle(ControlStyles.UserPaint, true);
}



protected override void OnPaint(PaintEventArgs e)
{

Graphics g = e.Graphics;

Color borderColor = Color.FromKnownColor(KnownColor.ControlDark);
Color textColor = Color.FromKnownColor(KnownColor.ControlText);
Font textFont = this.Font;

SizeF textSize = g.MeasureString(this.Text, textFont);

int padding = (int)(textSize.Height / 2);

Rectangle bounds = new Rectangle(0, padding , this.Width, this.Height - (padding * 2));

ControlPaint.DrawBorder(g, bounds, borderColor, ButtonBorderStyle.Dashed);

Rectangle textBounds = new Rectangle(10, 0, (int)textSize.Width + 6, (int)textSize.Height);

g.FillRectangle(new SolidBrush(Color.FromArgb(240, 240, 240)), textBounds);

TextRenderer.DrawText(g, this.Text, textFont, new Point(10, 0), textColor);

if (db_margin.Length > 1)
{
Font db_margin_font = new Font(this.Font.FontFamily, 15f, FontStyle.Bold);

SizeF db_margin_textSize = g.MeasureString(db_margin.ToString(), db_margin_font);

g.FillRectangle(new SolidBrush(Color.FromArgb(240, 240, 240)), new Rectangle(this.Width - (int)db_margin_textSize.Width - 15, 0, (int)db_margin_textSize.Width + 5, (int)db_margin_textSize.Height));
TextRenderer.DrawText(g, db_margin.ToString(), db_margin_font, new Point(this.Width - (int)db_margin_textSize.Width - 15, 0), textColor);
}
}
}
}
20 changes: 12 additions & 8 deletions Utilities/DynamicPropertyGroups.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ namespace opentuner.Utilities
public class DynamicPropertyGroup
{

private delegate void UpdateTitleDelegate(CollapsibleGroupBox group_box, Object obj);
private delegate void UpdateTitleDelegate(CustomGroupBox group_box, Object obj);
public delegate void SliderChanged(string key, int value);


private Control _parent;
private Label _big_num_label;

//private GroupBox _groupBox;
private CollapsibleGroupBox _groupBox;
private CustomGroupBox _groupBox;
private List<DynamicPropertyInterface> _items = new List<DynamicPropertyInterface>();

public event SliderChanged OnSlidersChanged;
Expand All @@ -52,13 +52,14 @@ public DynamicPropertyGroup(string GroupTitle, Control Parent)


// groupbox
_groupBox = new CollapsibleGroupBox();
_groupBox = new CustomGroupBox();
_groupBox.Dock = DockStyle.Top;
_groupBox.AutoSize = true;
_groupBox.Text = GroupTitle;
_groupBox.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));


/*
// main number - d number value
_big_num_label = new Label();
_big_num_label.Text = "";
Expand All @@ -71,7 +72,7 @@ public DynamicPropertyGroup(string GroupTitle, Control Parent)
_big_num_label.Left = _groupBox.Width - _big_num_label.Width - 2;
_big_num_label.Font = new Font("Arial", 15, FontStyle.Bold);
_big_num_label.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;

*/
_groupBox.Controls.Add(_big_num_label);
Parent.Controls.Add(_groupBox);
Parent.Resize += _groupBox_Resize;
Expand All @@ -81,11 +82,11 @@ public DynamicPropertyGroup(string GroupTitle, Control Parent)

private void _groupBox_Resize(object sender, EventArgs e)
{
_big_num_label.Top = 8;
_big_num_label.Left = _groupBox.Width - _big_num_label.Width ;
//_big_num_label.Top = 8;
//_big_num_label.Left = _groupBox.Width - _big_num_label.Width ;
}

private void UpdateTitle(CollapsibleGroupBox group_box, Object obj)
private void UpdateTitle(CustomGroupBox group_box, Object obj)
{
if (group_box == null)
return;
Expand All @@ -104,6 +105,7 @@ private void UpdateTitle(CollapsibleGroupBox group_box, Object obj)
}
}

/*
private void UpdateBigLabel(Label Lbl, Object obj)
{
if (Lbl == null)
Expand All @@ -122,11 +124,13 @@ private void UpdateBigLabel(Label Lbl, Object obj)
Lbl.Text = obj.ToString();
}
}
*/


public void UpdateBigLabel(string Text)
{
UpdateBigLabel(_big_num_label, Text);
//UpdateBigLabel(_big_num_label, Text);
_groupBox.db_margin = Text;
}

public void UpdateTitle(string Title)
Expand Down
13 changes: 10 additions & 3 deletions Utilities/DynamicPropertySlider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class DynamicPropertySlider : DynamicPropertyInterface
{
public delegate void SliderChanged(string key, int value);

private const int ItemHeight = 20;
//private const int ItemHeight = 20;
private TrackBar _trackBar;

private int _min;
Expand Down Expand Up @@ -56,7 +56,14 @@ protected void InitComponents(GroupBox Group, string Key, string Title)
//_titleLabel.BorderStyle = BorderStyle.FixedSingle;
_titleLabel.AutoSize = false;
_titleLabel.Width = _parent.Width / 2 - 5;
_titleLabel.Height = ItemHeight;
//_titleLabel.Height = ItemHeight;

using (Graphics g = _titleLabel.CreateGraphics())
{
SizeF textSize = g.MeasureString("Hyq", _titleLabel.Font);
_titleLabel.Height = 2 + (int)Math.Ceiling(textSize.Height);
}

_titleLabel.Left = 5;
_titleLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;

Expand All @@ -68,7 +75,7 @@ protected void InitComponents(GroupBox Group, string Key, string Title)
_trackBar = new TrackBar();
_trackBar.AutoSize = false;
_trackBar.Top = _titleLabel.Top;
_trackBar.Height = ItemHeight;
_trackBar.Height = _titleLabel.Height;
_trackBar.Width = _parent.Width - _trackBar.Left - 5;
_trackBar.Minimum = _min;
_trackBar.Maximum = _max;
Expand Down
22 changes: 14 additions & 8 deletions Utilities/StreamInfoContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ namespace opentuner.Utilities
public class StreamInfoContainer : Label
{
OTSourceData last_info_data = null;
private Font font = new Font("Arial", 12, FontStyle.Bold);

public StreamInfoContainer(bool show)
{
BackColor = Color.Black;
Dock = DockStyle.Top;
Height = 30;

//Height = 30;
Visible = show;
}

Expand All @@ -34,14 +36,18 @@ protected override void OnPaint(PaintEventArgs pe)
base.OnPaint(pe);

ForeColor = Color.Black;
Font = new Font("Arial", 12, FontStyle.Bold);

SizeF temp_text_size = pe.Graphics.MeasureString("Temp", font);
this.Height = (int)temp_text_size.Height + 10;


pe.Graphics.FillRectangle(Brushes.Black, 0, 0, Width, Height);
pe.Graphics.DrawRectangle(Pens.White, 0, 0, Width - 1, Height - 1);

if (last_info_data == null)
return;


string info = "";

string locked_info = last_info_data.service_name + " - " +
Expand All @@ -57,20 +63,20 @@ protected override void OnPaint(PaintEventArgs pe)

if (last_info_data.demod_locked)
{
pe.Graphics.DrawString(locked_info, Font, Brushes.LimeGreen, new PointF(x_pos, y_pos));
SizeF textSize = pe.Graphics.MeasureString(locked_info, Font);
pe.Graphics.DrawString(locked_info, font, Brushes.LimeGreen, new PointF(x_pos, y_pos));
SizeF textSize = pe.Graphics.MeasureString(locked_info, font);
x_pos += (int)textSize.Width ;
}
else
{
pe.Graphics.DrawString("No Lock", Font, Brushes.PaleVioletRed, new PointF(x_pos, y_pos));
SizeF textSize = pe.Graphics.MeasureString("No Lock", Font);
pe.Graphics.DrawString("No Lock", font, Brushes.PaleVioletRed, new PointF(x_pos, y_pos));
SizeF textSize = pe.Graphics.MeasureString("No Lock", font);
x_pos += (int)textSize.Width;
}

pe.Graphics.DrawString(info, Font, Brushes.AntiqueWhite, new PointF(x_pos, y_pos));
pe.Graphics.DrawString(info, font, Brushes.AntiqueWhite, new PointF(x_pos, y_pos));

x_pos += (int)pe.Graphics.MeasureString(info, Font).Width;
x_pos += (int)pe.Graphics.MeasureString(info, font).Width;

using (Font emojiFont = new Font("Segoe UI Emoji", 12, FontStyle.Bold))
{
Expand Down
2 changes: 1 addition & 1 deletion opentuner.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@
</Compile>
<Compile Include="lookups.cs" />
<Compile Include="MediaSources\Minitiouner\HardwareInterfaces\MTHardwareInterface.cs" />
<Compile Include="Utilities\CollapsibleGroupBox.cs">
<Compile Include="Utilities\CustomGroupBox.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="Utilities\CommonFunctions.cs" />
Expand Down

0 comments on commit 8f1fc05

Please sign in to comment.