desktop_example.anubis 5.03 KB

   
   
   
   An example using 'desktop.anubis'. 

   
read tools/basis.anubis   

   
read host_window.anubis   
read widget.anubis   
read tools.anubis
read image.anubis   
read box.anubis   
read table.anubis   
read text.anubis   
read button.anubis   
read desktop.anubis   
read menu_manager.anubis   
read menus.anubis   
read window.anubis   
   
read tartan_generator.anubis
   
   
define HostImage
   default_image
     =
   print("making a tartan\n"); 
   to_host_image(make_tartan_image(150,100),1). 
   
define HostImage
   load_image
     (
       String name
     ) =
   with path = anubis_directory+"library/examples/graphism/image_samples/"+name+".jpg", 
   if read_image_from_JPEG_file(path) is 
     {
       cannot_open_file then print("Cannot find file '"+name+"'.\n"); default_image,
       decompress_error then print("Cannot decompress file '"+name+"'.\n"); default_image,
       ok(jpeg_image) then to_host_image(jpeg_image,1)
     }. 
   
define Widget
   my_support
     (
       String jpg_filename
     ) =
   with path = anubis_directory+"library/examples/graphism/image_samples/"+jpg_filename, 
   if image(path) is 
     {
       failure then print("Cannot find file: "+path+"\n"); image(default_image), 
       success(w) then w
     }.
  
   
   
 define Widget
   command_button
     (
       WidgetParameters parms, 
       WidgetParameters grey_parms, 
       WidgetSupport supp, 
       String text
     ) =
   create_button
     (
       100,25,
       push_down(grey_parms), 
       (WidgetEventToolBox etb) |-> command(supp) <-
          if *command(supp) is 
            {
              hide   then show,
              show   then hide, 
              expose then should_not_happen(show), 
              delete then should_not_happen(show)
            },
   
       (One u) |-> if *command(supp) is hide
         then center_text(grey_parms,text)
         else center_text(parms,text),
   
       []
     ). 

   
 define MenuItem
   command_menu
     (
       String name, 
       WidgetParameters parms, 
       WidgetSupport supp, 
     ) =
   item((One u) |-> if *command(supp) is show then "* "+name else "    "+name, 
     (WidgetEventToolBox etb) |-> command(supp) <-
     if *command(supp) is 
       {
         hide then show, 
         show then hide,
         expose then should_not_happen(show), 
         delete then should_not_happen(show)
       }).

   
 define List(MenuItem)   
   numbers_list
     (
       Var(MenuCommand) menu_command_v, 
       WidgetParameters parms,
       Word32 n
     ) =
   if n =< 0 then [] else
   with action = (WidgetEventToolBox etb) |-> print("You choosed "+n+"\n");
                    menu_command_v <- clear, 
   if n (mod 10) = 0
   then [separator,
         item(integer_to_string(n),action) 
          . numbers_list(menu_command_v,parms,n-1)]
   else [item(integer_to_string(n),action) 
          . numbers_list(menu_command_v,parms,n-1)].
   
   
define WidgetSupport
   window_image
     (
       Word32 x, Word32 y, 
       Word32 w, Word32 h, 
       String name
     ) =
   support(x,y,create_box(relief_rgb(rgb(128,128,128)),10,
                        window(rgb(128,128,128),var(w),var(h),
                      my_support(name+".jpg"),resizable,both,(One _) |-> rgb(0,0,0))),var(show)). 
   
   
define Widget
  exit_widget
  (
    SystemFont            font
  ) =
  button
  (
    (One u) |-> push_down(100,20,center_text("Exit",font,rgb(255,0,0)),rgb(200,200,200)), 
    (One u) |-> blocking, 
    (WidgetEventToolBox etb) |-> close_host_window(etb), 
    [ ]
  ).
   
global define One
   desktop_example
     (
       List(String) args 
     ) =   
   with font_name = "helvetica_bold_r_12", 
   if load_system_font(font_name) is 
   {
     failure then print("Cannot load system font '"+font_name+"'.\n"), 
     success(font) then 
       if screen_size is (sw,sh) then 
       with exit = exit_widget(font), 
       with suppexit  = if size(exit) is (ew,eh) then 
                        support(0,   sh-eh, exit,                      var(show)), 
       with support2  = support(150, 300,   my_support("cows.jpg"),    var(show)),
       with support2a = support(150, 300,   my_support("fingers.jpg"), var(show)),
       with support2b = support(150, 300,   my_support("farm.jpg"),    var(show)),
       with support3  = support(10,  100,   my_support("mountain.jpg"),var(show)),
       with support3a = support(10,  100,   my_support("torrent.jpg"), var(show)),
       with support4  = support(200, 200,   my_support("flowers.jpg"), var(show)),
       forget(
       open_host_window(
             //transient,
             managed(resizable), 
             create_desktop(var(sw),var(sh),
                           color(rgb(100,200,0)), 
                           (One u) |-> u, 
                           [
                             suppexit, 
                             support4,support3a,support3,
                             support2b,support2a,support2
                           ],
                           var((DesktopCommand)none)),
           0,0,
           "Desktop Example (window 1)"))
   }.