From 673ffecf17aa4d362ce251396bdabc46836dc048 Mon Sep 17 00:00:00 2001 From: Vasiliy Doylov Date: Sun, 2 Mar 2025 10:53:09 +0300 Subject: [PATCH] WIP: SSC TEST Signed-off-by: Vasiliy Doylov --- .gitignore | 3 +- po/POTFILES.in | 2 +- src/application.vala | 7 ++++ src/gtk/help-overlay.blp | 24 +++++++++++++ src/gtk/help-overlay.ui | 29 --------------- src/gui/bubble-bar.vala | 55 +++++++++++++++++++++++++++++ src/gui/bubble-circle.vala | 0 src/gui/meson.build | 4 +++ src/meson.build | 37 ++++++++++++++++--- src/resources.gresource.xml | 1 + src/sensors/accel.vala | 0 src/sensors/gyro.vala | 0 src/sensors/meson.build | 5 +++ src/sensors/sensor.vala | 11 ++++++ src/style.css | 5 +++ src/window.blp | 51 ++++++++++++++++++++++++++ src/window.ui | 50 -------------------------- src/window.vala | 22 +++++++++--- subprojects/blueprint-compiler.wrap | 8 +++++ 19 files changed, 224 insertions(+), 90 deletions(-) create mode 100644 src/gtk/help-overlay.blp delete mode 100644 src/gtk/help-overlay.ui create mode 100644 src/gui/bubble-bar.vala create mode 100644 src/gui/bubble-circle.vala create mode 100644 src/gui/meson.build create mode 100644 src/sensors/accel.vala create mode 100644 src/sensors/gyro.vala create mode 100644 src/sensors/meson.build create mode 100644 src/sensors/sensor.vala create mode 100644 src/style.css create mode 100644 src/window.blp delete mode 100644 src/window.ui create mode 100644 subprojects/blueprint-compiler.wrap diff --git a/.gitignore b/.gitignore index 600d2d3..21b1578 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -.vscode \ No newline at end of file +.vscode +/subprojects/blueprint-compiler diff --git a/po/POTFILES.in b/po/POTFILES.in index d0bbdc1..0ae2164 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -5,4 +5,4 @@ data/io.gitlab.nekocwd.thecattools.metainfo.xml.in data/io.gitlab.nekocwd.thecattools.gschema.xml src/main.vala src/window.vala -src/window.ui +src/window.blp diff --git a/src/application.vala b/src/application.vala index 52c0d58..3d64493 100644 --- a/src/application.vala +++ b/src/application.vala @@ -41,6 +41,13 @@ public class TheCatTools.Application : Adw.Application { win.present (); } + public override void startup () { + base.startup (); + var provider = new Gtk.CssProvider (); + provider.load_from_resource ("/io/gitlab/nekocwd/the-cat-tools/style.css"); + Gtk.StyleContext.add_provider_for_display (Gdk.Display.get_default (), provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION); + } + private void on_about_action () { string[] developers = { "Vasiliy Doylov (NekoCWD) " }; var about = new Adw.AboutDialog () { diff --git a/src/gtk/help-overlay.blp b/src/gtk/help-overlay.blp new file mode 100644 index 0000000..90ee78f --- /dev/null +++ b/src/gtk/help-overlay.blp @@ -0,0 +1,24 @@ +using Gtk 4.0; + +ShortcutsWindow help_overlay { + modal: true; + + ShortcutsSection { + section-name: "shortcuts"; + max-height: 10; + + ShortcutsGroup { + title: C_("shortcut window", "General"); + + ShortcutsShortcut { + title: C_("shortcut window", "Show Shortcuts"); + action-name: "win.show-help-overlay"; + } + + ShortcutsShortcut { + title: C_("shortcut window", "Quit"); + action-name: "app.quit"; + } + } + } +} diff --git a/src/gtk/help-overlay.ui b/src/gtk/help-overlay.ui deleted file mode 100644 index ef12f02..0000000 --- a/src/gtk/help-overlay.ui +++ /dev/null @@ -1,29 +0,0 @@ - - - - True - - - shortcuts - 10 - - - General - - - Show Shortcuts - win.show-help-overlay - - - - - Quit - app.quit - - - - - - - - diff --git a/src/gui/bubble-bar.vala b/src/gui/bubble-bar.vala new file mode 100644 index 0000000..6dcb141 --- /dev/null +++ b/src/gui/bubble-bar.vala @@ -0,0 +1,55 @@ +class TheCatTools.GUI.BoubleBar : Gtk.DrawingArea, Gtk.Orientable { + public float value { get; set; default = 0; } + public Gtk.Orientation orientation { get; set; } + construct { + set_draw_func (draw); + notify["value"].connect (queue_draw); + add_css_class ("bubble-bar"); + notify["orientation"].connect (orientation_changed); + orientation_changed (); + } + void orientation_changed () { + if (orientation == Gtk.Orientation.HORIZONTAL) { + width_request = 60; + } else { + height_request = 60; + } + } + + void draw (Gtk.DrawingArea drawing_area, Cairo.Context cr, int width, int height) { + message ("Draw %dx%d", width, height); + var fg_c = get_color (); + var line_width = height / 120; + var gap = line_width;; + var radius = width / 2 - gap; + var position = radius + (height - radius * 2) * (value) / 180; + message ("%f = %f", value, position); + + // Bubble + cr.set_source_rgba (fg_c.red, fg_c.green, fg_c.blue, fg_c.alpha); + cr.arc (width / 2, position, radius, 0, 2 * Math.PI); + cr.fill (); + cr.set_source_rgba (fg_c.red, fg_c.green, fg_c.blue, fg_c.alpha); + + // Lines + var bc = get_style_context ().get_color (); + cr.set_source_rgba (fg_c.red, fg_c.green, fg_c.blue, fg_c.alpha); + cr.set_line_width (line_width); + cr.move_to (gap, position); + cr.rel_line_to (radius * 2, 0); + cr.stroke (); + cr.set_source_rgba (fg_c.red, fg_c.green, fg_c.blue, fg_c.alpha); + // -O- + cr.move_to (0, height / 2); + cr.rel_line_to (gap, 0); + cr.rel_move_to (radius * 2, 0); + cr.rel_line_to (gap, 0); + // Up line + cr.move_to (0, height / 2 - radius - gap); + cr.rel_line_to (width, 0); + // Down line + cr.move_to (0, height / 2 + radius + gap); + cr.rel_line_to (width, 0); + cr.stroke (); + } +} \ No newline at end of file diff --git a/src/gui/bubble-circle.vala b/src/gui/bubble-circle.vala new file mode 100644 index 0000000..e69de29 diff --git a/src/gui/meson.build b/src/gui/meson.build new file mode 100644 index 0000000..e3d76c6 --- /dev/null +++ b/src/gui/meson.build @@ -0,0 +1,4 @@ +gui_sources = [ + 'bubble-bar.vala', + 'bubble-circle.vala', +] diff --git a/src/meson.build b/src/meson.build index a96b3f8..dc2ac79 100644 --- a/src/meson.build +++ b/src/meson.build @@ -1,25 +1,52 @@ -thecattools_sources = [ +main_sources = [ 'main.vala', 'application.vala', 'window.vala', ] -thecattools_deps = [ +subdir('sensors') +foreach src : sensors_sources + main_sources += 'sensors' / src +endforeach +subdir('gui') +foreach src : gui_sources + main_sources += 'gui' / src +endforeach + +deps = [ config_dep, dependency('gtk4'), dependency('libadwaita-1', version: '>= 1.4'), + dependency('libssc') ] -thecattools_sources += gnome.compile_resources( +blueprints = custom_target( + 'blueprints', + input: files( + 'gtk/help-overlay.blp', + 'window.blp', + ), + output: '.', + command: [ + find_program('blueprint-compiler'), + 'batch-compile', + '@OUTPUT@', + '@CURRENT_SOURCE_DIR@', + '@INPUT@', + ], +) + +main_sources += gnome.compile_resources( 'resources', 'resources.gresource.xml', c_name: 'the_cat_tools', + dependencies: blueprints, ) executable( 'the_cat_tools', - thecattools_sources, - dependencies: thecattools_deps, + main_sources, + dependencies: deps, include_directories: config_inc, install: true, ) diff --git a/src/resources.gresource.xml b/src/resources.gresource.xml index 4b64ce3..f51d5e4 100644 --- a/src/resources.gresource.xml +++ b/src/resources.gresource.xml @@ -3,5 +3,6 @@ window.ui gtk/help-overlay.ui + style.css \ No newline at end of file diff --git a/src/sensors/accel.vala b/src/sensors/accel.vala new file mode 100644 index 0000000..e69de29 diff --git a/src/sensors/gyro.vala b/src/sensors/gyro.vala new file mode 100644 index 0000000..e69de29 diff --git a/src/sensors/meson.build b/src/sensors/meson.build new file mode 100644 index 0000000..27688df --- /dev/null +++ b/src/sensors/meson.build @@ -0,0 +1,5 @@ +sensors_sources = [ + 'sensor.vala', + 'accel.vala', + 'gyro.vala', +] diff --git a/src/sensors/sensor.vala b/src/sensors/sensor.vala new file mode 100644 index 0000000..720e227 --- /dev/null +++ b/src/sensors/sensor.vala @@ -0,0 +1,11 @@ +enum SensorType { + ACCELERATION, + LIGHT, + VELOCITY, + COMPASS, +} +public interface TheCatTools.Sensors.Sensor : Object { + public abstract string name { get; protected set; } + public abstract string id { get; protected set; } + public abstract Adw.Dialog get_configuration_dialog (); +} \ No newline at end of file diff --git a/src/style.css b/src/style.css new file mode 100644 index 0000000..266507f --- /dev/null +++ b/src/style.css @@ -0,0 +1,5 @@ +.bubble-bar { + color: var(--accent-color); + background-color: var(--view-bg-color); + border-radius: 20px; +} \ No newline at end of file diff --git a/src/window.blp b/src/window.blp new file mode 100644 index 0000000..3df8d3e --- /dev/null +++ b/src/window.blp @@ -0,0 +1,51 @@ +using Gtk 4.0; +using Adw 1; + +template $TheCatToolsWindow: Adw.ApplicationWindow { + title: _("TheCatTools"); + default-width: 800; + default-height: 600; + + content: Adw.ToolbarView { + [top] + Adw.HeaderBar { + [end] + MenuButton { + primary: true; + icon-name: "open-menu-symbolic"; + tooltip-text: _("Main Menu"); + menu-model: primary_menu; + } + } + + content: Adw.ClampScrollable { + orientation: vertical; + + Adw.Clamp { + CenterBox { + [start] + $TheCatToolsGUIBoubleBar bar {} + } + } + }; + }; +} + +menu primary_menu { + section { + item { + label: _("_Preferences"); + action: "app.preferences"; + } + + item { + label: _("_Keyboard Shortcuts"); + action: "win.show-help-overlay"; + } + + item { + label: _("_About TheCatTools"); + action: "app.about"; + } + } +} diff --git a/src/window.ui b/src/window.ui deleted file mode 100644 index 5b7b768..0000000 --- a/src/window.ui +++ /dev/null @@ -1,50 +0,0 @@ - - - - - - -
- - _Preferences - app.preferences - - - _Keyboard Shortcuts - win.show-help-overlay - - - _About TheCatTools - app.about - -
-
-
diff --git a/src/window.vala b/src/window.vala index 322efa1..65212c1 100644 --- a/src/window.vala +++ b/src/window.vala @@ -17,12 +17,26 @@ * SPDX-License-Identifier: GPL-3.0-or-later */ -[GtkTemplate (ui = "/io/gitlab/nekocwd/the-cat-tools/window.ui")] +[GtkTemplate(ui = "/io/gitlab/nekocwd/the-cat-tools/window.ui")] public class TheCatTools.Window : Adw.ApplicationWindow { [GtkChild] - private unowned Gtk.Label label; + private unowned GUI.BoubleBar bar; + async void start_sensors() { + var gyro = yield new SSC.SensorAccelerometer(null); + message("Gyro created"); + yield gyro.open(null); - public Window (Gtk.Application app) { - Object (application: app); + message("Gyro openned"); + gyro.measurement.connect((x, y, z) => { + message("Gyro measure %f %f %f m/s", x, y, z); + }); + } + + public Window(Gtk.Application app) { + Object(application: app); + start_sensors.begin(); + var ts = new TimeoutSource(10); + ts.set_callback(() => { bar.value += 0.5f; if (bar.value >= 360)bar.value = 0; return true; }); + ts.attach(); } } \ No newline at end of file diff --git a/subprojects/blueprint-compiler.wrap b/subprojects/blueprint-compiler.wrap new file mode 100644 index 0000000..2665f2c --- /dev/null +++ b/subprojects/blueprint-compiler.wrap @@ -0,0 +1,8 @@ +[wrap-git] +directory = blueprint-compiler +url = https://gitlab.gnome.org/jwestman/blueprint-compiler.git +revision = v0.16.0 +depth = 1 + +[provide] +program_names = blueprint-compiler \ No newline at end of file