使用ScrollGraphicalViewer滚动时重画问题

时间:2018-06-30 18:09:50

标签: swt eclipse-rcp eclipse-gef

环境:Win10上的Eclipse Neon。

我有一个较旧的GEF / SWT RCP应用程序,该应用程序使用ScrollingGraphicalViewer来处理滚动。滚动时,应保留在滚动条中的原始图像已正确移动,但未绘制新区域。 有时,最小化和还原应用程序窗口可使其正确重绘。尽管在其他时候,它会像未滚动图像一样显示图像,但是滚动条指示它已滚动。

水平滚动和垂直滚动都会发生这种情况。我只用拇指滚动进行测试,因为它是单步移动,而不是具有大量重绘的连续操作。

这是一个代码示例。是我的一张图中的paintFigure()方法达到了全宽。


      protected void paintFigure (Graphics graphics)
      {
        if (log.isTraceEnabled ()) {
          final Rectangle dummy = new Rectangle ();
          log.trace (String.format ("Paint rung %s, bounds %s, clip %s", rungId.getText (), getBounds (), graphics.getClip (dummy))); //$NON-NLS-1$
        }
        super.paintFigure (graphics);

        // Draw the vertical bars
        Rectangle r = getBounds ().getCopy ();
        r.width -= LINE_WIDTH;
        r.width += 1; // Coming up 1 short for some reason
        r.shrink (MARGIN, 0);
        if (log.isTraceEnabled ()) {
          log.trace (String.format ("Adjusted bounds %s", r)); //$NON-NLS-1$
        }
        final int connectionY = r.y + connectionYOffset;
        int connectionXStart = instructionsFigure.getBounds ().right ();
        int connectionXStop = r.right ();
        graphics.drawLine (connectionXStart, connectionY, connectionXStop, connectionY);
        connectionXStart = r.x-4;
        connectionXStop = instructionsFigure.getBounds ().x;
        graphics.drawLine (connectionXStart, connectionY, connectionXStop, connectionY);

        graphics.setLineWidth (LINE_WIDTH);
        graphics.drawLine (r.getTopRight (), r.getBottomRight ());

        graphics.drawLine (r.x - 4, r.y, r.x - 4, r.y+r.height);
      }

这是一些跟踪输出。请注意,LadderLayer是梯级的父级图形。

Initial display:
TRACE   2018-06-30 10:08:56,289 10099   com.bas.basplc.ui.editors.ladder_editor.figures.LadderLayer [main]  Paint ladder layer, bounds Rectangle(0.0, 0.0, 1200.0, 2190.0), clip Rectangle(0.0, 0.0, 1070.0, 673.0)
TRACE   2018-06-30 10:08:56,289 10099   com.bas.basplc.ui.editors.ladder_editor.figures.RungFigure  [main]  Paint rung 0, bounds Rectangle(3.0, 3.0, 1200.0, 384.0), clip Rectangle(3.0, 3.0, 1067.0, 384.0)
TRACE   2018-06-30 10:08:56,290 10100   com.bas.basplc.ui.editors.ladder_editor.figures.RungFigure  [main]  Adjusted bounds Rectangle(63.0, 3.0, 1078.0, 384.0)
Not sure what is being drawn here:
TRACE   2018-06-30 10:08:56,370 10180   com.bas.basplc.ui.editors.ladder_editor.figures.LadderLayer [main]  Paint ladder layer, bounds Rectangle(0.0, 0.0, 1200.0, 2190.0), clip Rectangle(1047.0, 15.0, 23.0, 658.0)
TRACE   2018-06-30 10:08:56,370 10180   com.bas.basplc.ui.editors.ladder_editor.figures.RungFigure  [main]  Paint rung 0, bounds Rectangle(3.0, 3.0, 1200.0, 384.0), clip Rectangle(1047.0, 15.0, 23.0, 372.0)
TRACE   2018-06-30 10:08:56,370 10180   com.bas.basplc.ui.editors.ladder_editor.figures.RungFigure  [main]  Adjusted bounds Rectangle(63.0, 3.0, 1078.0, 384.0)
Thumb scroll right:
TRACE   2018-06-30 10:10:16,244 90054   com.bas.basplc.ui.editors.ladder_editor.figures.LadderLayer [main]  Paint ladder layer, bounds Rectangle(0.0, 0.0, 1200.0, 2190.0), clip Rectangle(940.0, 0.0, 130.0, 673.0)
TRACE   2018-06-30 10:10:16,245 90055   com.bas.basplc.ui.editors.ladder_editor.figures.RungFigure  [main]  Paint rung 0, bounds Rectangle(3.0, 3.0, 1200.0, 384.0), clip Rectangle(940.0, 3.0, 130.0, 384.0)
TRACE   2018-06-30 10:10:16,245 90055   com.bas.basplc.ui.editors.ladder_editor.figures.RungFigure  [main]  Adjusted bounds Rectangle(63.0, 3.0, 1078.0, 384.0)
Redraw after minimize/restore:
TRACE   2018-06-30 10:11:56,406 190216  com.bas.basplc.ui.editors.ladder_editor.figures.LadderLayer [main]  Paint ladder layer, bounds Rectangle(0.0, 0.0, 1200.0, 2190.0), clip Rectangle(0.0, 0.0, 1070.0, 673.0)
TRACE   2018-06-30 10:11:56,406 190216  com.bas.basplc.ui.editors.ladder_editor.figures.RungFigure  [main]  Paint rung 0, bounds Rectangle(3.0, 3.0, 1200.0, 384.0), clip Rectangle(3.0, 3.0, 1067.0, 384.0)
TRACE   2018-06-30 10:11:56,407 190217  com.bas.basplc.ui.editors.ladder_editor.figures.RungFigure  [main]  Adjusted bounds Rectangle(63.0, 3.0, 1078.0, 384.0)

拇指滚动之前: enter image description here

拇指滚动后: enter image description here

1 个答案:

答案 0 :(得分:0)

解决了!我正在使用SimpleRootEditPart,视口,LayeredPane,Layer,AbstractLayout。切换到这些格式的自由格式后,我现在可以清晰滚动了。