void Plotter::MouseMotion(View& view, int x, int y, int button_state) { const int d[2] = {x-last_mouse_pos[0], y-last_mouse_pos[1]}; const float is[2] = {rview.x.Size(), rview.y.Size() }; const float df[2] = {is[0]*d[0]/(float)v.w, is[1]*d[1]/(float)v.h}; // Update hover status (after potential resizing) ScreenToPlot(x, y, hover[0], hover[1]); if( button_state == MouseButtonLeft ) { // Update selected range selection.x.max = hover[0]; selection.y.max = hover[1]; }else if(button_state == MouseButtonMiddle ) { Special(view, InputSpecialScroll, df[0], df[1], 0.0f, 0.0f, 0.0f, 0.0f, button_state); }else if(button_state == MouseButtonRight ) { const float c[2] = { track || trigger_edge ? last_track_val[0] : hover[0], hover[1] }; const float scale[2] = { 1.0f + (float)d[0] / (float)v.w, 1.0f - (float)d[1] / (float)v.h, }; ScaleView(scale[0], scale[1], c[0], c[1]); } last_mouse_pos[0] = x; last_mouse_pos[1] = y; }
void Plotter::Mouse(View& /*view*/, MouseButton button, int x, int y, bool pressed, int button_state) { // Update hover status (after potential resizing) ScreenToPlot(x, y, hover[0], hover[1]); const float scinc = 1.05f; const float scdec = 1.0f/scinc; const float c[2] = { track || trigger_edge ? last_track_val[0] : hover[0], hover[1] }; if(button_state & KeyModifierShift) { if(button == MouseWheelUp) { ScaleViewSmooth(1.0f, scinc, c[0], c[1]); }else if(button == MouseWheelDown) { ScaleViewSmooth(1.0f, scdec, c[0], c[1]); }else if(button == MouseWheelLeft) { ScaleViewSmooth(scinc, 1.0f, c[0], c[1]); }else if(button == MouseWheelRight) { ScaleViewSmooth(scdec, 1.0f, c[0], c[1]); } }else if(button_state & KeyModifierCtrl) { if(button == MouseWheelUp) { ScaleViewSmooth(scinc, 1.0f, c[0], c[1]); }else if(button == MouseWheelDown) { ScaleViewSmooth(scdec, 1.0f, c[0], c[1]); } }else{ const float mvfactor = 1.0f/20.0f; if(button == MouseButtonLeft) { // Update selected range if(pressed) { selection.x.min = hover[0]; selection.y.min = hover[1]; trigger_value = selection.y.min; } selection.x.max = hover[0]; selection.y.max = hover[1]; }else if(button == MouseWheelUp) { ScrollViewSmooth(0.0f, +mvfactor*rview.y.Size() ); }else if(button == MouseWheelDown) { ScrollViewSmooth(0.0f, -mvfactor*rview.y.Size() ); }else if(button == MouseWheelLeft) { ScrollViewSmooth(+mvfactor*rview.x.Size(), 0.0f ); }else if(button == MouseWheelRight) { ScrollViewSmooth(-mvfactor*rview.x.Size(), 0.0f ); } } FixSelection(); last_mouse_pos[0] = x; last_mouse_pos[1] = y; }
void Plotter::Mouse(View&, MouseButton button, int x, int y, bool pressed, int button_state) { last_mouse_pos[0] = x; last_mouse_pos[1] = y; mouse_state = button_state; if(button == MouseWheelUp || button == MouseWheelDown) { //const float mean = (int_y[0] + int_y[1])/2.0; const float scale = 1.0f + ((button == MouseWheelDown) ? 0.1 : -0.1); // int_y[0] = scale*(int_y[0] - mean) + mean; // int_y[1] = scale*(int_y[1] - mean) + mean; int_y[0] = scale*(int_y[0]) ; int_y[1] = scale*(int_y[1]) ; } ScreenToPlot(x,y); }
void Plotter::Special(View&, InputSpecial inType, float x, float y, float p1, float p2, float /*p3*/, float /*p4*/, int button_state) { if(inType == InputSpecialScroll) { const float d[2] = {p1,-p2}; const float is[2] = {rview.x.Size(),rview.y.Size() }; const float df[2] = {is[0]*d[0]/(float)v.w, is[1]*d[1]/(float)v.h}; ScrollView(-df[0], -df[1]); } else if(inType == InputSpecialZoom) { float scalex = 1.0; float scaley = 1.0; #ifdef _OSX_ if (button_state & KeyModifierCmd) { #else if (button_state & KeyModifierCtrl) { #endif scalex = 1-p1; }else{ scaley = 1-p1; } const float c[2] = { track || trigger_edge ? last_track_val[0] : hover[0], hover[1] }; ScaleView(scalex, scaley, c[0], c[1]); } // Update hover status (after potential resizing) ScreenToPlot( (int)x, (int)y, hover[0], hover[1]); } void Plotter::AddSeries(const std::string& x_expr, const std::string& y_expr, DrawingMode drawing_mode, Colour colour, const std::string& title, DataLog *log) { if( !std::isfinite(colour.r) ) { colour = colour_wheel.GetUniqueColour(); } plotseries.push_back( PlotSeries() ); plotseries.back().CreatePlot(x_expr, y_expr, colour, (title == "$y") ? y_expr : title); plotseries.back().log = log; plotseries.back().drawing_mode = (GLenum)drawing_mode; } void Plotter::ClearSeries() { plotseries.clear(); } Marker& Plotter::AddMarker(Marker::Direction d, float value, Marker::Equality leg, Colour c ) { return AddMarker(Marker(d,value,leg,c)); } Marker& Plotter::AddMarker( const Marker& marker ) { plotmarkers.push_back( marker ); return plotmarkers.back(); }
void Plotter::PassiveMouseMotion(View&, int x, int y, int /*button_state*/) { ScreenToPlot(x, y, hover[0], hover[1]); }