The Green Shoes Manual 1.1.362
Built-in Methods
These methods can be used anywhere throughout Green Shoes programs.
All of these commands are unusual because you don't attach them with a dot. Every other method in this manual must be attached to an object with a dot. But these are built-in methods (also called: Kernel methods.) Which means no dot!
A common one is alert
:
alert "No dots in sight"
Compare that to the method reverse
, which isn't a Kernel method and is only available for Arrays and Strings:
Shoes.app do
para "Plaster of Paris".reverse
#=> "siraP fo retsalP"
para [:dogs, :cows, :snakes].reverse
#=> [:snakes, :cows, :dogs]
end
Most Green Shoes methods for drawing and making buttons and so on are attached to slots. See the section on Slots for more.
Built-in Constants
Green Shoes also has a handful of built-in constants which may prove useful if you are trying to sniff out what release of Green Shoes is running.
DIR is a full path of green_shoes/lib
.
COLORS is a complete list of colors available to the app.
FONTS is a complete list of fonts available to the app.
VERSION is a Green Shoes version.
Shoes.app do
para VERSION
para fg(DIR, red)
image File.join(DIR, '../static/gshoes-icon.png')
para fg(FONTS.join(', '), green)
para COLORS.map{|k, v| [k, v]}
end
Pops up a window containing a short message.
alert "I'm afraid I must interject!"
Please use alerts sparingly, as they are incredibly annoying! If you are using alerts to show messages to help you debug your program, try checking out the standard Ruby method puts
or p
methods.
If you want to make alert() thread safe, i.e. unblock main thread, use :block => false
option. If you want to change window title, use :title => a string
option.
Pops up a window and asks a question. For example, you may want to ask someone their name.
if name = ask("Please, enter your name:")
Shoes.app{para "Welcome, #{name}!"}
end
When the above script is run, the person at the computer will see a window with a blank box for entering their name. The name will then be saved in the name
variable.
Pops up a color picker window. The program will wait for a color to be picked, then gives you back a Color object. See the Color
help for some ways you can use this color.
backcolor = ask_color "Pick a background"
Shoes.app do
background backcolor
end
Pops up an "Open file..." window. It's the standard window which shows all of your folders and lets you select a file to open. Hands you back the name of the file.
filename = ask_open_file
Shoes.app do
para File.read(filename)
end
Pops up a "Save file..." window, similiar to ask_open_file
, described previously.
save_as = ask_save_file
Shoes.app do
para save_as
end
Pops up an "Open folder..." window. It's the standard window which shows all of your folders and lets you select a folder to open. Hands you back the name of the folder.
folder = ask_open_folder
Shoes.app do
para Dir.entries(folder)
end
Pops up a "Save folder..." window, similiar to ask_open_folder
, described previously.
save_to = ask_save_folder
Shoes.app do
para save_to
end
Pops up a yes-or-no question. If the person at the computer, clicks yes, you'll get back a true
. If not, you'll get back false
.
if confirm("Draw a circle?")
Shoes.app{ oval top: 0, left: 0, radius: 50 }
end
Stops your program. Call this anytime you want to suddenly call it quits.
PLEASE NOTE: If you need to use Ruby's own exit
method (like in a forked Ruby process,) call Kernel.exit
.
Loads a TrueType (or other type of font) from a file. While TrueType is supported by all platforms, your platform may support other types of fonts. Shoes uses each operating system's built-in font system to make this work.
Note: Green Shoes doesn't support font method so far.
Here's a rough idea of what fonts work on which platforms:
- Bitmap fonts (.bdf, .pcf, .snf) - Linux
- Font resource (.fon) - Windows
- Windows bitmap font file (.fnt) - Linux, Windows
- PostScript OpenType font (.otf) - Mac OS X, Linux, Windows
- Type1 multiple master (.mmm) - Windows
- Type1 font bits (.pfb) - Linux, Windows
- Type1 font metrics (.pfm) - Linux, Windows
- TrueType font (.ttf) - Mac OS X, Linux, Windows
- TrueType collection (.ttc) - Mac OS X, Linux, Windows
If the font is properly loaded, you'll get back an array of font names found in the file. Otherwise, nil
is returned if no fonts were found in the file.
Also of interest: the Shoes::FONTS
constant is a complete list of fonts available to you on this platform. You can check for a certain font by using include?
.
if Shoes::FONTS.include? "Coolvetica"
alert "Coolvetica is available on this system."
else
alert "You do not have the Coolvetica font."
end
If you have trouble with fonts showing up, make sure your app loads the font before it is used. Especially on OS X, if fonts are used before they are loaded, the font cache will tend to ignore loaded fonts.
Builds a linear gradient from two colors. For each color, you may pass in a color/rgb method or a string describing the color. The gradient(green, red)
is the same as green..red
for example. Also possible to use different kind of args like this: gradient(green, '#FA3')
Shoes.app do
oval 100, 100, 100,
fill: gradient(green, '#FA3'), angle: 45
end
Create a grayscale color from a level of darkness and, optionally, an alpha level.
Shoes.app do
nostroke
11.times do |i|
y = x = 50 + 10 * i
r = 200 - 10 * i
oval x, y, r, fill: gray(1-i*0.1)
end
end
Create a color from red, green and blue components. An alpha level (indicating transparency) can also be added, optionally.
When passing in a whole number, use values from 0 to 255.
Shoes.app do
blueviolet = rgb(138, 43, 226, 0.5)
darkgreen = rgb(0, 100, 0, 0.5)
oval 100, 100, 100,
fill: [blueviolet, darkgreen].sample(1)
end
Or, use a decimal number from 0.0 to 1.0.
Shoes.app do
blueviolet = rgb(0.54, 0.17, 0.89)
darkgreen = rgb(0, 0.4, 0)
oval 100, 100, 100,
fill: [blueviolet, darkgreen].sample(1)
end
Next: The App Object