Sophie

Sophie

distrib > Fedora > 14 > x86_64 > media > updates > by-pkgid > cd38b09e3cb8d6c675b02d30393e68af > files > 58

kaya-doc-0.5.2-8.fc14.noarch.rpm

/** webimages example (copyright 2006 Chris Morris)
 * This example demonstrates how to use a webprog to return HTML
 * and PNG images from the same application, using a customised
 * displayPage() function.
 */

webapp webimages;

import Image;
import Webapp;
import HTMLDocument;

data WebReturn = HTML(HTMLDocument h) | PNGimage(WebImage p);

WebReturn webmain() {
    return runHandler(@noImage);
}

"Default function to generate form"
WebReturn noImage() {
    doc = HTMLDocument::new(HTML4Strict,"Image testing");
    // make a new document and add a couple of paragraphs
    p = addParagraph(doc.body);
    url = localControlURL(@testfn,[150,100,25]);
    link = appendInlineElement(p,Hyperlink(url),"Dark orange");
    p2 = addParagraph(doc.body);
    url = localControlURL(@testfn,[80,200,200]);
    link = appendInlineElement(p2,Hyperlink(url),"Light blue");
    return HTML(doc);
}

"Make a very simple square image using the GD library"
WebReturn testfn([Int] colours) {
    i = create(200,200);
    bg = makeColour(i,colours[0],colours[1],colours[2]);
    return PNGimage(webPNG(i,[]));
}

"This function just calls the appropriate displayPage function for the
data type, using Kaya's function overloading features."
Void displayPage(WebReturn web) {
  case web of {
    HTML(h) -> displayPage(h);
    | PNGimage(p) -> displayPage(p);
  }
}