Skip to content

Commit

Permalink
Implement ability to specify banner pieces
Browse files Browse the repository at this point in the history
Implement the ability to specify which banner pieces are displayed in the video banner. Camera name, date/time, frame count.
  • Loading branch information
victor-david committed Aug 20, 2020
1 parent 32bfd4c commit d651fec
Show file tree
Hide file tree
Showing 8 changed files with 220 additions and 95 deletions.
83 changes: 75 additions & 8 deletions src/Camera.App/Core/CameraControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,6 @@ public double StatusWidth
/// </summary>
public static readonly DependencyProperty StatusWidthProperty = StatusWidthPropertyKey.DependencyProperty;


/// <summary>
/// Gets the height of the status banner.
/// </summary>
Expand Down Expand Up @@ -537,6 +536,63 @@ private static void OnStatusPlacementChanged(DependencyObject d, DependencyPrope
(d as CameraControl)?.SyncStatusBannerToSize();
}

/// <summary>
/// Gets a boolean value that determines if the camera name displays in the status banner.
/// </summary>
public bool IsStatusCameraName
{
get => (bool)GetValue(IsStatusCameraNameProperty);
private set => SetValue(IsStatusCameraNamePropertyKey, value);
}

private static readonly DependencyPropertyKey IsStatusCameraNamePropertyKey = DependencyProperty.RegisterReadOnly
(
nameof(IsStatusCameraName), typeof(bool), typeof(CameraControl), new PropertyMetadata(true)
);

/// <summary>
/// Identifies the <see cref="IsStatusCameraName"/> dependency property.
/// </summary>
public static readonly DependencyProperty IsStatusCameraNameProperty = IsStatusCameraNamePropertyKey.DependencyProperty;

/// <summary>
/// Gets a boolean value that determines if the current date/time displays in the status banner.
/// </summary>
public bool IsStatusDateTime
{
get => (bool)GetValue(IsStatusDateTimeProperty);
private set => SetValue(IsStatusDateTimePropertyKey, value);
}

private static readonly DependencyPropertyKey IsStatusDateTimePropertyKey = DependencyProperty.RegisterReadOnly
(
nameof(IsStatusDateTime), typeof(bool), typeof(CameraControl), new PropertyMetadata(true)
);

/// <summary>
/// Identifies the <see cref="IsStatusDateTime"/> dependency property.
/// </summary>
public static readonly DependencyProperty IsStatusDateTimeProperty = IsStatusDateTimePropertyKey.DependencyProperty;

/// <summary>
/// Gets a boolean value that determines if the frame count displays in the status banner.
/// </summary>
public bool IsStatusFrameCount
{
get => (bool)GetValue(IsStatusFrameCountProperty);
private set => SetValue(IsStatusFrameCountPropertyKey, value);
}

private static readonly DependencyPropertyKey IsStatusFrameCountPropertyKey = DependencyProperty.RegisterReadOnly
(
nameof(IsStatusFrameCount), typeof(bool), typeof(CameraControl), new PropertyMetadata(true)
);

/// <summary>
/// Identifies the <see cref="IsStatusFrameCount"/> dependency property.
/// </summary>
public static readonly DependencyProperty IsStatusFrameCountProperty = IsStatusFrameCountPropertyKey.DependencyProperty;

/// <summary>
/// Gets or sets the date/time format to use on the status banner. Default is "yyyy-MMM-dd hh:mm:ss tt".
/// </summary>
Expand Down Expand Up @@ -761,24 +817,35 @@ public override void OnApplyTemplate()
}

/// <summary>
/// Updates <see cref="StatusPlacement"/> according to the current flags of <see cref="Camera"/>.
/// Updates the status control according to the current flags of <see cref="Camera"/>.
/// </summary>
public void UpdateStatusPlacement()
public void UpdateStatusControl()
{
if (Camera != null)
{
if (Camera.Flags.HasFlag(CameraFlags.StatusTop))
{
StatusPlacement = StatusPlacement.Top;
return;
}
if (Camera.Flags.HasFlag(CameraFlags.StatusBottom))
else if (Camera.Flags.HasFlag(CameraFlags.StatusBottom))
{
StatusPlacement = StatusPlacement.Bottom;
return;
}
else
{
StatusPlacement = StatusPlacement.None;
}

IsStatusCameraName = Camera.Flags.HasFlag(CameraFlags.StatusCameraName);
IsStatusDateTime = Camera.Flags.HasFlag(CameraFlags.StatusDateTime);
IsStatusFrameCount = Camera.Flags.HasFlag(CameraFlags.StatusFrameCount);

/* if none of the flags are present, turn off the banner */
if (!IsStatusCameraName && !IsStatusDateTime && !IsStatusFrameCount)
{
StatusPlacement = StatusPlacement.None;
}
}
StatusPlacement = StatusPlacement.None;
}
#endregion

Expand Down Expand Up @@ -1015,7 +1082,7 @@ private void InitializeCamera()
IsFlipped = Camera.Flags.HasFlag(CameraFlags.Flip);
IsMirrored = Camera.Flags.HasFlag(CameraFlags.Mirror);

UpdateStatusPlacement();
UpdateStatusControl();

FullScreenCommand = RelayCommand.Create(RunFullScreenCommand);

Expand Down
2 changes: 1 addition & 1 deletion src/Camera.App/Core/CameraWallControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ private void UpdateStatusBanner(long id)
{
if (GetCameraHost(id) is CameraHostBorder host)
{
host.CameraControl.UpdateStatusPlacement();
host.CameraControl.UpdateStatusControl();
}
}

Expand Down
32 changes: 24 additions & 8 deletions src/Camera.App/Themes/Generic/CameraControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -175,17 +175,22 @@
Style="{StaticResource BorderStreamStatus}"
Height="{TemplateBinding StatusHeight}"
Width="{TemplateBinding StatusWidth}">
<Grid core:Property.ColumnWidths="Auto,*,Auto">
<Grid core:Property.ColumnWidths="Auto,*,Auto">

<TextBlock Text="{TemplateBinding CameraName}"/>
<TextBlock x:Name="TextName" Text="{TemplateBinding CameraName}"/>

<TextBlock Grid.Column="1" Margin="6,0" Text="{TemplateBinding StatusTimeText}"/>
<TextBlock
x:Name="TextDateTime"
Grid.Column="1"
Margin="3,0"
HorizontalAlignment="Center"
Text="{TemplateBinding StatusTimeText}"/>

<TextBlock Grid.Column="2" HorizontalAlignment="Right">
<Run Text="Frames:"/>
<Run Foreground="Red" Text="{Binding FrameCount,RelativeSource={RelativeSource AncestorType=core:CameraControl},Mode=OneWay}"/>
</TextBlock>
</Grid>
<TextBlock x:Name="TextFrameCount" Grid.Column="2" HorizontalAlignment="Right">
<Run Text="Frames:"/>
<Run Foreground="Red" Text="{Binding FrameCount,RelativeSource={RelativeSource AncestorType=core:CameraControl},Mode=OneWay}"/>
</TextBlock>
</Grid>
</Border>

<!-- Error banner -->
Expand Down Expand Up @@ -321,6 +326,17 @@
<Trigger Property="StatusPlacement" Value="{StaticResource StatusPlacementNone}">
<Setter TargetName="PART_Status" Property="Visibility" Value="Collapsed"/>
</Trigger>
<Trigger Property="IsStatusCameraName" Value="False">
<Setter TargetName="TextName" Property="Visibility" Value="Collapsed"/>
<Setter TargetName="TextDateTime" Property="HorizontalAlignment" Value="Left"/>
</Trigger>
<Trigger Property="IsStatusDateTime" Value="False">
<Setter TargetName="TextDateTime" Property="VirtualizingPanel.Visibility" Value="Collapsed"/>
</Trigger>
<Trigger Property="IsStatusFrameCount" Value="False">
<Setter TargetName="TextFrameCount" Property="Visibility" Value="Collapsed"/>
<Setter TargetName="TextDateTime" Property="HorizontalAlignment" Value="Right"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>

Expand Down
29 changes: 19 additions & 10 deletions src/Camera.App/View/CameraManageWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,30 @@
<TextBox Grid.Row="1" Text="{Binding Camera.UserId}"/>
<TextBox Grid.Row="1" Grid.Column="1" Text="{Binding Camera.Password}"/>
</Grid>

<!-- Status / orientation-->
<Grid core:Property.ColumnWidths="*,*,*" Margin="6">
<StackPanel>
<TextBlock Text="Status Placement"/>
<CheckBox Content="Top" IsChecked="{Binding IsStatusTop}"/>
<CheckBox Content="Bottom" IsChecked="{Binding IsStatusBottom}"/>
<CheckBox Content="Off" IsChecked="{Binding IsStatusNone}"/>
</StackPanel>

<Grid core:Property.ColumnWidths="*,*" Margin="0,6">
<!-- Status banner -->
<HeaderedItemsControl Header="Status banner">
<Button Content="Top" Command="{Binding Commands[ChangeStatusBanner]}" CommandParameter="{StaticResource CameraFlagStatusTop}"/>
<Button Content="Bottom" Command="{Binding Commands[ChangeStatusBanner]}" CommandParameter="{StaticResource CameraFlagStatusBottom}"/>
<Button Content="Off" Command="{Binding Commands[ChangeStatusBanner]}" CommandParameter="{StaticResource CameraFlagNone}"/>
</HeaderedItemsControl>
<StackPanel Grid.Column="1">
<TextBlock Text="Include"/>
<CheckBox Content="Camera name" IsChecked="{Binding IsStatusCameraName}"/>
<CheckBox Content="Date / time" IsChecked="{Binding IsStatusDateTime}"/>
<CheckBox Content="Frame count" IsChecked="{Binding IsStatusFrameCount}"/>
</StackPanel>

<HeaderedItemsControl Grid.Column="1" Header="Orientation">
<StackPanel Grid.Column="2">
<TextBlock Text="Orientation"/>
<CheckBox Content="Flipped" IsChecked="{Binding IsFlipped}"/>
<CheckBox Content="Mirrored" IsChecked="{Binding IsMirrored}"/>
</HeaderedItemsControl>
</StackPanel>
</Grid>

<Grid core:Property.RowHeights="Auto,*" core:Property.ColumnWidths="*, 80">

<!-- Notes -->
Expand Down
87 changes: 70 additions & 17 deletions src/Camera.App/ViewModel/CameraManageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,7 @@ public int MotionSpeed
public bool TranslateX
{
get => Camera.Flags.HasFlag(CameraFlags.TranslateX);
set
{
Camera.SetTranslateX(value);
OnPropertyChanged();
}
set => Camera.ToggleFlag(CameraFlags.TranslateX, value);
}

/// <summary>
Expand All @@ -142,39 +138,96 @@ public bool TranslateX
public bool TranslateY
{
get => Camera.Flags.HasFlag(CameraFlags.TranslateY);
set => Camera.ToggleFlag(CameraFlags.TranslateY, value);
}

/// <summary>
/// Gets or sets a boolean value that determines if the camers status banner is on the top.
/// </summary>
public bool IsStatusTop
{
get => Camera.Flags.HasFlag(CameraFlags.StatusTop);
set
{
Camera.SetTranslateY(value);
OnPropertyChanged();
Camera.ChangeFlags(CameraFlags.StatusTop, CameraFlags.StatusBottom);
OnPropertyChanged(nameof(IsStatusBottom));
OnPropertyChanged(nameof(IsStatusNone));
}
}

/// <summary>
/// Gets or sets a boolean value that determines if the video image is flipped.
/// Gets or sets a boolean value that determines if the camers status banner is on the bottom.
/// </summary>
public bool IsFlipped
public bool IsStatusBottom
{
get => Camera.Flags.HasFlag(CameraFlags.Flip);
get => Camera.Flags.HasFlag(CameraFlags.StatusBottom);
set
{
Camera.SetFlip(value);
OnPropertyChanged();
Camera.ChangeFlags(CameraFlags.StatusBottom, CameraFlags.StatusTop);
OnPropertyChanged(nameof(IsStatusTop));
OnPropertyChanged(nameof(IsStatusNone));
}
}

/// <summary>
/// Gets or sets a boolean value that determines if the video image is mirrored.
/// Gets or sets a boolean value that determines if the camers status banner is turned off.
/// </summary>
public bool IsMirrored
public bool IsStatusNone
{
get => Camera.Flags.HasFlag(CameraFlags.Mirror);
get => !Camera.Flags.HasFlag(CameraFlags.StatusTop) && !Camera.Flags.HasFlag(CameraFlags.StatusBottom);
set
{
Camera.SetMirror(value);
OnPropertyChanged();
Camera.ChangeFlags(CameraFlags.None, CameraFlags.StatusTop | CameraFlags.StatusBottom);
OnPropertyChanged(nameof(IsStatusTop));
OnPropertyChanged(nameof(IsStatusBottom));
}
}

/// <summary>
/// Gets or sets a boolean value that determines if the camera name displays in the status banner.
/// </summary>
public bool IsStatusCameraName
{
get => Camera.Flags.HasFlag(CameraFlags.StatusCameraName);
set => Camera.ToggleFlag(CameraFlags.StatusCameraName, value);
}

/// <summary>
/// Gets or sets a boolean value that determines if the current date/time displays in the status banner.
/// </summary>
public bool IsStatusDateTime
{
get => Camera.Flags.HasFlag(CameraFlags.StatusDateTime);
set => Camera.ToggleFlag(CameraFlags.StatusDateTime, value);
}

/// <summary>
/// Gets or sets a boolean value that determines if the frame count displays in the status banner.
/// </summary>
public bool IsStatusFrameCount
{
get => Camera.Flags.HasFlag(CameraFlags.StatusFrameCount);
set => Camera.ToggleFlag(CameraFlags.StatusFrameCount, value);
}

/// <summary>
/// Gets or sets a boolean value that determines if the video image is flipped.
/// </summary>
public bool IsFlipped
{
get => Camera.Flags.HasFlag(CameraFlags.Flip);
set => Camera.ToggleFlag(CameraFlags.Flip, value);
}

/// <summary>
/// Gets or sets a boolean value that determines if the video image is mirrored.
/// </summary>
public bool IsMirrored
{
get => Camera.Flags.HasFlag(CameraFlags.Mirror);
set => Camera.ToggleFlag(CameraFlags.Mirror, value);
}

/// <summary>
/// Gets or sets the brightness.
/// </summary>
Expand Down
22 changes: 17 additions & 5 deletions src/Restless.App.Database/Core/CameraFlags.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,36 @@ public enum CameraFlags : long
/// </summary>
StatusBottom = 2,
/// <summary>
/// When status is displayed, include the camera name.
/// </summary>
StatusCameraName = 4,
/// <summary>
/// When status is displayed, include the current date/time.
/// </summary>
StatusDateTime = 8,
/// <summary>
/// When status is displayed, include the frame count.
/// </summary>
StatusFrameCount = 16,
/// <summary>
/// Camera is on the wall
/// </summary>
IncludeOnWall = 8,
IncludeOnWall = 32,
/// <summary>
/// Translate X movement (left / right)
/// </summary>
TranslateX = 16,
TranslateX = 64,
/// <summary>
/// Translate Y movement (up / down)
/// </summary>
TranslateY = 32,
TranslateY = 128,
/// <summary>
/// Flip the video image.
/// </summary>
Flip = 64,
Flip = 256,
/// <summary>
/// Mirror the video image.
/// </summary>
Mirror = 128,
Mirror = 512,
}
}
Loading

0 comments on commit d651fec

Please sign in to comment.