Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: ngscopeclient/scopehal-apps
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 6586ffec0c52
Choose a base ref
...
head repository: ngscopeclient/scopehal-apps
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: ad9a3d46f530
Choose a head ref
  • 1 commit
  • 3 files changed
  • 1 contributor

Commits on May 15, 2021

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    ad9a3d4 View commit details
Showing with 93 additions and 6 deletions.
  1. +1 −1 lib
  2. +86 −4 src/glscopeclient/Timeline.cpp
  3. +6 −1 src/glscopeclient/Timeline.h
2 changes: 1 addition & 1 deletion lib
90 changes: 86 additions & 4 deletions src/glscopeclient/Timeline.cpp
Original file line number Diff line number Diff line change
@@ -42,6 +42,7 @@ Timeline::Timeline(OscilloscopeWindow* parent, WaveformGroup* group)
: m_group(group)
, m_parent(parent)
, m_xAxisUnit(Unit::UNIT_FS)
, m_dragScope(NULL)
{
m_dragState = DRAG_NONE;
m_dragStartX = 0;
@@ -63,6 +64,45 @@ Timeline::~Timeline()
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// UI events

/**
@brief Figure out where the cursor is
*/
Timeline::DragState Timeline::HitTest(double x, double /*y*/, Oscilloscope** pscope)
{
//Find the trigger arrow
double trig_x = 0;
bool trig_found = false;
auto children = m_group->m_waveformBox.get_children();
if(!children.empty())
{
auto view = dynamic_cast<WaveformArea*>(children[0]);
if(view != NULL)
{
auto scope = view->GetChannel().m_channel->GetScope();
if(scope != NULL)
{
float xscale = m_group->m_pixelsPerXUnit / get_window()->get_scale_factor();
auto trig = scope->GetTrigger();
if(trig)
{
trig_x = (scope->GetTriggerOffset() - m_group->m_xAxisOffset) * xscale;
trig_found = true;
if(pscope)
*pscope = scope;
}
}
}
}

//Trigger position
if(trig_found && fabs(x - trig_x) < 5 )
return DRAG_TRIGGER;

//The entire timeline is draggable, so default to that if we're not anywhere special
else
return DRAG_TIMELINE;
}

bool Timeline::on_button_press_event(GdkEventButton* event)
{
auto scale = get_window()->get_scale_factor();
@@ -74,11 +114,24 @@ bool Timeline::on_button_press_event(GdkEventButton* event)
//for now, only handle left click
if(event->button == 1)
{
m_dragState = DRAG_TIMELINE;
m_dragStartX = event->x;
m_originalTimeOffset = m_group->m_xAxisOffset;
Oscilloscope* target = NULL;
m_dragState = HitTest(event->x, event->y, &target);

get_window()->set_cursor(Gdk::Cursor::create(get_display(), "grabbing"));
switch(m_dragState)
{
case DRAG_TRIGGER:
get_window()->set_cursor(Gdk::Cursor::create(get_display(), "ew-resize"));
m_dragScope = target;
break;

case DRAG_TIMELINE:
default:
m_originalTimeOffset = m_group->m_xAxisOffset;
get_window()->set_cursor(Gdk::Cursor::create(get_display(), "grabbing"));
break;
}

m_dragStartX = event->x;
}
}

@@ -126,7 +179,36 @@ bool Timeline::on_motion_notify_event(GdkEventMotion* event)
}
break;

//Dragging the trigger
case DRAG_TRIGGER:
{
//Figure out where the trigger is being dragged to
double sx = event->x / m_group->m_pixelsPerXUnit;
int64_t t = static_cast<int64_t>(round(sx)) + m_group->m_xAxisOffset;

m_dragScope->SetTriggerOffset(t);
queue_draw();
}
break;

//Not dragging anything, update the cursor
case DRAG_NONE:
default:
{
auto target = HitTest(event->x, event->y);

switch(target)
{
case DRAG_TRIGGER:
get_window()->set_cursor(Gdk::Cursor::create(get_display(), "ew-resize"));
break;

case DRAG_TIMELINE:
default:
get_window()->set_cursor(Gdk::Cursor::create(get_display(), "grab"));
break;
}
}
break;
}

7 changes: 6 additions & 1 deletion src/glscopeclient/Timeline.h
Original file line number Diff line number Diff line change
@@ -47,7 +47,8 @@ class Timeline : public Gtk::Layout
enum DragState
{
DRAG_NONE,
DRAG_TIMELINE
DRAG_TIMELINE,
DRAG_TRIGGER
} m_dragState;

double m_dragStartX;
@@ -59,6 +60,8 @@ class Timeline : public Gtk::Layout
virtual bool on_motion_notify_event(GdkEventMotion* event);
virtual bool on_scroll_event (GdkEventScroll* ev);

DragState HitTest(double x, double y, Oscilloscope** pscope = NULL);

virtual void on_realize();

void Render(const Cairo::RefPtr<Cairo::Context>& cr, OscilloscopeChannel* chan);
@@ -78,6 +81,8 @@ class Timeline : public Gtk::Layout
{ return get_pango_context()->get_resolution() / 96; }

Unit m_xAxisUnit;

Oscilloscope* m_dragScope;
};

#endif