Skip to content

Commit

Permalink
Merge pull request #4 from NickvisionApps/drawing
Browse files Browse the repository at this point in the history
Drawing modes and settings
  • Loading branch information
nlogozzo authored Jun 27, 2023
2 parents 52edb61 + e622f6b commit e27e546
Show file tree
Hide file tree
Showing 13 changed files with 3,780 additions and 125 deletions.
1 change: 1 addition & 0 deletions NickvisionCavalier.GNOME/Blueprints/drawing_view.blp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Gtk.Stack _root {
child: Gtk.GLArea _glArea {
hexpand: true;
vexpand: true;
auto-render: false;
};
}
}
150 changes: 144 additions & 6 deletions NickvisionCavalier.GNOME/Blueprints/preferences_dialog.blp
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,75 @@ using Gtk 4.0;
using Adw 1;

Adw.PreferencesWindow _root {
default-width: 600;
default-height: 400;
default-width: 780;
default-height: 500;
modal: false;
destroy-with-parent: true;
hide-on-close: false;
hide-on-close: true;
title: _("Preferences");

Adw.PreferencesPage {
title: _("Cavalier");
icon-name: "org.nickvision.cavalier-symbolic";

Adw.PreferencesGroup {
title: _("Drawing mode");

Adw.ActionRow {
title: _("Wave");
activatable-widget: _waveCheckButton;

[prefix]
Gtk.CheckButton _waveCheckButton {}
}

Adw.ActionRow {
title: _("Levels");
activatable-widget: _levelsCheckButton;

[prefix]
Gtk.CheckButton _levelsCheckButton {
group: _waveCheckButton;
}
}

Adw.ActionRow {
title: _("Particles");
activatable-widget: _particlesCheckButton;

[prefix]
Gtk.CheckButton _particlesCheckButton {
group: _waveCheckButton;
}
}

Adw.ActionRow {
title: _("Bars");
activatable-widget: _barsCheckButton;

[prefix]
Gtk.CheckButton _barsCheckButton {
group: _waveCheckButton;
}
}

Adw.ActionRow {
title: _("Spine");
activatable-widget: _spineCheckButton;

[prefix]
Gtk.CheckButton _spineCheckButton {
group: _waveCheckButton;
}
}
}

Adw.PreferencesGroup {
Adw.ComboRow _mirrorRow {
title: _("Mirror");
}
}

Adw.PreferencesGroup {
Adw.ActionRow {
title: _("Drawing area margin");
Expand All @@ -31,12 +89,86 @@ Adw.PreferencesWindow _root {
};
}
}

Adw.ComboRow _directionRow {
title: _("Drawing direction");
model: Gtk.StringList {
strings ["Top to bottom", "Bottom to top", "Left to right", "Right to left" ]
};
}

Adw.ActionRow _offsetRow {
title: _("Offset between items");
subtitle: _("The size of spaces between elements (in percent).");

[suffix]
Gtk.Scale _offsetScale {
width-request: 180;
draw-value: true;
value-pos: left;
digits: 0;
adjustment: Gtk.Adjustment {
lower: 0;
upper: 20;
step-increment: 1;
};
}
}

Adw.ActionRow _roundnessRow {
title: _("Roundness of items");
subtitle: _("How much rounded the elements should be (in percent).");

[suffix]
Gtk.Scale _roundnessScale {
width-request: 180;
draw-value: true;
value-pos: left;
digits: 0;
adjustment: Gtk.Adjustment {
lower: 0;
upper: 100;
step-increment: 1;
};
}
}

Adw.ActionRow {
title: _("Filling");
subtitle: _("Whether shapes should be filled or outlined.");
activatable-widget: _fillingSwitch;

[suffix]
Gtk.Switch _fillingSwitch {
valign: center;
}
}

Adw.ActionRow _thicknessRow {
title: _("Thickness of lines");
subtitle: _("Thickness of lines when filling is off (in pixels).");
sensitive: bind _fillingSwitch.active inverted;

[suffix]
Gtk.Scale _thicknessScale {
width-request: 180;
draw-value: true;
value-pos: left;
digits: 0;
adjustment: Gtk.Adjustment {
lower: 1;
upper: 10;
step-increment: 1;
};
}
}
}

Adw.PreferencesGroup {
Adw.ActionRow {
title: _("Borderless window");
subtitle: _("Whether to disable window shadow and borders.");
activatable-widget: _borderlessSwitch;

[suffix]
Gtk.Switch _borderlessSwitch {
Expand All @@ -47,6 +179,7 @@ Adw.PreferencesWindow _root {
Adw.ActionRow {
title: _("Sharp corners");
subtitle: _("Whether the main window corners should be sharp.");
activatable-widget: _sharpCornersSwitch;

[suffix]
Gtk.Switch _sharpCornersSwitch {
Expand All @@ -57,6 +190,7 @@ Adw.PreferencesWindow _root {
Adw.ActionRow {
title: _("Window controls");
subtitle: _("Whether to show window control buttons.");
activatable-widget: _windowControlsSwitch;

[suffix]
Gtk.Switch _windowControlsSwitch {
Expand All @@ -67,6 +201,7 @@ Adw.PreferencesWindow _root {
Adw.ActionRow {
title: _("Autohide headerbar");
subtitle: _("Whether to hide headerbar when main window is not focused.");
activatable-widget: _autohideHeaderSwitch;

[suffix]
Gtk.Switch _autohideHeaderSwitch {
Expand Down Expand Up @@ -109,6 +244,7 @@ Adw.PreferencesWindow _root {
Adw.ActionRow {
title: _("Automatic sensitivity");
subtitle: _("Attempt to decrease sensitivity if the bars peak.");
activatable-widget: _autosensSwitch;

[suffix]
Gtk.Switch _autosensSwitch {
Expand Down Expand Up @@ -155,6 +291,7 @@ Adw.PreferencesWindow _root {
Adw.ActionRow {
title: _("Monstercat smoothing");
subtitle: _("Whether to enable the so-called «Monstercat smoothing».");
activatable-widget: _monstercatSwitch;

[suffix]
Gtk.Switch _monstercatSwitch {
Expand All @@ -164,7 +301,7 @@ Adw.PreferencesWindow _root {

Adw.ActionRow {
title: _("Noise reduction");
subtitle: _("This factor adjusts the integral and gravity filters to keep the signal smooth.\n1 will be very slow and smooth, 0 will be fast but noisy.");
subtitle: _("This factor adjusts the integral and gravity filters to keep the signal smooth.\nHigher value leads to a slower and smoother result.");

[suffix]
Gtk.Scale _noiseReductionScale {
Expand All @@ -173,8 +310,8 @@ Adw.PreferencesWindow _root {
value-pos: left;
digits: 2;
adjustment: Gtk.Adjustment {
lower: 0.0;
upper: 1.0;
lower: 0.15;
upper: 0.95;
step-increment: 0.01;
};
}
Expand All @@ -183,6 +320,7 @@ Adw.PreferencesWindow _root {
Adw.ActionRow {
title: _("Reverse order");
subtitle: _("Whether to reverse order of bars for each channel.");
activatable-widget: _reverseSwitch;

[suffix]
Gtk.Switch _reverseSwitch {
Expand Down
4 changes: 2 additions & 2 deletions NickvisionCavalier.GNOME/Blueprints/window.blp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ menu mainMenu {
}

Adw.ApplicationWindow _root {
width-request: 170;
height-request: 170;
width-request: 232;
height-request: 232;

Gtk.Overlay _overlay {
[overlay]
Expand Down
42 changes: 26 additions & 16 deletions NickvisionCavalier.GNOME/Views/DrawingView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,35 @@ namespace NickvisionCavalier.GNOME.Views;
/// </summary>
public partial class DrawingView : Gtk.Stack
{
public delegate bool GSourceFunc(nint data);

[LibraryImport("libEGL.so.1", StringMarshalling = StringMarshalling.Utf8)]
private static partial IntPtr eglGetProcAddress(string name);
//TODO: GLX and WGL
private static partial nint eglGetProcAddress(string name);
[LibraryImport("libGL.so.1", StringMarshalling = StringMarshalling.Utf8)]
private static partial void glClear(uint mask);

[LibraryImport("libadwaita-1.so.0", StringMarshalling = StringMarshalling.Utf8)]
private static partial void g_main_context_invoke(nint context, GSourceFunc function, nint data);

[Gtk.Connect] private readonly Gtk.GLArea _glArea;

private readonly DrawingViewController _controller;
private GRContext? _ctx;
private SKSurface? _skSurface;
private float[]? _sample;

private readonly GSourceFunc _queueRender;

private DrawingView(Gtk.Builder builder, DrawingViewController controller) : base(builder.GetPointer("_root"), false)
{
_controller = controller;
_queueRender = (x) =>
{
if (GetVisibleChildName() != "gl")
{
SetVisibleChildName("gl");
}
_glArea.QueueRender();
return false;
};
//Build UI
builder.Connect(this);
_glArea.OnRealize += (sender, e) =>
Expand All @@ -35,15 +48,11 @@ private DrawingView(Gtk.Builder builder, DrawingViewController controller) : bas
var grInt = GRGlInterface.Create(eglGetProcAddress);
_ctx = GRContext.CreateGl(grInt);
};
_glArea.OnResize += OnResize;
_glArea.OnResize += (sender, e) => CreateSurface();
_controller.Cava.OutputReceived += (sender, sample) =>
{
if (GetVisibleChildName() != "gl")
{
SetVisibleChildName("gl");
}
_sample = sample;
_glArea.QueueRender();
g_main_context_invoke(0, _queueRender, 0);
};
_glArea.OnRender += OnRender;
}
Expand All @@ -57,16 +66,17 @@ public DrawingView(DrawingViewController controller) : this(Builder.FromFile("dr
}

/// <summary>
/// (Re)creates surface on area resize
/// (Re)creates drawing surface
/// </summary>
/// <param name="sender">Gtk.GLArea</param>
/// <param name="e">EventArgs</param>
private void OnResize(Gtk.GLArea sender, EventArgs e)
private void CreateSurface()
{
_skSurface?.Dispose();
var imgInfo = new SKImageInfo(sender.GetAllocatedWidth(), sender.GetAllocatedHeight());
var imgInfo = new SKImageInfo(_glArea.GetAllocatedWidth(), _glArea.GetAllocatedHeight());
_skSurface = SKSurface.Create(_ctx, false, imgInfo);
_controller.Canvas = _skSurface.Canvas;
if (_skSurface != null)
{
_controller.Canvas = _skSurface.Canvas;
}
}

/// <summary>
Expand Down
29 changes: 8 additions & 21 deletions NickvisionCavalier.GNOME/Views/MainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,24 @@ public class MainWindow : Adw.ApplicationWindow
private readonly MainWindowController _controller;
private readonly Adw.Application _application;
private readonly DrawingView _drawingView;
private readonly PreferencesDialog _preferencesDialog;

private MainWindow(Gtk.Builder builder, MainWindowController controller, Adw.Application application) : base(builder.GetPointer("_root"), false)
{
//Window Settings
_controller = controller;
_application = application;
//Build UI
builder.Connect(this);
SetDefaultSize((int)_controller.WindowWidth, (int)_controller.WindowHeight);
SetTitle(_controller.AppInfo.ShortName);
SetIconName(_controller.AppInfo.ID);
if (_controller.IsDevVersion)
{
AddCssClass("devel");
}
//Build UI
builder.Connect(this);
_drawingView = new DrawingView(new DrawingViewController());
_overlay.SetChild(_drawingView);
var prefController = _controller.CreatePreferencesViewController();
prefController.OnWindowSettingsChanged += UpdateWindowSettings;
prefController.OnCavaSettingsChanged += _drawingView.UpdateCavaSettings;
_preferencesDialog = new PreferencesDialog(prefController, _application, this);
UpdateWindowSettings(null, EventArgs.Empty);
OnNotify += (sender, e) =>
{
Expand All @@ -53,7 +54,7 @@ private MainWindow(Gtk.Builder builder, MainWindowController controller, Adw.App
};
//Preferences Action
var actPreferences = Gio.SimpleAction.New("preferences", null);
actPreferences.OnActivate += Preferences;
actPreferences.OnActivate += (sender, e) => _preferencesDialog.Present();
AddAction(actPreferences);
application.SetAccelsForAction("win.preferences", new string[] { "<Ctrl>comma" });
//Keyboard Shortcuts Action
Expand Down Expand Up @@ -91,20 +92,6 @@ public void Start()
Present();
}

/// <summary>
/// Occurs when the preferences action is triggered
/// </summary>
/// <param name="sender">Gio.SimpleAction</param>
/// <param name="e">EventArgs</param>
private void Preferences(Gio.SimpleAction sender, EventArgs e)
{
var prefController = _controller.CreatePreferencesViewController();
prefController.OnWindowSettingsChanged += UpdateWindowSettings;
prefController.OnCavaSettingsChanged += _drawingView.UpdateCavaSettings;
var preferencesDialog = new PreferencesDialog(prefController, _application, this);
preferencesDialog.Present();
}

/// <summary>
/// Occurs when settings for the window have changed
/// </summary>
Expand Down
Loading

0 comments on commit e27e546

Please sign in to comment.