X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=net.mograsim.logic.ui%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fui%2FLogicUIRenderer.java;h=04d0f25143dde868dbc45c4b13ac244d35e13f5b;hb=e7eb7ef33104e3795a0f312623fd2b947392aea1;hp=ce204599d69725fa0c9fc87a0ac7d4037e91b826;hpb=e7193d1fb16edc79e9cc3d8adcfb71caecd8463b;p=Mograsim.git diff --git a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/LogicUIRenderer.java b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/LogicUIRenderer.java index ce204599..04d0f251 100644 --- a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/LogicUIRenderer.java +++ b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/LogicUIRenderer.java @@ -22,21 +22,33 @@ public class LogicUIRenderer public void render(GeneralGC gc, Rectangle visibleRegion) { + gc.setClipping(visibleRegion); gc.setLineWidth(.5); - model.getWires().forEach(w -> w.render(gc)); - model.getComponents().forEach(c -> drawComponent(gc, c, visibleRegion)); + model.getWires().forEach(w -> + { + Rectangle bounds = w.getBounds(); + double lw = gc.getLineWidth(); + if (visibleRegion.intersects(bounds.x - lw, bounds.y - lw, bounds.width + lw + lw, bounds.height + lw + lw)) + w.render(gc); + }); + model.getComponents().forEach(c -> renderComponent(gc, c, visibleRegion)); } - private static void drawComponent(GeneralGC gc, GUIComponent component, Rectangle visibleRegion) + private static void renderComponent(GeneralGC gc, GUIComponent component, Rectangle visibleRegion) { - component.render(gc, visibleRegion); - if (DRAW_PINS) + Rectangle bounds = component.getBounds(); + double lw = gc.getLineWidth(); + if (visibleRegion.intersects(bounds.x - lw, bounds.y - lw, bounds.width + lw + lw, bounds.height + lw + lw)) { - gc.setBackground(gc.getDevice().getSystemColor(SWT.COLOR_DARK_CYAN)); - for (Pin p : component.getPins()) + component.render(gc, visibleRegion); + if (DRAW_PINS) { - Point pos = p.getPos(); - gc.fillOval(pos.x - 1, pos.y - 1, 2, 2); + gc.setBackground(gc.getDevice().getSystemColor(SWT.COLOR_DARK_CYAN)); + for (Pin p : component.getPins()) + { + Point pos = p.getPos(); + gc.fillOval(pos.x - 1, pos.y - 1, 2, 2); + } } } }