OK. In progress...

This commit is contained in:
Kolan Sh 2018-01-16 20:09:14 +03:00
parent 8fd012dce5
commit efa0c07ccb
3 changed files with 44 additions and 42 deletions

View File

@ -368,40 +368,6 @@ namespace CairoChart {
}
}
public virtual void set_active_cursor (Point p, bool remove = false) {
cursors.active_cursor = scr2rel_point(p);
cursors.is_cursor_active = ! remove;
}
public virtual void add_active_cursor () {
cursors.list.append (cursors.active_cursor);
cursors.is_cursor_active = false;
}
public virtual void remove_active_cursor () {
if (cursors.list.length() == 0) return;
var distance = width * width;
uint rm_indx = 0;
uint i = 0;
foreach (var c in cursors.list) {
double d = distance;
switch (cursors.cursor_style.orientation) {
case Cursors.Orientation.VERTICAL:
d = (rel2scr_x(c.x) - rel2scr_x(cursors.active_cursor.x)).abs();
break;
case Cursors.Orientation.HORIZONTAL:
d = (rel2scr_y(c.y) - rel2scr_y(cursors.active_cursor.y)).abs();
break;
}
if (d < distance) {
distance = d;
rm_indx = i;
}
++i;
}
if (distance < cursors.cursor_style.select_distance)
cursors.list.delete_link(cursors.list.nth(rm_indx));
cursors.is_cursor_active = false;
}
protected virtual bool x_in_plot_area (double x) {
if (math.x_in_range(x, plot_x_min, plot_x_max))
return true;
@ -418,13 +384,13 @@ namespace CairoChart {
return false;
}
protected virtual Float128 scr2rel_x (Float128 x) {
public virtual Float128 scr2rel_x (Float128 x) {
return rz_x_min + (x - plot_x_min) / (plot_x_max - plot_x_min) * (rz_x_max - rz_x_min);
}
protected virtual Float128 scr2rel_y (Float128 y) {
public virtual Float128 scr2rel_y (Float128 y) {
return rz_y_max - (plot_y_max - y) / (plot_y_max - plot_y_min) * (rz_y_max - rz_y_min);
}
protected virtual Point scr2rel_point (Point p) {
public virtual Point scr2rel_point (Point p) {
return Point (scr2rel_x(p.x), scr2rel_y(p.y));
}
public virtual Float128 rel2scr_x(Float128 x) {

View File

@ -55,6 +55,42 @@ namespace CairoChart {
CursorCross[] crossings;
}
public virtual void set_active_cursor (Chart chart, Point p, bool remove = false) {
active_cursor = chart.scr2rel_point(p);
is_cursor_active = ! remove;
}
public virtual void add_active_cursor () {
list.append (active_cursor);
is_cursor_active = false;
}
public virtual void remove_active_cursor (Chart chart) {
if (list.length() == 0) return;
var distance = 1024.0 * 1024.0;//width * width;
uint rm_indx = 0;
uint i = 0;
foreach (var c in list) {
double d = distance;
switch (cursor_style.orientation) {
case Cursors.Orientation.VERTICAL:
d = (chart.rel2scr_x(c.x) - chart.rel2scr_x(active_cursor.x)).abs();
break;
case Cursors.Orientation.HORIZONTAL:
d = (chart.rel2scr_y(c.y) - chart.rel2scr_y(active_cursor.y)).abs();
break;
}
if (d < distance) {
distance = d;
rm_indx = i;
}
++i;
}
if (distance < cursor_style.select_distance)
list.delete_link(list.nth(rm_indx));
is_cursor_active = false;
}
protected List<Point?> get_all_cursors (Chart chart) {
var all_cursors = list.copy_deep ((src) => { return src; });
if (is_cursor_active)

View File

@ -454,11 +454,11 @@ int main (string[] args) {
switch (event.button) {
case 1: // start cursor position selection
if ((event.state & Gdk.ModifierType.SHIFT_MASK) != 0) { // remove cursor
chart.set_active_cursor (Point(event.x, event.y), true);
chart.remove_active_cursor();
chart.cursors.set_active_cursor (chart, Point(event.x, event.y), true);
chart.cursors.remove_active_cursor(chart);
mouse_state = MouseState.FREE;
} else { // add cursor
chart.set_active_cursor (Point(event.x, event.y));
chart.cursors.set_active_cursor (chart, Point(event.x, event.y));
mouse_state = MouseState.CURSOR_SELECTION;
}
da.queue_draw_area(0, 0, da.get_allocated_width(), da.get_allocated_height());
@ -490,7 +490,7 @@ int main (string[] args) {
//da.queue_draw_area(0, 0, da.get_allocated_width(), da.get_allocated_height());
//mouse_state = MouseState.FREE;
} else { // add cursor
chart.add_active_cursor ();
chart.cursors.add_active_cursor ();
mouse_state = MouseState.FREE;
}
break;
@ -532,7 +532,7 @@ int main (string[] args) {
break;
case MouseState.CURSOR_SELECTION:
chart.set_active_cursor (Point(event.x, event.y));
chart.cursors.set_active_cursor (chart, Point(event.x, event.y));
da.queue_draw_area(0, 0, da.get_allocated_width(), da.get_allocated_height());
break;
}