Permalink
Browse files

Improved image method. Now it can download a image file directly off …

…the web.
  • Loading branch information...
1 parent f45e5d1 commit c7841bc1ccbf98225d196a473c25dbf6ba003c65 @ashbb committed Apr 28, 2012
Showing with 25 additions and 9 deletions.
  1. +1 −1 VERSION
  2. +16 −2 lib/shoes/app.rb
  3. +3 −2 purple_shoes.gemspec
  4. BIN static/downloading.png
  5. +5 −4 static/manual-en.txt
View
@@ -1 +1 @@
-0.0.147
+0.5.148
View
@@ -133,11 +133,25 @@ def inscription *msg; textblock Para, 10, *msg; end
def image name, args={}, &blk
args = basic_attributes args
args[:rotate] ||= rotate
+ if name =~ /^(http|https):\/\//
+ tmpname = File.join(Dir.tmpdir, "__purple_shoes_#{Time.now.to_f}.png")
+ url, name = name, File.join(DIR, '../static/downloading.png')
+ end
img = Swt::Image.new Shoes.display, name
args[:full_width], args[:full_height] = img.getImageData.width, img.getImageData.height
args[:real], args[:app] = img, self
Image.new(args).tap do |s|
+ download url, save: tmpname do
+ tmp = Swt::Image.new Shoes.display, tmpname
+ s.real = tmp
+ s.full_width, s.full_height = tmp.getImageData.width, tmp.getImageData.height
+ if s.initials[:width].zero? and s.initials[:height].zero?
+ s.width, s.height = s.full_width, s.full_height
+ end
+ File.delete tmpname
+ end if url
+
pl = Swt::PaintListener.new
s.pl = pl
class << pl; self end.
@@ -148,11 +162,11 @@ class << pl; self end.
unless s.hided
Shoes.set_rotate e.gc, *s.rotate do
if s.initials[:width].zero? and s.initials[:height].zero?
- gc.drawImage img, s.left, s.top
+ gc.drawImage s.real, s.left, s.top
else
s.width = s.full_width if s.width.zero?
s.height = s.full_height if s.height.zero?
- gc.drawImage img, 0, 0, s.full_width, s.full_height, s.left, s.top, s.width, s.height
+ gc.drawImage s.real, 0, 0, s.full_width, s.full_height, s.left, s.top, s.width, s.height
end
end
end
@@ -5,11 +5,11 @@
Gem::Specification.new do |s|
s.name = "purple_shoes"
- s.version = "0.0.147"
+ s.version = "0.5.148"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["ashbb"]
- s.date = "2012-04-27"
+ s.date = "2012-04-28"
s.description = "Purple Shoes is one of colorful Shoes, written in JRuby and SWT."
s.email = "ashbbb@gmail.com"
s.executables = ["pshoes"]
@@ -206,6 +206,7 @@ Gem::Specification.new do |s|
"snapshots/sample99.png",
"static/code_highlighter.js",
"static/code_highlighter_ruby.js",
+ "static/downloading.png",
"static/man-editor-notepad.png",
"static/man-editor-osx.png",
"static/man-ele-background.png",
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -3339,7 +3339,7 @@ You can use web URLs directly as well.
{{{
#!ruby
Shoes.app do
- image "http://is.gd/c0mBtb"
+ image "http://is.gd/GVAGF7"
end
}}}
@@ -3383,10 +3383,11 @@ Rotates the Image element by a certain number of `degrees`.
{{{
Shoes.app do
- img = image File.join(DIR, '../samples/cy.png')
- img.move 200, 200
+ g = image File.join(DIR, '../samples/cy.png')
+ g.move 200, 200
animate do |i|
- img.rotate i*10
+ g.rotate =
+ [i*10, g.left+g.width/2, g.top+g.height/2]
end
end
}}}

0 comments on commit c7841bc

Please sign in to comment.