The VIEW object

The view structure is used for all visible objects. When we need to show something on the screen we use this structure, that also inherits functions/variables from the t_object structure. When we need to draw a window to the screen f.e., we need to make a view structure with the view_init() function and then set draw() function to new drawing function that show window. For drawing all functions from Allegro are used, but for text output you should use Seals own functions.


view_init ()
     Description:
       This function initialize a new view and sets some important values. 
       All objects that inherit functions/variables from the t_view, such  
       as t_window, t_button, t_textline etc, must use this function in  
       their initializating functions.

     Syntax:
       p_view  view_init ( p_view o, t_rect r );

     Parameters:
       o           Allocated memory to store the view in.
       r           Rectangle that defines the view.

     Returns:
       The new t_view structure.




The t_view structure

Variables
     Name:         struct t_object  obclass;

     Description:  Says that we want to inherit functions/variables from 
                   the t_object structure.



     Name:         struct t_brush  brush;

     Description:  Brush structure for background drawing. This structure 
                   is used when you use function background.



     Name:         struct t_rect  bounds;

     Description:  Local rectangular area. This origins are aligned to 
                   the owner.



     Name:         struct t_rect  clip;

     Description:  Rectangle of view, the area in which we can draw.



     Name:         BITMAP  *draw_buffer;

     Description:  Buffer of view. It's aligned to size of screen. This 
                   is returned from "begin_paint" function. 



     Name:         BITMAP  *draw_out;

     Description:  Default value is screen.



     Name:         l_int  drag_mode;

     Description:  Mode of dragging. You must set it before the first 
                   calling of drag_view function. Flags are DM_xxxx.
                   (see above)



     Name:         l_int  draw_mode;

     Description:  The mode of drawing. F.e. DWM_TESTSUBVIEWS or 
                   DWM_ONLYTOBUFFER



     Name:         l_text  info_text;

     Description:  Text that will be displayed, when cursor is over the
                   view and CTRL+F1 is pressed.



     Name:         l_int  align;

     Description:  Alignment of the view. Uses the same values as in text-
                   alignments: TX_ALIGN_xxxxx etc. Use it before inserting.



     Name:         l_font  *font;

     Description:  Font of the view's text.



     Name:         l_int  cursor;

     Description:  Cursor that will be displayed when mouse is placed over
                   the view. See the object MOUSE for available values.



     Name:         l_color  *palette;

     Description:  Palette of the view. To get colors in palette use function 
                   "o->get_color(o, index);". Set the palette before first
                   calling of draw function.




Functions

drag_view ()
     Description:
       Drags a view and moves it or changes its area. 

     Syntax:
       void  (*drag_view) ( p_view o, l_word mode, t_event *event );

     Parameters:
       o           View to move or resize.
       mode        Can be one of the DM_xxx modes. You must set the
                   drag_mode flags of "o" to same flags as "mode". 
                   F.e. if you want to move window, you must first in 
                   the init function set drag_mode "|= DM_DRAGMOVE;" 
                   and then you can use this function by DM_DRAGMOVE 
                   argument.
       event       The event to occur when dragging.

     Returns:
       -



size_minimum ()
     Description:
       Gets the miminum size of a view.

     Syntax:
       t_point (*size_minimum) ( p_view o );

     Parameters:
       o           The view to check.

     Returns:
       A point structure where p.x is minimum width
       and p.y is the minimum height.



draw ()
     Description:
       Virtual functions for drawing. You must preceed all drawing with:
       "BITMAP *out = o->begin_paint(o, &p, o->get_local_extent(o));"
       where "&p" is a pointer to a t_point structure that contains the
       global position from left,top corner in buffer screen.

       Then you can use the Allegro functions, such as:
         if ( out ) {
             rectfill(out, p.x, p.y, p.x+100, p.y+100);
         };

       All Allegro functions must end with:
         o->end_of_paint(o, ,,same as begin_paint 3rd argument");

     Syntax:
       void  (*draw) ( p_view o );

     Parameters:
       p_view      View to draw in.

     Returns:
       -



draw_view ()
     Description:
       Main function for object redrawing. If you want to redraw an 
       object by it's sub-objects, please call this function.

     Syntax:
       void  (*draw_view) ( p_view o );

     Parameters:
       o           Object to redraw.

     Returns:
       -



draw_sub_views ()
     Description:
       Draws all sub-objects of an object.

     Syntax:
       void  (*draw_sub_views) ( p_view o, p_view from, p_view to );

     Parameters:
       o           Objects to draw views in.
       from        Sub-object to start from.
       to          Sub-object to end with.

     Returns:
       -



begin_paint ()
     Description:
       This function must be placed before all Allegro's drawing functions.

     Syntax:
       BITMAP* (*begin_paint) ( p_view o, t_point *p, t_rect rwhere );

     Parameters:
       o           The object to draw on.
       p           Pointer to a t_point structure containing the origin
                   of the view from the top left corner of the screen.
       rwhere      The rectangle in which we want to draw. Something that
                   clips. This must have the same area as in the
                   end_of_paint() function.

     Returns:
       The BITMAP where the object will be drawn. This is used when
       calling Allegro's functions.



end_of_paint ()
     Description:
       Must be called after using Allegro's functions.

     Syntax:
       void  (*end_of_paint) ( p_view o, t_rect rwhere );

     Parameters:
       o           The object to draw on.
       rwhere      The rectangle in which we want to draw. Something that
                   clips. This must have the same area as in the
                   begin_paint() function.

     Returns:
       -



draw_in_rect ()
     Description:
       Draws a view in a rectangle.

     Syntax:
       void  (*draw_in_rect) ( p_view o, t_rect r );

     Parameters:
       o           The view to draw.
       r           Rectangle to draw in.

     Returns:
       -



draw_me ()
     Description:
       Draws the object WITHOUT drawing the sub-objects.

     Syntax:
       void  (*draw_me) ( p_view o );

     Parameters:
       o           The object to draw.

     Returns:
       -



get_local_extent ()
     Description:
       Gets width and height of an object.

     Syntax:
       t_rect  (*get_local_extent) ( p_view o );

     Parameters:
       o           The object to measure.

     Returns:
       A t_rect containing (0, 0, width, height).  



get_global_bounds ()
     Description:
       Get the global bounds of a rectangle.

     Syntax:
       t_rect  (*get_global_bounds) ( p_view o, t_rect r );

     Parameters:
       o           The object containing the rectangle.
       r           The rectangle to check.

     Returns:
       A t_rect structure containing the bounds.



show ()
     Description:
       Shows a view.

     Syntax:
       void  (*show) ( p_view o );

     Parameters:
       o           The view to show.

     Returns:
       -



hide ()
     Description:
       Hides a view.

     Syntax:
       void  (*hide) ( p_view o );

     Parameters:
       o           The view to hide.

     Returns:
       -



set_draw_mode ()
     Description:
       Sets flags of an object's "draw_mode" variable.

     Syntax:
       void  (*set_draw_mode) ( p_view o, l_int dm, l_bool set );

     Parameters:
       o           Object who's variable to set.
       dm          Flags to set.
       set         The flags are only set if "set" is set to True.

     Returns:
       



is_draw_mode ()
     Description:
       Checks if a "draw_mode" variable contains flags.

     Syntax:
       l_bool  (*is_draw_mode) ( p_view o, l_int dm );

     Parameters:
       o           The object who's variable to check.
       dm          The flags to check for.

     Returns:
       True if flags are found. False otherwise.



size_limits ()
     Description:
       Gets the limits of an object.

     Syntax:
       t_rect  (*size_limits) ( p_view o );

     Parameters:
       o           The view who's limits to check.

     Returns:
       A t_rect structure containing the limits.



change_bounds ()
     Description:
       Changes the bounds of an object.

     Syntax:
       void  (*change_bounds) ( p_view o, t_rect nr );

     Parameters:
       o           Object to modify.
       nr          The new bounds.

     Returns:
       -



background ()
     Description:
       Draws the background of an object.

     Syntax:
       void  (*background) ( p_view o, t_rect r );

     Parameters:
       o           The object who's background to draw.
       r           The rectangle to draw in.

     Returns:
       -




Available flags

Options settings:

     Syntax:       #define VW_OF_VISIBILITY    0x0000020

     Description:  The object can be visible at the beginning, when 
                   object is inserted to other object.



     Syntax:       #define VW_OF_IGNORELIM     0x0000040

     Description:  Ignores owner's limits.



Drag mode settings:

     Syntax:       #define DM_DRAGMOVE         0x0000001

     Description:  With this flag set makes it possible to drag and  
                   move the object.



     Syntax:       #define DM_DRAGGROW         0x0000002

     Description:  With this flag set makes it possible to drag and 
                   resize the object.



Draw mode settings:

     Syntax:       #define DWM_TESTSUBVIEWS    0x0000001

     Description:  Test sub views in Draw function.



     Syntax:       #define DWM_ONLYTOBUFFER    0x0000002

     Description:  Draw only to buffer.



     Syntax:       #define DWM_ONLYTOSCREEN    0x0000004

     Description:  Draw only to screen.



Brush states:

     Syntax:       #define BRUSH_STRETCH       0x0000001

     Description:  Background is stretched.



     Syntax:       #define BRUSH_SELFIMG       0x0000002 

     Description:  Image was created for this brush only. When object 
                   is disposed, memory for the image is also freed.



     Syntax:       #define BRUSH_GRADIENT      0x0000004 

     Description:  Color is gradient to color2. 



     Syntax:       #define BRUSH_GRADIENT_HOR  0x0000008 

     Description:  If this bits are set, gradient is horizontal. Otherwise 
                   the gradient is vertical.




The t_brush structure


     Name:         l_long  state;

     Description:  Flags of background drawing. f.e. BRUSH_STRETCH...



     Name:         l_color    color;

     Description:  Color of background. Is ignored, if background is set.



     Name:         BITMAP    *background;

     Description:  Image of the background.



     Name:         l_color    color2;

     Description:  Second color to what will be gradient, when state
                   is set to BRUSH_GRADIENT.



     Name:         l_char     reserved[22];

     Description:  Reserved for future versions.




Example:

An example of a draw function:

     void   my_draw ( p_view o )
     {

       /* return {0, 0, rect_sizex(o->bounds), rect_sizey(o->bounds)}*/
       t_rect  r = o->get_local_extent(o); 
       t_point p;

       BITMAP *out = o->begin_paint(o, &p, r);

       if ( out ) {

         o->background(o, out, rect_move(r, p.x, p.y));
    
         button(out, p.x+r.a.x, p.y+r.a.y, p.x+r.b.x, p.y+r.b.y, 
                COLOR(CO_BLACK), COLOR(CO_WHITE));

       };

       o->end_of_paint(o, r);
     };


     p_view v = view_init(malloc(sizeof(t_view)), r);
     v->draw = &my_draw;
     OBJECT(desktop)->insert(OBJECT(desktop), OBJECT(v));