Skip to content

Commit

Permalink
add selection save hint
Browse files Browse the repository at this point in the history
  • Loading branch information
stronnag committed Mar 4, 2023
1 parent f3ced72 commit b77ac60
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 19 deletions.
5 changes: 5 additions & 0 deletions data/org.stronnag.wayfarer.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,10 @@
<default>false</default>
<summary>Use notifications to stop recording</summary>
</key>

<key name="show-hint" type="b">
<default>true</default>
<summary>Show a hint message on area selection</summary>
</key>
</schema>
</schemalist>
9 changes: 9 additions & 0 deletions data/wayfarer.blp
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,15 @@ Gtk.Box prefsstuff {
halign: fill;
}
}
Gtk.Box {
spacing: 4;
orientation: horizontal;
[start]
Gtk.CheckButton prefs_hint {
label: "Show area selection hint";
halign: fill;
}
}
}

/*
Expand Down
70 changes: 59 additions & 11 deletions src/selection.vala
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ public class AreaWindow : Gtk.Window {
private const int BLOB_RADIUS=20;
private const int LINE_RELAX=4;
private const float LINE_WIDTH=2.0f;
private const string ENDTEXT = "Save the area :\n - Press Enter or Space, or\n - Click Button 2 or Button 3\nQuit : Press ESCape";

private enum DrawMode {
NONE,
RECT,
NONE = 0,
RECT = 1,
TEXT = 2,
}

private enum DragMode {
Expand Down Expand Up @@ -54,17 +56,22 @@ public class AreaWindow : Gtk.Window {
private Gdk.RGBA fill;
private Gdk.RGBA stroke;
private Gdk.RGBA bfill;
private Gdk.RGBA dfill;
public signal void area_set(int x0, int y0, int x1, int y1);
public signal void area_quit();

bool ingrab = false;
private bool show_hint;
private bool ingrab = false;
private DrawMode drawmode;
private DragMode dragmode;

public AreaWindow() {
public AreaWindow(bool _show_hint) {
show_hint = _show_hint;
fill = Gdk.RGBA(){red = 1.0f, green = 1.0f, blue = 1.0f, alpha= 0.2f};
stroke = Gdk.RGBA(){red = 1.0f, green = 1.0f, blue = 1.0f, alpha = 0.5f};
bfill = Gdk.RGBA(){red = 1.0f, green = 1.0f, blue = 1.0f, alpha = 0.8f};
dfill = Gdk.RGBA(){red = 0.0f, green = 0.0f, blue = 0.0f, alpha= 0.5f};

title = "Wayfarer";
drawmode = DrawMode.NONE;
dragmode = DragMode.FREE;
Expand Down Expand Up @@ -135,6 +142,8 @@ public class AreaWindow : Gtk.Window {
if (dragmode == DragMode.GRAB) {
dragmode = set_cursor_mode(absx, absy);
}
drawmode = DrawMode.TEXT;
queue_draw();
});

gestd.drag_update.connect((x,y) => {
Expand Down Expand Up @@ -257,25 +266,64 @@ public class AreaWindow : Gtk.Window {
snap.pop();
}

private void show_message(Gtk.Snapshot snap) {
var width = ((endx-spx)*9)/10;
var height = ((endy - spy)*9)/10;
var font = new Pango.FontDescription();
font.set_family("Sans");
var fsize = 20 * Pango.SCALE;
var context = this.get_pango_context();
var layout = new Pango.Layout(context);
font.set_size(fsize);
layout.set_font_description(font);
layout.set_text(ENDTEXT, -1);
int lwidth;
int lheight;
layout.get_pixel_size(out lwidth, out lheight);
var fw = fsize * width / lwidth;
var fh = fsize * height / lheight ;
fsize = (fw < fh) ? fw : fh;
font.set_size(fsize);
layout.set_font_description(font);
layout.set_text(ENDTEXT, -1);
layout.get_pixel_size(out lwidth, out lheight);
var point = Graphene.Point();
point.x = spx + (endx-spx)/20;
var bh = (endy- spy);
point.y = spy + (endy-spy)/20 + (bh-lheight)/2;
snap.save();
snap.translate(point);
snap.append_layout(layout, bfill);
snap.restore();
}

public override void snapshot (Gtk.Snapshot snap) {
if (drawmode == DrawMode.RECT) {
if (drawmode == DrawMode.NONE) {
var rect = Graphene.Rect.zero();
snap.append_color(bfill, rect);
} else {
float[] lwidths = {LINE_WIDTH, LINE_WIDTH, LINE_WIDTH, LINE_WIDTH};
Gdk.RGBA[] lcols = {stroke, stroke, stroke, stroke};

var rect = Graphene.Rect.zero();
var rrect = Gsk.RoundedRect(){};
rect.init(spx, spy, endx-spx, endy-spy);
rrect.init_from_rect(rect, 0.0f);
snap.append_color(fill, rect);
if (drawmode == DrawMode.TEXT) {
snap.append_color(dfill, rect);
} else {
snap.append_color(fill, rect);
}
snap.append_border(rrect, lwidths, lcols);
add_corner(snap, spx, spy);
add_corner(snap, endx, spy);
add_corner(snap, endx, endy);
add_corner(snap, spx, endy);
} else {
var rect = Graphene.Rect.zero();
snap.append_color(bfill, rect);
}
if (drawmode == DrawMode.TEXT) {
if(show_hint) {
show_message(snap);
}
}
}
}

private void set_bg() {
Expand Down
17 changes: 10 additions & 7 deletions src/settings.vala
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
[Compact]
public class Conf : Object {
public string audio_device { get; set; }
public string video_dir { get; set; }
public string media_type { get; set; }
public string restore_token { get; set; }
public string video_dir { get; set; }
public string media_type { get; set; }
public string restore_token { get; set; }

public uint32 audio_rate { get; set; }
public uint32 frame_rate { get; set; }
public uint32 audio_rate { get; set; }
public uint32 frame_rate { get; set; }

public bool notify_start { get; set; }
public bool notify_stop { get; set; }
public bool notify_start { get; set; }
public bool notify_stop { get; set; }

public bool show_hint { get; set; }

private Settings s;

Expand All @@ -24,5 +26,6 @@ public class Conf : Object {
s.bind("frame-rate", this, "frame-rate", SettingsBindFlags.DEFAULT);
s.bind("notify-start", this, "notify_start", SettingsBindFlags.DEFAULT);
s.bind("notify-stop", this, "notify_stop", SettingsBindFlags.DEFAULT);
s.bind("show-hint", this, "show-hint", SettingsBindFlags.DEFAULT);
}
}
5 changes: 4 additions & 1 deletion src/wayfarer.vala
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ public class Wayfarer : Gtk.Application {
Gtk.Button prefapply = builder.get_object("prefsapply") as Button;
CheckButton prefs_not = builder.get_object("prefs_not") as CheckButton;
CheckButton prefs_notall = builder.get_object("prefs_notall") as CheckButton;
CheckButton prefs_hint = builder.get_object("prefs_hint") as CheckButton;
Gtk.Entry prefs_audiorate = builder.get_object("prefs_audiorate") as Entry;
mediasel = builder.get_object("media_sel") as ComboBoxText;

Expand Down Expand Up @@ -193,6 +194,7 @@ public class Wayfarer : Gtk.Application {
prefapply.clicked.connect(() => {
conf.notify_start = prefs_not.active;
conf.notify_stop = prefs_notall.active;
conf.show_hint = prefs_hint.active;
conf.audio_rate = int.parse(prefs_audiorate.text);
prefs.hide();
});
Expand Down Expand Up @@ -331,6 +333,7 @@ public class Wayfarer : Gtk.Application {

prefs_not.active = conf.notify_start;
prefs_notall.active = conf.notify_stop;
prefs_hint.active = conf.show_hint;

audiosource.changed.connect(() => {
conf.audio_device = audiosource.active_id;
Expand Down Expand Up @@ -482,7 +485,7 @@ public class Wayfarer : Gtk.Application {
if(ctrlseta) {
window.hide();
}
sw = new AreaWindow ();
sw = new AreaWindow (conf.show_hint);
sw.area_set.connect((x0, y0, x1, y1) => {
var swh = sw.get_allocated_height();
var offset = sources[0].height - swh;
Expand Down

0 comments on commit b77ac60

Please sign in to comment.