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

📄 sma_swim.c

📁 sharp的arm920t 7A400的评估板附带光盘Sharp KEVLH7A400 v0.3b Welcome to the SHARP KEV7A400 Evaluation board
💻 C
📖 第 1 页 / 共 2 页
字号:
/***********************************************************************
 * $Workfile:   SMA_swim.c  $
 * $Revision:   1.0  $
 * $Author:   WellsK  $
 * $Date:   Aug 27 2002 08:36:00  $
 *
 * Project: Simple Windowing Interface Manager (SWIM)
 *
 * Description:
 *  See the swim.h header file for a description of this package.
 *
 *  How to use this package:
 *    Prior to any use of this package's functions, call swim_window_open
 *    first to initialize a window. This returns a window ID value that
 *    is used in all subsequent windowing calls. Be sure to call the
 *    swim_window_close function to 'deallocate' the window so it can be
 *    used again.
 *
 * Revision History:
 * $Log:   //smaicnt2/pvcs/VM/CHIPS/archives/SOC/Source/Graphics/SWIM/SMA_swim.c-arc  $
 * 
 *    Rev 1.0   Aug 27 2002 08:36:00   WellsK
 * Initial revision.
 * 
 *
 * SHARP MICROELECTRONICS OF THE AMERICAS MAKES NO REPRESENTATION
 * OR WARRANTIES WITH RESPECT TO THE PERFORMANCE OF THIS SOFTWARE,
 * AND SPECIFICALLY DISCLAIMS ANY RESPONSIBILITY FOR ANY DAMAGES, 
 * SPECIAL OR CONSEQUENTIAL, CONNECTED WITH THE USE OF THIS SOFTWARE.
 *
 * SHARP MICROELECTRONICS OF THE AMERICAS PROVIDES THIS SOFTWARE SOLELY 
 * FOR THE PURPOSE OF SOFTWARE DEVELOPMENT INCORPORATING THE USE OF A 
 * SHARP MICROCONTROLLER OR SYSTEM-ON-CHIP PRODUCT. USE OF THIS SOURCE
 * FILE IMPLIES ACCEPTANCE OF THESE CONDITIONS.
 *
 * COPYRIGHT (C) 2002 SHARP MICROELECTRONICS OF THE AMERICAS, INC.
 *     CAMAS, WA
 **********************************************************************/
#include "SMA_types.h"
#include "SMA_swim.h"
#include "SMA_fonts.h"

//**********************************************************************
// Configuration and package data
//**********************************************************************
// Array of window configuration structures
swim_window_type window [WINDOWSMAX];

//**********************************************************************
// Functions
//**********************************************************************

/***********************************************************************
 *
 * Function: swim_put_pixel
 *
 * Purpose:
 *  Puts a pixel at the virtual X, Y coordinate in the window.
 *
 * Processing:
 *  Convert the virtual pixel position to a physical position.
 *  If the pixel is inside the window draw area, update the pixel
 *     on the display.
 *
 * Parameters:
 *  win : Window identifier
 *  x1  : Virtual X position of pixel
 *  y1  : Virtual Y position of pixel
 *
 * Outputs:
 *  None
 *
 * Returns:
 *  Nothing
 *
 * Notes:
 *  The pixel will not be displayed if the pixel exceeds the window
 *  virtual size. Pixel positions below 0 should not be used with this
 *  function.
 *
 **********************************************************************/
void swim_put_pixel (INT_32 win, INT_32 x1, INT_32 y1)
{
    INT_16 realx, realy;

    // Convert virtual coordinate to physical coordinate taking into
    // consideration the border size of the window
    realx = window [win].xpvmin + x1;
    realy = window [win].ypvmin + y1;

    // Only put the pixel in the window if it fits in the window
    if ((realx <= window [win].xpvmax) &&
        (realy <= window [win].ypvmax))
    {
        * (window [win].fb + realx + (realy * window [win].xpsize)) =
            window [win].pen;
    }
}

/***********************************************************************
 *
 * Function: swim_put_line_raw
 *
 * Purpose:
 *  Draw a line on the physical display.
 *
 * Processing:
 *  See function.
 *
 * Parameters: 
 *  win : Window identifier
 *  x1  : Physical X position of X line start
 *  y1  : Physical Y position of Y line start
 *  x2  : Physical X position of X line end
 *  y2  : Physical Y position of Y line end
 *
 * Outputs:
 *  None
 *
 * Returns:
 *  Nothing
 *
 * Notes:
 *  This function is private to this module.
 *
 **********************************************************************/
void swim_put_line_raw (INT_32 win, INT_32 x1, INT_32 y1, INT_32 x2,
    INT_32 y2)
{
    INT_32 xinc, yinc;
    INT_32 pixel_start, pixel_end;
    INT_32 line;
    INT_32 offs;
    INT_32 xv, yv;

    // Drawing is performed at a much 'higher' resolution that the
    // actual display. Before writing to the frame buffer, the 'lower'
    // resolution is restored.

    // Swap x1 and x2 if x1 is larger than x2
    if (x1 > x2)
    {
        line = x1;
        x1 = x2;
        x2 = line;
    }

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

    // Determine difference X and Y values
    xinc = x2 - x1;
    yinc = y2 - y1;

    if (xinc > yinc)
    {
        // Use X axis for drawing
        pixel_start = x1;   // Starting pixel
        pixel_end = x2;     // Ending pixel

        // Determine incremental values for X and Y
        yinc = window [win].ypsize * yinc / xinc;
        xinc = window [win].xpsize;
    }
    else
    {
        // Use Y axis for drawing
        pixel_start = y1;   // Starting pixel
        pixel_end = y2;     // Ending pixel

        // Determine scaling factors
        xinc = window [win].xpsize * xinc / yinc;
        yinc = window [win].ypsize;
    }

    x1 = x1 * window [win].xpsize;
    y1 = y1 * window [win].ypsize;

    // Draw line
    for (line = pixel_start; line <= pixel_end;)
    {
        // Convert pixel address into real offset in display
        // Only plot if in physical display
        xv = x1 / window [win].xpsize;
        yv = y1 / window [win].ypsize;
        if ((xv >= 0) && (yv >= 0) &&
            (xv <= (window [win].xpsize - 1)) &&
            (yv <= (window [win].ypsize - 1)))
        {
            offs = xv + yv * window [win].xpsize;
            * (window [win].fb + offs) = window [win].pen;
        }
        else
        {
            // Out of display, force exit
            line = pixel_end + 1;
        }

        // Increment X and Y pixel locations
        x1 = x1 + xinc;
        y1 = y1 + yinc;

        // Increment to next pixel
        line++;
    }
}

/***********************************************************************
 *
 * Function: swim_put_line
 *
 * Purpose:
 *  Draw a line in the virtual window with clipping.
 *
 * Processing:
 *  See function.
 *
 * Parameters: 
 *  win : Window identifier
 *  x1  : Virtual X position of X line start
 *  y1  : Virtual Y position of Y line start
 *  x2  : Virtual X position of X line end
 *  y2  : Virtual Y position of Y line end
 *
 * Outputs:
 *  None
 *
 * Returns:
 *  Nothing
 *
 * Notes:
 *  This function supports clipping.
 *
 **********************************************************************/
void swim_put_line (INT_32 win, INT_32 x1, INT_32 y1, INT_32 x2,
    INT_32 y2)
{
    INT_32 xinc, yinc;
    INT_32 pixel_start, pixel_end;
    INT_32 line;
    INT_32 offs;
    INT_32 xv, yv;

    // Drawing is performed at a much 'higher' resolution that the
    // actual display. Before writing to the frame buffer, the 'lower'
    // resolution is restored.

    // Swap x1 and x2 if x1 is larger than x2
    if (x1 > x2)
    {
        line = x1;
        x1 = x2;
        x2 = line;
    }

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

    // Convert virtual coordinates to physical coordinates
    x1 = x1 + window [win].xpvmin;
    x2 = x2 + window [win].xpvmin;
    y1 = y1 + window [win].ypvmin;
    y2 = y2 + window [win].ypvmin;

    // Determine difference X and Y values
    xinc = x2 - x1;
    yinc = y2 - y1;

    if (xinc > yinc)
    {
        // Use X axis for drawing
        pixel_start = x1;   // Starting pixel
        pixel_end = x2;     // Ending pixel

        // Determine incremental values for X and Y
        yinc = window [win].ypsize * yinc / xinc;
        xinc = window [win].xpsize;
    }
    else
    {
        // Use Y axis for drawing
        pixel_start = y1;   // Starting pixel
        pixel_end = y2;     // Ending pixel

        // Determine scaling factors
        xinc = window [win].xpsize * xinc / yinc;
        yinc = window [win].ypsize;
    }

    x1 = x1 * window [win].xpsize;
    y1 = y1 * window [win].ypsize;

    // Draw line
    for (line = pixel_start; line <= pixel_end;)
    {
        // Convert pixel address into real offset in display
        // Only plot if in physical display
        xv = x1 / window [win].xpsize;
        yv = y1 / window [win].ypsize;
        if ((xv >= window [win].xpvmin) &&
            (yv >= window [win].ypvmin) &&
            (xv <= window [win].xpvmax) &&
            (yv <= window [win].ypvmax))
        {
            offs = xv + yv * window [win].xpsize;
            * (window [win].fb + offs) = window [win].pen;
        }
        else
        {
            // Out of window, force exit
            line = pixel_end + 1;
        }

        // Increment X and Y pixel locations
        x1 = x1 + xinc;
        y1 = y1 + yinc;

        // Increment to next pixel
        line++;
    }
}

/***********************************************************************
 *
 * 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 (INT_32 win, color_type colr)
{
    INT_32 x, y;

    for (y = window [win].ypvmin; y <= window [win].ypvmax; y++)
    {
        for (x = window [win].xpvmin; x <= window [win].xpvmax; x++)
        {
             * (window [win].fb + x + (y * window [win].xpsize)) =
                 window [win].bkg;
        }
    }
}

/***********************************************************************
 *
 * Function: swim_put_box
 *

⌨️ 快捷键说明

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