protected int focus_first;
protected int focus_end;
protected int focus_size;
- protected double[] focus_starts;
+ protected int[] focus_starts;
protected bool focus_locked;
protected double focus_centre;
list[i] = "Antani %d".printf(i);
cur_el = 0;
- focus_centre = 0.0;
+ focus_centre = 0;
focus_size = 20;
- focus_starts = new double[focus_size + 1];
+ focus_starts = new int[focus_size + 1];
focus_locked = false;
distortion_factor = 30;
focus_layout();
public override bool motion_notify_event(Gdk.EventMotion event)
{
int old_cur_el = cur_el;
- double x = event.x / allocation.width;
- double y = event.y / allocation.height;
+ int x = (int)event.x;
+ int y = (int)event.y;
- focus_locked = x < 0.5 && y >= focus_starts[0] && y < focus_starts[focus_end - focus_first];
+ focus_locked = x < allocation.width/2 && y >= focus_starts[0] && y < focus_starts[focus_end - focus_first];
if (focus_locked)
{
}
} else {
- cur_el = (int)Math.round(y * list.length);
+ cur_el = y * list.length / allocation.height;
if (old_cur_el != cur_el)
focus_layout();
}
return false;
}
- protected double el_y(int idx)
+ protected int el_y(int idx)
{
- double layout_min = 0;
- double layout_max = 1;
// Undistorted Y
- double undy = (double)idx/list.length;
+ double undy = (double)idx * allocation.height / list.length;
// Distorted position
- double pos = fisheye(undy, focus_centre, distortion_factor, layout_min, layout_max);
+ double pos = fisheye(undy, focus_centre, distortion_factor, 0, allocation.height);
//stderr.printf("%d %f %f\n", idx, undy, pos);
- return pos;
+ return (int)Math.round(pos);
}
protected void focus_layout()
{
// Anchor point
- focus_centre = (double)cur_el/list.length;
+ focus_centre = (double)cur_el*allocation.height/list.length;
focus_first = cur_el > focus_size/2 ? cur_el-focus_size/2 : 0;
focus_end = focus_first + focus_size;
// Compute starting positions for all items in focus
for (int idx = focus_first; idx < focus_end; ++idx)
{
- double posprev = idx == 0 ? 0 : el_y(idx-1);
- double pos = el_y(idx);
- double posnext = idx == list.length-1 ? 1 : el_y(idx+1);
- double y0 = (pos+posprev)/2;
- double y1 = (pos+posnext)/2;
+ int posprev = idx == 0 ? 0 : el_y(idx-1);
+ int pos = el_y(idx);
+ int posnext = idx == list.length-1 ? 1 : el_y(idx+1);
+ int y0 = (pos+posprev)/2;
+ int y1 = (pos+posnext)/2;
focus_starts[idx - focus_first] = y0;
focus_starts[idx - focus_first + 1] = y1;
Gdk.cairo_set_source_color(context, style.bg[Gtk.StateType.NORMAL]);
context.paint();
- // Normalise coordinates
- context.translate (0, 0);
- context.scale(allocation.width, allocation.height);
-
// Focus lock area
Gdk.cairo_set_source_color(context, style.bg[Gtk.StateType.ACTIVE]);
context.new_path();
- context.rectangle(0, focus_starts[0], 0.5, focus_starts[focus_end - focus_first]);
+ context.rectangle(0, focus_starts[0], allocation.width/2, focus_starts[focus_end - focus_first]);
context.fill();
context.stroke();
// Focus movement area
Gdk.cairo_set_source_color(context, style.bg[Gtk.StateType.INSENSITIVE]);
context.new_path();
- context.rectangle(0.5, 0, 1, 1);
+ context.rectangle(allocation.width/2, 0, allocation.width, allocation.height);
context.fill();
context.stroke();
context.select_font_face(style.font_desc.get_family(), Cairo.FontSlant.NORMAL, Cairo.FontWeight.NORMAL);
for (int idx = focus_first; idx < focus_end; ++idx)
{
- double y0 = focus_starts[idx - focus_first];
- double y1 = focus_starts[idx - focus_first + 1];
+ int y0 = focus_starts[idx - focus_first];
+ int y1 = focus_starts[idx - focus_first + 1];
if (idx == cur_el)
{
Gdk.cairo_set_source_color(context, style.bg[Gtk.StateType.SELECTED]);
context.new_path();
- context.rectangle(0, y0, 1, y1-y0);
+ context.rectangle(0, y0, allocation.width, y1-y0);
context.fill();
context.stroke();