resizer.anubis 3.33 KB

   
   
                             The Anubis/Paradize Project.
   
                                 The resizer widget. 
   
                        Copyright (c) Alain Prouté 2004-2005. 

   
   Authors:   Alain Prouté

   
read widget.anubis   
read tools.anubis   


   This file defines  the 'resizer' widget. This  widget appears as a small  square with 4
   arrows pointing to top-left, top-right bottom-left and bottom-right. When left clicked,
   it captures the mouse, and while the mouse is captured it adds the coordinates of mouse
   movements to  two variables given at its  creation.  Of course, these  variables may be
   monitored  by other  widgets (like  windows or  scrollbars for  example), and  this may
   produce various effects, like 'resizing'.
   
public define Widget
   create_resizer
     (
       WidgetParameters         parameters, 
       Var(Int32)               x_v,            // variable controled by the resizer
       Var(Int32)               y_v,            // idem
       Var(Int32)               w_v             // width of resizer (pixels)
     ). 
   
   
   
   --- That's all for the public part ! --------------------------------------------------
   

   
   
define (KeyboardState ks, WidgetMouseCapturedEvent e) -> WidgetAnswer
   captured_handler
     (
       Var(Int32)    x_v,     // controled variables
       Var(Int32)    y_v,  
       Var(Int32)   mx_v,     // last known position of mouse
       Var(Int32)   my_v
     ) =
   (KeyboardState ks, WidgetMouseCapturedEvent e) |->
   with xe = x(e), ye = y(e), 
   x_v <- *x_v + (xe - *mx_v);
   mx_v <- xe;
   y_v <- *y_v + (ye - *my_v); 
   my_v <- ye;
   handled([]).  
   
   
   
public define Widget   
   create_resizer
     (
       WidgetParameters         parms, 
       Var(Int32)               x_v,            // variable controled by the resizer
       Var(Int32)               y_v,            // idem
       Var(Int32)               w_v             // width of resizer (pixels)
     ) =
   create_widget(
   
   /* set childs positions */ 
   (WidgetPositionToolBox ptb) |-> unique, 
   
   /* get size */ 
   (One u) |-> (*w_v,*w_v), 
   
   /* redraw */ 
   (WidgetDrawToolBox dtb) |-> 
      draw_relief_area(dtb,1,rect(0,0,*w_v,*w_v),
                       *main_color_v(parms),
                       *light_color_v(parms),
                       *dark_color_v(parms)),
      
   /* Duplicate */ 
   (One u) |-> create_resizer(parms,x_v,y_v,w_v), 
   
   /* Change size */ 
   (Int32 w, Int32 h) |-> alert, 
   
   /* event handling */ 
   (WidgetEventToolBox etb, WidgetNormalEvent e) |-> 
      if e is 
        {
          mouse_gone             then not_handled([]),
          mouse_move(ks,x,y)     then not_handled([]),
          mouse_click(ks,mc,x,y) then 
            if mc is 
              {
                left_down    then
                  forget(capture_mouse(etb,captured_handler(x_v,y_v,
                                                            var((Int32)x),var((Int32)y))));
                  handled([]), 
   
                left_up      then not_handled([]),
                middle_down  then not_handled([]),
                middle_up    then not_handled([]),
                right_down   then not_handled([]),
                right_up     then not_handled([]),
              }
        },
   
   /* monitoring */ 
   [ ]
   ).