Added a test launch config
[Mograsim.git] / plugins / net.mograsim.plugin.core / src / net / mograsim / plugin / util / ImageDescriptorWithMargins.java
diff --git a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/util/ImageDescriptorWithMargins.java b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/util/ImageDescriptorWithMargins.java
new file mode 100644 (file)
index 0000000..a664b09
--- /dev/null
@@ -0,0 +1,37 @@
+package net.mograsim.plugin.util;
+
+import org.eclipse.jface.resource.CompositeImageDescriptor;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.swt.graphics.Point;
+
+public class ImageDescriptorWithMargins extends CompositeImageDescriptor
+{
+       private final ImageDescriptor input;
+       private final Point size;
+       private final int ox, oy;
+
+       public ImageDescriptorWithMargins(ImageDescriptor input, Point size)
+       {
+               this(input, 0, 0, size);
+       }
+
+       public ImageDescriptorWithMargins(ImageDescriptor input, int offX, int offY, Point size)
+       {
+               this.input = input;
+               this.size = size;
+               this.ox = offX;
+               this.oy = offY;
+       }
+
+       @Override
+       protected Point getSize()
+       {
+               return size;
+       }
+
+       @Override
+       protected void drawCompositeImage(int width, int height)
+       {
+               drawImage(input::getImageData, ox, oy);
+       }
+}
\ No newline at end of file