WIP: SSC TEST

Signed-off-by: Vasiliy Doylov <nekodevelopper@gmail.com>
This commit is contained in:
Vasiliy Doylov 2025-03-02 10:53:09 +03:00
parent b9365b2574
commit 673ffecf17
Signed by: NekoCWD
GPG key ID: B7BE22D44474A582
19 changed files with 224 additions and 90 deletions

3
.gitignore vendored
View file

@ -1 +1,2 @@
.vscode .vscode
/subprojects/blueprint-compiler

View file

@ -5,4 +5,4 @@ data/io.gitlab.nekocwd.thecattools.metainfo.xml.in
data/io.gitlab.nekocwd.thecattools.gschema.xml data/io.gitlab.nekocwd.thecattools.gschema.xml
src/main.vala src/main.vala
src/window.vala src/window.vala
src/window.ui src/window.blp

View file

@ -41,6 +41,13 @@ public class TheCatTools.Application : Adw.Application {
win.present (); 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 () { private void on_about_action () {
string[] developers = { "Vasiliy Doylov (NekoCWD) <nekodevelopper@gmail.com>" }; string[] developers = { "Vasiliy Doylov (NekoCWD) <nekodevelopper@gmail.com>" };
var about = new Adw.AboutDialog () { var about = new Adw.AboutDialog () {

24
src/gtk/help-overlay.blp Normal file
View file

@ -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";
}
}
}
}

View file

@ -1,29 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<object class="GtkShortcutsWindow" id="help_overlay">
<property name="modal">True</property>
<child>
<object class="GtkShortcutsSection">
<property name="section-name">shortcuts</property>
<property name="max-height">10</property>
<child>
<object class="GtkShortcutsGroup">
<property name="title" translatable="yes" context="shortcut window">General</property>
<child>
<object class="GtkShortcutsShortcut">
<property name="title" translatable="yes" context="shortcut window">Show Shortcuts</property>
<property name="action-name">win.show-help-overlay</property>
</object>
</child>
<child>
<object class="GtkShortcutsShortcut">
<property name="title" translatable="yes" context="shortcut window">Quit</property>
<property name="action-name">app.quit</property>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</interface>

55
src/gui/bubble-bar.vala Normal file
View file

@ -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 ();
}
}

View file

4
src/gui/meson.build Normal file
View file

@ -0,0 +1,4 @@
gui_sources = [
'bubble-bar.vala',
'bubble-circle.vala',
]

View file

@ -1,25 +1,52 @@
thecattools_sources = [ main_sources = [
'main.vala', 'main.vala',
'application.vala', 'application.vala',
'window.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, config_dep,
dependency('gtk4'), dependency('gtk4'),
dependency('libadwaita-1', version: '>= 1.4'), 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',
'resources.gresource.xml', 'resources.gresource.xml',
c_name: 'the_cat_tools', c_name: 'the_cat_tools',
dependencies: blueprints,
) )
executable( executable(
'the_cat_tools', 'the_cat_tools',
thecattools_sources, main_sources,
dependencies: thecattools_deps, dependencies: deps,
include_directories: config_inc, include_directories: config_inc,
install: true, install: true,
) )

View file

@ -3,5 +3,6 @@
<gresource prefix="/io/gitlab/nekocwd/the-cat-tools"> <gresource prefix="/io/gitlab/nekocwd/the-cat-tools">
<file preprocess="xml-stripblanks">window.ui</file> <file preprocess="xml-stripblanks">window.ui</file>
<file preprocess="xml-stripblanks">gtk/help-overlay.ui</file> <file preprocess="xml-stripblanks">gtk/help-overlay.ui</file>
<file>style.css</file>
</gresource> </gresource>
</gresources> </gresources>

0
src/sensors/accel.vala Normal file
View file

0
src/sensors/gyro.vala Normal file
View file

5
src/sensors/meson.build Normal file
View file

@ -0,0 +1,5 @@
sensors_sources = [
'sensor.vala',
'accel.vala',
'gyro.vala',
]

11
src/sensors/sensor.vala Normal file
View file

@ -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 ();
}

5
src/style.css Normal file
View file

@ -0,0 +1,5 @@
.bubble-bar {
color: var(--accent-color);
background-color: var(--view-bg-color);
border-radius: 20px;
}

51
src/window.blp Normal file
View file

@ -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";
}
}
}

View file

@ -1,50 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<requires lib="gtk" version="4.0"/>
<requires lib="Adw" version="1.0"/>
<template class="TheCatToolsWindow" parent="AdwApplicationWindow">
<property name="title" translatable="yes">TheCatTools</property>
<property name="default-width">800</property>
<property name="default-height">600</property>
<property name="content">
<object class="AdwToolbarView">
<child type="top">
<object class="AdwHeaderBar">
<child type="end">
<object class="GtkMenuButton">
<property name="primary">True</property>
<property name="icon-name">open-menu-symbolic</property>
<property name="tooltip-text" translatable="yes">Main Menu</property>
<property name="menu-model">primary_menu</property>
</object>
</child>
</object>
</child>
<property name="content">
<object class="GtkLabel" id="label">
<property name="label" translatable="yes">Hello, World!</property>
<style>
<class name="title-1"/>
</style>
</object>
</property>
</object>
</property>
</template>
<menu id="primary_menu">
<section>
<item>
<attribute name="label" translatable="yes">_Preferences</attribute>
<attribute name="action">app.preferences</attribute>
</item>
<item>
<attribute name="label" translatable="yes">_Keyboard Shortcuts</attribute>
<attribute name="action">win.show-help-overlay</attribute>
</item>
<item>
<attribute name="label" translatable="yes">_About TheCatTools</attribute>
<attribute name="action">app.about</attribute>
</item>
</section>
</menu>
</interface>

View file

@ -17,12 +17,26 @@
* SPDX-License-Identifier: GPL-3.0-or-later * 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 { public class TheCatTools.Window : Adw.ApplicationWindow {
[GtkChild] [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) { message("Gyro openned");
Object (application: app); 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();
} }
} }

View file

@ -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