Fix sensors
Signed-off-by: Vasiliy Doylov <nekodevelopper@gmail.com>
This commit is contained in:
parent
2e158e3c97
commit
a130ca830b
3 changed files with 74 additions and 48 deletions
|
@ -1,5 +1,7 @@
|
||||||
class TheCatTools.GUI.BoubleBar : Gtk.DrawingArea, Gtk.Orientable {
|
class TheCatTools.GUI.BoubleBar : Gtk.DrawingArea, Gtk.Orientable {
|
||||||
public float value { get; set; default = 0; }
|
public double value { get; set; default = 0; }
|
||||||
|
public Gtk.Adjustment adjustment { get; set; default = new Gtk.Adjustment (0, -90, 90, 0, 0, 0); }
|
||||||
|
|
||||||
public Gtk.Orientation orientation { get; set; }
|
public Gtk.Orientation orientation { get; set; }
|
||||||
construct {
|
construct {
|
||||||
set_draw_func (draw);
|
set_draw_func (draw);
|
||||||
|
@ -7,54 +9,55 @@ class TheCatTools.GUI.BoubleBar : Gtk.DrawingArea, Gtk.Orientable {
|
||||||
add_css_class ("bubble-bar");
|
add_css_class ("bubble-bar");
|
||||||
notify["orientation"].connect (orientation_changed);
|
notify["orientation"].connect (orientation_changed);
|
||||||
orientation_changed ();
|
orientation_changed ();
|
||||||
|
vexpand = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void orientation_changed () {
|
void orientation_changed () {
|
||||||
|
message ("Request orientation");
|
||||||
|
var orientation = orientation == Gtk.Orientation.HORIZONTAL;
|
||||||
|
width_request = -1;
|
||||||
|
width_request = orientation ? -1 : 60;
|
||||||
|
height_request = orientation ? 60 : -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void set_color_rgba (Cairo.Context cr, Gdk.RGBA color) {
|
||||||
|
cr.set_source_rgba (color.red, color.green, color.blue, color.alpha);
|
||||||
|
}
|
||||||
|
|
||||||
|
double get_adjusted_value () {
|
||||||
|
var res = value;
|
||||||
|
if (res > 90)
|
||||||
|
res = 180 - res;
|
||||||
|
if (res < -90)
|
||||||
|
res = -180 + res;
|
||||||
|
return res.clamp (adjustment.lower, adjustment.upper);
|
||||||
|
}
|
||||||
|
|
||||||
|
void draw_meow (Cairo.Context cr, int width, int height) {
|
||||||
|
var gap = 2;
|
||||||
|
var radius = width / 2 - gap / 2;
|
||||||
|
var val = get_adjusted_value ();
|
||||||
|
var position = radius + (height - 2 * radius) * (val - adjustment.lower) / (adjustment.upper - adjustment.lower);
|
||||||
|
|
||||||
|
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.move_to (10, 10);
|
||||||
|
cr.show_text ("Meow");
|
||||||
|
}
|
||||||
|
|
||||||
|
void draw (Gtk.DrawingArea self, Cairo.Context cr, int width, int height) {
|
||||||
|
message ("Draw %dx%d", width, height);
|
||||||
if (orientation == Gtk.Orientation.HORIZONTAL) {
|
if (orientation == Gtk.Orientation.HORIZONTAL) {
|
||||||
width_request = 60;
|
cr.rotate (Math.PI / 2);
|
||||||
|
cr.translate (0, -width);
|
||||||
|
draw_meow (cr, height, width);
|
||||||
} else {
|
} else {
|
||||||
height_request = 60;
|
draw_meow (cr, width, height);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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 value = (value * -1) + 90;
|
|
||||||
if (value > 180)
|
|
||||||
value = 360 - value;
|
|
||||||
if (value < 0)
|
|
||||||
value *= -1;
|
|
||||||
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 ();
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
.bubble-bar {
|
.bubble-bar {
|
||||||
color: var(--accent-color);
|
color: var(--accent-bg-color);
|
||||||
background-color: var(--view-bg-color);
|
background-color: var(--view-bg-color);
|
||||||
border-radius: 20px;
|
border-radius: 20px;
|
||||||
}
|
}
|
|
@ -22,9 +22,32 @@ template $TheCatToolsWindow: Adw.ApplicationWindow {
|
||||||
orientation: vertical;
|
orientation: vertical;
|
||||||
|
|
||||||
Adw.Clamp {
|
Adw.Clamp {
|
||||||
CenterBox {
|
Grid {
|
||||||
|
orientation: horizontal;
|
||||||
|
column-spacing: 24;
|
||||||
|
|
||||||
[start]
|
[start]
|
||||||
$TheCatToolsGUIBoubleBar bar {}
|
$TheCatToolsGUIBoubleBar hbar {
|
||||||
|
orientation: horizontal;
|
||||||
|
layout {
|
||||||
|
column: 2;
|
||||||
|
row: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
halign: fill;
|
||||||
|
hexpand: true;
|
||||||
|
valign: end;
|
||||||
|
vexpand: false;
|
||||||
|
}
|
||||||
|
|
||||||
|
[start]
|
||||||
|
$TheCatToolsGUIBoubleBar vbar {
|
||||||
|
orientation: vertical;
|
||||||
|
layout {
|
||||||
|
column: 1;
|
||||||
|
row: 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue