WIP: SSC TEST
Signed-off-by: Vasiliy Doylov <nekodevelopper@gmail.com>
This commit is contained in:
parent
b9365b2574
commit
673ffecf17
19 changed files with 224 additions and 90 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1 +1,2 @@
|
|||
.vscode
|
||||
/subprojects/blueprint-compiler
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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) <nekodevelopper@gmail.com>" };
|
||||
var about = new Adw.AboutDialog () {
|
||||
|
|
24
src/gtk/help-overlay.blp
Normal file
24
src/gtk/help-overlay.blp
Normal 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";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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
55
src/gui/bubble-bar.vala
Normal 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 ();
|
||||
}
|
||||
}
|
0
src/gui/bubble-circle.vala
Normal file
0
src/gui/bubble-circle.vala
Normal file
4
src/gui/meson.build
Normal file
4
src/gui/meson.build
Normal file
|
@ -0,0 +1,4 @@
|
|||
gui_sources = [
|
||||
'bubble-bar.vala',
|
||||
'bubble-circle.vala',
|
||||
]
|
|
@ -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,
|
||||
)
|
||||
|
|
|
@ -3,5 +3,6 @@
|
|||
<gresource prefix="/io/gitlab/nekocwd/the-cat-tools">
|
||||
<file preprocess="xml-stripblanks">window.ui</file>
|
||||
<file preprocess="xml-stripblanks">gtk/help-overlay.ui</file>
|
||||
<file>style.css</file>
|
||||
</gresource>
|
||||
</gresources>
|
0
src/sensors/accel.vala
Normal file
0
src/sensors/accel.vala
Normal file
0
src/sensors/gyro.vala
Normal file
0
src/sensors/gyro.vala
Normal file
5
src/sensors/meson.build
Normal file
5
src/sensors/meson.build
Normal file
|
@ -0,0 +1,5 @@
|
|||
sensors_sources = [
|
||||
'sensor.vala',
|
||||
'accel.vala',
|
||||
'gyro.vala',
|
||||
]
|
11
src/sensors/sensor.vala
Normal file
11
src/sensors/sensor.vala
Normal 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
5
src/style.css
Normal 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
51
src/window.blp
Normal 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";
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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>
|
|
@ -20,9 +20,23 @@
|
|||
[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);
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
8
subprojects/blueprint-compiler.wrap
Normal file
8
subprojects/blueprint-compiler.wrap
Normal 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
|
Loading…
Add table
Add a link
Reference in a new issue