summaryrefslogtreecommitdiff
path: root/src/renderers
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff-webhosting.net>2015-08-19 16:25:31 +0200
committerJörg Frings-Fürst <debian@jff-webhosting.net>2015-08-19 16:25:31 +0200
commit10af7615316fd91eef61cc66a8ede38a2bff3fdc (patch)
tree0f5731b91e14dc14f0ba6f3394768222f66a31be /src/renderers
parent0b56dfbf01171226a0bb035afcd13358b6477710 (diff)
Imported Upstream version 0.6.5upstream/0.6.5
Diffstat (limited to 'src/renderers')
-rw-r--r--src/renderers/pieRenderer.vala62
-rwxr-xr-xsrc/renderers/pieWindow.vala45
-rw-r--r--src/renderers/sliceRenderer.vala17
3 files changed, 87 insertions, 37 deletions
diff --git a/src/renderers/pieRenderer.vala b/src/renderers/pieRenderer.vala
index cd50644..1ff2b3e 100644
--- a/src/renderers/pieRenderer.vala
+++ b/src/renderers/pieRenderer.vala
@@ -221,7 +221,7 @@ public class PieRenderer : GLib.Object {
}
}
- this.set_highlighted_slice(this.quickaction);
+ this.select_by_index(this.quickaction);
ShowPieMode showpie= ShowPieMode.FULL_PIE;
@@ -500,19 +500,19 @@ public class PieRenderer : GLib.Object {
if (this.first_slice_idx+this.visible_slice_count >= slices.size) {
this.visible_slice_count= slices.size - this.first_slice_idx;
}
- this.reset_sclice_anim();
- this.set_highlighted_slice(-1);
+ this.reset_slice_anim();
+ this.select_by_index(-1);
calc_key_navigation_pos();
this.key_board_control = true;
} else if (this.first_slice_idx > 0) {
//go to first page
this.first_slice_idx= 0;
- this.reset_sclice_anim();
+ this.reset_slice_anim();
//recover the original value
this.visible_slice_count= this.original_visible_slice_count;
- this.reset_sclice_anim();
- this.set_highlighted_slice(-1);
+ this.reset_slice_anim();
+ this.select_by_index(-1);
calc_key_navigation_pos();
this.key_board_control = true;
}
@@ -532,8 +532,8 @@ public class PieRenderer : GLib.Object {
if (this.first_slice_idx < 0) {
this.first_slice_idx= 0;
}
- this.reset_sclice_anim();
- this.set_highlighted_slice(-1);
+ this.reset_slice_anim();
+ this.select_by_index(-1);
calc_key_navigation_pos();
this.key_board_control = true;
@@ -547,20 +547,54 @@ public class PieRenderer : GLib.Object {
//last page has less slices than previous
this.visible_slice_count= n;
this.first_slice_idx= slices.size - this.visible_slice_count;
- this.reset_sclice_anim();
- this.set_highlighted_slice(-1);
+ this.reset_slice_anim();
+ this.select_by_index(-1);
calc_key_navigation_pos();
this.key_board_control = true;
}
}
- private void reset_sclice_anim() {
+ private void reset_slice_anim() {
//reset animation values in all the new visible slices
for (int i= 0; i < this.visible_slice_count; ++i)
this.slices[ i+this.first_slice_idx ].reset_anim();
}
/////////////////////////////////////////////////////////////////////
+ /// Selects a slice based on a search string.
+ /////////////////////////////////////////////////////////////////////
+
+ public void select_by_string(string search) {
+ float max_similarity = 0;
+ int index = -1;
+
+ for (int i=0; i<this.visible_slice_count; ++i) {
+ float similarity = 0;
+ int cur_pos = 0;
+ var name = slices[this.first_slice_idx+i].action.name.down();
+
+ for (int j=0; j<search.length; ++j) {
+ int next_pos = name.index_of(search.substring(j, 1), cur_pos);
+
+ if (next_pos != -1) {
+ cur_pos = next_pos;
+ similarity += (float)(name.length-next_pos)/name.length + 2;
+ }
+ }
+
+ if (similarity > max_similarity) {
+ index = this.first_slice_idx+i;
+ max_similarity = similarity;
+ }
+ }
+
+ if (index >= 0 && index < slice_count()) {
+ key_board_control = true;
+ select_by_index(index);
+ }
+ }
+
+ /////////////////////////////////////////////////////////////////////
/// Returns the amount of slices in this pie.
/////////////////////////////////////////////////////////////////////
@@ -616,7 +650,7 @@ public class PieRenderer : GLib.Object {
next_active_slice = -1;
}
- this.set_highlighted_slice(next_active_slice);
+ this.select_by_index(next_active_slice);
}
center.draw(frame_time, ctx, angle, slice_track);
@@ -639,7 +673,7 @@ public class PieRenderer : GLib.Object {
/// Called when the currently active slice changes.
/////////////////////////////////////////////////////////////////////
- public void set_highlighted_slice(int index) {
+ public void select_by_index(int index) {
if (index != this.active_slice) {
if (index >= this.first_slice_idx && index < this.first_slice_idx+this.visible_slice_count)
this.active_slice = index;
@@ -847,7 +881,7 @@ public class PieRenderer : GLib.Object {
pos= this.first_slice_idx;
}
- this.set_highlighted_slice(pos);
+ this.select_by_index(pos);
this.key_board_control = true;
}
diff --git a/src/renderers/pieWindow.vala b/src/renderers/pieWindow.vala
index 95432c5..a49813a 100755
--- a/src/renderers/pieWindow.vala
+++ b/src/renderers/pieWindow.vala
@@ -95,6 +95,13 @@ public class PieWindow : Gtk.Window {
private bool has_compositing = false;
/////////////////////////////////////////////////////////////////////
+ /// When a Pie is opened, pressed buttons are accumulated and
+ /// matches are searched in all slices.
+ /////////////////////////////////////////////////////////////////////
+
+ private string search_string = "";
+
+ /////////////////////////////////////////////////////////////////////
/// C'tor, sets up the window.
/////////////////////////////////////////////////////////////////////
@@ -145,7 +152,7 @@ public class PieWindow : Gtk.Window {
this.key_press_event.connect((e) => {
if (e.keyval != last_key) {
last_key = e.keyval;
- this.handle_key_press(e.keyval, e.time);
+ this.handle_key_press(e.keyval, e.time, e.str);
}
return true;
});
@@ -429,7 +436,7 @@ public class PieWindow : Gtk.Window {
/// Do some useful stuff when keys are pressed.
/////////////////////////////////////////////////////////////////////
- private void handle_key_press(uint key, uint32 time_stamp) {
+ private void handle_key_press(uint key, uint32 time_stamp, string text) {
if (Gdk.keyval_name(key) == "Escape") this.cancel();
else if (Gdk.keyval_name(key) == "Return") this.activate_slice(time_stamp);
else if (!PieManager.get_is_turbo(this.renderer.id)) {
@@ -441,23 +448,31 @@ public class PieWindow : Gtk.Window {
else if (Gdk.keyval_name(key) == "Page_Up") this.renderer.select_prevpage();
else if (Gdk.keyval_name(key) == "Tab") this.renderer.select_nextpage();
else if (Gdk.keyval_name(key) == "ISO_Left_Tab") this.renderer.select_prevpage();
- else if (Gdk.keyval_name(key) == "Alt_L") this.renderer.show_hotkeys = true;
+ else if (Gdk.keyval_name(key) == "Alt_L" && !Config.global.search_by_string) this.renderer.show_hotkeys = true;
else {
- int index = -1;
- if (key >= 48 && key <= 57) index = ((int)key - 39)%10;
- else if (key >= 97 && key <= 122) index = (int)key - 87;
- else if (key >= 65 && key <= 90) index = (int)key - 55;
+ if (Config.global.search_by_string) {
+ this.search_string += text;
+ this.renderer.select_by_string(search_string.down());
+
+ } else {
+
+ int index = -1;
+
+ if (key >= 48 && key <= 57) index = ((int)key - 39)%10;
+ else if (key >= 97 && key <= 122) index = (int)key - 87;
+ else if (key >= 65 && key <= 90) index = (int)key - 55;
- if (index >= 0 && index < this.renderer.slice_count()) {
- this.renderer.key_board_control = true;
- this.renderer.set_highlighted_slice(index);
+ if (index >= 0 && index < this.renderer.slice_count()) {
+ this.renderer.key_board_control = true;
+ this.renderer.select_by_index(index);
- if (this.renderer.active_slice == index) {
- GLib.Timeout.add((uint)(Config.global.theme.transition_time*1000.0), ()=> {
- this.activate_slice(time_stamp);
- return false;
- });
+ if (this.renderer.active_slice == index) {
+ GLib.Timeout.add((uint)(Config.global.theme.transition_time*1000.0), ()=> {
+ this.activate_slice(time_stamp);
+ return false;
+ });
+ }
}
}
}
diff --git a/src/renderers/sliceRenderer.vala b/src/renderers/sliceRenderer.vala
index dfcf512..591fbdd 100644
--- a/src/renderers/sliceRenderer.vala
+++ b/src/renderers/sliceRenderer.vala
@@ -46,6 +46,12 @@ public class SliceRenderer : GLib.Object {
public Color color {get; private set;}
/////////////////////////////////////////////////////////////////////
+ /// The Action which is rendered by this SliceRenderer.
+ /////////////////////////////////////////////////////////////////////
+
+ public Action action;
+
+ /////////////////////////////////////////////////////////////////////
/// The two Images used, when this slice is active or not.
/////////////////////////////////////////////////////////////////////
@@ -59,12 +65,6 @@ public class SliceRenderer : GLib.Object {
private Image hotkey;
/////////////////////////////////////////////////////////////////////
- /// The Action which is rendered by this SliceRenderer.
- /////////////////////////////////////////////////////////////////////
-
- private Action action;
-
- /////////////////////////////////////////////////////////////////////
/// The PieRenderer which owns this SliceRenderer.
/////////////////////////////////////////////////////////////////////
@@ -150,7 +150,7 @@ public class SliceRenderer : GLib.Object {
this.hotkey = new RenderedText(hotkey_label, (int)Config.global.theme.slice_radius*2,
(int)Config.global.theme.slice_radius*2, "sans 20",
- Config.global.theme.caption_color, Config.global.global_scale);
+ new Color(), Config.global.global_scale);
}
/////////////////////////////////////////////////////////////////////
@@ -284,8 +284,9 @@ public class SliceRenderer : GLib.Object {
ctx.paint();
// draw hotkeys if necassary
- if (this.parent.show_hotkeys)
+ if (this.parent.show_hotkeys) {
this.hotkey.paint_on(ctx, 1.0);
+ }
ctx.restore();
}