Skip to content

Commit

Permalink
Features:
Browse files Browse the repository at this point in the history
* More focused movement
* Translated libEasyPlayer SDK from chinese to English
* Detect non common resolutions and strech video when in full screen
Fixed bugs:
* on positions reset the leds and the log window does not change the positions
* click on leds or logs window does not focus all windows
* when mqtt unable to connect application exists instantly
* unable to use custom ports with mqtt
  • Loading branch information
e1z0 committed Mar 28, 2024
1 parent 011d95f commit 6374be8
Show file tree
Hide file tree
Showing 9 changed files with 405 additions and 183 deletions.
209 changes: 179 additions & 30 deletions Src/Client/Classes/Camera.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class Camera
public bool Disabled { get; set; }
public bool SoundEnabled { get; set; }
public bool FullScreen { get; set; }
public bool LastStrechState { get; set; }
public bool Recording { get; set; }
public ContextMenuStrip contextMenu { get; set; }

Expand All @@ -48,6 +49,10 @@ public class Camera
public ToolStripMenuItem camMenuItem = new ToolStripMenuItem();
public ToolStripMenuItem recordMenuItem = new ToolStripMenuItem();
public ToolStripMenuItem enableSoundMenuItem = new ToolStripMenuItem();
// window resize and move variables
private int movX, movY;
private bool isMoving;
private bool FormLock;

private Form cameraForm;

Expand Down Expand Up @@ -218,21 +223,7 @@ public void SpawnCameraWindow()
cameraForm.TopMost = true;


cameraForm.Click += (sender, e) =>
{
MouseEventArgs mouseEvent = e as MouseEventArgs;
if (mouseEvent != null && mouseEvent.Button == MouseButtons.Left)
{
if (Settings.Advanced.FocusAllWindowsOnClick && cameraForm.WindowState != FormWindowState.Maximized)
{
// Get all open forms and bring each one to the front
foreach (Form form in Application.OpenForms)
{
form.Focus();
}
}
}
};
cameraForm.Click += CameraClick;

cameraForm.FormClosing += (sender, e) =>
{
Expand All @@ -244,7 +235,6 @@ public void SpawnCameraWindow()
Label camLabel = new Label();
camLabel.Text = Name;
camLabel.Font = new Font(camLabel.Font.FontFamily, 16);

camLabel.AutoSize = true;
camLabel.BorderStyle = BorderStyle.None;
camLabel.ForeColor = Color.White;
Expand All @@ -258,6 +248,20 @@ public void SpawnCameraWindow()
else
camLabel.Visible = false;
}

camLabel.Click += (sender, e) => {
Label lbl = sender as Label;
if (lbl != null)
{
Logger.WriteDebug("camera label click");
Form frm = lbl.Parent as Form;
if (frm != null)
CameraFullScreen(frm, FullScreen);
}
};



cameraForm.Controls.Add(camLabel);


Expand All @@ -278,7 +282,7 @@ public void SpawnCameraWindow()
camLbl.ForeColor = Color.White;
camLbl.BackColor = Color.Transparent;
camLbl.Visible = true;
LabelFadeOut(camLbl, frm);
CameraLabelFadeOut(camLbl, frm);
}
}
Expand All @@ -292,56 +296,199 @@ public void SpawnCameraWindow()
};

// bind keydown events
cameraForm.KeyDown += CustomUI.FormsKeyDown;
cameraForm.KeyDown += CameraKeyDown;
// detect which window is focused
//cameraForm.GotFocus += (sender, e) => {
//};
// Enable moving windows on mouse click
cameraForm.MouseDown += CustomUI.FormsMouseDown;
cameraForm.MouseDown += CameraMouseDown;
// mouse move event
cameraForm.MouseMove += CustomUI.FormsMouseMove;
cameraForm.MouseMove += CameraMouseMove;
// mouse button up event
cameraForm.MouseUp += CustomUI.FormsMouseUp;
cameraForm.MouseUp += CameraMouseUp;
// end of enabling windows movement on mouse click

cameraForm.DoubleClick += new EventHandler(video_DoubleClick);
cameraForm.DoubleClick += new EventHandler(CameraDoubleClick);
cameraForm.Tag = Id;
cameraForm.Text = Name;
callBack = new PlayerSdk.MediaSourceCallBack(MediaCallback);
ChannelID = PlayerSdk.EasyPlayer_OpenStream(Url, cameraForm.Handle, RENDER_FORMAT, isTCP ? 1 : 0, "", "", callBack, IntPtr.Zero, isHardEncode);
if (ChannelID > 0)
{
PlayerSdk.EasyPlayer_SetFrameCache(ChannelID, streamCache);
LastStrechState = true;
PlayerSdk.EasyPlayer_SetShownToScale(ChannelID, 1);
}
cameraForm.Show();
Win32Func.MoveWindow(cameraForm.Handle, WX, WY, WWidth, WHeight, true);
}
}

private bool InvalidResolution()
{
bool badresolution = false;
Screen primaryScreen = Screen.PrimaryScreen;
var aspect = (float)primaryScreen.Bounds.Width / primaryScreen.Bounds.Height;

switch (primaryScreen.Bounds.Height)
{
case 600:
badresolution = true;
break;
case 720:
badresolution = true;
break;
case 768:
badresolution = true;
break;
case 800:
badresolution = true;
break;
default:
badresolution = false;
break;
}

Logger.WriteDebug("Detected aspect ratio: {0} working area: {1} bounds: {2} Bad resolution: {3}", aspect, primaryScreen.WorkingArea, primaryScreen.Bounds, badresolution);
return badresolution;
}

private void CameraFullScreen(Form frm, bool state)
{
if (state)
{
frm.WindowState = FormWindowState.Normal;
FullScreen = false;
if (InvalidResolution())
PlayerSdk.EasyPlayer_SetShownToScale(ChannelID, LastStrechState ? 1 : 0);
}
else
{
frm.WindowState = FormWindowState.Maximized;
FullScreen = true;
if (InvalidResolution())
PlayerSdk.EasyPlayer_SetShownToScale(ChannelID, 0);
}
}

/*
private void CameraBackToNormal(Form frm)
{
frm.WindowState = FormWindowState.Normal;
FullScreen = false;
}
*/

// full screen on window
private void video_DoubleClick(object sender, EventArgs e)
private void CameraDoubleClick(object sender, EventArgs e)
{
Logger.WriteDebug("Camera window double click");
FormLock = true;
Form frm = sender as Form;
if (frm != null)
CameraFullScreen(frm, FullScreen);
FormLock = false;
}

public static void CameraKeyDown(object sender, KeyEventArgs e)
{
Form frm = sender as Form;

if (e.KeyCode == Keys.Up)
{
frm.Height -= Settings.Advanced.ResizeWindowBy;
}
else if (e.KeyCode == Keys.Down)
{
if (FullScreen)
frm.Height += Settings.Advanced.ResizeWindowBy;
}
else if (e.KeyCode == Keys.Left)
{
frm.Width -= Settings.Advanced.ResizeWindowBy;
}
else if (e.KeyCode == Keys.Right)
{
frm.Width += Settings.Advanced.ResizeWindowBy;
}
}

private void CameraClick(object sender, EventArgs e)
{
MouseEventArgs mouseEvent = e as MouseEventArgs;
if (mouseEvent != null && mouseEvent.Button == MouseButtons.Left)
{
if (Settings.Advanced.FocusAllWindowsOnClick && cameraForm.WindowState != FormWindowState.Maximized)
{
frm.WindowState = FormWindowState.Normal;
FullScreen = false;
// Get all open forms and bring each one to the front
foreach (Form form in Application.OpenForms)
{
form.Focus();
}
}
else
}
FormLock = true;
}

private void CameraMouseDown(object sender, MouseEventArgs e)
{
// Assign this method to mouse_Down event of Form or Panel,whatever you want
if (!FormLock)
{
if (e != null && e.Button == MouseButtons.Left && e.Clicks == 1)
{
Logger.WriteDebug("Camera window mouse down");
isMoving = true;
movX = e.X;
movY = e.Y;
}
if (Control.MouseButtons == MouseButtons.Right)
isMoving = false;
}

}

private void CameraMouseMove(object sender, MouseEventArgs e)
{
if (!FormLock)
{
if (isMoving)
{
frm.WindowState = FormWindowState.Maximized;
FullScreen = true;
Logger.WriteDebug("Camera window is moving");
if (sender is Form)
{
Form frm = (Form)sender;
if (frm != null)
frm.SetDesktopLocation(Control.MousePosition.X - movX, Control.MousePosition.Y - movY);
}
else
{
Control control = sender as Control;
if (control != null)
{
Form parentForm = control.FindForm();
parentForm.SetDesktopLocation(Control.MousePosition.X - movX, Control.MousePosition.Y - movY);
}

}
}
}
}

private void CameraMouseUp(object sender, MouseEventArgs e)
{
// Assign this method to Mouse_Up event of Form or Panel.
if (e.Button == MouseButtons.Left)
{
Logger.WriteDebug("Camera window mouse up");
isMoving = false;
}
FormLock = false;
}




public void LabelFadeOut(Label label, Form parent, int timeout = 2000)
private void CameraLabelFadeOut(Label label, Form parent, int timeout = 2000)
{

if (label.Visible)
Expand Down Expand Up @@ -390,6 +537,8 @@ private int MediaCallback(int _channelId, IntPtr _channelPtr, int _frameType, In
return 0;
}




}
}
6 changes: 6 additions & 0 deletions Src/Client/Classes/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,11 @@ public static void WriteLog(string message, params object[] args)
}
}
}
public static void WriteDebug(string message, params object[] args)
{
#if DEBUG
WriteLog("DEBUG -> " + message, args);
#endif
}
}
}
9 changes: 9 additions & 0 deletions Src/Client/CustomUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,14 @@ public static void FormsMouseDown(object sender, MouseEventArgs e)
// Assign this method to mouse_Down event of Form or Panel,whatever you want
if (Control.MouseButtons == MouseButtons.Left)
{
if (Settings.Advanced.FocusAllWindowsOnClick)
{
// Get all open forms and bring each one to the front
foreach (Form form in Application.OpenForms)
{
form.Focus();
}
}
isMoving = true;
movX = e.X;
movY = e.Y;
Expand Down Expand Up @@ -308,6 +316,7 @@ public void Init()
}
Form ledform = new Form();
ledform.ShowInTaskbar = false;
ledform.Name = "Leds";
ledform.Text = "Leds";
ledform.Icon = icon;
ledform.BackColor = Color.Black;
Expand Down
3 changes: 3 additions & 0 deletions Src/Client/LogForm.Designer.cs

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

Loading

0 comments on commit 6374be8

Please sign in to comment.