-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add pan, tilt and zoom buttons to full view
Signed-off-by: Daniel Lo Nigro <git@d.sb>
- Loading branch information
Showing
9 changed files
with
155 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
using Gtk 4.0; | ||
|
||
Grid pan_and_tilt_buttons { | ||
column-spacing: 4; | ||
row-spacing: 4; | ||
|
||
Button _up { | ||
tooltip-text: _('Up'); | ||
icon-name: 'go-up'; | ||
width-request: 50; | ||
height-request: 50; | ||
|
||
layout { | ||
row: '0'; | ||
column: '1'; | ||
} | ||
} | ||
|
||
Button _down { | ||
tooltip-text: _('Down'); | ||
icon-name: 'go-down'; | ||
width-request: 50; | ||
height-request: 50; | ||
|
||
layout { | ||
row: '1'; | ||
column: '1'; | ||
} | ||
} | ||
|
||
Button _left { | ||
tooltip-text: _('Left'); | ||
icon-name: 'go-previous'; | ||
width-request: 50; | ||
height-request: 50; | ||
|
||
layout { | ||
row: '1'; | ||
column: '0'; | ||
} | ||
} | ||
|
||
Button _right { | ||
tooltip-text: _('Right'); | ||
icon-name: 'go-next'; | ||
width-request: 50; | ||
height-request: 50; | ||
|
||
layout { | ||
row: '1'; | ||
column: '2'; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// SPDX-License-Identifier: MIT | ||
// SPDX-FileCopyrightText: 2024 Daniel Lo Nigro <d@d.sb> | ||
|
||
using Gtk; | ||
using WebCamControl.Core; | ||
using WebCamControl.Gtk.Extensions; | ||
|
||
namespace WebCamControl.Gtk.Widgets; | ||
|
||
/// <summary> | ||
/// Renders up, down, left, and right buttons to adjust the pan and tilt. | ||
/// </summary> | ||
public class PanAndTiltButtons : Box | ||
{ | ||
private const float _panTiltAdjustmentAmount = 2f; | ||
|
||
private readonly ICamera _camera; | ||
private readonly Builder _builder; | ||
|
||
#pragma warning disable CS0649 // Field is never assigned to, and will always have its default value | ||
[Connect] private readonly PressAndHoldButton _up = default!; | ||
[Connect] private readonly PressAndHoldButton _down = default!; | ||
[Connect] private readonly PressAndHoldButton _left = default!; | ||
[Connect] private readonly PressAndHoldButton _right = default!; | ||
#pragma warning restore CS0649 // Field is never assigned to, and will always have its default value | ||
|
||
public PanAndTiltButtons(ICamera camera) | ||
{ | ||
_camera = camera; | ||
_builder = new Builder("PanAndTiltButtons.ui"); | ||
var rootWidget = (Grid)_builder.GetObject("pan_and_tilt_buttons")!; | ||
Append(rootWidget); | ||
_builder.Connect(this); | ||
|
||
AttachEvents(); | ||
} | ||
|
||
private void AttachEvents() | ||
{ | ||
_left.DisableCameraControlIfUnsupported(_camera.Pan); | ||
_right.DisableCameraControlIfUnsupported(_camera.Pan); | ||
if (_camera.Pan != null) | ||
{ | ||
_left.OnHeld += (_, _) => _camera.Pan.Value -= _panTiltAdjustmentAmount; | ||
_right.OnHeld += (_, _) => _camera.Pan.Value += _panTiltAdjustmentAmount; | ||
} | ||
|
||
_down.DisableCameraControlIfUnsupported(_camera.Tilt); | ||
_up.DisableCameraControlIfUnsupported(_camera.Tilt); | ||
if (_camera.Tilt != null) | ||
{ | ||
_down.OnHeld += (_, _) => _camera.Tilt.Value -= _panTiltAdjustmentAmount; | ||
_up.OnHeld += (_, _) => _camera.Tilt.Value += _panTiltAdjustmentAmount; | ||
} | ||
} | ||
|
||
public override void Dispose() | ||
{ | ||
GC.SuppressFinalize(this); | ||
base.Dispose(); | ||
_builder.Dispose(); | ||
} | ||
} |