abl_swim.c
来自「SHARP_ARM720T_LH79524/5软件开发包_支持TFT_LCD_N」· C语言 代码 · 共 996 行 · 第 1/2 页
C
996 行
/***********************************************************************
* $Workfile: abl_swim.c $
* $Revision: 1.5 $
* $Author: WellsK $
* $Date: Oct 04 2004 15:01:00 $
*
* Project: Simple Windowing Interface Manager (SWIM)
*
* Description:
* See the swim.h header file for a description of this package.
*
* Revision History:
* $Log: //smaicnt2/pvcs/VM/sharpmcu/archives/sharpmcu/software/abl/source/abl_swim.c-arc $
*
* Rev 1.5 Oct 04 2004 15:01:00 WellsK
* Added function to create a window without clearing the
* background and defaulting to transparent text background.
*
* Rev 1.4 Sep 09 2004 09:54:32 WellsK
* Corrected clear screen function's use of background color
* instead of passed color.
*
* Rev 1.3 Jan 05 2004 10:55:56 WellsK
* Corrected an virtual line draw issue that would cause a divide
* by zero when the line start and end points were the same.
*
* Rev 1.2 Sep 30 2003 16:56:24 WellsK
* Added swim_put_diamond function.
*
* Rev 1.1 Jun 25 2003 14:11:42 WellsK
* Changed default font type to point directly to helvr10 font data
* structure. Added functions to return virtual window sizes.
*
* Rev 1.0 Jun 09 2003 12:06:28 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) 2001 SHARP MICROELECTRONICS OF THE AMERICAS, INC.
* CAMAS, WA
**********************************************************************/
#include "abl_swim.h"
#include "abl_fonts.h"
#include "abl_helvr10.h"
/***********************************************************************
* Private functions
**********************************************************************/
/***********************************************************************
*
* 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: None
*
**********************************************************************/
void swim_put_line_raw(SWIM_WINDOW_T *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;
pixel_end = x2;
/* Determine incremental values for X and Y */
yinc = win->ypsize * yinc / xinc;
xinc = win->xpsize;
}
else
{
/* Use Y axis for drawing */
pixel_start = y1;
pixel_end = y2;
/* Determine scaling factors */
xinc = win->xpsize * xinc / yinc;
yinc = win->ypsize;
}
x1 = x1 * win->xpsize;
y1 = y1 * 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 / win->xpsize;
yv = y1 / win->ypsize;
if ((xv >= 0) && (yv >= 0) &&
(xv <= (win->xpsize - 1)) &&
(yv <= (win->ypsize - 1)))
{
offs = xv + yv * win->xpsize;
* (win->fb + offs) = 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_window_open_p
*
* 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
* clear : Clear window flag
*
* 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_p(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 clear)
{
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 */
if (clear == TRUE)
{
swim_clear_screen(win, bkcolor);
}
/* Use the default font and make background transparent */
win->font = (FONT_T *) &font_helvr10;
/* Set starting text position in upper left of window */
win->xvpos = win->xpvmin;
win->yvpos = win->ypvmin;
}
return init;
}
/***********************************************************************
* Public 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(SWIM_WINDOW_T *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 = win->xpvmin + x1;
realy = win->ypvmin + y1;
/* Only put the pixel in the window if it fits in the window */
if ((realx <= win->xpvmax) &&
(realy <= win->ypvmax))
{
*(win->fb + realx + (realy * win->xpsize)) = win->pen;
}
}
/***********************************************************************
*
* 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(SWIM_WINDOW_T *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 + win->xpvmin;
x2 = x2 + win->xpvmin;
y1 = y1 + win->ypvmin;
y2 = y2 + win->ypvmin;
/* Determine difference X and Y values */
xinc = x2 - x1;
yinc = y2 - y1;
if ((xinc == 0) && (yinc == 0))
{
/* Line origins are the same! Plot a pixel instead */
*(win->fb + x1 + (y1 * win->xpsize)) = win->pen;
}
else
{
if (xinc > yinc)
{
/* Use X axis for drawing */
pixel_start = x1;
pixel_end = x2;
/* Determine incremental values for X and Y */
yinc = win->ypsize * yinc / xinc;
xinc = win->xpsize;
}
else
{
/* Use Y axis for drawing */
pixel_start = y1;
pixel_end = y2;
/* Determine scaling factors */
xinc = win->xpsize * xinc / yinc;
yinc = win->ypsize;
}
x1 = x1 * win->xpsize;
y1 = y1 * 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 / win->xpsize;
yv = y1 / win->ypsize;
if ((xv >= win->xpvmin) &&
(yv >= win->ypvmin) &&
(xv <= win->xpvmax) &&
(yv <= win->ypvmax))
{
offs = xv + yv * win->xpsize;
* (win->fb + offs) = 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_put_diamond
*
* Purpose:
* Purpose: Draw a diamond in the virtual window
*
* Processing:
* See function.
*
* Parameters:
* win : Window identifier
* x : Virtual X position of the diamond
* y : Virtual Y position of the diamond
* rx : Radius for horizontal
* ry : Radius for vertical
*
* Outputs: None
*
* Returns: Nothing
*
* Notes:
* This function supports clipping.
*
**********************************************************************/
void swim_put_diamond(SWIM_WINDOW_T *win,
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?