REBOL [Title: ""] ; header is still required, even if a title isn't included effect-types: ["Invert" "Grayscale" "Emboss" "Blur" "Sharpen" "Flip 1x1" "Rotate 90" "Tint 83" "Contrast 66" "Luma 150" "None"] ; this creates a short list of image effects that are built ; into Rebol, and assigns the variable word "effect-types" ; to the block play-sound: func [sound-file] [ wait 0 ring: load sound-file sound-port: open sound:// insert sound-port ring wait sound-port close sound-port ] ; The line above imports the simple "play-sound" function ; created earlier in the tutorial. For this program to work ; correctly as it is, the play_sound.r file should be saved ; to C:\ image-url: to-url request-text/title/default { Enter the url of an image to use:} trim { http://rebol.com/view/demos/palms.jpg} ; ask user for the location of a new image (with a default ; location), and assign it to the word "new-image" gui: [ ; The following code displays the program menu, using a ; "choice" button widget (a menu-select type of button ; built in to Rebol). The button is 160 pixels ; across, and is placed at the uppermost, leftmost ; pixel in the GUI (0x0) using the built-in word "at". ; The action block for the button contains various ; functions to be performed, based on the selected choice ; (using conditional "if" evaluations. This could have ; been done with less code, using a "switch" syntax. ; "If" was used, however, to demonstrate that there are ; always alternate ways to express yourself in code - ; just like in spoken language.). across ; horizontally aligns all the following GUI widgets, ; so they appear next to each other in the layout ; (the default behavior in Rebol is to align elements ; vertically). space -1 ; changes the spacing of consecutive widgets so they're ; on top of each other at 20x2 choice 160 tan trim { Save Image} "View Saved Image" "Download New Image" trim { -------------} "Exit" [ if value = "Save Image" [ filename: to-file request-file/title/file/save trim { Save file as:} "Save" %/c/effectedimage.png ; request a filename to save the image as, ; defaults to "c:\effectedimage.png" save/png filename to-image picture ; save the image to hard drive ] if value = "View Saved Image" [ view-filename: to-file request-file/title/file trim { View file:} "Save" filename view/new center-face layout [image load view-filename] ; read the selected image from the hard drive ; and display it in a new GUI window ] if value = "Download New Image" [ new-image: load to-url request-text/title/default trim { Enter a new image url} trim { http://www.rebol.com/view/bay.jpg} ; ask for the location of a new image, ; and assign it to the word "new-image" picture/image: new-image ; replace the old image with the new one show picture ; update the GUI display ] if value = "-------------" [] ; don't do anything if value = "Exit" [ play-sound %/c/windows/media/tada.wav quit ; exit the program ] ] choice tan "Info" "About" [alert "Image Effector - Copyright 2005, Nick Antonaccio"] ; a simple "about" box below ; vertically aligns successive GUI widgets - ; the opposite of "across" space 5 ; spread out the widgets some more pad 2 ; put 2 pixels of blank space before the next widget box 550x1 white ; draws a line 550 pixels wide, 1 pixel tall ; (just a cosmetic separator) pad 10 ; put some more space between widgets vh1 "Double click each effect in the list on the right:" ; a big text header for the GUI return ; advances to the next row in the GUI across picture: image load image-url ; get the image entered at the beginning of the program, ; and give it a label text-list data effect-types [ current-effect: to-string value picture/effect: to-block form current-effect show picture ] ; The code above creates a text-list gui widget ; and assigns a block of actions to it, to be run whenever the ; user clicks on the list. The block of actions is indented ; and each action is placed on separate line for readability. ; The first line assigns the word "current-effect" to the value ; which the user has selected from the list. The second line ; applies that effect to the image (the words "to-block" and "form" ; are required for the way effects are applied syntactically. ; The third line displays the newly effected image. The "show" ; word is _very_ important. It needs to be used whenever a GUI ; element is updated. ] view/options center-face layout gui [no-title] ; display the gui block above ; "/options [no title]" displays the window without a title bar ; (so it can't be moved around), ; and "center-face" centers the window on the screen