Fix sensors
Signed-off-by: Vasiliy Doylov <nekodevelopper@gmail.com>
This commit is contained in:
parent
08a08a516a
commit
8d747ce4c1
4 changed files with 68 additions and 36 deletions
|
@ -1,43 +1,60 @@
|
||||||
class TheCatTools.GUI.BoubleCircle : DrawingAreaOrientable {
|
class TheCatTools.GUI.BoubleCircle : Adw.Bin, Gtk.Orientable {
|
||||||
public double value_x { get; set; default = 0; }
|
public int requested_size { get; set; default = 60; }
|
||||||
public double value_y { get; set; default = 0; }
|
|
||||||
public Gtk.Adjustment adjustment { get; set; default = new Gtk.Adjustment (0, -90, 90, 0, 0, 0); }
|
public Gtk.Adjustment adjustment { get; set; default = new Gtk.Adjustment (0, -90, 90, 0, 0, 0); }
|
||||||
|
public Gtk.Orientation orientation { get; set; }
|
||||||
|
public Bubble bubble = new Bubble ();
|
||||||
|
public Circle clamps_ok = new Circle ();
|
||||||
|
public Gtk.Overlay overlay = new Gtk.Overlay ();
|
||||||
|
|
||||||
construct {
|
construct {
|
||||||
|
width_request = 60;
|
||||||
|
add_css_class ("bubble-bar");
|
||||||
notify["value"].connect (queue_draw);
|
notify["value"].connect (queue_draw);
|
||||||
add_css_class ("bubble-circle");
|
notify["orientation"].connect (orientation_changed);
|
||||||
orientation_changed ();
|
orientation_changed ();
|
||||||
vexpand = true;
|
bubble.vexpand = true;
|
||||||
|
bubble.hexpand = true;
|
||||||
|
overlay.add_overlay (clamps_ok);
|
||||||
|
overlay.add_overlay (bubble);
|
||||||
|
set_child (overlay);
|
||||||
|
bind_property ("orientation", clamps_ok, "orientation", GLib.BindingFlags.SYNC_CREATE);
|
||||||
|
bind_property ("orientation", bubble, "orientation", GLib.BindingFlags.SYNC_CREATE);
|
||||||
|
clamps_ok.bind_state_to_bubble_pos (bubble);
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_color_rgba (Cairo.Context cr, Gdk.RGBA color) {
|
public void orientation_changed () {
|
||||||
cr.set_source_rgba (color.red, color.green, color.blue, color.alpha);
|
var orientation = orientation == Gtk.Orientation.HORIZONTAL;
|
||||||
|
width_request = -1;
|
||||||
|
width_request = orientation ? -1 : requested_size;
|
||||||
|
height_request = orientation ? requested_size : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
double get_adjusted_value () {
|
public class Circle : DrawingAreaOrientable {
|
||||||
var res = value * -1;
|
public Gtk.Adjustment adjustment { get; set; default = new Gtk.Adjustment (0, -90, 90, 0, 0, 0); }
|
||||||
if (res > 90)
|
public Gtk.Adjustment clamps { get; set; default = new Gtk.Adjustment (0, -10, 10, 0, 0, 0); }
|
||||||
res = 180 - res;
|
construct {
|
||||||
if (res < -90)
|
add_css_class ("circle");
|
||||||
res = -180 - res;
|
}
|
||||||
return res.clamp (adjustment.lower, adjustment.upper);
|
public void bind_state_to_bubble_pos (Bubble bubble) {
|
||||||
|
bubble.notify["value-x"].connect (() => {
|
||||||
|
bool inb = true;
|
||||||
|
if (bubble.value_x >= clamps.upper) {
|
||||||
|
set_state_flags (Gtk.StateFlags.CHECKED, false);
|
||||||
|
inb = false;
|
||||||
|
} else if (bubble.value_x <= clamps.lower) {
|
||||||
|
set_state_flags (Gtk.StateFlags.CHECKED, false);
|
||||||
|
inb = false;
|
||||||
|
} else
|
||||||
|
unset_state_flags (Gtk.StateFlags.CHECKED);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void draw_func (Gtk.DrawingArea self, Cairo.Context cr, int width, int height) {
|
public override void draw_func (Gtk.DrawingArea self, Cairo.Context cr, int width, int height) {
|
||||||
var gap = 2;
|
var range = adjustment.upper - adjustment.lower;
|
||||||
var radius = width / 2 - gap / 2;
|
Utils.set_color_rgba (cr, get_color ());
|
||||||
var val = get_adjusted_value ();
|
var radius = width / range * (clamps.upper - clamps.lower);
|
||||||
var position = radius + (height - 2 * radius) * (val - adjustment.lower) / (adjustment.upper - adjustment.lower);
|
cr.arc (width / 2, height / 2, radius, 0, Math.PI * 2);
|
||||||
|
|
||||||
set_color_rgba (cr, get_color ());
|
|
||||||
cr.arc (radius, position, radius, 0, Math.PI * 2);
|
|
||||||
cr.fill ();
|
|
||||||
|
|
||||||
cr.move_to (0, 0);
|
|
||||||
cr.line_to (width, height);
|
|
||||||
cr.set_line_width (3);
|
|
||||||
cr.stroke ();
|
cr.stroke ();
|
||||||
cr.move_to (10, 10);
|
}
|
||||||
cr.show_text ("Meow");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -3,4 +3,6 @@ gui_sources = [
|
||||||
'drawing-area-orientable.vala',
|
'drawing-area-orientable.vala',
|
||||||
'bubble.vala',
|
'bubble.vala',
|
||||||
'bubble-bar.vala',
|
'bubble-bar.vala',
|
||||||
|
'bubble-circle.vala',
|
||||||
|
|
||||||
]
|
]
|
||||||
|
|
|
@ -27,14 +27,14 @@ template $TheCatToolsWindow: Adw.ApplicationWindow {
|
||||||
margin-end: 12;
|
margin-end: 12;
|
||||||
orientation: horizontal;
|
orientation: horizontal;
|
||||||
column-spacing: 24;
|
column-spacing: 24;
|
||||||
|
row-spacing: 24;
|
||||||
|
|
||||||
[start]
|
|
||||||
$TheCatToolsGUIBoubleBar hbar {
|
$TheCatToolsGUIBoubleBar hbar {
|
||||||
orientation: horizontal;
|
orientation: horizontal;
|
||||||
|
|
||||||
layout {
|
layout {
|
||||||
column: 2;
|
column: 2;
|
||||||
row: 1;
|
row: 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
halign: fill;
|
halign: fill;
|
||||||
|
@ -43,7 +43,6 @@ template $TheCatToolsWindow: Adw.ApplicationWindow {
|
||||||
vexpand: false;
|
vexpand: false;
|
||||||
}
|
}
|
||||||
|
|
||||||
[start]
|
|
||||||
$TheCatToolsGUIBoubleBar vbar {
|
$TheCatToolsGUIBoubleBar vbar {
|
||||||
orientation: vertical;
|
orientation: vertical;
|
||||||
vexpand: true;
|
vexpand: true;
|
||||||
|
@ -53,6 +52,16 @@ template $TheCatToolsWindow: Adw.ApplicationWindow {
|
||||||
row: 1;
|
row: 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$TheCatToolsGUIBoubleCircle circle {
|
||||||
|
orientation: vertical;
|
||||||
|
vexpand: true;
|
||||||
|
|
||||||
|
layout {
|
||||||
|
column: 2;
|
||||||
|
row: 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -26,6 +26,8 @@ public class TheCatTools.Window : Adw.ApplicationWindow {
|
||||||
private unowned GUI.BoubleBar hbar;
|
private unowned GUI.BoubleBar hbar;
|
||||||
[GtkChild]
|
[GtkChild]
|
||||||
private unowned GUI.BoubleBar vbar;
|
private unowned GUI.BoubleBar vbar;
|
||||||
|
[GtkChild]
|
||||||
|
private unowned GUI.BoubleCircle circle;
|
||||||
private SSC.SensorAccelerometer accel;
|
private SSC.SensorAccelerometer accel;
|
||||||
|
|
||||||
async void start_sensors() {
|
async void start_sensors() {
|
||||||
|
@ -43,6 +45,8 @@ public class TheCatTools.Window : Adw.ApplicationWindow {
|
||||||
message("%f\t%f", x_angle, y_angle);
|
message("%f\t%f", x_angle, y_angle);
|
||||||
hbar.bubble.value_x = (float) x_angle;
|
hbar.bubble.value_x = (float) x_angle;
|
||||||
vbar.bubble.value_x = (float) y_angle;
|
vbar.bubble.value_x = (float) y_angle;
|
||||||
|
circle.bubble.value_x = (float) x_angle;
|
||||||
|
circle.bubble.value_y = (float) y_angle;
|
||||||
});
|
});
|
||||||
} catch (Error err) {
|
} catch (Error err) {
|
||||||
message("Failed to open Sensor %s", err.message);
|
message("Failed to open Sensor %s", err.message);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue