abl_swim.c

来自「SHARP_ARM720T_LH79524/5软件开发包_支持TFT_LCD_N」· C语言 代码 · 共 996 行 · 第 1/2 页

C
996
字号
                      INT_32 x,
                      INT_32 y,
                      INT_32 rx,
                      INT_32 ry)
{
    INT_32 xinc, idy, xleft, xright, pixel, ydsp;

    /* For center line, limit to size of the window */
    xleft = x - rx;
    if (xleft < win->xpvmin)
    {
        xleft = win->xpvmin;
    }
    xright = x + rx;
    if (xright > win->xpvmax)
    {
        xright = win->xpvmax;
    }

    /* Draw the left and right pixels of the center line in the pen
       color */
    * (win->fb + xleft + (y * win->xpsize)) = win->pen;
    * (win->fb + xright + (y * win->xpsize)) = win->pen;
 
    /* Draw the center line first in the fill color */
    if ((y >= win->ypvmin) && (y <= win->ypvmax))
    {
        for (pixel = (xleft + 1); pixel < (xright - 1); pixel++)
        {
            * (win->fb + pixel + (y * win->xpsize)) = win->fill;
        }
    }

    /* Draw the top and bottom halves of the diamond */
    for (idy = 1; idy <= ry; idy++)
    {
        /* Compute left and right endpoints for the horizontal line */
        xinc = ((ry - idy) * rx);
        xleft = x - xinc / ry;
        xright = x + xinc / ry;

        /* Clip left and right edges if needed */
        if (xleft < win->xpvmin)
        {
            xleft = win->xpvmin;
        }
        if (xright > win->xpvmax)
        {
            xright = win->xpvmax;
        }

        /* Convert virtual coordinates to physical coordinates */
        xleft = xleft + win->xpmin;
        xright = xright + win->xpmin;

            /* Only render top line if it is visible */
        if ((y - idy) >= win->ypvmin)
        {
            /* Convert to physical coordinate */
            ydsp = ((y - idy) + win->ypmin) * win->xpsize;

            /* Draw the left pixel of the line in the pen color */
            * (win->fb + xleft + ydsp) = win->pen;
            
            /* Draw top line in fill color */
            for (pixel = (ydsp + xleft + 1);
                pixel <= (ydsp + xright - 1); pixel++)
            {
                * (win->fb + pixel) = win->fill;
            }

            /* Draw the right pixel of the line in the pen color */
            * (win->fb + xright + ydsp) = win->pen;
        }

        /* Only render bottom line if it is visible */
        if ((y + idy) <= win->ypvmax)
        {
            /* Convert to physical offset */
            ydsp = ((y + idy) + win->ypmin) * win->xpsize;

            /* Draw the left pixel of the line in the pen color */
            * (win->fb + xleft + ydsp) = win->pen;

            /* Draw top line in fill color */
            for (pixel = (ydsp + xleft + 1);
                pixel <= (ydsp + xright - 1); pixel++)
            {
                * (win->fb + pixel) = win->fill;
            }

            /* Draw the right pixel of the line in the pen color */
            * (win->fb + xright + ydsp) = win->pen;
        }
    }
}

/***********************************************************************
 *
 * Function: swim_clear_screen
 *
 * Purpose:
 *     Fills the draw area of the display with the selected color
 *
 * Processing:
 *     Loop through all virtual window (draw area) locations and
 *     updates them with the passed color value.
 *
 * Parameters: 
 *     win  : Window identifier
 *     colr : Color to place in the window
 *
 * Outputs:  None
 *
 * Returns: Nothing
 *
 * Notes: None
 *
 **********************************************************************/
void swim_clear_screen(SWIM_WINDOW_T *win,
                       COLOR_T colr)
{
    INT_32 x, y;

    for (y = win->ypvmin; y <= win->ypvmax; y++)
    {
        for (x = win->xpvmin; x <= win->xpvmax; x++)
        {
             * (win->fb + x + (y * win->xpsize)) = colr;
        }
    }
}

/***********************************************************************
 *
 * Function: swim_put_box
 *
 * Purpose: Place a box with corners (X1, Y1) and (X2, Y2)
 *
 * Processing:
 *     See function.
 *
 * Parameters: 
 *     win : Window identifier
 *     x1  : Virtual left position of box
 *     y1  : Virtual upper position of box
 *     x2  : Virtual right position of box
 *     y2  : Virtual lower position of box
 *
 * Outputs: None
 *
 * Returns: Nothing
 *
 * Notes: None
 *
 **********************************************************************/
void swim_put_box(SWIM_WINDOW_T *win,
                  INT_32 x1,
                  INT_32 y1,
                  INT_32 x2,
                  INT_32 y2)
{
    INT_32 xinc, yinc;
    INT_32 ysave;

    if (x1 > x2)
    {
        xinc = x1;
        x1 = x2;
        x2 = xinc;
    }

    /* Swap y1 and y2 if y1 is larger than y2 */
    if (y1 > y2)
    {
        yinc = y1;
        y1 = y2;
        y2 = yinc;
    }

    /* Convert virtual coordinates to physical coordinates */
    x1 = x1 + win->xpvmin;
    x2 = x2 + win->xpvmin;
    y1 = y1 + win->ypvmin;
    y2 = y2 + win->ypvmin;

    /* Clip boxes to window sizes */
    if (x1 < win->xpvmin)
    {
        x1 = win->xpvmin;
    }
    if (y1 < win->ypvmin)
    {
        y1 = win->ypvmin;
    }
    if (x2 > win->xpvmax)
    {
        x2 = win->xpvmax;
    }
    if (y2 > win->ypvmax)
    {
        y2 = win->ypvmax;
    }

    /* Get X and Y differences */
    xinc = x2 - x1;
    yinc = y2 - y1;

    /* Make outer edge of box in pen color */
    swim_put_line_raw(win, x1, y1, x2, y1);
    swim_put_line_raw(win, x2, y1, x2, y2);
    swim_put_line_raw(win, x2, y2, x1, y2);
    swim_put_line_raw(win, x1, y2, x1, y1);

    /* Increment X, Y values so they won't overwrite the edge */
    x1++;
    y1++;

    /* Draw the box inside with the fill color */
    ysave = y1;
    while (x1 < x2)
    {
        y1 = ysave;
        while (y1 < y2)
        {
             * (win->fb + x1 + (y1 * win->xpsize)) = win->fill;
             y1++;
        }
      
        x1++;
    }
}

/***********************************************************************
 *
 * Function: swim_window_open
 *
 * Purpose: Initializes a window and the default values for the window
 *
 * Processing:
 *     See function.
 *
 * Parameters: 
 *     win          : Preallocated windows structure to fill
 *     xsize        : Physical horizontal dimension of the display
 *     ysize        : Physical vertical dimension of the display
 *     fbaddr       : Address of the display's frame buffer
 *     xwin_min     : Physical window left coordinate
 *     ywin_min     : Physical window top coordinate
 *     xwin_max     : Physical window right coordinate
 *     ywin_max     : Physical window bottom coordinate
 *     border_width : Width of the window border in pixels
 *     pcolor       : Pen color
 *     bkcolor      : Background color
 *     fcolor       : Fill color
 *
 * Outputs: None
 *
 * Returns:
 *  TRUE if the window was initialized correctly, otherwise FALSE
 *
 * Notes:
 *     This function must be called prior to any other window function
 *
 **********************************************************************/
BOOL_32 swim_window_open(SWIM_WINDOW_T *win,
                         INT_32 xsize,
                         INT_32 ysize,
                         COLOR_T *fbaddr,
                         INT_32 xwin_min,
                         INT_32 ywin_min,
                         INT_32 xwin_max,
                         INT_32 ywin_max,
                         INT_32 border_width,
                         COLOR_T pcolor,
                         COLOR_T bkcolor,
                         COLOR_T fcolor)
{
    BOOL_32 init;

    init = swim_window_open_p(win, xsize, ysize, fbaddr, xwin_min,
       ywin_min, xwin_max, ywin_max, border_width, pcolor, bkcolor,
       fcolor, TRUE);

    /* Default font background is not transparent */
    win->tfont = 1;

    return init;
}

/***********************************************************************
 *
 * Function: swim_window_open_noclear
 *
 * Purpose: Initializes a window and the default values for the window
 *
 * Processing:
 *     See function.
 *
 * Parameters: 
 *     win          : Preallocated windows structure to fill
 *     xsize        : Physical horizontal dimension of the display
 *     ysize        : Physical vertical dimension of the display
 *     fbaddr       : Address of the display's frame buffer
 *     xwin_min     : Physical window left coordinate
 *     ywin_min     : Physical window top coordinate
 *     xwin_max     : Physical window right coordinate
 *     ywin_max     : Physical window bottom coordinate
 *     border_width : Width of the window border in pixels
 *     pcolor       : Pen color
 *     bkcolor      : Background color
 *     fcolor       : Fill color
 *
 * Outputs: None
 *
 * Returns:
 *  TRUE if the window was initialized correctly, otherwise FALSE
 *
 * Notes:
 *     This function must be called prior to any other window function
 *
 **********************************************************************/
BOOL_32 swim_window_open_noclear(SWIM_WINDOW_T *win,
                                 INT_32 xsize,
                                 INT_32 ysize,
                                 COLOR_T *fbaddr,
                                 INT_32 xwin_min,
                                 INT_32 ywin_min,
                                 INT_32 xwin_max,
                                 INT_32 ywin_max,
                                 INT_32 border_width,
                                 COLOR_T pcolor,
                                 COLOR_T bkcolor,
                                 COLOR_T fcolor)
{
    BOOL_32 init;

    init = swim_window_open_p(win, xsize, ysize, fbaddr, xwin_min,
       ywin_min, xwin_max, ywin_max, border_width, pcolor, bkcolor,
       fcolor, FALSE);

    /* Default font background is transparent */
    win->tfont = 0;

    return init;
}

/***********************************************************************
 *
 * Function: swim_window_close
 *
 * Purpose: Reallocates a window for use
 *
 * Processing:
 *     For the passed window ID, clear the window used flag.
 *
 * Parameters: 
 *     win : Window identifier
 *
 * Outputs:  None
 *
 * Returns:  Nothing
 *
 * Notes:
 *     This is a defunct function and is not needed.
 *
 **********************************************************************/
void swim_window_close(SWIM_WINDOW_T *win)
{
    win->winused = 0x0;
}

/***********************************************************************
 *
 * Function: swim_set_pen_color
 *
 * Purpose: Sets the pen color
 *
 * Processing:
 *     For the passed window ID, update to the passed pen color.
 *
 * Parameters: 
 *     win       : Window identifier
 *     pen_color : New pen color
 *
 * Outputs: None
 *
 * Returns: Nothing
 *
 * Notes: None
 *
 **********************************************************************/
void swim_set_pen_color(SWIM_WINDOW_T *win,
                        COLOR_T pen_color)
{
    win->pen = pen_color;
}

/***********************************************************************
 *
 * Function: swim_set_fill_color
 *
 * Purpose: Sets the fill color
 *
 * Processing:
 *     For the passed window ID, update to the passed fill color.
 *
 * Parameters: 
 *     win        : Window identifier
 *     fill_color : New fill color
 *
 * Outputs: None
 *
 * Returns: Nothing
 *
 * Notes: None
 *
 **********************************************************************/
void swim_set_fill_color(SWIM_WINDOW_T *win,
                         COLOR_T fill_color)
{
    win->fill = fill_color;
}

/***********************************************************************
 *
 * Function: swim_set_bkg_color
 *
 * Purpose: Sets the color used for backgrounds
 *
 * Processing:
 *     For the passed window ID, update to the passed background color.
 *
 * Parameters: 
 *     win        : Window identifier
 *     tbkg_color : New background color
 *
 * Outputs: None
 *
 * Returns: Nothing
 *
 * Notes: None
 *
 **********************************************************************/
void swim_set_bkg_color(SWIM_WINDOW_T *win,
                        COLOR_T bkg_color)
{
    win->bkg = bkg_color;
}

/***********************************************************************
 *
 * Function: swim_get_horizontal_size
 *
 * Purpose: Get the virtual window horizontal size
 *
 * Processing:
 *     For the passed window ID, return the x size of the window.
 *
 * Parameters: 
 *     win        : Window identifier
 *
 * Outputs: None
 *
 * Returns: The virtual window horizontal size
 *
 * Notes: None
 *
 **********************************************************************/
INT_32 swim_get_horizontal_size(SWIM_WINDOW_T *win)
{
    return win->xvsize;
}

/***********************************************************************
 *
 * Function: swim_get_vertical_size
 *
 * Purpose: Get the virtual window vertical size
 *
 * Processing:
 *     For the passed window ID, return the x size of the window.
 *
 * Parameters: 
 *     win        : Window identifier
 *
 * Outputs: None
 *
 * Returns: The virtual window horizontal size
 *
 * Notes: None
 *
 **********************************************************************/
INT_32 swim_get_vertical_size(SWIM_WINDOW_T *win)
{
    return win->yvsize;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?