Skip to content

Commit

Permalink
added image player. sized incompatiable production alert. tweaked san…
Browse files Browse the repository at this point in the history
…dbox scenes
  • Loading branch information
slagyr committed Dec 31, 2011
1 parent fd0da59 commit c0b5460
Show file tree
Hide file tree
Showing 11 changed files with 164 additions and 43 deletions.
6 changes: 3 additions & 3 deletions productions/examples/sandbox/images_scene/props.rb
Expand Up @@ -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:"
Expand All @@ -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
3 changes: 1 addition & 2 deletions productions/examples/sandbox/stages.rb
Expand Up @@ -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
3 changes: 2 additions & 1 deletion productions/utilities/incompatibleVersion/styles.xml
Expand Up @@ -3,6 +3,7 @@
secondary_background_color="#8fc927"
gradient="on"
gradient_angle="270"
padding="20"/>
padding="20"
height="auto"/>
</styles>

3 changes: 3 additions & 0 deletions resources/limelight/builtin/players/image.xml
@@ -0,0 +1,3 @@
<player class="limelight.builtin.players.Image">
<onCast>install</onCast>
</player>
2 changes: 1 addition & 1 deletion ruby/ruby.iml
Expand Up @@ -33,8 +33,8 @@
<orderEntry type="library" scope="PROVIDED" name="rspec-core (v2.7.1, RVM: jruby-1.6.5 [global]) [gem]" level="application" />
<orderEntry type="library" scope="PROVIDED" name="rspec-expectations (v2.7.0, RVM: jruby-1.6.5 [global]) [gem]" level="application" />
<orderEntry type="library" scope="PROVIDED" name="diff-lcs (v1.1.3, RVM: jruby-1.6.5 [global]) [gem]" level="application" />
<orderEntry type="library" scope="PROVIDED" name="rspec (v2.7.0, RVM: jruby-1.6.5 [global]) [gem]" level="application" />
<orderEntry type="library" scope="PROVIDED" name="rspec-mocks (v2.7.0, RVM: jruby-1.6.5 [global]) [gem]" level="application" />
<orderEntry type="library" scope="PROVIDED" name="rspec (v2.7.0, RVM: jruby-1.6.5 [global]) [gem]" level="application" />
</component>
</module>

59 changes: 59 additions & 0 deletions 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);
}
}
24 changes: 12 additions & 12 deletions src/limelight/ui/model/ImagePanel.java
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -155,7 +155,7 @@ public void setRotation(double angle)
{
rotation = angle;
markAsDirty();
((PanelBase) getParent()).markAsDirty();
getParent().markAsDirty();
markAsNeedingLayout();
doPropagateSizeChangeUp(getParent());
}
Expand All @@ -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()
Expand All @@ -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 = "<data>";
filename = "[DATA]";

markAsNeedingLayout();
getParent().markAsNeedingLayout();
Expand Down
14 changes: 6 additions & 8 deletions src/limelight/ui/model/PanelBase.java
Expand Up @@ -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()
Expand All @@ -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);
Expand Down
61 changes: 61 additions & 0 deletions 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());
}
}

18 changes: 9 additions & 9 deletions test/limelight/ui/model/ImagePanelLayoutTest.java
Expand Up @@ -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());
Expand All @@ -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);
Expand All @@ -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();
Expand All @@ -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);
Expand All @@ -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();

Expand All @@ -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");
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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");
Expand Down

0 comments on commit c0b5460

Please sign in to comment.