⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 abl_swim.c

📁 sharp触摸屏测试代码
💻 C
📖 第 1 页 / 共 2 页
字号:
                * (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)) = win->bkg;
        }
    }
}

/***********************************************************************
 *
 * 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)
{
    INT_32 i;
    BOOL_32 init = FALSE;

    /* Before continuing, check to see that the window size is
       in the physical dimensions of the display */
    if ((xwin_min >= 0) && (ywin_min >= 0) &&
        (xwin_max < xsize) && (ywin_max < ysize))
    {
        init = TRUE;
    }
    else
    {
        /* Window size is out of the physical display size, so it
           should be invalidated */
        win->winused = 0x0;
    }

    if (init == TRUE)
    {
        /* Save physical display dimensions */
        win->xpsize = xsize;
        win->ypsize = ysize;

        /* Save frame buffer address */
        win->fb = fbaddr;

        /* Save physical window dimensions and default colors */
        win->xpmin = xwin_min;
        win->ypmin = ywin_min;
        win->xpmax = xwin_max;
        win->ypmax = ywin_max;
        win->pen = pcolor;
        win->bkg = bkcolor;
        win->fill = fcolor;

        /* Compute physical window dimensions of draw area only */
        win->xpvmin = xwin_min + border_width;
        win->ypvmin = ywin_min + border_width;
        win->xpvmax = xwin_max - border_width;
        win->ypvmax = ywin_max - border_width;

        /* Compute virtual window size of draw area */
        win->xvsize = xwin_max - xwin_min - 2 * border_width;
        win->yvsize = ywin_max - ywin_min - 2 * border_width;

        /* Fill in any unused border padding between draw area and border
           will fill color */
        for (i = 0; i < border_width; i++)
        {
            swim_put_line_raw(win, (xwin_min + i),
                (ywin_min + i), (xwin_max - i), (ywin_min + i));
            swim_put_line_raw(win, (xwin_max - i),
                (ywin_min + i), (xwin_max - i), (ywin_max - i));
            swim_put_line_raw(win, (xwin_max - i),
                (ywin_max - i), (xwin_min + i), (ywin_max - i));
            swim_put_line_raw(win, (xwin_min + i),
                (ywin_max - i), (xwin_min + i), (ywin_min + i));
        }

        /* Clear draw area with background color */
        swim_clear_screen(win, bkcolor);

        /* Use the default font and make background transparent */
        win->font = (FONT_T *) &font_helvr10;
        win->tfont = 1;

        /* Set starting text position in upper left of window */
        win->xvpos = win->xpvmin;
        win->yvpos = win->ypvmin;
    }
   
   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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -