From c0b54603db216c400e9bc1a7c77745c9a0c3503b Mon Sep 17 00:00:00 2001 From: Micah Date: Sat, 31 Dec 2011 17:34:58 +0100 Subject: [PATCH] added image player. sized incompatiable production alert. tweaked sandbox scenes --- .../examples/sandbox/images_scene/props.rb | 6 +- productions/examples/sandbox/stages.rb | 3 +- .../utilities/incompatibleVersion/styles.xml | 3 +- resources/limelight/builtin/players/image.xml | 3 + ruby/ruby.iml | 2 +- src/limelight/builtin/players/Image.java | 59 ++++++++++++++++++ src/limelight/ui/model/ImagePanel.java | 24 ++++---- src/limelight/ui/model/PanelBase.java | 14 ++--- test/limelight/builtin/players/ImageTest.java | 61 +++++++++++++++++++ .../ui/model/ImagePanelLayoutTest.java | 18 +++--- test/limelight/ui/model/ImagePanelTest.java | 14 ++--- 11 files changed, 164 insertions(+), 43 deletions(-) create mode 100644 resources/limelight/builtin/players/image.xml create mode 100644 src/limelight/builtin/players/Image.java create mode 100644 test/limelight/builtin/players/ImageTest.java diff --git a/productions/examples/sandbox/images_scene/props.rb b/productions/examples/sandbox/images_scene/props.rb index 4c209a5e..1ef0c2da 100644 --- a/productions/examples/sandbox/images_scene/props.rb +++ b/productions/examples/sandbox/images_scene/props.rb @@ -15,11 +15,11 @@ end setting do label :text => "Scaled:", :width => "100%" - input :players => "check_box", :checked => true, :id => "scaled_checkbox", :on_button_pushed => "scene.find('logo').scaled = checked?" + input :players => "check_box", :checked => true, :id => "scaled_checkbox", :on_button_pushed => "scene.find('logo').stagehands['image'].scaled = stagehands['check-box'].checked?" end setting do label :text => "Rotation:" - input :players => "text_box", :text => "0", :id => "rotation_input", :on_focus_lost => "scene.find('logo').rotation = text.to_f" + input :players => "text_box", :text => "0", :id => "rotation_input", :on_focus_lost => "scene.find('logo').stagehands['image'].rotation = text.to_f" end setting do label :text => "Horizontal Align:" @@ -31,6 +31,6 @@ end end image_area do - logo :id => "logo", :players => "image", :image => "images/logo.png" + logo :id => "logo", :players => "image", :filename => "images/logo.png" end end diff --git a/productions/examples/sandbox/stages.rb b/productions/examples/sandbox/stages.rb index 7d3527ae..0e431522 100644 --- a/productions/examples/sandbox/stages.rb +++ b/productions/examples/sandbox/stages.rb @@ -2,8 +2,7 @@ #- Limelight and all included source files are distributed under terms of the GNU LGPL. stage "Limelight Sandbox" do -# default_scene "click_me" - default_scene "scrolling" + default_scene "click_me" size [900, 900] location :center, :center end \ No newline at end of file diff --git a/productions/utilities/incompatibleVersion/styles.xml b/productions/utilities/incompatibleVersion/styles.xml index 3c51d298..df6b2281 100644 --- a/productions/utilities/incompatibleVersion/styles.xml +++ b/productions/utilities/incompatibleVersion/styles.xml @@ -3,6 +3,7 @@ secondary_background_color="#8fc927" gradient="on" gradient_angle="270" - padding="20"/> + padding="20" + height="auto"/> diff --git a/resources/limelight/builtin/players/image.xml b/resources/limelight/builtin/players/image.xml new file mode 100644 index 00000000..11eca99e --- /dev/null +++ b/resources/limelight/builtin/players/image.xml @@ -0,0 +1,3 @@ + + install + \ No newline at end of file diff --git a/ruby/ruby.iml b/ruby/ruby.iml index af9d63f4..b6690b11 100644 --- a/ruby/ruby.iml +++ b/ruby/ruby.iml @@ -33,8 +33,8 @@ - + diff --git a/src/limelight/builtin/players/Image.java b/src/limelight/builtin/players/Image.java new file mode 100644 index 00000000..a1756a9f --- /dev/null +++ b/src/limelight/builtin/players/Image.java @@ -0,0 +1,59 @@ +package limelight.builtin.players; + +import limelight.ui.events.panel.PanelEvent; +import limelight.ui.model.ImagePanel; +import limelight.ui.model.PropPanel; + +public class Image +{ + private PropPanel propPanel; + private ImagePanel imagePanel; + + public void install(PanelEvent event) + { + imagePanel = new ImagePanel(); + propPanel = (PropPanel) event.getRecipient(); + propPanel.add(imagePanel); + propPanel.getStagehands().put("image", this); + } + + public PropPanel getPropPanel() + { + return propPanel; + } + + public ImagePanel getImagePanel() + { + return imagePanel; + } + + public void setFilename(String path) + { + imagePanel.setFilename(path); + } + + public String getFilename() + { + return imagePanel.getFilename(); + } + + public void setRotation(double angle) + { + imagePanel.setRotation(angle); + } + + public double getRotation() + { + return imagePanel.getRotation(); + } + + public boolean isScaled() + { + return imagePanel.isScaled(); + } + + public void setScaled(boolean value) + { + imagePanel.setScaled(value); + } +} diff --git a/src/limelight/ui/model/ImagePanel.java b/src/limelight/ui/model/ImagePanel.java index 5903b20a..c8de867c 100644 --- a/src/limelight/ui/model/ImagePanel.java +++ b/src/limelight/ui/model/ImagePanel.java @@ -16,7 +16,7 @@ public class ImagePanel extends PanelBase { private double rotation; - private String imageFile; + private String filename; private Image image; private AffineTransform transform; private double rotatedWidth; @@ -125,20 +125,20 @@ private void applyScaling() public Image getImage() { - if(image == null && imageFile != null && imageFile.trim().length() > 0) + if(image == null && filename != null && filename.trim().length() > 0) { try { Scene rootPanel = getRoot(); - if(rootPanel != null && imageFile != null) + if(rootPanel != null && filename != null) { ImageCache imageCache = rootPanel.getImageCache(); - setImage(imageCache.getImage(imageFile)); + setImage(imageCache.getImage(filename)); } } catch(Exception e) { - throw new LimelightException("Could not load image: " + imageFile + " (" + e.toString() + ")"); + throw new LimelightException("Could not load image: " + filename + " (" + e.toString() + ")"); } } return image; @@ -155,7 +155,7 @@ public void setRotation(double angle) { rotation = angle; markAsDirty(); - ((PanelBase) getParent()).markAsDirty(); + getParent().markAsDirty(); markAsNeedingLayout(); doPropagateSizeChangeUp(getParent()); } @@ -165,14 +165,14 @@ public double getRotation() return rotation; } - public void setImageFile(String filePath) + public void setFilename(String filePath) { - imageFile = filePath; + filename = filePath; } - public String getImageFile() + public String getFilename() { - return imageFile; + return filename; } public boolean isScaled() @@ -187,11 +187,11 @@ public void setScaled(boolean b) getParent().markAsNeedingLayout(); } - public void setImageData(byte[] bytes) throws Exception + public void setData(byte[] bytes) throws Exception { ImageInputStream imageInput = new MemoryCacheImageInputStream(new ByteArrayInputStream(bytes)); setImage(ImageIO.read(imageInput)); - imageFile = ""; + filename = "[DATA]"; markAsNeedingLayout(); getParent().markAsNeedingLayout(); diff --git a/src/limelight/ui/model/PanelBase.java b/src/limelight/ui/model/PanelBase.java index bc85ac6c..77b8119e 100644 --- a/src/limelight/ui/model/PanelBase.java +++ b/src/limelight/ui/model/PanelBase.java @@ -228,16 +228,14 @@ public boolean canBeBuffered() public synchronized void markAsNeedingLayout(Layout layout) { - if(getRoot() != null) + if(neededLayout == null) { - if(neededLayout == null) - { - neededLayout = layout; // Set first... race conditions otherwise. + neededLayout = layout; // Set first... race conditions otherwise. + if(getRoot() != null) getRoot().addPanelNeedingLayout(this); - } - else if(layout.overides(neededLayout)) - neededLayout = layout; } + else if(layout.overides(neededLayout)) + neededLayout = layout; } public void markAsNeedingLayout() @@ -250,7 +248,7 @@ public boolean needsLayout() return neededLayout != null; } - //TODO This is a little inefficient. Reconsider what get's passed to props. + //TODO This is a little inefficient. Reconsider what gets passed to props. protected MouseEvent translatedEvent(MouseEvent e) { e = new MouseEvent(e.getComponent(), e.getID(), e.getWhen(), e.getModifiers(), e.getX(), e.getY(), e.getClickCount(), false); diff --git a/test/limelight/builtin/players/ImageTest.java b/test/limelight/builtin/players/ImageTest.java new file mode 100644 index 00000000..c685162a --- /dev/null +++ b/test/limelight/builtin/players/ImageTest.java @@ -0,0 +1,61 @@ +package limelight.builtin.players; + +import limelight.model.api.FakePropProxy; +import limelight.ui.events.panel.CastEvent; +import limelight.ui.model.PropPanel; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +public class ImageTest +{ + public Image image; + public PropPanel propPanel; + + @Before + public void setUp() throws Exception + { + image = new Image(); + propPanel = new PropPanel(new FakePropProxy()); + image.install(new CastEvent(propPanel)); + } + + @Test + public void installation() throws Exception + { + assertEquals(propPanel, image.getPropPanel()); + assertNotNull(image.getImagePanel()); + assertEquals(image.getImagePanel(), propPanel.getChildren().get(0)); + assertEquals(true, propPanel.isSterilized()); + assertNotNull(propPanel.getStagehands().get("image")); + assertEquals(Image.class, propPanel.getStagehands().get("image").getClass()); + } + + @Test + public void settingTheImagePath() throws Exception + { + image.setFilename("foo.jpg"); + assertEquals("foo.jpg", image.getFilename()); + assertEquals("foo.jpg", image.getImagePanel().getFilename()); + } + + @Test + public void rotation() throws Exception + { + image.setRotation(123.45); + assertEquals(123.45, image.getRotation(), 0.01); + assertEquals(123.45, image.getImagePanel().getRotation(), 0.01); + } + + @Test + public void scaled() throws Exception + { + assertEquals(true, image.isScaled()); + image.setScaled(false); + assertEquals(false, image.isScaled()); + assertEquals(false, image.getImagePanel().isScaled()); + } +} + diff --git a/test/limelight/ui/model/ImagePanelLayoutTest.java b/test/limelight/ui/model/ImagePanelLayoutTest.java index 7215559d..71162813 100644 --- a/test/limelight/ui/model/ImagePanelLayoutTest.java +++ b/test/limelight/ui/model/ImagePanelLayoutTest.java @@ -46,7 +46,7 @@ public void override() throws Exception public void getDimensionsWhenAuto() throws Exception { final String filePath = TestUtil.DATA_DIR + "/star.gif"; - panel.setImageFile(filePath); + panel.setFilename(filePath); panel.doLayout(); assertEquals(200, panel.getHeight()); @@ -56,7 +56,7 @@ public void getDimensionsWhenAuto() throws Exception @Test public void getDimensionsWhenNotAuto() throws Exception { - panel.setImageFile(TestUtil.DATA_DIR + "/star.gif"); + panel.setFilename(TestUtil.DATA_DIR + "/star.gif"); parent.style.setWidth("100"); parent.style.setHeight("150"); parent.childConsumableBounds = new Box(0, 0, 100, 150); @@ -69,7 +69,7 @@ public void getDimensionsWhenNotAuto() throws Exception @Test public void getScaleTransformWhenDimensionsAreAuto() throws Exception { - panel.setImageFile(TestUtil.DATA_DIR + "/star.gif"); + panel.setFilename(TestUtil.DATA_DIR + "/star.gif"); panel.doLayout(); AffineTransform tranform = panel.getTransform(); @@ -80,7 +80,7 @@ public void getScaleTransformWhenDimensionsAreAuto() throws Exception @Test public void getScaleTransformWhenDimensionsAreNotAuto() throws Exception { - panel.setImageFile(TestUtil.DATA_DIR + "/star.gif"); + panel.setFilename(TestUtil.DATA_DIR + "/star.gif"); parent.style.setWidth("100"); parent.style.setHeight("150"); parent.childConsumableBounds = new Box(0, 0, 100, 150); @@ -94,7 +94,7 @@ public void getScaleTransformWhenDimensionsAreNotAuto() throws Exception @Test public void getRotationTransformWhenDimensionsAreAuto() throws Exception { - panel.setImageFile(TestUtil.DATA_DIR + "/star.gif"); + panel.setFilename(TestUtil.DATA_DIR + "/star.gif"); panel.setRotation(45); panel.doLayout(); @@ -108,7 +108,7 @@ public void getRotationTransformWhenDimensionsAreAuto() throws Exception @Test public void getScalleTransformWhenDimensionsAreNotAutoAndScalingIsOff() throws Exception { - panel.setImageFile(TestUtil.DATA_DIR + "/star.gif"); + panel.setFilename(TestUtil.DATA_DIR + "/star.gif"); panel.setScaled(false); parent.style.setWidth("100"); parent.style.setHeight("150"); @@ -123,7 +123,7 @@ public void getScalleTransformWhenDimensionsAreNotAutoAndScalingIsOff() throws E @Test public void hasConstrainedProportionsWhenWidthIsNotAuto() throws Exception { - panel.setImageFile(TestUtil.DATA_DIR + "/star.gif"); + panel.setFilename(TestUtil.DATA_DIR + "/star.gif"); parent.style.setWidth("100"); parent.childConsumableBounds = new Box(0, 0, 100, 200); parent.doLayout(); @@ -136,7 +136,7 @@ public void hasConstrainedProportionsWhenWidthIsNotAuto() throws Exception @Test public void hasConstrainedProportionsWhenHeightIsNotAuto() throws Exception { - panel.setImageFile(TestUtil.DATA_DIR + "/star.gif"); + panel.setFilename(TestUtil.DATA_DIR + "/star.gif"); parent.style.setHeight("100"); parent.childConsumableBounds = new Box(0, 0, 200, 100); parent.doLayout(); @@ -149,7 +149,7 @@ public void hasConstrainedProportionsWhenHeightIsNotAuto() throws Exception @Test public void sizeRemainsWhenStaticAndNotScaled() throws Exception { - panel.setImageFile(TestUtil.DATA_DIR + "/star.gif"); + panel.setFilename(TestUtil.DATA_DIR + "/star.gif"); panel.setScaled(false); parent.style.setHeight("400"); parent.style.setHeight("400"); diff --git a/test/limelight/ui/model/ImagePanelTest.java b/test/limelight/ui/model/ImagePanelTest.java index db2037a6..94376adc 100644 --- a/test/limelight/ui/model/ImagePanelTest.java +++ b/test/limelight/ui/model/ImagePanelTest.java @@ -43,8 +43,8 @@ public void setUp() throws Exception @Test public void setImageFile() throws Exception { - panel.setImageFile("blah/blah.png"); - assertEquals("blah/blah.png", panel.getImageFile()); + panel.setFilename("blah/blah.png"); + assertEquals("blah/blah.png", panel.getFilename()); } @Test @@ -100,7 +100,7 @@ private void checkSettingImageDataWith(String imageFile) throws Exception StreamReader reader = new StreamReader(TestUtil.fs.inputStream(TestUtil.dataDirPath(imageFile))); byte[] bytes = reader.readBytes(100000); - panel.setImageData(bytes); + panel.setData(bytes); assertEquals(200, panel.getImage().getHeight(null)); assertEquals(200, panel.getImage().getWidth(null)); @@ -109,7 +109,7 @@ private void checkSettingImageDataWith(String imageFile) throws Exception @Test public void settingImageDataUpdatesInfo() throws Exception { - panel.setImageFile(TestUtil.dataDirPath("small_star.gif")); + panel.setFilename(TestUtil.dataDirPath("small_star.gif")); panel.getImage(); panel.resetLayout(); parent.resetLayout(); @@ -118,7 +118,7 @@ public void settingImageDataUpdatesInfo() throws Exception assertEquals(200, panel.getImageWidth(), 0.1); assertEquals(200, panel.getImageHeight(), 0.1); - assertEquals("", panel.getImageFile()); + assertEquals("[DATA]", panel.getFilename()); assertEquals(true, panel.needsLayout()); assertEquals(true, parent.needsLayout()); } @@ -126,10 +126,10 @@ public void settingImageDataUpdatesInfo() throws Exception @Test public void doesntCrashWhenNoImageFileProvided() throws Exception { - panel.setImageFile(null); + panel.setFilename(null); assertEquals(null, panel.getImage()); - panel.setImageFile(""); + panel.setFilename(""); assertEquals(null, panel.getImage()); } }