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: 95e42f4e8f73
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: a7399980591a
Choose a head ref
  • 2 commits
  • 4 files changed
  • 1 contributor

Commits on Oct 30, 2020

  1. Copy the full SHA
    2e2ea44 View commit details
  2. WaveformArea: various fixes to display and input handling when high-D…

    …PI scaling is active. See #255.
    azonenberg committed Oct 30, 2020
    Copy the full SHA
    a739998 View commit details
Showing with 52 additions and 7 deletions.
  1. +22 −6 src/glscopeclient/Timeline.cpp
  2. +4 −0 src/glscopeclient/WaveformArea.cpp
  3. +1 −1 src/glscopeclient/WaveformArea_cairo.cpp
  4. +25 −0 src/glscopeclient/WaveformArea_events.cpp
28 changes: 22 additions & 6 deletions src/glscopeclient/Timeline.cpp
Original file line number Diff line number Diff line change
@@ -65,6 +65,10 @@ Timeline::~Timeline()

bool Timeline::on_button_press_event(GdkEventButton* event)
{
auto scale = get_window()->get_scale_factor();
event->x *= scale;
event->y *= scale;

if(event->type == GDK_BUTTON_PRESS)
{
//for now, only handle left click
@@ -102,6 +106,10 @@ bool Timeline::on_button_release_event(GdkEventButton* event)

bool Timeline::on_motion_notify_event(GdkEventMotion* event)
{
auto scale = get_window()->get_scale_factor();
event->x *= scale;
event->y *= scale;

switch(m_dragState)
{
//Dragging the horizontal offset
@@ -127,6 +135,10 @@ bool Timeline::on_motion_notify_event(GdkEventMotion* event)

bool Timeline::on_scroll_event (GdkEventScroll* ev)
{
auto scale = get_window()->get_scale_factor();
ev->x *= scale;
ev->y *= scale;

int64_t timestamp = (ev->x / m_group->m_pixelsPerXUnit) + m_group->m_xAxisOffset;

switch(ev->direction)
@@ -201,14 +213,16 @@ bool Timeline::on_draw(const Cairo::RefPtr<Cairo::Context>& cr)

void Timeline::Render(const Cairo::RefPtr<Cairo::Context>& cr, OscilloscopeChannel* chan)
{
float xscale = m_group->m_pixelsPerXUnit / get_window()->get_scale_factor();

size_t w = get_width();
size_t h = get_height();
double ytop = 2;
double ybot = h - 10;
double ymid = (h-10) / 2;

//Figure out rounding granularity, based on our time scales
int64_t width_ps = w / m_group->m_pixelsPerXUnit;
int64_t width_ps = w / xscale;
int64_t round_divisor = 1;
if(width_ps < 1E4)
{
@@ -242,7 +256,7 @@ void Timeline::Render(const Cairo::RefPtr<Cairo::Context>& cr, OscilloscopeChann

//Figure out about how much time per graduation to use
const double min_label_grad_width = 75 * GetDPIScale(); //Minimum distance between text labels, in pixels
double grad_ps_nominal = min_label_grad_width / m_group->m_pixelsPerXUnit;
double grad_ps_nominal = min_label_grad_width / xscale;

//Round so the division sizes are sane
double units_per_grad = grad_ps_nominal * 1.0 / round_divisor;
@@ -272,12 +286,12 @@ void Timeline::Render(const Cairo::RefPtr<Cairo::Context>& cr, OscilloscopeChann
int sheight;
for(double t = tstart; t < (tstart + width_ps + grad_ps_rounded); t += grad_ps_rounded)
{
double x = (t - m_group->m_xAxisOffset) * m_group->m_pixelsPerXUnit;
double x = (t - m_group->m_xAxisOffset) * xscale;

//Draw fine ticks first (even if the labeled graduation doesn't fit)
for(int tick=1; tick < nsubticks; tick++)
{
double subx = (t - m_group->m_xAxisOffset + tick*subtick) * m_group->m_pixelsPerXUnit;
double subx = (t - m_group->m_xAxisOffset + tick*subtick) * xscale;

if(subx < 0)
continue;
@@ -356,7 +370,7 @@ void Timeline::Render(const Cairo::RefPtr<Cairo::Context>& cr, OscilloscopeChann
if(scope == NULL)
return;
int64_t timestamp = scope->GetTriggerOffset();
double x = (timestamp - m_group->m_xAxisOffset) * m_group->m_pixelsPerXUnit;
double x = (timestamp - m_group->m_xAxisOffset) * xscale;

auto trig = scope->GetTrigger();
if(trig)
@@ -386,6 +400,8 @@ void Timeline::DrawCursor(
bool draw_left,
bool show_delta)
{
float xscale = m_group->m_pixelsPerXUnit / get_window()->get_scale_factor();

int h = get_height();

Gdk::Color black("black");
@@ -434,7 +450,7 @@ void Timeline::DrawCursor(
tlayout->get_pixel_size(swidth, sheight);

//Decide which side of the line to draw on
double x = (ps - m_group->m_xAxisOffset) * m_group->m_pixelsPerXUnit;
double x = (ps - m_group->m_xAxisOffset) * xscale;
double right = x-5;
double left = right - swidth - 5;
if(!draw_left)
4 changes: 4 additions & 0 deletions src/glscopeclient/WaveformArea.cpp
Original file line number Diff line number Diff line change
@@ -442,6 +442,10 @@ void WaveformArea::on_realize()
Gtk::GLArea::on_realize();
make_current();

//Apply DPI scaling to Pango fonts since we are not using Cairo scaling
auto c = get_pango_context();
c->set_resolution(c->get_resolution() * get_window()->get_scale_factor());

//Set up GLEW
if(!m_isGlewInitialized)
{
2 changes: 1 addition & 1 deletion src/glscopeclient/WaveformArea_cairo.cpp
Original file line number Diff line number Diff line change
@@ -229,7 +229,7 @@ void WaveformArea::RenderTriggerArrow(
{
float y = VoltsToYPosition(voltage);

float trisize = 5 * GetDPIScale();
float trisize = 5 * GetDPIScale() * get_window()->get_scale_factor();

//Dragging? Arrow follows mouse
if(dragging)
25 changes: 25 additions & 0 deletions src/glscopeclient/WaveformArea_events.cpp
Original file line number Diff line number Diff line change
@@ -116,6 +116,11 @@ void WaveformArea::on_resize(int width, int height)

bool WaveformArea::on_scroll_event (GdkEventScroll* ev)
{
//Scaling for hi-dpi
auto scale = get_window()->get_scale_factor();
ev->x *= scale;
ev->y *= scale;

m_clickLocation = HitTest(ev->x, ev->y);

switch(m_clickLocation)
@@ -194,6 +199,11 @@ bool WaveformArea::on_scroll_event (GdkEventScroll* ev)

bool WaveformArea::on_button_press_event(GdkEventButton* event)
{
//Scaling for hi-dpi
auto scale = get_window()->get_scale_factor();
event->x *= scale;
event->y *= scale;

//TODO: See if we right clicked on our main channel or a protocol decoder.
//If a decoder, filter for that instead
m_selectedChannel = m_channel;
@@ -220,6 +230,11 @@ bool WaveformArea::on_button_press_event(GdkEventButton* event)

void WaveformArea::OnSingleClick(GdkEventButton* event, int64_t timestamp)
{
//Scaling for hi-dpi
auto scale = get_window()->get_scale_factor();
event->x *= scale;
event->y *= scale;

switch(m_clickLocation)
{
//Move cursors if we click on them
@@ -429,6 +444,11 @@ void WaveformArea::OnDoubleClick(GdkEventButton* /*event*/, int64_t /*timestamp*

bool WaveformArea::on_button_release_event(GdkEventButton* event)
{
//Scaling for hi-dpi
auto scale = get_window()->get_scale_factor();
event->x *= scale;
event->y *= scale;

int64_t timestamp = XPositionToXAxisUnits(event->x);

switch(m_dragState)
@@ -572,6 +592,11 @@ bool WaveformArea::on_button_release_event(GdkEventButton* event)

bool WaveformArea::on_motion_notify_event(GdkEventMotion* event)
{
//Scaling for hi-dpi
auto scale = get_window()->get_scale_factor();
event->x *= scale;
event->y *= scale;

m_cursorX = event->x;
m_cursorY = event->y;